aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CREDITS8
-rw-r--r--Documentation/filesystems/nfs-rdma.txt252
-rw-r--r--Documentation/sound/alsa/ALSA-Configuration.txt47
-rw-r--r--Documentation/video4linux/CARDLIST.au08284
-rw-r--r--Documentation/video4linux/CARDLIST.bttv2
-rw-r--r--Documentation/video4linux/CARDLIST.cx238853
-rw-r--r--Documentation/video4linux/CARDLIST.cx889
-rw-r--r--Documentation/video4linux/CARDLIST.saa713413
-rw-r--r--Documentation/video4linux/extract_xc3028.pl46
-rw-r--r--MAINTAINERS6
-rw-r--r--arch/alpha/kernel/osf_sys.c1
-rw-r--r--arch/alpha/kernel/pci.c22
-rw-r--r--arch/alpha/kernel/sys_nautilus.c2
-rw-r--r--arch/arm/mach-integrator/time.c5
-rw-r--r--arch/arm/mach-lh7a40x/arch-kev7a400.c5
-rw-r--r--arch/arm/mm/Kconfig6
-rw-r--r--arch/arm/mm/proc-arm1020.S2
-rw-r--r--arch/arm/mm/proc-arm1020e.S2
-rw-r--r--arch/arm/mm/proc-arm1022.S2
-rw-r--r--arch/arm/mm/proc-arm1026.S2
-rw-r--r--arch/arm/mm/proc-arm6_7.S4
-rw-r--r--arch/arm/mm/proc-arm720.S2
-rw-r--r--arch/arm/mm/proc-arm740.S1
-rw-r--r--arch/arm/mm/proc-arm7tdmi.S1
-rw-r--r--arch/arm/mm/proc-arm920.S2
-rw-r--r--arch/arm/mm/proc-arm922.S2
-rw-r--r--arch/arm/mm/proc-arm925.S2
-rw-r--r--arch/arm/mm/proc-arm926.S2
-rw-r--r--arch/arm/mm/proc-arm940.S1
-rw-r--r--arch/arm/mm/proc-arm946.S1
-rw-r--r--arch/arm/mm/proc-arm9tdmi.S1
-rw-r--r--arch/arm/mm/proc-feroceon.S2
-rw-r--r--arch/arm/mm/proc-sa110.S2
-rw-r--r--arch/arm/mm/proc-sa1100.S2
-rw-r--r--arch/arm/mm/proc-v6.S2
-rw-r--r--arch/arm/mm/proc-v7.S2
-rw-r--r--arch/arm/mm/proc-xsc3.S1
-rw-r--r--arch/arm/mm/proc-xscale.S2
-rw-r--r--arch/blackfin/Kconfig161
-rw-r--r--arch/blackfin/Makefile5
-rw-r--r--arch/blackfin/boot/.gitignore1
-rw-r--r--arch/blackfin/configs/BF527-EZKIT_defconfig8
-rw-r--r--arch/blackfin/configs/BF533-EZKIT_defconfig4
-rw-r--r--arch/blackfin/configs/BF533-STAMP_defconfig4
-rw-r--r--arch/blackfin/configs/BF537-STAMP_defconfig4
-rw-r--r--arch/blackfin/configs/BF548-EZKIT_defconfig8
-rw-r--r--arch/blackfin/configs/BF561-EZKIT_defconfig4
-rw-r--r--arch/blackfin/configs/CM-BF533_defconfig912
-rw-r--r--arch/blackfin/configs/CM-BF537E_defconfig940
-rw-r--r--arch/blackfin/configs/CM-BF537U_defconfig940
-rw-r--r--arch/blackfin/configs/CM-BF548_defconfig1373
-rw-r--r--arch/blackfin/configs/CM-BF561_defconfig876
-rw-r--r--arch/blackfin/configs/H8606_defconfig4
-rw-r--r--arch/blackfin/configs/IP0X_defconfig1252
-rw-r--r--arch/blackfin/configs/PNAV-10_defconfig4
-rw-r--r--arch/blackfin/configs/SRV1_defconfig1290
-rw-r--r--arch/blackfin/kernel/Makefile8
-rw-r--r--arch/blackfin/kernel/bfin_dma_5xx.c13
-rw-r--r--arch/blackfin/kernel/bfin_gpio.c169
-rw-r--r--arch/blackfin/kernel/cplb-mpu/cplbinfo.c8
-rw-r--r--arch/blackfin/kernel/cplb-mpu/cplbinit.c4
-rw-r--r--arch/blackfin/kernel/cplb-mpu/cplbmgr.c128
-rw-r--r--arch/blackfin/kernel/cplb-nompu/cplbinfo.c15
-rw-r--r--arch/blackfin/kernel/cplb-nompu/cplbinit.c31
-rw-r--r--arch/blackfin/kernel/dma-mapping.c4
-rw-r--r--arch/blackfin/kernel/gptimers.c24
-rw-r--r--arch/blackfin/kernel/process.c69
-rw-r--r--arch/blackfin/kernel/ptrace.c7
-rw-r--r--arch/blackfin/kernel/reboot.c69
-rw-r--r--arch/blackfin/kernel/setup.c131
-rw-r--r--arch/blackfin/kernel/signal.c24
-rw-r--r--arch/blackfin/kernel/sys_bfin.c2
-rw-r--r--arch/blackfin/kernel/time-ts.c219
-rw-r--r--arch/blackfin/kernel/time.c19
-rw-r--r--arch/blackfin/kernel/traps.c94
-rw-r--r--arch/blackfin/kernel/vmlinux.lds.S54
-rw-r--r--arch/blackfin/mach-bf527/Makefile2
-rw-r--r--arch/blackfin/mach-bf527/boards/ezkit.c36
-rw-r--r--arch/blackfin/mach-bf527/cpu.c161
-rw-r--r--arch/blackfin/mach-bf527/dma.c5
-rw-r--r--arch/blackfin/mach-bf527/head.S18
-rw-r--r--arch/blackfin/mach-bf533/Makefile2
-rw-r--r--arch/blackfin/mach-bf533/boards/H8606.c25
-rw-r--r--arch/blackfin/mach-bf533/boards/Kconfig6
-rw-r--r--arch/blackfin/mach-bf533/boards/Makefile1
-rw-r--r--arch/blackfin/mach-bf533/boards/cm_bf533.c25
-rw-r--r--arch/blackfin/mach-bf533/boards/ezkit.c25
-rw-r--r--arch/blackfin/mach-bf533/boards/generic_board.c2
-rw-r--r--arch/blackfin/mach-bf533/boards/ip0x.c303
-rw-r--r--arch/blackfin/mach-bf533/boards/stamp.c62
-rw-r--r--arch/blackfin/mach-bf533/cpu.c158
-rw-r--r--arch/blackfin/mach-bf533/dma.c5
-rw-r--r--arch/blackfin/mach-bf533/head.S34
-rw-r--r--arch/blackfin/mach-bf537/Makefile2
-rw-r--r--arch/blackfin/mach-bf537/boards/cm_bf537.c58
-rw-r--r--arch/blackfin/mach-bf537/boards/generic_board.c34
-rw-r--r--arch/blackfin/mach-bf537/boards/minotaur.c36
-rw-r--r--arch/blackfin/mach-bf537/boards/pnav10.c31
-rw-r--r--arch/blackfin/mach-bf537/boards/stamp.c93
-rw-r--r--arch/blackfin/mach-bf537/cpu.c159
-rw-r--r--arch/blackfin/mach-bf537/dma.c5
-rw-r--r--arch/blackfin/mach-bf537/head.S46
-rw-r--r--arch/blackfin/mach-bf548/Makefile2
-rw-r--r--arch/blackfin/mach-bf548/boards/Kconfig6
-rw-r--r--arch/blackfin/mach-bf548/boards/Makefile1
-rw-r--r--arch/blackfin/mach-bf548/boards/cm_bf548.c664
-rw-r--r--arch/blackfin/mach-bf548/boards/ezkit.c105
-rw-r--r--arch/blackfin/mach-bf548/cpu.c159
-rw-r--r--arch/blackfin/mach-bf548/dma.c4
-rw-r--r--arch/blackfin/mach-bf548/head.S18
-rw-r--r--arch/blackfin/mach-bf561/boards/cm_bf561.c25
-rw-r--r--arch/blackfin/mach-bf561/boards/ezkit.c32
-rw-r--r--arch/blackfin/mach-bf561/boards/generic_board.c2
-rw-r--r--arch/blackfin/mach-bf561/boards/tepla.c2
-rw-r--r--arch/blackfin/mach-bf561/dma.c5
-rw-r--r--arch/blackfin/mach-bf561/head.S34
-rw-r--r--arch/blackfin/mach-common/Makefile3
-rw-r--r--arch/blackfin/mach-common/arch_checks.c3
-rw-r--r--arch/blackfin/mach-common/cpufreq.c194
-rw-r--r--arch/blackfin/mach-common/entry.S128
-rw-r--r--arch/blackfin/mach-common/ints-priority.c56
-rw-r--r--arch/blackfin/mach-common/lock.S2
-rw-r--r--arch/blackfin/mm/blackfin_sram.c2
-rw-r--r--arch/blackfin/oprofile/common.c2
-rw-r--r--arch/blackfin/oprofile/op_model_bf533.c2
-rw-r--r--arch/sparc/kernel/entry.S1
-rw-r--r--arch/sparc/kernel/signal.c5
-rw-r--r--arch/sparc64/Kconfig20
-rw-r--r--arch/sparc64/defconfig99
-rw-r--r--arch/sparc64/kernel/ebus.c1
-rw-r--r--arch/sparc64/kernel/entry.S37
-rw-r--r--arch/sparc64/kernel/entry.h1
-rw-r--r--arch/sparc64/kernel/etrap.S4
-rw-r--r--arch/sparc64/kernel/iommu.c33
-rw-r--r--arch/sparc64/kernel/isa.c1
-rw-r--r--arch/sparc64/kernel/mdesc.c28
-rw-r--r--arch/sparc64/kernel/of_device.c12
-rw-r--r--arch/sparc64/kernel/pci.c12
-rw-r--r--arch/sparc64/kernel/pci_fire.c5
-rw-r--r--arch/sparc64/kernel/pci_impl.h4
-rw-r--r--arch/sparc64/kernel/pci_msi.c8
-rw-r--r--arch/sparc64/kernel/pci_psycho.c5
-rw-r--r--arch/sparc64/kernel/pci_sabre.c4
-rw-r--r--arch/sparc64/kernel/pci_schizo.c5
-rw-r--r--arch/sparc64/kernel/pci_sun4v.c13
-rw-r--r--arch/sparc64/kernel/prom.c14
-rw-r--r--arch/sparc64/kernel/rtrap.S21
-rw-r--r--arch/sparc64/kernel/sbus.c3
-rw-r--r--arch/sparc64/kernel/setup.c3
-rw-r--r--arch/sparc64/kernel/signal.c25
-rw-r--r--arch/sparc64/kernel/signal32.c20
-rw-r--r--arch/sparc64/kernel/smp.c11
-rw-r--r--arch/sparc64/kernel/sparc64_ksyms.c2
-rw-r--r--arch/sparc64/kernel/stacktrace.c16
-rw-r--r--arch/sparc64/kernel/sun4v_tlb_miss.S16
-rw-r--r--arch/sparc64/kernel/sysfs.c12
-rw-r--r--arch/sparc64/kernel/traps.c19
-rw-r--r--arch/sparc64/kernel/tsb.S2
-rw-r--r--arch/sparc64/kernel/winfixup.S12
-rw-r--r--arch/sparc64/mm/init.c989
-rw-r--r--arch/sparc64/mm/tsb.c3
-rw-r--r--arch/sparc64/mm/ultra.S4
-rw-r--r--drivers/char/Kconfig28
-rw-r--r--drivers/char/Makefile1
-rw-r--r--drivers/char/bfin-otp.c189
-rw-r--r--drivers/char/mwave/tp3780i.c14
-rw-r--r--drivers/input/misc/Kconfig1
-rw-r--r--drivers/media/Kconfig11
-rw-r--r--drivers/media/common/ir-functions.c2
-rw-r--r--drivers/media/common/ir-keymaps.c172
-rw-r--r--drivers/media/common/saa7146_core.c8
-rw-r--r--drivers/media/common/saa7146_i2c.c6
-rw-r--r--drivers/media/common/saa7146_vbi.c4
-rw-r--r--drivers/media/common/saa7146_video.c4
-rw-r--r--drivers/media/dvb/b2c2/Kconfig5
-rw-r--r--drivers/media/dvb/b2c2/Makefile2
-rw-r--r--drivers/media/dvb/b2c2/flexcop-common.h17
-rw-r--r--drivers/media/dvb/b2c2/flexcop-dma.c4
-rw-r--r--drivers/media/dvb/b2c2/flexcop-eeprom.c9
-rw-r--r--drivers/media/dvb/b2c2/flexcop-fe-tuner.c211
-rw-r--r--drivers/media/dvb/b2c2/flexcop-i2c.c180
-rw-r--r--drivers/media/dvb/b2c2/flexcop-misc.c2
-rw-r--r--drivers/media/dvb/b2c2/flexcop-pci.c2
-rw-r--r--drivers/media/dvb/b2c2/flexcop-reg.h2
-rw-r--r--drivers/media/dvb/b2c2/flexcop-sram.c28
-rw-r--r--drivers/media/dvb/b2c2/flexcop-usb.c17
-rw-r--r--drivers/media/dvb/b2c2/flexcop.c18
-rw-r--r--drivers/media/dvb/bt8xx/Kconfig2
-rw-r--r--drivers/media/dvb/bt8xx/Makefile5
-rw-r--r--drivers/media/dvb/bt8xx/dst.c2
-rw-r--r--drivers/media/dvb/bt8xx/dst_ca.c10
-rw-r--r--drivers/media/dvb/bt8xx/dvb-bt8xx.c23
-rw-r--r--drivers/media/dvb/bt8xx/dvb-bt8xx.h2
-rw-r--r--drivers/media/dvb/cinergyT2/cinergyT2.c9
-rw-r--r--drivers/media/dvb/dvb-core/demux.h2
-rw-r--r--drivers/media/dvb/dvb-core/dmxdev.c87
-rw-r--r--drivers/media/dvb/dvb-core/dvb_ca_en50221.c36
-rw-r--r--drivers/media/dvb/dvb-core/dvb_demux.c6
-rw-r--r--drivers/media/dvb/dvb-core/dvb_frontend.c30
-rw-r--r--drivers/media/dvb/dvb-core/dvb_net.c32
-rw-r--r--drivers/media/dvb/dvb-core/dvb_ringbuffer.c6
-rw-r--r--drivers/media/dvb/dvb-core/dvb_ringbuffer.h8
-rw-r--r--drivers/media/dvb/dvb-core/dvbdev.c47
-rw-r--r--drivers/media/dvb/dvb-core/dvbdev.h13
-rw-r--r--drivers/media/dvb/dvb-usb/Kconfig1
-rw-r--r--drivers/media/dvb/dvb-usb/a800.c6
-rw-r--r--drivers/media/dvb/dvb-usb/af9005.c5
-rw-r--r--drivers/media/dvb/dvb-usb/au6610.c6
-rw-r--r--drivers/media/dvb/dvb-usb/cxusb.c51
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700.h4
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700_core.c9
-rw-r--r--drivers/media/dvb/dvb-usb/dib0700_devices.c325
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-mb.c14
-rw-r--r--drivers/media/dvb/dvb-usb/dibusb-mc.c5
-rw-r--r--drivers/media/dvb/dvb-usb/digitv.c8
-rw-r--r--drivers/media/dvb/dvb-usb/dtt200u.c17
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-common.h3
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-dvb.c9
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-ids.h13
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb-init.c16
-rw-r--r--drivers/media/dvb/dvb-usb/dvb-usb.h5
-rw-r--r--drivers/media/dvb/dvb-usb/gl861.c6
-rw-r--r--drivers/media/dvb/dvb-usb/gp8psk-fe.c4
-rw-r--r--drivers/media/dvb/dvb-usb/gp8psk.c5
-rw-r--r--drivers/media/dvb/dvb-usb/m920x.c34
-rw-r--r--drivers/media/dvb/dvb-usb/nova-t-usb2.c5
-rw-r--r--drivers/media/dvb/dvb-usb/opera1.c8
-rw-r--r--drivers/media/dvb/dvb-usb/ttusb2.c67
-rw-r--r--drivers/media/dvb/dvb-usb/umt-010.c5
-rw-r--r--drivers/media/dvb/dvb-usb/vp702x-fe.c18
-rw-r--r--drivers/media/dvb/dvb-usb/vp702x.c5
-rw-r--r--drivers/media/dvb/dvb-usb/vp7045.c6
-rw-r--r--drivers/media/dvb/frontends/Kconfig28
-rw-r--r--drivers/media/dvb/frontends/Makefile4
-rw-r--r--drivers/media/dvb/frontends/au8522.c692
-rw-r--r--drivers/media/dvb/frontends/au8522.h56
-rw-r--r--drivers/media/dvb/frontends/bcm3510.c4
-rw-r--r--drivers/media/dvb/frontends/bcm3510.h2
-rw-r--r--drivers/media/dvb/frontends/bsbe1.h58
-rw-r--r--drivers/media/dvb/frontends/bsru6.h2
-rw-r--r--drivers/media/dvb/frontends/cx22700.c12
-rw-r--r--drivers/media/dvb/frontends/cx22700.h2
-rw-r--r--drivers/media/dvb/frontends/cx22702.c26
-rw-r--r--drivers/media/dvb/frontends/cx22702.h2
-rw-r--r--drivers/media/dvb/frontends/cx24110.c6
-rw-r--r--drivers/media/dvb/frontends/cx24110.h2
-rw-r--r--drivers/media/dvb/frontends/cx24113.h48
-rw-r--r--drivers/media/dvb/frontends/cx24123.c304
-rw-r--r--drivers/media/dvb/frontends/cx24123.h21
-rw-r--r--drivers/media/dvb/frontends/dib3000.h2
-rw-r--r--drivers/media/dvb/frontends/dib3000mc.h2
-rw-r--r--drivers/media/dvb/frontends/dib7000p.c8
-rw-r--r--drivers/media/dvb/frontends/dib7000p.h2
-rw-r--r--drivers/media/dvb/frontends/dvb-pll.c260
-rw-r--r--drivers/media/dvb/frontends/dvb-pll.h33
-rw-r--r--drivers/media/dvb/frontends/isl6405.c164
-rw-r--r--drivers/media/dvb/frontends/isl6405.h74
-rw-r--r--drivers/media/dvb/frontends/isl6421.h2
-rw-r--r--drivers/media/dvb/frontends/itd1000.c400
-rw-r--r--drivers/media/dvb/frontends/itd1000.h42
-rw-r--r--drivers/media/dvb/frontends/itd1000_priv.h88
-rw-r--r--drivers/media/dvb/frontends/l64781.c2
-rw-r--r--drivers/media/dvb/frontends/l64781.h2
-rw-r--r--drivers/media/dvb/frontends/lgdt330x.c40
-rw-r--r--drivers/media/dvb/frontends/lgdt330x.h2
-rw-r--r--drivers/media/dvb/frontends/lnbp21.h2
-rw-r--r--drivers/media/dvb/frontends/mt2060.h2
-rw-r--r--drivers/media/dvb/frontends/mt2131.c14
-rw-r--r--drivers/media/dvb/frontends/mt2131.h2
-rw-r--r--drivers/media/dvb/frontends/mt2266.h2
-rw-r--r--drivers/media/dvb/frontends/mt312.c151
-rw-r--r--drivers/media/dvb/frontends/mt312.h5
-rw-r--r--drivers/media/dvb/frontends/mt312_priv.h5
-rw-r--r--drivers/media/dvb/frontends/mt352.c8
-rw-r--r--drivers/media/dvb/frontends/mt352.h2
-rw-r--r--drivers/media/dvb/frontends/nxt200x.c26
-rw-r--r--drivers/media/dvb/frontends/nxt200x.h2
-rw-r--r--drivers/media/dvb/frontends/nxt6000.c2
-rw-r--r--drivers/media/dvb/frontends/nxt6000.h2
-rw-r--r--drivers/media/dvb/frontends/or51132.c6
-rw-r--r--drivers/media/dvb/frontends/or51132.h2
-rw-r--r--drivers/media/dvb/frontends/or51211.c6
-rw-r--r--drivers/media/dvb/frontends/or51211.h2
-rw-r--r--drivers/media/dvb/frontends/qt1010.h2
-rw-r--r--drivers/media/dvb/frontends/s5h1409.c50
-rw-r--r--drivers/media/dvb/frontends/s5h1409.h2
-rw-r--r--drivers/media/dvb/frontends/s5h1420.c523
-rw-r--r--drivers/media/dvb/frontends/s5h1420.h64
-rw-r--r--drivers/media/dvb/frontends/s5h1420_priv.h102
-rw-r--r--drivers/media/dvb/frontends/sp8870.c38
-rw-r--r--drivers/media/dvb/frontends/sp8870.h2
-rw-r--r--drivers/media/dvb/frontends/sp887x.c18
-rw-r--r--drivers/media/dvb/frontends/sp887x.h2
-rw-r--r--drivers/media/dvb/frontends/stv0297.c14
-rw-r--r--drivers/media/dvb/frontends/stv0297.h2
-rw-r--r--drivers/media/dvb/frontends/stv0299.c85
-rw-r--r--drivers/media/dvb/frontends/stv0299.h13
-rw-r--r--drivers/media/dvb/frontends/tda10021.c4
-rw-r--r--drivers/media/dvb/frontends/tda10023.c4
-rw-r--r--drivers/media/dvb/frontends/tda1002x.h4
-rw-r--r--drivers/media/dvb/frontends/tda10048.c841
-rw-r--r--drivers/media/dvb/frontends/tda10048.h63
-rw-r--r--drivers/media/dvb/frontends/tda1004x.c56
-rw-r--r--drivers/media/dvb/frontends/tda1004x.h5
-rw-r--r--drivers/media/dvb/frontends/tda10086.c147
-rw-r--r--drivers/media/dvb/frontends/tda10086.h14
-rw-r--r--drivers/media/dvb/frontends/tda18271-common.c57
-rw-r--r--drivers/media/dvb/frontends/tda18271-fe.c418
-rw-r--r--drivers/media/dvb/frontends/tda18271-priv.h18
-rw-r--r--drivers/media/dvb/frontends/tda18271-tables.c84
-rw-r--r--drivers/media/dvb/frontends/tda18271.h25
-rw-r--r--drivers/media/dvb/frontends/tda8083.c4
-rw-r--r--drivers/media/dvb/frontends/tda8083.h2
-rw-r--r--drivers/media/dvb/frontends/tda826x.c25
-rw-r--r--drivers/media/dvb/frontends/tda826x.h2
-rw-r--r--drivers/media/dvb/frontends/tda827x.c167
-rw-r--r--drivers/media/dvb/frontends/tda827x.h6
-rw-r--r--drivers/media/dvb/frontends/tua6100.c2
-rw-r--r--drivers/media/dvb/frontends/tua6100.h2
-rw-r--r--drivers/media/dvb/frontends/ves1820.c4
-rw-r--r--drivers/media/dvb/frontends/ves1820.h2
-rw-r--r--drivers/media/dvb/frontends/ves1x93.c8
-rw-r--r--drivers/media/dvb/frontends/ves1x93.h2
-rw-r--r--drivers/media/dvb/frontends/xc5000.c46
-rw-r--r--drivers/media/dvb/frontends/xc5000.h2
-rw-r--r--drivers/media/dvb/frontends/zl10353.c8
-rw-r--r--drivers/media/dvb/frontends/zl10353.h2
-rw-r--r--drivers/media/dvb/pluto2/pluto2.c5
-rw-r--r--drivers/media/dvb/ttpci/av7110.c16
-rw-r--r--drivers/media/dvb/ttpci/av7110.h2
-rw-r--r--drivers/media/dvb/ttpci/av7110_hw.c42
-rw-r--r--drivers/media/dvb/ttpci/av7110_ir.c6
-rw-r--r--drivers/media/dvb/ttpci/av7110_v4l.c4
-rw-r--r--drivers/media/dvb/ttpci/budget-av.c16
-rw-r--r--drivers/media/dvb/ttpci/budget-ci.c6
-rw-r--r--drivers/media/dvb/ttpci/budget-core.c9
-rw-r--r--drivers/media/dvb/ttpci/budget.c111
-rw-r--r--drivers/media/dvb/ttpci/budget.h3
-rw-r--r--drivers/media/dvb/ttpci/ttpci-eeprom.c2
-rw-r--r--drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c58
-rw-r--r--drivers/media/dvb/ttusb-dec/ttusb_dec.c112
-rw-r--r--drivers/media/dvb/ttusb-dec/ttusbdecfe.c4
-rw-r--r--drivers/media/radio/dsbr100.c2
-rw-r--r--drivers/media/radio/miropcm20-radio.c2
-rw-r--r--drivers/media/radio/miropcm20-rds.c2
-rw-r--r--drivers/media/radio/radio-aimslab.c2
-rw-r--r--drivers/media/radio/radio-aztech.c2
-rw-r--r--drivers/media/radio/radio-cadet.c12
-rw-r--r--drivers/media/radio/radio-gemtek-pci.c2
-rw-r--r--drivers/media/radio/radio-gemtek.c2
-rw-r--r--drivers/media/radio/radio-maestro.c2
-rw-r--r--drivers/media/radio/radio-maxiradio.c2
-rw-r--r--drivers/media/radio/radio-rtrack2.c2
-rw-r--r--drivers/media/radio/radio-sf16fmi.c2
-rw-r--r--drivers/media/radio/radio-sf16fmr2.c104
-rw-r--r--drivers/media/radio/radio-si470x.c59
-rw-r--r--drivers/media/radio/radio-terratec.c2
-rw-r--r--drivers/media/radio/radio-trust.c2
-rw-r--r--drivers/media/radio/radio-typhoon.c44
-rw-r--r--drivers/media/radio/radio-zoltrix.c2
-rw-r--r--drivers/media/video/Kconfig56
-rw-r--r--drivers/media/video/Makefile12
-rw-r--r--drivers/media/video/adv7170.c2
-rw-r--r--drivers/media/video/adv7175.c2
-rw-r--r--drivers/media/video/arv.c6
-rw-r--r--drivers/media/video/au0828/Kconfig12
-rw-r--r--drivers/media/video/au0828/Makefile9
-rw-r--r--drivers/media/video/au0828/au0828-cards.c182
-rw-r--r--drivers/media/video/au0828/au0828-cards.h25
-rw-r--r--drivers/media/video/au0828/au0828-core.c270
-rw-r--r--drivers/media/video/au0828/au0828-dvb.c373
-rw-r--r--drivers/media/video/au0828/au0828-i2c.c385
-rw-r--r--drivers/media/video/au0828/au0828-reg.h38
-rw-r--r--drivers/media/video/au0828/au0828.h128
-rw-r--r--drivers/media/video/bt819.c2
-rw-r--r--drivers/media/video/bt856.c2
-rw-r--r--drivers/media/video/bt8xx/bttv-cards.c55
-rw-r--r--drivers/media/video/bt8xx/bttv-driver.c36
-rw-r--r--drivers/media/video/bt8xx/bttv-input.c6
-rw-r--r--drivers/media/video/bt8xx/bttv-vbi.c2
-rw-r--r--drivers/media/video/bt8xx/bttv.h3
-rw-r--r--drivers/media/video/bt8xx/bttvp.h1
-rw-r--r--drivers/media/video/bw-qcam.c6
-rw-r--r--drivers/media/video/c-qcam.c13
-rw-r--r--drivers/media/video/cafe_ccic.c4
-rw-r--r--drivers/media/video/cpia.c2
-rw-r--r--drivers/media/video/cpia.h4
-rw-r--r--drivers/media/video/cpia2/cpia2_core.c16
-rw-r--r--drivers/media/video/cpia2/cpia2_usb.c2
-rw-r--r--drivers/media/video/cpia2/cpia2_v4l.c2
-rw-r--r--drivers/media/video/cpia_usb.c2
-rw-r--r--drivers/media/video/cx23885/Kconfig2
-rw-r--r--drivers/media/video/cx23885/Makefile2
-rw-r--r--drivers/media/video/cx23885/cx23885-417.c1764
-rw-r--r--drivers/media/video/cx23885/cx23885-cards.c116
-rw-r--r--drivers/media/video/cx23885/cx23885-core.c310
-rw-r--r--drivers/media/video/cx23885/cx23885-dvb.c172
-rw-r--r--drivers/media/video/cx23885/cx23885-i2c.c46
-rw-r--r--drivers/media/video/cx23885/cx23885-video.c58
-rw-r--r--drivers/media/video/cx23885/cx23885.h27
-rw-r--r--drivers/media/video/cx25840/cx25840-core.c97
-rw-r--r--drivers/media/video/cx25840/cx25840-core.h2
-rw-r--r--drivers/media/video/cx25840/cx25840-firmware.c11
-rw-r--r--drivers/media/video/cx25840/cx25840-vbi.c6
-rw-r--r--drivers/media/video/cx88/Kconfig1
-rw-r--r--drivers/media/video/cx88/cx88-alsa.c14
-rw-r--r--drivers/media/video/cx88/cx88-blackbird.c18
-rw-r--r--drivers/media/video/cx88/cx88-cards.c585
-rw-r--r--drivers/media/video/cx88/cx88-core.c17
-rw-r--r--drivers/media/video/cx88/cx88-dvb.c260
-rw-r--r--drivers/media/video/cx88/cx88-i2c.c4
-rw-r--r--drivers/media/video/cx88/cx88-input.c15
-rw-r--r--drivers/media/video/cx88/cx88-mpeg.c20
-rw-r--r--drivers/media/video/cx88/cx88-tvaudio.c30
-rw-r--r--drivers/media/video/cx88/cx88-vbi.c2
-rw-r--r--drivers/media/video/cx88/cx88-video.c63
-rw-r--r--drivers/media/video/cx88/cx88.h14
-rw-r--r--drivers/media/video/dabfirmware.h7
-rw-r--r--drivers/media/video/dabusb.c8
-rw-r--r--drivers/media/video/dpc7146.c4
-rw-r--r--drivers/media/video/em28xx/Kconfig14
-rw-r--r--drivers/media/video/em28xx/Makefile1
-rw-r--r--drivers/media/video/em28xx/em28xx-audio.c2
-rw-r--r--drivers/media/video/em28xx/em28xx-cards.c207
-rw-r--r--drivers/media/video/em28xx/em28xx-core.c776
-rw-r--r--drivers/media/video/em28xx/em28xx-dvb.c474
-rw-r--r--drivers/media/video/em28xx/em28xx-i2c.c160
-rw-r--r--drivers/media/video/em28xx/em28xx-input.c26
-rw-r--r--drivers/media/video/em28xx/em28xx-reg.h88
-rw-r--r--drivers/media/video/em28xx/em28xx-video.c1078
-rw-r--r--drivers/media/video/em28xx/em28xx.h318
-rw-r--r--drivers/media/video/et61x251/et61x251.h6
-rw-r--r--drivers/media/video/et61x251/et61x251_core.c4
-rw-r--r--drivers/media/video/hexium_gemini.c4
-rw-r--r--drivers/media/video/hexium_orion.c4
-rw-r--r--drivers/media/video/ir-kbd-i2c.c28
-rw-r--r--drivers/media/video/ivtv/Kconfig1
-rw-r--r--drivers/media/video/ivtv/ivtv-cards.c7
-rw-r--r--drivers/media/video/ivtv/ivtv-cards.h2
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.c46
-rw-r--r--drivers/media/video/ivtv/ivtv-driver.h2
-rw-r--r--drivers/media/video/ivtv/ivtv-fileops.c6
-rw-r--r--drivers/media/video/ivtv/ivtv-i2c.c12
-rw-r--r--drivers/media/video/ivtv/ivtv-ioctl.c42
-rw-r--r--drivers/media/video/ivtv/ivtv-irq.c25
-rw-r--r--drivers/media/video/ivtv/ivtv-mailbox.c11
-rw-r--r--drivers/media/video/ivtv/ivtv-queue.c4
-rw-r--r--drivers/media/video/ivtv/ivtv-streams.c3
-rw-r--r--drivers/media/video/ivtv/ivtv-yuv.c38
-rw-r--r--drivers/media/video/meye.c1361
-rw-r--r--drivers/media/video/msp3400-driver.c4
-rw-r--r--drivers/media/video/msp3400-kthreads.c15
-rw-r--r--drivers/media/video/mt20xx.c7
-rw-r--r--drivers/media/video/mt20xx.h2
-rw-r--r--drivers/media/video/mt9m001.c722
-rw-r--r--drivers/media/video/mt9v022.c844
-rw-r--r--drivers/media/video/mxb.c4
-rw-r--r--drivers/media/video/ov511.c4
-rw-r--r--drivers/media/video/ov511.h2
-rw-r--r--drivers/media/video/ovcamchip/ovcamchip_priv.h4
-rw-r--r--drivers/media/video/pms.c6
-rw-r--r--drivers/media/video/pvrusb2/Kconfig24
-rw-r--r--drivers/media/video/pvrusb2/Makefile6
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-context.c306
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-context.h16
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-ctrl.c19
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c4
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-debug.h2
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-debugifc.c24
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-devattr.c270
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-devattr.h72
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-dvb.c425
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-dvb.h41
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-encoder.c19
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-fx2-cmd.h43
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h26
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw.c903
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-hdw.h39
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-i2c-core.c2
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-io.c30
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-io.h12
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-main.c16
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-std.c9
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-sysfs.c53
-rw-r--r--drivers/media/video/pvrusb2/pvrusb2-v4l2.c195
-rw-r--r--drivers/media/video/pwc/pwc-if.c16
-rw-r--r--drivers/media/video/pwc/pwc-v4l.c4
-rw-r--r--drivers/media/video/pxa_camera.c1206
-rw-r--r--drivers/media/video/saa5249.c2
-rw-r--r--drivers/media/video/saa6588.c8
-rw-r--r--drivers/media/video/saa7110.c2
-rw-r--r--drivers/media/video/saa7111.c2
-rw-r--r--drivers/media/video/saa7114.c2
-rw-r--r--drivers/media/video/saa7115.c4
-rw-r--r--drivers/media/video/saa711x.c2
-rw-r--r--drivers/media/video/saa7134/Kconfig1
-rw-r--r--drivers/media/video/saa7134/saa7134-alsa.c16
-rw-r--r--drivers/media/video/saa7134/saa7134-cards.c507
-rw-r--r--drivers/media/video/saa7134/saa7134-core.c52
-rw-r--r--drivers/media/video/saa7134/saa7134-dvb.c434
-rw-r--r--drivers/media/video/saa7134/saa7134-empress.c10
-rw-r--r--drivers/media/video/saa7134/saa7134-i2c.c6
-rw-r--r--drivers/media/video/saa7134/saa7134-input.c19
-rw-r--r--drivers/media/video/saa7134/saa7134-reg.h3
-rw-r--r--drivers/media/video/saa7134/saa7134-ts.c2
-rw-r--r--drivers/media/video/saa7134/saa7134-tvaudio.c21
-rw-r--r--drivers/media/video/saa7134/saa7134-vbi.c2
-rw-r--r--drivers/media/video/saa7134/saa7134-video.c17
-rw-r--r--drivers/media/video/saa7134/saa7134.h22
-rw-r--r--drivers/media/video/saa717x.c1516
-rw-r--r--drivers/media/video/saa7185.c2
-rw-r--r--drivers/media/video/se401.c12
-rw-r--r--drivers/media/video/sn9c102/sn9c102.h6
-rw-r--r--drivers/media/video/sn9c102/sn9c102_core.c12
-rw-r--r--drivers/media/video/sn9c102/sn9c102_sensor.h3
-rw-r--r--drivers/media/video/soc_camera.c1031
-rw-r--r--drivers/media/video/stk-webcam.c6
-rw-r--r--drivers/media/video/stradis.c6
-rw-r--r--drivers/media/video/stv680.c13
-rw-r--r--drivers/media/video/tcm825x.c2
-rw-r--r--drivers/media/video/tda8290.c18
-rw-r--r--drivers/media/video/tda8290.h6
-rw-r--r--drivers/media/video/tda9840.c4
-rw-r--r--drivers/media/video/tda9887.c42
-rw-r--r--drivers/media/video/tda9887.h2
-rw-r--r--drivers/media/video/tea5761.c22
-rw-r--r--drivers/media/video/tea5761.h4
-rw-r--r--drivers/media/video/tea5767.c39
-rw-r--r--drivers/media/video/tea5767.h4
-rw-r--r--drivers/media/video/tea6415c.c4
-rw-r--r--drivers/media/video/tea6420.c4
-rw-r--r--drivers/media/video/tuner-core.c55
-rw-r--r--drivers/media/video/tuner-i2c.h118
-rw-r--r--drivers/media/video/tuner-simple.c861
-rw-r--r--drivers/media/video/tuner-simple.h13
-rw-r--r--drivers/media/video/tuner-types.c188
-rw-r--r--drivers/media/video/tuner-xc2028-types.h23
-rw-r--r--drivers/media/video/tuner-xc2028.c165
-rw-r--r--drivers/media/video/tuner-xc2028.h6
-rw-r--r--drivers/media/video/tvaudio.c8
-rw-r--r--drivers/media/video/tveeprom.c103
-rw-r--r--drivers/media/video/tvp5150.c2
-rw-r--r--drivers/media/video/usbvideo/ibmcam.c64
-rw-r--r--drivers/media/video/usbvideo/konicawc.c4
-rw-r--r--drivers/media/video/usbvideo/quickcam_messenger.c4
-rw-r--r--drivers/media/video/usbvideo/ultracam.c4
-rw-r--r--drivers/media/video/usbvideo/usbvideo.c148
-rw-r--r--drivers/media/video/usbvideo/vicam.c4
-rw-r--r--drivers/media/video/usbvision/usbvision-core.c45
-rw-r--r--drivers/media/video/usbvision/usbvision-i2c.c8
-rw-r--r--drivers/media/video/usbvision/usbvision-video.c46
-rw-r--r--drivers/media/video/v4l1-compat.c1735
-rw-r--r--drivers/media/video/videobuf-core.c209
-rw-r--r--drivers/media/video/videobuf-dma-sg.c156
-rw-r--r--drivers/media/video/videobuf-dvb.c18
-rw-r--r--drivers/media/video/videobuf-vmalloc.c211
-rw-r--r--drivers/media/video/videocodec.c115
-rw-r--r--drivers/media/video/videodev.c74
-rw-r--r--drivers/media/video/vino.c10
-rw-r--r--drivers/media/video/vivi.c350
-rw-r--r--drivers/media/video/vpx3220.c2
-rw-r--r--drivers/media/video/w9966.c8
-rw-r--r--drivers/media/video/w9968cf.c4
-rw-r--r--drivers/media/video/w9968cf.h6
-rw-r--r--drivers/media/video/zc0301/zc0301.h6
-rw-r--r--drivers/media/video/zc0301/zc0301_core.c4
-rw-r--r--drivers/media/video/zoran.h16
-rw-r--r--drivers/media/video/zoran_card.c6
-rw-r--r--drivers/media/video/zoran_card.h2
-rw-r--r--drivers/media/video/zoran_device.c12
-rw-r--r--drivers/media/video/zoran_driver.c26
-rw-r--r--drivers/media/video/zr36016.c5
-rw-r--r--drivers/media/video/zr36050.c5
-rw-r--r--drivers/media/video/zr36060.c6
-rw-r--r--drivers/media/video/zr364xx.c4
-rw-r--r--drivers/mfd/htc-pasic3.c3
-rw-r--r--drivers/net/Kconfig2
-rw-r--r--drivers/net/ppp_generic.c48
-rw-r--r--drivers/net/tun.c21
-rw-r--r--drivers/net/wireless/Makefile3
-rw-r--r--drivers/net/wireless/ath5k/hw.c14
-rw-r--r--drivers/net/wireless/b43/dma.c47
-rw-r--r--drivers/net/wireless/b43/main.c32
-rw-r--r--drivers/net/wireless/b43/phy.c2
-rw-r--r--drivers/net/wireless/iwlwifi/iwl3945-base.c1
-rw-r--r--drivers/net/wireless/iwlwifi/iwl4965-base.c1
-rw-r--r--drivers/net/wireless/prism54/isl_ioctl.c2
-rw-r--r--drivers/net/wireless/rndis_wlan.c5
-rw-r--r--drivers/pcmcia/Kconfig2
-rw-r--r--drivers/serial/bfin_5xx.c56
-rw-r--r--drivers/serial/sunzilog.c30
-rw-r--r--drivers/ssb/pci.c5
-rw-r--r--fs/Kconfig179
-rw-r--r--fs/lockd/clntproc.c184
-rw-r--r--fs/lockd/host.c93
-rw-r--r--fs/lockd/mon.c113
-rw-r--r--fs/lockd/svc.c162
-rw-r--r--fs/lockd/svclock.c6
-rw-r--r--fs/lockd/svcshare.c3
-rw-r--r--fs/nfs/Makefile3
-rw-r--r--fs/nfs/callback.c93
-rw-r--r--fs/nfs/client.c23
-rw-r--r--fs/nfs/dir.c2
-rw-r--r--fs/nfs/direct.c88
-rw-r--r--fs/nfs/file.c18
-rw-r--r--fs/nfs/inode.c45
-rw-r--r--fs/nfs/internal.h13
-rw-r--r--fs/nfs/namespace.c2
-rw-r--r--fs/nfs/nfs2xdr.c113
-rw-r--r--fs/nfs/nfs3xdr.c71
-rw-r--r--fs/nfs/nfs4proc.c39
-rw-r--r--fs/nfs/nfs4state.c49
-rw-r--r--fs/nfs/nfs4xdr.c147
-rw-r--r--fs/nfs/read.c94
-rw-r--r--fs/nfs/super.c147
-rw-r--r--fs/nfs/symlink.c1
-rw-r--r--fs/nfs/unlink.c2
-rw-r--r--fs/nfs/write.c207
-rw-r--r--fs/nfsd/auth.c1
-rw-r--r--fs/nfsd/export.c9
-rw-r--r--fs/nfsd/nfs4callback.c28
-rw-r--r--fs/nfsd/nfs4idmap.c2
-rw-r--r--fs/nfsd/nfs4state.c71
-rw-r--r--fs/nfsd/nfs4xdr.c13
-rw-r--r--fs/nfsd/nfsctl.c22
-rw-r--r--fs/nfsd/nfsfh.c228
-rw-r--r--fs/nfsd/nfssvc.c2
-rw-r--r--fs/nfsd/vfs.c35
-rw-r--r--include/asm-blackfin/.gitignore1
-rw-r--r--include/asm-blackfin/bfin-global.h10
-rw-r--r--include/asm-blackfin/bug.h13
-rw-r--r--include/asm-blackfin/cplb.h26
-rw-r--r--include/asm-blackfin/dma-mapping.h15
-rw-r--r--include/asm-blackfin/dma.h3
-rw-r--r--include/asm-blackfin/gptimers.h150
-rw-r--r--include/asm-blackfin/mach-bf527/anomaly.h80
-rw-r--r--include/asm-blackfin/mach-bf527/bfin_serial_5xx.h48
-rw-r--r--include/asm-blackfin/mach-bf527/bfin_sir.h133
-rw-r--r--include/asm-blackfin/mach-bf527/blackfin.h15
-rw-r--r--include/asm-blackfin/mach-bf527/cdefBF52x_base.h90
-rw-r--r--include/asm-blackfin/mach-bf527/dma.h3
-rw-r--r--include/asm-blackfin/mach-bf533/anomaly.h10
-rw-r--r--include/asm-blackfin/mach-bf533/bfin_serial_5xx.h50
-rw-r--r--include/asm-blackfin/mach-bf533/bfin_sir.h120
-rw-r--r--include/asm-blackfin/mach-bf533/blackfin.h15
-rw-r--r--include/asm-blackfin/mach-bf533/cdefBF532.h31
-rw-r--r--include/asm-blackfin/mach-bf533/defBF532.h29
-rw-r--r--include/asm-blackfin/mach-bf533/dma.h3
-rw-r--r--include/asm-blackfin/mach-bf533/mem_init.h10
-rw-r--r--include/asm-blackfin/mach-bf537/anomaly.h17
-rw-r--r--include/asm-blackfin/mach-bf537/bfin_serial_5xx.h48
-rw-r--r--include/asm-blackfin/mach-bf537/bfin_sir.h133
-rw-r--r--include/asm-blackfin/mach-bf537/blackfin.h39
-rw-r--r--include/asm-blackfin/mach-bf537/cdefBF534.h65
-rw-r--r--include/asm-blackfin/mach-bf537/dma.h3
-rw-r--r--include/asm-blackfin/mach-bf548/anomaly.h1
-rw-r--r--include/asm-blackfin/mach-bf548/bfin_serial_5xx.h48
-rw-r--r--include/asm-blackfin/mach-bf548/bfin_sir.h149
-rw-r--r--include/asm-blackfin/mach-bf548/blackfin.h38
-rw-r--r--include/asm-blackfin/mach-bf548/cdefBF542.h12
-rw-r--r--include/asm-blackfin/mach-bf548/cdefBF544.h33
-rw-r--r--include/asm-blackfin/mach-bf548/cdefBF547.h33
-rw-r--r--include/asm-blackfin/mach-bf548/cdefBF548.h33
-rw-r--r--include/asm-blackfin/mach-bf548/cdefBF549.h35
-rw-r--r--include/asm-blackfin/mach-bf548/cdefBF54x_base.h418
-rw-r--r--include/asm-blackfin/mach-bf548/dma.h2
-rw-r--r--include/asm-blackfin/mach-bf548/mem_init.h20
-rw-r--r--include/asm-blackfin/mach-bf561/anomaly.h6
-rw-r--r--include/asm-blackfin/mach-bf561/bfin_serial_5xx.h50
-rw-r--r--include/asm-blackfin/mach-bf561/bfin_sir.h120
-rw-r--r--include/asm-blackfin/mach-bf561/blackfin.h14
-rw-r--r--include/asm-blackfin/mach-bf561/cdefBF561.h34
-rw-r--r--include/asm-blackfin/mach-bf561/defBF561.h31
-rw-r--r--include/asm-blackfin/mach-bf561/dma.h3
-rw-r--r--include/asm-blackfin/portmux.h4
-rw-r--r--include/asm-blackfin/processor.h5
-rw-r--r--include/asm-blackfin/signal.h2
-rw-r--r--include/asm-blackfin/thread_info.h11
-rw-r--r--include/asm-blackfin/time.h36
-rw-r--r--include/asm-blackfin/timex.h17
-rw-r--r--include/asm-blackfin/trace.h4
-rw-r--r--include/asm-blackfin/uaccess.h4
-rw-r--r--include/asm-blackfin/unistd.h26
-rw-r--r--include/asm-sparc/device.h2
-rw-r--r--include/asm-sparc/prom.h5
-rw-r--r--include/asm-sparc64/iommu.h3
-rw-r--r--include/asm-sparc64/mmzone.h17
-rw-r--r--include/asm-sparc64/numnodes.h6
-rw-r--r--include/asm-sparc64/ptrace.h18
-rw-r--r--include/asm-sparc64/sparsemem.h2
-rw-r--r--include/asm-sparc64/topology.h73
-rw-r--r--include/asm-sparc64/ttable.h14
-rw-r--r--include/linux/dvb/dmx.h3
-rw-r--r--include/linux/exportfs.h2
-rw-r--r--include/linux/i2c-id.h1
-rw-r--r--include/linux/ieee80211.h20
-rw-r--r--include/linux/lockd/lockd.h18
-rw-r--r--include/linux/lockd/sm_inter.h1
-rw-r--r--include/linux/meye.h2
-rw-r--r--include/linux/nfs3.h2
-rw-r--r--include/linux/nfs_fs.h5
-rw-r--r--include/linux/nfs_fs_sb.h10
-rw-r--r--include/linux/nfs_xdr.h10
-rw-r--r--include/linux/nfsd/Kbuild4
-rw-r--r--include/linux/nfsd/cache.h2
-rw-r--r--include/linux/nfsd/nfsd.h11
-rw-r--r--include/linux/rtnetlink.h4
-rw-r--r--include/linux/sunrpc/auth.h17
-rw-r--r--include/linux/sunrpc/auth_gss.h1
-rw-r--r--include/linux/sunrpc/cache.h1
-rw-r--r--include/linux/sunrpc/clnt.h9
-rw-r--r--include/linux/sunrpc/gss_krb5.h6
-rw-r--r--include/linux/sunrpc/sched.h41
-rw-r--r--include/linux/sunrpc/svc.h1
-rw-r--r--include/linux/sunrpc/svcauth.h5
-rw-r--r--include/linux/sunrpc/svcsock.h4
-rw-r--r--include/linux/sunrpc/xprt.h10
-rw-r--r--include/linux/videodev2.h55
-rw-r--r--include/media/ir-common.h3
-rw-r--r--include/media/soc_camera.h179
-rw-r--r--include/media/tuner-types.h17
-rw-r--r--include/media/tuner.h2
-rw-r--r--include/media/v4l2-chip-ident.h6
-rw-r--r--include/media/v4l2-dev.h4
-rw-r--r--include/media/videobuf-core.h24
-rw-r--r--include/media/videobuf-dma-sg.h17
-rw-r--r--include/media/videobuf-dvb.h3
-rw-r--r--include/media/videobuf-vmalloc.h4
-rw-r--r--include/net/ipv6.h9
-rw-r--r--include/sound/ac97_codec.h1
-rw-r--r--include/sound/ak4114.h1
-rw-r--r--include/sound/ak4xxx-adda.h2
-rw-r--r--include/sound/asoundef.h8
-rw-r--r--include/sound/control.h7
-rw-r--r--include/sound/core.h10
-rw-r--r--include/sound/mpu401.h15
-rw-r--r--include/sound/version.h4
-rw-r--r--lib/lmb.c2
-rw-r--r--net/core/rtnetlink.c6
-rw-r--r--net/ipv4/fib_hash.c17
-rw-r--r--net/ipv4/fib_trie.c18
-rw-r--r--net/ipv4/route.c11
-rw-r--r--net/ipv4/tcp_ipv4.c36
-rw-r--r--net/ipv4/udp.c15
-rw-r--r--net/mac80211/mlme.c28
-rw-r--r--net/mac80211/rx.c2
-rw-r--r--net/mac80211/wme.c2
-rw-r--r--net/rxrpc/rxkad.c2
-rw-r--r--net/sctp/objcnt.c9
-rw-r--r--net/sunrpc/Makefile2
-rw-r--r--net/sunrpc/auth.c71
-rw-r--r--net/sunrpc/auth_generic.c177
-rw-r--r--net/sunrpc/auth_gss/auth_gss.c105
-rw-r--r--net/sunrpc/auth_gss/gss_generic_token.c4
-rw-r--r--net/sunrpc/auth_gss/gss_krb5_crypto.c6
-rw-r--r--net/sunrpc/auth_gss/gss_krb5_seal.c9
-rw-r--r--net/sunrpc/auth_gss/gss_krb5_seqnum.c4
-rw-r--r--net/sunrpc/auth_gss/gss_krb5_unseal.c2
-rw-r--r--net/sunrpc/auth_gss/gss_krb5_wrap.c8
-rw-r--r--net/sunrpc/auth_gss/gss_spkm3_seal.c4
-rw-r--r--net/sunrpc/auth_gss/svcauth_gss.c9
-rw-r--r--net/sunrpc/auth_null.c3
-rw-r--r--net/sunrpc/auth_unix.c59
-rw-r--r--net/sunrpc/cache.c1
-rw-r--r--net/sunrpc/clnt.c50
-rw-r--r--net/sunrpc/rpcb_clnt.c2
-rw-r--r--net/sunrpc/sched.c264
-rw-r--r--net/sunrpc/svc.c25
-rw-r--r--net/sunrpc/svc_xprt.c30
-rw-r--r--net/sunrpc/svcauth_unix.c118
-rw-r--r--net/sunrpc/svcsock.c29
-rw-r--r--net/sunrpc/xprt.c80
-rw-r--r--net/sunrpc/xprtrdma/svc_rdma_transport.c2
-rw-r--r--net/sunrpc/xprtsock.c82
-rw-r--r--net/unix/af_unix.c6
-rw-r--r--sound/arm/pxa2xx-ac97.c34
-rw-r--r--sound/core/Kconfig4
-rw-r--r--sound/core/Makefile1
-rw-r--r--sound/core/init.c38
-rw-r--r--sound/core/misc.c4
-rw-r--r--sound/core/oss/mixer_oss.c2
-rw-r--r--sound/core/seq/oss/seq_oss_synth.c9
-rw-r--r--sound/core/vmaster.c (renamed from sound/pci/hda/vmaster.c)13
-rw-r--r--sound/drivers/Kconfig18
-rw-r--r--sound/drivers/Makefile2
-rw-r--r--sound/drivers/dummy.c37
-rw-r--r--sound/drivers/ml403-ac97cr.c6
-rw-r--r--sound/drivers/mpu401/mpu401_uart.c23
-rw-r--r--sound/drivers/pcsp/Makefile2
-rw-r--r--sound/drivers/pcsp/pcsp.c235
-rw-r--r--sound/drivers/pcsp/pcsp.h82
-rw-r--r--sound/drivers/pcsp/pcsp_input.c116
-rw-r--r--sound/drivers/pcsp/pcsp_input.h14
-rw-r--r--sound/drivers/pcsp/pcsp_lib.c338
-rw-r--r--sound/drivers/pcsp/pcsp_mixer.c143
-rw-r--r--sound/i2c/other/ak4114.c24
-rw-r--r--sound/i2c/other/ak4xxx-adda.c16
-rw-r--r--sound/isa/sb/sb16_csp.c28
-rw-r--r--sound/isa/sb/sb_common.c6
-rw-r--r--sound/oss/dmabuf.c4
-rw-r--r--sound/oss/trident.c12
-rw-r--r--sound/oss/trident.h2
-rw-r--r--sound/oss/vwsnd.c6
-rw-r--r--sound/pci/Kconfig22
-rw-r--r--sound/pci/Makefile1
-rw-r--r--sound/pci/ac97/ac97_patch.c46
-rw-r--r--sound/pci/ac97/ac97_pcm.c1
-rw-r--r--sound/pci/ad1889.c6
-rw-r--r--sound/pci/ali5451/ali5451.c32
-rw-r--r--sound/pci/als300.c4
-rw-r--r--sound/pci/atiixp.c2
-rw-r--r--sound/pci/atiixp_modem.c2
-rw-r--r--sound/pci/au88x0/au88x0.c2
-rw-r--r--sound/pci/au88x0/au88x0_pcm.c10
-rw-r--r--sound/pci/aw2/Makefile3
-rw-r--r--sound/pci/aw2/aw2-alsa.c794
-rw-r--r--sound/pci/aw2/aw2-saa7146.c465
-rw-r--r--sound/pci/aw2/aw2-saa7146.h105
-rw-r--r--sound/pci/aw2/aw2-tsl.c110
-rw-r--r--sound/pci/aw2/saa7146.h168
-rw-r--r--sound/pci/azt3328.c7
-rw-r--r--sound/pci/ca0106/ca0106_main.c21
-rw-r--r--sound/pci/ca0106/ca0106_mixer.c59
-rw-r--r--sound/pci/cmipci.c13
-rw-r--r--sound/pci/cs46xx/cs46xx_lib.c6
-rw-r--r--sound/pci/echoaudio/echoaudio.c7
-rw-r--r--sound/pci/emu10k1/emu10k1_main.c15
-rw-r--r--sound/pci/emu10k1/emu10k1x.c30
-rw-r--r--sound/pci/emu10k1/emuproc.c2
-rw-r--r--sound/pci/ens1370.c9
-rw-r--r--sound/pci/es1938.c5
-rw-r--r--sound/pci/es1968.c42
-rw-r--r--sound/pci/fm801.c8
-rw-r--r--sound/pci/hda/Makefile2
-rw-r--r--sound/pci/hda/hda_codec.c201
-rw-r--r--sound/pci/hda/hda_codec.h13
-rw-r--r--sound/pci/hda/hda_generic.c4
-rw-r--r--sound/pci/hda/hda_intel.c459
-rw-r--r--sound/pci/hda/hda_local.h20
-rw-r--r--sound/pci/hda/hda_patch.h28
-rw-r--r--sound/pci/hda/patch_analog.c581
-rw-r--r--sound/pci/hda/patch_atihdmi.c8
-rw-r--r--sound/pci/hda/patch_cmedia.c13
-rw-r--r--sound/pci/hda/patch_conexant.c68
-rw-r--r--sound/pci/hda/patch_realtek.c1248
-rw-r--r--sound/pci/hda/patch_si3054.c4
-rw-r--r--sound/pci/hda/patch_sigmatel.c391
-rw-r--r--sound/pci/hda/patch_via.c14
-rw-r--r--sound/pci/ice1712/delta.c22
-rw-r--r--sound/pci/ice1712/delta.h2
-rw-r--r--sound/pci/ice1712/ews.c15
-rw-r--r--sound/pci/ice1712/ews.h4
-rw-r--r--sound/pci/ice1712/hoontech.c21
-rw-r--r--sound/pci/ice1712/ice1712.c45
-rw-r--r--sound/pci/ice1712/ice1712.h17
-rw-r--r--sound/pci/ice1712/ice1724.c431
-rw-r--r--sound/pci/ice1712/juli.c486
-rw-r--r--sound/pci/ice1712/pontis.c4
-rw-r--r--sound/pci/ice1712/prodigy192.c37
-rw-r--r--sound/pci/ice1712/revo.c55
-rw-r--r--sound/pci/intel8x0.c33
-rw-r--r--sound/pci/intel8x0m.c9
-rw-r--r--sound/pci/korg1212/korg1212.c1
-rw-r--r--sound/pci/maestro3.c38
-rw-r--r--sound/pci/nm256/nm256.c4
-rw-r--r--sound/pci/oxygen/cs4362a.h69
-rw-r--r--sound/pci/oxygen/cs4398.h69
-rw-r--r--sound/pci/oxygen/hifier.c36
-rw-r--r--sound/pci/oxygen/oxygen.c129
-rw-r--r--sound/pci/oxygen/oxygen.h23
-rw-r--r--sound/pci/oxygen/oxygen_io.c23
-rw-r--r--sound/pci/oxygen/oxygen_lib.c113
-rw-r--r--sound/pci/oxygen/oxygen_mixer.c217
-rw-r--r--sound/pci/oxygen/oxygen_pcm.c78
-rw-r--r--sound/pci/oxygen/pcm1796.h58
-rw-r--r--sound/pci/oxygen/virtuoso.c594
-rw-r--r--sound/pci/oxygen/wm8785.h45
-rw-r--r--sound/pci/pcxhr/pcxhr.c7
-rw-r--r--sound/pci/pcxhr/pcxhr_core.c33
-rw-r--r--sound/pci/riptide/riptide.c14
-rw-r--r--sound/pci/rme32.c3
-rw-r--r--sound/pci/rme96.c3
-rw-r--r--sound/pci/rme9652/hdsp.c54
-rw-r--r--sound/pci/rme9652/hdspm.c19
-rw-r--r--sound/pci/sis7019.c1
-rw-r--r--sound/pci/trident/trident_main.c4
-rw-r--r--sound/pci/via82xx.c2
-rw-r--r--sound/pci/via82xx_modem.c2
-rw-r--r--sound/pci/ymfpci/ymfpci_main.c4
-rw-r--r--sound/ppc/awacs.c265
-rw-r--r--sound/ppc/awacs.h21
-rw-r--r--sound/ppc/burgundy.c465
-rw-r--r--sound/ppc/burgundy.h31
-rw-r--r--sound/ppc/pmac.c10
-rw-r--r--sound/soc/Kconfig1
-rw-r--r--sound/soc/Makefile2
-rw-r--r--sound/soc/codecs/Kconfig4
-rw-r--r--sound/soc/codecs/Makefile2
-rw-r--r--sound/soc/codecs/ac97.c16
-rw-r--r--sound/soc/codecs/cs4270.c2
-rw-r--r--sound/soc/codecs/tlv320aic3x.c22
-rw-r--r--sound/soc/codecs/wm8731.c23
-rw-r--r--sound/soc/codecs/wm8750.c27
-rw-r--r--sound/soc/codecs/wm8753.c5
-rw-r--r--sound/soc/codecs/wm9712.c8
-rw-r--r--sound/soc/codecs/wm9713.c1300
-rw-r--r--sound/soc/codecs/wm9713.h53
-rw-r--r--sound/soc/davinci/Kconfig19
-rw-r--r--sound/soc/davinci/Makefile11
-rw-r--r--sound/soc/davinci/davinci-evm.c208
-rw-r--r--sound/soc/davinci/davinci-i2s.c407
-rw-r--r--sound/soc/davinci/davinci-i2s.h17
-rw-r--r--sound/soc/davinci/davinci-pcm.c389
-rw-r--r--sound/soc/davinci/davinci-pcm.h29
-rw-r--r--sound/soc/fsl/fsl_dma.c1
-rw-r--r--sound/soc/fsl/fsl_ssi.c1
-rw-r--r--sound/soc/pxa/corgi.c11
-rw-r--r--sound/soc/pxa/poodle.c8
-rw-r--r--sound/soc/pxa/pxa2xx-ac97.c37
-rw-r--r--sound/soc/pxa/pxa2xx-pcm.c9
-rw-r--r--sound/soc/pxa/spitz.c6
-rw-r--r--sound/soc/s3c24xx/neo1973_wm8753.c1
-rw-r--r--sound/soc/s3c24xx/s3c24xx-i2s.c41
-rw-r--r--sound/soc/s3c24xx/s3c24xx-pcm.c30
-rw-r--r--sound/soc/sh/Kconfig1
-rw-r--r--sound/soc/soc-core.c2
-rw-r--r--sound/soc/soc-dapm.c7
-rw-r--r--sound/spi/at73c213.c44
-rw-r--r--sound/usb/caiaq/caiaq-audio.c81
-rw-r--r--sound/usb/caiaq/caiaq-device.c4
-rw-r--r--sound/usb/usbaudio.c98
-rw-r--r--sound/usb/usbquirks.h75
932 files changed, 51866 insertions, 13926 deletions
diff --git a/CREDITS b/CREDITS
index da0a56e23bee..8fec7b3f96d5 100644
--- a/CREDITS
+++ b/CREDITS
@@ -403,6 +403,8 @@ D: Linux CD and Support Giveaway List
403N: Erik Inge Bolsø 403N: Erik Inge Bolsø
404E: knan@mo.himolde.no 404E: knan@mo.himolde.no
405D: Misc kernel hacks 405D: Misc kernel hacks
406D: Updated PC speaker driver for 2.3
407S: Norway
406 408
407N: Andreas E. Bombe 409N: Andreas E. Bombe
408E: andreas.bombe@munich.netsurf.de 410E: andreas.bombe@munich.netsurf.de
@@ -3116,6 +3118,12 @@ S: Post Office Box 64132
3116S: Sunnyvale, California 94088-4132 3118S: Sunnyvale, California 94088-4132
3117S: USA 3119S: USA
3118 3120
3121N: Stas Sergeev
3122E: stsp@users.sourceforge.net
3123D: PCM PC-Speaker driver
3124D: misc fixes
3125S: Russia
3126
3119N: Simon Shapiro 3127N: Simon Shapiro
3120E: shimon@i-Connect.Net 3128E: shimon@i-Connect.Net
3121W: http://www.-i-Connect.Net/~shimon 3129W: http://www.-i-Connect.Net/~shimon
diff --git a/Documentation/filesystems/nfs-rdma.txt b/Documentation/filesystems/nfs-rdma.txt
new file mode 100644
index 000000000000..1ae34879574b
--- /dev/null
+++ b/Documentation/filesystems/nfs-rdma.txt
@@ -0,0 +1,252 @@
1################################################################################
2# #
3# NFS/RDMA README #
4# #
5################################################################################
6
7 Author: NetApp and Open Grid Computing
8 Date: February 25, 2008
9
10Table of Contents
11~~~~~~~~~~~~~~~~~
12 - Overview
13 - Getting Help
14 - Installation
15 - Check RDMA and NFS Setup
16 - NFS/RDMA Setup
17
18Overview
19~~~~~~~~
20
21 This document describes how to install and setup the Linux NFS/RDMA client
22 and server software.
23
24 The NFS/RDMA client was first included in Linux 2.6.24. The NFS/RDMA server
25 was first included in the following release, Linux 2.6.25.
26
27 In our testing, we have obtained excellent performance results (full 10Gbit
28 wire bandwidth at minimal client CPU) under many workloads. The code passes
29 the full Connectathon test suite and operates over both Infiniband and iWARP
30 RDMA adapters.
31
32Getting Help
33~~~~~~~~~~~~
34
35 If you get stuck, you can ask questions on the
36
37 nfs-rdma-devel@lists.sourceforge.net
38
39 mailing list.
40
41Installation
42~~~~~~~~~~~~
43
44 These instructions are a step by step guide to building a machine for
45 use with NFS/RDMA.
46
47 - Install an RDMA device
48
49 Any device supported by the drivers in drivers/infiniband/hw is acceptable.
50
51 Testing has been performed using several Mellanox-based IB cards, the
52 Ammasso AMS1100 iWARP adapter, and the Chelsio cxgb3 iWARP adapter.
53
54 - Install a Linux distribution and tools
55
56 The first kernel release to contain both the NFS/RDMA client and server was
57 Linux 2.6.25 Therefore, a distribution compatible with this and subsequent
58 Linux kernel release should be installed.
59
60 The procedures described in this document have been tested with
61 distributions from Red Hat's Fedora Project (http://fedora.redhat.com/).
62
63 - Install nfs-utils-1.1.1 or greater on the client
64
65 An NFS/RDMA mount point can only be obtained by using the mount.nfs
66 command in nfs-utils-1.1.1 or greater. To see which version of mount.nfs
67 you are using, type:
68
69 > /sbin/mount.nfs -V
70
71 If the version is less than 1.1.1 or the command does not exist,
72 then you will need to install the latest version of nfs-utils.
73
74 Download the latest package from:
75
76 http://www.kernel.org/pub/linux/utils/nfs
77
78 Uncompress the package and follow the installation instructions.
79
80 If you will not be using GSS and NFSv4, the installation process
81 can be simplified by disabling these features when running configure:
82
83 > ./configure --disable-gss --disable-nfsv4
84
85 For more information on this see the package's README and INSTALL files.
86
87 After building the nfs-utils package, there will be a mount.nfs binary in
88 the utils/mount directory. This binary can be used to initiate NFS v2, v3,
89 or v4 mounts. To initiate a v4 mount, the binary must be called mount.nfs4.
90 The standard technique is to create a symlink called mount.nfs4 to mount.nfs.
91
92 NOTE: mount.nfs and therefore nfs-utils-1.1.1 or greater is only needed
93 on the NFS client machine. You do not need this specific version of
94 nfs-utils on the server. Furthermore, only the mount.nfs command from
95 nfs-utils-1.1.1 is needed on the client.
96
97 - Install a Linux kernel with NFS/RDMA
98
99 The NFS/RDMA client and server are both included in the mainline Linux
100 kernel version 2.6.25 and later. This and other versions of the 2.6 Linux
101 kernel can be found at:
102
103 ftp://ftp.kernel.org/pub/linux/kernel/v2.6/
104
105 Download the sources and place them in an appropriate location.
106
107 - Configure the RDMA stack
108
109 Make sure your kernel configuration has RDMA support enabled. Under
110 Device Drivers -> InfiniBand support, update the kernel configuration
111 to enable InfiniBand support [NOTE: the option name is misleading. Enabling
112 InfiniBand support is required for all RDMA devices (IB, iWARP, etc.)].
113
114 Enable the appropriate IB HCA support (mlx4, mthca, ehca, ipath, etc.) or
115 iWARP adapter support (amso, cxgb3, etc.).
116
117 If you are using InfiniBand, be sure to enable IP-over-InfiniBand support.
118
119 - Configure the NFS client and server
120
121 Your kernel configuration must also have NFS file system support and/or
122 NFS server support enabled. These and other NFS related configuration
123 options can be found under File Systems -> Network File Systems.
124
125 - Build, install, reboot
126
127 The NFS/RDMA code will be enabled automatically if NFS and RDMA
128 are turned on. The NFS/RDMA client and server are configured via the hidden
129 SUNRPC_XPRT_RDMA config option that depends on SUNRPC and INFINIBAND. The
130 value of SUNRPC_XPRT_RDMA will be:
131
132 - N if either SUNRPC or INFINIBAND are N, in this case the NFS/RDMA client
133 and server will not be built
134 - M if both SUNRPC and INFINIBAND are on (M or Y) and at least one is M,
135 in this case the NFS/RDMA client and server will be built as modules
136 - Y if both SUNRPC and INFINIBAND are Y, in this case the NFS/RDMA client
137 and server will be built into the kernel
138
139 Therefore, if you have followed the steps above and turned no NFS and RDMA,
140 the NFS/RDMA client and server will be built.
141
142 Build a new kernel, install it, boot it.
143
144Check RDMA and NFS Setup
145~~~~~~~~~~~~~~~~~~~~~~~~
146
147 Before configuring the NFS/RDMA software, it is a good idea to test
148 your new kernel to ensure that the kernel is working correctly.
149 In particular, it is a good idea to verify that the RDMA stack
150 is functioning as expected and standard NFS over TCP/IP and/or UDP/IP
151 is working properly.
152
153 - Check RDMA Setup
154
155 If you built the RDMA components as modules, load them at
156 this time. For example, if you are using a Mellanox Tavor/Sinai/Arbel
157 card:
158
159 > modprobe ib_mthca
160 > modprobe ib_ipoib
161
162 If you are using InfiniBand, make sure there is a Subnet Manager (SM)
163 running on the network. If your IB switch has an embedded SM, you can
164 use it. Otherwise, you will need to run an SM, such as OpenSM, on one
165 of your end nodes.
166
167 If an SM is running on your network, you should see the following:
168
169 > cat /sys/class/infiniband/driverX/ports/1/state
170 4: ACTIVE
171
172 where driverX is mthca0, ipath5, ehca3, etc.
173
174 To further test the InfiniBand software stack, use IPoIB (this
175 assumes you have two IB hosts named host1 and host2):
176
177 host1> ifconfig ib0 a.b.c.x
178 host2> ifconfig ib0 a.b.c.y
179 host1> ping a.b.c.y
180 host2> ping a.b.c.x
181
182 For other device types, follow the appropriate procedures.
183
184 - Check NFS Setup
185
186 For the NFS components enabled above (client and/or server),
187 test their functionality over standard Ethernet using TCP/IP or UDP/IP.
188
189NFS/RDMA Setup
190~~~~~~~~~~~~~~
191
192 We recommend that you use two machines, one to act as the client and
193 one to act as the server.
194
195 One time configuration:
196
197 - On the server system, configure the /etc/exports file and
198 start the NFS/RDMA server.
199
200 Exports entries with the following format have been tested:
201
202 /vol0 10.97.103.47(rw,async) 192.168.0.47(rw,async,insecure,no_root_squash)
203
204 Here the first IP address is the client's Ethernet address and the second
205 IP address is the clients IPoIB address.
206
207 Each time a machine boots:
208
209 - Load and configure the RDMA drivers
210
211 For InfiniBand using a Mellanox adapter:
212
213 > modprobe ib_mthca
214 > modprobe ib_ipoib
215 > ifconfig ib0 a.b.c.d
216
217 NOTE: use unique addresses for the client and server
218
219 - Start the NFS server
220
221 If the NFS/RDMA server was built as a module (CONFIG_SUNRPC_XPRT_RDMA=m in kernel config),
222 load the RDMA transport module:
223
224 > modprobe svcrdma
225
226 Regardless of how the server was built (module or built-in), start the server:
227
228 > /etc/init.d/nfs start
229
230 or
231
232 > service nfs start
233
234 Instruct the server to listen on the RDMA transport:
235
236 > echo rdma 2050 > /proc/fs/nfsd/portlist
237
238 - On the client system
239
240 If the NFS/RDMA client was built as a module (CONFIG_SUNRPC_XPRT_RDMA=m in kernel config),
241 load the RDMA client module:
242
243 > modprobe xprtrdma.ko
244
245 Regardless of how the client was built (module or built-in), issue the mount.nfs command:
246
247 > /path/to/your/mount.nfs <IPoIB-server-name-or-address>:/<export> /mnt -i -o rdma,port=2050
248
249 To verify that the mount is using RDMA, run "cat /proc/mounts" and check the
250 "proto" field for the given mount.
251
252 Congratulations! You're using NFS/RDMA!
diff --git a/Documentation/sound/alsa/ALSA-Configuration.txt b/Documentation/sound/alsa/ALSA-Configuration.txt
index e985cf5e0410..fd4c32a031c9 100644
--- a/Documentation/sound/alsa/ALSA-Configuration.txt
+++ b/Documentation/sound/alsa/ALSA-Configuration.txt
@@ -284,6 +284,13 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
284 control correctly. If you have problems regarding this, try 284 control correctly. If you have problems regarding this, try
285 another ALSA compliant mixer (alsamixer works). 285 another ALSA compliant mixer (alsamixer works).
286 286
287 Module snd-aw2
288 --------------
289
290 Module for Audiowerk2 sound card
291
292 This module supports multiple cards.
293
287 Module snd-azt2320 294 Module snd-azt2320
288 ------------------ 295 ------------------
289 296
@@ -818,19 +825,25 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
818 hippo_1 Hippo (Benq) with jack detection 825 hippo_1 Hippo (Benq) with jack detection
819 sony-assamd Sony ASSAMD 826 sony-assamd Sony ASSAMD
820 ultra Samsung Q1 Ultra Vista model 827 ultra Samsung Q1 Ultra Vista model
828 lenovo-3000 Lenovo 3000 y410
821 basic fixed pin assignment w/o SPDIF 829 basic fixed pin assignment w/o SPDIF
822 auto auto-config reading BIOS (default) 830 auto auto-config reading BIOS (default)
823 831
824 ALC268 832 ALC267/268
833 quanta-il1 Quanta IL1 mini-notebook
825 3stack 3-stack model 834 3stack 3-stack model
826 toshiba Toshiba A205 835 toshiba Toshiba A205
827 acer Acer laptops 836 acer Acer laptops
828 dell Dell OEM laptops (Vostro 1200) 837 dell Dell OEM laptops (Vostro 1200)
838 zepto Zepto laptops
829 test for testing/debugging purpose, almost all controls can 839 test for testing/debugging purpose, almost all controls can
830 adjusted. Appearing only when compiled with 840 adjusted. Appearing only when compiled with
831 $CONFIG_SND_DEBUG=y 841 $CONFIG_SND_DEBUG=y
832 auto auto-config reading BIOS (default) 842 auto auto-config reading BIOS (default)
833 843
844 ALC269
845 basic Basic preset
846
834 ALC662 847 ALC662
835 3stack-dig 3-stack (2-channel) with SPDIF 848 3stack-dig 3-stack (2-channel) with SPDIF
836 3stack-6ch 3-stack (6-channel) 849 3stack-6ch 3-stack (6-channel)
@@ -871,10 +884,11 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
871 lenovo-nb0763 Lenovo NB0763 884 lenovo-nb0763 Lenovo NB0763
872 lenovo-ms7195-dig Lenovo MS7195 885 lenovo-ms7195-dig Lenovo MS7195
873 haier-w66 Haier W66 886 haier-w66 Haier W66
874 6stack-hp HP machines with 6stack (Nettle boards)
875 3stack-hp HP machines with 3stack (Lucknow, Samba boards) 887 3stack-hp HP machines with 3stack (Lucknow, Samba boards)
876 6stack-dell Dell machines with 6stack (Inspiron 530) 888 6stack-dell Dell machines with 6stack (Inspiron 530)
877 mitac Mitac 8252D 889 mitac Mitac 8252D
890 clevo-m720 Clevo M720 laptop series
891 fujitsu-pi2515 Fujitsu AMILO Pi2515
878 auto auto-config reading BIOS (default) 892 auto auto-config reading BIOS (default)
879 893
880 ALC861/660 894 ALC861/660
@@ -911,6 +925,12 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
911 3stack 3-stack mode (default) 925 3stack 3-stack mode (default)
912 6stack 6-stack mode 926 6stack 6-stack mode
913 927
928 AD1884A / AD1883 / AD1984A / AD1984B
929 desktop 3-stack desktop (default)
930 laptop laptop with HP jack sensing
931 mobile mobile devices with HP jack sensing
932 thinkpad Lenovo Thinkpad X300
933
914 AD1884 934 AD1884
915 N/A 935 N/A
916 936
@@ -936,7 +956,7 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
936 laptop-automute 2-channel with EAPD and HP-automute (Lenovo N100) 956 laptop-automute 2-channel with EAPD and HP-automute (Lenovo N100)
937 ultra 2-channel with EAPD (Samsung Ultra tablet PC) 957 ultra 2-channel with EAPD (Samsung Ultra tablet PC)
938 958
939 AD1988 959 AD1988/AD1988B/AD1989A/AD1989B
940 6stack 6-jack 960 6stack 6-jack
941 6stack-dig ditto with SPDIF 961 6stack-dig ditto with SPDIF
942 3stack 3-jack 962 3stack 3-jack
@@ -979,6 +999,7 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
979 dell-m26 Dell Inspiron 1501 999 dell-m26 Dell Inspiron 1501
980 dell-m27 Dell Inspiron E1705/9400 1000 dell-m27 Dell Inspiron E1705/9400
981 gateway Gateway laptops with EAPD control 1001 gateway Gateway laptops with EAPD control
1002 panasonic Panasonic CF-74
982 1003
983 STAC9205/9254 1004 STAC9205/9254
984 ref Reference board 1005 ref Reference board
@@ -1017,6 +1038,16 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
1017 3stack D965 3stack 1038 3stack D965 3stack
1018 5stack D965 5stack + SPDIF 1039 5stack D965 5stack + SPDIF
1019 dell-3stack Dell Dimension E520 1040 dell-3stack Dell Dimension E520
1041 dell-bios Fixes with Dell BIOS setup
1042
1043 STAC92HD71B*
1044 ref Reference board
1045 dell-m4-1 Dell desktops
1046 dell-m4-2 Dell desktops
1047
1048 STAC92HD73*
1049 ref Reference board
1050 dell-m6 Dell desktops
1020 1051
1021 STAC9872 1052 STAC9872
1022 vaio Setup for VAIO FE550G/SZ110 1053 vaio Setup for VAIO FE550G/SZ110
@@ -1590,6 +1621,16 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
1590 1621
1591 Power management is _not_ supported. 1622 Power management is _not_ supported.
1592 1623
1624 Module snd-pcsp
1625 -----------------
1626
1627 Module for internal PC-Speaker.
1628
1629 nforce_wa - enable NForce chipset workaround. Expect bad sound.
1630
1631 This module supports system beeps, some kind of PCM playback and
1632 even a few mixer controls.
1633
1593 Module snd-pcxhr 1634 Module snd-pcxhr
1594 ---------------- 1635 ----------------
1595 1636
diff --git a/Documentation/video4linux/CARDLIST.au0828 b/Documentation/video4linux/CARDLIST.au0828
new file mode 100644
index 000000000000..aaae360312e4
--- /dev/null
+++ b/Documentation/video4linux/CARDLIST.au0828
@@ -0,0 +1,4 @@
1 0 -> Unknown board (au0828)
2 1 -> Hauppauge HVR950Q (au0828) [2040:7200]
3 2 -> Hauppauge HVR850 (au0828) [2040:7240]
4 3 -> DViCO FusionHDTV USB (au0828) [0fe9:d620]
diff --git a/Documentation/video4linux/CARDLIST.bttv b/Documentation/video4linux/CARDLIST.bttv
index d97cf7cc6088..f32efb6fb12c 100644
--- a/Documentation/video4linux/CARDLIST.bttv
+++ b/Documentation/video4linux/CARDLIST.bttv
@@ -148,3 +148,5 @@
148147 -> VoodooTV 200 (USA) [121a:3000] 148147 -> VoodooTV 200 (USA) [121a:3000]
149148 -> DViCO FusionHDTV 2 [dbc0:d200] 149148 -> DViCO FusionHDTV 2 [dbc0:d200]
150149 -> Typhoon TV-Tuner PCI (50684) 150149 -> Typhoon TV-Tuner PCI (50684)
151150 -> Geovision GV-600 [008a:763c]
152151 -> Kozumi KTV-01C
diff --git a/Documentation/video4linux/CARDLIST.cx23885 b/Documentation/video4linux/CARDLIST.cx23885
index 0924e6e142c4..929b90c8387f 100644
--- a/Documentation/video4linux/CARDLIST.cx23885
+++ b/Documentation/video4linux/CARDLIST.cx23885
@@ -5,3 +5,6 @@
5 4 -> DViCO FusionHDTV5 Express [18ac:d500] 5 4 -> DViCO FusionHDTV5 Express [18ac:d500]
6 5 -> Hauppauge WinTV-HVR1500Q [0070:7790,0070:7797] 6 5 -> Hauppauge WinTV-HVR1500Q [0070:7790,0070:7797]
7 6 -> Hauppauge WinTV-HVR1500 [0070:7710,0070:7717] 7 6 -> Hauppauge WinTV-HVR1500 [0070:7710,0070:7717]
8 7 -> Hauppauge WinTV-HVR1200 [0070:71d1]
9 8 -> Hauppauge WinTV-HVR1700 [0070:8101]
10 9 -> Hauppauge WinTV-HVR1400 [0070:8010]
diff --git a/Documentation/video4linux/CARDLIST.cx88 b/Documentation/video4linux/CARDLIST.cx88
index bc5593bd9704..543957346469 100644
--- a/Documentation/video4linux/CARDLIST.cx88
+++ b/Documentation/video4linux/CARDLIST.cx88
@@ -57,3 +57,12 @@
57 56 -> Hauppauge WinTV-HVR1300 DVB-T/Hybrid MPEG Encoder [0070:9600,0070:9601,0070:9602] 57 56 -> Hauppauge WinTV-HVR1300 DVB-T/Hybrid MPEG Encoder [0070:9600,0070:9601,0070:9602]
58 57 -> ADS Tech Instant Video PCI [1421:0390] 58 57 -> ADS Tech Instant Video PCI [1421:0390]
59 58 -> Pinnacle PCTV HD 800i [11bd:0051] 59 58 -> Pinnacle PCTV HD 800i [11bd:0051]
60 59 -> DViCO FusionHDTV 5 PCI nano [18ac:d530]
61 60 -> Pinnacle Hybrid PCTV [12ab:1788]
62 61 -> Winfast TV2000 XP Global [107d:6f18]
63 62 -> PowerColor Real Angel 330 [14f1:ea3d]
64 63 -> Geniatech X8000-MT DVBT [14f1:8852]
65 64 -> DViCO FusionHDTV DVB-T PRO [18ac:db30]
66 65 -> DViCO FusionHDTV 7 Gold [18ac:d610]
67 66 -> Prolink Pixelview MPEG 8000GT [1554:4935]
68 67 -> Kworld PlusTV HD PCI 120 (ATSC 120) [17de:08c1]
diff --git a/Documentation/video4linux/CARDLIST.saa7134 b/Documentation/video4linux/CARDLIST.saa7134
index 0424901ebc78..44d84dd15ad6 100644
--- a/Documentation/video4linux/CARDLIST.saa7134
+++ b/Documentation/video4linux/CARDLIST.saa7134
@@ -25,8 +25,8 @@
25 24 -> KNC One TV-Station DVR [1894:a006] 25 24 -> KNC One TV-Station DVR [1894:a006]
26 25 -> ASUS TV-FM 7133 [1043:4843] 26 25 -> ASUS TV-FM 7133 [1043:4843]
27 26 -> Pinnacle PCTV Stereo (saa7134) [11bd:002b] 27 26 -> Pinnacle PCTV Stereo (saa7134) [11bd:002b]
28 27 -> Manli MuchTV M-TV002/Behold TV 403 FM 28 27 -> Manli MuchTV M-TV002
29 28 -> Manli MuchTV M-TV001/Behold TV 401 29 28 -> Manli MuchTV M-TV001
30 29 -> Nagase Sangyo TransGear 3000TV [1461:050c] 30 29 -> Nagase Sangyo TransGear 3000TV [1461:050c]
31 30 -> Elitegroup ECS TVP3XP FM1216 Tuner Card(PAL-BG,FM) [1019:4cb4] 31 30 -> Elitegroup ECS TVP3XP FM1216 Tuner Card(PAL-BG,FM) [1019:4cb4]
32 31 -> Elitegroup ECS TVP3XP FM1236 Tuner Card (NTSC,FM) [1019:4cb5] 32 31 -> Elitegroup ECS TVP3XP FM1236 Tuner Card (NTSC,FM) [1019:4cb5]
@@ -131,3 +131,12 @@
131130 -> Beholder BeholdTV M6 / BeholdTV M6 Extra [5ace:6190,5ace:6193] 131130 -> Beholder BeholdTV M6 / BeholdTV M6 Extra [5ace:6190,5ace:6193]
132131 -> Twinhan Hybrid DTV-DVB 3056 PCI [1822:0022] 132131 -> Twinhan Hybrid DTV-DVB 3056 PCI [1822:0022]
133132 -> Genius TVGO AM11MCE 133132 -> Genius TVGO AM11MCE
134133 -> NXP Snake DVB-S reference design
135134 -> Medion/Creatix CTX953 Hybrid [16be:0010]
136135 -> MSI TV@nywhere A/D v1.1 [1462:8625]
137136 -> AVerMedia Cardbus TV/Radio (E506R) [1461:f436]
138137 -> AVerMedia Hybrid TV/Radio (A16D) [1461:f936]
139138 -> Avermedia M115 [1461:a836]
140139 -> Compro VideoMate T750 [185b:c900]
141140 -> Avermedia DVB-S Pro A700 [1461:a7a1]
142141 -> Avermedia DVB-S Hybrid+FM A700 [1461:a7a2]
diff --git a/Documentation/video4linux/extract_xc3028.pl b/Documentation/video4linux/extract_xc3028.pl
index cced8ac5c543..2cb816047fc1 100644
--- a/Documentation/video4linux/extract_xc3028.pl
+++ b/Documentation/video4linux/extract_xc3028.pl
@@ -686,11 +686,11 @@ sub main_firmware($$$$)
686 write_hunk(812664, 192); 686 write_hunk(812664, 192);
687 687
688 # 688 #
689 # Firmware 58, type: SCODE FW HAS IF (0x60000000), IF = 4.50 MHz id: NTSC/M Jp (0000000000002000), size: 192 689 # Firmware 58, type: SCODE FW MTS LCD NOGD MONO IF HAS IF (0x6002b004), IF = 4.50 MHz id: NTSC PAL/M PAL/N (000000000000b700), size: 192
690 # 690 #
691 691
692 write_le32(0x60000000); # Type 692 write_le32(0x6002b004); # Type
693 write_le64(0x00000000, 0x00002000); # ID 693 write_le64(0x00000000, 0x0000b700); # ID
694 write_le16(4500); # IF 694 write_le16(4500); # IF
695 write_le32(192); # Size 695 write_le32(192); # Size
696 write_hunk(807672, 192); 696 write_hunk(807672, 192);
@@ -706,10 +706,10 @@ sub main_firmware($$$$)
706 write_hunk(807864, 192); 706 write_hunk(807864, 192);
707 707
708 # 708 #
709 # Firmware 60, type: SCODE FW DTV78 ZARLINK456 HAS IF (0x62000100), IF = 4.76 MHz id: (0000000000000000), size: 192 709 # Firmware 60, type: SCODE FW DTV6 QAM DTV7 DTV78 DTV8 ZARLINK456 HAS IF (0x620003e0), IF = 4.76 MHz id: (0000000000000000), size: 192
710 # 710 #
711 711
712 write_le32(0x62000100); # Type 712 write_le32(0x620003e0); # Type
713 write_le64(0x00000000, 0x00000000); # ID 713 write_le64(0x00000000, 0x00000000); # ID
714 write_le16(4760); # IF 714 write_le16(4760); # IF
715 write_le32(192); # Size 715 write_le32(192); # Size
@@ -726,30 +726,30 @@ sub main_firmware($$$$)
726 write_hunk(811512, 192); 726 write_hunk(811512, 192);
727 727
728 # 728 #
729 # Firmware 62, type: SCODE FW DTV7 ZARLINK456 HAS IF (0x62000080), IF = 5.26 MHz id: (0000000000000000), size: 192 729 # Firmware 62, type: SCODE FW HAS IF (0x60000000), IF = 5.26 MHz id: (0000000000000000), size: 192
730 # 730 #
731 731
732 write_le32(0x62000080); # Type 732 write_le32(0x60000000); # Type
733 write_le64(0x00000000, 0x00000000); # ID 733 write_le64(0x00000000, 0x00000000); # ID
734 write_le16(5260); # IF 734 write_le16(5260); # IF
735 write_le32(192); # Size 735 write_le32(192); # Size
736 write_hunk(810552, 192); 736 write_hunk(810552, 192);
737 737
738 # 738 #
739 # Firmware 63, type: SCODE FW MONO HAS IF (0x60008000), IF = 5.32 MHz id: PAL/BG NICAM/B (0000000800000007), size: 192 739 # Firmware 63, type: SCODE FW MONO HAS IF (0x60008000), IF = 5.32 MHz id: PAL/BG A2 NICAM (0000000f00000007), size: 192
740 # 740 #
741 741
742 write_le32(0x60008000); # Type 742 write_le32(0x60008000); # Type
743 write_le64(0x00000008, 0x00000007); # ID 743 write_le64(0x0000000f, 0x00000007); # ID
744 write_le16(5320); # IF 744 write_le16(5320); # IF
745 write_le32(192); # Size 745 write_le32(192); # Size
746 write_hunk(810744, 192); 746 write_hunk(810744, 192);
747 747
748 # 748 #
749 # Firmware 64, type: SCODE FW DTV8 CHINA HAS IF (0x64000200), IF = 5.40 MHz id: (0000000000000000), size: 192 749 # Firmware 64, type: SCODE FW DTV7 DTV78 DTV8 DIBCOM52 CHINA HAS IF (0x65000380), IF = 5.40 MHz id: (0000000000000000), size: 192
750 # 750 #
751 751
752 write_le32(0x64000200); # Type 752 write_le32(0x65000380); # Type
753 write_le64(0x00000000, 0x00000000); # ID 753 write_le64(0x00000000, 0x00000000); # ID
754 write_le16(5400); # IF 754 write_le16(5400); # IF
755 write_le32(192); # Size 755 write_le32(192); # Size
@@ -766,50 +766,50 @@ sub main_firmware($$$$)
766 write_hunk(809592, 192); 766 write_hunk(809592, 192);
767 767
768 # 768 #
769 # Firmware 66, type: SCODE FW HAS IF (0x60000000), IF = 5.64 MHz id: PAL/BG A2/B (0000000200000007), size: 192 769 # Firmware 66, type: SCODE FW HAS IF (0x60000000), IF = 5.64 MHz id: PAL/BG A2 (0000000300000007), size: 192
770 # 770 #
771 771
772 write_le32(0x60000000); # Type 772 write_le32(0x60000000); # Type
773 write_le64(0x00000002, 0x00000007); # ID 773 write_le64(0x00000003, 0x00000007); # ID
774 write_le16(5640); # IF 774 write_le16(5640); # IF
775 write_le32(192); # Size 775 write_le32(192); # Size
776 write_hunk(808440, 192); 776 write_hunk(808440, 192);
777 777
778 # 778 #
779 # Firmware 67, type: SCODE FW HAS IF (0x60000000), IF = 5.74 MHz id: PAL/BG NICAM/B (0000000800000007), size: 192 779 # Firmware 67, type: SCODE FW HAS IF (0x60000000), IF = 5.74 MHz id: PAL/BG NICAM (0000000c00000007), size: 192
780 # 780 #
781 781
782 write_le32(0x60000000); # Type 782 write_le32(0x60000000); # Type
783 write_le64(0x00000008, 0x00000007); # ID 783 write_le64(0x0000000c, 0x00000007); # ID
784 write_le16(5740); # IF 784 write_le16(5740); # IF
785 write_le32(192); # Size 785 write_le32(192); # Size
786 write_hunk(808632, 192); 786 write_hunk(808632, 192);
787 787
788 # 788 #
789 # Firmware 68, type: SCODE FW DTV7 DIBCOM52 HAS IF (0x61000080), IF = 5.90 MHz id: (0000000000000000), size: 192 789 # Firmware 68, type: SCODE FW HAS IF (0x60000000), IF = 5.90 MHz id: (0000000000000000), size: 192
790 # 790 #
791 791
792 write_le32(0x61000080); # Type 792 write_le32(0x60000000); # Type
793 write_le64(0x00000000, 0x00000000); # ID 793 write_le64(0x00000000, 0x00000000); # ID
794 write_le16(5900); # IF 794 write_le16(5900); # IF
795 write_le32(192); # Size 795 write_le32(192); # Size
796 write_hunk(810360, 192); 796 write_hunk(810360, 192);
797 797
798 # 798 #
799 # Firmware 69, type: SCODE FW MONO HAS IF (0x60008000), IF = 6.00 MHz id: PAL/I (0000000000000010), size: 192 799 # Firmware 69, type: SCODE FW MONO HAS IF (0x60008000), IF = 6.00 MHz id: PAL/DK PAL/I SECAM/K3 SECAM/L SECAM/Lc NICAM (0000000c04c000f0), size: 192
800 # 800 #
801 801
802 write_le32(0x60008000); # Type 802 write_le32(0x60008000); # Type
803 write_le64(0x00000000, 0x00000010); # ID 803 write_le64(0x0000000c, 0x04c000f0); # ID
804 write_le16(6000); # IF 804 write_le16(6000); # IF
805 write_le32(192); # Size 805 write_le32(192); # Size
806 write_hunk(808824, 192); 806 write_hunk(808824, 192);
807 807
808 # 808 #
809 # Firmware 70, type: SCODE FW DTV6 QAM F6MHZ HAS IF (0x68000060), IF = 6.20 MHz id: (0000000000000000), size: 192 809 # Firmware 70, type: SCODE FW DTV6 QAM ATSC LG60 F6MHZ HAS IF (0x68050060), IF = 6.20 MHz id: (0000000000000000), size: 192
810 # 810 #
811 811
812 write_le32(0x68000060); # Type 812 write_le32(0x68050060); # Type
813 write_le64(0x00000000, 0x00000000); # ID 813 write_le64(0x00000000, 0x00000000); # ID
814 write_le16(6200); # IF 814 write_le16(6200); # IF
815 write_le32(192); # Size 815 write_le32(192); # Size
@@ -846,11 +846,11 @@ sub main_firmware($$$$)
846 write_hunk(809208, 192); 846 write_hunk(809208, 192);
847 847
848 # 848 #
849 # Firmware 74, type: SCODE FW MONO HAS IF (0x60008000), IF = 6.50 MHz id: SECAM/K3 (0000000004000000), size: 192 849 # Firmware 74, type: SCODE FW MONO HAS IF (0x60008000), IF = 6.50 MHz id: PAL/DK SECAM/K3 SECAM/L NICAM (0000000c044000e0), size: 192
850 # 850 #
851 851
852 write_le32(0x60008000); # Type 852 write_le32(0x60008000); # Type
853 write_le64(0x00000000, 0x04000000); # ID 853 write_le64(0x0000000c, 0x044000e0); # ID
854 write_le16(6500); # IF 854 write_le16(6500); # IF
855 write_le32(192); # Size 855 write_le32(192); # Size
856 write_hunk(811128, 192); 856 write_hunk(811128, 192);
diff --git a/MAINTAINERS b/MAINTAINERS
index c0cc52a9afe5..f50e927a1189 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -2558,12 +2558,10 @@ W: http://www.tazenda.demon.co.uk/phil/linux-hp
2558S: Maintained 2558S: Maintained
2559 2559
2560MAC80211 2560MAC80211
2561P: Michael Wu
2562M: flamingice@sourmilk.net
2563P: Johannes Berg 2561P: Johannes Berg
2564M: johannes@sipsolutions.net 2562M: johannes@sipsolutions.net
2565P: Jiri Benc 2563P: Michael Wu
2566M: jbenc@suse.cz 2564M: flamingice@sourmilk.net
2567L: linux-wireless@vger.kernel.org 2565L: linux-wireless@vger.kernel.org
2568W: http://linuxwireless.org/ 2566W: http://linuxwireless.org/
2569T: git kernel.org:/pub/scm/linux/kernel/git/linville/wireless-2.6.git 2567T: git kernel.org:/pub/scm/linux/kernel/git/linville/wireless-2.6.git
diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
index 8c71daf94a59..9fee37e2596f 100644
--- a/arch/alpha/kernel/osf_sys.c
+++ b/arch/alpha/kernel/osf_sys.c
@@ -75,6 +75,7 @@ osf_set_program_attributes(unsigned long text_start, unsigned long text_len,
75 lock_kernel(); 75 lock_kernel();
76 mm = current->mm; 76 mm = current->mm;
77 mm->end_code = bss_start + bss_len; 77 mm->end_code = bss_start + bss_len;
78 mm->start_brk = bss_start + bss_len;
78 mm->brk = bss_start + bss_len; 79 mm->brk = bss_start + bss_len;
79#if 0 80#if 0
80 printk("set_program_attributes(%lx %lx %lx %lx)\n", 81 printk("set_program_attributes(%lx %lx %lx %lx)\n",
diff --git a/arch/alpha/kernel/pci.c b/arch/alpha/kernel/pci.c
index c107cc08daf4..78357798b6fd 100644
--- a/arch/alpha/kernel/pci.c
+++ b/arch/alpha/kernel/pci.c
@@ -71,25 +71,13 @@ DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82378, quirk_i
71static void __init 71static void __init
72quirk_cypress(struct pci_dev *dev) 72quirk_cypress(struct pci_dev *dev)
73{ 73{
74 /* The Notorious Cy82C693 chip. */
75
76 /* The Cypress IDE controller doesn't support native mode, but it
77 has programmable addresses of IDE command/control registers.
78 This violates PCI specifications, confuses the IDE subsystem and
79 causes resource conflicts between the primary HD_CMD register and
80 the floppy controller. Ugh. Fix that. */
81 if (dev->class >> 8 == PCI_CLASS_STORAGE_IDE) {
82 dev->resource[0].flags = 0;
83 dev->resource[1].flags = 0;
84 }
85
86 /* The Cypress bridge responds on the PCI bus in the address range 74 /* The Cypress bridge responds on the PCI bus in the address range
87 0xffff0000-0xffffffff (conventional x86 BIOS ROM). There is no 75 0xffff0000-0xffffffff (conventional x86 BIOS ROM). There is no
88 way to turn this off. The bridge also supports several extended 76 way to turn this off. The bridge also supports several extended
89 BIOS ranges (disabled after power-up), and some consoles do turn 77 BIOS ranges (disabled after power-up), and some consoles do turn
90 them on. So if we use a large direct-map window, or a large SG 78 them on. So if we use a large direct-map window, or a large SG
91 window, we must avoid the entire 0xfff00000-0xffffffff region. */ 79 window, we must avoid the entire 0xfff00000-0xffffffff region. */
92 else if (dev->class >> 8 == PCI_CLASS_BRIDGE_ISA) { 80 if (dev->class >> 8 == PCI_CLASS_BRIDGE_ISA) {
93 if (__direct_map_base + __direct_map_size >= 0xfff00000UL) 81 if (__direct_map_base + __direct_map_size >= 0xfff00000UL)
94 __direct_map_size = 0xfff00000UL - __direct_map_base; 82 __direct_map_size = 0xfff00000UL - __direct_map_base;
95 else { 83 else {
@@ -391,7 +379,7 @@ pcibios_set_master(struct pci_dev *dev)
391 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 64); 379 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 64);
392} 380}
393 381
394static void __init 382void __init
395pcibios_claim_one_bus(struct pci_bus *b) 383pcibios_claim_one_bus(struct pci_bus *b)
396{ 384{
397 struct pci_dev *dev; 385 struct pci_dev *dev;
@@ -405,7 +393,8 @@ pcibios_claim_one_bus(struct pci_bus *b)
405 393
406 if (r->parent || !r->start || !r->flags) 394 if (r->parent || !r->start || !r->flags)
407 continue; 395 continue;
408 pci_claim_resource(dev, i); 396 if (pci_probe_only || (r->flags & IORESOURCE_PCI_FIXED))
397 pci_claim_resource(dev, i);
409 } 398 }
410 } 399 }
411 400
@@ -444,8 +433,7 @@ common_init_pci(void)
444 } 433 }
445 } 434 }
446 435
447 if (pci_probe_only) 436 pcibios_claim_console_setup();
448 pcibios_claim_console_setup();
449 437
450 pci_assign_unassigned_resources(); 438 pci_assign_unassigned_resources();
451 pci_fixup_irqs(alpha_mv.pci_swizzle, alpha_mv.pci_map_irq); 439 pci_fixup_irqs(alpha_mv.pci_swizzle, alpha_mv.pci_map_irq);
diff --git a/arch/alpha/kernel/sys_nautilus.c b/arch/alpha/kernel/sys_nautilus.c
index 920196bcbb61..a7f23b5ab814 100644
--- a/arch/alpha/kernel/sys_nautilus.c
+++ b/arch/alpha/kernel/sys_nautilus.c
@@ -187,6 +187,7 @@ nautilus_machine_check(unsigned long vector, unsigned long la_ptr)
187} 187}
188 188
189extern void free_reserved_mem(void *, void *); 189extern void free_reserved_mem(void *, void *);
190extern void pcibios_claim_one_bus(struct pci_bus *);
190 191
191static struct resource irongate_mem = { 192static struct resource irongate_mem = {
192 .name = "Irongate PCI MEM", 193 .name = "Irongate PCI MEM",
@@ -205,6 +206,7 @@ nautilus_init_pci(void)
205 /* Scan our single hose. */ 206 /* Scan our single hose. */
206 bus = pci_scan_bus(0, alpha_mv.pci_ops, hose); 207 bus = pci_scan_bus(0, alpha_mv.pci_ops, hose);
207 hose->bus = bus; 208 hose->bus = bus;
209 pcibios_claim_one_bus(bus);
208 210
209 irongate = pci_get_bus_and_slot(0, 0); 211 irongate = pci_get_bus_and_slot(0, 0);
210 bus->self = irongate; 212 bus->self = irongate;
diff --git a/arch/arm/mach-integrator/time.c b/arch/arm/mach-integrator/time.c
index 5235f64f235b..8508a0db3eaf 100644
--- a/arch/arm/mach-integrator/time.c
+++ b/arch/arm/mach-integrator/time.c
@@ -124,8 +124,11 @@ static int rtc_probe(struct amba_device *dev, void *id)
124 124
125 xtime.tv_sec = __raw_readl(rtc_base + RTC_DR); 125 xtime.tv_sec = __raw_readl(rtc_base + RTC_DR);
126 126
127 /* note that 'dev' is merely used for irq disambiguation;
128 * it is not actually referenced in the irq handler
129 */
127 ret = request_irq(dev->irq[0], arm_rtc_interrupt, IRQF_DISABLED, 130 ret = request_irq(dev->irq[0], arm_rtc_interrupt, IRQF_DISABLED,
128 "rtc-pl030", NULL); 131 "rtc-pl030", dev);
129 if (ret) 132 if (ret)
130 goto map_out; 133 goto map_out;
131 134
diff --git a/arch/arm/mach-lh7a40x/arch-kev7a400.c b/arch/arm/mach-lh7a40x/arch-kev7a400.c
index 6d26661d99f6..2ef7d0097b38 100644
--- a/arch/arm/mach-lh7a40x/arch-kev7a400.c
+++ b/arch/arm/mach-lh7a40x/arch-kev7a400.c
@@ -75,10 +75,9 @@ static void kev7a400_cpld_handler (unsigned int irq, struct irq_desc *desc)
75{ 75{
76 u32 mask = CPLD_LATCHED_INTS; 76 u32 mask = CPLD_LATCHED_INTS;
77 irq = IRQ_KEV7A400_CPLD; 77 irq = IRQ_KEV7A400_CPLD;
78 for (; mask; mask >>= 1, ++irq) { 78 for (; mask; mask >>= 1, ++irq)
79 if (mask & 1) 79 if (mask & 1)
80 desc[irq].handle (irq, desc); 80 desc_handle_irq(irq, desc);
81 }
82} 81}
83 82
84void __init lh7a40x_init_board_irq (void) 83void __init lh7a40x_init_board_irq (void)
diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
index 746cbb7c8e95..1b8229d9c9d5 100644
--- a/arch/arm/mm/Kconfig
+++ b/arch/arm/mm/Kconfig
@@ -32,6 +32,7 @@ config CPU_ARM7TDMI
32 depends on !MMU 32 depends on !MMU
33 select CPU_32v4T 33 select CPU_32v4T
34 select CPU_ABRT_LV4T 34 select CPU_ABRT_LV4T
35 select CPU_PABRT_NOIFAR
35 select CPU_CACHE_V4 36 select CPU_CACHE_V4
36 help 37 help
37 A 32-bit RISC microprocessor based on the ARM7 processor core 38 A 32-bit RISC microprocessor based on the ARM7 processor core
@@ -85,6 +86,7 @@ config CPU_ARM740T
85 depends on !MMU 86 depends on !MMU
86 select CPU_32v4T 87 select CPU_32v4T
87 select CPU_ABRT_LV4T 88 select CPU_ABRT_LV4T
89 select CPU_PABRT_NOIFAR
88 select CPU_CACHE_V3 # although the core is v4t 90 select CPU_CACHE_V3 # although the core is v4t
89 select CPU_CP15_MPU 91 select CPU_CP15_MPU
90 help 92 help
@@ -101,6 +103,7 @@ config CPU_ARM9TDMI
101 depends on !MMU 103 depends on !MMU
102 select CPU_32v4T 104 select CPU_32v4T
103 select CPU_ABRT_NOMMU 105 select CPU_ABRT_NOMMU
106 select CPU_PABRT_NOIFAR
104 select CPU_CACHE_V4 107 select CPU_CACHE_V4
105 help 108 help
106 A 32-bit RISC microprocessor based on the ARM9 processor core 109 A 32-bit RISC microprocessor based on the ARM9 processor core
@@ -200,6 +203,7 @@ config CPU_ARM940T
200 depends on !MMU 203 depends on !MMU
201 select CPU_32v4T 204 select CPU_32v4T
202 select CPU_ABRT_NOMMU 205 select CPU_ABRT_NOMMU
206 select CPU_PABRT_NOIFAR
203 select CPU_CACHE_VIVT 207 select CPU_CACHE_VIVT
204 select CPU_CP15_MPU 208 select CPU_CP15_MPU
205 help 209 help
@@ -217,6 +221,7 @@ config CPU_ARM946E
217 depends on !MMU 221 depends on !MMU
218 select CPU_32v5 222 select CPU_32v5
219 select CPU_ABRT_NOMMU 223 select CPU_ABRT_NOMMU
224 select CPU_PABRT_NOIFAR
220 select CPU_CACHE_VIVT 225 select CPU_CACHE_VIVT
221 select CPU_CP15_MPU 226 select CPU_CP15_MPU
222 help 227 help
@@ -351,6 +356,7 @@ config CPU_XSC3
351 default y 356 default y
352 select CPU_32v5 357 select CPU_32v5
353 select CPU_ABRT_EV5T 358 select CPU_ABRT_EV5T
359 select CPU_PABRT_NOIFAR
354 select CPU_CACHE_VIVT 360 select CPU_CACHE_VIVT
355 select CPU_CP15_MMU 361 select CPU_CP15_MMU
356 select CPU_TLB_V4WBI if MMU 362 select CPU_TLB_V4WBI if MMU
diff --git a/arch/arm/mm/proc-arm1020.S b/arch/arm/mm/proc-arm1020.S
index 32fd7ea533f2..5673f4d6113b 100644
--- a/arch/arm/mm/proc-arm1020.S
+++ b/arch/arm/mm/proc-arm1020.S
@@ -471,6 +471,7 @@ arm1020_crval:
471 .type arm1020_processor_functions, #object 471 .type arm1020_processor_functions, #object
472arm1020_processor_functions: 472arm1020_processor_functions:
473 .word v4t_early_abort 473 .word v4t_early_abort
474 .word pabort_noifar
474 .word cpu_arm1020_proc_init 475 .word cpu_arm1020_proc_init
475 .word cpu_arm1020_proc_fin 476 .word cpu_arm1020_proc_fin
476 .word cpu_arm1020_reset 477 .word cpu_arm1020_reset
@@ -478,7 +479,6 @@ arm1020_processor_functions:
478 .word cpu_arm1020_dcache_clean_area 479 .word cpu_arm1020_dcache_clean_area
479 .word cpu_arm1020_switch_mm 480 .word cpu_arm1020_switch_mm
480 .word cpu_arm1020_set_pte_ext 481 .word cpu_arm1020_set_pte_ext
481 .word pabort_noifar
482 .size arm1020_processor_functions, . - arm1020_processor_functions 482 .size arm1020_processor_functions, . - arm1020_processor_functions
483 483
484 .section ".rodata" 484 .section ".rodata"
diff --git a/arch/arm/mm/proc-arm1020e.S b/arch/arm/mm/proc-arm1020e.S
index fe2b0ae70274..4343fdb0e9e5 100644
--- a/arch/arm/mm/proc-arm1020e.S
+++ b/arch/arm/mm/proc-arm1020e.S
@@ -452,6 +452,7 @@ arm1020e_crval:
452 .type arm1020e_processor_functions, #object 452 .type arm1020e_processor_functions, #object
453arm1020e_processor_functions: 453arm1020e_processor_functions:
454 .word v4t_early_abort 454 .word v4t_early_abort
455 .word pabort_noifar
455 .word cpu_arm1020e_proc_init 456 .word cpu_arm1020e_proc_init
456 .word cpu_arm1020e_proc_fin 457 .word cpu_arm1020e_proc_fin
457 .word cpu_arm1020e_reset 458 .word cpu_arm1020e_reset
@@ -459,7 +460,6 @@ arm1020e_processor_functions:
459 .word cpu_arm1020e_dcache_clean_area 460 .word cpu_arm1020e_dcache_clean_area
460 .word cpu_arm1020e_switch_mm 461 .word cpu_arm1020e_switch_mm
461 .word cpu_arm1020e_set_pte_ext 462 .word cpu_arm1020e_set_pte_ext
462 .word pabort_noifar
463 .size arm1020e_processor_functions, . - arm1020e_processor_functions 463 .size arm1020e_processor_functions, . - arm1020e_processor_functions
464 464
465 .section ".rodata" 465 .section ".rodata"
diff --git a/arch/arm/mm/proc-arm1022.S b/arch/arm/mm/proc-arm1022.S
index 06dde678e19d..2a4ea1659e96 100644
--- a/arch/arm/mm/proc-arm1022.S
+++ b/arch/arm/mm/proc-arm1022.S
@@ -435,6 +435,7 @@ arm1022_crval:
435 .type arm1022_processor_functions, #object 435 .type arm1022_processor_functions, #object
436arm1022_processor_functions: 436arm1022_processor_functions:
437 .word v4t_early_abort 437 .word v4t_early_abort
438 .word pabort_noifar
438 .word cpu_arm1022_proc_init 439 .word cpu_arm1022_proc_init
439 .word cpu_arm1022_proc_fin 440 .word cpu_arm1022_proc_fin
440 .word cpu_arm1022_reset 441 .word cpu_arm1022_reset
@@ -442,7 +443,6 @@ arm1022_processor_functions:
442 .word cpu_arm1022_dcache_clean_area 443 .word cpu_arm1022_dcache_clean_area
443 .word cpu_arm1022_switch_mm 444 .word cpu_arm1022_switch_mm
444 .word cpu_arm1022_set_pte_ext 445 .word cpu_arm1022_set_pte_ext
445 .word pabort_noifar
446 .size arm1022_processor_functions, . - arm1022_processor_functions 446 .size arm1022_processor_functions, . - arm1022_processor_functions
447 447
448 .section ".rodata" 448 .section ".rodata"
diff --git a/arch/arm/mm/proc-arm1026.S b/arch/arm/mm/proc-arm1026.S
index f5506e6e681e..77a1babd421c 100644
--- a/arch/arm/mm/proc-arm1026.S
+++ b/arch/arm/mm/proc-arm1026.S
@@ -430,6 +430,7 @@ arm1026_crval:
430 .type arm1026_processor_functions, #object 430 .type arm1026_processor_functions, #object
431arm1026_processor_functions: 431arm1026_processor_functions:
432 .word v5t_early_abort 432 .word v5t_early_abort
433 .word pabort_noifar
433 .word cpu_arm1026_proc_init 434 .word cpu_arm1026_proc_init
434 .word cpu_arm1026_proc_fin 435 .word cpu_arm1026_proc_fin
435 .word cpu_arm1026_reset 436 .word cpu_arm1026_reset
@@ -437,7 +438,6 @@ arm1026_processor_functions:
437 .word cpu_arm1026_dcache_clean_area 438 .word cpu_arm1026_dcache_clean_area
438 .word cpu_arm1026_switch_mm 439 .word cpu_arm1026_switch_mm
439 .word cpu_arm1026_set_pte_ext 440 .word cpu_arm1026_set_pte_ext
440 .word pabort_noifar
441 .size arm1026_processor_functions, . - arm1026_processor_functions 441 .size arm1026_processor_functions, . - arm1026_processor_functions
442 442
443 .section .rodata 443 .section .rodata
diff --git a/arch/arm/mm/proc-arm6_7.S b/arch/arm/mm/proc-arm6_7.S
index 14b6a95c8d45..c371fc87776e 100644
--- a/arch/arm/mm/proc-arm6_7.S
+++ b/arch/arm/mm/proc-arm6_7.S
@@ -293,6 +293,7 @@ __arm7_setup: mov r0, #0
293 .type arm6_processor_functions, #object 293 .type arm6_processor_functions, #object
294ENTRY(arm6_processor_functions) 294ENTRY(arm6_processor_functions)
295 .word cpu_arm6_data_abort 295 .word cpu_arm6_data_abort
296 .word pabort_noifar
296 .word cpu_arm6_proc_init 297 .word cpu_arm6_proc_init
297 .word cpu_arm6_proc_fin 298 .word cpu_arm6_proc_fin
298 .word cpu_arm6_reset 299 .word cpu_arm6_reset
@@ -300,7 +301,6 @@ ENTRY(arm6_processor_functions)
300 .word cpu_arm6_dcache_clean_area 301 .word cpu_arm6_dcache_clean_area
301 .word cpu_arm6_switch_mm 302 .word cpu_arm6_switch_mm
302 .word cpu_arm6_set_pte_ext 303 .word cpu_arm6_set_pte_ext
303 .word pabort_noifar
304 .size arm6_processor_functions, . - arm6_processor_functions 304 .size arm6_processor_functions, . - arm6_processor_functions
305 305
306/* 306/*
@@ -310,6 +310,7 @@ ENTRY(arm6_processor_functions)
310 .type arm7_processor_functions, #object 310 .type arm7_processor_functions, #object
311ENTRY(arm7_processor_functions) 311ENTRY(arm7_processor_functions)
312 .word cpu_arm7_data_abort 312 .word cpu_arm7_data_abort
313 .word pabort_noifar
313 .word cpu_arm7_proc_init 314 .word cpu_arm7_proc_init
314 .word cpu_arm7_proc_fin 315 .word cpu_arm7_proc_fin
315 .word cpu_arm7_reset 316 .word cpu_arm7_reset
@@ -317,7 +318,6 @@ ENTRY(arm7_processor_functions)
317 .word cpu_arm7_dcache_clean_area 318 .word cpu_arm7_dcache_clean_area
318 .word cpu_arm7_switch_mm 319 .word cpu_arm7_switch_mm
319 .word cpu_arm7_set_pte_ext 320 .word cpu_arm7_set_pte_ext
320 .word pabort_noifar
321 .size arm7_processor_functions, . - arm7_processor_functions 321 .size arm7_processor_functions, . - arm7_processor_functions
322 322
323 .section ".rodata" 323 .section ".rodata"
diff --git a/arch/arm/mm/proc-arm720.S b/arch/arm/mm/proc-arm720.S
index ca5e7aac2da7..d64f8e6f75ab 100644
--- a/arch/arm/mm/proc-arm720.S
+++ b/arch/arm/mm/proc-arm720.S
@@ -198,6 +198,7 @@ arm720_crval:
198 .type arm720_processor_functions, #object 198 .type arm720_processor_functions, #object
199ENTRY(arm720_processor_functions) 199ENTRY(arm720_processor_functions)
200 .word v4t_late_abort 200 .word v4t_late_abort
201 .word pabort_noifar
201 .word cpu_arm720_proc_init 202 .word cpu_arm720_proc_init
202 .word cpu_arm720_proc_fin 203 .word cpu_arm720_proc_fin
203 .word cpu_arm720_reset 204 .word cpu_arm720_reset
@@ -205,7 +206,6 @@ ENTRY(arm720_processor_functions)
205 .word cpu_arm720_dcache_clean_area 206 .word cpu_arm720_dcache_clean_area
206 .word cpu_arm720_switch_mm 207 .word cpu_arm720_switch_mm
207 .word cpu_arm720_set_pte_ext 208 .word cpu_arm720_set_pte_ext
208 .word pabort_noifar
209 .size arm720_processor_functions, . - arm720_processor_functions 209 .size arm720_processor_functions, . - arm720_processor_functions
210 210
211 .section ".rodata" 211 .section ".rodata"
diff --git a/arch/arm/mm/proc-arm740.S b/arch/arm/mm/proc-arm740.S
index 7069f495cf9b..3a57376c8bc9 100644
--- a/arch/arm/mm/proc-arm740.S
+++ b/arch/arm/mm/proc-arm740.S
@@ -126,6 +126,7 @@ __arm740_setup:
126 .type arm740_processor_functions, #object 126 .type arm740_processor_functions, #object
127ENTRY(arm740_processor_functions) 127ENTRY(arm740_processor_functions)
128 .word v4t_late_abort 128 .word v4t_late_abort
129 .word pabort_noifar
129 .word cpu_arm740_proc_init 130 .word cpu_arm740_proc_init
130 .word cpu_arm740_proc_fin 131 .word cpu_arm740_proc_fin
131 .word cpu_arm740_reset 132 .word cpu_arm740_reset
diff --git a/arch/arm/mm/proc-arm7tdmi.S b/arch/arm/mm/proc-arm7tdmi.S
index d091c2571823..7b3ecdeb5370 100644
--- a/arch/arm/mm/proc-arm7tdmi.S
+++ b/arch/arm/mm/proc-arm7tdmi.S
@@ -64,6 +64,7 @@ __arm7tdmi_setup:
64 .type arm7tdmi_processor_functions, #object 64 .type arm7tdmi_processor_functions, #object
65ENTRY(arm7tdmi_processor_functions) 65ENTRY(arm7tdmi_processor_functions)
66 .word v4t_late_abort 66 .word v4t_late_abort
67 .word pabort_noifar
67 .word cpu_arm7tdmi_proc_init 68 .word cpu_arm7tdmi_proc_init
68 .word cpu_arm7tdmi_proc_fin 69 .word cpu_arm7tdmi_proc_fin
69 .word cpu_arm7tdmi_reset 70 .word cpu_arm7tdmi_reset
diff --git a/arch/arm/mm/proc-arm920.S b/arch/arm/mm/proc-arm920.S
index 0170d4f466ea..28cdb060df45 100644
--- a/arch/arm/mm/proc-arm920.S
+++ b/arch/arm/mm/proc-arm920.S
@@ -417,6 +417,7 @@ arm920_crval:
417 .type arm920_processor_functions, #object 417 .type arm920_processor_functions, #object
418arm920_processor_functions: 418arm920_processor_functions:
419 .word v4t_early_abort 419 .word v4t_early_abort
420 .word pabort_noifar
420 .word cpu_arm920_proc_init 421 .word cpu_arm920_proc_init
421 .word cpu_arm920_proc_fin 422 .word cpu_arm920_proc_fin
422 .word cpu_arm920_reset 423 .word cpu_arm920_reset
@@ -424,7 +425,6 @@ arm920_processor_functions:
424 .word cpu_arm920_dcache_clean_area 425 .word cpu_arm920_dcache_clean_area
425 .word cpu_arm920_switch_mm 426 .word cpu_arm920_switch_mm
426 .word cpu_arm920_set_pte_ext 427 .word cpu_arm920_set_pte_ext
427 .word pabort_noifar
428 .size arm920_processor_functions, . - arm920_processor_functions 428 .size arm920_processor_functions, . - arm920_processor_functions
429 429
430 .section ".rodata" 430 .section ".rodata"
diff --git a/arch/arm/mm/proc-arm922.S b/arch/arm/mm/proc-arm922.S
index b7952493d404..94ddcb4a4b76 100644
--- a/arch/arm/mm/proc-arm922.S
+++ b/arch/arm/mm/proc-arm922.S
@@ -421,6 +421,7 @@ arm922_crval:
421 .type arm922_processor_functions, #object 421 .type arm922_processor_functions, #object
422arm922_processor_functions: 422arm922_processor_functions:
423 .word v4t_early_abort 423 .word v4t_early_abort
424 .word pabort_noifar
424 .word cpu_arm922_proc_init 425 .word cpu_arm922_proc_init
425 .word cpu_arm922_proc_fin 426 .word cpu_arm922_proc_fin
426 .word cpu_arm922_reset 427 .word cpu_arm922_reset
@@ -428,7 +429,6 @@ arm922_processor_functions:
428 .word cpu_arm922_dcache_clean_area 429 .word cpu_arm922_dcache_clean_area
429 .word cpu_arm922_switch_mm 430 .word cpu_arm922_switch_mm
430 .word cpu_arm922_set_pte_ext 431 .word cpu_arm922_set_pte_ext
431 .word pabort_noifar
432 .size arm922_processor_functions, . - arm922_processor_functions 432 .size arm922_processor_functions, . - arm922_processor_functions
433 433
434 .section ".rodata" 434 .section ".rodata"
diff --git a/arch/arm/mm/proc-arm925.S b/arch/arm/mm/proc-arm925.S
index e2988eba4cf6..065087afb772 100644
--- a/arch/arm/mm/proc-arm925.S
+++ b/arch/arm/mm/proc-arm925.S
@@ -484,6 +484,7 @@ arm925_crval:
484 .type arm925_processor_functions, #object 484 .type arm925_processor_functions, #object
485arm925_processor_functions: 485arm925_processor_functions:
486 .word v4t_early_abort 486 .word v4t_early_abort
487 .word pabort_noifar
487 .word cpu_arm925_proc_init 488 .word cpu_arm925_proc_init
488 .word cpu_arm925_proc_fin 489 .word cpu_arm925_proc_fin
489 .word cpu_arm925_reset 490 .word cpu_arm925_reset
@@ -491,7 +492,6 @@ arm925_processor_functions:
491 .word cpu_arm925_dcache_clean_area 492 .word cpu_arm925_dcache_clean_area
492 .word cpu_arm925_switch_mm 493 .word cpu_arm925_switch_mm
493 .word cpu_arm925_set_pte_ext 494 .word cpu_arm925_set_pte_ext
494 .word pabort_noifar
495 .size arm925_processor_functions, . - arm925_processor_functions 495 .size arm925_processor_functions, . - arm925_processor_functions
496 496
497 .section ".rodata" 497 .section ".rodata"
diff --git a/arch/arm/mm/proc-arm926.S b/arch/arm/mm/proc-arm926.S
index 62f7d1dfe016..997db8472b5c 100644
--- a/arch/arm/mm/proc-arm926.S
+++ b/arch/arm/mm/proc-arm926.S
@@ -437,6 +437,7 @@ arm926_crval:
437 .type arm926_processor_functions, #object 437 .type arm926_processor_functions, #object
438arm926_processor_functions: 438arm926_processor_functions:
439 .word v5tj_early_abort 439 .word v5tj_early_abort
440 .word pabort_noifar
440 .word cpu_arm926_proc_init 441 .word cpu_arm926_proc_init
441 .word cpu_arm926_proc_fin 442 .word cpu_arm926_proc_fin
442 .word cpu_arm926_reset 443 .word cpu_arm926_reset
@@ -444,7 +445,6 @@ arm926_processor_functions:
444 .word cpu_arm926_dcache_clean_area 445 .word cpu_arm926_dcache_clean_area
445 .word cpu_arm926_switch_mm 446 .word cpu_arm926_switch_mm
446 .word cpu_arm926_set_pte_ext 447 .word cpu_arm926_set_pte_ext
447 .word pabort_noifar
448 .size arm926_processor_functions, . - arm926_processor_functions 448 .size arm926_processor_functions, . - arm926_processor_functions
449 449
450 .section ".rodata" 450 .section ".rodata"
diff --git a/arch/arm/mm/proc-arm940.S b/arch/arm/mm/proc-arm940.S
index 786c593778f0..44ead902bd54 100644
--- a/arch/arm/mm/proc-arm940.S
+++ b/arch/arm/mm/proc-arm940.S
@@ -321,6 +321,7 @@ __arm940_setup:
321 .type arm940_processor_functions, #object 321 .type arm940_processor_functions, #object
322ENTRY(arm940_processor_functions) 322ENTRY(arm940_processor_functions)
323 .word nommu_early_abort 323 .word nommu_early_abort
324 .word pabort_noifar
324 .word cpu_arm940_proc_init 325 .word cpu_arm940_proc_init
325 .word cpu_arm940_proc_fin 326 .word cpu_arm940_proc_fin
326 .word cpu_arm940_reset 327 .word cpu_arm940_reset
diff --git a/arch/arm/mm/proc-arm946.S b/arch/arm/mm/proc-arm946.S
index a60c1421d450..2218b0c01330 100644
--- a/arch/arm/mm/proc-arm946.S
+++ b/arch/arm/mm/proc-arm946.S
@@ -376,6 +376,7 @@ __arm946_setup:
376 .type arm946_processor_functions, #object 376 .type arm946_processor_functions, #object
377ENTRY(arm946_processor_functions) 377ENTRY(arm946_processor_functions)
378 .word nommu_early_abort 378 .word nommu_early_abort
379 .word pabort_noifar
379 .word cpu_arm946_proc_init 380 .word cpu_arm946_proc_init
380 .word cpu_arm946_proc_fin 381 .word cpu_arm946_proc_fin
381 .word cpu_arm946_reset 382 .word cpu_arm946_reset
diff --git a/arch/arm/mm/proc-arm9tdmi.S b/arch/arm/mm/proc-arm9tdmi.S
index 4848eeac86b6..c85c1f50e396 100644
--- a/arch/arm/mm/proc-arm9tdmi.S
+++ b/arch/arm/mm/proc-arm9tdmi.S
@@ -64,6 +64,7 @@ __arm9tdmi_setup:
64 .type arm9tdmi_processor_functions, #object 64 .type arm9tdmi_processor_functions, #object
65ENTRY(arm9tdmi_processor_functions) 65ENTRY(arm9tdmi_processor_functions)
66 .word nommu_early_abort 66 .word nommu_early_abort
67 .word pabort_noifar
67 .word cpu_arm9tdmi_proc_init 68 .word cpu_arm9tdmi_proc_init
68 .word cpu_arm9tdmi_proc_fin 69 .word cpu_arm9tdmi_proc_fin
69 .word cpu_arm9tdmi_reset 70 .word cpu_arm9tdmi_reset
diff --git a/arch/arm/mm/proc-feroceon.S b/arch/arm/mm/proc-feroceon.S
index 2f169b28e938..90e7594e29b1 100644
--- a/arch/arm/mm/proc-feroceon.S
+++ b/arch/arm/mm/proc-feroceon.S
@@ -423,6 +423,7 @@ feroceon_crval:
423 .type feroceon_processor_functions, #object 423 .type feroceon_processor_functions, #object
424feroceon_processor_functions: 424feroceon_processor_functions:
425 .word v5t_early_abort 425 .word v5t_early_abort
426 .word pabort_noifar
426 .word cpu_feroceon_proc_init 427 .word cpu_feroceon_proc_init
427 .word cpu_feroceon_proc_fin 428 .word cpu_feroceon_proc_fin
428 .word cpu_feroceon_reset 429 .word cpu_feroceon_reset
@@ -430,7 +431,6 @@ feroceon_processor_functions:
430 .word cpu_feroceon_dcache_clean_area 431 .word cpu_feroceon_dcache_clean_area
431 .word cpu_feroceon_switch_mm 432 .word cpu_feroceon_switch_mm
432 .word cpu_feroceon_set_pte_ext 433 .word cpu_feroceon_set_pte_ext
433 .word pabort_noifar
434 .size feroceon_processor_functions, . - feroceon_processor_functions 434 .size feroceon_processor_functions, . - feroceon_processor_functions
435 435
436 .section ".rodata" 436 .section ".rodata"
diff --git a/arch/arm/mm/proc-sa110.S b/arch/arm/mm/proc-sa110.S
index 4db3d6299a2b..9818195dbf11 100644
--- a/arch/arm/mm/proc-sa110.S
+++ b/arch/arm/mm/proc-sa110.S
@@ -216,6 +216,7 @@ sa110_crval:
216 .type sa110_processor_functions, #object 216 .type sa110_processor_functions, #object
217ENTRY(sa110_processor_functions) 217ENTRY(sa110_processor_functions)
218 .word v4_early_abort 218 .word v4_early_abort
219 .word pabort_noifar
219 .word cpu_sa110_proc_init 220 .word cpu_sa110_proc_init
220 .word cpu_sa110_proc_fin 221 .word cpu_sa110_proc_fin
221 .word cpu_sa110_reset 222 .word cpu_sa110_reset
@@ -223,7 +224,6 @@ ENTRY(sa110_processor_functions)
223 .word cpu_sa110_dcache_clean_area 224 .word cpu_sa110_dcache_clean_area
224 .word cpu_sa110_switch_mm 225 .word cpu_sa110_switch_mm
225 .word cpu_sa110_set_pte_ext 226 .word cpu_sa110_set_pte_ext
226 .word pabort_noifar
227 .size sa110_processor_functions, . - sa110_processor_functions 227 .size sa110_processor_functions, . - sa110_processor_functions
228 228
229 .section ".rodata" 229 .section ".rodata"
diff --git a/arch/arm/mm/proc-sa1100.S b/arch/arm/mm/proc-sa1100.S
index 3cdef043760f..c5fe27ad2892 100644
--- a/arch/arm/mm/proc-sa1100.S
+++ b/arch/arm/mm/proc-sa1100.S
@@ -231,6 +231,7 @@ sa1100_crval:
231 .type sa1100_processor_functions, #object 231 .type sa1100_processor_functions, #object
232ENTRY(sa1100_processor_functions) 232ENTRY(sa1100_processor_functions)
233 .word v4_early_abort 233 .word v4_early_abort
234 .word pabort_noifar
234 .word cpu_sa1100_proc_init 235 .word cpu_sa1100_proc_init
235 .word cpu_sa1100_proc_fin 236 .word cpu_sa1100_proc_fin
236 .word cpu_sa1100_reset 237 .word cpu_sa1100_reset
@@ -238,7 +239,6 @@ ENTRY(sa1100_processor_functions)
238 .word cpu_sa1100_dcache_clean_area 239 .word cpu_sa1100_dcache_clean_area
239 .word cpu_sa1100_switch_mm 240 .word cpu_sa1100_switch_mm
240 .word cpu_sa1100_set_pte_ext 241 .word cpu_sa1100_set_pte_ext
241 .word pabort_noifar
242 .size sa1100_processor_functions, . - sa1100_processor_functions 242 .size sa1100_processor_functions, . - sa1100_processor_functions
243 243
244 .section ".rodata" 244 .section ".rodata"
diff --git a/arch/arm/mm/proc-v6.S b/arch/arm/mm/proc-v6.S
index bf760ea2f789..5702ec58b2a2 100644
--- a/arch/arm/mm/proc-v6.S
+++ b/arch/arm/mm/proc-v6.S
@@ -219,6 +219,7 @@ v6_crval:
219 .type v6_processor_functions, #object 219 .type v6_processor_functions, #object
220ENTRY(v6_processor_functions) 220ENTRY(v6_processor_functions)
221 .word v6_early_abort 221 .word v6_early_abort
222 .word pabort_noifar
222 .word cpu_v6_proc_init 223 .word cpu_v6_proc_init
223 .word cpu_v6_proc_fin 224 .word cpu_v6_proc_fin
224 .word cpu_v6_reset 225 .word cpu_v6_reset
@@ -226,7 +227,6 @@ ENTRY(v6_processor_functions)
226 .word cpu_v6_dcache_clean_area 227 .word cpu_v6_dcache_clean_area
227 .word cpu_v6_switch_mm 228 .word cpu_v6_switch_mm
228 .word cpu_v6_set_pte_ext 229 .word cpu_v6_set_pte_ext
229 .word pabort_noifar
230 .size v6_processor_functions, . - v6_processor_functions 230 .size v6_processor_functions, . - v6_processor_functions
231 231
232 .type cpu_arch_name, #object 232 .type cpu_arch_name, #object
diff --git a/arch/arm/mm/proc-v7.S b/arch/arm/mm/proc-v7.S
index a1d7331cd64c..b49f9a4c82c8 100644
--- a/arch/arm/mm/proc-v7.S
+++ b/arch/arm/mm/proc-v7.S
@@ -205,6 +205,7 @@ __v7_setup_stack:
205 .type v7_processor_functions, #object 205 .type v7_processor_functions, #object
206ENTRY(v7_processor_functions) 206ENTRY(v7_processor_functions)
207 .word v7_early_abort 207 .word v7_early_abort
208 .word pabort_ifar
208 .word cpu_v7_proc_init 209 .word cpu_v7_proc_init
209 .word cpu_v7_proc_fin 210 .word cpu_v7_proc_fin
210 .word cpu_v7_reset 211 .word cpu_v7_reset
@@ -212,7 +213,6 @@ ENTRY(v7_processor_functions)
212 .word cpu_v7_dcache_clean_area 213 .word cpu_v7_dcache_clean_area
213 .word cpu_v7_switch_mm 214 .word cpu_v7_switch_mm
214 .word cpu_v7_set_pte_ext 215 .word cpu_v7_set_pte_ext
215 .word pabort_ifar
216 .size v7_processor_functions, . - v7_processor_functions 216 .size v7_processor_functions, . - v7_processor_functions
217 217
218 .type cpu_arch_name, #object 218 .type cpu_arch_name, #object
diff --git a/arch/arm/mm/proc-xsc3.S b/arch/arm/mm/proc-xsc3.S
index d95921a2ab99..3533741a76f6 100644
--- a/arch/arm/mm/proc-xsc3.S
+++ b/arch/arm/mm/proc-xsc3.S
@@ -450,6 +450,7 @@ xsc3_crval:
450 .type xsc3_processor_functions, #object 450 .type xsc3_processor_functions, #object
451ENTRY(xsc3_processor_functions) 451ENTRY(xsc3_processor_functions)
452 .word v5t_early_abort 452 .word v5t_early_abort
453 .word pabort_noifar
453 .word cpu_xsc3_proc_init 454 .word cpu_xsc3_proc_init
454 .word cpu_xsc3_proc_fin 455 .word cpu_xsc3_proc_fin
455 .word cpu_xsc3_reset 456 .word cpu_xsc3_reset
diff --git a/arch/arm/mm/proc-xscale.S b/arch/arm/mm/proc-xscale.S
index 1a6d89823dff..2dd85273976f 100644
--- a/arch/arm/mm/proc-xscale.S
+++ b/arch/arm/mm/proc-xscale.S
@@ -527,6 +527,7 @@ xscale_crval:
527 .type xscale_processor_functions, #object 527 .type xscale_processor_functions, #object
528ENTRY(xscale_processor_functions) 528ENTRY(xscale_processor_functions)
529 .word v5t_early_abort 529 .word v5t_early_abort
530 .word pabort_noifar
530 .word cpu_xscale_proc_init 531 .word cpu_xscale_proc_init
531 .word cpu_xscale_proc_fin 532 .word cpu_xscale_proc_fin
532 .word cpu_xscale_reset 533 .word cpu_xscale_reset
@@ -534,7 +535,6 @@ ENTRY(xscale_processor_functions)
534 .word cpu_xscale_dcache_clean_area 535 .word cpu_xscale_dcache_clean_area
535 .word cpu_xscale_switch_mm 536 .word cpu_xscale_switch_mm
536 .word cpu_xscale_set_pte_ext 537 .word cpu_xscale_set_pte_ext
537 .word pabort_noifar
538 .size xscale_processor_functions, . - xscale_processor_functions 538 .size xscale_processor_functions, . - xscale_processor_functions
539 539
540 .section ".rodata" 540 .section ".rodata"
diff --git a/arch/blackfin/Kconfig b/arch/blackfin/Kconfig
index 2dd1f300a5cf..795d0ac67c21 100644
--- a/arch/blackfin/Kconfig
+++ b/arch/blackfin/Kconfig
@@ -47,10 +47,6 @@ config GENERIC_IRQ_PROBE
47 bool 47 bool
48 default y 48 default y
49 49
50config GENERIC_TIME
51 bool
52 default n
53
54config GENERIC_GPIO 50config GENERIC_GPIO
55 bool 51 bool
56 default y 52 default y
@@ -224,16 +220,6 @@ config BF54x
224 depends on (BF542 || BF544 || BF547 || BF548 || BF549) 220 depends on (BF542 || BF544 || BF547 || BF548 || BF549)
225 default y 221 default y
226 222
227config BFIN_DUAL_CORE
228 bool
229 depends on (BF561)
230 default y
231
232config BFIN_SINGLE_CORE
233 bool
234 depends on !BFIN_DUAL_CORE
235 default y
236
237config MEM_GENERIC_BOARD 223config MEM_GENERIC_BOARD
238 bool 224 bool
239 depends on GENERIC_BOARD 225 depends on GENERIC_BOARD
@@ -263,7 +249,7 @@ config MEM_MT48LC8M32B2B5_7
263 249
264config MEM_MT48LC32M16A2TG_75 250config MEM_MT48LC32M16A2TG_75
265 bool 251 bool
266 depends on (BFIN527_EZKIT) 252 depends on (BFIN527_EZKIT || BFIN532_IP0X)
267 default y 253 default y
268 254
269source "arch/blackfin/mach-bf527/Kconfig" 255source "arch/blackfin/mach-bf527/Kconfig"
@@ -286,17 +272,34 @@ config CMDLINE
286 to the kernel, you may specify one here. As a minimum, you should specify 272 to the kernel, you may specify one here. As a minimum, you should specify
287 the memory size and the root device (e.g., mem=8M, root=/dev/nfs). 273 the memory size and the root device (e.g., mem=8M, root=/dev/nfs).
288 274
275config BOOT_LOAD
276 hex "Kernel load address for booting"
277 default "0x1000"
278 range 0x1000 0x20000000
279 help
280 This option allows you to set the load address of the kernel.
281 This can be useful if you are on a board which has a small amount
282 of memory or you wish to reserve some memory at the beginning of
283 the address space.
284
285 Note that you need to keep this value above 4k (0x1000) as this
286 memory region is used to capture NULL pointer references as well
287 as some core kernel functions.
288
289comment "Clock/PLL Setup" 289comment "Clock/PLL Setup"
290 290
291config CLKIN_HZ 291config CLKIN_HZ
292 int "Crystal Frequency in Hz" 292 int "Frequency of the crystal on the board in Hz"
293 default "11059200" if BFIN533_STAMP 293 default "11059200" if BFIN533_STAMP
294 default "27000000" if BFIN533_EZKIT 294 default "27000000" if BFIN533_EZKIT
295 default "25000000" if (BFIN537_STAMP || BFIN527_EZKIT || H8606_HVSISTEMAS) 295 default "25000000" if (BFIN537_STAMP || BFIN527_EZKIT || H8606_HVSISTEMAS)
296 default "30000000" if BFIN561_EZKIT 296 default "30000000" if BFIN561_EZKIT
297 default "24576000" if PNAV10 297 default "24576000" if PNAV10
298 default "10000000" if BFIN532_IP0X
298 help 299 help
299 The frequency of CLKIN crystal oscillator on the board in Hz. 300 The frequency of CLKIN crystal oscillator on the board in Hz.
301 Warning: This value should match the crystal on the board. Otherwise,
302 peripherals won't work properly.
300 303
301config BFIN_KERNEL_CLOCK 304config BFIN_KERNEL_CLOCK
302 bool "Re-program Clocks while Kernel boots?" 305 bool "Re-program Clocks while Kernel boots?"
@@ -307,6 +310,25 @@ config BFIN_KERNEL_CLOCK
307 are also not changed, and the Bootloader does 100% of the hardware 310 are also not changed, and the Bootloader does 100% of the hardware
308 configuration. 311 configuration.
309 312
313config MEM_SIZE
314 int "SDRAM Memory Size in MBytes"
315 depends on BFIN_KERNEL_CLOCK
316 default 64
317
318config MEM_ADD_WIDTH
319 int "Memory Address Width"
320 depends on BFIN_KERNEL_CLOCK
321 depends on (!BF54x)
322 range 8 11
323 default 9 if BFIN533_EZKIT
324 default 9 if BFIN561_EZKIT
325 default 9 if H8606_HVSISTEMAS
326 default 10 if BFIN527_EZKIT
327 default 10 if BFIN537_STAMP
328 default 11 if BFIN533_STAMP
329 default 10 if PNAV10
330 default 10 if BFIN532_IP0X
331
310config PLL_BYPASS 332config PLL_BYPASS
311 bool "Bypass PLL" 333 bool "Bypass PLL"
312 depends on BFIN_KERNEL_CLOCK 334 depends on BFIN_KERNEL_CLOCK
@@ -325,7 +347,7 @@ config VCO_MULT
325 range 1 64 347 range 1 64
326 default "22" if BFIN533_EZKIT 348 default "22" if BFIN533_EZKIT
327 default "45" if BFIN533_STAMP 349 default "45" if BFIN533_STAMP
328 default "20" if (BFIN537_STAMP || BFIN527_EZKIT || BFIN548_EZKIT) 350 default "20" if (BFIN537_STAMP || BFIN527_EZKIT || BFIN548_EZKIT || BFIN548_BLUETECHNIX_CM)
329 default "22" if BFIN533_BLUETECHNIX_CM 351 default "22" if BFIN533_BLUETECHNIX_CM
330 default "20" if BFIN537_BLUETECHNIX_CM 352 default "20" if BFIN537_BLUETECHNIX_CM
331 default "20" if BFIN561_BLUETECHNIX_CM 353 default "20" if BFIN561_BLUETECHNIX_CM
@@ -360,19 +382,33 @@ config SCLK_DIV
360 int "System Clock Divider" 382 int "System Clock Divider"
361 depends on BFIN_KERNEL_CLOCK 383 depends on BFIN_KERNEL_CLOCK
362 range 1 15 384 range 1 15
363 default 5 if BFIN533_EZKIT 385 default 5
364 default 5 if BFIN533_STAMP
365 default 4 if (BFIN537_STAMP || BFIN527_EZKIT || BFIN548_EZKIT)
366 default 5 if BFIN533_BLUETECHNIX_CM
367 default 4 if BFIN537_BLUETECHNIX_CM
368 default 4 if BFIN561_BLUETECHNIX_CM
369 default 5 if BFIN561_EZKIT
370 default 3 if H8606_HVSISTEMAS
371 help 386 help
372 This sets the frequency of the system clock (including SDRAM or DDR). 387 This sets the frequency of the system clock (including SDRAM or DDR).
373 This can be between 1 and 15 388 This can be between 1 and 15
374 System Clock = (PLL frequency) / (this setting) 389 System Clock = (PLL frequency) / (this setting)
375 390
391config MAX_MEM_SIZE
392 int "Max SDRAM Memory Size in MBytes"
393 depends on !BFIN_KERNEL_CLOCK && !MPU
394 default 512
395 help
396 This is the max memory size that the kernel will create CPLB
397 tables for. Your system will not be able to handle any more.
398
399choice
400 prompt "DDR SDRAM Chip Type"
401 depends on BFIN_KERNEL_CLOCK
402 depends on BF54x
403 default MEM_MT46V32M16_5B
404
405config MEM_MT46V32M16_6T
406 bool "MT46V32M16_6T"
407
408config MEM_MT46V32M16_5B
409 bool "MT46V32M16_5B"
410endchoice
411
376# 412#
377# Max & Min Speeds for various Chips 413# Max & Min Speeds for various Chips
378# 414#
@@ -415,42 +451,33 @@ comment "Kernel Timer/Scheduler"
415 451
416source kernel/Kconfig.hz 452source kernel/Kconfig.hz
417 453
418comment "Memory Setup" 454config GENERIC_TIME
419 455 bool "Generic time"
420config MEM_SIZE 456 default y
421 int "SDRAM Memory Size in MBytes"
422 default 32 if BFIN533_EZKIT
423 default 64 if BFIN527_EZKIT
424 default 64 if BFIN537_STAMP
425 default 64 if BFIN548_EZKIT
426 default 64 if BFIN561_EZKIT
427 default 128 if BFIN533_STAMP
428 default 64 if PNAV10
429 default 32 if H8606_HVSISTEMAS
430 457
431config MEM_ADD_WIDTH 458config GENERIC_CLOCKEVENTS
432 int "SDRAM Memory Address Width" 459 bool "Generic clock events"
433 depends on (!BF54x) 460 depends on GENERIC_TIME
434 default 9 if BFIN533_EZKIT 461 default y
435 default 9 if BFIN561_EZKIT
436 default 9 if H8606_HVSISTEMAS
437 default 10 if BFIN527_EZKIT
438 default 10 if BFIN537_STAMP
439 default 11 if BFIN533_STAMP
440 default 10 if PNAV10
441 462
463config CYCLES_CLOCKSOURCE
464 bool "Use 'CYCLES' as a clocksource (EXPERIMENTAL)"
465 depends on EXPERIMENTAL
466 depends on GENERIC_CLOCKEVENTS
467 depends on !BFIN_SCRATCH_REG_CYCLES
468 default n
469 help
470 If you say Y here, you will enable support for using the 'cycles'
471 registers as a clock source. Doing so means you will be unable to
472 safely write to the 'cycles' register during runtime. You will
473 still be able to read it (such as for performance monitoring), but
474 writing the registers will most likely crash the kernel.
442 475
443choice 476source kernel/time/Kconfig
444 prompt "DDR SDRAM Chip Type"
445 depends on BFIN548_EZKIT
446 default MEM_MT46V32M16_5B
447 477
448config MEM_MT46V32M16_6T 478comment "Memory Setup"
449 bool "MT46V32M16_6T"
450 479
451config MEM_MT46V32M16_5B 480comment "Misc"
452 bool "MT46V32M16_5B"
453endchoice
454 481
455config ENET_FLASH_PIN 482config ENET_FLASH_PIN
456 int "PF port/pin used for flash and ethernet sharing" 483 int "PF port/pin used for flash and ethernet sharing"
@@ -462,20 +489,6 @@ config ENET_FLASH_PIN
462 code. 489 code.
463 For example: PF0 --> 0,PF1 --> 1,PF2 --> 2, etc. 490 For example: PF0 --> 0,PF1 --> 1,PF2 --> 2, etc.
464 491
465config BOOT_LOAD
466 hex "Kernel load address for booting"
467 default "0x1000"
468 range 0x1000 0x20000000
469 help
470 This option allows you to set the load address of the kernel.
471 This can be useful if you are on a board which has a small amount
472 of memory or you wish to reserve some memory at the beginning of
473 the address space.
474
475 Note that you need to keep this value above 4k (0x1000) as this
476 memory region is used to capture NULL pointer references as well
477 as some core kernel functions.
478
479choice 492choice
480 prompt "Blackfin Exception Scratch Register" 493 prompt "Blackfin Exception Scratch Register"
481 default BFIN_SCRATCH_REG_RETN 494 default BFIN_SCRATCH_REG_RETN
@@ -661,14 +674,6 @@ endchoice
661 674
662source "mm/Kconfig" 675source "mm/Kconfig"
663 676
664config LARGE_ALLOCS
665 bool "Allow allocating large blocks (> 1MB) of memory"
666 help
667 Allow the slab memory allocator to keep chains for very large
668 memory sizes - upto 32MB. You may need this if your system has
669 a lot of RAM, and you need to able to allocate very large
670 contiguous chunks. If unsure, say N.
671
672config BFIN_GPTIMERS 677config BFIN_GPTIMERS
673 tristate "Enable Blackfin General Purpose Timers API" 678 tristate "Enable Blackfin General Purpose Timers API"
674 default n 679 default n
diff --git a/arch/blackfin/Makefile b/arch/blackfin/Makefile
index 75eba2ca7881..3cbe16caad4b 100644
--- a/arch/blackfin/Makefile
+++ b/arch/blackfin/Makefile
@@ -72,6 +72,11 @@ rev-$(CONFIG_BF_REV_ANY) := any
72KBUILD_CFLAGS += -mcpu=$(cpu-y)-$(rev-y) 72KBUILD_CFLAGS += -mcpu=$(cpu-y)-$(rev-y)
73KBUILD_AFLAGS += -mcpu=$(cpu-y)-$(rev-y) 73KBUILD_AFLAGS += -mcpu=$(cpu-y)-$(rev-y)
74 74
75# - we utilize the silicon rev from the toolchain, so move it over to the checkflags
76# - the l1_text attribute is Blackfin specific, so fake it out as used to kill warnings
77CHECKFLAGS_SILICON = $(shell echo "" | $(CPP) $(KBUILD_CFLAGS) -dD - 2>/dev/null | awk '$$2 == "__SILICON_REVISION__" { print $$3 }')
78CHECKFLAGS += -D__SILICON_REVISION__=$(CHECKFLAGS_SILICON) -Dl1_text=__used__
79
75head-y := arch/$(ARCH)/mach-$(MACHINE)/head.o arch/$(ARCH)/kernel/init_task.o 80head-y := arch/$(ARCH)/mach-$(MACHINE)/head.o arch/$(ARCH)/kernel/init_task.o
76 81
77core-y += arch/$(ARCH)/kernel/ arch/$(ARCH)/mm/ arch/$(ARCH)/mach-common/ 82core-y += arch/$(ARCH)/kernel/ arch/$(ARCH)/mm/ arch/$(ARCH)/mach-common/
diff --git a/arch/blackfin/boot/.gitignore b/arch/blackfin/boot/.gitignore
new file mode 100644
index 000000000000..3ae03994b88d
--- /dev/null
+++ b/arch/blackfin/boot/.gitignore
@@ -0,0 +1 @@
+vmImage
diff --git a/arch/blackfin/configs/BF527-EZKIT_defconfig b/arch/blackfin/configs/BF527-EZKIT_defconfig
index ae320dcfedef..64876dfc2e55 100644
--- a/arch/blackfin/configs/BF527-EZKIT_defconfig
+++ b/arch/blackfin/configs/BF527-EZKIT_defconfig
@@ -13,7 +13,7 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
13CONFIG_GENERIC_HWEIGHT=y 13CONFIG_GENERIC_HWEIGHT=y
14CONFIG_GENERIC_HARDIRQS=y 14CONFIG_GENERIC_HARDIRQS=y
15CONFIG_GENERIC_IRQ_PROBE=y 15CONFIG_GENERIC_IRQ_PROBE=y
16# CONFIG_GENERIC_TIME is not set 16CONFIG_GENERIC_TIME=y
17CONFIG_GENERIC_GPIO=y 17CONFIG_GENERIC_GPIO=y
18CONFIG_FORCE_MAX_ZONEORDER=14 18CONFIG_FORCE_MAX_ZONEORDER=14
19CONFIG_GENERIC_CALIBRATE_DELAY=y 19CONFIG_GENERIC_CALIBRATE_DELAY=y
@@ -250,7 +250,7 @@ CONFIG_HZ=250
250# 250#
251# Memory Setup 251# Memory Setup
252# 252#
253CONFIG_MEM_SIZE=64 253CONFIG_MAX_MEM_SIZE=512
254CONFIG_MEM_ADD_WIDTH=10 254CONFIG_MEM_ADD_WIDTH=10
255CONFIG_BOOT_LOAD=0x1000 255CONFIG_BOOT_LOAD=0x1000
256CONFIG_BFIN_SCRATCH_REG_RETN=y 256CONFIG_BFIN_SCRATCH_REG_RETN=y
@@ -720,8 +720,8 @@ CONFIG_BFIN_OTP=y
720# 720#
721CONFIG_SERIAL_BFIN=y 721CONFIG_SERIAL_BFIN=y
722CONFIG_SERIAL_BFIN_CONSOLE=y 722CONFIG_SERIAL_BFIN_CONSOLE=y
723# CONFIG_SERIAL_BFIN_DMA is not set 723CONFIG_SERIAL_BFIN_DMA=y
724CONFIG_SERIAL_BFIN_PIO=y 724# CONFIG_SERIAL_BFIN_PIO is not set
725# CONFIG_SERIAL_BFIN_UART0 is not set 725# CONFIG_SERIAL_BFIN_UART0 is not set
726CONFIG_SERIAL_BFIN_UART1=y 726CONFIG_SERIAL_BFIN_UART1=y
727# CONFIG_BFIN_UART1_CTSRTS is not set 727# CONFIG_BFIN_UART1_CTSRTS is not set
diff --git a/arch/blackfin/configs/BF533-EZKIT_defconfig b/arch/blackfin/configs/BF533-EZKIT_defconfig
index 9621caa60b5f..8d817ba01945 100644
--- a/arch/blackfin/configs/BF533-EZKIT_defconfig
+++ b/arch/blackfin/configs/BF533-EZKIT_defconfig
@@ -13,7 +13,7 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
13CONFIG_GENERIC_HWEIGHT=y 13CONFIG_GENERIC_HWEIGHT=y
14CONFIG_GENERIC_HARDIRQS=y 14CONFIG_GENERIC_HARDIRQS=y
15CONFIG_GENERIC_IRQ_PROBE=y 15CONFIG_GENERIC_IRQ_PROBE=y
16# CONFIG_GENERIC_TIME is not set 16CONFIG_GENERIC_TIME=y
17CONFIG_GENERIC_GPIO=y 17CONFIG_GENERIC_GPIO=y
18CONFIG_FORCE_MAX_ZONEORDER=14 18CONFIG_FORCE_MAX_ZONEORDER=14
19CONFIG_GENERIC_CALIBRATE_DELAY=y 19CONFIG_GENERIC_CALIBRATE_DELAY=y
@@ -212,7 +212,7 @@ CONFIG_HZ=250
212# 212#
213# Memory Setup 213# Memory Setup
214# 214#
215CONFIG_MEM_SIZE=32 215CONFIG_MAX_MEM_SIZE=512
216CONFIG_MEM_ADD_WIDTH=9 216CONFIG_MEM_ADD_WIDTH=9
217CONFIG_BOOT_LOAD=0x1000 217CONFIG_BOOT_LOAD=0x1000
218CONFIG_BFIN_SCRATCH_REG_RETN=y 218CONFIG_BFIN_SCRATCH_REG_RETN=y
diff --git a/arch/blackfin/configs/BF533-STAMP_defconfig b/arch/blackfin/configs/BF533-STAMP_defconfig
index b51e76ce7f4f..20d598d17bd1 100644
--- a/arch/blackfin/configs/BF533-STAMP_defconfig
+++ b/arch/blackfin/configs/BF533-STAMP_defconfig
@@ -13,7 +13,7 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
13CONFIG_GENERIC_HWEIGHT=y 13CONFIG_GENERIC_HWEIGHT=y
14CONFIG_GENERIC_HARDIRQS=y 14CONFIG_GENERIC_HARDIRQS=y
15CONFIG_GENERIC_IRQ_PROBE=y 15CONFIG_GENERIC_IRQ_PROBE=y
16# CONFIG_GENERIC_TIME is not set 16CONFIG_GENERIC_TIME=y
17CONFIG_GENERIC_GPIO=y 17CONFIG_GENERIC_GPIO=y
18CONFIG_FORCE_MAX_ZONEORDER=14 18CONFIG_FORCE_MAX_ZONEORDER=14
19CONFIG_GENERIC_CALIBRATE_DELAY=y 19CONFIG_GENERIC_CALIBRATE_DELAY=y
@@ -212,7 +212,7 @@ CONFIG_HZ=250
212# 212#
213# Memory Setup 213# Memory Setup
214# 214#
215CONFIG_MEM_SIZE=128 215CONFIG_MAX_MEM_SIZE=512
216CONFIG_MEM_ADD_WIDTH=11 216CONFIG_MEM_ADD_WIDTH=11
217CONFIG_ENET_FLASH_PIN=0 217CONFIG_ENET_FLASH_PIN=0
218CONFIG_BOOT_LOAD=0x1000 218CONFIG_BOOT_LOAD=0x1000
diff --git a/arch/blackfin/configs/BF537-STAMP_defconfig b/arch/blackfin/configs/BF537-STAMP_defconfig
index d45fa535dad7..b5189c8ba263 100644
--- a/arch/blackfin/configs/BF537-STAMP_defconfig
+++ b/arch/blackfin/configs/BF537-STAMP_defconfig
@@ -13,7 +13,7 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
13CONFIG_GENERIC_HWEIGHT=y 13CONFIG_GENERIC_HWEIGHT=y
14CONFIG_GENERIC_HARDIRQS=y 14CONFIG_GENERIC_HARDIRQS=y
15CONFIG_GENERIC_IRQ_PROBE=y 15CONFIG_GENERIC_IRQ_PROBE=y
16# CONFIG_GENERIC_TIME is not set 16CONFIG_GENERIC_TIME=y
17CONFIG_GENERIC_GPIO=y 17CONFIG_GENERIC_GPIO=y
18CONFIG_FORCE_MAX_ZONEORDER=14 18CONFIG_FORCE_MAX_ZONEORDER=14
19CONFIG_GENERIC_CALIBRATE_DELAY=y 19CONFIG_GENERIC_CALIBRATE_DELAY=y
@@ -220,7 +220,7 @@ CONFIG_HZ=250
220# 220#
221# Memory Setup 221# Memory Setup
222# 222#
223CONFIG_MEM_SIZE=64 223CONFIG_MAX_MEM_SIZE=512
224CONFIG_MEM_ADD_WIDTH=10 224CONFIG_MEM_ADD_WIDTH=10
225CONFIG_BOOT_LOAD=0x1000 225CONFIG_BOOT_LOAD=0x1000
226CONFIG_BFIN_SCRATCH_REG_RETN=y 226CONFIG_BFIN_SCRATCH_REG_RETN=y
diff --git a/arch/blackfin/configs/BF548-EZKIT_defconfig b/arch/blackfin/configs/BF548-EZKIT_defconfig
index c9707f7665ad..5bfdfb287d13 100644
--- a/arch/blackfin/configs/BF548-EZKIT_defconfig
+++ b/arch/blackfin/configs/BF548-EZKIT_defconfig
@@ -13,7 +13,7 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
13CONFIG_GENERIC_HWEIGHT=y 13CONFIG_GENERIC_HWEIGHT=y
14CONFIG_GENERIC_HARDIRQS=y 14CONFIG_GENERIC_HARDIRQS=y
15CONFIG_GENERIC_IRQ_PROBE=y 15CONFIG_GENERIC_IRQ_PROBE=y
16# CONFIG_GENERIC_TIME is not set 16CONFIG_GENERIC_TIME=y
17CONFIG_GENERIC_GPIO=y 17CONFIG_GENERIC_GPIO=y
18CONFIG_FORCE_MAX_ZONEORDER=14 18CONFIG_FORCE_MAX_ZONEORDER=14
19CONFIG_GENERIC_CALIBRATE_DELAY=y 19CONFIG_GENERIC_CALIBRATE_DELAY=y
@@ -285,7 +285,7 @@ CONFIG_HZ=250
285# 285#
286# Memory Setup 286# Memory Setup
287# 287#
288CONFIG_MEM_SIZE=64 288CONFIG_MAX_MEM_SIZE=512
289# CONFIG_MEM_MT46V32M16_6T is not set 289# CONFIG_MEM_MT46V32M16_6T is not set
290CONFIG_MEM_MT46V32M16_5B=y 290CONFIG_MEM_MT46V32M16_5B=y
291CONFIG_BOOT_LOAD=0x1000 291CONFIG_BOOT_LOAD=0x1000
@@ -813,8 +813,8 @@ CONFIG_HW_CONSOLE=y
813# 813#
814CONFIG_SERIAL_BFIN=y 814CONFIG_SERIAL_BFIN=y
815CONFIG_SERIAL_BFIN_CONSOLE=y 815CONFIG_SERIAL_BFIN_CONSOLE=y
816# CONFIG_SERIAL_BFIN_DMA is not set 816CONFIG_SERIAL_BFIN_DMA=y
817CONFIG_SERIAL_BFIN_PIO=y 817# CONFIG_SERIAL_BFIN_PIO is not set
818# CONFIG_SERIAL_BFIN_UART0 is not set 818# CONFIG_SERIAL_BFIN_UART0 is not set
819CONFIG_SERIAL_BFIN_UART1=y 819CONFIG_SERIAL_BFIN_UART1=y
820# CONFIG_BFIN_UART1_CTSRTS is not set 820# CONFIG_BFIN_UART1_CTSRTS is not set
diff --git a/arch/blackfin/configs/BF561-EZKIT_defconfig b/arch/blackfin/configs/BF561-EZKIT_defconfig
index 4d8a63331309..b4a20c890816 100644
--- a/arch/blackfin/configs/BF561-EZKIT_defconfig
+++ b/arch/blackfin/configs/BF561-EZKIT_defconfig
@@ -13,7 +13,7 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
13CONFIG_GENERIC_HWEIGHT=y 13CONFIG_GENERIC_HWEIGHT=y
14CONFIG_GENERIC_HARDIRQS=y 14CONFIG_GENERIC_HARDIRQS=y
15CONFIG_GENERIC_IRQ_PROBE=y 15CONFIG_GENERIC_IRQ_PROBE=y
16# CONFIG_GENERIC_TIME is not set 16CONFIG_GENERIC_TIME=y
17CONFIG_GENERIC_GPIO=y 17CONFIG_GENERIC_GPIO=y
18CONFIG_FORCE_MAX_ZONEORDER=14 18CONFIG_FORCE_MAX_ZONEORDER=14
19CONFIG_GENERIC_CALIBRATE_DELAY=y 19CONFIG_GENERIC_CALIBRATE_DELAY=y
@@ -256,7 +256,7 @@ CONFIG_HZ=250
256# 256#
257# Memory Setup 257# Memory Setup
258# 258#
259CONFIG_MEM_SIZE=64 259CONFIG_MAX_MEM_SIZE=512
260CONFIG_MEM_ADD_WIDTH=9 260CONFIG_MEM_ADD_WIDTH=9
261CONFIG_BOOT_LOAD=0x1000 261CONFIG_BOOT_LOAD=0x1000
262CONFIG_BFIN_SCRATCH_REG_RETN=y 262CONFIG_BFIN_SCRATCH_REG_RETN=y
diff --git a/arch/blackfin/configs/CM-BF533_defconfig b/arch/blackfin/configs/CM-BF533_defconfig
new file mode 100644
index 000000000000..560890fe0d30
--- /dev/null
+++ b/arch/blackfin/configs/CM-BF533_defconfig
@@ -0,0 +1,912 @@
1#
2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.22.16
4#
5# CONFIG_MMU is not set
6# CONFIG_FPU is not set
7CONFIG_RWSEM_GENERIC_SPINLOCK=y
8# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
9CONFIG_BLACKFIN=y
10CONFIG_ZONE_DMA=y
11CONFIG_SEMAPHORE_SLEEPERS=y
12CONFIG_GENERIC_FIND_NEXT_BIT=y
13CONFIG_GENERIC_HWEIGHT=y
14CONFIG_GENERIC_HARDIRQS=y
15CONFIG_GENERIC_IRQ_PROBE=y
16CONFIG_GENERIC_TIME=y
17CONFIG_GENERIC_GPIO=y
18CONFIG_FORCE_MAX_ZONEORDER=14
19CONFIG_GENERIC_CALIBRATE_DELAY=y
20CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
21
22#
23# Code maturity level options
24#
25CONFIG_EXPERIMENTAL=y
26CONFIG_BROKEN_ON_SMP=y
27CONFIG_INIT_ENV_ARG_LIMIT=32
28
29#
30# General setup
31#
32CONFIG_LOCALVERSION=""
33CONFIG_LOCALVERSION_AUTO=y
34CONFIG_SYSVIPC=y
35# CONFIG_IPC_NS is not set
36CONFIG_SYSVIPC_SYSCTL=y
37# CONFIG_POSIX_MQUEUE is not set
38# CONFIG_BSD_PROCESS_ACCT is not set
39# CONFIG_TASKSTATS is not set
40# CONFIG_UTS_NS is not set
41# CONFIG_AUDIT is not set
42# CONFIG_IKCONFIG is not set
43CONFIG_LOG_BUF_SHIFT=14
44CONFIG_SYSFS_DEPRECATED=y
45# CONFIG_RELAY is not set
46# CONFIG_BLK_DEV_INITRD is not set
47# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
48CONFIG_SYSCTL=y
49CONFIG_EMBEDDED=y
50# CONFIG_UID16 is not set
51CONFIG_SYSCTL_SYSCALL=y
52CONFIG_KALLSYMS=y
53# CONFIG_KALLSYMS_EXTRA_PASS is not set
54# CONFIG_HOTPLUG is not set
55CONFIG_PRINTK=y
56CONFIG_BUG=y
57CONFIG_ELF_CORE=y
58CONFIG_BASE_FULL=y
59CONFIG_FUTEX=y
60CONFIG_ANON_INODES=y
61CONFIG_EPOLL=y
62CONFIG_SIGNALFD=y
63CONFIG_EVENTFD=y
64CONFIG_VM_EVENT_COUNTERS=y
65CONFIG_BIG_ORDER_ALLOC_NOFAIL_MAGIC=3
66# CONFIG_NP2 is not set
67CONFIG_SLAB=y
68# CONFIG_SLUB is not set
69# CONFIG_SLOB is not set
70CONFIG_RT_MUTEXES=y
71CONFIG_TINY_SHMEM=y
72CONFIG_BASE_SMALL=0
73
74#
75# Loadable module support
76#
77CONFIG_MODULES=y
78CONFIG_MODULE_UNLOAD=y
79# CONFIG_MODULE_FORCE_UNLOAD is not set
80# CONFIG_MODVERSIONS is not set
81# CONFIG_MODULE_SRCVERSION_ALL is not set
82CONFIG_KMOD=y
83
84#
85# Block layer
86#
87CONFIG_BLOCK=y
88# CONFIG_LBD is not set
89# CONFIG_BLK_DEV_IO_TRACE is not set
90# CONFIG_LSF is not set
91
92#
93# IO Schedulers
94#
95CONFIG_IOSCHED_NOOP=y
96# CONFIG_IOSCHED_AS is not set
97# CONFIG_IOSCHED_DEADLINE is not set
98CONFIG_IOSCHED_CFQ=y
99# CONFIG_DEFAULT_AS is not set
100# CONFIG_DEFAULT_DEADLINE is not set
101# CONFIG_DEFAULT_CFQ is not set
102CONFIG_DEFAULT_NOOP=y
103CONFIG_DEFAULT_IOSCHED="noop"
104CONFIG_PREEMPT_NONE=y
105# CONFIG_PREEMPT_VOLUNTARY is not set
106# CONFIG_PREEMPT is not set
107
108#
109# Blackfin Processor Options
110#
111
112#
113# Processor and Board Settings
114#
115# CONFIG_BF522 is not set
116# CONFIG_BF523 is not set
117# CONFIG_BF524 is not set
118# CONFIG_BF525 is not set
119# CONFIG_BF526 is not set
120# CONFIG_BF527 is not set
121# CONFIG_BF531 is not set
122# CONFIG_BF532 is not set
123CONFIG_BF533=y
124# CONFIG_BF534 is not set
125# CONFIG_BF536 is not set
126# CONFIG_BF537 is not set
127# CONFIG_BF542 is not set
128# CONFIG_BF544 is not set
129# CONFIG_BF547 is not set
130# CONFIG_BF548 is not set
131# CONFIG_BF549 is not set
132# CONFIG_BF561 is not set
133# CONFIG_BF_REV_0_0 is not set
134# CONFIG_BF_REV_0_1 is not set
135# CONFIG_BF_REV_0_2 is not set
136CONFIG_BF_REV_0_3=y
137# CONFIG_BF_REV_0_4 is not set
138# CONFIG_BF_REV_0_5 is not set
139# CONFIG_BF_REV_ANY is not set
140# CONFIG_BF_REV_NONE is not set
141CONFIG_BF53x=y
142CONFIG_BFIN_SINGLE_CORE=y
143CONFIG_MEM_MT48LC16M16A2TG_75=y
144# CONFIG_BFIN533_EZKIT is not set
145# CONFIG_BFIN533_STAMP is not set
146CONFIG_BFIN533_BLUETECHNIX_CM=y
147# CONFIG_H8606_HVSISTEMAS is not set
148# CONFIG_GENERIC_BF533_BOARD is not set
149
150#
151# BF533/2/1 Specific Configuration
152#
153
154#
155# Interrupt Priority Assignment
156#
157
158#
159# Priority
160#
161CONFIG_UART_ERROR=7
162CONFIG_SPORT0_ERROR=7
163CONFIG_SPI_ERROR=7
164CONFIG_SPORT1_ERROR=7
165CONFIG_PPI_ERROR=7
166CONFIG_DMA_ERROR=7
167CONFIG_PLLWAKE_ERROR=7
168CONFIG_RTC_ERROR=8
169CONFIG_DMA0_PPI=8
170CONFIG_DMA1_SPORT0RX=9
171CONFIG_DMA2_SPORT0TX=9
172CONFIG_DMA3_SPORT1RX=9
173CONFIG_DMA4_SPORT1TX=9
174CONFIG_DMA5_SPI=10
175CONFIG_DMA6_UARTRX=10
176CONFIG_DMA7_UARTTX=10
177CONFIG_TIMER0=11
178CONFIG_TIMER1=11
179CONFIG_TIMER2=11
180CONFIG_PFA=12
181CONFIG_PFB=12
182CONFIG_MEMDMA0=13
183CONFIG_MEMDMA1=13
184CONFIG_WDTIMER=13
185
186#
187# Board customizations
188#
189# CONFIG_CMDLINE_BOOL is not set
190
191#
192# Clock/PLL Setup
193#
194CONFIG_CLKIN_HZ=25000000
195# CONFIG_BFIN_KERNEL_CLOCK is not set
196CONFIG_MAX_VCO_HZ=750000000
197CONFIG_MIN_VCO_HZ=50000000
198CONFIG_MAX_SCLK_HZ=133333333
199CONFIG_MIN_SCLK_HZ=27000000
200
201#
202# Kernel Timer/Scheduler
203#
204# CONFIG_HZ_100 is not set
205CONFIG_HZ_250=y
206# CONFIG_HZ_300 is not set
207# CONFIG_HZ_1000 is not set
208CONFIG_HZ=250
209
210#
211# Memory Setup
212#
213CONFIG_MAX_MEM_SIZE=32
214CONFIG_MEM_ADD_WIDTH=9
215CONFIG_BOOT_LOAD=0x1000
216CONFIG_BFIN_SCRATCH_REG_RETN=y
217# CONFIG_BFIN_SCRATCH_REG_RETE is not set
218# CONFIG_BFIN_SCRATCH_REG_CYCLES is not set
219
220#
221# Blackfin Kernel Optimizations
222#
223
224#
225# Memory Optimizations
226#
227CONFIG_I_ENTRY_L1=y
228CONFIG_EXCPT_IRQ_SYSC_L1=y
229CONFIG_DO_IRQ_L1=y
230CONFIG_CORE_TIMER_IRQ_L1=y
231CONFIG_IDLE_L1=y
232CONFIG_SCHEDULE_L1=y
233CONFIG_ARITHMETIC_OPS_L1=y
234CONFIG_ACCESS_OK_L1=y
235CONFIG_MEMSET_L1=y
236CONFIG_MEMCPY_L1=y
237CONFIG_SYS_BFIN_SPINLOCK_L1=y
238CONFIG_IP_CHECKSUM_L1=y
239CONFIG_CACHELINE_ALIGNED_L1=y
240CONFIG_SYSCALL_TAB_L1=y
241CONFIG_CPLB_SWITCH_TAB_L1=y
242CONFIG_RAMKERNEL=y
243# CONFIG_ROMKERNEL is not set
244CONFIG_SELECT_MEMORY_MODEL=y
245CONFIG_FLATMEM_MANUAL=y
246# CONFIG_DISCONTIGMEM_MANUAL is not set
247# CONFIG_SPARSEMEM_MANUAL is not set
248CONFIG_FLATMEM=y
249CONFIG_FLAT_NODE_MEM_MAP=y
250# CONFIG_SPARSEMEM_STATIC is not set
251CONFIG_SPLIT_PTLOCK_CPUS=4
252# CONFIG_RESOURCES_64BIT is not set
253CONFIG_ZONE_DMA_FLAG=1
254CONFIG_LARGE_ALLOCS=y
255# CONFIG_BFIN_GPTIMERS is not set
256CONFIG_BFIN_DMA_5XX=y
257# CONFIG_DMA_UNCACHED_2M is not set
258CONFIG_DMA_UNCACHED_1M=y
259# CONFIG_DMA_UNCACHED_NONE is not set
260
261#
262# Cache Support
263#
264CONFIG_BFIN_ICACHE=y
265CONFIG_BFIN_DCACHE=y
266# CONFIG_BFIN_DCACHE_BANKA is not set
267# CONFIG_BFIN_ICACHE_LOCK is not set
268CONFIG_BFIN_WB=y
269# CONFIG_BFIN_WT is not set
270CONFIG_L1_MAX_PIECE=16
271# CONFIG_MPU is not set
272
273#
274# Asynchonous Memory Configuration
275#
276
277#
278# EBIU_AMGCTL Global Control
279#
280CONFIG_C_AMCKEN=y
281CONFIG_C_CDPRIO=y
282# CONFIG_C_AMBEN is not set
283# CONFIG_C_AMBEN_B0 is not set
284# CONFIG_C_AMBEN_B0_B1 is not set
285# CONFIG_C_AMBEN_B0_B1_B2 is not set
286CONFIG_C_AMBEN_ALL=y
287
288#
289# EBIU_AMBCTL Control
290#
291CONFIG_BANK_0=0x7BB0
292CONFIG_BANK_1=0x7BB0
293CONFIG_BANK_2=0x7BB0
294CONFIG_BANK_3=0xFFC3
295
296#
297# Bus options (PCI, PCMCIA, EISA, MCA, ISA)
298#
299# CONFIG_PCI is not set
300# CONFIG_ARCH_SUPPORTS_MSI is not set
301
302#
303# PCCARD (PCMCIA/CardBus) support
304#
305
306#
307# Executable file formats
308#
309CONFIG_BINFMT_ELF_FDPIC=y
310CONFIG_BINFMT_FLAT=y
311CONFIG_BINFMT_ZFLAT=y
312CONFIG_BINFMT_SHARED_FLAT=y
313# CONFIG_BINFMT_MISC is not set
314
315#
316# Power management options
317#
318# CONFIG_PM is not set
319# CONFIG_PM_WAKEUP_BY_GPIO is not set
320
321#
322# CPU Frequency scaling
323#
324# CONFIG_CPU_FREQ is not set
325
326#
327# Networking
328#
329CONFIG_NET=y
330
331#
332# Networking options
333#
334CONFIG_PACKET=y
335# CONFIG_PACKET_MMAP is not set
336CONFIG_UNIX=y
337CONFIG_XFRM=y
338# CONFIG_XFRM_USER is not set
339# CONFIG_XFRM_SUB_POLICY is not set
340# CONFIG_XFRM_MIGRATE is not set
341# CONFIG_NET_KEY is not set
342CONFIG_INET=y
343# CONFIG_IP_MULTICAST is not set
344# CONFIG_IP_ADVANCED_ROUTER is not set
345CONFIG_IP_FIB_HASH=y
346# CONFIG_IP_PNP is not set
347# CONFIG_NET_IPIP is not set
348# CONFIG_NET_IPGRE is not set
349# CONFIG_ARPD is not set
350CONFIG_SYN_COOKIES=y
351# CONFIG_INET_AH is not set
352# CONFIG_INET_ESP is not set
353# CONFIG_INET_IPCOMP is not set
354# CONFIG_INET_XFRM_TUNNEL is not set
355# CONFIG_INET_TUNNEL is not set
356CONFIG_INET_XFRM_MODE_TRANSPORT=y
357CONFIG_INET_XFRM_MODE_TUNNEL=y
358CONFIG_INET_XFRM_MODE_BEET=y
359CONFIG_INET_DIAG=y
360CONFIG_INET_TCP_DIAG=y
361# CONFIG_TCP_CONG_ADVANCED is not set
362CONFIG_TCP_CONG_CUBIC=y
363CONFIG_DEFAULT_TCP_CONG="cubic"
364# CONFIG_TCP_MD5SIG is not set
365# CONFIG_IPV6 is not set
366# CONFIG_INET6_XFRM_TUNNEL is not set
367# CONFIG_INET6_TUNNEL is not set
368# CONFIG_NETLABEL is not set
369# CONFIG_NETWORK_SECMARK is not set
370# CONFIG_NETFILTER is not set
371# CONFIG_IP_DCCP is not set
372# CONFIG_IP_SCTP is not set
373# CONFIG_TIPC is not set
374# CONFIG_ATM is not set
375# CONFIG_BRIDGE is not set
376# CONFIG_VLAN_8021Q is not set
377# CONFIG_DECNET is not set
378# CONFIG_LLC2 is not set
379# CONFIG_IPX is not set
380# CONFIG_ATALK is not set
381# CONFIG_X25 is not set
382# CONFIG_LAPB is not set
383# CONFIG_ECONET is not set
384# CONFIG_WAN_ROUTER is not set
385
386#
387# QoS and/or fair queueing
388#
389# CONFIG_NET_SCHED is not set
390
391#
392# Network testing
393#
394# CONFIG_NET_PKTGEN is not set
395# CONFIG_HAMRADIO is not set
396# CONFIG_IRDA is not set
397# CONFIG_BT is not set
398# CONFIG_AF_RXRPC is not set
399
400#
401# Wireless
402#
403# CONFIG_CFG80211 is not set
404# CONFIG_WIRELESS_EXT is not set
405# CONFIG_MAC80211 is not set
406# CONFIG_IEEE80211 is not set
407# CONFIG_RFKILL is not set
408
409#
410# Device Drivers
411#
412
413#
414# Generic Driver Options
415#
416CONFIG_STANDALONE=y
417CONFIG_PREVENT_FIRMWARE_BUILD=y
418# CONFIG_SYS_HYPERVISOR is not set
419
420#
421# Connector - unified userspace <-> kernelspace linker
422#
423# CONFIG_CONNECTOR is not set
424CONFIG_MTD=y
425# CONFIG_MTD_DEBUG is not set
426# CONFIG_MTD_CONCAT is not set
427CONFIG_MTD_PARTITIONS=y
428# CONFIG_MTD_REDBOOT_PARTS is not set
429# CONFIG_MTD_CMDLINE_PARTS is not set
430
431#
432# User Modules And Translation Layers
433#
434CONFIG_MTD_CHAR=y
435CONFIG_MTD_BLKDEVS=y
436CONFIG_MTD_BLOCK=y
437# CONFIG_FTL is not set
438# CONFIG_NFTL is not set
439# CONFIG_INFTL is not set
440# CONFIG_RFD_FTL is not set
441# CONFIG_SSFDC is not set
442
443#
444# RAM/ROM/Flash chip drivers
445#
446# CONFIG_MTD_CFI is not set
447# CONFIG_MTD_JEDECPROBE is not set
448CONFIG_MTD_MAP_BANK_WIDTH_1=y
449CONFIG_MTD_MAP_BANK_WIDTH_2=y
450CONFIG_MTD_MAP_BANK_WIDTH_4=y
451# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
452# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
453# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
454CONFIG_MTD_CFI_I1=y
455CONFIG_MTD_CFI_I2=y
456# CONFIG_MTD_CFI_I4 is not set
457# CONFIG_MTD_CFI_I8 is not set
458CONFIG_MTD_RAM=y
459# CONFIG_MTD_ROM is not set
460# CONFIG_MTD_ABSENT is not set
461
462#
463# Mapping drivers for chip access
464#
465# CONFIG_MTD_COMPLEX_MAPPINGS is not set
466CONFIG_MTD_UCLINUX=y
467# CONFIG_MTD_PLATRAM is not set
468
469#
470# Self-contained MTD device drivers
471#
472# CONFIG_MTD_SLRAM is not set
473# CONFIG_MTD_PHRAM is not set
474# CONFIG_MTD_MTDRAM is not set
475# CONFIG_MTD_BLOCK2MTD is not set
476
477#
478# Disk-On-Chip Device Drivers
479#
480# CONFIG_MTD_DOC2000 is not set
481# CONFIG_MTD_DOC2001 is not set
482# CONFIG_MTD_DOC2001PLUS is not set
483# CONFIG_MTD_NAND is not set
484# CONFIG_MTD_ONENAND is not set
485
486#
487# UBI - Unsorted block images
488#
489# CONFIG_MTD_UBI is not set
490
491#
492# Parallel port support
493#
494# CONFIG_PARPORT is not set
495
496#
497# Plug and Play support
498#
499# CONFIG_PNPACPI is not set
500
501#
502# Block devices
503#
504# CONFIG_BLK_DEV_COW_COMMON is not set
505# CONFIG_BLK_DEV_LOOP is not set
506# CONFIG_BLK_DEV_NBD is not set
507CONFIG_BLK_DEV_RAM=y
508CONFIG_BLK_DEV_RAM_COUNT=16
509CONFIG_BLK_DEV_RAM_SIZE=4096
510CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
511# CONFIG_CDROM_PKTCDVD is not set
512# CONFIG_ATA_OVER_ETH is not set
513
514#
515# Misc devices
516#
517# CONFIG_IDE is not set
518
519#
520# SCSI device support
521#
522# CONFIG_RAID_ATTRS is not set
523# CONFIG_SCSI is not set
524# CONFIG_SCSI_NETLINK is not set
525# CONFIG_ATA is not set
526
527#
528# Multi-device support (RAID and LVM)
529#
530# CONFIG_MD is not set
531
532#
533# Network device support
534#
535CONFIG_NETDEVICES=y
536# CONFIG_DUMMY is not set
537# CONFIG_BONDING is not set
538# CONFIG_EQUALIZER is not set
539# CONFIG_TUN is not set
540# CONFIG_PHYLIB is not set
541
542#
543# Ethernet (10 or 100Mbit)
544#
545CONFIG_NET_ETHERNET=y
546CONFIG_MII=y
547CONFIG_SMC91X=y
548# CONFIG_SMSC911X is not set
549# CONFIG_DM9000 is not set
550CONFIG_NETDEV_1000=y
551# CONFIG_AX88180 is not set
552CONFIG_NETDEV_10000=y
553
554#
555# Wireless LAN
556#
557# CONFIG_WLAN_PRE80211 is not set
558# CONFIG_WLAN_80211 is not set
559# CONFIG_WAN is not set
560# CONFIG_PPP is not set
561# CONFIG_SLIP is not set
562# CONFIG_SHAPER is not set
563# CONFIG_NETCONSOLE is not set
564# CONFIG_NETPOLL is not set
565# CONFIG_NET_POLL_CONTROLLER is not set
566
567#
568# ISDN subsystem
569#
570# CONFIG_ISDN is not set
571
572#
573# Telephony Support
574#
575# CONFIG_PHONE is not set
576
577#
578# Input device support
579#
580# CONFIG_INPUT is not set
581
582#
583# Hardware I/O ports
584#
585# CONFIG_SERIO is not set
586# CONFIG_GAMEPORT is not set
587
588#
589# Character devices
590#
591# CONFIG_AD9960 is not set
592# CONFIG_SPI_ADC_BF533 is not set
593# CONFIG_BF5xx_PFLAGS is not set
594# CONFIG_BF5xx_PPIFCD is not set
595# CONFIG_BFIN_SIMPLE_TIMER is not set
596# CONFIG_BF5xx_PPI is not set
597CONFIG_BFIN_SPORT=y
598# CONFIG_BFIN_TIMER_LATENCY is not set
599# CONFIG_VT is not set
600# CONFIG_SERIAL_NONSTANDARD is not set
601
602#
603# Serial drivers
604#
605# CONFIG_SERIAL_8250 is not set
606
607#
608# Non-8250 serial port support
609#
610CONFIG_SERIAL_BFIN=y
611CONFIG_SERIAL_BFIN_CONSOLE=y
612CONFIG_SERIAL_BFIN_DMA=y
613# CONFIG_SERIAL_BFIN_PIO is not set
614CONFIG_SERIAL_BFIN_UART0=y
615# CONFIG_BFIN_UART0_CTSRTS is not set
616CONFIG_SERIAL_CORE=y
617CONFIG_SERIAL_CORE_CONSOLE=y
618# CONFIG_SERIAL_BFIN_SPORT is not set
619CONFIG_UNIX98_PTYS=y
620CONFIG_LEGACY_PTYS=y
621CONFIG_LEGACY_PTY_COUNT=256
622
623#
624# CAN, the car bus and industrial fieldbus
625#
626# CONFIG_CAN4LINUX is not set
627
628#
629# IPMI
630#
631# CONFIG_IPMI_HANDLER is not set
632# CONFIG_WATCHDOG is not set
633# CONFIG_HW_RANDOM is not set
634# CONFIG_GEN_RTC is not set
635# CONFIG_R3964 is not set
636# CONFIG_RAW_DRIVER is not set
637
638#
639# TPM devices
640#
641# CONFIG_TCG_TPM is not set
642# CONFIG_I2C is not set
643
644#
645# SPI support
646#
647# CONFIG_SPI is not set
648# CONFIG_SPI_MASTER is not set
649
650#
651# Dallas's 1-wire bus
652#
653# CONFIG_W1 is not set
654CONFIG_HWMON=y
655# CONFIG_HWMON_VID is not set
656# CONFIG_SENSORS_ABITUGURU is not set
657# CONFIG_SENSORS_F71805F is not set
658# CONFIG_SENSORS_PC87427 is not set
659# CONFIG_SENSORS_SMSC47M1 is not set
660# CONFIG_SENSORS_SMSC47B397 is not set
661# CONFIG_SENSORS_VT1211 is not set
662# CONFIG_SENSORS_W83627HF is not set
663# CONFIG_HWMON_DEBUG_CHIP is not set
664
665#
666# Multifunction device drivers
667#
668# CONFIG_MFD_SM501 is not set
669
670#
671# Multimedia devices
672#
673# CONFIG_VIDEO_DEV is not set
674# CONFIG_DVB_CORE is not set
675CONFIG_DAB=y
676
677#
678# Graphics support
679#
680# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
681
682#
683# Display device support
684#
685# CONFIG_DISPLAY_SUPPORT is not set
686# CONFIG_VGASTATE is not set
687# CONFIG_FB is not set
688
689#
690# Sound
691#
692# CONFIG_SOUND is not set
693
694#
695# USB support
696#
697CONFIG_USB_ARCH_HAS_HCD=y
698# CONFIG_USB_ARCH_HAS_OHCI is not set
699# CONFIG_USB_ARCH_HAS_EHCI is not set
700# CONFIG_USB is not set
701
702#
703# Enable Host or Gadget support to see Inventra options
704#
705
706#
707# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
708#
709
710#
711# USB Gadget Support
712#
713# CONFIG_USB_GADGET is not set
714# CONFIG_MMC is not set
715
716#
717# LED devices
718#
719# CONFIG_NEW_LEDS is not set
720
721#
722# LED drivers
723#
724
725#
726# LED Triggers
727#
728
729#
730# InfiniBand support
731#
732
733#
734# EDAC - error detection and reporting (RAS) (EXPERIMENTAL)
735#
736
737#
738# Real Time Clock
739#
740# CONFIG_RTC_CLASS is not set
741
742#
743# DMA Engine support
744#
745# CONFIG_DMA_ENGINE is not set
746
747#
748# DMA Clients
749#
750
751#
752# DMA Devices
753#
754
755#
756# PBX support
757#
758# CONFIG_PBX is not set
759
760#
761# File systems
762#
763CONFIG_EXT2_FS=y
764CONFIG_EXT2_FS_XATTR=y
765# CONFIG_EXT2_FS_POSIX_ACL is not set
766# CONFIG_EXT2_FS_SECURITY is not set
767# CONFIG_EXT3_FS is not set
768# CONFIG_EXT4DEV_FS is not set
769CONFIG_FS_MBCACHE=y
770# CONFIG_REISERFS_FS is not set
771# CONFIG_JFS_FS is not set
772# CONFIG_FS_POSIX_ACL is not set
773# CONFIG_XFS_FS is not set
774# CONFIG_GFS2_FS is not set
775# CONFIG_OCFS2_FS is not set
776# CONFIG_MINIX_FS is not set
777# CONFIG_ROMFS_FS is not set
778CONFIG_INOTIFY=y
779CONFIG_INOTIFY_USER=y
780# CONFIG_QUOTA is not set
781CONFIG_DNOTIFY=y
782# CONFIG_AUTOFS_FS is not set
783# CONFIG_AUTOFS4_FS is not set
784# CONFIG_FUSE_FS is not set
785
786#
787# CD-ROM/DVD Filesystems
788#
789# CONFIG_ISO9660_FS is not set
790# CONFIG_UDF_FS is not set
791
792#
793# DOS/FAT/NT Filesystems
794#
795# CONFIG_MSDOS_FS is not set
796# CONFIG_VFAT_FS is not set
797# CONFIG_NTFS_FS is not set
798
799#
800# Pseudo filesystems
801#
802CONFIG_PROC_FS=y
803CONFIG_PROC_SYSCTL=y
804CONFIG_SYSFS=y
805# CONFIG_TMPFS is not set
806# CONFIG_HUGETLB_PAGE is not set
807CONFIG_RAMFS=y
808# CONFIG_CONFIGFS_FS is not set
809
810#
811# Miscellaneous filesystems
812#
813# CONFIG_ADFS_FS is not set
814# CONFIG_AFFS_FS is not set
815# CONFIG_HFS_FS is not set
816# CONFIG_HFSPLUS_FS is not set
817# CONFIG_BEFS_FS is not set
818# CONFIG_BFS_FS is not set
819# CONFIG_EFS_FS is not set
820# CONFIG_YAFFS_FS is not set
821# CONFIG_JFFS2_FS is not set
822# CONFIG_CRAMFS is not set
823# CONFIG_VXFS_FS is not set
824# CONFIG_HPFS_FS is not set
825# CONFIG_QNX4FS_FS is not set
826# CONFIG_SYSV_FS is not set
827# CONFIG_UFS_FS is not set
828
829#
830# Network File Systems
831#
832# CONFIG_NFS_FS is not set
833# CONFIG_NFSD is not set
834# CONFIG_SMB_FS is not set
835# CONFIG_CIFS is not set
836# CONFIG_NCP_FS is not set
837# CONFIG_CODA_FS is not set
838# CONFIG_AFS_FS is not set
839# CONFIG_9P_FS is not set
840
841#
842# Partition Types
843#
844# CONFIG_PARTITION_ADVANCED is not set
845CONFIG_MSDOS_PARTITION=y
846
847#
848# Native Language Support
849#
850# CONFIG_NLS is not set
851
852#
853# Distributed Lock Manager
854#
855# CONFIG_DLM is not set
856
857#
858# Profiling support
859#
860# CONFIG_PROFILING is not set
861
862#
863# Kernel hacking
864#
865# CONFIG_PRINTK_TIME is not set
866CONFIG_ENABLE_MUST_CHECK=y
867# CONFIG_MAGIC_SYSRQ is not set
868# CONFIG_UNUSED_SYMBOLS is not set
869# CONFIG_DEBUG_FS is not set
870# CONFIG_HEADERS_CHECK is not set
871# CONFIG_DEBUG_KERNEL is not set
872# CONFIG_DEBUG_BUGVERBOSE is not set
873# CONFIG_DEBUG_MMRS is not set
874CONFIG_DEBUG_HUNT_FOR_ZERO=y
875CONFIG_DEBUG_BFIN_HWTRACE_ON=y
876CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_OFF=y
877# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE is not set
878# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_TWO is not set
879CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION=0
880# CONFIG_DEBUG_BFIN_HWTRACE_EXPAND is not set
881# CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE is not set
882# CONFIG_EARLY_PRINTK is not set
883CONFIG_CPLB_INFO=y
884CONFIG_ACCESS_CHECK=y
885
886#
887# Security options
888#
889# CONFIG_KEYS is not set
890CONFIG_SECURITY=y
891# CONFIG_SECURITY_NETWORK is not set
892CONFIG_SECURITY_CAPABILITIES=y
893
894#
895# Cryptographic options
896#
897# CONFIG_CRYPTO is not set
898
899#
900# Library routines
901#
902CONFIG_BITREVERSE=y
903CONFIG_CRC_CCITT=m
904# CONFIG_CRC16 is not set
905# CONFIG_CRC_ITU_T is not set
906CONFIG_CRC32=y
907# CONFIG_LIBCRC32C is not set
908CONFIG_ZLIB_INFLATE=y
909CONFIG_PLIST=y
910CONFIG_HAS_IOMEM=y
911CONFIG_HAS_IOPORT=y
912CONFIG_HAS_DMA=y
diff --git a/arch/blackfin/configs/CM-BF537E_defconfig b/arch/blackfin/configs/CM-BF537E_defconfig
new file mode 100644
index 000000000000..9f66d2de1007
--- /dev/null
+++ b/arch/blackfin/configs/CM-BF537E_defconfig
@@ -0,0 +1,940 @@
1#
2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.22.16
4#
5# CONFIG_MMU is not set
6# CONFIG_FPU is not set
7CONFIG_RWSEM_GENERIC_SPINLOCK=y
8# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
9CONFIG_BLACKFIN=y
10CONFIG_ZONE_DMA=y
11CONFIG_SEMAPHORE_SLEEPERS=y
12CONFIG_GENERIC_FIND_NEXT_BIT=y
13CONFIG_GENERIC_HWEIGHT=y
14CONFIG_GENERIC_HARDIRQS=y
15CONFIG_GENERIC_IRQ_PROBE=y
16CONFIG_GENERIC_TIME=y
17CONFIG_GENERIC_GPIO=y
18CONFIG_FORCE_MAX_ZONEORDER=14
19CONFIG_GENERIC_CALIBRATE_DELAY=y
20CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
21
22#
23# Code maturity level options
24#
25CONFIG_EXPERIMENTAL=y
26CONFIG_BROKEN_ON_SMP=y
27CONFIG_INIT_ENV_ARG_LIMIT=32
28
29#
30# General setup
31#
32CONFIG_LOCALVERSION=""
33CONFIG_LOCALVERSION_AUTO=y
34CONFIG_SYSVIPC=y
35# CONFIG_IPC_NS is not set
36CONFIG_SYSVIPC_SYSCTL=y
37# CONFIG_POSIX_MQUEUE is not set
38# CONFIG_BSD_PROCESS_ACCT is not set
39# CONFIG_TASKSTATS is not set
40# CONFIG_UTS_NS is not set
41# CONFIG_AUDIT is not set
42# CONFIG_IKCONFIG is not set
43CONFIG_LOG_BUF_SHIFT=14
44CONFIG_SYSFS_DEPRECATED=y
45# CONFIG_RELAY is not set
46# CONFIG_BLK_DEV_INITRD is not set
47# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
48CONFIG_SYSCTL=y
49CONFIG_EMBEDDED=y
50# CONFIG_UID16 is not set
51CONFIG_SYSCTL_SYSCALL=y
52CONFIG_KALLSYMS=y
53# CONFIG_KALLSYMS_EXTRA_PASS is not set
54# CONFIG_HOTPLUG is not set
55CONFIG_PRINTK=y
56CONFIG_BUG=y
57CONFIG_ELF_CORE=y
58CONFIG_BASE_FULL=y
59CONFIG_FUTEX=y
60CONFIG_ANON_INODES=y
61CONFIG_EPOLL=y
62CONFIG_SIGNALFD=y
63CONFIG_EVENTFD=y
64CONFIG_VM_EVENT_COUNTERS=y
65CONFIG_BIG_ORDER_ALLOC_NOFAIL_MAGIC=3
66# CONFIG_NP2 is not set
67CONFIG_SLAB=y
68# CONFIG_SLUB is not set
69# CONFIG_SLOB is not set
70CONFIG_RT_MUTEXES=y
71CONFIG_TINY_SHMEM=y
72CONFIG_BASE_SMALL=0
73
74#
75# Loadable module support
76#
77CONFIG_MODULES=y
78CONFIG_MODULE_UNLOAD=y
79# CONFIG_MODULE_FORCE_UNLOAD is not set
80# CONFIG_MODVERSIONS is not set
81# CONFIG_MODULE_SRCVERSION_ALL is not set
82CONFIG_KMOD=y
83
84#
85# Block layer
86#
87CONFIG_BLOCK=y
88# CONFIG_LBD is not set
89# CONFIG_BLK_DEV_IO_TRACE is not set
90# CONFIG_LSF is not set
91
92#
93# IO Schedulers
94#
95CONFIG_IOSCHED_NOOP=y
96# CONFIG_IOSCHED_AS is not set
97# CONFIG_IOSCHED_DEADLINE is not set
98CONFIG_IOSCHED_CFQ=y
99# CONFIG_DEFAULT_AS is not set
100# CONFIG_DEFAULT_DEADLINE is not set
101# CONFIG_DEFAULT_CFQ is not set
102CONFIG_DEFAULT_NOOP=y
103CONFIG_DEFAULT_IOSCHED="noop"
104CONFIG_PREEMPT_NONE=y
105# CONFIG_PREEMPT_VOLUNTARY is not set
106# CONFIG_PREEMPT is not set
107
108#
109# Blackfin Processor Options
110#
111
112#
113# Processor and Board Settings
114#
115# CONFIG_BF522 is not set
116# CONFIG_BF523 is not set
117# CONFIG_BF524 is not set
118# CONFIG_BF525 is not set
119# CONFIG_BF526 is not set
120# CONFIG_BF527 is not set
121# CONFIG_BF531 is not set
122# CONFIG_BF532 is not set
123# CONFIG_BF533 is not set
124# CONFIG_BF534 is not set
125# CONFIG_BF536 is not set
126CONFIG_BF537=y
127# CONFIG_BF542 is not set
128# CONFIG_BF544 is not set
129# CONFIG_BF547 is not set
130# CONFIG_BF548 is not set
131# CONFIG_BF549 is not set
132# CONFIG_BF561 is not set
133# CONFIG_BF_REV_0_0 is not set
134# CONFIG_BF_REV_0_1 is not set
135CONFIG_BF_REV_0_2=y
136# CONFIG_BF_REV_0_3 is not set
137# CONFIG_BF_REV_0_4 is not set
138# CONFIG_BF_REV_0_5 is not set
139# CONFIG_BF_REV_ANY is not set
140# CONFIG_BF_REV_NONE is not set
141CONFIG_BF53x=y
142CONFIG_BFIN_SINGLE_CORE=y
143CONFIG_MEM_MT48LC16M16A2TG_75=y
144CONFIG_IRQ_PLL_WAKEUP=7
145CONFIG_IRQ_RTC=8
146CONFIG_IRQ_PPI=8
147CONFIG_IRQ_SPORT0_RX=9
148CONFIG_IRQ_SPORT0_TX=9
149CONFIG_IRQ_SPORT1_RX=9
150CONFIG_IRQ_SPORT1_TX=9
151CONFIG_IRQ_TWI=10
152CONFIG_IRQ_SPI=10
153CONFIG_IRQ_UART0_RX=10
154CONFIG_IRQ_UART0_TX=10
155CONFIG_IRQ_UART1_RX=10
156CONFIG_IRQ_UART1_TX=10
157CONFIG_IRQ_MAC_RX=11
158CONFIG_IRQ_MAC_TX=11
159CONFIG_IRQ_TMR0=12
160CONFIG_IRQ_TMR1=12
161CONFIG_IRQ_TMR2=12
162CONFIG_IRQ_TMR3=12
163CONFIG_IRQ_TMR4=12
164CONFIG_IRQ_TMR5=12
165CONFIG_IRQ_TMR6=12
166CONFIG_IRQ_TMR7=12
167CONFIG_IRQ_PORTG_INTB=12
168CONFIG_IRQ_MEM_DMA0=13
169CONFIG_IRQ_MEM_DMA1=13
170CONFIG_IRQ_WATCH=13
171# CONFIG_BFIN537_STAMP is not set
172CONFIG_BFIN537_BLUETECHNIX_CM=y
173# CONFIG_PNAV10 is not set
174# CONFIG_CAMSIG_MINOTAUR is not set
175# CONFIG_GENERIC_BF537_BOARD is not set
176
177#
178# BF537 Specific Configuration
179#
180
181#
182# Interrupt Priority Assignment
183#
184
185#
186# Priority
187#
188CONFIG_IRQ_DMA_ERROR=7
189CONFIG_IRQ_ERROR=7
190CONFIG_IRQ_CAN_RX=11
191CONFIG_IRQ_CAN_TX=11
192CONFIG_IRQ_PROG_INTA=12
193
194#
195# Board customizations
196#
197# CONFIG_CMDLINE_BOOL is not set
198
199#
200# Clock/PLL Setup
201#
202CONFIG_CLKIN_HZ=25000000
203# CONFIG_BFIN_KERNEL_CLOCK is not set
204CONFIG_MAX_VCO_HZ=600000000
205CONFIG_MIN_VCO_HZ=50000000
206CONFIG_MAX_SCLK_HZ=133333333
207CONFIG_MIN_SCLK_HZ=27000000
208
209#
210# Kernel Timer/Scheduler
211#
212# CONFIG_HZ_100 is not set
213CONFIG_HZ_250=y
214# CONFIG_HZ_300 is not set
215# CONFIG_HZ_1000 is not set
216CONFIG_HZ=250
217
218#
219# Memory Setup
220#
221CONFIG_MAX_MEM_SIZE=32
222CONFIG_MEM_ADD_WIDTH=9
223CONFIG_BOOT_LOAD=0x1000
224CONFIG_BFIN_SCRATCH_REG_RETN=y
225# CONFIG_BFIN_SCRATCH_REG_RETE is not set
226# CONFIG_BFIN_SCRATCH_REG_CYCLES is not set
227
228#
229# Blackfin Kernel Optimizations
230#
231
232#
233# Memory Optimizations
234#
235CONFIG_I_ENTRY_L1=y
236CONFIG_EXCPT_IRQ_SYSC_L1=y
237CONFIG_DO_IRQ_L1=y
238CONFIG_CORE_TIMER_IRQ_L1=y
239CONFIG_IDLE_L1=y
240CONFIG_SCHEDULE_L1=y
241CONFIG_ARITHMETIC_OPS_L1=y
242CONFIG_ACCESS_OK_L1=y
243CONFIG_MEMSET_L1=y
244CONFIG_MEMCPY_L1=y
245CONFIG_SYS_BFIN_SPINLOCK_L1=y
246CONFIG_IP_CHECKSUM_L1=y
247CONFIG_CACHELINE_ALIGNED_L1=y
248CONFIG_SYSCALL_TAB_L1=y
249CONFIG_CPLB_SWITCH_TAB_L1=y
250CONFIG_RAMKERNEL=y
251# CONFIG_ROMKERNEL is not set
252CONFIG_SELECT_MEMORY_MODEL=y
253CONFIG_FLATMEM_MANUAL=y
254# CONFIG_DISCONTIGMEM_MANUAL is not set
255# CONFIG_SPARSEMEM_MANUAL is not set
256CONFIG_FLATMEM=y
257CONFIG_FLAT_NODE_MEM_MAP=y
258# CONFIG_SPARSEMEM_STATIC is not set
259CONFIG_SPLIT_PTLOCK_CPUS=4
260# CONFIG_RESOURCES_64BIT is not set
261CONFIG_ZONE_DMA_FLAG=1
262CONFIG_LARGE_ALLOCS=y
263# CONFIG_BFIN_GPTIMERS is not set
264CONFIG_BFIN_DMA_5XX=y
265# CONFIG_DMA_UNCACHED_2M is not set
266CONFIG_DMA_UNCACHED_1M=y
267# CONFIG_DMA_UNCACHED_NONE is not set
268
269#
270# Cache Support
271#
272CONFIG_BFIN_ICACHE=y
273CONFIG_BFIN_DCACHE=y
274# CONFIG_BFIN_DCACHE_BANKA is not set
275# CONFIG_BFIN_ICACHE_LOCK is not set
276CONFIG_BFIN_WB=y
277# CONFIG_BFIN_WT is not set
278CONFIG_L1_MAX_PIECE=16
279# CONFIG_MPU is not set
280
281#
282# Asynchonous Memory Configuration
283#
284
285#
286# EBIU_AMGCTL Global Control
287#
288CONFIG_C_AMCKEN=y
289CONFIG_C_CDPRIO=y
290# CONFIG_C_AMBEN is not set
291# CONFIG_C_AMBEN_B0 is not set
292# CONFIG_C_AMBEN_B0_B1 is not set
293# CONFIG_C_AMBEN_B0_B1_B2 is not set
294CONFIG_C_AMBEN_ALL=y
295
296#
297# EBIU_AMBCTL Control
298#
299CONFIG_BANK_0=0x7BB0
300CONFIG_BANK_1=0x7BB0
301CONFIG_BANK_2=0x7BB0
302CONFIG_BANK_3=0xFFC3
303
304#
305# Bus options (PCI, PCMCIA, EISA, MCA, ISA)
306#
307# CONFIG_PCI is not set
308# CONFIG_ARCH_SUPPORTS_MSI is not set
309
310#
311# PCCARD (PCMCIA/CardBus) support
312#
313
314#
315# Executable file formats
316#
317CONFIG_BINFMT_ELF_FDPIC=y
318CONFIG_BINFMT_FLAT=y
319CONFIG_BINFMT_ZFLAT=y
320CONFIG_BINFMT_SHARED_FLAT=y
321# CONFIG_BINFMT_MISC is not set
322
323#
324# Power management options
325#
326# CONFIG_PM is not set
327# CONFIG_PM_WAKEUP_BY_GPIO is not set
328
329#
330# CPU Frequency scaling
331#
332# CONFIG_CPU_FREQ is not set
333
334#
335# Networking
336#
337CONFIG_NET=y
338
339#
340# Networking options
341#
342CONFIG_PACKET=y
343# CONFIG_PACKET_MMAP is not set
344CONFIG_UNIX=y
345CONFIG_XFRM=y
346# CONFIG_XFRM_USER is not set
347# CONFIG_XFRM_SUB_POLICY is not set
348# CONFIG_XFRM_MIGRATE is not set
349# CONFIG_NET_KEY is not set
350CONFIG_INET=y
351# CONFIG_IP_MULTICAST is not set
352# CONFIG_IP_ADVANCED_ROUTER is not set
353CONFIG_IP_FIB_HASH=y
354# CONFIG_IP_PNP is not set
355# CONFIG_NET_IPIP is not set
356# CONFIG_NET_IPGRE is not set
357# CONFIG_ARPD is not set
358CONFIG_SYN_COOKIES=y
359# CONFIG_INET_AH is not set
360# CONFIG_INET_ESP is not set
361# CONFIG_INET_IPCOMP is not set
362# CONFIG_INET_XFRM_TUNNEL is not set
363# CONFIG_INET_TUNNEL is not set
364CONFIG_INET_XFRM_MODE_TRANSPORT=y
365CONFIG_INET_XFRM_MODE_TUNNEL=y
366CONFIG_INET_XFRM_MODE_BEET=y
367CONFIG_INET_DIAG=y
368CONFIG_INET_TCP_DIAG=y
369# CONFIG_TCP_CONG_ADVANCED is not set
370CONFIG_TCP_CONG_CUBIC=y
371CONFIG_DEFAULT_TCP_CONG="cubic"
372# CONFIG_TCP_MD5SIG is not set
373# CONFIG_IPV6 is not set
374# CONFIG_INET6_XFRM_TUNNEL is not set
375# CONFIG_INET6_TUNNEL is not set
376# CONFIG_NETLABEL is not set
377# CONFIG_NETWORK_SECMARK is not set
378# CONFIG_NETFILTER is not set
379# CONFIG_IP_DCCP is not set
380# CONFIG_IP_SCTP is not set
381# CONFIG_TIPC is not set
382# CONFIG_ATM is not set
383# CONFIG_BRIDGE is not set
384# CONFIG_VLAN_8021Q is not set
385# CONFIG_DECNET is not set
386# CONFIG_LLC2 is not set
387# CONFIG_IPX is not set
388# CONFIG_ATALK is not set
389# CONFIG_X25 is not set
390# CONFIG_LAPB is not set
391# CONFIG_ECONET is not set
392# CONFIG_WAN_ROUTER is not set
393
394#
395# QoS and/or fair queueing
396#
397# CONFIG_NET_SCHED is not set
398
399#
400# Network testing
401#
402# CONFIG_NET_PKTGEN is not set
403# CONFIG_HAMRADIO is not set
404# CONFIG_IRDA is not set
405# CONFIG_BT is not set
406# CONFIG_AF_RXRPC is not set
407
408#
409# Wireless
410#
411# CONFIG_CFG80211 is not set
412# CONFIG_WIRELESS_EXT is not set
413# CONFIG_MAC80211 is not set
414# CONFIG_IEEE80211 is not set
415# CONFIG_RFKILL is not set
416
417#
418# Device Drivers
419#
420
421#
422# Generic Driver Options
423#
424CONFIG_STANDALONE=y
425CONFIG_PREVENT_FIRMWARE_BUILD=y
426# CONFIG_SYS_HYPERVISOR is not set
427
428#
429# Connector - unified userspace <-> kernelspace linker
430#
431# CONFIG_CONNECTOR is not set
432CONFIG_MTD=y
433# CONFIG_MTD_DEBUG is not set
434# CONFIG_MTD_CONCAT is not set
435CONFIG_MTD_PARTITIONS=y
436# CONFIG_MTD_REDBOOT_PARTS is not set
437# CONFIG_MTD_CMDLINE_PARTS is not set
438
439#
440# User Modules And Translation Layers
441#
442CONFIG_MTD_CHAR=y
443CONFIG_MTD_BLKDEVS=y
444CONFIG_MTD_BLOCK=y
445# CONFIG_FTL is not set
446# CONFIG_NFTL is not set
447# CONFIG_INFTL is not set
448# CONFIG_RFD_FTL is not set
449# CONFIG_SSFDC is not set
450
451#
452# RAM/ROM/Flash chip drivers
453#
454# CONFIG_MTD_CFI is not set
455# CONFIG_MTD_JEDECPROBE is not set
456CONFIG_MTD_MAP_BANK_WIDTH_1=y
457CONFIG_MTD_MAP_BANK_WIDTH_2=y
458CONFIG_MTD_MAP_BANK_WIDTH_4=y
459# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
460# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
461# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
462CONFIG_MTD_CFI_I1=y
463CONFIG_MTD_CFI_I2=y
464# CONFIG_MTD_CFI_I4 is not set
465# CONFIG_MTD_CFI_I8 is not set
466CONFIG_MTD_RAM=y
467# CONFIG_MTD_ROM is not set
468# CONFIG_MTD_ABSENT is not set
469
470#
471# Mapping drivers for chip access
472#
473# CONFIG_MTD_COMPLEX_MAPPINGS is not set
474CONFIG_MTD_UCLINUX=y
475# CONFIG_MTD_PLATRAM is not set
476
477#
478# Self-contained MTD device drivers
479#
480# CONFIG_MTD_SLRAM is not set
481# CONFIG_MTD_PHRAM is not set
482# CONFIG_MTD_MTDRAM is not set
483# CONFIG_MTD_BLOCK2MTD is not set
484
485#
486# Disk-On-Chip Device Drivers
487#
488# CONFIG_MTD_DOC2000 is not set
489# CONFIG_MTD_DOC2001 is not set
490# CONFIG_MTD_DOC2001PLUS is not set
491# CONFIG_MTD_NAND is not set
492# CONFIG_MTD_ONENAND is not set
493
494#
495# UBI - Unsorted block images
496#
497# CONFIG_MTD_UBI is not set
498
499#
500# Parallel port support
501#
502# CONFIG_PARPORT is not set
503
504#
505# Plug and Play support
506#
507# CONFIG_PNPACPI is not set
508
509#
510# Block devices
511#
512# CONFIG_BLK_DEV_COW_COMMON is not set
513# CONFIG_BLK_DEV_LOOP is not set
514# CONFIG_BLK_DEV_NBD is not set
515CONFIG_BLK_DEV_RAM=y
516CONFIG_BLK_DEV_RAM_COUNT=16
517CONFIG_BLK_DEV_RAM_SIZE=4096
518CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
519# CONFIG_CDROM_PKTCDVD is not set
520# CONFIG_ATA_OVER_ETH is not set
521
522#
523# Misc devices
524#
525# CONFIG_IDE is not set
526
527#
528# SCSI device support
529#
530# CONFIG_RAID_ATTRS is not set
531# CONFIG_SCSI is not set
532# CONFIG_SCSI_NETLINK is not set
533# CONFIG_ATA is not set
534
535#
536# Multi-device support (RAID and LVM)
537#
538# CONFIG_MD is not set
539
540#
541# Network device support
542#
543CONFIG_NETDEVICES=y
544# CONFIG_DUMMY is not set
545# CONFIG_BONDING is not set
546# CONFIG_EQUALIZER is not set
547# CONFIG_TUN is not set
548CONFIG_PHYLIB=y
549
550#
551# MII PHY device drivers
552#
553# CONFIG_MARVELL_PHY is not set
554# CONFIG_DAVICOM_PHY is not set
555# CONFIG_QSEMI_PHY is not set
556# CONFIG_LXT_PHY is not set
557# CONFIG_CICADA_PHY is not set
558# CONFIG_VITESSE_PHY is not set
559# CONFIG_SMSC_PHY is not set
560# CONFIG_BROADCOM_PHY is not set
561# CONFIG_FIXED_PHY is not set
562
563#
564# Ethernet (10 or 100Mbit)
565#
566CONFIG_NET_ETHERNET=y
567CONFIG_MII=y
568# CONFIG_SMC91X is not set
569CONFIG_BFIN_MAC=y
570CONFIG_BFIN_MAC_USE_L1=y
571CONFIG_BFIN_TX_DESC_NUM=10
572CONFIG_BFIN_RX_DESC_NUM=20
573# CONFIG_BFIN_MAC_RMII is not set
574# CONFIG_SMSC911X is not set
575# CONFIG_DM9000 is not set
576CONFIG_NETDEV_1000=y
577# CONFIG_AX88180 is not set
578CONFIG_NETDEV_10000=y
579
580#
581# Wireless LAN
582#
583# CONFIG_WLAN_PRE80211 is not set
584# CONFIG_WLAN_80211 is not set
585# CONFIG_WAN is not set
586# CONFIG_PPP is not set
587# CONFIG_SLIP is not set
588# CONFIG_SHAPER is not set
589# CONFIG_NETCONSOLE is not set
590# CONFIG_NETPOLL is not set
591# CONFIG_NET_POLL_CONTROLLER is not set
592
593#
594# ISDN subsystem
595#
596# CONFIG_ISDN is not set
597
598#
599# Telephony Support
600#
601# CONFIG_PHONE is not set
602
603#
604# Input device support
605#
606# CONFIG_INPUT is not set
607
608#
609# Hardware I/O ports
610#
611# CONFIG_SERIO is not set
612# CONFIG_GAMEPORT is not set
613
614#
615# Character devices
616#
617# CONFIG_AD9960 is not set
618# CONFIG_SPI_ADC_BF533 is not set
619# CONFIG_BF5xx_PFLAGS is not set
620# CONFIG_BF5xx_PPIFCD is not set
621# CONFIG_BFIN_SIMPLE_TIMER is not set
622# CONFIG_BF5xx_PPI is not set
623CONFIG_BFIN_SPORT=y
624# CONFIG_BFIN_TIMER_LATENCY is not set
625# CONFIG_VT is not set
626# CONFIG_SERIAL_NONSTANDARD is not set
627
628#
629# Serial drivers
630#
631# CONFIG_SERIAL_8250 is not set
632
633#
634# Non-8250 serial port support
635#
636CONFIG_SERIAL_BFIN=y
637CONFIG_SERIAL_BFIN_CONSOLE=y
638CONFIG_SERIAL_BFIN_DMA=y
639# CONFIG_SERIAL_BFIN_PIO is not set
640CONFIG_SERIAL_BFIN_UART0=y
641# CONFIG_BFIN_UART0_CTSRTS is not set
642CONFIG_SERIAL_BFIN_UART1=y
643# CONFIG_BFIN_UART1_CTSRTS is not set
644CONFIG_SERIAL_CORE=y
645CONFIG_SERIAL_CORE_CONSOLE=y
646# CONFIG_SERIAL_BFIN_SPORT is not set
647CONFIG_UNIX98_PTYS=y
648CONFIG_LEGACY_PTYS=y
649CONFIG_LEGACY_PTY_COUNT=256
650
651#
652# CAN, the car bus and industrial fieldbus
653#
654# CONFIG_CAN4LINUX is not set
655
656#
657# IPMI
658#
659# CONFIG_IPMI_HANDLER is not set
660# CONFIG_WATCHDOG is not set
661# CONFIG_HW_RANDOM is not set
662# CONFIG_GEN_RTC is not set
663# CONFIG_R3964 is not set
664# CONFIG_RAW_DRIVER is not set
665
666#
667# TPM devices
668#
669# CONFIG_TCG_TPM is not set
670# CONFIG_I2C is not set
671
672#
673# SPI support
674#
675# CONFIG_SPI is not set
676# CONFIG_SPI_MASTER is not set
677
678#
679# Dallas's 1-wire bus
680#
681# CONFIG_W1 is not set
682CONFIG_HWMON=y
683# CONFIG_HWMON_VID is not set
684# CONFIG_SENSORS_ABITUGURU is not set
685# CONFIG_SENSORS_F71805F is not set
686# CONFIG_SENSORS_PC87427 is not set
687# CONFIG_SENSORS_SMSC47M1 is not set
688# CONFIG_SENSORS_SMSC47B397 is not set
689# CONFIG_SENSORS_VT1211 is not set
690# CONFIG_SENSORS_W83627HF is not set
691# CONFIG_HWMON_DEBUG_CHIP is not set
692
693#
694# Multifunction device drivers
695#
696# CONFIG_MFD_SM501 is not set
697
698#
699# Multimedia devices
700#
701# CONFIG_VIDEO_DEV is not set
702# CONFIG_DVB_CORE is not set
703CONFIG_DAB=y
704
705#
706# Graphics support
707#
708# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
709
710#
711# Display device support
712#
713# CONFIG_DISPLAY_SUPPORT is not set
714# CONFIG_VGASTATE is not set
715# CONFIG_FB is not set
716
717#
718# Sound
719#
720# CONFIG_SOUND is not set
721
722#
723# USB support
724#
725CONFIG_USB_ARCH_HAS_HCD=y
726# CONFIG_USB_ARCH_HAS_OHCI is not set
727# CONFIG_USB_ARCH_HAS_EHCI is not set
728# CONFIG_USB is not set
729
730#
731# Enable Host or Gadget support to see Inventra options
732#
733
734#
735# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
736#
737
738#
739# USB Gadget Support
740#
741# CONFIG_USB_GADGET is not set
742# CONFIG_MMC is not set
743
744#
745# LED devices
746#
747# CONFIG_NEW_LEDS is not set
748
749#
750# LED drivers
751#
752
753#
754# LED Triggers
755#
756
757#
758# InfiniBand support
759#
760
761#
762# EDAC - error detection and reporting (RAS) (EXPERIMENTAL)
763#
764
765#
766# Real Time Clock
767#
768# CONFIG_RTC_CLASS is not set
769
770#
771# DMA Engine support
772#
773# CONFIG_DMA_ENGINE is not set
774
775#
776# DMA Clients
777#
778
779#
780# DMA Devices
781#
782
783#
784# PBX support
785#
786# CONFIG_PBX is not set
787
788#
789# File systems
790#
791CONFIG_EXT2_FS=y
792CONFIG_EXT2_FS_XATTR=y
793# CONFIG_EXT2_FS_POSIX_ACL is not set
794# CONFIG_EXT2_FS_SECURITY is not set
795# CONFIG_EXT3_FS is not set
796# CONFIG_EXT4DEV_FS is not set
797CONFIG_FS_MBCACHE=y
798# CONFIG_REISERFS_FS is not set
799# CONFIG_JFS_FS is not set
800# CONFIG_FS_POSIX_ACL is not set
801# CONFIG_XFS_FS is not set
802# CONFIG_GFS2_FS is not set
803# CONFIG_OCFS2_FS is not set
804# CONFIG_MINIX_FS is not set
805# CONFIG_ROMFS_FS is not set
806CONFIG_INOTIFY=y
807CONFIG_INOTIFY_USER=y
808# CONFIG_QUOTA is not set
809CONFIG_DNOTIFY=y
810# CONFIG_AUTOFS_FS is not set
811# CONFIG_AUTOFS4_FS is not set
812# CONFIG_FUSE_FS is not set
813
814#
815# CD-ROM/DVD Filesystems
816#
817# CONFIG_ISO9660_FS is not set
818# CONFIG_UDF_FS is not set
819
820#
821# DOS/FAT/NT Filesystems
822#
823# CONFIG_MSDOS_FS is not set
824# CONFIG_VFAT_FS is not set
825# CONFIG_NTFS_FS is not set
826
827#
828# Pseudo filesystems
829#
830CONFIG_PROC_FS=y
831CONFIG_PROC_SYSCTL=y
832CONFIG_SYSFS=y
833# CONFIG_TMPFS is not set
834# CONFIG_HUGETLB_PAGE is not set
835CONFIG_RAMFS=y
836# CONFIG_CONFIGFS_FS is not set
837
838#
839# Miscellaneous filesystems
840#
841# CONFIG_ADFS_FS is not set
842# CONFIG_AFFS_FS is not set
843# CONFIG_HFS_FS is not set
844# CONFIG_HFSPLUS_FS is not set
845# CONFIG_BEFS_FS is not set
846# CONFIG_BFS_FS is not set
847# CONFIG_EFS_FS is not set
848# CONFIG_YAFFS_FS is not set
849# CONFIG_JFFS2_FS is not set
850# CONFIG_CRAMFS is not set
851# CONFIG_VXFS_FS is not set
852# CONFIG_HPFS_FS is not set
853# CONFIG_QNX4FS_FS is not set
854# CONFIG_SYSV_FS is not set
855# CONFIG_UFS_FS is not set
856
857#
858# Network File Systems
859#
860# CONFIG_NFS_FS is not set
861# CONFIG_NFSD is not set
862# CONFIG_SMB_FS is not set
863# CONFIG_CIFS is not set
864# CONFIG_NCP_FS is not set
865# CONFIG_CODA_FS is not set
866# CONFIG_AFS_FS is not set
867# CONFIG_9P_FS is not set
868
869#
870# Partition Types
871#
872# CONFIG_PARTITION_ADVANCED is not set
873CONFIG_MSDOS_PARTITION=y
874
875#
876# Native Language Support
877#
878# CONFIG_NLS is not set
879
880#
881# Distributed Lock Manager
882#
883# CONFIG_DLM is not set
884
885#
886# Profiling support
887#
888# CONFIG_PROFILING is not set
889
890#
891# Kernel hacking
892#
893# CONFIG_PRINTK_TIME is not set
894CONFIG_ENABLE_MUST_CHECK=y
895# CONFIG_MAGIC_SYSRQ is not set
896# CONFIG_UNUSED_SYMBOLS is not set
897# CONFIG_DEBUG_FS is not set
898# CONFIG_HEADERS_CHECK is not set
899# CONFIG_DEBUG_KERNEL is not set
900# CONFIG_DEBUG_BUGVERBOSE is not set
901# CONFIG_DEBUG_MMRS is not set
902# CONFIG_DEBUG_HUNT_FOR_ZERO is not set
903CONFIG_DEBUG_BFIN_HWTRACE_ON=y
904CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_OFF=y
905# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE is not set
906# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_TWO is not set
907CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION=0
908# CONFIG_DEBUG_BFIN_HWTRACE_EXPAND is not set
909# CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE is not set
910# CONFIG_EARLY_PRINTK is not set
911CONFIG_CPLB_INFO=y
912CONFIG_ACCESS_CHECK=y
913
914#
915# Security options
916#
917# CONFIG_KEYS is not set
918CONFIG_SECURITY=y
919# CONFIG_SECURITY_NETWORK is not set
920CONFIG_SECURITY_CAPABILITIES=y
921
922#
923# Cryptographic options
924#
925# CONFIG_CRYPTO is not set
926
927#
928# Library routines
929#
930CONFIG_BITREVERSE=y
931CONFIG_CRC_CCITT=m
932# CONFIG_CRC16 is not set
933# CONFIG_CRC_ITU_T is not set
934CONFIG_CRC32=y
935# CONFIG_LIBCRC32C is not set
936CONFIG_ZLIB_INFLATE=y
937CONFIG_PLIST=y
938CONFIG_HAS_IOMEM=y
939CONFIG_HAS_IOPORT=y
940CONFIG_HAS_DMA=y
diff --git a/arch/blackfin/configs/CM-BF537U_defconfig b/arch/blackfin/configs/CM-BF537U_defconfig
new file mode 100644
index 000000000000..2694d06c5bde
--- /dev/null
+++ b/arch/blackfin/configs/CM-BF537U_defconfig
@@ -0,0 +1,940 @@
1#
2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.22.16
4#
5# CONFIG_MMU is not set
6# CONFIG_FPU is not set
7CONFIG_RWSEM_GENERIC_SPINLOCK=y
8# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
9CONFIG_BLACKFIN=y
10CONFIG_ZONE_DMA=y
11CONFIG_SEMAPHORE_SLEEPERS=y
12CONFIG_GENERIC_FIND_NEXT_BIT=y
13CONFIG_GENERIC_HWEIGHT=y
14CONFIG_GENERIC_HARDIRQS=y
15CONFIG_GENERIC_IRQ_PROBE=y
16CONFIG_GENERIC_TIME=y
17CONFIG_GENERIC_GPIO=y
18CONFIG_FORCE_MAX_ZONEORDER=14
19CONFIG_GENERIC_CALIBRATE_DELAY=y
20CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
21
22#
23# Code maturity level options
24#
25CONFIG_EXPERIMENTAL=y
26CONFIG_BROKEN_ON_SMP=y
27CONFIG_INIT_ENV_ARG_LIMIT=32
28
29#
30# General setup
31#
32CONFIG_LOCALVERSION=""
33CONFIG_LOCALVERSION_AUTO=y
34CONFIG_SYSVIPC=y
35# CONFIG_IPC_NS is not set
36CONFIG_SYSVIPC_SYSCTL=y
37# CONFIG_POSIX_MQUEUE is not set
38# CONFIG_BSD_PROCESS_ACCT is not set
39# CONFIG_TASKSTATS is not set
40# CONFIG_UTS_NS is not set
41# CONFIG_AUDIT is not set
42# CONFIG_IKCONFIG is not set
43CONFIG_LOG_BUF_SHIFT=14
44CONFIG_SYSFS_DEPRECATED=y
45# CONFIG_RELAY is not set
46# CONFIG_BLK_DEV_INITRD is not set
47# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
48CONFIG_SYSCTL=y
49CONFIG_EMBEDDED=y
50# CONFIG_UID16 is not set
51CONFIG_SYSCTL_SYSCALL=y
52CONFIG_KALLSYMS=y
53# CONFIG_KALLSYMS_EXTRA_PASS is not set
54# CONFIG_HOTPLUG is not set
55CONFIG_PRINTK=y
56CONFIG_BUG=y
57CONFIG_ELF_CORE=y
58CONFIG_BASE_FULL=y
59CONFIG_FUTEX=y
60CONFIG_ANON_INODES=y
61CONFIG_EPOLL=y
62CONFIG_SIGNALFD=y
63CONFIG_EVENTFD=y
64CONFIG_VM_EVENT_COUNTERS=y
65CONFIG_BIG_ORDER_ALLOC_NOFAIL_MAGIC=3
66# CONFIG_NP2 is not set
67CONFIG_SLAB=y
68# CONFIG_SLUB is not set
69# CONFIG_SLOB is not set
70CONFIG_RT_MUTEXES=y
71CONFIG_TINY_SHMEM=y
72CONFIG_BASE_SMALL=0
73
74#
75# Loadable module support
76#
77CONFIG_MODULES=y
78CONFIG_MODULE_UNLOAD=y
79# CONFIG_MODULE_FORCE_UNLOAD is not set
80# CONFIG_MODVERSIONS is not set
81# CONFIG_MODULE_SRCVERSION_ALL is not set
82CONFIG_KMOD=y
83
84#
85# Block layer
86#
87CONFIG_BLOCK=y
88# CONFIG_LBD is not set
89# CONFIG_BLK_DEV_IO_TRACE is not set
90# CONFIG_LSF is not set
91
92#
93# IO Schedulers
94#
95CONFIG_IOSCHED_NOOP=y
96# CONFIG_IOSCHED_AS is not set
97# CONFIG_IOSCHED_DEADLINE is not set
98CONFIG_IOSCHED_CFQ=y
99# CONFIG_DEFAULT_AS is not set
100# CONFIG_DEFAULT_DEADLINE is not set
101# CONFIG_DEFAULT_CFQ is not set
102CONFIG_DEFAULT_NOOP=y
103CONFIG_DEFAULT_IOSCHED="noop"
104CONFIG_PREEMPT_NONE=y
105# CONFIG_PREEMPT_VOLUNTARY is not set
106# CONFIG_PREEMPT is not set
107
108#
109# Blackfin Processor Options
110#
111
112#
113# Processor and Board Settings
114#
115# CONFIG_BF522 is not set
116# CONFIG_BF523 is not set
117# CONFIG_BF524 is not set
118# CONFIG_BF525 is not set
119# CONFIG_BF526 is not set
120# CONFIG_BF527 is not set
121# CONFIG_BF531 is not set
122# CONFIG_BF532 is not set
123# CONFIG_BF533 is not set
124# CONFIG_BF534 is not set
125# CONFIG_BF536 is not set
126CONFIG_BF537=y
127# CONFIG_BF542 is not set
128# CONFIG_BF544 is not set
129# CONFIG_BF547 is not set
130# CONFIG_BF548 is not set
131# CONFIG_BF549 is not set
132# CONFIG_BF561 is not set
133# CONFIG_BF_REV_0_0 is not set
134# CONFIG_BF_REV_0_1 is not set
135CONFIG_BF_REV_0_2=y
136# CONFIG_BF_REV_0_3 is not set
137# CONFIG_BF_REV_0_4 is not set
138# CONFIG_BF_REV_0_5 is not set
139# CONFIG_BF_REV_ANY is not set
140# CONFIG_BF_REV_NONE is not set
141CONFIG_BF53x=y
142CONFIG_BFIN_SINGLE_CORE=y
143CONFIG_MEM_MT48LC16M16A2TG_75=y
144CONFIG_IRQ_PLL_WAKEUP=7
145CONFIG_IRQ_RTC=8
146CONFIG_IRQ_PPI=8
147CONFIG_IRQ_SPORT0_RX=9
148CONFIG_IRQ_SPORT0_TX=9
149CONFIG_IRQ_SPORT1_RX=9
150CONFIG_IRQ_SPORT1_TX=9
151CONFIG_IRQ_TWI=10
152CONFIG_IRQ_SPI=10
153CONFIG_IRQ_UART0_RX=10
154CONFIG_IRQ_UART0_TX=10
155CONFIG_IRQ_UART1_RX=10
156CONFIG_IRQ_UART1_TX=10
157CONFIG_IRQ_MAC_RX=11
158CONFIG_IRQ_MAC_TX=11
159CONFIG_IRQ_TMR0=12
160CONFIG_IRQ_TMR1=12
161CONFIG_IRQ_TMR2=12
162CONFIG_IRQ_TMR3=12
163CONFIG_IRQ_TMR4=12
164CONFIG_IRQ_TMR5=12
165CONFIG_IRQ_TMR6=12
166CONFIG_IRQ_TMR7=12
167CONFIG_IRQ_PORTG_INTB=12
168CONFIG_IRQ_MEM_DMA0=13
169CONFIG_IRQ_MEM_DMA1=13
170CONFIG_IRQ_WATCH=13
171# CONFIG_BFIN537_STAMP is not set
172CONFIG_BFIN537_BLUETECHNIX_CM=y
173# CONFIG_PNAV10 is not set
174# CONFIG_CAMSIG_MINOTAUR is not set
175# CONFIG_GENERIC_BF537_BOARD is not set
176
177#
178# BF537 Specific Configuration
179#
180
181#
182# Interrupt Priority Assignment
183#
184
185#
186# Priority
187#
188CONFIG_IRQ_DMA_ERROR=7
189CONFIG_IRQ_ERROR=7
190CONFIG_IRQ_CAN_RX=11
191CONFIG_IRQ_CAN_TX=11
192CONFIG_IRQ_PROG_INTA=12
193
194#
195# Board customizations
196#
197# CONFIG_CMDLINE_BOOL is not set
198
199#
200# Clock/PLL Setup
201#
202CONFIG_CLKIN_HZ=30000000
203# CONFIG_BFIN_KERNEL_CLOCK is not set
204CONFIG_MAX_VCO_HZ=600000000
205CONFIG_MIN_VCO_HZ=50000000
206CONFIG_MAX_SCLK_HZ=133333333
207CONFIG_MIN_SCLK_HZ=27000000
208
209#
210# Kernel Timer/Scheduler
211#
212# CONFIG_HZ_100 is not set
213CONFIG_HZ_250=y
214# CONFIG_HZ_300 is not set
215# CONFIG_HZ_1000 is not set
216CONFIG_HZ=250
217
218#
219# Memory Setup
220#
221CONFIG_MAX_MEM_SIZE=32
222CONFIG_MEM_ADD_WIDTH=9
223CONFIG_BOOT_LOAD=0x1000
224CONFIG_BFIN_SCRATCH_REG_RETN=y
225# CONFIG_BFIN_SCRATCH_REG_RETE is not set
226# CONFIG_BFIN_SCRATCH_REG_CYCLES is not set
227
228#
229# Blackfin Kernel Optimizations
230#
231
232#
233# Memory Optimizations
234#
235CONFIG_I_ENTRY_L1=y
236CONFIG_EXCPT_IRQ_SYSC_L1=y
237CONFIG_DO_IRQ_L1=y
238CONFIG_CORE_TIMER_IRQ_L1=y
239CONFIG_IDLE_L1=y
240CONFIG_SCHEDULE_L1=y
241CONFIG_ARITHMETIC_OPS_L1=y
242CONFIG_ACCESS_OK_L1=y
243CONFIG_MEMSET_L1=y
244CONFIG_MEMCPY_L1=y
245CONFIG_SYS_BFIN_SPINLOCK_L1=y
246CONFIG_IP_CHECKSUM_L1=y
247CONFIG_CACHELINE_ALIGNED_L1=y
248CONFIG_SYSCALL_TAB_L1=y
249CONFIG_CPLB_SWITCH_TAB_L1=y
250CONFIG_RAMKERNEL=y
251# CONFIG_ROMKERNEL is not set
252CONFIG_SELECT_MEMORY_MODEL=y
253CONFIG_FLATMEM_MANUAL=y
254# CONFIG_DISCONTIGMEM_MANUAL is not set
255# CONFIG_SPARSEMEM_MANUAL is not set
256CONFIG_FLATMEM=y
257CONFIG_FLAT_NODE_MEM_MAP=y
258# CONFIG_SPARSEMEM_STATIC is not set
259CONFIG_SPLIT_PTLOCK_CPUS=4
260# CONFIG_RESOURCES_64BIT is not set
261CONFIG_ZONE_DMA_FLAG=1
262CONFIG_LARGE_ALLOCS=y
263# CONFIG_BFIN_GPTIMERS is not set
264CONFIG_BFIN_DMA_5XX=y
265# CONFIG_DMA_UNCACHED_2M is not set
266CONFIG_DMA_UNCACHED_1M=y
267# CONFIG_DMA_UNCACHED_NONE is not set
268
269#
270# Cache Support
271#
272CONFIG_BFIN_ICACHE=y
273CONFIG_BFIN_DCACHE=y
274# CONFIG_BFIN_DCACHE_BANKA is not set
275# CONFIG_BFIN_ICACHE_LOCK is not set
276CONFIG_BFIN_WB=y
277# CONFIG_BFIN_WT is not set
278CONFIG_L1_MAX_PIECE=16
279# CONFIG_MPU is not set
280
281#
282# Asynchonous Memory Configuration
283#
284
285#
286# EBIU_AMGCTL Global Control
287#
288CONFIG_C_AMCKEN=y
289CONFIG_C_CDPRIO=y
290# CONFIG_C_AMBEN is not set
291# CONFIG_C_AMBEN_B0 is not set
292# CONFIG_C_AMBEN_B0_B1 is not set
293# CONFIG_C_AMBEN_B0_B1_B2 is not set
294CONFIG_C_AMBEN_ALL=y
295
296#
297# EBIU_AMBCTL Control
298#
299CONFIG_BANK_0=0x7BB0
300CONFIG_BANK_1=0x7BB0
301CONFIG_BANK_2=0xFFC3
302CONFIG_BANK_3=0xFFC3
303
304#
305# Bus options (PCI, PCMCIA, EISA, MCA, ISA)
306#
307# CONFIG_PCI is not set
308# CONFIG_ARCH_SUPPORTS_MSI is not set
309
310#
311# PCCARD (PCMCIA/CardBus) support
312#
313
314#
315# Executable file formats
316#
317CONFIG_BINFMT_ELF_FDPIC=y
318CONFIG_BINFMT_FLAT=y
319CONFIG_BINFMT_ZFLAT=y
320CONFIG_BINFMT_SHARED_FLAT=y
321# CONFIG_BINFMT_MISC is not set
322
323#
324# Power management options
325#
326# CONFIG_PM is not set
327# CONFIG_PM_WAKEUP_BY_GPIO is not set
328
329#
330# CPU Frequency scaling
331#
332# CONFIG_CPU_FREQ is not set
333
334#
335# Networking
336#
337CONFIG_NET=y
338
339#
340# Networking options
341#
342CONFIG_PACKET=y
343# CONFIG_PACKET_MMAP is not set
344CONFIG_UNIX=y
345CONFIG_XFRM=y
346# CONFIG_XFRM_USER is not set
347# CONFIG_XFRM_SUB_POLICY is not set
348# CONFIG_XFRM_MIGRATE is not set
349# CONFIG_NET_KEY is not set
350CONFIG_INET=y
351# CONFIG_IP_MULTICAST is not set
352# CONFIG_IP_ADVANCED_ROUTER is not set
353CONFIG_IP_FIB_HASH=y
354# CONFIG_IP_PNP is not set
355# CONFIG_NET_IPIP is not set
356# CONFIG_NET_IPGRE is not set
357# CONFIG_ARPD is not set
358CONFIG_SYN_COOKIES=y
359# CONFIG_INET_AH is not set
360# CONFIG_INET_ESP is not set
361# CONFIG_INET_IPCOMP is not set
362# CONFIG_INET_XFRM_TUNNEL is not set
363# CONFIG_INET_TUNNEL is not set
364CONFIG_INET_XFRM_MODE_TRANSPORT=y
365CONFIG_INET_XFRM_MODE_TUNNEL=y
366CONFIG_INET_XFRM_MODE_BEET=y
367CONFIG_INET_DIAG=y
368CONFIG_INET_TCP_DIAG=y
369# CONFIG_TCP_CONG_ADVANCED is not set
370CONFIG_TCP_CONG_CUBIC=y
371CONFIG_DEFAULT_TCP_CONG="cubic"
372# CONFIG_TCP_MD5SIG is not set
373# CONFIG_IPV6 is not set
374# CONFIG_INET6_XFRM_TUNNEL is not set
375# CONFIG_INET6_TUNNEL is not set
376# CONFIG_NETLABEL is not set
377# CONFIG_NETWORK_SECMARK is not set
378# CONFIG_NETFILTER is not set
379# CONFIG_IP_DCCP is not set
380# CONFIG_IP_SCTP is not set
381# CONFIG_TIPC is not set
382# CONFIG_ATM is not set
383# CONFIG_BRIDGE is not set
384# CONFIG_VLAN_8021Q is not set
385# CONFIG_DECNET is not set
386# CONFIG_LLC2 is not set
387# CONFIG_IPX is not set
388# CONFIG_ATALK is not set
389# CONFIG_X25 is not set
390# CONFIG_LAPB is not set
391# CONFIG_ECONET is not set
392# CONFIG_WAN_ROUTER is not set
393
394#
395# QoS and/or fair queueing
396#
397# CONFIG_NET_SCHED is not set
398
399#
400# Network testing
401#
402# CONFIG_NET_PKTGEN is not set
403# CONFIG_HAMRADIO is not set
404# CONFIG_IRDA is not set
405# CONFIG_BT is not set
406# CONFIG_AF_RXRPC is not set
407
408#
409# Wireless
410#
411# CONFIG_CFG80211 is not set
412# CONFIG_WIRELESS_EXT is not set
413# CONFIG_MAC80211 is not set
414# CONFIG_IEEE80211 is not set
415# CONFIG_RFKILL is not set
416
417#
418# Device Drivers
419#
420
421#
422# Generic Driver Options
423#
424CONFIG_STANDALONE=y
425CONFIG_PREVENT_FIRMWARE_BUILD=y
426# CONFIG_SYS_HYPERVISOR is not set
427
428#
429# Connector - unified userspace <-> kernelspace linker
430#
431# CONFIG_CONNECTOR is not set
432CONFIG_MTD=y
433# CONFIG_MTD_DEBUG is not set
434# CONFIG_MTD_CONCAT is not set
435CONFIG_MTD_PARTITIONS=y
436# CONFIG_MTD_REDBOOT_PARTS is not set
437# CONFIG_MTD_CMDLINE_PARTS is not set
438
439#
440# User Modules And Translation Layers
441#
442CONFIG_MTD_CHAR=y
443CONFIG_MTD_BLKDEVS=y
444CONFIG_MTD_BLOCK=y
445# CONFIG_FTL is not set
446# CONFIG_NFTL is not set
447# CONFIG_INFTL is not set
448# CONFIG_RFD_FTL is not set
449# CONFIG_SSFDC is not set
450
451#
452# RAM/ROM/Flash chip drivers
453#
454# CONFIG_MTD_CFI is not set
455# CONFIG_MTD_JEDECPROBE is not set
456CONFIG_MTD_MAP_BANK_WIDTH_1=y
457CONFIG_MTD_MAP_BANK_WIDTH_2=y
458CONFIG_MTD_MAP_BANK_WIDTH_4=y
459# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
460# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
461# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
462CONFIG_MTD_CFI_I1=y
463CONFIG_MTD_CFI_I2=y
464# CONFIG_MTD_CFI_I4 is not set
465# CONFIG_MTD_CFI_I8 is not set
466CONFIG_MTD_RAM=y
467# CONFIG_MTD_ROM is not set
468# CONFIG_MTD_ABSENT is not set
469
470#
471# Mapping drivers for chip access
472#
473# CONFIG_MTD_COMPLEX_MAPPINGS is not set
474CONFIG_MTD_UCLINUX=y
475# CONFIG_MTD_PLATRAM is not set
476
477#
478# Self-contained MTD device drivers
479#
480# CONFIG_MTD_SLRAM is not set
481# CONFIG_MTD_PHRAM is not set
482# CONFIG_MTD_MTDRAM is not set
483# CONFIG_MTD_BLOCK2MTD is not set
484
485#
486# Disk-On-Chip Device Drivers
487#
488# CONFIG_MTD_DOC2000 is not set
489# CONFIG_MTD_DOC2001 is not set
490# CONFIG_MTD_DOC2001PLUS is not set
491# CONFIG_MTD_NAND is not set
492# CONFIG_MTD_ONENAND is not set
493
494#
495# UBI - Unsorted block images
496#
497# CONFIG_MTD_UBI is not set
498
499#
500# Parallel port support
501#
502# CONFIG_PARPORT is not set
503
504#
505# Plug and Play support
506#
507# CONFIG_PNPACPI is not set
508
509#
510# Block devices
511#
512# CONFIG_BLK_DEV_COW_COMMON is not set
513# CONFIG_BLK_DEV_LOOP is not set
514# CONFIG_BLK_DEV_NBD is not set
515CONFIG_BLK_DEV_RAM=y
516CONFIG_BLK_DEV_RAM_COUNT=16
517CONFIG_BLK_DEV_RAM_SIZE=4096
518CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
519# CONFIG_CDROM_PKTCDVD is not set
520# CONFIG_ATA_OVER_ETH is not set
521
522#
523# Misc devices
524#
525# CONFIG_IDE is not set
526
527#
528# SCSI device support
529#
530# CONFIG_RAID_ATTRS is not set
531# CONFIG_SCSI is not set
532# CONFIG_SCSI_NETLINK is not set
533# CONFIG_ATA is not set
534
535#
536# Multi-device support (RAID and LVM)
537#
538# CONFIG_MD is not set
539
540#
541# Network device support
542#
543CONFIG_NETDEVICES=y
544# CONFIG_DUMMY is not set
545# CONFIG_BONDING is not set
546# CONFIG_EQUALIZER is not set
547# CONFIG_TUN is not set
548# CONFIG_PHYLIB is not set
549
550#
551# Ethernet (10 or 100Mbit)
552#
553CONFIG_NET_ETHERNET=y
554CONFIG_MII=y
555CONFIG_SMC91X=y
556# CONFIG_BFIN_MAC is not set
557# CONFIG_SMSC911X is not set
558# CONFIG_DM9000 is not set
559CONFIG_NETDEV_1000=y
560# CONFIG_AX88180 is not set
561CONFIG_NETDEV_10000=y
562
563#
564# Wireless LAN
565#
566# CONFIG_WLAN_PRE80211 is not set
567# CONFIG_WLAN_80211 is not set
568# CONFIG_WAN is not set
569# CONFIG_PPP is not set
570# CONFIG_SLIP is not set
571# CONFIG_SHAPER is not set
572# CONFIG_NETCONSOLE is not set
573# CONFIG_NETPOLL is not set
574# CONFIG_NET_POLL_CONTROLLER is not set
575
576#
577# ISDN subsystem
578#
579# CONFIG_ISDN is not set
580
581#
582# Telephony Support
583#
584# CONFIG_PHONE is not set
585
586#
587# Input device support
588#
589# CONFIG_INPUT is not set
590
591#
592# Hardware I/O ports
593#
594# CONFIG_SERIO is not set
595# CONFIG_GAMEPORT is not set
596
597#
598# Character devices
599#
600# CONFIG_AD9960 is not set
601# CONFIG_SPI_ADC_BF533 is not set
602# CONFIG_BF5xx_PFLAGS is not set
603# CONFIG_BF5xx_PPIFCD is not set
604# CONFIG_BFIN_SIMPLE_TIMER is not set
605# CONFIG_BF5xx_PPI is not set
606CONFIG_BFIN_SPORT=y
607# CONFIG_BFIN_TIMER_LATENCY is not set
608# CONFIG_VT is not set
609# CONFIG_SERIAL_NONSTANDARD is not set
610
611#
612# Serial drivers
613#
614# CONFIG_SERIAL_8250 is not set
615
616#
617# Non-8250 serial port support
618#
619CONFIG_SERIAL_BFIN=y
620CONFIG_SERIAL_BFIN_CONSOLE=y
621CONFIG_SERIAL_BFIN_DMA=y
622# CONFIG_SERIAL_BFIN_PIO is not set
623CONFIG_SERIAL_BFIN_UART0=y
624# CONFIG_BFIN_UART0_CTSRTS is not set
625CONFIG_SERIAL_BFIN_UART1=y
626# CONFIG_BFIN_UART1_CTSRTS is not set
627CONFIG_SERIAL_CORE=y
628CONFIG_SERIAL_CORE_CONSOLE=y
629# CONFIG_SERIAL_BFIN_SPORT is not set
630CONFIG_UNIX98_PTYS=y
631CONFIG_LEGACY_PTYS=y
632CONFIG_LEGACY_PTY_COUNT=256
633
634#
635# CAN, the car bus and industrial fieldbus
636#
637# CONFIG_CAN4LINUX is not set
638
639#
640# IPMI
641#
642# CONFIG_IPMI_HANDLER is not set
643# CONFIG_WATCHDOG is not set
644# CONFIG_HW_RANDOM is not set
645# CONFIG_GEN_RTC is not set
646# CONFIG_R3964 is not set
647# CONFIG_RAW_DRIVER is not set
648
649#
650# TPM devices
651#
652# CONFIG_TCG_TPM is not set
653# CONFIG_I2C is not set
654
655#
656# SPI support
657#
658# CONFIG_SPI is not set
659# CONFIG_SPI_MASTER is not set
660
661#
662# Dallas's 1-wire bus
663#
664# CONFIG_W1 is not set
665CONFIG_HWMON=y
666# CONFIG_HWMON_VID is not set
667# CONFIG_SENSORS_ABITUGURU is not set
668# CONFIG_SENSORS_F71805F is not set
669# CONFIG_SENSORS_PC87427 is not set
670# CONFIG_SENSORS_SMSC47M1 is not set
671# CONFIG_SENSORS_SMSC47B397 is not set
672# CONFIG_SENSORS_VT1211 is not set
673# CONFIG_SENSORS_W83627HF is not set
674# CONFIG_HWMON_DEBUG_CHIP is not set
675
676#
677# Multifunction device drivers
678#
679# CONFIG_MFD_SM501 is not set
680
681#
682# Multimedia devices
683#
684# CONFIG_VIDEO_DEV is not set
685# CONFIG_DVB_CORE is not set
686CONFIG_DAB=y
687
688#
689# Graphics support
690#
691# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
692
693#
694# Display device support
695#
696# CONFIG_DISPLAY_SUPPORT is not set
697# CONFIG_VGASTATE is not set
698# CONFIG_FB is not set
699
700#
701# Sound
702#
703# CONFIG_SOUND is not set
704
705#
706# USB support
707#
708CONFIG_USB_ARCH_HAS_HCD=y
709# CONFIG_USB_ARCH_HAS_OHCI is not set
710# CONFIG_USB_ARCH_HAS_EHCI is not set
711# CONFIG_USB is not set
712# CONFIG_USB_MUSB_HDRC is not set
713# CONFIG_USB_GADGET_MUSB_HDRC is not set
714
715#
716# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
717#
718
719#
720# USB Gadget Support
721#
722CONFIG_USB_GADGET=y
723# CONFIG_USB_GADGET_DEBUG_FILES is not set
724CONFIG_USB_GADGET_SELECTED=y
725# CONFIG_USB_GADGET_FSL_USB2 is not set
726CONFIG_USB_GADGET_NET2272=y
727CONFIG_USB_NET2272=y
728# CONFIG_USB_GADGET_NET2280 is not set
729# CONFIG_USB_GADGET_PXA2XX is not set
730# CONFIG_USB_GADGET_GOKU is not set
731# CONFIG_USB_GADGET_LH7A40X is not set
732# CONFIG_USB_GADGET_OMAP is not set
733# CONFIG_USB_GADGET_AT91 is not set
734# CONFIG_USB_GADGET_DUMMY_HCD is not set
735CONFIG_USB_GADGET_DUALSPEED=y
736# CONFIG_USB_ZERO is not set
737# CONFIG_USB_ETH is not set
738# CONFIG_USB_GADGETFS is not set
739# CONFIG_USB_FILE_STORAGE is not set
740# CONFIG_USB_G_SERIAL is not set
741# CONFIG_USB_MIDI_GADGET is not set
742# CONFIG_MMC is not set
743
744#
745# LED devices
746#
747# CONFIG_NEW_LEDS is not set
748
749#
750# LED drivers
751#
752
753#
754# LED Triggers
755#
756
757#
758# InfiniBand support
759#
760
761#
762# EDAC - error detection and reporting (RAS) (EXPERIMENTAL)
763#
764
765#
766# Real Time Clock
767#
768# CONFIG_RTC_CLASS is not set
769
770#
771# DMA Engine support
772#
773# CONFIG_DMA_ENGINE is not set
774
775#
776# DMA Clients
777#
778
779#
780# DMA Devices
781#
782
783#
784# PBX support
785#
786# CONFIG_PBX is not set
787
788#
789# File systems
790#
791CONFIG_EXT2_FS=y
792CONFIG_EXT2_FS_XATTR=y
793# CONFIG_EXT2_FS_POSIX_ACL is not set
794# CONFIG_EXT2_FS_SECURITY is not set
795# CONFIG_EXT3_FS is not set
796# CONFIG_EXT4DEV_FS is not set
797CONFIG_FS_MBCACHE=y
798# CONFIG_REISERFS_FS is not set
799# CONFIG_JFS_FS is not set
800# CONFIG_FS_POSIX_ACL is not set
801# CONFIG_XFS_FS is not set
802# CONFIG_GFS2_FS is not set
803# CONFIG_OCFS2_FS is not set
804# CONFIG_MINIX_FS is not set
805# CONFIG_ROMFS_FS is not set
806CONFIG_INOTIFY=y
807CONFIG_INOTIFY_USER=y
808# CONFIG_QUOTA is not set
809CONFIG_DNOTIFY=y
810# CONFIG_AUTOFS_FS is not set
811# CONFIG_AUTOFS4_FS is not set
812# CONFIG_FUSE_FS is not set
813
814#
815# CD-ROM/DVD Filesystems
816#
817# CONFIG_ISO9660_FS is not set
818# CONFIG_UDF_FS is not set
819
820#
821# DOS/FAT/NT Filesystems
822#
823# CONFIG_MSDOS_FS is not set
824# CONFIG_VFAT_FS is not set
825# CONFIG_NTFS_FS is not set
826
827#
828# Pseudo filesystems
829#
830CONFIG_PROC_FS=y
831CONFIG_PROC_SYSCTL=y
832CONFIG_SYSFS=y
833# CONFIG_TMPFS is not set
834# CONFIG_HUGETLB_PAGE is not set
835CONFIG_RAMFS=y
836# CONFIG_CONFIGFS_FS is not set
837
838#
839# Miscellaneous filesystems
840#
841# CONFIG_ADFS_FS is not set
842# CONFIG_AFFS_FS is not set
843# CONFIG_HFS_FS is not set
844# CONFIG_HFSPLUS_FS is not set
845# CONFIG_BEFS_FS is not set
846# CONFIG_BFS_FS is not set
847# CONFIG_EFS_FS is not set
848# CONFIG_YAFFS_FS is not set
849# CONFIG_JFFS2_FS is not set
850# CONFIG_CRAMFS is not set
851# CONFIG_VXFS_FS is not set
852# CONFIG_HPFS_FS is not set
853# CONFIG_QNX4FS_FS is not set
854# CONFIG_SYSV_FS is not set
855# CONFIG_UFS_FS is not set
856
857#
858# Network File Systems
859#
860# CONFIG_NFS_FS is not set
861# CONFIG_NFSD is not set
862# CONFIG_SMB_FS is not set
863# CONFIG_CIFS is not set
864# CONFIG_NCP_FS is not set
865# CONFIG_CODA_FS is not set
866# CONFIG_AFS_FS is not set
867# CONFIG_9P_FS is not set
868
869#
870# Partition Types
871#
872# CONFIG_PARTITION_ADVANCED is not set
873CONFIG_MSDOS_PARTITION=y
874
875#
876# Native Language Support
877#
878# CONFIG_NLS is not set
879
880#
881# Distributed Lock Manager
882#
883# CONFIG_DLM is not set
884
885#
886# Profiling support
887#
888# CONFIG_PROFILING is not set
889
890#
891# Kernel hacking
892#
893# CONFIG_PRINTK_TIME is not set
894CONFIG_ENABLE_MUST_CHECK=y
895# CONFIG_MAGIC_SYSRQ is not set
896# CONFIG_UNUSED_SYMBOLS is not set
897# CONFIG_DEBUG_FS is not set
898# CONFIG_HEADERS_CHECK is not set
899# CONFIG_DEBUG_KERNEL is not set
900# CONFIG_DEBUG_BUGVERBOSE is not set
901# CONFIG_DEBUG_MMRS is not set
902# CONFIG_DEBUG_HUNT_FOR_ZERO is not set
903CONFIG_DEBUG_BFIN_HWTRACE_ON=y
904CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_OFF=y
905# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE is not set
906# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_TWO is not set
907CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION=0
908# CONFIG_DEBUG_BFIN_HWTRACE_EXPAND is not set
909# CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE is not set
910# CONFIG_EARLY_PRINTK is not set
911CONFIG_CPLB_INFO=y
912CONFIG_ACCESS_CHECK=y
913
914#
915# Security options
916#
917# CONFIG_KEYS is not set
918CONFIG_SECURITY=y
919# CONFIG_SECURITY_NETWORK is not set
920CONFIG_SECURITY_CAPABILITIES=y
921
922#
923# Cryptographic options
924#
925# CONFIG_CRYPTO is not set
926
927#
928# Library routines
929#
930CONFIG_BITREVERSE=y
931CONFIG_CRC_CCITT=m
932# CONFIG_CRC16 is not set
933# CONFIG_CRC_ITU_T is not set
934CONFIG_CRC32=y
935# CONFIG_LIBCRC32C is not set
936CONFIG_ZLIB_INFLATE=y
937CONFIG_PLIST=y
938CONFIG_HAS_IOMEM=y
939CONFIG_HAS_IOPORT=y
940CONFIG_HAS_DMA=y
diff --git a/arch/blackfin/configs/CM-BF548_defconfig b/arch/blackfin/configs/CM-BF548_defconfig
new file mode 100644
index 000000000000..90207251c533
--- /dev/null
+++ b/arch/blackfin/configs/CM-BF548_defconfig
@@ -0,0 +1,1373 @@
1#
2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.24.4
4#
5# CONFIG_MMU is not set
6# CONFIG_FPU is not set
7CONFIG_RWSEM_GENERIC_SPINLOCK=y
8# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
9CONFIG_BLACKFIN=y
10CONFIG_ZONE_DMA=y
11CONFIG_SEMAPHORE_SLEEPERS=y
12CONFIG_GENERIC_FIND_NEXT_BIT=y
13CONFIG_GENERIC_HWEIGHT=y
14CONFIG_GENERIC_HARDIRQS=y
15CONFIG_GENERIC_IRQ_PROBE=y
16CONFIG_GENERIC_GPIO=y
17CONFIG_FORCE_MAX_ZONEORDER=14
18CONFIG_GENERIC_CALIBRATE_DELAY=y
19CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
20
21#
22# General setup
23#
24CONFIG_EXPERIMENTAL=y
25CONFIG_BROKEN_ON_SMP=y
26CONFIG_INIT_ENV_ARG_LIMIT=32
27CONFIG_LOCALVERSION=""
28CONFIG_LOCALVERSION_AUTO=y
29CONFIG_SYSVIPC=y
30CONFIG_SYSVIPC_SYSCTL=y
31# CONFIG_POSIX_MQUEUE is not set
32# CONFIG_BSD_PROCESS_ACCT is not set
33# CONFIG_TASKSTATS is not set
34# CONFIG_USER_NS is not set
35# CONFIG_PID_NS is not set
36# CONFIG_AUDIT is not set
37CONFIG_IKCONFIG=y
38CONFIG_IKCONFIG_PROC=y
39CONFIG_LOG_BUF_SHIFT=14
40# CONFIG_CGROUPS is not set
41CONFIG_FAIR_GROUP_SCHED=y
42CONFIG_FAIR_USER_SCHED=y
43# CONFIG_FAIR_CGROUP_SCHED is not set
44CONFIG_SYSFS_DEPRECATED=y
45# CONFIG_RELAY is not set
46CONFIG_BLK_DEV_INITRD=y
47CONFIG_INITRAMFS_SOURCE=""
48# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
49CONFIG_SYSCTL=y
50CONFIG_EMBEDDED=y
51CONFIG_UID16=y
52CONFIG_SYSCTL_SYSCALL=y
53CONFIG_KALLSYMS=y
54# CONFIG_KALLSYMS_EXTRA_PASS is not set
55CONFIG_HOTPLUG=y
56CONFIG_PRINTK=y
57CONFIG_BUG=y
58CONFIG_ELF_CORE=y
59CONFIG_BASE_FULL=y
60CONFIG_FUTEX=y
61CONFIG_ANON_INODES=y
62CONFIG_EPOLL=y
63CONFIG_SIGNALFD=y
64CONFIG_EVENTFD=y
65CONFIG_VM_EVENT_COUNTERS=y
66CONFIG_BIG_ORDER_ALLOC_NOFAIL_MAGIC=3
67# CONFIG_NP2 is not set
68CONFIG_SLAB=y
69# CONFIG_SLUB is not set
70# CONFIG_SLOB is not set
71CONFIG_SLABINFO=y
72CONFIG_RT_MUTEXES=y
73CONFIG_TINY_SHMEM=y
74CONFIG_BASE_SMALL=0
75CONFIG_MODULES=y
76CONFIG_MODULE_UNLOAD=y
77# CONFIG_MODULE_FORCE_UNLOAD is not set
78# CONFIG_MODVERSIONS is not set
79# CONFIG_MODULE_SRCVERSION_ALL is not set
80CONFIG_KMOD=y
81CONFIG_BLOCK=y
82# CONFIG_LBD is not set
83# CONFIG_BLK_DEV_IO_TRACE is not set
84# CONFIG_LSF is not set
85# CONFIG_BLK_DEV_BSG is not set
86
87#
88# IO Schedulers
89#
90CONFIG_IOSCHED_NOOP=y
91CONFIG_IOSCHED_AS=y
92# CONFIG_IOSCHED_DEADLINE is not set
93CONFIG_IOSCHED_CFQ=y
94CONFIG_DEFAULT_AS=y
95# CONFIG_DEFAULT_DEADLINE is not set
96# CONFIG_DEFAULT_CFQ is not set
97# CONFIG_DEFAULT_NOOP is not set
98CONFIG_DEFAULT_IOSCHED="anticipatory"
99# CONFIG_PREEMPT_NONE is not set
100CONFIG_PREEMPT_VOLUNTARY=y
101# CONFIG_PREEMPT is not set
102
103#
104# Blackfin Processor Options
105#
106
107#
108# Processor and Board Settings
109#
110# CONFIG_BF522 is not set
111# CONFIG_BF523 is not set
112# CONFIG_BF524 is not set
113# CONFIG_BF525 is not set
114# CONFIG_BF526 is not set
115# CONFIG_BF527 is not set
116# CONFIG_BF531 is not set
117# CONFIG_BF532 is not set
118# CONFIG_BF533 is not set
119# CONFIG_BF534 is not set
120# CONFIG_BF536 is not set
121# CONFIG_BF537 is not set
122# CONFIG_BF542 is not set
123# CONFIG_BF544 is not set
124# CONFIG_BF547 is not set
125CONFIG_BF548=y
126# CONFIG_BF549 is not set
127# CONFIG_BF561 is not set
128CONFIG_BF_REV_0_0=y
129# CONFIG_BF_REV_0_1 is not set
130# CONFIG_BF_REV_0_2 is not set
131# CONFIG_BF_REV_0_3 is not set
132# CONFIG_BF_REV_0_4 is not set
133# CONFIG_BF_REV_0_5 is not set
134# CONFIG_BF_REV_ANY is not set
135# CONFIG_BF_REV_NONE is not set
136CONFIG_BF54x=y
137CONFIG_IRQ_PLL_WAKEUP=7
138CONFIG_IRQ_RTC=8
139CONFIG_IRQ_SPORT0_RX=9
140CONFIG_IRQ_SPORT0_TX=9
141CONFIG_IRQ_SPORT1_RX=9
142CONFIG_IRQ_SPORT1_TX=9
143CONFIG_IRQ_UART0_RX=10
144CONFIG_IRQ_UART0_TX=10
145CONFIG_IRQ_UART1_RX=10
146CONFIG_IRQ_UART1_TX=10
147CONFIG_IRQ_CNT=8
148CONFIG_IRQ_USB_INT0=11
149CONFIG_IRQ_USB_INT1=11
150CONFIG_IRQ_USB_INT2=11
151CONFIG_IRQ_USB_DMA=11
152CONFIG_IRQ_TIMER0=11
153CONFIG_IRQ_TIMER1=11
154CONFIG_IRQ_TIMER2=11
155CONFIG_IRQ_TIMER3=11
156CONFIG_IRQ_TIMER4=11
157CONFIG_IRQ_TIMER5=11
158CONFIG_IRQ_TIMER6=11
159CONFIG_IRQ_TIMER7=11
160CONFIG_IRQ_TIMER8=11
161CONFIG_IRQ_TIMER9=11
162CONFIG_IRQ_TIMER10=11
163# CONFIG_BFIN548_EZKIT is not set
164CONFIG_BFIN548_BLUETECHNIX_CM=y
165
166#
167# BF548 Specific Configuration
168#
169# CONFIG_DEB_DMA_URGENT is not set
170
171#
172# Interrupt Priority Assignment
173#
174
175#
176# Priority
177#
178CONFIG_IRQ_DMAC0_ERR=7
179CONFIG_IRQ_EPPI0_ERR=7
180CONFIG_IRQ_SPORT0_ERR=7
181CONFIG_IRQ_SPORT1_ERR=7
182CONFIG_IRQ_SPI0_ERR=7
183CONFIG_IRQ_UART0_ERR=7
184CONFIG_IRQ_EPPI0=8
185CONFIG_IRQ_SPI0=10
186CONFIG_IRQ_PINT0=12
187CONFIG_IRQ_PINT1=12
188CONFIG_IRQ_MDMAS0=13
189CONFIG_IRQ_MDMAS1=13
190CONFIG_IRQ_WATCHDOG=13
191CONFIG_IRQ_DMAC1_ERR=7
192CONFIG_IRQ_SPORT2_ERR=7
193CONFIG_IRQ_SPORT3_ERR=7
194CONFIG_IRQ_MXVR_DATA=7
195CONFIG_IRQ_SPI1_ERR=7
196CONFIG_IRQ_SPI2_ERR=7
197CONFIG_IRQ_UART1_ERR=7
198CONFIG_IRQ_UART2_ERR=7
199CONFIG_IRQ_CAN0_ERR=7
200CONFIG_IRQ_SPORT2_RX=9
201CONFIG_IRQ_SPORT2_TX=9
202CONFIG_IRQ_SPORT3_RX=9
203CONFIG_IRQ_SPORT3_TX=9
204CONFIG_IRQ_EPPI1=9
205CONFIG_IRQ_EPPI2=9
206CONFIG_IRQ_SPI1=10
207CONFIG_IRQ_SPI2=10
208CONFIG_IRQ_ATAPI_RX=10
209CONFIG_IRQ_ATAPI_TX=10
210CONFIG_IRQ_TWI0=11
211CONFIG_IRQ_TWI1=11
212CONFIG_IRQ_CAN0_RX=11
213CONFIG_IRQ_CAN0_TX=11
214CONFIG_IRQ_MDMAS2=13
215CONFIG_IRQ_MDMAS3=13
216CONFIG_IRQ_MXVR_ERR=11
217CONFIG_IRQ_MXVR_MSG=11
218CONFIG_IRQ_MXVR_PKT=11
219CONFIG_IRQ_EPPI1_ERR=7
220CONFIG_IRQ_EPPI2_ERR=7
221CONFIG_IRQ_UART3_ERR=7
222CONFIG_IRQ_HOST_ERR=7
223CONFIG_IRQ_PIXC_ERR=7
224CONFIG_IRQ_NFC_ERR=7
225CONFIG_IRQ_ATAPI_ERR=7
226CONFIG_IRQ_CAN1_ERR=7
227CONFIG_IRQ_HS_DMA_ERR=7
228CONFIG_IRQ_PIXC_IN0=8
229CONFIG_IRQ_PIXC_IN1=8
230CONFIG_IRQ_PIXC_OUT=8
231CONFIG_IRQ_SDH=8
232CONFIG_IRQ_KEY=8
233CONFIG_IRQ_CAN1_RX=11
234CONFIG_IRQ_CAN1_TX=11
235CONFIG_IRQ_SDH_MASK0=11
236CONFIG_IRQ_SDH_MASK1=11
237CONFIG_IRQ_OTPSEC=11
238CONFIG_IRQ_PINT2=11
239CONFIG_IRQ_PINT3=11
240
241#
242# Pin Interrupt to Port Assignment
243#
244
245#
246# Assignment
247#
248CONFIG_PINTx_REASSIGN=y
249CONFIG_PINT0_ASSIGN=0x00000101
250CONFIG_PINT1_ASSIGN=0x01010000
251CONFIG_PINT2_ASSIGN=0x07000101
252CONFIG_PINT3_ASSIGN=0x02020303
253
254#
255# Board customizations
256#
257# CONFIG_CMDLINE_BOOL is not set
258
259#
260# Clock/PLL Setup
261#
262CONFIG_CLKIN_HZ=25000000
263# CONFIG_BFIN_KERNEL_CLOCK is not set
264CONFIG_MAX_VCO_HZ=600000000
265CONFIG_MIN_VCO_HZ=50000000
266CONFIG_MAX_SCLK_HZ=133333333
267CONFIG_MIN_SCLK_HZ=27000000
268
269#
270# Kernel Timer/Scheduler
271#
272# CONFIG_HZ_100 is not set
273CONFIG_HZ_250=y
274# CONFIG_HZ_300 is not set
275# CONFIG_HZ_1000 is not set
276CONFIG_HZ=250
277# CONFIG_GENERIC_TIME is not set
278# CONFIG_TICK_ONESHOT is not set
279
280#
281# Memory Setup
282#
283CONFIG_MAX_MEM_SIZE=64
284# CONFIG_MEM_MT46V32M16_6T is not set
285CONFIG_MEM_MT46V32M16_5B=y
286CONFIG_BOOT_LOAD=0x1000
287CONFIG_BFIN_SCRATCH_REG_RETN=y
288# CONFIG_BFIN_SCRATCH_REG_RETE is not set
289# CONFIG_BFIN_SCRATCH_REG_CYCLES is not set
290
291#
292# Blackfin Kernel Optimizations
293#
294
295#
296# Memory Optimizations
297#
298CONFIG_I_ENTRY_L1=y
299CONFIG_EXCPT_IRQ_SYSC_L1=y
300CONFIG_DO_IRQ_L1=y
301CONFIG_CORE_TIMER_IRQ_L1=y
302CONFIG_IDLE_L1=y
303# CONFIG_SCHEDULE_L1 is not set
304CONFIG_ARITHMETIC_OPS_L1=y
305CONFIG_ACCESS_OK_L1=y
306# CONFIG_MEMSET_L1 is not set
307# CONFIG_MEMCPY_L1 is not set
308# CONFIG_SYS_BFIN_SPINLOCK_L1 is not set
309# CONFIG_IP_CHECKSUM_L1 is not set
310CONFIG_CACHELINE_ALIGNED_L1=y
311# CONFIG_SYSCALL_TAB_L1 is not set
312# CONFIG_CPLB_SWITCH_TAB_L1 is not set
313CONFIG_RAMKERNEL=y
314# CONFIG_ROMKERNEL is not set
315CONFIG_SELECT_MEMORY_MODEL=y
316CONFIG_FLATMEM_MANUAL=y
317# CONFIG_DISCONTIGMEM_MANUAL is not set
318# CONFIG_SPARSEMEM_MANUAL is not set
319CONFIG_FLATMEM=y
320CONFIG_FLAT_NODE_MEM_MAP=y
321# CONFIG_SPARSEMEM_STATIC is not set
322# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
323CONFIG_SPLIT_PTLOCK_CPUS=4
324# CONFIG_RESOURCES_64BIT is not set
325CONFIG_ZONE_DMA_FLAG=1
326CONFIG_VIRT_TO_BUS=y
327# CONFIG_BFIN_GPTIMERS is not set
328CONFIG_BFIN_DMA_5XX=y
329# CONFIG_DMA_UNCACHED_2M is not set
330CONFIG_DMA_UNCACHED_1M=y
331# CONFIG_DMA_UNCACHED_NONE is not set
332
333#
334# Cache Support
335#
336CONFIG_BFIN_ICACHE=y
337CONFIG_BFIN_DCACHE=y
338# CONFIG_BFIN_DCACHE_BANKA is not set
339# CONFIG_BFIN_ICACHE_LOCK is not set
340# CONFIG_BFIN_WB is not set
341CONFIG_BFIN_WT=y
342CONFIG_L1_MAX_PIECE=16
343# CONFIG_MPU is not set
344
345#
346# Asynchonous Memory Configuration
347#
348
349#
350# EBIU_AMGCTL Global Control
351#
352CONFIG_C_AMCKEN=y
353# CONFIG_C_CDPRIO is not set
354# CONFIG_C_AMBEN is not set
355# CONFIG_C_AMBEN_B0 is not set
356# CONFIG_C_AMBEN_B0_B1 is not set
357# CONFIG_C_AMBEN_B0_B1_B2 is not set
358CONFIG_C_AMBEN_ALL=y
359
360#
361# EBIU_AMBCTL Control
362#
363CONFIG_BANK_0=0x7BB0
364CONFIG_BANK_1=0x5554
365CONFIG_BANK_2=0x7BB0
366CONFIG_BANK_3=0x99B3
367CONFIG_EBIU_MBSCTLVAL=0x0
368CONFIG_EBIU_MODEVAL=0x1
369CONFIG_EBIU_FCTLVAL=0x6
370
371#
372# Bus options (PCI, PCMCIA, EISA, MCA, ISA)
373#
374# CONFIG_PCI is not set
375# CONFIG_ARCH_SUPPORTS_MSI is not set
376# CONFIG_PCCARD is not set
377
378#
379# Executable file formats
380#
381CONFIG_BINFMT_ELF_FDPIC=y
382CONFIG_BINFMT_FLAT=y
383CONFIG_BINFMT_ZFLAT=y
384# CONFIG_BINFMT_SHARED_FLAT is not set
385# CONFIG_BINFMT_MISC is not set
386
387#
388# Power management options
389#
390# CONFIG_PM is not set
391CONFIG_SUSPEND_UP_POSSIBLE=y
392# CONFIG_PM_WAKEUP_BY_GPIO is not set
393
394#
395# CPU Frequency scaling
396#
397# CONFIG_CPU_FREQ is not set
398
399#
400# Networking
401#
402CONFIG_NET=y
403
404#
405# Networking options
406#
407CONFIG_PACKET=y
408# CONFIG_PACKET_MMAP is not set
409CONFIG_UNIX=y
410CONFIG_XFRM=y
411# CONFIG_XFRM_USER is not set
412# CONFIG_XFRM_SUB_POLICY is not set
413# CONFIG_XFRM_MIGRATE is not set
414# CONFIG_NET_KEY is not set
415CONFIG_INET=y
416# CONFIG_IP_MULTICAST is not set
417# CONFIG_IP_ADVANCED_ROUTER is not set
418CONFIG_IP_FIB_HASH=y
419CONFIG_IP_PNP=y
420# CONFIG_IP_PNP_DHCP is not set
421# CONFIG_IP_PNP_BOOTP is not set
422# CONFIG_IP_PNP_RARP is not set
423# CONFIG_NET_IPIP is not set
424# CONFIG_NET_IPGRE is not set
425# CONFIG_ARPD is not set
426CONFIG_SYN_COOKIES=y
427# CONFIG_INET_AH is not set
428# CONFIG_INET_ESP is not set
429# CONFIG_INET_IPCOMP is not set
430# CONFIG_INET_XFRM_TUNNEL is not set
431# CONFIG_INET_TUNNEL is not set
432CONFIG_INET_XFRM_MODE_TRANSPORT=y
433CONFIG_INET_XFRM_MODE_TUNNEL=y
434CONFIG_INET_XFRM_MODE_BEET=y
435# CONFIG_INET_LRO is not set
436CONFIG_INET_DIAG=y
437CONFIG_INET_TCP_DIAG=y
438# CONFIG_TCP_CONG_ADVANCED is not set
439CONFIG_TCP_CONG_CUBIC=y
440CONFIG_DEFAULT_TCP_CONG="cubic"
441# CONFIG_TCP_MD5SIG is not set
442# CONFIG_IPV6 is not set
443# CONFIG_INET6_XFRM_TUNNEL is not set
444# CONFIG_INET6_TUNNEL is not set
445# CONFIG_NETLABEL is not set
446# CONFIG_NETWORK_SECMARK is not set
447# CONFIG_NETFILTER is not set
448# CONFIG_IP_DCCP is not set
449# CONFIG_IP_SCTP is not set
450# CONFIG_TIPC is not set
451# CONFIG_ATM is not set
452# CONFIG_BRIDGE is not set
453# CONFIG_VLAN_8021Q is not set
454# CONFIG_DECNET is not set
455# CONFIG_LLC2 is not set
456# CONFIG_IPX is not set
457# CONFIG_ATALK is not set
458# CONFIG_X25 is not set
459# CONFIG_LAPB is not set
460# CONFIG_ECONET is not set
461# CONFIG_WAN_ROUTER is not set
462# CONFIG_NET_SCHED is not set
463
464#
465# Network testing
466#
467# CONFIG_NET_PKTGEN is not set
468# CONFIG_HAMRADIO is not set
469# CONFIG_IRDA is not set
470# CONFIG_BT is not set
471# CONFIG_AF_RXRPC is not set
472
473#
474# Wireless
475#
476# CONFIG_CFG80211 is not set
477# CONFIG_WIRELESS_EXT is not set
478# CONFIG_MAC80211 is not set
479# CONFIG_IEEE80211 is not set
480# CONFIG_RFKILL is not set
481# CONFIG_NET_9P is not set
482
483#
484# Device Drivers
485#
486
487#
488# Generic Driver Options
489#
490CONFIG_UEVENT_HELPER_PATH="/sbin/hotplug"
491CONFIG_STANDALONE=y
492CONFIG_PREVENT_FIRMWARE_BUILD=y
493# CONFIG_FW_LOADER is not set
494# CONFIG_SYS_HYPERVISOR is not set
495# CONFIG_CONNECTOR is not set
496CONFIG_MTD=y
497# CONFIG_MTD_DEBUG is not set
498# CONFIG_MTD_CONCAT is not set
499CONFIG_MTD_PARTITIONS=y
500# CONFIG_MTD_REDBOOT_PARTS is not set
501CONFIG_MTD_CMDLINE_PARTS=y
502
503#
504# User Modules And Translation Layers
505#
506CONFIG_MTD_CHAR=y
507CONFIG_MTD_BLKDEVS=y
508CONFIG_MTD_BLOCK=y
509# CONFIG_FTL is not set
510# CONFIG_NFTL is not set
511# CONFIG_INFTL is not set
512# CONFIG_RFD_FTL is not set
513# CONFIG_SSFDC is not set
514# CONFIG_MTD_OOPS is not set
515
516#
517# RAM/ROM/Flash chip drivers
518#
519CONFIG_MTD_CFI=y
520# CONFIG_MTD_JEDECPROBE is not set
521CONFIG_MTD_GEN_PROBE=y
522# CONFIG_MTD_CFI_ADV_OPTIONS is not set
523CONFIG_MTD_MAP_BANK_WIDTH_1=y
524CONFIG_MTD_MAP_BANK_WIDTH_2=y
525CONFIG_MTD_MAP_BANK_WIDTH_4=y
526# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
527# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
528# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
529CONFIG_MTD_CFI_I1=y
530CONFIG_MTD_CFI_I2=y
531# CONFIG_MTD_CFI_I4 is not set
532# CONFIG_MTD_CFI_I8 is not set
533CONFIG_MTD_CFI_INTELEXT=y
534# CONFIG_MTD_CFI_AMDSTD is not set
535# CONFIG_MTD_CFI_STAA is not set
536CONFIG_MTD_CFI_UTIL=y
537CONFIG_MTD_RAM=y
538# CONFIG_MTD_ROM is not set
539# CONFIG_MTD_ABSENT is not set
540
541#
542# Mapping drivers for chip access
543#
544CONFIG_MTD_COMPLEX_MAPPINGS=y
545CONFIG_MTD_PHYSMAP=y
546CONFIG_MTD_PHYSMAP_START=0x20000000
547CONFIG_MTD_PHYSMAP_LEN=0x800000
548CONFIG_MTD_PHYSMAP_BANKWIDTH=2
549# CONFIG_MTD_UCLINUX is not set
550# CONFIG_MTD_PLATRAM is not set
551
552#
553# Self-contained MTD device drivers
554#
555# CONFIG_MTD_DATAFLASH is not set
556# CONFIG_MTD_M25P80 is not set
557# CONFIG_MTD_SLRAM is not set
558# CONFIG_MTD_PHRAM is not set
559# CONFIG_MTD_MTDRAM is not set
560# CONFIG_MTD_BLOCK2MTD is not set
561
562#
563# Disk-On-Chip Device Drivers
564#
565# CONFIG_MTD_DOC2000 is not set
566# CONFIG_MTD_DOC2001 is not set
567# CONFIG_MTD_DOC2001PLUS is not set
568# CONFIG_MTD_NAND is not set
569# CONFIG_MTD_ONENAND is not set
570
571#
572# UBI - Unsorted block images
573#
574# CONFIG_MTD_UBI is not set
575# CONFIG_PARPORT is not set
576CONFIG_BLK_DEV=y
577# CONFIG_BLK_DEV_COW_COMMON is not set
578# CONFIG_BLK_DEV_LOOP is not set
579# CONFIG_BLK_DEV_NBD is not set
580# CONFIG_BLK_DEV_UB is not set
581CONFIG_BLK_DEV_RAM=y
582CONFIG_BLK_DEV_RAM_COUNT=16
583CONFIG_BLK_DEV_RAM_SIZE=4096
584CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
585# CONFIG_CDROM_PKTCDVD is not set
586# CONFIG_ATA_OVER_ETH is not set
587CONFIG_MISC_DEVICES=y
588# CONFIG_EEPROM_93CX6 is not set
589# CONFIG_IDE is not set
590
591#
592# SCSI device support
593#
594# CONFIG_RAID_ATTRS is not set
595CONFIG_SCSI=y
596CONFIG_SCSI_DMA=y
597# CONFIG_SCSI_TGT is not set
598# CONFIG_SCSI_NETLINK is not set
599CONFIG_SCSI_PROC_FS=y
600
601#
602# SCSI support type (disk, tape, CD-ROM)
603#
604CONFIG_BLK_DEV_SD=y
605# CONFIG_CHR_DEV_ST is not set
606# CONFIG_CHR_DEV_OSST is not set
607CONFIG_BLK_DEV_SR=y
608# CONFIG_BLK_DEV_SR_VENDOR is not set
609# CONFIG_CHR_DEV_SG is not set
610# CONFIG_CHR_DEV_SCH is not set
611
612#
613# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
614#
615# CONFIG_SCSI_MULTI_LUN is not set
616# CONFIG_SCSI_CONSTANTS is not set
617# CONFIG_SCSI_LOGGING is not set
618# CONFIG_SCSI_SCAN_ASYNC is not set
619CONFIG_SCSI_WAIT_SCAN=m
620
621#
622# SCSI Transports
623#
624# CONFIG_SCSI_SPI_ATTRS is not set
625# CONFIG_SCSI_FC_ATTRS is not set
626# CONFIG_SCSI_ISCSI_ATTRS is not set
627# CONFIG_SCSI_SAS_LIBSAS is not set
628# CONFIG_SCSI_SRP_ATTRS is not set
629CONFIG_SCSI_LOWLEVEL=y
630# CONFIG_ISCSI_TCP is not set
631# CONFIG_SCSI_DEBUG is not set
632# CONFIG_ATA is not set
633# CONFIG_MD is not set
634CONFIG_NETDEVICES=y
635# CONFIG_NETDEVICES_MULTIQUEUE is not set
636# CONFIG_DUMMY is not set
637# CONFIG_BONDING is not set
638# CONFIG_MACVLAN is not set
639# CONFIG_EQUALIZER is not set
640# CONFIG_TUN is not set
641# CONFIG_VETH is not set
642# CONFIG_PHYLIB is not set
643CONFIG_NET_ETHERNET=y
644CONFIG_MII=y
645# CONFIG_SMC91X is not set
646CONFIG_SMSC911X=y
647# CONFIG_DM9000 is not set
648# CONFIG_IBM_NEW_EMAC_ZMII is not set
649# CONFIG_IBM_NEW_EMAC_RGMII is not set
650# CONFIG_IBM_NEW_EMAC_TAH is not set
651# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
652# CONFIG_B44 is not set
653# CONFIG_NETDEV_1000 is not set
654# CONFIG_NETDEV_10000 is not set
655
656#
657# Wireless LAN
658#
659# CONFIG_WLAN_PRE80211 is not set
660# CONFIG_WLAN_80211 is not set
661
662#
663# USB Network Adapters
664#
665# CONFIG_USB_CATC is not set
666# CONFIG_USB_KAWETH is not set
667# CONFIG_USB_PEGASUS is not set
668# CONFIG_USB_RTL8150 is not set
669# CONFIG_USB_USBNET is not set
670# CONFIG_WAN is not set
671# CONFIG_PPP is not set
672# CONFIG_SLIP is not set
673# CONFIG_SHAPER is not set
674# CONFIG_NETCONSOLE is not set
675# CONFIG_NETPOLL is not set
676# CONFIG_NET_POLL_CONTROLLER is not set
677# CONFIG_ISDN is not set
678# CONFIG_PHONE is not set
679
680#
681# Input device support
682#
683CONFIG_INPUT=y
684# CONFIG_INPUT_FF_MEMLESS is not set
685# CONFIG_INPUT_POLLDEV is not set
686
687#
688# Userland interfaces
689#
690# CONFIG_INPUT_MOUSEDEV is not set
691# CONFIG_INPUT_JOYDEV is not set
692CONFIG_INPUT_EVDEV=m
693CONFIG_INPUT_EVBUG=m
694
695#
696# Input Device Drivers
697#
698CONFIG_INPUT_KEYBOARD=y
699# CONFIG_KEYBOARD_ATKBD is not set
700# CONFIG_KEYBOARD_SUNKBD is not set
701# CONFIG_KEYBOARD_LKKBD is not set
702# CONFIG_KEYBOARD_XTKBD is not set
703# CONFIG_KEYBOARD_NEWTON is not set
704# CONFIG_KEYBOARD_STOWAWAY is not set
705# CONFIG_KEYBOARD_GPIO is not set
706# CONFIG_KEYBOARD_BFIN is not set
707# CONFIG_KEYBOARD_OPENCORES is not set
708# CONFIG_INPUT_MOUSE is not set
709# CONFIG_INPUT_JOYSTICK is not set
710# CONFIG_INPUT_TABLET is not set
711# CONFIG_INPUT_TOUCHSCREEN is not set
712# CONFIG_INPUT_MISC is not set
713
714#
715# Hardware I/O ports
716#
717# CONFIG_SERIO is not set
718# CONFIG_GAMEPORT is not set
719
720#
721# Character devices
722#
723# CONFIG_AD9960 is not set
724# CONFIG_SPI_ADC_BF533 is not set
725# CONFIG_BF5xx_PPIFCD is not set
726# CONFIG_BFIN_SIMPLE_TIMER is not set
727# CONFIG_BF5xx_PPI is not set
728CONFIG_BFIN_OTP=y
729# CONFIG_BFIN_OTP_WRITE_ENABLE is not set
730# CONFIG_BFIN_SPORT is not set
731# CONFIG_BFIN_TIMER_LATENCY is not set
732# CONFIG_TWI_LCD is not set
733# CONFIG_SIMPLE_GPIO is not set
734# CONFIG_VT is not set
735# CONFIG_SERIAL_NONSTANDARD is not set
736
737#
738# Serial drivers
739#
740# CONFIG_SERIAL_8250 is not set
741
742#
743# Non-8250 serial port support
744#
745CONFIG_SERIAL_BFIN=y
746CONFIG_SERIAL_BFIN_CONSOLE=y
747# CONFIG_SERIAL_BFIN_DMA is not set
748CONFIG_SERIAL_BFIN_PIO=y
749# CONFIG_SERIAL_BFIN_UART0 is not set
750CONFIG_SERIAL_BFIN_UART1=y
751# CONFIG_BFIN_UART1_CTSRTS is not set
752# CONFIG_SERIAL_BFIN_UART2 is not set
753# CONFIG_SERIAL_BFIN_UART3 is not set
754CONFIG_SERIAL_CORE=y
755CONFIG_SERIAL_CORE_CONSOLE=y
756# CONFIG_SERIAL_BFIN_SPORT is not set
757CONFIG_UNIX98_PTYS=y
758# CONFIG_LEGACY_PTYS is not set
759
760#
761# CAN, the car bus and industrial fieldbus
762#
763# CONFIG_CAN4LINUX is not set
764# CONFIG_IPMI_HANDLER is not set
765CONFIG_HW_RANDOM=y
766# CONFIG_GEN_RTC is not set
767# CONFIG_R3964 is not set
768# CONFIG_RAW_DRIVER is not set
769# CONFIG_TCG_TPM is not set
770CONFIG_I2C=y
771CONFIG_I2C_BOARDINFO=y
772CONFIG_I2C_CHARDEV=y
773
774#
775# I2C Algorithms
776#
777# CONFIG_I2C_ALGOBIT is not set
778# CONFIG_I2C_ALGOPCF is not set
779# CONFIG_I2C_ALGOPCA is not set
780
781#
782# I2C Hardware Bus support
783#
784CONFIG_I2C_BLACKFIN_TWI=y
785CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ=50
786# CONFIG_I2C_GPIO is not set
787# CONFIG_I2C_OCORES is not set
788# CONFIG_I2C_PARPORT_LIGHT is not set
789# CONFIG_I2C_SIMTEC is not set
790# CONFIG_I2C_TAOS_EVM is not set
791# CONFIG_I2C_STUB is not set
792# CONFIG_I2C_TINY_USB is not set
793
794#
795# Miscellaneous I2C Chip support
796#
797# CONFIG_SENSORS_DS1337 is not set
798# CONFIG_SENSORS_DS1374 is not set
799# CONFIG_DS1682 is not set
800# CONFIG_SENSORS_AD5252 is not set
801# CONFIG_SENSORS_EEPROM is not set
802# CONFIG_SENSORS_PCF8574 is not set
803# CONFIG_SENSORS_PCF8575 is not set
804# CONFIG_SENSORS_PCA9543 is not set
805# CONFIG_SENSORS_PCA9539 is not set
806# CONFIG_SENSORS_PCF8591 is not set
807# CONFIG_SENSORS_MAX6875 is not set
808# CONFIG_SENSORS_TSL2550 is not set
809# CONFIG_I2C_DEBUG_CORE is not set
810# CONFIG_I2C_DEBUG_ALGO is not set
811# CONFIG_I2C_DEBUG_BUS is not set
812# CONFIG_I2C_DEBUG_CHIP is not set
813
814#
815# SPI support
816#
817CONFIG_SPI=y
818CONFIG_SPI_MASTER=y
819
820#
821# SPI Master Controller Drivers
822#
823CONFIG_SPI_BFIN=y
824# CONFIG_SPI_BITBANG is not set
825
826#
827# SPI Protocol Masters
828#
829# CONFIG_SPI_AT25 is not set
830# CONFIG_SPI_SPIDEV is not set
831# CONFIG_SPI_TLE62X0 is not set
832# CONFIG_W1 is not set
833# CONFIG_POWER_SUPPLY is not set
834CONFIG_HWMON=y
835# CONFIG_HWMON_VID is not set
836# CONFIG_SENSORS_AD7418 is not set
837# CONFIG_SENSORS_ADM1021 is not set
838# CONFIG_SENSORS_ADM1025 is not set
839# CONFIG_SENSORS_ADM1026 is not set
840# CONFIG_SENSORS_ADM1029 is not set
841# CONFIG_SENSORS_ADM1031 is not set
842# CONFIG_SENSORS_ADM9240 is not set
843# CONFIG_SENSORS_ADT7470 is not set
844# CONFIG_SENSORS_ATXP1 is not set
845# CONFIG_SENSORS_DS1621 is not set
846# CONFIG_SENSORS_F71805F is not set
847# CONFIG_SENSORS_F71882FG is not set
848# CONFIG_SENSORS_F75375S is not set
849# CONFIG_SENSORS_GL518SM is not set
850# CONFIG_SENSORS_GL520SM is not set
851# CONFIG_SENSORS_IT87 is not set
852# CONFIG_SENSORS_LM63 is not set
853# CONFIG_SENSORS_LM70 is not set
854# CONFIG_SENSORS_LM75 is not set
855# CONFIG_SENSORS_LM77 is not set
856# CONFIG_SENSORS_LM78 is not set
857# CONFIG_SENSORS_LM80 is not set
858# CONFIG_SENSORS_LM83 is not set
859# CONFIG_SENSORS_LM85 is not set
860# CONFIG_SENSORS_LM87 is not set
861# CONFIG_SENSORS_LM90 is not set
862# CONFIG_SENSORS_LM92 is not set
863# CONFIG_SENSORS_LM93 is not set
864# CONFIG_SENSORS_MAX1619 is not set
865# CONFIG_SENSORS_MAX6650 is not set
866# CONFIG_SENSORS_PC87360 is not set
867# CONFIG_SENSORS_PC87427 is not set
868# CONFIG_SENSORS_DME1737 is not set
869# CONFIG_SENSORS_SMSC47M1 is not set
870# CONFIG_SENSORS_SMSC47M192 is not set
871# CONFIG_SENSORS_SMSC47B397 is not set
872# CONFIG_SENSORS_THMC50 is not set
873# CONFIG_SENSORS_VT1211 is not set
874# CONFIG_SENSORS_W83781D is not set
875# CONFIG_SENSORS_W83791D is not set
876# CONFIG_SENSORS_W83792D is not set
877# CONFIG_SENSORS_W83793 is not set
878# CONFIG_SENSORS_W83L785TS is not set
879# CONFIG_SENSORS_W83627HF is not set
880# CONFIG_SENSORS_W83627EHF is not set
881# CONFIG_HWMON_DEBUG_CHIP is not set
882CONFIG_WATCHDOG=y
883# CONFIG_WATCHDOG_NOWAYOUT is not set
884
885#
886# Watchdog Device Drivers
887#
888# CONFIG_SOFT_WATCHDOG is not set
889CONFIG_BFIN_WDT=y
890
891#
892# USB-based Watchdog Cards
893#
894# CONFIG_USBPCWATCHDOG is not set
895
896#
897# Sonics Silicon Backplane
898#
899CONFIG_SSB_POSSIBLE=y
900# CONFIG_SSB is not set
901
902#
903# Multifunction device drivers
904#
905# CONFIG_MFD_SM501 is not set
906
907#
908# Multimedia devices
909#
910# CONFIG_VIDEO_DEV is not set
911# CONFIG_DVB_CORE is not set
912CONFIG_DAB=y
913# CONFIG_USB_DABUSB is not set
914
915#
916# Graphics support
917#
918# CONFIG_VGASTATE is not set
919# CONFIG_VIDEO_OUTPUT_CONTROL is not set
920# CONFIG_FB is not set
921# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
922
923#
924# Display device support
925#
926# CONFIG_DISPLAY_SUPPORT is not set
927
928#
929# Sound
930#
931# CONFIG_SOUND is not set
932CONFIG_HID_SUPPORT=y
933CONFIG_HID=y
934# CONFIG_HID_DEBUG is not set
935# CONFIG_HIDRAW is not set
936
937#
938# USB Input Devices
939#
940CONFIG_USB_HID=y
941# CONFIG_USB_HIDINPUT_POWERBOOK is not set
942# CONFIG_HID_FF is not set
943# CONFIG_USB_HIDDEV is not set
944CONFIG_USB_SUPPORT=y
945CONFIG_USB_ARCH_HAS_HCD=y
946# CONFIG_USB_ARCH_HAS_OHCI is not set
947# CONFIG_USB_ARCH_HAS_EHCI is not set
948CONFIG_USB=y
949# CONFIG_USB_DEBUG is not set
950
951#
952# Miscellaneous USB options
953#
954# CONFIG_USB_DEVICEFS is not set
955CONFIG_USB_DEVICE_CLASS=y
956# CONFIG_USB_DYNAMIC_MINORS is not set
957# CONFIG_USB_OTG is not set
958
959#
960# USB Host Controller Drivers
961#
962# CONFIG_USB_ISP116X_HCD is not set
963# CONFIG_USB_ISP1362_HCD is not set
964# CONFIG_USB_ISP1760_HCD is not set
965# CONFIG_USB_SL811_HCD is not set
966# CONFIG_USB_R8A66597_HCD is not set
967CONFIG_USB_MUSB_HDRC=y
968CONFIG_USB_MUSB_SOC=y
969
970#
971# Blackfin BF54x, BF525 and BF527 high speed USB support
972#
973CONFIG_USB_MUSB_HOST=y
974# CONFIG_USB_MUSB_PERIPHERAL is not set
975# CONFIG_USB_MUSB_OTG is not set
976CONFIG_USB_MUSB_HDRC_HCD=y
977# CONFIG_MUSB_PIO_ONLY is not set
978# CONFIG_USB_INVENTRA_DMA is not set
979# CONFIG_USB_TI_CPPI_DMA is not set
980CONFIG_USB_MUSB_LOGLEVEL=0
981
982#
983# USB Device Class drivers
984#
985# CONFIG_USB_ACM is not set
986# CONFIG_USB_PRINTER is not set
987
988#
989# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
990#
991
992#
993# may also be needed; see USB_STORAGE Help for more information
994#
995CONFIG_USB_STORAGE=y
996# CONFIG_USB_STORAGE_DEBUG is not set
997# CONFIG_USB_STORAGE_DATAFAB is not set
998# CONFIG_USB_STORAGE_FREECOM is not set
999# CONFIG_USB_STORAGE_ISD200 is not set
1000# CONFIG_USB_STORAGE_DPCM is not set
1001# CONFIG_USB_STORAGE_USBAT is not set
1002# CONFIG_USB_STORAGE_SDDR09 is not set
1003# CONFIG_USB_STORAGE_SDDR55 is not set
1004# CONFIG_USB_STORAGE_JUMPSHOT is not set
1005# CONFIG_USB_STORAGE_ALAUDA is not set
1006# CONFIG_USB_STORAGE_ONETOUCH is not set
1007# CONFIG_USB_STORAGE_KARMA is not set
1008# CONFIG_USB_LIBUSUAL is not set
1009
1010#
1011# USB Imaging devices
1012#
1013# CONFIG_USB_MDC800 is not set
1014# CONFIG_USB_MICROTEK is not set
1015CONFIG_USB_MON=y
1016
1017#
1018# USB port drivers
1019#
1020
1021#
1022# USB Serial Converter support
1023#
1024# CONFIG_USB_SERIAL is not set
1025
1026#
1027# USB Miscellaneous drivers
1028#
1029# CONFIG_USB_EMI62 is not set
1030# CONFIG_USB_EMI26 is not set
1031# CONFIG_USB_ADUTUX is not set
1032# CONFIG_USB_AUERSWALD is not set
1033# CONFIG_USB_RIO500 is not set
1034# CONFIG_USB_LEGOTOWER is not set
1035# CONFIG_USB_LCD is not set
1036# CONFIG_USB_BERRY_CHARGE is not set
1037# CONFIG_USB_LED is not set
1038# CONFIG_USB_CYPRESS_CY7C63 is not set
1039# CONFIG_USB_CYTHERM is not set
1040# CONFIG_USB_PHIDGET is not set
1041# CONFIG_USB_IDMOUSE is not set
1042# CONFIG_USB_FTDI_ELAN is not set
1043# CONFIG_USB_APPLEDISPLAY is not set
1044# CONFIG_USB_SISUSBVGA is not set
1045# CONFIG_USB_LD is not set
1046# CONFIG_USB_TRANCEVIBRATOR is not set
1047# CONFIG_USB_IOWARRIOR is not set
1048
1049#
1050# USB DSL modem support
1051#
1052
1053#
1054# USB Gadget Support
1055#
1056# CONFIG_USB_GADGET is not set
1057CONFIG_MMC=y
1058# CONFIG_MMC_DEBUG is not set
1059# CONFIG_MMC_UNSAFE_RESUME is not set
1060
1061#
1062# MMC/SD Card Drivers
1063#
1064CONFIG_MMC_BLOCK=y
1065CONFIG_MMC_BLOCK_BOUNCE=y
1066# CONFIG_SDIO_UART is not set
1067
1068#
1069# MMC/SD Host Controller Drivers
1070#
1071CONFIG_SDH_BFIN=y
1072# CONFIG_MMC_SPI is not set
1073# CONFIG_SPI_MMC is not set
1074# CONFIG_NEW_LEDS is not set
1075CONFIG_RTC_LIB=y
1076CONFIG_RTC_CLASS=y
1077CONFIG_RTC_HCTOSYS=y
1078CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
1079# CONFIG_RTC_DEBUG is not set
1080
1081#
1082# RTC interfaces
1083#
1084CONFIG_RTC_INTF_SYSFS=y
1085CONFIG_RTC_INTF_PROC=y
1086CONFIG_RTC_INTF_DEV=y
1087# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
1088# CONFIG_RTC_DRV_TEST is not set
1089
1090#
1091# I2C RTC drivers
1092#
1093# CONFIG_RTC_DRV_DS1307 is not set
1094# CONFIG_RTC_DRV_DS1374 is not set
1095# CONFIG_RTC_DRV_DS1672 is not set
1096# CONFIG_RTC_DRV_MAX6900 is not set
1097# CONFIG_RTC_DRV_RS5C372 is not set
1098# CONFIG_RTC_DRV_ISL1208 is not set
1099# CONFIG_RTC_DRV_X1205 is not set
1100# CONFIG_RTC_DRV_PCF8563 is not set
1101# CONFIG_RTC_DRV_PCF8583 is not set
1102# CONFIG_RTC_DRV_M41T80 is not set
1103
1104#
1105# SPI RTC drivers
1106#
1107# CONFIG_RTC_DRV_RS5C348 is not set
1108# CONFIG_RTC_DRV_MAX6902 is not set
1109
1110#
1111# Platform RTC drivers
1112#
1113# CONFIG_RTC_DRV_DS1553 is not set
1114# CONFIG_RTC_DRV_STK17TA8 is not set
1115# CONFIG_RTC_DRV_DS1742 is not set
1116# CONFIG_RTC_DRV_M48T86 is not set
1117# CONFIG_RTC_DRV_M48T59 is not set
1118# CONFIG_RTC_DRV_V3020 is not set
1119
1120#
1121# on-CPU RTC drivers
1122#
1123CONFIG_RTC_DRV_BFIN=y
1124
1125#
1126# Userspace I/O
1127#
1128# CONFIG_UIO is not set
1129
1130#
1131# PBX support
1132#
1133# CONFIG_PBX is not set
1134
1135#
1136# File systems
1137#
1138# CONFIG_EXT2_FS is not set
1139# CONFIG_EXT3_FS is not set
1140# CONFIG_EXT4DEV_FS is not set
1141# CONFIG_REISERFS_FS is not set
1142# CONFIG_JFS_FS is not set
1143# CONFIG_FS_POSIX_ACL is not set
1144# CONFIG_XFS_FS is not set
1145# CONFIG_GFS2_FS is not set
1146# CONFIG_OCFS2_FS is not set
1147# CONFIG_MINIX_FS is not set
1148# CONFIG_ROMFS_FS is not set
1149CONFIG_INOTIFY=y
1150CONFIG_INOTIFY_USER=y
1151# CONFIG_QUOTA is not set
1152CONFIG_DNOTIFY=y
1153# CONFIG_AUTOFS_FS is not set
1154# CONFIG_AUTOFS4_FS is not set
1155# CONFIG_FUSE_FS is not set
1156
1157#
1158# CD-ROM/DVD Filesystems
1159#
1160CONFIG_ISO9660_FS=m
1161CONFIG_JOLIET=y
1162CONFIG_ZISOFS=y
1163# CONFIG_UDF_FS is not set
1164
1165#
1166# DOS/FAT/NT Filesystems
1167#
1168CONFIG_FAT_FS=m
1169CONFIG_MSDOS_FS=m
1170CONFIG_VFAT_FS=m
1171CONFIG_FAT_DEFAULT_CODEPAGE=437
1172CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
1173CONFIG_NTFS_FS=m
1174# CONFIG_NTFS_DEBUG is not set
1175CONFIG_NTFS_RW=y
1176
1177#
1178# Pseudo filesystems
1179#
1180CONFIG_PROC_FS=y
1181CONFIG_PROC_SYSCTL=y
1182CONFIG_SYSFS=y
1183# CONFIG_TMPFS is not set
1184# CONFIG_HUGETLB_PAGE is not set
1185# CONFIG_CONFIGFS_FS is not set
1186
1187#
1188# Miscellaneous filesystems
1189#
1190# CONFIG_ADFS_FS is not set
1191# CONFIG_AFFS_FS is not set
1192# CONFIG_HFS_FS is not set
1193# CONFIG_HFSPLUS_FS is not set
1194# CONFIG_BEFS_FS is not set
1195# CONFIG_BFS_FS is not set
1196# CONFIG_EFS_FS is not set
1197CONFIG_YAFFS_FS=m
1198CONFIG_YAFFS_YAFFS1=y
1199# CONFIG_YAFFS_DOES_ECC is not set
1200CONFIG_YAFFS_YAFFS2=y
1201CONFIG_YAFFS_AUTO_YAFFS2=y
1202# CONFIG_YAFFS_DISABLE_LAZY_LOAD is not set
1203CONFIG_YAFFS_CHECKPOINT_RESERVED_BLOCKS=10
1204# CONFIG_YAFFS_DISABLE_WIDE_TNODES is not set
1205# CONFIG_YAFFS_ALWAYS_CHECK_CHUNK_ERASED is not set
1206CONFIG_YAFFS_SHORT_NAMES_IN_RAM=y
1207CONFIG_JFFS2_FS=m
1208CONFIG_JFFS2_FS_DEBUG=0
1209CONFIG_JFFS2_FS_WRITEBUFFER=y
1210# CONFIG_JFFS2_FS_WBUF_VERIFY is not set
1211# CONFIG_JFFS2_SUMMARY is not set
1212# CONFIG_JFFS2_FS_XATTR is not set
1213# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
1214CONFIG_JFFS2_ZLIB=y
1215# CONFIG_JFFS2_LZO is not set
1216CONFIG_JFFS2_RTIME=y
1217# CONFIG_JFFS2_RUBIN is not set
1218# CONFIG_CRAMFS is not set
1219# CONFIG_VXFS_FS is not set
1220# CONFIG_HPFS_FS is not set
1221# CONFIG_QNX4FS_FS is not set
1222# CONFIG_SYSV_FS is not set
1223# CONFIG_UFS_FS is not set
1224CONFIG_NETWORK_FILESYSTEMS=y
1225CONFIG_NFS_FS=m
1226CONFIG_NFS_V3=y
1227# CONFIG_NFS_V3_ACL is not set
1228# CONFIG_NFS_V4 is not set
1229# CONFIG_NFS_DIRECTIO is not set
1230CONFIG_NFSD=m
1231CONFIG_NFSD_V3=y
1232# CONFIG_NFSD_V3_ACL is not set
1233# CONFIG_NFSD_V4 is not set
1234CONFIG_NFSD_TCP=y
1235CONFIG_LOCKD=m
1236CONFIG_LOCKD_V4=y
1237CONFIG_EXPORTFS=m
1238CONFIG_NFS_COMMON=y
1239CONFIG_SUNRPC=m
1240# CONFIG_SUNRPC_BIND34 is not set
1241# CONFIG_RPCSEC_GSS_KRB5 is not set
1242# CONFIG_RPCSEC_GSS_SPKM3 is not set
1243CONFIG_SMB_FS=m
1244CONFIG_SMB_NLS_DEFAULT=y
1245CONFIG_SMB_NLS_REMOTE="cp437"
1246CONFIG_CIFS=y
1247# CONFIG_CIFS_STATS is not set
1248# CONFIG_CIFS_WEAK_PW_HASH is not set
1249# CONFIG_CIFS_XATTR is not set
1250# CONFIG_CIFS_DEBUG2 is not set
1251# CONFIG_CIFS_EXPERIMENTAL is not set
1252# CONFIG_NCP_FS is not set
1253# CONFIG_CODA_FS is not set
1254# CONFIG_AFS_FS is not set
1255
1256#
1257# Partition Types
1258#
1259CONFIG_PARTITION_ADVANCED=y
1260# CONFIG_ACORN_PARTITION is not set
1261# CONFIG_OSF_PARTITION is not set
1262# CONFIG_AMIGA_PARTITION is not set
1263# CONFIG_ATARI_PARTITION is not set
1264# CONFIG_MAC_PARTITION is not set
1265CONFIG_MSDOS_PARTITION=y
1266# CONFIG_BSD_DISKLABEL is not set
1267# CONFIG_MINIX_SUBPARTITION is not set
1268# CONFIG_SOLARIS_X86_PARTITION is not set
1269# CONFIG_UNIXWARE_DISKLABEL is not set
1270# CONFIG_LDM_PARTITION is not set
1271# CONFIG_SGI_PARTITION is not set
1272# CONFIG_ULTRIX_PARTITION is not set
1273# CONFIG_SUN_PARTITION is not set
1274# CONFIG_KARMA_PARTITION is not set
1275# CONFIG_EFI_PARTITION is not set
1276# CONFIG_SYSV68_PARTITION is not set
1277CONFIG_NLS=y
1278CONFIG_NLS_DEFAULT="iso8859-1"
1279CONFIG_NLS_CODEPAGE_437=m
1280CONFIG_NLS_CODEPAGE_737=m
1281CONFIG_NLS_CODEPAGE_775=m
1282CONFIG_NLS_CODEPAGE_850=m
1283CONFIG_NLS_CODEPAGE_852=m
1284CONFIG_NLS_CODEPAGE_855=m
1285CONFIG_NLS_CODEPAGE_857=m
1286CONFIG_NLS_CODEPAGE_860=m
1287CONFIG_NLS_CODEPAGE_861=m
1288CONFIG_NLS_CODEPAGE_862=m
1289CONFIG_NLS_CODEPAGE_863=m
1290CONFIG_NLS_CODEPAGE_864=m
1291CONFIG_NLS_CODEPAGE_865=m
1292CONFIG_NLS_CODEPAGE_866=m
1293CONFIG_NLS_CODEPAGE_869=m
1294CONFIG_NLS_CODEPAGE_936=m
1295CONFIG_NLS_CODEPAGE_950=m
1296CONFIG_NLS_CODEPAGE_932=m
1297CONFIG_NLS_CODEPAGE_949=m
1298CONFIG_NLS_CODEPAGE_874=m
1299CONFIG_NLS_ISO8859_8=m
1300CONFIG_NLS_CODEPAGE_1250=m
1301CONFIG_NLS_CODEPAGE_1251=m
1302CONFIG_NLS_ASCII=m
1303CONFIG_NLS_ISO8859_1=m
1304CONFIG_NLS_ISO8859_2=m
1305CONFIG_NLS_ISO8859_3=m
1306CONFIG_NLS_ISO8859_4=m
1307CONFIG_NLS_ISO8859_5=m
1308CONFIG_NLS_ISO8859_6=m
1309CONFIG_NLS_ISO8859_7=m
1310CONFIG_NLS_ISO8859_9=m
1311CONFIG_NLS_ISO8859_13=m
1312CONFIG_NLS_ISO8859_14=m
1313CONFIG_NLS_ISO8859_15=m
1314CONFIG_NLS_KOI8_R=m
1315CONFIG_NLS_KOI8_U=m
1316CONFIG_NLS_UTF8=m
1317# CONFIG_DLM is not set
1318CONFIG_INSTRUMENTATION=y
1319# CONFIG_PROFILING is not set
1320# CONFIG_MARKERS is not set
1321
1322#
1323# Kernel hacking
1324#
1325# CONFIG_PRINTK_TIME is not set
1326CONFIG_ENABLE_WARN_DEPRECATED=y
1327CONFIG_ENABLE_MUST_CHECK=y
1328# CONFIG_MAGIC_SYSRQ is not set
1329# CONFIG_UNUSED_SYMBOLS is not set
1330CONFIG_DEBUG_FS=y
1331# CONFIG_HEADERS_CHECK is not set
1332# CONFIG_DEBUG_KERNEL is not set
1333# CONFIG_DEBUG_BUGVERBOSE is not set
1334# CONFIG_SAMPLES is not set
1335# CONFIG_DEBUG_MMRS is not set
1336CONFIG_DEBUG_HUNT_FOR_ZERO=y
1337CONFIG_DEBUG_BFIN_HWTRACE_ON=y
1338CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_OFF=y
1339# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE is not set
1340# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_TWO is not set
1341CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION=0
1342# CONFIG_DEBUG_BFIN_HWTRACE_EXPAND is not set
1343# CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE is not set
1344# CONFIG_EARLY_PRINTK is not set
1345CONFIG_CPLB_INFO=y
1346CONFIG_ACCESS_CHECK=y
1347
1348#
1349# Security options
1350#
1351# CONFIG_KEYS is not set
1352CONFIG_SECURITY=y
1353# CONFIG_SECURITY_NETWORK is not set
1354# CONFIG_SECURITY_CAPABILITIES is not set
1355# CONFIG_SECURITY_ROOTPLUG is not set
1356# CONFIG_CRYPTO is not set
1357
1358#
1359# Library routines
1360#
1361CONFIG_BITREVERSE=y
1362CONFIG_CRC_CCITT=m
1363# CONFIG_CRC16 is not set
1364# CONFIG_CRC_ITU_T is not set
1365CONFIG_CRC32=y
1366# CONFIG_CRC7 is not set
1367# CONFIG_LIBCRC32C is not set
1368CONFIG_ZLIB_INFLATE=y
1369CONFIG_ZLIB_DEFLATE=m
1370CONFIG_PLIST=y
1371CONFIG_HAS_IOMEM=y
1372CONFIG_HAS_IOPORT=y
1373CONFIG_HAS_DMA=y
diff --git a/arch/blackfin/configs/CM-BF561_defconfig b/arch/blackfin/configs/CM-BF561_defconfig
new file mode 100644
index 000000000000..daf00906c1ef
--- /dev/null
+++ b/arch/blackfin/configs/CM-BF561_defconfig
@@ -0,0 +1,876 @@
1#
2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.24.4
4# Tue Apr 1 10:50:11 2008
5#
6# CONFIG_MMU is not set
7# CONFIG_FPU is not set
8CONFIG_RWSEM_GENERIC_SPINLOCK=y
9# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
10CONFIG_BLACKFIN=y
11CONFIG_ZONE_DMA=y
12CONFIG_SEMAPHORE_SLEEPERS=y
13CONFIG_GENERIC_FIND_NEXT_BIT=y
14CONFIG_GENERIC_HWEIGHT=y
15CONFIG_GENERIC_HARDIRQS=y
16CONFIG_GENERIC_IRQ_PROBE=y
17CONFIG_GENERIC_GPIO=y
18CONFIG_FORCE_MAX_ZONEORDER=14
19CONFIG_GENERIC_CALIBRATE_DELAY=y
20CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
21
22#
23# General setup
24#
25CONFIG_EXPERIMENTAL=y
26CONFIG_BROKEN_ON_SMP=y
27CONFIG_INIT_ENV_ARG_LIMIT=32
28CONFIG_LOCALVERSION=""
29CONFIG_LOCALVERSION_AUTO=y
30CONFIG_SYSVIPC=y
31CONFIG_SYSVIPC_SYSCTL=y
32# CONFIG_POSIX_MQUEUE is not set
33# CONFIG_BSD_PROCESS_ACCT is not set
34# CONFIG_TASKSTATS is not set
35# CONFIG_USER_NS is not set
36# CONFIG_PID_NS is not set
37# CONFIG_AUDIT is not set
38# CONFIG_IKCONFIG is not set
39CONFIG_LOG_BUF_SHIFT=14
40# CONFIG_CGROUPS is not set
41CONFIG_FAIR_GROUP_SCHED=y
42CONFIG_FAIR_USER_SCHED=y
43# CONFIG_FAIR_CGROUP_SCHED is not set
44CONFIG_SYSFS_DEPRECATED=y
45# CONFIG_RELAY is not set
46# CONFIG_BLK_DEV_INITRD is not set
47# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
48CONFIG_SYSCTL=y
49CONFIG_EMBEDDED=y
50# CONFIG_UID16 is not set
51CONFIG_SYSCTL_SYSCALL=y
52CONFIG_KALLSYMS=y
53# CONFIG_KALLSYMS_EXTRA_PASS is not set
54# CONFIG_HOTPLUG is not set
55CONFIG_PRINTK=y
56CONFIG_BUG=y
57CONFIG_ELF_CORE=y
58CONFIG_BASE_FULL=y
59CONFIG_FUTEX=y
60CONFIG_ANON_INODES=y
61CONFIG_EPOLL=y
62CONFIG_SIGNALFD=y
63CONFIG_EVENTFD=y
64CONFIG_VM_EVENT_COUNTERS=y
65CONFIG_BIG_ORDER_ALLOC_NOFAIL_MAGIC=3
66# CONFIG_NP2 is not set
67CONFIG_SLAB=y
68# CONFIG_SLUB is not set
69# CONFIG_SLOB is not set
70CONFIG_SLABINFO=y
71CONFIG_RT_MUTEXES=y
72CONFIG_TINY_SHMEM=y
73CONFIG_BASE_SMALL=0
74CONFIG_MODULES=y
75CONFIG_MODULE_UNLOAD=y
76# CONFIG_MODULE_FORCE_UNLOAD is not set
77# CONFIG_MODVERSIONS is not set
78# CONFIG_MODULE_SRCVERSION_ALL is not set
79CONFIG_KMOD=y
80CONFIG_BLOCK=y
81# CONFIG_LBD is not set
82# CONFIG_BLK_DEV_IO_TRACE is not set
83# CONFIG_LSF is not set
84# CONFIG_BLK_DEV_BSG is not set
85
86#
87# IO Schedulers
88#
89CONFIG_IOSCHED_NOOP=y
90# CONFIG_IOSCHED_AS is not set
91# CONFIG_IOSCHED_DEADLINE is not set
92CONFIG_IOSCHED_CFQ=y
93# CONFIG_DEFAULT_AS is not set
94# CONFIG_DEFAULT_DEADLINE is not set
95# CONFIG_DEFAULT_CFQ is not set
96CONFIG_DEFAULT_NOOP=y
97CONFIG_DEFAULT_IOSCHED="noop"
98CONFIG_PREEMPT_NONE=y
99# CONFIG_PREEMPT_VOLUNTARY is not set
100# CONFIG_PREEMPT is not set
101
102#
103# Blackfin Processor Options
104#
105
106#
107# Processor and Board Settings
108#
109# CONFIG_BF522 is not set
110# CONFIG_BF523 is not set
111# CONFIG_BF524 is not set
112# CONFIG_BF525 is not set
113# CONFIG_BF526 is not set
114# CONFIG_BF527 is not set
115# CONFIG_BF531 is not set
116# CONFIG_BF532 is not set
117# CONFIG_BF533 is not set
118# CONFIG_BF534 is not set
119# CONFIG_BF536 is not set
120# CONFIG_BF537 is not set
121# CONFIG_BF542 is not set
122# CONFIG_BF544 is not set
123# CONFIG_BF547 is not set
124# CONFIG_BF548 is not set
125# CONFIG_BF549 is not set
126CONFIG_BF561=y
127# CONFIG_BF_REV_0_0 is not set
128# CONFIG_BF_REV_0_1 is not set
129# CONFIG_BF_REV_0_2 is not set
130CONFIG_BF_REV_0_3=y
131# CONFIG_BF_REV_0_4 is not set
132# CONFIG_BF_REV_0_5 is not set
133# CONFIG_BF_REV_ANY is not set
134# CONFIG_BF_REV_NONE is not set
135CONFIG_BFIN_DUAL_CORE=y
136CONFIG_MEM_MT48LC8M32B2B5_7=y
137CONFIG_IRQ_PLL_WAKEUP=7
138CONFIG_IRQ_SPORT0_ERROR=7
139CONFIG_IRQ_SPORT1_ERROR=7
140CONFIG_IRQ_SPI_ERROR=7
141# CONFIG_BFIN561_EZKIT is not set
142# CONFIG_BFIN561_TEPLA is not set
143CONFIG_BFIN561_BLUETECHNIX_CM=y
144# CONFIG_GENERIC_BF561_BOARD is not set
145
146#
147# BF561 Specific Configuration
148#
149
150#
151# Core B Support
152#
153
154#
155# Core B Support
156#
157CONFIG_BF561_COREB=y
158# CONFIG_BF561_COREB_RESET is not set
159
160#
161# Interrupt Priority Assignment
162#
163
164#
165# Priority
166#
167CONFIG_IRQ_DMA1_ERROR=7
168CONFIG_IRQ_DMA2_ERROR=7
169CONFIG_IRQ_IMDMA_ERROR=7
170CONFIG_IRQ_PPI0_ERROR=7
171CONFIG_IRQ_PPI1_ERROR=7
172CONFIG_IRQ_UART_ERROR=7
173CONFIG_IRQ_RESERVED_ERROR=7
174CONFIG_IRQ_DMA1_0=8
175CONFIG_IRQ_DMA1_1=8
176CONFIG_IRQ_DMA1_2=8
177CONFIG_IRQ_DMA1_3=8
178CONFIG_IRQ_DMA1_4=8
179CONFIG_IRQ_DMA1_5=8
180CONFIG_IRQ_DMA1_6=8
181CONFIG_IRQ_DMA1_7=8
182CONFIG_IRQ_DMA1_8=8
183CONFIG_IRQ_DMA1_9=8
184CONFIG_IRQ_DMA1_10=8
185CONFIG_IRQ_DMA1_11=8
186CONFIG_IRQ_DMA2_0=9
187CONFIG_IRQ_DMA2_1=9
188CONFIG_IRQ_DMA2_2=9
189CONFIG_IRQ_DMA2_3=9
190CONFIG_IRQ_DMA2_4=9
191CONFIG_IRQ_DMA2_5=9
192CONFIG_IRQ_DMA2_6=9
193CONFIG_IRQ_DMA2_7=9
194CONFIG_IRQ_DMA2_8=9
195CONFIG_IRQ_DMA2_9=9
196CONFIG_IRQ_DMA2_10=9
197CONFIG_IRQ_DMA2_11=9
198CONFIG_IRQ_TIMER0=10
199CONFIG_IRQ_TIMER1=10
200CONFIG_IRQ_TIMER2=10
201CONFIG_IRQ_TIMER3=10
202CONFIG_IRQ_TIMER4=10
203CONFIG_IRQ_TIMER5=10
204CONFIG_IRQ_TIMER6=10
205CONFIG_IRQ_TIMER7=10
206CONFIG_IRQ_TIMER8=10
207CONFIG_IRQ_TIMER9=10
208CONFIG_IRQ_TIMER10=10
209CONFIG_IRQ_TIMER11=10
210CONFIG_IRQ_PROG0_INTA=11
211CONFIG_IRQ_PROG0_INTB=11
212CONFIG_IRQ_PROG1_INTA=11
213CONFIG_IRQ_PROG1_INTB=11
214CONFIG_IRQ_PROG2_INTA=11
215CONFIG_IRQ_PROG2_INTB=11
216CONFIG_IRQ_DMA1_WRRD0=8
217CONFIG_IRQ_DMA1_WRRD1=8
218CONFIG_IRQ_DMA2_WRRD0=9
219CONFIG_IRQ_DMA2_WRRD1=9
220CONFIG_IRQ_IMDMA_WRRD0=12
221CONFIG_IRQ_IMDMA_WRRD1=12
222CONFIG_IRQ_WDTIMER=13
223
224#
225# Board customizations
226#
227# CONFIG_CMDLINE_BOOL is not set
228
229#
230# Clock/PLL Setup
231#
232CONFIG_CLKIN_HZ=25000000
233# CONFIG_BFIN_KERNEL_CLOCK is not set
234CONFIG_MAX_VCO_HZ=600000000
235CONFIG_MIN_VCO_HZ=50000000
236CONFIG_MAX_SCLK_HZ=133333333
237CONFIG_MIN_SCLK_HZ=27000000
238
239#
240# Kernel Timer/Scheduler
241#
242# CONFIG_HZ_100 is not set
243CONFIG_HZ_250=y
244# CONFIG_HZ_300 is not set
245# CONFIG_HZ_1000 is not set
246CONFIG_HZ=250
247CONFIG_GENERIC_TIME=y
248CONFIG_GENERIC_CLOCKEVENTS=y
249# CONFIG_CYCLES_CLOCKSOURCE is not set
250# CONFIG_TICK_ONESHOT is not set
251# CONFIG_NO_HZ is not set
252# CONFIG_HIGH_RES_TIMERS is not set
253CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
254
255#
256# Memory Setup
257#
258CONFIG_MAX_MEM_SIZE=32
259CONFIG_BOOT_LOAD=0x1000
260CONFIG_BFIN_SCRATCH_REG_RETN=y
261# CONFIG_BFIN_SCRATCH_REG_RETE is not set
262# CONFIG_BFIN_SCRATCH_REG_CYCLES is not set
263
264#
265# Blackfin Kernel Optimizations
266#
267
268#
269# Memory Optimizations
270#
271CONFIG_I_ENTRY_L1=y
272CONFIG_EXCPT_IRQ_SYSC_L1=y
273CONFIG_DO_IRQ_L1=y
274CONFIG_CORE_TIMER_IRQ_L1=y
275CONFIG_IDLE_L1=y
276CONFIG_SCHEDULE_L1=y
277CONFIG_ARITHMETIC_OPS_L1=y
278CONFIG_ACCESS_OK_L1=y
279CONFIG_MEMSET_L1=y
280CONFIG_MEMCPY_L1=y
281CONFIG_SYS_BFIN_SPINLOCK_L1=y
282CONFIG_IP_CHECKSUM_L1=y
283CONFIG_CACHELINE_ALIGNED_L1=y
284CONFIG_SYSCALL_TAB_L1=y
285CONFIG_CPLB_SWITCH_TAB_L1=y
286CONFIG_RAMKERNEL=y
287# CONFIG_ROMKERNEL is not set
288CONFIG_SELECT_MEMORY_MODEL=y
289CONFIG_FLATMEM_MANUAL=y
290# CONFIG_DISCONTIGMEM_MANUAL is not set
291# CONFIG_SPARSEMEM_MANUAL is not set
292CONFIG_FLATMEM=y
293CONFIG_FLAT_NODE_MEM_MAP=y
294# CONFIG_SPARSEMEM_STATIC is not set
295# CONFIG_SPARSEMEM_VMEMMAP_ENABLE is not set
296CONFIG_SPLIT_PTLOCK_CPUS=4
297# CONFIG_RESOURCES_64BIT is not set
298CONFIG_ZONE_DMA_FLAG=1
299CONFIG_VIRT_TO_BUS=y
300CONFIG_LARGE_ALLOCS=y
301# CONFIG_BFIN_GPTIMERS is not set
302CONFIG_BFIN_DMA_5XX=y
303# CONFIG_DMA_UNCACHED_2M is not set
304CONFIG_DMA_UNCACHED_1M=y
305# CONFIG_DMA_UNCACHED_NONE is not set
306
307#
308# Cache Support
309#
310CONFIG_BFIN_ICACHE=y
311CONFIG_BFIN_DCACHE=y
312# CONFIG_BFIN_DCACHE_BANKA is not set
313# CONFIG_BFIN_ICACHE_LOCK is not set
314CONFIG_BFIN_WB=y
315# CONFIG_BFIN_WT is not set
316CONFIG_L1_MAX_PIECE=16
317# CONFIG_MPU is not set
318
319#
320# Asynchonous Memory Configuration
321#
322
323#
324# EBIU_AMGCTL Global Control
325#
326CONFIG_C_AMCKEN=y
327CONFIG_C_CDPRIO=y
328CONFIG_C_B0PEN=y
329CONFIG_C_B1PEN=y
330CONFIG_C_B2PEN=y
331# CONFIG_C_B3PEN is not set
332# CONFIG_C_AMBEN is not set
333# CONFIG_C_AMBEN_B0 is not set
334# CONFIG_C_AMBEN_B0_B1 is not set
335# CONFIG_C_AMBEN_B0_B1_B2 is not set
336CONFIG_C_AMBEN_ALL=y
337
338#
339# EBIU_AMBCTL Control
340#
341CONFIG_BANK_0=0x7BB0
342CONFIG_BANK_1=0x7BB0
343CONFIG_BANK_2=0x7BB0
344CONFIG_BANK_3=0xFFC3
345
346#
347# Bus options (PCI, PCMCIA, EISA, MCA, ISA)
348#
349# CONFIG_PCI is not set
350# CONFIG_ARCH_SUPPORTS_MSI is not set
351
352#
353# Executable file formats
354#
355CONFIG_BINFMT_ELF_FDPIC=y
356CONFIG_BINFMT_FLAT=y
357CONFIG_BINFMT_ZFLAT=y
358CONFIG_BINFMT_SHARED_FLAT=y
359# CONFIG_BINFMT_MISC is not set
360
361#
362# Power management options
363#
364# CONFIG_PM is not set
365CONFIG_SUSPEND_UP_POSSIBLE=y
366# CONFIG_PM_WAKEUP_BY_GPIO is not set
367
368#
369# Networking
370#
371CONFIG_NET=y
372
373#
374# Networking options
375#
376CONFIG_PACKET=y
377# CONFIG_PACKET_MMAP is not set
378CONFIG_UNIX=y
379CONFIG_XFRM=y
380# CONFIG_XFRM_USER is not set
381# CONFIG_XFRM_SUB_POLICY is not set
382# CONFIG_XFRM_MIGRATE is not set
383# CONFIG_NET_KEY is not set
384CONFIG_INET=y
385# CONFIG_IP_MULTICAST is not set
386# CONFIG_IP_ADVANCED_ROUTER is not set
387CONFIG_IP_FIB_HASH=y
388# CONFIG_IP_PNP is not set
389# CONFIG_NET_IPIP is not set
390# CONFIG_NET_IPGRE is not set
391# CONFIG_ARPD is not set
392CONFIG_SYN_COOKIES=y
393# CONFIG_INET_AH is not set
394# CONFIG_INET_ESP is not set
395# CONFIG_INET_IPCOMP is not set
396# CONFIG_INET_XFRM_TUNNEL is not set
397# CONFIG_INET_TUNNEL is not set
398CONFIG_INET_XFRM_MODE_TRANSPORT=y
399CONFIG_INET_XFRM_MODE_TUNNEL=y
400CONFIG_INET_XFRM_MODE_BEET=y
401# CONFIG_INET_LRO is not set
402CONFIG_INET_DIAG=y
403CONFIG_INET_TCP_DIAG=y
404# CONFIG_TCP_CONG_ADVANCED is not set
405CONFIG_TCP_CONG_CUBIC=y
406CONFIG_DEFAULT_TCP_CONG="cubic"
407# CONFIG_TCP_MD5SIG is not set
408# CONFIG_IPV6 is not set
409# CONFIG_INET6_XFRM_TUNNEL is not set
410# CONFIG_INET6_TUNNEL is not set
411# CONFIG_NETLABEL is not set
412# CONFIG_NETWORK_SECMARK is not set
413# CONFIG_NETFILTER is not set
414# CONFIG_IP_DCCP is not set
415# CONFIG_IP_SCTP is not set
416# CONFIG_TIPC is not set
417# CONFIG_ATM is not set
418# CONFIG_BRIDGE is not set
419# CONFIG_VLAN_8021Q is not set
420# CONFIG_DECNET is not set
421# CONFIG_LLC2 is not set
422# CONFIG_IPX is not set
423# CONFIG_ATALK is not set
424# CONFIG_X25 is not set
425# CONFIG_LAPB is not set
426# CONFIG_ECONET is not set
427# CONFIG_WAN_ROUTER is not set
428# CONFIG_NET_SCHED is not set
429
430#
431# Network testing
432#
433# CONFIG_NET_PKTGEN is not set
434# CONFIG_HAMRADIO is not set
435# CONFIG_IRDA is not set
436# CONFIG_BT is not set
437# CONFIG_AF_RXRPC is not set
438
439#
440# Wireless
441#
442# CONFIG_CFG80211 is not set
443# CONFIG_WIRELESS_EXT is not set
444# CONFIG_MAC80211 is not set
445# CONFIG_IEEE80211 is not set
446# CONFIG_RFKILL is not set
447# CONFIG_NET_9P is not set
448
449#
450# Device Drivers
451#
452
453#
454# Generic Driver Options
455#
456CONFIG_STANDALONE=y
457CONFIG_PREVENT_FIRMWARE_BUILD=y
458# CONFIG_SYS_HYPERVISOR is not set
459# CONFIG_CONNECTOR is not set
460CONFIG_MTD=y
461# CONFIG_MTD_DEBUG is not set
462# CONFIG_MTD_CONCAT is not set
463CONFIG_MTD_PARTITIONS=y
464# CONFIG_MTD_REDBOOT_PARTS is not set
465# CONFIG_MTD_CMDLINE_PARTS is not set
466
467#
468# User Modules And Translation Layers
469#
470CONFIG_MTD_CHAR=y
471CONFIG_MTD_BLKDEVS=y
472CONFIG_MTD_BLOCK=y
473# CONFIG_FTL is not set
474# CONFIG_NFTL is not set
475# CONFIG_INFTL is not set
476# CONFIG_RFD_FTL is not set
477# CONFIG_SSFDC is not set
478# CONFIG_MTD_OOPS is not set
479
480#
481# RAM/ROM/Flash chip drivers
482#
483# CONFIG_MTD_CFI is not set
484# CONFIG_MTD_JEDECPROBE is not set
485CONFIG_MTD_MAP_BANK_WIDTH_1=y
486CONFIG_MTD_MAP_BANK_WIDTH_2=y
487CONFIG_MTD_MAP_BANK_WIDTH_4=y
488# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
489# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
490# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
491CONFIG_MTD_CFI_I1=y
492CONFIG_MTD_CFI_I2=y
493# CONFIG_MTD_CFI_I4 is not set
494# CONFIG_MTD_CFI_I8 is not set
495CONFIG_MTD_RAM=y
496# CONFIG_MTD_ROM is not set
497# CONFIG_MTD_ABSENT is not set
498
499#
500# Mapping drivers for chip access
501#
502# CONFIG_MTD_COMPLEX_MAPPINGS is not set
503CONFIG_MTD_UCLINUX=y
504# CONFIG_MTD_PLATRAM is not set
505
506#
507# Self-contained MTD device drivers
508#
509# CONFIG_MTD_SLRAM is not set
510# CONFIG_MTD_PHRAM is not set
511# CONFIG_MTD_MTDRAM is not set
512# CONFIG_MTD_BLOCK2MTD is not set
513
514#
515# Disk-On-Chip Device Drivers
516#
517# CONFIG_MTD_DOC2000 is not set
518# CONFIG_MTD_DOC2001 is not set
519# CONFIG_MTD_DOC2001PLUS is not set
520# CONFIG_MTD_NAND is not set
521# CONFIG_MTD_ONENAND is not set
522
523#
524# UBI - Unsorted block images
525#
526# CONFIG_MTD_UBI is not set
527# CONFIG_PARPORT is not set
528CONFIG_BLK_DEV=y
529# CONFIG_BLK_DEV_COW_COMMON is not set
530# CONFIG_BLK_DEV_LOOP is not set
531# CONFIG_BLK_DEV_NBD is not set
532CONFIG_BLK_DEV_RAM=y
533CONFIG_BLK_DEV_RAM_COUNT=16
534CONFIG_BLK_DEV_RAM_SIZE=4096
535CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
536# CONFIG_CDROM_PKTCDVD is not set
537# CONFIG_ATA_OVER_ETH is not set
538CONFIG_MISC_DEVICES=y
539# CONFIG_EEPROM_93CX6 is not set
540# CONFIG_IDE is not set
541# CONFIG_BFIN_IDE_ADDRESS_MAPPING_MODE0 is not set
542# CONFIG_BFIN_IDE_ADDRESS_MAPPING_MODE1 is not set
543
544#
545# SCSI device support
546#
547# CONFIG_RAID_ATTRS is not set
548# CONFIG_SCSI is not set
549# CONFIG_SCSI_DMA is not set
550# CONFIG_SCSI_NETLINK is not set
551# CONFIG_ATA is not set
552# CONFIG_MD is not set
553CONFIG_NETDEVICES=y
554# CONFIG_NETDEVICES_MULTIQUEUE is not set
555# CONFIG_DUMMY is not set
556# CONFIG_BONDING is not set
557# CONFIG_MACVLAN is not set
558# CONFIG_EQUALIZER is not set
559# CONFIG_TUN is not set
560# CONFIG_VETH is not set
561# CONFIG_PHYLIB is not set
562CONFIG_NET_ETHERNET=y
563CONFIG_MII=y
564CONFIG_SMC91X=y
565# CONFIG_SMSC911X is not set
566# CONFIG_DM9000 is not set
567# CONFIG_IBM_NEW_EMAC_ZMII is not set
568# CONFIG_IBM_NEW_EMAC_RGMII is not set
569# CONFIG_IBM_NEW_EMAC_TAH is not set
570# CONFIG_IBM_NEW_EMAC_EMAC4 is not set
571# CONFIG_B44 is not set
572CONFIG_NETDEV_1000=y
573# CONFIG_AX88180 is not set
574CONFIG_NETDEV_10000=y
575
576#
577# Wireless LAN
578#
579# CONFIG_WLAN_PRE80211 is not set
580# CONFIG_WLAN_80211 is not set
581# CONFIG_WAN is not set
582# CONFIG_PPP is not set
583# CONFIG_SLIP is not set
584# CONFIG_SHAPER is not set
585# CONFIG_NETCONSOLE is not set
586# CONFIG_NETPOLL is not set
587# CONFIG_NET_POLL_CONTROLLER is not set
588# CONFIG_ISDN is not set
589# CONFIG_PHONE is not set
590
591#
592# Input device support
593#
594# CONFIG_INPUT is not set
595
596#
597# Hardware I/O ports
598#
599# CONFIG_SERIO is not set
600# CONFIG_GAMEPORT is not set
601
602#
603# Character devices
604#
605# CONFIG_AD9960 is not set
606# CONFIG_SPI_ADC_BF533 is not set
607# CONFIG_BF5xx_PPIFCD is not set
608# CONFIG_BFIN_SIMPLE_TIMER is not set
609# CONFIG_BF5xx_PPI is not set
610# CONFIG_BFIN_SPORT is not set
611# CONFIG_BFIN_TIMER_LATENCY is not set
612# CONFIG_SIMPLE_GPIO is not set
613# CONFIG_VT is not set
614# CONFIG_SERIAL_NONSTANDARD is not set
615
616#
617# Serial drivers
618#
619# CONFIG_SERIAL_8250 is not set
620
621#
622# Non-8250 serial port support
623#
624CONFIG_SERIAL_BFIN=y
625CONFIG_SERIAL_BFIN_CONSOLE=y
626CONFIG_SERIAL_BFIN_DMA=y
627# CONFIG_SERIAL_BFIN_PIO is not set
628CONFIG_SERIAL_BFIN_UART0=y
629# CONFIG_BFIN_UART0_CTSRTS is not set
630CONFIG_SERIAL_CORE=y
631CONFIG_SERIAL_CORE_CONSOLE=y
632# CONFIG_SERIAL_BFIN_SPORT is not set
633CONFIG_UNIX98_PTYS=y
634CONFIG_LEGACY_PTYS=y
635CONFIG_LEGACY_PTY_COUNT=256
636
637#
638# CAN, the car bus and industrial fieldbus
639#
640# CONFIG_CAN4LINUX is not set
641# CONFIG_IPMI_HANDLER is not set
642# CONFIG_HW_RANDOM is not set
643# CONFIG_GEN_RTC is not set
644# CONFIG_R3964 is not set
645# CONFIG_RAW_DRIVER is not set
646# CONFIG_TCG_TPM is not set
647# CONFIG_I2C is not set
648
649#
650# SPI support
651#
652# CONFIG_SPI is not set
653# CONFIG_SPI_MASTER is not set
654# CONFIG_W1 is not set
655# CONFIG_POWER_SUPPLY is not set
656CONFIG_HWMON=y
657# CONFIG_HWMON_VID is not set
658# CONFIG_SENSORS_F71805F is not set
659# CONFIG_SENSORS_F71882FG is not set
660# CONFIG_SENSORS_IT87 is not set
661# CONFIG_SENSORS_PC87360 is not set
662# CONFIG_SENSORS_PC87427 is not set
663# CONFIG_SENSORS_SMSC47M1 is not set
664# CONFIG_SENSORS_SMSC47B397 is not set
665# CONFIG_SENSORS_VT1211 is not set
666# CONFIG_SENSORS_W83627HF is not set
667# CONFIG_SENSORS_W83627EHF is not set
668# CONFIG_HWMON_DEBUG_CHIP is not set
669# CONFIG_WATCHDOG is not set
670
671#
672# Sonics Silicon Backplane
673#
674CONFIG_SSB_POSSIBLE=y
675# CONFIG_SSB is not set
676
677#
678# Multifunction device drivers
679#
680# CONFIG_MFD_SM501 is not set
681
682#
683# Multimedia devices
684#
685# CONFIG_VIDEO_DEV is not set
686# CONFIG_DVB_CORE is not set
687CONFIG_DAB=y
688
689#
690# Graphics support
691#
692# CONFIG_VGASTATE is not set
693# CONFIG_VIDEO_OUTPUT_CONTROL is not set
694# CONFIG_FB is not set
695# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
696
697#
698# Display device support
699#
700# CONFIG_DISPLAY_SUPPORT is not set
701
702#
703# Sound
704#
705# CONFIG_SOUND is not set
706CONFIG_USB_SUPPORT=y
707CONFIG_USB_ARCH_HAS_HCD=y
708# CONFIG_USB_ARCH_HAS_OHCI is not set
709# CONFIG_USB_ARCH_HAS_EHCI is not set
710# CONFIG_USB is not set
711
712#
713# Enable Host or Gadget support to see Inventra options
714#
715
716#
717# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
718#
719
720#
721# USB Gadget Support
722#
723# CONFIG_USB_GADGET is not set
724# CONFIG_MMC is not set
725# CONFIG_NEW_LEDS is not set
726# CONFIG_RTC_CLASS is not set
727
728#
729# Userspace I/O
730#
731# CONFIG_UIO is not set
732
733#
734# PBX support
735#
736# CONFIG_PBX is not set
737
738#
739# File systems
740#
741CONFIG_EXT2_FS=y
742CONFIG_EXT2_FS_XATTR=y
743# CONFIG_EXT2_FS_POSIX_ACL is not set
744# CONFIG_EXT2_FS_SECURITY is not set
745# CONFIG_EXT3_FS is not set
746# CONFIG_EXT4DEV_FS is not set
747CONFIG_FS_MBCACHE=y
748# CONFIG_REISERFS_FS is not set
749# CONFIG_JFS_FS is not set
750# CONFIG_FS_POSIX_ACL is not set
751# CONFIG_XFS_FS is not set
752# CONFIG_GFS2_FS is not set
753# CONFIG_OCFS2_FS is not set
754# CONFIG_MINIX_FS is not set
755# CONFIG_ROMFS_FS is not set
756CONFIG_INOTIFY=y
757CONFIG_INOTIFY_USER=y
758# CONFIG_QUOTA is not set
759CONFIG_DNOTIFY=y
760# CONFIG_AUTOFS_FS is not set
761# CONFIG_AUTOFS4_FS is not set
762# CONFIG_FUSE_FS is not set
763
764#
765# CD-ROM/DVD Filesystems
766#
767# CONFIG_ISO9660_FS is not set
768# CONFIG_UDF_FS is not set
769
770#
771# DOS/FAT/NT Filesystems
772#
773# CONFIG_MSDOS_FS is not set
774# CONFIG_VFAT_FS is not set
775# CONFIG_NTFS_FS is not set
776
777#
778# Pseudo filesystems
779#
780CONFIG_PROC_FS=y
781CONFIG_PROC_SYSCTL=y
782CONFIG_SYSFS=y
783# CONFIG_TMPFS is not set
784# CONFIG_HUGETLB_PAGE is not set
785# CONFIG_CONFIGFS_FS is not set
786
787#
788# Miscellaneous filesystems
789#
790# CONFIG_ADFS_FS is not set
791# CONFIG_AFFS_FS is not set
792# CONFIG_HFS_FS is not set
793# CONFIG_HFSPLUS_FS is not set
794# CONFIG_BEFS_FS is not set
795# CONFIG_BFS_FS is not set
796# CONFIG_EFS_FS is not set
797# CONFIG_YAFFS_FS is not set
798# CONFIG_JFFS2_FS is not set
799# CONFIG_CRAMFS is not set
800# CONFIG_VXFS_FS is not set
801# CONFIG_HPFS_FS is not set
802# CONFIG_QNX4FS_FS is not set
803# CONFIG_SYSV_FS is not set
804# CONFIG_UFS_FS is not set
805CONFIG_NETWORK_FILESYSTEMS=y
806# CONFIG_NFS_FS is not set
807# CONFIG_NFSD is not set
808# CONFIG_SMB_FS is not set
809# CONFIG_CIFS is not set
810# CONFIG_NCP_FS is not set
811# CONFIG_CODA_FS is not set
812# CONFIG_AFS_FS is not set
813
814#
815# Partition Types
816#
817# CONFIG_PARTITION_ADVANCED is not set
818CONFIG_MSDOS_PARTITION=y
819# CONFIG_NLS is not set
820# CONFIG_DLM is not set
821CONFIG_INSTRUMENTATION=y
822# CONFIG_PROFILING is not set
823# CONFIG_MARKERS is not set
824
825#
826# Kernel hacking
827#
828# CONFIG_PRINTK_TIME is not set
829CONFIG_ENABLE_WARN_DEPRECATED=y
830CONFIG_ENABLE_MUST_CHECK=y
831# CONFIG_MAGIC_SYSRQ is not set
832# CONFIG_UNUSED_SYMBOLS is not set
833# CONFIG_DEBUG_FS is not set
834# CONFIG_HEADERS_CHECK is not set
835# CONFIG_DEBUG_KERNEL is not set
836# CONFIG_DEBUG_BUGVERBOSE is not set
837# CONFIG_SAMPLES is not set
838# CONFIG_DEBUG_MMRS is not set
839CONFIG_DEBUG_HUNT_FOR_ZERO=y
840CONFIG_DEBUG_BFIN_HWTRACE_ON=y
841CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_OFF=y
842# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE is not set
843# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_TWO is not set
844CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION=0
845# CONFIG_DEBUG_BFIN_HWTRACE_EXPAND is not set
846# CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE is not set
847# CONFIG_EARLY_PRINTK is not set
848# CONFIG_DUAL_CORE_TEST_MODULE is not set
849CONFIG_CPLB_INFO=y
850CONFIG_ACCESS_CHECK=y
851
852#
853# Security options
854#
855# CONFIG_KEYS is not set
856CONFIG_SECURITY=y
857# CONFIG_SECURITY_NETWORK is not set
858CONFIG_SECURITY_CAPABILITIES=y
859# CONFIG_SECURITY_FILE_CAPABILITIES is not set
860# CONFIG_CRYPTO is not set
861
862#
863# Library routines
864#
865CONFIG_BITREVERSE=y
866CONFIG_CRC_CCITT=m
867# CONFIG_CRC16 is not set
868# CONFIG_CRC_ITU_T is not set
869CONFIG_CRC32=y
870# CONFIG_CRC7 is not set
871# CONFIG_LIBCRC32C is not set
872CONFIG_ZLIB_INFLATE=y
873CONFIG_PLIST=y
874CONFIG_HAS_IOMEM=y
875CONFIG_HAS_IOPORT=y
876CONFIG_HAS_DMA=y
diff --git a/arch/blackfin/configs/H8606_defconfig b/arch/blackfin/configs/H8606_defconfig
index 18cbb8c3c373..679c7483ea71 100644
--- a/arch/blackfin/configs/H8606_defconfig
+++ b/arch/blackfin/configs/H8606_defconfig
@@ -13,7 +13,7 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
13CONFIG_GENERIC_HWEIGHT=y 13CONFIG_GENERIC_HWEIGHT=y
14CONFIG_GENERIC_HARDIRQS=y 14CONFIG_GENERIC_HARDIRQS=y
15CONFIG_GENERIC_IRQ_PROBE=y 15CONFIG_GENERIC_IRQ_PROBE=y
16# CONFIG_GENERIC_TIME is not set 16CONFIG_GENERIC_TIME=y
17CONFIG_GENERIC_GPIO=y 17CONFIG_GENERIC_GPIO=y
18CONFIG_FORCE_MAX_ZONEORDER=14 18CONFIG_FORCE_MAX_ZONEORDER=14
19CONFIG_GENERIC_CALIBRATE_DELAY=y 19CONFIG_GENERIC_CALIBRATE_DELAY=y
@@ -207,7 +207,7 @@ CONFIG_HZ=250
207# 207#
208# Memory Setup 208# Memory Setup
209# 209#
210CONFIG_MEM_SIZE=32 210CONFIG_MAX_MEM_SIZE=32
211CONFIG_MEM_ADD_WIDTH=9 211CONFIG_MEM_ADD_WIDTH=9
212CONFIG_BOOT_LOAD=0x1000 212CONFIG_BOOT_LOAD=0x1000
213CONFIG_BFIN_SCRATCH_REG_RETN=y 213CONFIG_BFIN_SCRATCH_REG_RETN=y
diff --git a/arch/blackfin/configs/IP0X_defconfig b/arch/blackfin/configs/IP0X_defconfig
new file mode 100644
index 000000000000..5f6ff04a86c3
--- /dev/null
+++ b/arch/blackfin/configs/IP0X_defconfig
@@ -0,0 +1,1252 @@
1#
2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.22.18
4#
5# CONFIG_MMU is not set
6# CONFIG_FPU is not set
7CONFIG_RWSEM_GENERIC_SPINLOCK=y
8# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
9CONFIG_BLACKFIN=y
10CONFIG_ZONE_DMA=y
11CONFIG_SEMAPHORE_SLEEPERS=y
12CONFIG_GENERIC_FIND_NEXT_BIT=y
13CONFIG_GENERIC_HWEIGHT=y
14CONFIG_GENERIC_HARDIRQS=y
15CONFIG_GENERIC_IRQ_PROBE=y
16# CONFIG_GENERIC_TIME is not set
17CONFIG_GENERIC_GPIO=y
18CONFIG_FORCE_MAX_ZONEORDER=14
19CONFIG_GENERIC_CALIBRATE_DELAY=y
20CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
21
22#
23# Code maturity level options
24#
25CONFIG_EXPERIMENTAL=y
26CONFIG_BROKEN_ON_SMP=y
27CONFIG_INIT_ENV_ARG_LIMIT=32
28
29#
30# General setup
31#
32CONFIG_LOCALVERSION=""
33CONFIG_LOCALVERSION_AUTO=y
34CONFIG_SYSVIPC=y
35# CONFIG_IPC_NS is not set
36CONFIG_SYSVIPC_SYSCTL=y
37# CONFIG_POSIX_MQUEUE is not set
38# CONFIG_BSD_PROCESS_ACCT is not set
39# CONFIG_TASKSTATS is not set
40# CONFIG_UTS_NS is not set
41# CONFIG_AUDIT is not set
42# CONFIG_IKCONFIG is not set
43CONFIG_LOG_BUF_SHIFT=14
44CONFIG_SYSFS_DEPRECATED=y
45# CONFIG_RELAY is not set
46CONFIG_BLK_DEV_INITRD=y
47CONFIG_INITRAMFS_SOURCE=""
48# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
49CONFIG_SYSCTL=y
50CONFIG_EMBEDDED=y
51CONFIG_UID16=y
52CONFIG_SYSCTL_SYSCALL=y
53CONFIG_KALLSYMS=y
54# CONFIG_KALLSYMS_EXTRA_PASS is not set
55# CONFIG_HOTPLUG is not set
56CONFIG_PRINTK=y
57CONFIG_BUG=y
58CONFIG_ELF_CORE=y
59CONFIG_BASE_FULL=y
60CONFIG_FUTEX=y
61CONFIG_ANON_INODES=y
62CONFIG_EPOLL=y
63CONFIG_SIGNALFD=y
64CONFIG_EVENTFD=y
65CONFIG_VM_EVENT_COUNTERS=y
66CONFIG_BIG_ORDER_ALLOC_NOFAIL_MAGIC=3
67# CONFIG_NP2 is not set
68CONFIG_SLAB=y
69# CONFIG_SLUB is not set
70# CONFIG_SLOB is not set
71CONFIG_RT_MUTEXES=y
72CONFIG_TINY_SHMEM=y
73CONFIG_BASE_SMALL=0
74
75#
76# Loadable module support
77#
78CONFIG_MODULES=y
79CONFIG_MODULE_UNLOAD=y
80# CONFIG_MODULE_FORCE_UNLOAD is not set
81# CONFIG_MODVERSIONS is not set
82# CONFIG_MODULE_SRCVERSION_ALL is not set
83CONFIG_KMOD=y
84
85#
86# Block layer
87#
88CONFIG_BLOCK=y
89# CONFIG_LBD is not set
90# CONFIG_BLK_DEV_IO_TRACE is not set
91# CONFIG_LSF is not set
92
93#
94# IO Schedulers
95#
96CONFIG_IOSCHED_NOOP=y
97CONFIG_IOSCHED_AS=y
98# CONFIG_IOSCHED_DEADLINE is not set
99CONFIG_IOSCHED_CFQ=y
100CONFIG_DEFAULT_AS=y
101# CONFIG_DEFAULT_DEADLINE is not set
102# CONFIG_DEFAULT_CFQ is not set
103# CONFIG_DEFAULT_NOOP is not set
104CONFIG_DEFAULT_IOSCHED="anticipatory"
105CONFIG_PREEMPT_NONE=y
106# CONFIG_PREEMPT_VOLUNTARY is not set
107# CONFIG_PREEMPT is not set
108
109#
110# Blackfin Processor Options
111#
112
113#
114# Processor and Board Settings
115#
116# CONFIG_BF522 is not set
117# CONFIG_BF523 is not set
118# CONFIG_BF524 is not set
119# CONFIG_BF525 is not set
120# CONFIG_BF526 is not set
121# CONFIG_BF527 is not set
122# CONFIG_BF531 is not set
123CONFIG_BF532=y
124# CONFIG_BF533 is not set
125# CONFIG_BF534 is not set
126# CONFIG_BF536 is not set
127# CONFIG_BF537 is not set
128# CONFIG_BF542 is not set
129# CONFIG_BF544 is not set
130# CONFIG_BF547 is not set
131# CONFIG_BF548 is not set
132# CONFIG_BF549 is not set
133# CONFIG_BF561 is not set
134# CONFIG_BF_REV_0_0 is not set
135# CONFIG_BF_REV_0_1 is not set
136# CONFIG_BF_REV_0_2 is not set
137# CONFIG_BF_REV_0_3 is not set
138# CONFIG_BF_REV_0_4 is not set
139CONFIG_BF_REV_0_5=y
140# CONFIG_BF_REV_ANY is not set
141# CONFIG_BF_REV_NONE is not set
142CONFIG_BF53x=y
143CONFIG_BFIN_SINGLE_CORE=y
144CONFIG_MEM_MT48LC32M16A2TG_75=y
145# CONFIG_BFIN533_EZKIT is not set
146# CONFIG_BFIN533_STAMP is not set
147# CONFIG_BFIN533_BLUETECHNIX_CM is not set
148# CONFIG_H8606_HVSISTEMAS is not set
149CONFIG_BFIN532_IP0X=y
150# CONFIG_GENERIC_BF533_BOARD is not set
151
152#
153# BF533/2/1 Specific Configuration
154#
155
156#
157# Interrupt Priority Assignment
158#
159
160#
161# Priority
162#
163CONFIG_UART_ERROR=7
164CONFIG_SPORT0_ERROR=7
165CONFIG_SPI_ERROR=7
166CONFIG_SPORT1_ERROR=7
167CONFIG_PPI_ERROR=7
168CONFIG_DMA_ERROR=7
169CONFIG_PLLWAKE_ERROR=7
170CONFIG_RTC_ERROR=8
171CONFIG_DMA0_PPI=8
172CONFIG_DMA1_SPORT0RX=9
173CONFIG_DMA2_SPORT0TX=9
174CONFIG_DMA3_SPORT1RX=9
175CONFIG_DMA4_SPORT1TX=9
176CONFIG_DMA5_SPI=10
177CONFIG_DMA6_UARTRX=10
178CONFIG_DMA7_UARTTX=10
179CONFIG_TIMER0=11
180CONFIG_TIMER1=11
181CONFIG_TIMER2=11
182CONFIG_PFA=12
183CONFIG_PFB=12
184CONFIG_MEMDMA0=13
185CONFIG_MEMDMA1=13
186CONFIG_WDTIMER=13
187
188#
189# Board customizations
190#
191# CONFIG_CMDLINE_BOOL is not set
192
193#
194# Clock/PLL Setup
195#
196CONFIG_CLKIN_HZ=10000000
197# CONFIG_BFIN_KERNEL_CLOCK is not set
198CONFIG_MAX_VCO_HZ=400000000
199CONFIG_MIN_VCO_HZ=50000000
200CONFIG_MAX_SCLK_HZ=133333333
201CONFIG_MIN_SCLK_HZ=27000000
202
203#
204# Kernel Timer/Scheduler
205#
206# CONFIG_HZ_100 is not set
207CONFIG_HZ_250=y
208# CONFIG_HZ_300 is not set
209# CONFIG_HZ_1000 is not set
210CONFIG_HZ=250
211
212#
213# Memory Setup
214#
215CONFIG_MEM_SIZE=64
216CONFIG_MEM_ADD_WIDTH=10
217
218#
219# Hardware addresses
220#
221CONFIG_IP0X_NET1=0x20100000
222CONFIG_IP0X_NET2=0x20200000
223CONFIG_IP0X_USB=0x20300000
224CONFIG_BOOT_LOAD=0x1000
225CONFIG_BFIN_SCRATCH_REG_RETN=y
226# CONFIG_BFIN_SCRATCH_REG_RETE is not set
227# CONFIG_BFIN_SCRATCH_REG_CYCLES is not set
228
229#
230# Blackfin Kernel Optimizations
231#
232
233#
234# Memory Optimizations
235#
236CONFIG_I_ENTRY_L1=y
237CONFIG_EXCPT_IRQ_SYSC_L1=y
238CONFIG_DO_IRQ_L1=y
239CONFIG_CORE_TIMER_IRQ_L1=y
240CONFIG_IDLE_L1=y
241CONFIG_SCHEDULE_L1=y
242CONFIG_ARITHMETIC_OPS_L1=y
243CONFIG_ACCESS_OK_L1=y
244CONFIG_MEMSET_L1=y
245CONFIG_MEMCPY_L1=y
246CONFIG_SYS_BFIN_SPINLOCK_L1=y
247# CONFIG_IP_CHECKSUM_L1 is not set
248CONFIG_CACHELINE_ALIGNED_L1=y
249# CONFIG_SYSCALL_TAB_L1 is not set
250# CONFIG_CPLB_SWITCH_TAB_L1 is not set
251CONFIG_RAMKERNEL=y
252# CONFIG_ROMKERNEL is not set
253CONFIG_SELECT_MEMORY_MODEL=y
254CONFIG_FLATMEM_MANUAL=y
255# CONFIG_DISCONTIGMEM_MANUAL is not set
256# CONFIG_SPARSEMEM_MANUAL is not set
257CONFIG_FLATMEM=y
258CONFIG_FLAT_NODE_MEM_MAP=y
259# CONFIG_SPARSEMEM_STATIC is not set
260CONFIG_SPLIT_PTLOCK_CPUS=4
261# CONFIG_RESOURCES_64BIT is not set
262CONFIG_ZONE_DMA_FLAG=1
263CONFIG_LARGE_ALLOCS=y
264# CONFIG_BFIN_GPTIMERS is not set
265CONFIG_BFIN_DMA_5XX=y
266# CONFIG_DMA_UNCACHED_2M is not set
267CONFIG_DMA_UNCACHED_1M=y
268# CONFIG_DMA_UNCACHED_NONE is not set
269
270#
271# Cache Support
272#
273# CONFIG_BFIN_ICACHE is not set
274# CONFIG_BFIN_DCACHE is not set
275# CONFIG_BFIN_ICACHE_LOCK is not set
276CONFIG_L1_MAX_PIECE=16
277# CONFIG_MPU is not set
278
279#
280# Asynchonous Memory Configuration
281#
282
283#
284# EBIU_AMGCTL Global Control
285#
286CONFIG_C_AMCKEN=y
287CONFIG_C_CDPRIO=y
288# CONFIG_C_AMBEN is not set
289# CONFIG_C_AMBEN_B0 is not set
290# CONFIG_C_AMBEN_B0_B1 is not set
291# CONFIG_C_AMBEN_B0_B1_B2 is not set
292CONFIG_C_AMBEN_ALL=y
293
294#
295# EBIU_AMBCTL Control
296#
297CONFIG_BANK_0=0xffc2
298CONFIG_BANK_1=0xffc2
299CONFIG_BANK_2=0xffc2
300CONFIG_BANK_3=0xffc2
301
302#
303# Bus options (PCI, PCMCIA, EISA, MCA, ISA)
304#
305# CONFIG_PCI is not set
306# CONFIG_ARCH_SUPPORTS_MSI is not set
307
308#
309# PCCARD (PCMCIA/CardBus) support
310#
311
312#
313# Executable file formats
314#
315CONFIG_BINFMT_ELF_FDPIC=y
316CONFIG_BINFMT_FLAT=y
317CONFIG_BINFMT_ZFLAT=y
318# CONFIG_BINFMT_SHARED_FLAT is not set
319# CONFIG_BINFMT_MISC is not set
320
321#
322# Power management options
323#
324CONFIG_PM=y
325# CONFIG_PM_LEGACY is not set
326# CONFIG_PM_DEBUG is not set
327# CONFIG_PM_SYSFS_DEPRECATED is not set
328CONFIG_PM_BFIN_SLEEP_DEEPER=y
329# CONFIG_PM_BFIN_SLEEP is not set
330# CONFIG_PM_WAKEUP_BY_GPIO is not set
331
332#
333# Networking
334#
335CONFIG_NET=y
336
337#
338# Networking options
339#
340CONFIG_PACKET=y
341# CONFIG_PACKET_MMAP is not set
342CONFIG_UNIX=y
343CONFIG_XFRM=y
344# CONFIG_XFRM_USER is not set
345# CONFIG_XFRM_SUB_POLICY is not set
346# CONFIG_XFRM_MIGRATE is not set
347# CONFIG_NET_KEY is not set
348CONFIG_INET=y
349# CONFIG_IP_MULTICAST is not set
350# CONFIG_IP_ADVANCED_ROUTER is not set
351CONFIG_IP_FIB_HASH=y
352CONFIG_IP_PNP=y
353# CONFIG_IP_PNP_DHCP is not set
354# CONFIG_IP_PNP_BOOTP is not set
355# CONFIG_IP_PNP_RARP is not set
356# CONFIG_NET_IPIP is not set
357# CONFIG_NET_IPGRE is not set
358# CONFIG_ARPD is not set
359CONFIG_SYN_COOKIES=y
360# CONFIG_INET_AH is not set
361# CONFIG_INET_ESP is not set
362# CONFIG_INET_IPCOMP is not set
363# CONFIG_INET_XFRM_TUNNEL is not set
364# CONFIG_INET_TUNNEL is not set
365CONFIG_INET_XFRM_MODE_TRANSPORT=y
366CONFIG_INET_XFRM_MODE_TUNNEL=y
367CONFIG_INET_XFRM_MODE_BEET=y
368CONFIG_INET_DIAG=y
369CONFIG_INET_TCP_DIAG=y
370# CONFIG_TCP_CONG_ADVANCED is not set
371CONFIG_TCP_CONG_CUBIC=y
372CONFIG_DEFAULT_TCP_CONG="cubic"
373# CONFIG_TCP_MD5SIG is not set
374# CONFIG_IP_VS is not set
375# CONFIG_IPV6 is not set
376# CONFIG_INET6_XFRM_TUNNEL is not set
377# CONFIG_INET6_TUNNEL is not set
378# CONFIG_NETLABEL is not set
379# CONFIG_NETWORK_SECMARK is not set
380CONFIG_NETFILTER=y
381# CONFIG_NETFILTER_DEBUG is not set
382
383#
384# Core Netfilter Configuration
385#
386# CONFIG_NETFILTER_NETLINK is not set
387# CONFIG_NF_CONNTRACK_ENABLED is not set
388# CONFIG_NF_CONNTRACK is not set
389CONFIG_NETFILTER_XTABLES=y
390# CONFIG_NETFILTER_XT_TARGET_CLASSIFY is not set
391# CONFIG_NETFILTER_XT_TARGET_DSCP is not set
392# CONFIG_NETFILTER_XT_TARGET_MARK is not set
393# CONFIG_NETFILTER_XT_TARGET_NFQUEUE is not set
394# CONFIG_NETFILTER_XT_TARGET_NFLOG is not set
395# CONFIG_NETFILTER_XT_TARGET_TCPMSS is not set
396# CONFIG_NETFILTER_XT_MATCH_COMMENT is not set
397# CONFIG_NETFILTER_XT_MATCH_DCCP is not set
398# CONFIG_NETFILTER_XT_MATCH_DSCP is not set
399# CONFIG_NETFILTER_XT_MATCH_ESP is not set
400# CONFIG_NETFILTER_XT_MATCH_LENGTH is not set
401# CONFIG_NETFILTER_XT_MATCH_LIMIT is not set
402CONFIG_NETFILTER_XT_MATCH_MAC=y
403# CONFIG_NETFILTER_XT_MATCH_MARK is not set
404# CONFIG_NETFILTER_XT_MATCH_POLICY is not set
405CONFIG_NETFILTER_XT_MATCH_MULTIPORT=y
406# CONFIG_NETFILTER_XT_MATCH_PKTTYPE is not set
407# CONFIG_NETFILTER_XT_MATCH_QUOTA is not set
408# CONFIG_NETFILTER_XT_MATCH_REALM is not set
409# CONFIG_NETFILTER_XT_MATCH_SCTP is not set
410# CONFIG_NETFILTER_XT_MATCH_STATISTIC is not set
411# CONFIG_NETFILTER_XT_MATCH_STRING is not set
412# CONFIG_NETFILTER_XT_MATCH_TCPMSS is not set
413# CONFIG_NETFILTER_XT_MATCH_HASHLIMIT is not set
414
415#
416# IP: Netfilter Configuration
417#
418# CONFIG_IP_NF_QUEUE is not set
419CONFIG_IP_NF_IPTABLES=y
420CONFIG_IP_NF_MATCH_IPRANGE=y
421CONFIG_IP_NF_MATCH_TOS=y
422# CONFIG_IP_NF_MATCH_RECENT is not set
423# CONFIG_IP_NF_MATCH_ECN is not set
424# CONFIG_IP_NF_MATCH_AH is not set
425# CONFIG_IP_NF_MATCH_TTL is not set
426# CONFIG_IP_NF_MATCH_OWNER is not set
427# CONFIG_IP_NF_MATCH_ADDRTYPE is not set
428CONFIG_IP_NF_FILTER=y
429CONFIG_IP_NF_TARGET_REJECT=y
430# CONFIG_IP_NF_TARGET_LOG is not set
431# CONFIG_IP_NF_TARGET_ULOG is not set
432CONFIG_IP_NF_MANGLE=y
433CONFIG_IP_NF_TARGET_TOS=y
434# CONFIG_IP_NF_TARGET_ECN is not set
435# CONFIG_IP_NF_TARGET_TTL is not set
436# CONFIG_IP_NF_RAW is not set
437# CONFIG_IP_NF_ARPTABLES is not set
438# CONFIG_IP_DCCP is not set
439# CONFIG_IP_SCTP is not set
440# CONFIG_TIPC is not set
441# CONFIG_ATM is not set
442# CONFIG_BRIDGE is not set
443# CONFIG_VLAN_8021Q is not set
444# CONFIG_DECNET is not set
445# CONFIG_LLC2 is not set
446# CONFIG_IPX is not set
447# CONFIG_ATALK is not set
448# CONFIG_X25 is not set
449# CONFIG_LAPB is not set
450# CONFIG_ECONET is not set
451# CONFIG_WAN_ROUTER is not set
452
453#
454# QoS and/or fair queueing
455#
456# CONFIG_NET_SCHED is not set
457
458#
459# Network testing
460#
461# CONFIG_NET_PKTGEN is not set
462# CONFIG_HAMRADIO is not set
463# CONFIG_IRDA is not set
464# CONFIG_BT is not set
465# CONFIG_AF_RXRPC is not set
466
467#
468# Wireless
469#
470# CONFIG_CFG80211 is not set
471# CONFIG_WIRELESS_EXT is not set
472# CONFIG_MAC80211 is not set
473# CONFIG_IEEE80211 is not set
474# CONFIG_RFKILL is not set
475
476#
477# Device Drivers
478#
479
480#
481# Generic Driver Options
482#
483CONFIG_STANDALONE=y
484CONFIG_PREVENT_FIRMWARE_BUILD=y
485# CONFIG_SYS_HYPERVISOR is not set
486
487#
488# Connector - unified userspace <-> kernelspace linker
489#
490# CONFIG_CONNECTOR is not set
491CONFIG_MTD=y
492# CONFIG_MTD_DEBUG is not set
493# CONFIG_MTD_CONCAT is not set
494CONFIG_MTD_PARTITIONS=y
495# CONFIG_MTD_REDBOOT_PARTS is not set
496# CONFIG_MTD_CMDLINE_PARTS is not set
497
498#
499# User Modules And Translation Layers
500#
501CONFIG_MTD_CHAR=y
502CONFIG_MTD_BLKDEVS=y
503CONFIG_MTD_BLOCK=y
504# CONFIG_FTL is not set
505# CONFIG_NFTL is not set
506# CONFIG_INFTL is not set
507# CONFIG_RFD_FTL is not set
508# CONFIG_SSFDC is not set
509
510#
511# RAM/ROM/Flash chip drivers
512#
513CONFIG_MTD_CFI=y
514# CONFIG_MTD_JEDECPROBE is not set
515CONFIG_MTD_GEN_PROBE=y
516# CONFIG_MTD_CFI_ADV_OPTIONS is not set
517CONFIG_MTD_MAP_BANK_WIDTH_1=y
518CONFIG_MTD_MAP_BANK_WIDTH_2=y
519CONFIG_MTD_MAP_BANK_WIDTH_4=y
520# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
521# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
522# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
523CONFIG_MTD_CFI_I1=y
524CONFIG_MTD_CFI_I2=y
525# CONFIG_MTD_CFI_I4 is not set
526# CONFIG_MTD_CFI_I8 is not set
527# CONFIG_MTD_CFI_INTELEXT is not set
528CONFIG_MTD_CFI_AMDSTD=y
529# CONFIG_MTD_CFI_STAA is not set
530CONFIG_MTD_CFI_UTIL=y
531CONFIG_MTD_RAM=y
532# CONFIG_MTD_ROM is not set
533# CONFIG_MTD_ABSENT is not set
534
535#
536# Mapping drivers for chip access
537#
538CONFIG_MTD_COMPLEX_MAPPINGS=y
539# CONFIG_MTD_PHYSMAP is not set
540CONFIG_MTD_UCLINUX=y
541CONFIG_MTD_PLATRAM=y
542
543#
544# Self-contained MTD device drivers
545#
546# CONFIG_MTD_DATAFLASH is not set
547# CONFIG_MTD_M25P80 is not set
548# CONFIG_MTD_SLRAM is not set
549# CONFIG_MTD_PHRAM is not set
550# CONFIG_MTD_MTDRAM is not set
551# CONFIG_MTD_BLOCK2MTD is not set
552
553#
554# Disk-On-Chip Device Drivers
555#
556# CONFIG_MTD_DOC2000 is not set
557# CONFIG_MTD_DOC2001 is not set
558# CONFIG_MTD_DOC2001PLUS is not set
559CONFIG_MTD_NAND=y
560# CONFIG_MTD_NAND_VERIFY_WRITE is not set
561# CONFIG_MTD_NAND_ECC_SMC is not set
562# CONFIG_MTD_NAND_MUSEUM_IDS is not set
563CONFIG_MTD_NAND_BFIN=y
564CONFIG_BFIN_NAND_BASE=0x20000000
565CONFIG_BFIN_NAND_SIZE=0x10000000
566CONFIG_BFIN_NAND_CLE=2
567CONFIG_BFIN_NAND_ALE=1
568CONFIG_BFIN_NAND_READY=10
569CONFIG_MTD_NAND_IDS=y
570# CONFIG_MTD_NAND_DISKONCHIP is not set
571# CONFIG_MTD_NAND_NANDSIM is not set
572# CONFIG_MTD_NAND_PLATFORM is not set
573# CONFIG_MTD_ONENAND is not set
574
575#
576# UBI - Unsorted block images
577#
578# CONFIG_MTD_UBI is not set
579
580#
581# Parallel port support
582#
583# CONFIG_PARPORT is not set
584
585#
586# Plug and Play support
587#
588# CONFIG_PNPACPI is not set
589
590#
591# Block devices
592#
593# CONFIG_BLK_DEV_COW_COMMON is not set
594# CONFIG_BLK_DEV_LOOP is not set
595# CONFIG_BLK_DEV_NBD is not set
596# CONFIG_BLK_DEV_UB is not set
597CONFIG_BLK_DEV_RAM=y
598CONFIG_BLK_DEV_RAM_COUNT=16
599CONFIG_BLK_DEV_RAM_SIZE=4096
600CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
601# CONFIG_CDROM_PKTCDVD is not set
602# CONFIG_ATA_OVER_ETH is not set
603
604#
605# Misc devices
606#
607# CONFIG_IDE is not set
608
609#
610# SCSI device support
611#
612# CONFIG_RAID_ATTRS is not set
613CONFIG_SCSI=y
614# CONFIG_SCSI_TGT is not set
615# CONFIG_SCSI_NETLINK is not set
616CONFIG_SCSI_PROC_FS=y
617
618#
619# SCSI support type (disk, tape, CD-ROM)
620#
621CONFIG_BLK_DEV_SD=y
622# CONFIG_CHR_DEV_ST is not set
623# CONFIG_CHR_DEV_OSST is not set
624# CONFIG_BLK_DEV_SR is not set
625# CONFIG_CHR_DEV_SG is not set
626# CONFIG_CHR_DEV_SCH is not set
627
628#
629# Some SCSI devices (e.g. CD jukebox) support multiple LUNs
630#
631# CONFIG_SCSI_MULTI_LUN is not set
632# CONFIG_SCSI_CONSTANTS is not set
633# CONFIG_SCSI_LOGGING is not set
634# CONFIG_SCSI_SCAN_ASYNC is not set
635CONFIG_SCSI_WAIT_SCAN=m
636
637#
638# SCSI Transports
639#
640# CONFIG_SCSI_SPI_ATTRS is not set
641# CONFIG_SCSI_FC_ATTRS is not set
642# CONFIG_SCSI_ISCSI_ATTRS is not set
643# CONFIG_SCSI_SAS_ATTRS is not set
644# CONFIG_SCSI_SAS_LIBSAS is not set
645
646#
647# SCSI low-level drivers
648#
649# CONFIG_ISCSI_TCP is not set
650# CONFIG_SCSI_DEBUG is not set
651# CONFIG_ATA is not set
652
653#
654# Multi-device support (RAID and LVM)
655#
656# CONFIG_MD is not set
657
658#
659# Network device support
660#
661CONFIG_NETDEVICES=y
662# CONFIG_DUMMY is not set
663# CONFIG_BONDING is not set
664# CONFIG_EQUALIZER is not set
665# CONFIG_TUN is not set
666# CONFIG_PHYLIB is not set
667
668#
669# Ethernet (10 or 100Mbit)
670#
671CONFIG_NET_ETHERNET=y
672CONFIG_MII=y
673# CONFIG_SMC91X is not set
674# CONFIG_SMSC911X is not set
675CONFIG_DM9000=y
676CONFIG_NETDEV_1000=y
677# CONFIG_AX88180 is not set
678CONFIG_NETDEV_10000=y
679
680#
681# Wireless LAN
682#
683# CONFIG_WLAN_PRE80211 is not set
684# CONFIG_WLAN_80211 is not set
685
686#
687# USB Network Adapters
688#
689# CONFIG_USB_CATC is not set
690# CONFIG_USB_KAWETH is not set
691# CONFIG_USB_PEGASUS is not set
692# CONFIG_USB_RTL8150 is not set
693# CONFIG_USB_USBNET_MII is not set
694# CONFIG_USB_USBNET is not set
695# CONFIG_WAN is not set
696# CONFIG_PPP is not set
697# CONFIG_SLIP is not set
698# CONFIG_SHAPER is not set
699# CONFIG_NETCONSOLE is not set
700# CONFIG_NETPOLL is not set
701# CONFIG_NET_POLL_CONTROLLER is not set
702
703#
704# ISDN subsystem
705#
706# CONFIG_ISDN is not set
707
708#
709# Telephony Support
710#
711# CONFIG_PHONE is not set
712
713#
714# Input device support
715#
716# CONFIG_INPUT is not set
717
718#
719# Hardware I/O ports
720#
721# CONFIG_SERIO is not set
722# CONFIG_GAMEPORT is not set
723
724#
725# Character devices
726#
727# CONFIG_AD9960 is not set
728# CONFIG_SPI_ADC_BF533 is not set
729# CONFIG_BF5xx_PFLAGS is not set
730# CONFIG_BF5xx_PPIFCD is not set
731# CONFIG_BFIN_SIMPLE_TIMER is not set
732# CONFIG_BF5xx_PPI is not set
733CONFIG_BFIN_SPORT=y
734# CONFIG_BFIN_TIMER_LATENCY is not set
735# CONFIG_AD5304 is not set
736# CONFIG_VT is not set
737# CONFIG_SERIAL_NONSTANDARD is not set
738
739#
740# Serial drivers
741#
742# CONFIG_SERIAL_8250 is not set
743
744#
745# Non-8250 serial port support
746#
747CONFIG_SERIAL_BFIN=y
748CONFIG_SERIAL_BFIN_CONSOLE=y
749CONFIG_SERIAL_BFIN_DMA=y
750# CONFIG_SERIAL_BFIN_PIO is not set
751CONFIG_SERIAL_BFIN_UART0=y
752# CONFIG_BFIN_UART0_CTSRTS is not set
753CONFIG_SERIAL_CORE=y
754CONFIG_SERIAL_CORE_CONSOLE=y
755# CONFIG_SERIAL_BFIN_SPORT is not set
756CONFIG_UNIX98_PTYS=y
757# CONFIG_LEGACY_PTYS is not set
758
759#
760# CAN, the car bus and industrial fieldbus
761#
762# CONFIG_CAN4LINUX is not set
763
764#
765# IPMI
766#
767# CONFIG_IPMI_HANDLER is not set
768CONFIG_WATCHDOG=y
769# CONFIG_WATCHDOG_NOWAYOUT is not set
770
771#
772# Watchdog Device Drivers
773#
774# CONFIG_SOFT_WATCHDOG is not set
775# CONFIG_BFIN_WDT is not set
776
777#
778# USB-based Watchdog Cards
779#
780# CONFIG_USBPCWATCHDOG is not set
781CONFIG_HW_RANDOM=y
782# CONFIG_GEN_RTC is not set
783# CONFIG_R3964 is not set
784# CONFIG_RAW_DRIVER is not set
785
786#
787# TPM devices
788#
789# CONFIG_TCG_TPM is not set
790# CONFIG_I2C is not set
791
792#
793# SPI support
794#
795CONFIG_SPI=y
796CONFIG_SPI_MASTER=y
797
798#
799# SPI Master Controller Drivers
800#
801CONFIG_SPI_BFIN=y
802# CONFIG_SPI_BITBANG is not set
803
804#
805# SPI Protocol Masters
806#
807# CONFIG_SPI_AT25 is not set
808# CONFIG_SPI_SPIDEV is not set
809
810#
811# Dallas's 1-wire bus
812#
813# CONFIG_W1 is not set
814# CONFIG_HWMON is not set
815
816#
817# Multifunction device drivers
818#
819# CONFIG_MFD_SM501 is not set
820
821#
822# Multimedia devices
823#
824# CONFIG_VIDEO_DEV is not set
825# CONFIG_DVB_CORE is not set
826CONFIG_DAB=y
827# CONFIG_USB_DABUSB is not set
828
829#
830# Graphics support
831#
832# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
833
834#
835# Display device support
836#
837# CONFIG_DISPLAY_SUPPORT is not set
838# CONFIG_VGASTATE is not set
839# CONFIG_FB is not set
840
841#
842# Sound
843#
844# CONFIG_SOUND is not set
845
846#
847# USB support
848#
849CONFIG_USB_ARCH_HAS_HCD=y
850# CONFIG_USB_ARCH_HAS_OHCI is not set
851# CONFIG_USB_ARCH_HAS_EHCI is not set
852CONFIG_USB=y
853# CONFIG_USB_DEBUG is not set
854
855#
856# Miscellaneous USB options
857#
858CONFIG_USB_DEVICEFS=y
859CONFIG_USB_DEVICE_CLASS=y
860# CONFIG_USB_DYNAMIC_MINORS is not set
861# CONFIG_USB_SUSPEND is not set
862# CONFIG_USB_OTG is not set
863CONFIG_USB_OTG_WHITELIST=y
864# CONFIG_USB_OTG_BLACKLIST_HUB is not set
865
866#
867# USB Host Controller Drivers
868#
869# CONFIG_USB_ISP116X_HCD is not set
870CONFIG_USB_ISP1362_HCD=y
871# CONFIG_USB_ISP1760_HCD is not set
872# CONFIG_USB_SL811_HCD is not set
873# CONFIG_USB_MUSB_HDRC is not set
874
875#
876# USB Device Class drivers
877#
878# CONFIG_USB_ACM is not set
879# CONFIG_USB_PRINTER is not set
880
881#
882# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
883#
884
885#
886# may also be needed; see USB_STORAGE Help for more information
887#
888CONFIG_USB_STORAGE=y
889# CONFIG_USB_STORAGE_DEBUG is not set
890# CONFIG_USB_STORAGE_DATAFAB is not set
891# CONFIG_USB_STORAGE_FREECOM is not set
892# CONFIG_USB_STORAGE_DPCM is not set
893# CONFIG_USB_STORAGE_USBAT is not set
894# CONFIG_USB_STORAGE_SDDR09 is not set
895# CONFIG_USB_STORAGE_SDDR55 is not set
896# CONFIG_USB_STORAGE_JUMPSHOT is not set
897# CONFIG_USB_STORAGE_ALAUDA is not set
898# CONFIG_USB_STORAGE_KARMA is not set
899# CONFIG_USB_LIBUSUAL is not set
900
901#
902# USB Imaging devices
903#
904# CONFIG_USB_MDC800 is not set
905# CONFIG_USB_MICROTEK is not set
906CONFIG_USB_MON=y
907
908#
909# USB port drivers
910#
911
912#
913# USB Serial Converter support
914#
915# CONFIG_USB_SERIAL is not set
916
917#
918# USB Miscellaneous drivers
919#
920# CONFIG_USB_EMI62 is not set
921# CONFIG_USB_EMI26 is not set
922# CONFIG_USB_ADUTUX is not set
923# CONFIG_USB_AUERSWALD is not set
924# CONFIG_USB_RIO500 is not set
925# CONFIG_USB_LEGOTOWER is not set
926# CONFIG_USB_LCD is not set
927# CONFIG_USB_BERRY_CHARGE is not set
928# CONFIG_USB_LED is not set
929# CONFIG_USB_CYPRESS_CY7C63 is not set
930# CONFIG_USB_CYTHERM is not set
931# CONFIG_USB_PHIDGET is not set
932# CONFIG_USB_IDMOUSE is not set
933# CONFIG_USB_FTDI_ELAN is not set
934# CONFIG_USB_APPLEDISPLAY is not set
935# CONFIG_USB_LD is not set
936# CONFIG_USB_TRANCEVIBRATOR is not set
937# CONFIG_USB_IOWARRIOR is not set
938# CONFIG_USB_TEST is not set
939
940#
941# USB DSL modem support
942#
943
944#
945# USB Gadget Support
946#
947# CONFIG_USB_GADGET is not set
948CONFIG_MMC=m
949# CONFIG_MMC_DEBUG is not set
950# CONFIG_MMC_UNSAFE_RESUME is not set
951
952#
953# MMC/SD Card Drivers
954#
955CONFIG_MMC_BLOCK=m
956
957#
958# MMC/SD Host Controller Drivers
959#
960CONFIG_SPI_MMC=m
961CONFIG_SPI_MMC_FRAMEWORK_DRIVER=y
962# CONFIG_SPI_MMC_BFIN_PIO_SPI is not set
963CONFIG_SPI_MMC_CS_CHAN=5
964CONFIG_SPI_MMC_MAX_HZ=20000000
965# CONFIG_SPI_MMC_CARD_DETECT is not set
966# CONFIG_SPI_MMC_DEBUG_MODE is not set
967
968#
969# LED devices
970#
971# CONFIG_NEW_LEDS is not set
972
973#
974# LED drivers
975#
976
977#
978# LED Triggers
979#
980
981#
982# InfiniBand support
983#
984
985#
986# EDAC - error detection and reporting (RAS) (EXPERIMENTAL)
987#
988
989#
990# Real Time Clock
991#
992CONFIG_RTC_LIB=y
993CONFIG_RTC_CLASS=y
994CONFIG_RTC_HCTOSYS=y
995CONFIG_RTC_HCTOSYS_DEVICE="rtc0"
996# CONFIG_RTC_DEBUG is not set
997
998#
999# RTC interfaces
1000#
1001CONFIG_RTC_INTF_SYSFS=y
1002CONFIG_RTC_INTF_PROC=y
1003CONFIG_RTC_INTF_DEV=y
1004# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set
1005# CONFIG_RTC_DRV_TEST is not set
1006
1007#
1008# I2C RTC drivers
1009#
1010
1011#
1012# SPI RTC drivers
1013#
1014# CONFIG_RTC_DRV_RS5C348 is not set
1015# CONFIG_RTC_DRV_MAX6902 is not set
1016
1017#
1018# Platform RTC drivers
1019#
1020# CONFIG_RTC_DRV_DS1553 is not set
1021# CONFIG_RTC_DRV_DS1742 is not set
1022# CONFIG_RTC_DRV_M48T86 is not set
1023# CONFIG_RTC_DRV_V3020 is not set
1024
1025#
1026# on-CPU RTC drivers
1027#
1028CONFIG_RTC_DRV_BFIN=y
1029
1030#
1031# DMA Engine support
1032#
1033# CONFIG_DMA_ENGINE is not set
1034
1035#
1036# DMA Clients
1037#
1038
1039#
1040# DMA Devices
1041#
1042
1043#
1044# PBX support
1045#
1046# CONFIG_PBX is not set
1047
1048#
1049# File systems
1050#
1051CONFIG_EXT2_FS=y
1052CONFIG_EXT2_FS_XATTR=y
1053# CONFIG_EXT2_FS_POSIX_ACL is not set
1054# CONFIG_EXT2_FS_SECURITY is not set
1055# CONFIG_EXT3_FS is not set
1056# CONFIG_EXT4DEV_FS is not set
1057CONFIG_FS_MBCACHE=y
1058# CONFIG_REISERFS_FS is not set
1059# CONFIG_JFS_FS is not set
1060# CONFIG_FS_POSIX_ACL is not set
1061# CONFIG_XFS_FS is not set
1062# CONFIG_GFS2_FS is not set
1063# CONFIG_OCFS2_FS is not set
1064# CONFIG_MINIX_FS is not set
1065# CONFIG_ROMFS_FS is not set
1066CONFIG_INOTIFY=y
1067CONFIG_INOTIFY_USER=y
1068# CONFIG_QUOTA is not set
1069CONFIG_DNOTIFY=y
1070# CONFIG_AUTOFS_FS is not set
1071# CONFIG_AUTOFS4_FS is not set
1072# CONFIG_FUSE_FS is not set
1073
1074#
1075# CD-ROM/DVD Filesystems
1076#
1077# CONFIG_ISO9660_FS is not set
1078# CONFIG_UDF_FS is not set
1079
1080#
1081# DOS/FAT/NT Filesystems
1082#
1083CONFIG_FAT_FS=y
1084CONFIG_MSDOS_FS=y
1085CONFIG_VFAT_FS=y
1086CONFIG_FAT_DEFAULT_CODEPAGE=437
1087CONFIG_FAT_DEFAULT_IOCHARSET="iso8859-1"
1088# CONFIG_NTFS_FS is not set
1089
1090#
1091# Pseudo filesystems
1092#
1093CONFIG_PROC_FS=y
1094CONFIG_PROC_SYSCTL=y
1095CONFIG_SYSFS=y
1096# CONFIG_TMPFS is not set
1097# CONFIG_HUGETLB_PAGE is not set
1098CONFIG_RAMFS=y
1099# CONFIG_CONFIGFS_FS is not set
1100
1101#
1102# Miscellaneous filesystems
1103#
1104# CONFIG_ADFS_FS is not set
1105# CONFIG_AFFS_FS is not set
1106# CONFIG_HFS_FS is not set
1107# CONFIG_HFSPLUS_FS is not set
1108# CONFIG_BEFS_FS is not set
1109# CONFIG_BFS_FS is not set
1110# CONFIG_EFS_FS is not set
1111CONFIG_YAFFS_FS=y
1112CONFIG_YAFFS_YAFFS1=y
1113# CONFIG_YAFFS_DOES_ECC is not set
1114CONFIG_YAFFS_YAFFS2=y
1115CONFIG_YAFFS_AUTO_YAFFS2=y
1116# CONFIG_YAFFS_DISABLE_LAZY_LOAD is not set
1117CONFIG_YAFFS_CHECKPOINT_RESERVED_BLOCKS=10
1118# CONFIG_YAFFS_DISABLE_WIDE_TNODES is not set
1119# CONFIG_YAFFS_ALWAYS_CHECK_CHUNK_ERASED is not set
1120CONFIG_YAFFS_SHORT_NAMES_IN_RAM=y
1121# CONFIG_JFFS2_FS is not set
1122# CONFIG_CRAMFS is not set
1123# CONFIG_VXFS_FS is not set
1124# CONFIG_HPFS_FS is not set
1125# CONFIG_QNX4FS_FS is not set
1126# CONFIG_SYSV_FS is not set
1127# CONFIG_UFS_FS is not set
1128
1129#
1130# Network File Systems
1131#
1132# CONFIG_NFS_FS is not set
1133# CONFIG_NFSD is not set
1134# CONFIG_SMB_FS is not set
1135# CONFIG_CIFS is not set
1136# CONFIG_NCP_FS is not set
1137# CONFIG_CODA_FS is not set
1138# CONFIG_AFS_FS is not set
1139# CONFIG_9P_FS is not set
1140
1141#
1142# Partition Types
1143#
1144# CONFIG_PARTITION_ADVANCED is not set
1145CONFIG_MSDOS_PARTITION=y
1146
1147#
1148# Native Language Support
1149#
1150CONFIG_NLS=y
1151CONFIG_NLS_DEFAULT="iso8859-1"
1152CONFIG_NLS_CODEPAGE_437=y
1153# CONFIG_NLS_CODEPAGE_737 is not set
1154# CONFIG_NLS_CODEPAGE_775 is not set
1155# CONFIG_NLS_CODEPAGE_850 is not set
1156# CONFIG_NLS_CODEPAGE_852 is not set
1157# CONFIG_NLS_CODEPAGE_855 is not set
1158# CONFIG_NLS_CODEPAGE_857 is not set
1159# CONFIG_NLS_CODEPAGE_860 is not set
1160# CONFIG_NLS_CODEPAGE_861 is not set
1161# CONFIG_NLS_CODEPAGE_862 is not set
1162# CONFIG_NLS_CODEPAGE_863 is not set
1163# CONFIG_NLS_CODEPAGE_864 is not set
1164# CONFIG_NLS_CODEPAGE_865 is not set
1165# CONFIG_NLS_CODEPAGE_866 is not set
1166# CONFIG_NLS_CODEPAGE_869 is not set
1167# CONFIG_NLS_CODEPAGE_936 is not set
1168# CONFIG_NLS_CODEPAGE_950 is not set
1169# CONFIG_NLS_CODEPAGE_932 is not set
1170# CONFIG_NLS_CODEPAGE_949 is not set
1171# CONFIG_NLS_CODEPAGE_874 is not set
1172# CONFIG_NLS_ISO8859_8 is not set
1173# CONFIG_NLS_CODEPAGE_1250 is not set
1174# CONFIG_NLS_CODEPAGE_1251 is not set
1175# CONFIG_NLS_ASCII is not set
1176CONFIG_NLS_ISO8859_1=y
1177# CONFIG_NLS_ISO8859_2 is not set
1178# CONFIG_NLS_ISO8859_3 is not set
1179# CONFIG_NLS_ISO8859_4 is not set
1180# CONFIG_NLS_ISO8859_5 is not set
1181# CONFIG_NLS_ISO8859_6 is not set
1182# CONFIG_NLS_ISO8859_7 is not set
1183# CONFIG_NLS_ISO8859_9 is not set
1184# CONFIG_NLS_ISO8859_13 is not set
1185# CONFIG_NLS_ISO8859_14 is not set
1186# CONFIG_NLS_ISO8859_15 is not set
1187# CONFIG_NLS_KOI8_R is not set
1188# CONFIG_NLS_KOI8_U is not set
1189# CONFIG_NLS_UTF8 is not set
1190
1191#
1192# Distributed Lock Manager
1193#
1194# CONFIG_DLM is not set
1195
1196#
1197# Profiling support
1198#
1199# CONFIG_PROFILING is not set
1200
1201#
1202# Kernel hacking
1203#
1204# CONFIG_PRINTK_TIME is not set
1205CONFIG_ENABLE_MUST_CHECK=y
1206# CONFIG_MAGIC_SYSRQ is not set
1207# CONFIG_UNUSED_SYMBOLS is not set
1208# CONFIG_DEBUG_FS is not set
1209# CONFIG_HEADERS_CHECK is not set
1210# CONFIG_DEBUG_KERNEL is not set
1211# CONFIG_DEBUG_BUGVERBOSE is not set
1212# CONFIG_DEBUG_MMRS is not set
1213CONFIG_DEBUG_HUNT_FOR_ZERO=y
1214CONFIG_DEBUG_BFIN_HWTRACE_ON=y
1215CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_OFF=y
1216# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE is not set
1217# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_TWO is not set
1218CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION=0
1219# CONFIG_DEBUG_BFIN_HWTRACE_EXPAND is not set
1220# CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE is not set
1221# CONFIG_EARLY_PRINTK is not set
1222CONFIG_CPLB_INFO=y
1223CONFIG_ACCESS_CHECK=y
1224
1225#
1226# Security options
1227#
1228# CONFIG_KEYS is not set
1229CONFIG_SECURITY=y
1230# CONFIG_SECURITY_NETWORK is not set
1231CONFIG_SECURITY_CAPABILITIES=m
1232# CONFIG_SECURITY_ROOTPLUG is not set
1233
1234#
1235# Cryptographic options
1236#
1237# CONFIG_CRYPTO is not set
1238
1239#
1240# Library routines
1241#
1242CONFIG_BITREVERSE=y
1243CONFIG_CRC_CCITT=y
1244# CONFIG_CRC16 is not set
1245# CONFIG_CRC_ITU_T is not set
1246CONFIG_CRC32=y
1247# CONFIG_LIBCRC32C is not set
1248CONFIG_ZLIB_INFLATE=y
1249CONFIG_PLIST=y
1250CONFIG_HAS_IOMEM=y
1251CONFIG_HAS_IOPORT=y
1252CONFIG_HAS_DMA=y
diff --git a/arch/blackfin/configs/PNAV-10_defconfig b/arch/blackfin/configs/PNAV-10_defconfig
index 25709f504d8f..87622ad9df47 100644
--- a/arch/blackfin/configs/PNAV-10_defconfig
+++ b/arch/blackfin/configs/PNAV-10_defconfig
@@ -13,7 +13,7 @@ CONFIG_GENERIC_FIND_NEXT_BIT=y
13CONFIG_GENERIC_HWEIGHT=y 13CONFIG_GENERIC_HWEIGHT=y
14CONFIG_GENERIC_HARDIRQS=y 14CONFIG_GENERIC_HARDIRQS=y
15CONFIG_GENERIC_IRQ_PROBE=y 15CONFIG_GENERIC_IRQ_PROBE=y
16# CONFIG_GENERIC_TIME is not set 16CONFIG_GENERIC_TIME=y
17CONFIG_GENERIC_GPIO=y 17CONFIG_GENERIC_GPIO=y
18CONFIG_FORCE_MAX_ZONEORDER=14 18CONFIG_FORCE_MAX_ZONEORDER=14
19CONFIG_GENERIC_CALIBRATE_DELAY=y 19CONFIG_GENERIC_CALIBRATE_DELAY=y
@@ -214,7 +214,7 @@ CONFIG_HZ=250
214# 214#
215# Memory Setup 215# Memory Setup
216# 216#
217CONFIG_MEM_SIZE=64 217CONFIG_MAX_MEM_SIZE=64
218CONFIG_MEM_ADD_WIDTH=10 218CONFIG_MEM_ADD_WIDTH=10
219CONFIG_BOOT_LOAD=0x1000 219CONFIG_BOOT_LOAD=0x1000
220CONFIG_BFIN_SCRATCH_REG_RETN=y 220CONFIG_BFIN_SCRATCH_REG_RETN=y
diff --git a/arch/blackfin/configs/SRV1_defconfig b/arch/blackfin/configs/SRV1_defconfig
new file mode 100644
index 000000000000..951ea0412576
--- /dev/null
+++ b/arch/blackfin/configs/SRV1_defconfig
@@ -0,0 +1,1290 @@
1#
2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.22.10
4# Fri Nov 2 20:50:23 2007
5#
6# CONFIG_MMU is not set
7# CONFIG_FPU is not set
8CONFIG_RWSEM_GENERIC_SPINLOCK=y
9# CONFIG_RWSEM_XCHGADD_ALGORITHM is not set
10CONFIG_BLACKFIN=y
11CONFIG_ZONE_DMA=y
12CONFIG_BFIN=y
13CONFIG_SEMAPHORE_SLEEPERS=y
14CONFIG_GENERIC_FIND_NEXT_BIT=y
15CONFIG_GENERIC_HWEIGHT=y
16CONFIG_GENERIC_HARDIRQS=y
17CONFIG_GENERIC_IRQ_PROBE=y
18# CONFIG_GENERIC_TIME is not set
19CONFIG_GENERIC_GPIO=y
20CONFIG_FORCE_MAX_ZONEORDER=14
21CONFIG_GENERIC_CALIBRATE_DELAY=y
22CONFIG_IRQCHIP_DEMUX_GPIO=y
23CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
24
25#
26# Code maturity level options
27#
28CONFIG_EXPERIMENTAL=y
29CONFIG_BROKEN_ON_SMP=y
30CONFIG_INIT_ENV_ARG_LIMIT=32
31
32#
33# General setup
34#
35CONFIG_LOCALVERSION=""
36CONFIG_LOCALVERSION_AUTO=y
37CONFIG_SYSVIPC=y
38# CONFIG_IPC_NS is not set
39CONFIG_SYSVIPC_SYSCTL=y
40# CONFIG_POSIX_MQUEUE is not set
41# CONFIG_BSD_PROCESS_ACCT is not set
42# CONFIG_TASKSTATS is not set
43# CONFIG_UTS_NS is not set
44# CONFIG_AUDIT is not set
45# CONFIG_IKCONFIG is not set
46CONFIG_LOG_BUF_SHIFT=14
47CONFIG_SYSFS_DEPRECATED=y
48# CONFIG_RELAY is not set
49CONFIG_BLK_DEV_INITRD=y
50CONFIG_INITRAMFS_SOURCE=""
51# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
52CONFIG_SYSCTL=y
53CONFIG_EMBEDDED=y
54CONFIG_UID16=y
55CONFIG_SYSCTL_SYSCALL=y
56CONFIG_KALLSYMS=y
57CONFIG_KALLSYMS_ALL=y
58# CONFIG_KALLSYMS_EXTRA_PASS is not set
59CONFIG_HOTPLUG=y
60CONFIG_PRINTK=y
61CONFIG_BUG=y
62CONFIG_ELF_CORE=y
63CONFIG_BASE_FULL=y
64CONFIG_FUTEX=y
65CONFIG_ANON_INODES=y
66CONFIG_EPOLL=y
67CONFIG_SIGNALFD=y
68CONFIG_EVENTFD=y
69CONFIG_VM_EVENT_COUNTERS=y
70CONFIG_BIG_ORDER_ALLOC_NOFAIL_MAGIC=3
71# CONFIG_NP2 is not set
72CONFIG_SLAB=y
73# CONFIG_SLUB is not set
74# CONFIG_SLOB is not set
75CONFIG_RT_MUTEXES=y
76CONFIG_TINY_SHMEM=y
77CONFIG_BASE_SMALL=0
78
79#
80# Loadable module support
81#
82CONFIG_MODULES=y
83CONFIG_MODULE_UNLOAD=y
84# CONFIG_MODULE_FORCE_UNLOAD is not set
85# CONFIG_MODVERSIONS is not set
86# CONFIG_MODULE_SRCVERSION_ALL is not set
87CONFIG_KMOD=y
88
89#
90# Block layer
91#
92CONFIG_BLOCK=y
93# CONFIG_LBD is not set
94# CONFIG_BLK_DEV_IO_TRACE is not set
95# CONFIG_LSF is not set
96
97#
98# IO Schedulers
99#
100CONFIG_IOSCHED_NOOP=y
101CONFIG_IOSCHED_AS=y
102# CONFIG_IOSCHED_DEADLINE is not set
103CONFIG_IOSCHED_CFQ=y
104CONFIG_DEFAULT_AS=y
105# CONFIG_DEFAULT_DEADLINE is not set
106# CONFIG_DEFAULT_CFQ is not set
107# CONFIG_DEFAULT_NOOP is not set
108CONFIG_DEFAULT_IOSCHED="anticipatory"
109# CONFIG_PREEMPT_NONE is not set
110CONFIG_PREEMPT_VOLUNTARY=y
111# CONFIG_PREEMPT is not set
112
113#
114# Blackfin Processor Options
115#
116
117#
118# Processor and Board Settings
119#
120# CONFIG_BF522 is not set
121# CONFIG_BF525 is not set
122# CONFIG_BF527 is not set
123# CONFIG_BF531 is not set
124# CONFIG_BF532 is not set
125# CONFIG_BF533 is not set
126# CONFIG_BF534 is not set
127# CONFIG_BF536 is not set
128CONFIG_BF537=y
129# CONFIG_BF542 is not set
130# CONFIG_BF544 is not set
131# CONFIG_BF548 is not set
132# CONFIG_BF549 is not set
133# CONFIG_BF561 is not set
134# CONFIG_BF_REV_0_0 is not set
135# CONFIG_BF_REV_0_1 is not set
136CONFIG_BF_REV_0_2=y
137# CONFIG_BF_REV_0_3 is not set
138# CONFIG_BF_REV_0_4 is not set
139# CONFIG_BF_REV_0_5 is not set
140# CONFIG_BF_REV_ANY is not set
141# CONFIG_BF_REV_NONE is not set
142CONFIG_BF53x=y
143CONFIG_BFIN_SINGLE_CORE=y
144# CONFIG_BFIN527_EZKIT is not set
145# CONFIG_BFIN533_EZKIT is not set
146# CONFIG_BFIN533_STAMP is not set
147# CONFIG_BFIN537_STAMP is not set
148# CONFIG_CAMSIG_MINOTAUR is not set
149# CONFIG_BFIN533_BLUETECHNIX_CM is not set
150# CONFIG_BFIN537_BLUETECHNIX_CM is not set
151# CONFIG_BFIN548_EZKIT is not set
152# CONFIG_BFIN561_BLUETECHNIX_CM is not set
153# CONFIG_BFIN561_EZKIT is not set
154# CONFIG_BFIN561_TEPLA is not set
155# CONFIG_PNAV10 is not set
156# CONFIG_VISTASCAN is not set
157# CONFIG_BFIN533_SR3K is not set
158CONFIG_GENERIC_BOARD=y
159CONFIG_MEM_GENERIC_BOARD=y
160CONFIG_IRQ_PLL_WAKEUP=7
161CONFIG_IRQ_RTC=8
162CONFIG_IRQ_PPI=8
163CONFIG_IRQ_SPORT0_RX=9
164CONFIG_IRQ_SPORT0_TX=9
165CONFIG_IRQ_SPORT1_RX=9
166CONFIG_IRQ_SPORT1_TX=9
167CONFIG_IRQ_TWI=10
168CONFIG_IRQ_SPI=10
169CONFIG_IRQ_UART0_RX=10
170CONFIG_IRQ_UART0_TX=10
171CONFIG_IRQ_UART1_RX=10
172CONFIG_IRQ_UART1_TX=10
173CONFIG_IRQ_MAC_RX=11
174CONFIG_IRQ_MAC_TX=11
175CONFIG_IRQ_TMR0=12
176CONFIG_IRQ_TMR1=12
177CONFIG_IRQ_TMR2=12
178CONFIG_IRQ_TMR3=12
179CONFIG_IRQ_TMR4=12
180CONFIG_IRQ_TMR5=12
181CONFIG_IRQ_TMR6=12
182CONFIG_IRQ_TMR7=12
183CONFIG_IRQ_PORTG_INTB=12
184CONFIG_IRQ_MEM_DMA0=13
185CONFIG_IRQ_MEM_DMA1=13
186CONFIG_IRQ_WATCH=13
187
188#
189# BF537 Specific Configuration
190#
191
192#
193# Interrupt Priority Assignment
194#
195
196#
197# Priority
198#
199CONFIG_IRQ_DMA_ERROR=7
200CONFIG_IRQ_ERROR=7
201CONFIG_IRQ_CAN_RX=11
202CONFIG_IRQ_CAN_TX=11
203CONFIG_IRQ_PROG_INTA=12
204
205#
206# Board customizations
207#
208# CONFIG_CMDLINE_BOOL is not set
209
210#
211# Clock/PLL Setup
212#
213CONFIG_CLKIN_HZ=22118400
214# CONFIG_BFIN_KERNEL_CLOCK is not set
215CONFIG_MAX_VCO_HZ=600000000
216CONFIG_MIN_VCO_HZ=50000000
217CONFIG_MAX_SCLK_HZ=133000000
218CONFIG_MIN_SCLK_HZ=27000000
219
220#
221# Kernel Timer/Scheduler
222#
223# CONFIG_HZ_100 is not set
224CONFIG_HZ_250=y
225# CONFIG_HZ_300 is not set
226# CONFIG_HZ_1000 is not set
227CONFIG_HZ=250
228
229#
230# Memory Setup
231#
232CONFIG_MAX_MEM_SIZE=32
233CONFIG_MEM_ADD_WIDTH=9
234CONFIG_BOOT_LOAD=0x400000
235CONFIG_BFIN_SCRATCH_REG_RETN=y
236# CONFIG_BFIN_SCRATCH_REG_RETE is not set
237# CONFIG_BFIN_SCRATCH_REG_CYCLES is not set
238
239#
240# Blackfin Kernel Optimizations
241#
242
243#
244# Memory Optimizations
245#
246CONFIG_I_ENTRY_L1=y
247CONFIG_EXCPT_IRQ_SYSC_L1=y
248CONFIG_DO_IRQ_L1=y
249CONFIG_CORE_TIMER_IRQ_L1=y
250CONFIG_IDLE_L1=y
251CONFIG_SCHEDULE_L1=y
252CONFIG_ARITHMETIC_OPS_L1=y
253CONFIG_ACCESS_OK_L1=y
254CONFIG_MEMSET_L1=y
255CONFIG_MEMCPY_L1=y
256CONFIG_SYS_BFIN_SPINLOCK_L1=y
257# CONFIG_IP_CHECKSUM_L1 is not set
258CONFIG_CACHELINE_ALIGNED_L1=y
259# CONFIG_SYSCALL_TAB_L1 is not set
260# CONFIG_CPLB_SWITCH_TAB_L1 is not set
261CONFIG_RAMKERNEL=y
262# CONFIG_ROMKERNEL is not set
263CONFIG_SELECT_MEMORY_MODEL=y
264CONFIG_FLATMEM_MANUAL=y
265# CONFIG_DISCONTIGMEM_MANUAL is not set
266# CONFIG_SPARSEMEM_MANUAL is not set
267CONFIG_FLATMEM=y
268CONFIG_FLAT_NODE_MEM_MAP=y
269# CONFIG_SPARSEMEM_STATIC is not set
270CONFIG_SPLIT_PTLOCK_CPUS=4
271# CONFIG_RESOURCES_64BIT is not set
272CONFIG_ZONE_DMA_FLAG=1
273CONFIG_LARGE_ALLOCS=y
274CONFIG_BFIN_DMA_5XX=y
275CONFIG_DMA_UNCACHED_2M=y
276# CONFIG_DMA_UNCACHED_1M is not set
277# CONFIG_DMA_UNCACHED_NONE is not set
278
279#
280# Cache Support
281#
282CONFIG_BFIN_ICACHE=y
283CONFIG_BFIN_DCACHE=y
284# CONFIG_BFIN_DCACHE_BANKA is not set
285# CONFIG_BFIN_ICACHE_LOCK is not set
286# CONFIG_BFIN_WB is not set
287CONFIG_BFIN_WT=y
288CONFIG_L1_MAX_PIECE=16
289
290#
291# Asynchonous Memory Configuration
292#
293
294#
295# EBIU_AMGCTL Global Control
296#
297CONFIG_C_AMCKEN=y
298CONFIG_C_CDPRIO=y
299# CONFIG_C_AMBEN is not set
300# CONFIG_C_AMBEN_B0 is not set
301# CONFIG_C_AMBEN_B0_B1 is not set
302# CONFIG_C_AMBEN_B0_B1_B2 is not set
303CONFIG_C_AMBEN_ALL=y
304
305#
306# EBIU_AMBCTL Control
307#
308CONFIG_BANK_0=0x7BB0
309CONFIG_BANK_1=0x7BB0
310CONFIG_BANK_2=0x7BB0
311CONFIG_BANK_3=0x99B3
312
313#
314# Bus options (PCI, PCMCIA, EISA, MCA, ISA)
315#
316# CONFIG_PCI is not set
317# CONFIG_ARCH_SUPPORTS_MSI is not set
318
319#
320# PCCARD (PCMCIA/CardBus) support
321#
322# CONFIG_PCCARD is not set
323
324#
325# Executable file formats
326#
327CONFIG_BINFMT_ELF_FDPIC=y
328CONFIG_BINFMT_FLAT=y
329CONFIG_BINFMT_ZFLAT=y
330# CONFIG_BINFMT_SHARED_FLAT is not set
331# CONFIG_BINFMT_MISC is not set
332
333#
334# Power management options
335#
336CONFIG_PM=y
337# CONFIG_PM_LEGACY is not set
338# CONFIG_PM_DEBUG is not set
339# CONFIG_PM_SYSFS_DEPRECATED is not set
340CONFIG_PM_WAKEUP_GPIO_BY_SIC_IWR=y
341# CONFIG_PM_WAKEUP_BY_GPIO is not set
342# CONFIG_PM_WAKEUP_GPIO_API is not set
343CONFIG_PM_WAKEUP_SIC_IWR=0x80000000
344
345#
346# CPU Frequency scaling
347#
348# CONFIG_CPU_FREQ is not set
349
350#
351# Networking
352#
353CONFIG_NET=y
354
355#
356# Networking options
357#
358CONFIG_PACKET=y
359# CONFIG_PACKET_MMAP is not set
360CONFIG_UNIX=y
361CONFIG_XFRM=y
362# CONFIG_XFRM_USER is not set
363# CONFIG_XFRM_SUB_POLICY is not set
364# CONFIG_XFRM_MIGRATE is not set
365# CONFIG_NET_KEY is not set
366CONFIG_INET=y
367# CONFIG_IP_MULTICAST is not set
368# CONFIG_IP_ADVANCED_ROUTER is not set
369CONFIG_IP_FIB_HASH=y
370CONFIG_IP_PNP=y
371# CONFIG_IP_PNP_DHCP is not set
372# CONFIG_IP_PNP_BOOTP is not set
373# CONFIG_IP_PNP_RARP is not set
374# CONFIG_NET_IPIP is not set
375# CONFIG_NET_IPGRE is not set
376# CONFIG_ARPD is not set
377CONFIG_SYN_COOKIES=y
378# CONFIG_INET_AH is not set
379# CONFIG_INET_ESP is not set
380# CONFIG_INET_IPCOMP is not set
381# CONFIG_INET_XFRM_TUNNEL is not set
382# CONFIG_INET_TUNNEL is not set
383CONFIG_INET_XFRM_MODE_TRANSPORT=y
384CONFIG_INET_XFRM_MODE_TUNNEL=y
385CONFIG_INET_XFRM_MODE_BEET=y
386CONFIG_INET_DIAG=y
387CONFIG_INET_TCP_DIAG=y
388# CONFIG_TCP_CONG_ADVANCED is not set
389CONFIG_TCP_CONG_CUBIC=y
390CONFIG_DEFAULT_TCP_CONG="cubic"
391# CONFIG_TCP_MD5SIG is not set
392# CONFIG_IPV6 is not set
393# CONFIG_INET6_XFRM_TUNNEL is not set
394# CONFIG_INET6_TUNNEL is not set
395# CONFIG_NETLABEL is not set
396# CONFIG_NETWORK_SECMARK is not set
397# CONFIG_NETFILTER is not set
398# CONFIG_IP_DCCP is not set
399# CONFIG_IP_SCTP is not set
400# CONFIG_TIPC is not set
401# CONFIG_ATM is not set
402# CONFIG_BRIDGE is not set
403# CONFIG_VLAN_8021Q is not set
404# CONFIG_DECNET is not set
405# CONFIG_LLC2 is not set
406# CONFIG_IPX is not set
407# CONFIG_ATALK is not set
408# CONFIG_X25 is not set
409# CONFIG_LAPB is not set
410# CONFIG_ECONET is not set
411# CONFIG_WAN_ROUTER is not set
412
413#
414# QoS and/or fair queueing
415#
416# CONFIG_NET_SCHED is not set
417
418#
419# Network testing
420#
421# CONFIG_NET_PKTGEN is not set
422# CONFIG_HAMRADIO is not set
423CONFIG_IRDA=m
424
425#
426# IrDA protocols
427#
428CONFIG_IRLAN=m
429CONFIG_IRCOMM=m
430# CONFIG_IRDA_ULTRA is not set
431
432#
433# IrDA options
434#
435CONFIG_IRDA_CACHE_LAST_LSAP=y
436# CONFIG_IRDA_FAST_RR is not set
437# CONFIG_IRDA_DEBUG is not set
438
439#
440# Infrared-port device drivers
441#
442
443#
444# SIR device drivers
445#
446CONFIG_IRTTY_SIR=m
447
448#
449# Dongle support
450#
451# CONFIG_DONGLE is not set
452
453#
454# Old SIR device drivers
455#
456# CONFIG_IRPORT_SIR is not set
457
458#
459# Old Serial dongle support
460#
461
462#
463# FIR device drivers
464#
465# CONFIG_BT is not set
466# CONFIG_AF_RXRPC is not set
467
468#
469# Wireless
470#
471# CONFIG_CFG80211 is not set
472# CONFIG_WIRELESS_EXT is not set
473# CONFIG_MAC80211 is not set
474# CONFIG_IEEE80211 is not set
475# CONFIG_RFKILL is not set
476
477#
478# Device Drivers
479#
480
481#
482# Generic Driver Options
483#
484CONFIG_STANDALONE=y
485CONFIG_PREVENT_FIRMWARE_BUILD=y
486# CONFIG_FW_LOADER is not set
487# CONFIG_DEBUG_DRIVER is not set
488# CONFIG_DEBUG_DEVRES is not set
489# CONFIG_SYS_HYPERVISOR is not set
490
491#
492# Connector - unified userspace <-> kernelspace linker
493#
494# CONFIG_CONNECTOR is not set
495CONFIG_MTD=y
496# CONFIG_MTD_DEBUG is not set
497# CONFIG_MTD_CONCAT is not set
498CONFIG_MTD_PARTITIONS=y
499# CONFIG_MTD_REDBOOT_PARTS is not set
500# CONFIG_MTD_CMDLINE_PARTS is not set
501
502#
503# User Modules And Translation Layers
504#
505CONFIG_MTD_CHAR=m
506CONFIG_MTD_BLKDEVS=y
507CONFIG_MTD_BLOCK=y
508# CONFIG_FTL is not set
509# CONFIG_NFTL is not set
510# CONFIG_INFTL is not set
511# CONFIG_RFD_FTL is not set
512# CONFIG_SSFDC is not set
513
514#
515# RAM/ROM/Flash chip drivers
516#
517# CONFIG_MTD_CFI is not set
518CONFIG_MTD_JEDECPROBE=m
519CONFIG_MTD_GEN_PROBE=m
520# CONFIG_MTD_CFI_ADV_OPTIONS is not set
521CONFIG_MTD_MAP_BANK_WIDTH_1=y
522CONFIG_MTD_MAP_BANK_WIDTH_2=y
523CONFIG_MTD_MAP_BANK_WIDTH_4=y
524# CONFIG_MTD_MAP_BANK_WIDTH_8 is not set
525# CONFIG_MTD_MAP_BANK_WIDTH_16 is not set
526# CONFIG_MTD_MAP_BANK_WIDTH_32 is not set
527CONFIG_MTD_CFI_I1=y
528CONFIG_MTD_CFI_I2=y
529# CONFIG_MTD_CFI_I4 is not set
530# CONFIG_MTD_CFI_I8 is not set
531# CONFIG_MTD_CFI_INTELEXT is not set
532# CONFIG_MTD_CFI_AMDSTD is not set
533# CONFIG_MTD_CFI_STAA is not set
534CONFIG_MTD_MW320D=m
535CONFIG_MTD_RAM=y
536CONFIG_MTD_ROM=m
537# CONFIG_MTD_ABSENT is not set
538
539#
540# Mapping drivers for chip access
541#
542CONFIG_MTD_COMPLEX_MAPPINGS=y
543# CONFIG_MTD_PHYSMAP is not set
544CONFIG_MTD_BF5xx=m
545CONFIG_BFIN_FLASH_SIZE=0x400000
546CONFIG_EBIU_FLASH_BASE=0x20000000
547CONFIG_MTD_UCLINUX=y
548# CONFIG_MTD_PLATRAM is not set
549
550#
551# Self-contained MTD device drivers
552#
553# CONFIG_MTD_DATAFLASH is not set
554# CONFIG_MTD_M25P80 is not set
555# CONFIG_MTD_SLRAM is not set
556# CONFIG_MTD_PHRAM is not set
557# CONFIG_MTD_MTDRAM is not set
558# CONFIG_MTD_BLOCK2MTD is not set
559
560#
561# Disk-On-Chip Device Drivers
562#
563# CONFIG_MTD_DOC2000 is not set
564# CONFIG_MTD_DOC2001 is not set
565# CONFIG_MTD_DOC2001PLUS is not set
566CONFIG_MTD_NAND=m
567# CONFIG_MTD_NAND_VERIFY_WRITE is not set
568# CONFIG_MTD_NAND_ECC_SMC is not set
569# CONFIG_MTD_NAND_MUSEUM_IDS is not set
570CONFIG_MTD_NAND_BFIN=m
571CONFIG_BFIN_NAND_BASE=0x20212000
572CONFIG_BFIN_NAND_CLE=2
573CONFIG_BFIN_NAND_ALE=1
574CONFIG_BFIN_NAND_READY=3
575CONFIG_MTD_NAND_IDS=m
576# CONFIG_MTD_NAND_DISKONCHIP is not set
577# CONFIG_MTD_NAND_NANDSIM is not set
578# CONFIG_MTD_NAND_PLATFORM is not set
579# CONFIG_MTD_ONENAND is not set
580
581#
582# UBI - Unsorted block images
583#
584# CONFIG_MTD_UBI is not set
585
586#
587# Parallel port support
588#
589# CONFIG_PARPORT is not set
590
591#
592# Plug and Play support
593#
594# CONFIG_PNPACPI is not set
595
596#
597# Block devices
598#
599# CONFIG_BLK_DEV_COW_COMMON is not set
600# CONFIG_BLK_DEV_LOOP is not set
601# CONFIG_BLK_DEV_NBD is not set
602CONFIG_BLK_DEV_RAM=y
603CONFIG_BLK_DEV_RAM_COUNT=16
604CONFIG_BLK_DEV_RAM_SIZE=4096
605CONFIG_BLK_DEV_RAM_BLOCKSIZE=1024
606# CONFIG_CDROM_PKTCDVD is not set
607# CONFIG_ATA_OVER_ETH is not set
608
609#
610# Misc devices
611#
612# CONFIG_IDE is not set
613
614#
615# SCSI device support
616#
617# CONFIG_RAID_ATTRS is not set
618# CONFIG_SCSI is not set
619# CONFIG_SCSI_NETLINK is not set
620# CONFIG_ATA is not set
621
622#
623# Multi-device support (RAID and LVM)
624#
625# CONFIG_MD is not set
626
627#
628# Network device support
629#
630CONFIG_NETDEVICES=y
631# CONFIG_DUMMY is not set
632# CONFIG_BONDING is not set
633# CONFIG_EQUALIZER is not set
634# CONFIG_TUN is not set
635
636#
637# Ethernet (10 or 100Mbit)
638#
639# CONFIG_NET_ETHERNET is not set
640# CONFIG_NETDEV_1000 is not set
641# CONFIG_NETDEV_10000 is not set
642
643#
644# Wireless LAN
645#
646# CONFIG_WLAN_PRE80211 is not set
647# CONFIG_WLAN_80211 is not set
648# CONFIG_WAN is not set
649# CONFIG_PPP is not set
650# CONFIG_SLIP is not set
651# CONFIG_SHAPER is not set
652# CONFIG_NETCONSOLE is not set
653# CONFIG_NETPOLL is not set
654# CONFIG_NET_POLL_CONTROLLER is not set
655
656#
657# ISDN subsystem
658#
659# CONFIG_ISDN is not set
660
661#
662# Telephony Support
663#
664# CONFIG_PHONE is not set
665
666#
667# Input device support
668#
669CONFIG_INPUT=y
670# CONFIG_INPUT_FF_MEMLESS is not set
671# CONFIG_INPUT_POLLDEV is not set
672
673#
674# Userland interfaces
675#
676# CONFIG_INPUT_MOUSEDEV is not set
677# CONFIG_INPUT_JOYDEV is not set
678# CONFIG_INPUT_TSDEV is not set
679CONFIG_INPUT_EVDEV=m
680# CONFIG_INPUT_EVBUG is not set
681
682#
683# Input Device Drivers
684#
685# CONFIG_INPUT_KEYBOARD is not set
686# CONFIG_INPUT_MOUSE is not set
687# CONFIG_INPUT_JOYSTICK is not set
688# CONFIG_INPUT_TABLET is not set
689# CONFIG_INPUT_TOUCHSCREEN is not set
690CONFIG_INPUT_MISC=y
691# CONFIG_INPUT_ATI_REMOTE is not set
692# CONFIG_INPUT_ATI_REMOTE2 is not set
693# CONFIG_INPUT_KEYSPAN_REMOTE is not set
694# CONFIG_INPUT_POWERMATE is not set
695# CONFIG_INPUT_YEALINK is not set
696CONFIG_INPUT_UINPUT=y
697# CONFIG_BF53X_PFBUTTONS is not set
698# CONFIG_TWI_KEYPAD is not set
699
700#
701# Hardware I/O ports
702#
703# CONFIG_SERIO is not set
704# CONFIG_GAMEPORT is not set
705
706#
707# Character devices
708#
709# CONFIG_AD9960 is not set
710# CONFIG_SPI_ADC_BF533 is not set
711CONFIG_BF5xx_PFLAGS=y
712# CONFIG_BF5xx_PFLAGS_PROC is not set
713# CONFIG_BF5xx_PPIFCD is not set
714# CONFIG_BF5xx_TIMERS is not set
715# CONFIG_BF5xx_PPI is not set
716# CONFIG_BFIN_SPORT is not set
717# CONFIG_BFIN_TIMER_LATENCY is not set
718# CONFIG_TWI_LCD is not set
719# CONFIG_AD5304 is not set
720# CONFIG_BF5xx_TEA5764 is not set
721# CONFIG_BF5xx_FBDMA is not set
722# CONFIG_VT is not set
723# CONFIG_SERIAL_NONSTANDARD is not set
724
725#
726# Serial drivers
727#
728# CONFIG_SERIAL_8250 is not set
729
730#
731# Non-8250 serial port support
732#
733CONFIG_SERIAL_BFIN=y
734CONFIG_SERIAL_BFIN_CONSOLE=y
735CONFIG_SERIAL_BFIN_DMA=y
736# CONFIG_SERIAL_BFIN_PIO is not set
737CONFIG_SERIAL_BFIN_UART0=y
738# CONFIG_BFIN_UART0_CTSRTS is not set
739# CONFIG_SERIAL_BFIN_UART1 is not set
740CONFIG_SERIAL_CORE=y
741CONFIG_SERIAL_CORE_CONSOLE=y
742# CONFIG_SERIAL_BFIN_SPORT is not set
743CONFIG_UNIX98_PTYS=y
744# CONFIG_LEGACY_PTYS is not set
745
746#
747# CAN, the car bus and industrial fieldbus
748#
749# CONFIG_CAN4LINUX is not set
750
751#
752# IPMI
753#
754# CONFIG_IPMI_HANDLER is not set
755CONFIG_WATCHDOG=y
756# CONFIG_WATCHDOG_NOWAYOUT is not set
757
758#
759# Watchdog Device Drivers
760#
761# CONFIG_SOFT_WATCHDOG is not set
762CONFIG_BFIN_WDT=y
763CONFIG_HW_RANDOM=m
764# CONFIG_GEN_RTC is not set
765CONFIG_BLACKFIN_DPMC=y
766# CONFIG_R3964 is not set
767# CONFIG_RAW_DRIVER is not set
768
769#
770# TPM devices
771#
772# CONFIG_TCG_TPM is not set
773CONFIG_I2C=y
774CONFIG_I2C_BOARDINFO=y
775CONFIG_I2C_CHARDEV=y
776
777#
778# I2C Algorithms
779#
780# CONFIG_I2C_ALGOBIT is not set
781# CONFIG_I2C_ALGOPCF is not set
782# CONFIG_I2C_ALGOPCA is not set
783
784#
785# I2C Hardware Bus support
786#
787# CONFIG_I2C_BLACKFIN_GPIO is not set
788CONFIG_I2C_BLACKFIN_TWI=y
789CONFIG_I2C_BLACKFIN_TWI_CLK_KHZ=50
790# CONFIG_I2C_GPIO is not set
791# CONFIG_I2C_OCORES is not set
792# CONFIG_I2C_PARPORT_LIGHT is not set
793# CONFIG_I2C_SIMTEC is not set
794# CONFIG_I2C_STUB is not set
795
796#
797# Miscellaneous I2C Chip support
798#
799# CONFIG_SENSORS_DS1337 is not set
800# CONFIG_SENSORS_DS1374 is not set
801# CONFIG_SENSORS_AD5252 is not set
802# CONFIG_SENSORS_EEPROM is not set
803# CONFIG_SENSORS_PCF8574 is not set
804# CONFIG_SENSORS_PCF8575 is not set
805# CONFIG_SENSORS_PCA9543 is not set
806# CONFIG_SENSORS_PCA9539 is not set
807# CONFIG_SENSORS_PCF8591 is not set
808# CONFIG_SENSORS_MAX6875 is not set
809# CONFIG_I2C_DEBUG_CORE is not set
810# CONFIG_I2C_DEBUG_ALGO is not set
811# CONFIG_I2C_DEBUG_BUS is not set
812# CONFIG_I2C_DEBUG_CHIP is not set
813
814#
815# SPI support
816#
817CONFIG_SPI=y
818# CONFIG_SPI_DEBUG is not set
819CONFIG_SPI_MASTER=y
820
821#
822# SPI Master Controller Drivers
823#
824CONFIG_SPI_BFIN=y
825# CONFIG_SPI_BITBANG is not set
826
827#
828# SPI Protocol Masters
829#
830CONFIG_SPI_AT25=m
831# CONFIG_SPI_SPIDEV is not set
832
833#
834# Dallas's 1-wire bus
835#
836# CONFIG_W1 is not set
837CONFIG_HWMON=m
838# CONFIG_HWMON_VID is not set
839# CONFIG_SENSORS_ABITUGURU is not set
840# CONFIG_SENSORS_AD7418 is not set
841# CONFIG_SENSORS_ADM1021 is not set
842# CONFIG_SENSORS_ADM1025 is not set
843# CONFIG_SENSORS_ADM1026 is not set
844# CONFIG_SENSORS_ADM1029 is not set
845# CONFIG_SENSORS_ADM1031 is not set
846# CONFIG_SENSORS_ADM9240 is not set
847# CONFIG_SENSORS_ASB100 is not set
848# CONFIG_SENSORS_ATXP1 is not set
849# CONFIG_SENSORS_DS1621 is not set
850# CONFIG_SENSORS_F71805F is not set
851# CONFIG_SENSORS_FSCHER is not set
852# CONFIG_SENSORS_FSCPOS is not set
853# CONFIG_SENSORS_GL518SM is not set
854# CONFIG_SENSORS_GL520SM is not set
855# CONFIG_SENSORS_IT87 is not set
856# CONFIG_SENSORS_LM63 is not set
857# CONFIG_SENSORS_LM70 is not set
858# CONFIG_SENSORS_LM75 is not set
859# CONFIG_SENSORS_LM77 is not set
860# CONFIG_SENSORS_LM78 is not set
861# CONFIG_SENSORS_LM80 is not set
862# CONFIG_SENSORS_LM83 is not set
863# CONFIG_SENSORS_LM85 is not set
864# CONFIG_SENSORS_LM87 is not set
865# CONFIG_SENSORS_LM90 is not set
866# CONFIG_SENSORS_LM92 is not set
867# CONFIG_SENSORS_MAX1619 is not set
868# CONFIG_SENSORS_MAX6650 is not set
869# CONFIG_SENSORS_PC87360 is not set
870# CONFIG_SENSORS_PC87427 is not set
871# CONFIG_SENSORS_SMSC47M1 is not set
872# CONFIG_SENSORS_SMSC47M192 is not set
873# CONFIG_SENSORS_SMSC47B397 is not set
874# CONFIG_SENSORS_VT1211 is not set
875# CONFIG_SENSORS_W83781D is not set
876# CONFIG_SENSORS_W83791D is not set
877# CONFIG_SENSORS_W83792D is not set
878# CONFIG_SENSORS_W83793 is not set
879# CONFIG_SENSORS_W83L785TS is not set
880# CONFIG_SENSORS_W83627HF is not set
881# CONFIG_SENSORS_W83627EHF is not set
882# CONFIG_HWMON_DEBUG_CHIP is not set
883
884#
885# Multifunction device drivers
886#
887# CONFIG_MFD_SM501 is not set
888
889#
890# Multimedia devices
891#
892CONFIG_VIDEO_DEV=y
893# CONFIG_VIDEO_V4L1 is not set
894CONFIG_VIDEO_V4L1_COMPAT=y
895CONFIG_VIDEO_V4L2=y
896CONFIG_VIDEO_CAPTURE_DRIVERS=y
897# CONFIG_VIDEO_ADV_DEBUG is not set
898# CONFIG_VIDEO_HELPER_CHIPS_AUTO is not set
899
900#
901# Encoders/decoders and other helper chips
902#
903
904#
905# Audio decoders
906#
907# CONFIG_VIDEO_TDA9840 is not set
908# CONFIG_VIDEO_TEA6415C is not set
909# CONFIG_VIDEO_TEA6420 is not set
910# CONFIG_VIDEO_MSP3400 is not set
911# CONFIG_VIDEO_CS53L32A is not set
912# CONFIG_VIDEO_TLV320AIC23B is not set
913# CONFIG_VIDEO_WM8775 is not set
914# CONFIG_VIDEO_WM8739 is not set
915
916#
917# Video decoders
918#
919# CONFIG_VIDEO_OV7670 is not set
920# CONFIG_VIDEO_SAA711X is not set
921# CONFIG_VIDEO_TVP5150 is not set
922
923#
924# Video and audio decoders
925#
926# CONFIG_VIDEO_CX25840 is not set
927
928#
929# MPEG video encoders
930#
931# CONFIG_VIDEO_CX2341X is not set
932
933#
934# Video encoders
935#
936# CONFIG_VIDEO_SAA7127 is not set
937
938#
939# Video improvement chips
940#
941# CONFIG_VIDEO_UPD64031A is not set
942# CONFIG_VIDEO_UPD64083 is not set
943# CONFIG_VIDEO_SAA5246A is not set
944# CONFIG_VIDEO_SAA5249 is not set
945# CONFIG_VIDEO_PPI_GENERIC is not set
946CONFIG_VIDEO_BLACKFIN_CAM=m
947# CONFIG_VIDEO_BLACKFIN_MT9M001 is not set
948
949#
950# CMOS Camera Sensor Selection
951#
952# CONFIG_MT9V022 is not set
953# CONFIG_MT9M001 is not set
954# CONFIG_VS6524 is not set
955# CONFIG_VS6624 is not set
956CONFIG_OV9655=y
957# CONFIG_RADIO_ADAPTERS is not set
958# CONFIG_DVB_CORE is not set
959# CONFIG_DAB is not set
960
961#
962# Graphics support
963#
964# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
965
966#
967# Display device support
968#
969# CONFIG_DISPLAY_SUPPORT is not set
970# CONFIG_VGASTATE is not set
971# CONFIG_FB is not set
972
973#
974# Sound
975#
976# CONFIG_SOUND is not set
977
978#
979# HID Devices
980#
981# CONFIG_HID is not set
982
983#
984# USB support
985#
986CONFIG_USB_ARCH_HAS_HCD=y
987# CONFIG_USB_ARCH_HAS_OHCI is not set
988# CONFIG_USB_ARCH_HAS_EHCI is not set
989# CONFIG_USB is not set
990
991#
992# Enable Host or Gadget support to see Inventra options
993#
994
995#
996# NOTE: USB_STORAGE enables SCSI, and 'SCSI disk support'
997#
998
999#
1000# USB Gadget Support
1001#
1002# CONFIG_USB_GADGET is not set
1003# CONFIG_MMC is not set
1004
1005#
1006# LED devices
1007#
1008# CONFIG_NEW_LEDS is not set
1009
1010#
1011# LED drivers
1012#
1013
1014#
1015# LED Triggers
1016#
1017
1018#
1019# InfiniBand support
1020#
1021
1022#
1023# EDAC - error detection and reporting (RAS) (EXPERIMENTAL)
1024#
1025
1026#
1027# Real Time Clock
1028#
1029# CONFIG_RTC_CLASS is not set
1030
1031#
1032# DMA Engine support
1033#
1034# CONFIG_DMA_ENGINE is not set
1035
1036#
1037# DMA Clients
1038#
1039
1040#
1041# DMA Devices
1042#
1043
1044#
1045# PBX support
1046#
1047# CONFIG_PBX is not set
1048
1049#
1050# File systems
1051#
1052CONFIG_EXT2_FS=y
1053CONFIG_EXT2_FS_XATTR=y
1054# CONFIG_EXT2_FS_POSIX_ACL is not set
1055# CONFIG_EXT2_FS_SECURITY is not set
1056# CONFIG_EXT3_FS is not set
1057# CONFIG_EXT4DEV_FS is not set
1058CONFIG_FS_MBCACHE=y
1059# CONFIG_REISERFS_FS is not set
1060# CONFIG_JFS_FS is not set
1061# CONFIG_FS_POSIX_ACL is not set
1062# CONFIG_XFS_FS is not set
1063# CONFIG_GFS2_FS is not set
1064# CONFIG_OCFS2_FS is not set
1065# CONFIG_MINIX_FS is not set
1066# CONFIG_ROMFS_FS is not set
1067CONFIG_INOTIFY=y
1068CONFIG_INOTIFY_USER=y
1069# CONFIG_QUOTA is not set
1070CONFIG_DNOTIFY=y
1071# CONFIG_AUTOFS_FS is not set
1072# CONFIG_AUTOFS4_FS is not set
1073# CONFIG_FUSE_FS is not set
1074
1075#
1076# CD-ROM/DVD Filesystems
1077#
1078# CONFIG_ISO9660_FS is not set
1079# CONFIG_UDF_FS is not set
1080
1081#
1082# DOS/FAT/NT Filesystems
1083#
1084# CONFIG_MSDOS_FS is not set
1085# CONFIG_VFAT_FS is not set
1086# CONFIG_NTFS_FS is not set
1087
1088#
1089# Pseudo filesystems
1090#
1091CONFIG_PROC_FS=y
1092CONFIG_PROC_SYSCTL=y
1093CONFIG_SYSFS=y
1094# CONFIG_TMPFS is not set
1095# CONFIG_HUGETLB_PAGE is not set
1096CONFIG_RAMFS=y
1097# CONFIG_CONFIGFS_FS is not set
1098
1099#
1100# Miscellaneous filesystems
1101#
1102# CONFIG_ADFS_FS is not set
1103# CONFIG_AFFS_FS is not set
1104# CONFIG_HFS_FS is not set
1105# CONFIG_HFSPLUS_FS is not set
1106# CONFIG_BEFS_FS is not set
1107# CONFIG_BFS_FS is not set
1108# CONFIG_EFS_FS is not set
1109CONFIG_YAFFS_FS=m
1110CONFIG_YAFFS_YAFFS1=y
1111# CONFIG_YAFFS_DOES_ECC is not set
1112CONFIG_YAFFS_YAFFS2=y
1113CONFIG_YAFFS_AUTO_YAFFS2=y
1114# CONFIG_YAFFS_DISABLE_LAZY_LOAD is not set
1115CONFIG_YAFFS_CHECKPOINT_RESERVED_BLOCKS=10
1116# CONFIG_YAFFS_DISABLE_WIDE_TNODES is not set
1117# CONFIG_YAFFS_ALWAYS_CHECK_CHUNK_ERASED is not set
1118CONFIG_YAFFS_SHORT_NAMES_IN_RAM=y
1119CONFIG_JFFS2_FS=m
1120CONFIG_JFFS2_FS_DEBUG=0
1121CONFIG_JFFS2_FS_WRITEBUFFER=y
1122# CONFIG_JFFS2_SUMMARY is not set
1123# CONFIG_JFFS2_FS_XATTR is not set
1124# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set
1125CONFIG_JFFS2_ZLIB=y
1126CONFIG_JFFS2_RTIME=y
1127# CONFIG_JFFS2_RUBIN is not set
1128# CONFIG_CRAMFS is not set
1129# CONFIG_VXFS_FS is not set
1130# CONFIG_HPFS_FS is not set
1131# CONFIG_QNX4FS_FS is not set
1132# CONFIG_SYSV_FS is not set
1133# CONFIG_UFS_FS is not set
1134
1135#
1136# Network File Systems
1137#
1138CONFIG_NFS_FS=m
1139CONFIG_NFS_V3=y
1140# CONFIG_NFS_V3_ACL is not set
1141# CONFIG_NFS_V4 is not set
1142# CONFIG_NFS_DIRECTIO is not set
1143# CONFIG_NFSD is not set
1144CONFIG_LOCKD=m
1145CONFIG_LOCKD_V4=y
1146CONFIG_NFS_COMMON=y
1147CONFIG_SUNRPC=m
1148# CONFIG_SUNRPC_BIND34 is not set
1149# CONFIG_RPCSEC_GSS_KRB5 is not set
1150# CONFIG_RPCSEC_GSS_SPKM3 is not set
1151CONFIG_SMB_FS=m
1152# CONFIG_SMB_NLS_DEFAULT is not set
1153# CONFIG_CIFS is not set
1154# CONFIG_NCP_FS is not set
1155# CONFIG_CODA_FS is not set
1156# CONFIG_AFS_FS is not set
1157# CONFIG_9P_FS is not set
1158
1159#
1160# Partition Types
1161#
1162# CONFIG_PARTITION_ADVANCED is not set
1163CONFIG_MSDOS_PARTITION=y
1164
1165#
1166# Native Language Support
1167#
1168CONFIG_NLS=m
1169CONFIG_NLS_DEFAULT="iso8859-1"
1170# CONFIG_NLS_CODEPAGE_437 is not set
1171# CONFIG_NLS_CODEPAGE_737 is not set
1172# CONFIG_NLS_CODEPAGE_775 is not set
1173# CONFIG_NLS_CODEPAGE_850 is not set
1174# CONFIG_NLS_CODEPAGE_852 is not set
1175# CONFIG_NLS_CODEPAGE_855 is not set
1176# CONFIG_NLS_CODEPAGE_857 is not set
1177# CONFIG_NLS_CODEPAGE_860 is not set
1178# CONFIG_NLS_CODEPAGE_861 is not set
1179# CONFIG_NLS_CODEPAGE_862 is not set
1180# CONFIG_NLS_CODEPAGE_863 is not set
1181# CONFIG_NLS_CODEPAGE_864 is not set
1182# CONFIG_NLS_CODEPAGE_865 is not set
1183# CONFIG_NLS_CODEPAGE_866 is not set
1184# CONFIG_NLS_CODEPAGE_869 is not set
1185# CONFIG_NLS_CODEPAGE_936 is not set
1186# CONFIG_NLS_CODEPAGE_950 is not set
1187# CONFIG_NLS_CODEPAGE_932 is not set
1188# CONFIG_NLS_CODEPAGE_949 is not set
1189# CONFIG_NLS_CODEPAGE_874 is not set
1190# CONFIG_NLS_ISO8859_8 is not set
1191# CONFIG_NLS_CODEPAGE_1250 is not set
1192# CONFIG_NLS_CODEPAGE_1251 is not set
1193# CONFIG_NLS_ASCII is not set
1194# CONFIG_NLS_ISO8859_1 is not set
1195# CONFIG_NLS_ISO8859_2 is not set
1196# CONFIG_NLS_ISO8859_3 is not set
1197# CONFIG_NLS_ISO8859_4 is not set
1198# CONFIG_NLS_ISO8859_5 is not set
1199# CONFIG_NLS_ISO8859_6 is not set
1200# CONFIG_NLS_ISO8859_7 is not set
1201# CONFIG_NLS_ISO8859_9 is not set
1202# CONFIG_NLS_ISO8859_13 is not set
1203# CONFIG_NLS_ISO8859_14 is not set
1204# CONFIG_NLS_ISO8859_15 is not set
1205# CONFIG_NLS_KOI8_R is not set
1206# CONFIG_NLS_KOI8_U is not set
1207# CONFIG_NLS_UTF8 is not set
1208
1209#
1210# Distributed Lock Manager
1211#
1212# CONFIG_DLM is not set
1213
1214#
1215# Profiling support
1216#
1217# CONFIG_PROFILING is not set
1218
1219#
1220# Kernel hacking
1221#
1222# CONFIG_PRINTK_TIME is not set
1223CONFIG_ENABLE_MUST_CHECK=y
1224# CONFIG_MAGIC_SYSRQ is not set
1225# CONFIG_UNUSED_SYMBOLS is not set
1226# CONFIG_DEBUG_FS is not set
1227# CONFIG_HEADERS_CHECK is not set
1228CONFIG_DEBUG_KERNEL=y
1229# CONFIG_DEBUG_SHIRQ is not set
1230CONFIG_DETECT_SOFTLOCKUP=y
1231# CONFIG_SCHEDSTATS is not set
1232# CONFIG_TIMER_STATS is not set
1233# CONFIG_DEBUG_SLAB is not set
1234# CONFIG_DEBUG_RT_MUTEXES is not set
1235# CONFIG_RT_MUTEX_TESTER is not set
1236# CONFIG_DEBUG_SPINLOCK is not set
1237# CONFIG_DEBUG_MUTEXES is not set
1238# CONFIG_DEBUG_SPINLOCK_SLEEP is not set
1239# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
1240# CONFIG_DEBUG_KOBJECT is not set
1241# CONFIG_DEBUG_BUGVERBOSE is not set
1242CONFIG_DEBUG_INFO=y
1243# CONFIG_DEBUG_VM is not set
1244# CONFIG_DEBUG_LIST is not set
1245# CONFIG_FRAME_POINTER is not set
1246# CONFIG_FORCED_INLINING is not set
1247# CONFIG_RCU_TORTURE_TEST is not set
1248# CONFIG_FAULT_INJECTION is not set
1249# CONFIG_DEBUG_MMRS is not set
1250# CONFIG_DEBUG_HWERR is not set
1251CONFIG_DEBUG_HUNT_FOR_ZERO=y
1252CONFIG_DEBUG_BFIN_HWTRACE_ON=y
1253CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_OFF=y
1254# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_ONE is not set
1255# CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION_TWO is not set
1256CONFIG_DEBUG_BFIN_HWTRACE_COMPRESSION=0
1257# CONFIG_DEBUG_BFIN_HWTRACE_EXPAND is not set
1258# CONFIG_DEBUG_BFIN_NO_KERN_HWTRACE is not set
1259# CONFIG_EARLY_PRINTK is not set
1260CONFIG_CPLB_INFO=y
1261CONFIG_ACCESS_CHECK=y
1262
1263#
1264# Security options
1265#
1266# CONFIG_KEYS is not set
1267CONFIG_SECURITY=y
1268# CONFIG_SECURITY_NETWORK is not set
1269CONFIG_SECURITY_CAPABILITIES=y
1270
1271#
1272# Cryptographic options
1273#
1274# CONFIG_CRYPTO is not set
1275
1276#
1277# Library routines
1278#
1279CONFIG_BITREVERSE=y
1280CONFIG_CRC_CCITT=m
1281# CONFIG_CRC16 is not set
1282# CONFIG_CRC_ITU_T is not set
1283CONFIG_CRC32=y
1284# CONFIG_LIBCRC32C is not set
1285CONFIG_ZLIB_INFLATE=y
1286CONFIG_ZLIB_DEFLATE=m
1287CONFIG_PLIST=y
1288CONFIG_HAS_IOMEM=y
1289CONFIG_HAS_IOPORT=y
1290CONFIG_HAS_DMA=y
diff --git a/arch/blackfin/kernel/Makefile b/arch/blackfin/kernel/Makefile
index 318b9b692a48..6140cd69c782 100644
--- a/arch/blackfin/kernel/Makefile
+++ b/arch/blackfin/kernel/Makefile
@@ -6,9 +6,15 @@ extra-y := init_task.o vmlinux.lds
6 6
7obj-y := \ 7obj-y := \
8 entry.o process.o bfin_ksyms.o ptrace.o setup.o signal.o \ 8 entry.o process.o bfin_ksyms.o ptrace.o setup.o signal.o \
9 sys_bfin.o time.o traps.o irqchip.o dma-mapping.o flat.o \ 9 sys_bfin.o traps.o irqchip.o dma-mapping.o flat.o \
10 fixed_code.o reboot.o bfin_gpio.o 10 fixed_code.o reboot.o bfin_gpio.o
11 11
12ifeq ($(CONFIG_GENERIC_CLOCKEVENTS),y)
13 obj-y += time-ts.o
14else
15 obj-y += time.o
16endif
17
12obj-$(CONFIG_BFIN_GPTIMERS) += gptimers.o 18obj-$(CONFIG_BFIN_GPTIMERS) += gptimers.o
13obj-$(CONFIG_MODULES) += module.o 19obj-$(CONFIG_MODULES) += module.o
14obj-$(CONFIG_BFIN_DMA_5XX) += bfin_dma_5xx.o 20obj-$(CONFIG_BFIN_DMA_5XX) += bfin_dma_5xx.o
diff --git a/arch/blackfin/kernel/bfin_dma_5xx.c b/arch/blackfin/kernel/bfin_dma_5xx.c
index 8fd5d22cec34..fd5448d6107c 100644
--- a/arch/blackfin/kernel/bfin_dma_5xx.c
+++ b/arch/blackfin/kernel/bfin_dma_5xx.c
@@ -67,7 +67,7 @@ static int __init blackfin_dma_init(void)
67 67
68 for (i = 0; i < MAX_BLACKFIN_DMA_CHANNEL; i++) { 68 for (i = 0; i < MAX_BLACKFIN_DMA_CHANNEL; i++) {
69 dma_ch[i].chan_status = DMA_CHANNEL_FREE; 69 dma_ch[i].chan_status = DMA_CHANNEL_FREE;
70 dma_ch[i].regs = base_addr[i]; 70 dma_ch[i].regs = dma_io_base_addr[i];
71 mutex_init(&(dma_ch[i].dmalock)); 71 mutex_init(&(dma_ch[i].dmalock));
72 } 72 }
73 /* Mark MEMDMA Channel 0 as requested since we're using it internally */ 73 /* Mark MEMDMA Channel 0 as requested since we're using it internally */
@@ -106,12 +106,15 @@ int request_dma(unsigned int channel, char *device_id)
106 106
107#ifdef CONFIG_BF54x 107#ifdef CONFIG_BF54x
108 if (channel >= CH_UART2_RX && channel <= CH_UART3_TX) { 108 if (channel >= CH_UART2_RX && channel <= CH_UART3_TX) {
109 if (strncmp(device_id, "BFIN_UART", 9) == 0) 109 if (strncmp(device_id, "BFIN_UART", 9) == 0) {
110 dma_ch[channel].regs->peripheral_map &= 0x0FFF;
110 dma_ch[channel].regs->peripheral_map |= 111 dma_ch[channel].regs->peripheral_map |=
111 (channel - CH_UART2_RX + 0xC); 112 ((channel - CH_UART2_RX + 0xC)<<12);
112 else 113 } else {
114 dma_ch[channel].regs->peripheral_map &= 0x0FFF;
113 dma_ch[channel].regs->peripheral_map |= 115 dma_ch[channel].regs->peripheral_map |=
114 (channel - CH_UART2_RX + 0x6); 116 ((channel - CH_UART2_RX + 0x6)<<12);
117 }
115 } 118 }
116#endif 119#endif
117 120
diff --git a/arch/blackfin/kernel/bfin_gpio.c b/arch/blackfin/kernel/bfin_gpio.c
index 08788f7bbfba..7e8eaf4a31bb 100644
--- a/arch/blackfin/kernel/bfin_gpio.c
+++ b/arch/blackfin/kernel/bfin_gpio.c
@@ -95,14 +95,14 @@ enum {
95 AWA_data_clear = SYSCR, 95 AWA_data_clear = SYSCR,
96 AWA_data_set = SYSCR, 96 AWA_data_set = SYSCR,
97 AWA_toggle = SYSCR, 97 AWA_toggle = SYSCR,
98 AWA_maska = UART_SCR, 98 AWA_maska = BFIN_UART_SCR,
99 AWA_maska_clear = UART_SCR, 99 AWA_maska_clear = BFIN_UART_SCR,
100 AWA_maska_set = UART_SCR, 100 AWA_maska_set = BFIN_UART_SCR,
101 AWA_maska_toggle = UART_SCR, 101 AWA_maska_toggle = BFIN_UART_SCR,
102 AWA_maskb = UART_GCTL, 102 AWA_maskb = BFIN_UART_GCTL,
103 AWA_maskb_clear = UART_GCTL, 103 AWA_maskb_clear = BFIN_UART_GCTL,
104 AWA_maskb_set = UART_GCTL, 104 AWA_maskb_set = BFIN_UART_GCTL,
105 AWA_maskb_toggle = UART_GCTL, 105 AWA_maskb_toggle = BFIN_UART_GCTL,
106 AWA_dir = SPORT1_STAT, 106 AWA_dir = SPORT1_STAT,
107 AWA_polar = SPORT1_STAT, 107 AWA_polar = SPORT1_STAT,
108 AWA_edge = SPORT1_STAT, 108 AWA_edge = SPORT1_STAT,
@@ -348,11 +348,10 @@ static void portmux_setup(unsigned short per, unsigned short function)
348 offset = port_mux_lut[y].offset; 348 offset = port_mux_lut[y].offset;
349 muxreg = bfin_read_PORT_MUX(); 349 muxreg = bfin_read_PORT_MUX();
350 350
351 if (offset != 1) { 351 if (offset != 1)
352 muxreg &= ~(1 << offset); 352 muxreg &= ~(1 << offset);
353 } else { 353 else
354 muxreg &= ~(3 << 1); 354 muxreg &= ~(3 << 1);
355 }
356 355
357 muxreg |= (function << offset); 356 muxreg |= (function << offset);
358 bfin_write_PORT_MUX(muxreg); 357 bfin_write_PORT_MUX(muxreg);
@@ -396,39 +395,11 @@ inline void portmux_setup(unsigned short portno, unsigned short function)
396# define portmux_setup(...) do { } while (0) 395# define portmux_setup(...) do { } while (0)
397#endif 396#endif
398 397
399#ifndef BF548_FAMILY
400static void default_gpio(unsigned gpio)
401{
402 unsigned short bank, bitmask;
403 unsigned long flags;
404
405 bank = gpio_bank(gpio);
406 bitmask = gpio_bit(gpio);
407
408 local_irq_save(flags);
409
410 gpio_bankb[bank]->maska_clear = bitmask;
411 gpio_bankb[bank]->maskb_clear = bitmask;
412 SSYNC();
413 gpio_bankb[bank]->inen &= ~bitmask;
414 gpio_bankb[bank]->dir &= ~bitmask;
415 gpio_bankb[bank]->polar &= ~bitmask;
416 gpio_bankb[bank]->both &= ~bitmask;
417 gpio_bankb[bank]->edge &= ~bitmask;
418 AWA_DUMMY_READ(edge);
419 local_irq_restore(flags);
420}
421#else
422# define default_gpio(...) do { } while (0)
423#endif
424
425static int __init bfin_gpio_init(void) 398static int __init bfin_gpio_init(void)
426{ 399{
427
428 printk(KERN_INFO "Blackfin GPIO Controller\n"); 400 printk(KERN_INFO "Blackfin GPIO Controller\n");
429 401
430 return 0; 402 return 0;
431
432} 403}
433arch_initcall(bfin_gpio_init); 404arch_initcall(bfin_gpio_init);
434 405
@@ -821,10 +792,10 @@ int peripheral_request(unsigned short per, const char *label)
821 local_irq_save(flags); 792 local_irq_save(flags);
822 793
823 if (unlikely(reserved_gpio_map[gpio_bank(ident)] & gpio_bit(ident))) { 794 if (unlikely(reserved_gpio_map[gpio_bank(ident)] & gpio_bit(ident))) {
795 dump_stack();
824 printk(KERN_ERR 796 printk(KERN_ERR
825 "%s: Peripheral %d is already reserved as GPIO by %s !\n", 797 "%s: Peripheral %d is already reserved as GPIO by %s !\n",
826 __FUNCTION__, ident, get_label(ident)); 798 __func__, ident, get_label(ident));
827 dump_stack();
828 local_irq_restore(flags); 799 local_irq_restore(flags);
829 return -EBUSY; 800 return -EBUSY;
830 } 801 }
@@ -833,31 +804,31 @@ int peripheral_request(unsigned short per, const char *label)
833 804
834 u16 funct = get_portmux(ident); 805 u16 funct = get_portmux(ident);
835 806
836 /* 807 /*
837 * Pin functions like AMC address strobes my 808 * Pin functions like AMC address strobes my
838 * be requested and used by several drivers 809 * be requested and used by several drivers
839 */ 810 */
840 811
841 if (!((per & P_MAYSHARE) && (funct == P_FUNCT2MUX(per)))) { 812 if (!((per & P_MAYSHARE) && (funct == P_FUNCT2MUX(per)))) {
842 813
843 /* 814 /*
844 * Allow that the identical pin function can 815 * Allow that the identical pin function can
845 * be requested from the same driver twice 816 * be requested from the same driver twice
846 */ 817 */
847 818
848 if (cmp_label(ident, label) == 0) 819 if (cmp_label(ident, label) == 0)
849 goto anyway; 820 goto anyway;
850 821
822 dump_stack();
851 printk(KERN_ERR 823 printk(KERN_ERR
852 "%s: Peripheral %d function %d is already reserved by %s !\n", 824 "%s: Peripheral %d function %d is already reserved by %s !\n",
853 __FUNCTION__, ident, P_FUNCT2MUX(per), get_label(ident)); 825 __func__, ident, P_FUNCT2MUX(per), get_label(ident));
854 dump_stack();
855 local_irq_restore(flags); 826 local_irq_restore(flags);
856 return -EBUSY; 827 return -EBUSY;
857 } 828 }
858 } 829 }
859 830
860anyway: 831 anyway:
861 reserved_peri_map[gpio_bank(ident)] |= gpio_bit(ident); 832 reserved_peri_map[gpio_bank(ident)] |= gpio_bit(ident);
862 833
863 portmux_setup(ident, P_FUNCT2MUX(per)); 834 portmux_setup(ident, P_FUNCT2MUX(per));
@@ -890,47 +861,47 @@ int peripheral_request(unsigned short per, const char *label)
890 861
891 if (!check_gpio(ident)) { 862 if (!check_gpio(ident)) {
892 863
893 if (unlikely(reserved_gpio_map[gpio_bank(ident)] & gpio_bit(ident))) { 864 if (unlikely(reserved_gpio_map[gpio_bank(ident)] & gpio_bit(ident))) {
894 printk(KERN_ERR 865 dump_stack();
895 "%s: Peripheral %d is already reserved as GPIO by %s !\n", 866 printk(KERN_ERR
896 __FUNCTION__, ident, get_label(ident)); 867 "%s: Peripheral %d is already reserved as GPIO by %s !\n",
897 dump_stack(); 868 __func__, ident, get_label(ident));
898 local_irq_restore(flags); 869 local_irq_restore(flags);
899 return -EBUSY; 870 return -EBUSY;
900 } 871 }
901 872
902 } 873 }
903 874
904 if (unlikely(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident))) { 875 if (unlikely(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident))) {
905 876
906 /* 877 /*
907 * Pin functions like AMC address strobes my 878 * Pin functions like AMC address strobes my
908 * be requested and used by several drivers 879 * be requested and used by several drivers
909 */ 880 */
910 881
911 if (!(per & P_MAYSHARE)) { 882 if (!(per & P_MAYSHARE)) {
912 883
913 /* 884 /*
914 * Allow that the identical pin function can 885 * Allow that the identical pin function can
915 * be requested from the same driver twice 886 * be requested from the same driver twice
916 */ 887 */
917 888
918 if (cmp_label(ident, label) == 0) 889 if (cmp_label(ident, label) == 0)
919 goto anyway; 890 goto anyway;
920 891
892 dump_stack();
921 printk(KERN_ERR 893 printk(KERN_ERR
922 "%s: Peripheral %d function %d is already" 894 "%s: Peripheral %d function %d is already"
923 " reserved by %s !\n", 895 " reserved by %s !\n",
924 __FUNCTION__, ident, P_FUNCT2MUX(per), 896 __func__, ident, P_FUNCT2MUX(per),
925 get_label(ident)); 897 get_label(ident));
926 dump_stack();
927 local_irq_restore(flags); 898 local_irq_restore(flags);
928 return -EBUSY; 899 return -EBUSY;
929 } 900 }
930 901
931 } 902 }
932 903
933anyway: 904 anyway:
934 portmux_setup(per, P_FUNCT2MUX(per)); 905 portmux_setup(per, P_FUNCT2MUX(per));
935 906
936 port_setup(ident, PERIPHERAL_USAGE); 907 port_setup(ident, PERIPHERAL_USAGE);
@@ -944,7 +915,7 @@ anyway:
944EXPORT_SYMBOL(peripheral_request); 915EXPORT_SYMBOL(peripheral_request);
945#endif 916#endif
946 917
947int peripheral_request_list(unsigned short per[], const char *label) 918int peripheral_request_list(const unsigned short per[], const char *label)
948{ 919{
949 u16 cnt; 920 u16 cnt;
950 int ret; 921 int ret;
@@ -954,10 +925,10 @@ int peripheral_request_list(unsigned short per[], const char *label)
954 ret = peripheral_request(per[cnt], label); 925 ret = peripheral_request(per[cnt], label);
955 926
956 if (ret < 0) { 927 if (ret < 0) {
957 for ( ; cnt > 0; cnt--) { 928 for ( ; cnt > 0; cnt--)
958 peripheral_free(per[cnt - 1]); 929 peripheral_free(per[cnt - 1]);
959 } 930
960 return ret; 931 return ret;
961 } 932 }
962 } 933 }
963 934
@@ -981,15 +952,13 @@ void peripheral_free(unsigned short per)
981 952
982 local_irq_save(flags); 953 local_irq_save(flags);
983 954
984 if (unlikely(!(reserved_peri_map[gpio_bank(ident)] 955 if (unlikely(!(reserved_peri_map[gpio_bank(ident)] & gpio_bit(ident)))) {
985 & gpio_bit(ident)))) {
986 local_irq_restore(flags); 956 local_irq_restore(flags);
987 return; 957 return;
988 } 958 }
989 959
990 if (!(per & P_MAYSHARE)) { 960 if (!(per & P_MAYSHARE))
991 port_setup(ident, GPIO_USAGE); 961 port_setup(ident, GPIO_USAGE);
992 }
993 962
994 reserved_peri_map[gpio_bank(ident)] &= ~gpio_bit(ident); 963 reserved_peri_map[gpio_bank(ident)] &= ~gpio_bit(ident);
995 964
@@ -999,14 +968,11 @@ void peripheral_free(unsigned short per)
999} 968}
1000EXPORT_SYMBOL(peripheral_free); 969EXPORT_SYMBOL(peripheral_free);
1001 970
1002void peripheral_free_list(unsigned short per[]) 971void peripheral_free_list(const unsigned short per[])
1003{ 972{
1004 u16 cnt; 973 u16 cnt;
1005 974 for (cnt = 0; per[cnt] != 0; cnt++)
1006 for (cnt = 0; per[cnt] != 0; cnt++) {
1007 peripheral_free(per[cnt]); 975 peripheral_free(per[cnt]);
1008 }
1009
1010} 976}
1011EXPORT_SYMBOL(peripheral_free_list); 977EXPORT_SYMBOL(peripheral_free_list);
1012 978
@@ -1046,17 +1012,17 @@ int gpio_request(unsigned gpio, const char *label)
1046 } 1012 }
1047 1013
1048 if (unlikely(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) { 1014 if (unlikely(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
1015 dump_stack();
1049 printk(KERN_ERR "bfin-gpio: GPIO %d is already reserved by %s !\n", 1016 printk(KERN_ERR "bfin-gpio: GPIO %d is already reserved by %s !\n",
1050 gpio, get_label(gpio)); 1017 gpio, get_label(gpio));
1051 dump_stack();
1052 local_irq_restore(flags); 1018 local_irq_restore(flags);
1053 return -EBUSY; 1019 return -EBUSY;
1054 } 1020 }
1055 if (unlikely(reserved_peri_map[gpio_bank(gpio)] & gpio_bit(gpio))) { 1021 if (unlikely(reserved_peri_map[gpio_bank(gpio)] & gpio_bit(gpio))) {
1022 dump_stack();
1056 printk(KERN_ERR 1023 printk(KERN_ERR
1057 "bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n", 1024 "bfin-gpio: GPIO %d is already reserved as Peripheral by %s !\n",
1058 gpio, get_label(gpio)); 1025 gpio, get_label(gpio));
1059 dump_stack();
1060 local_irq_restore(flags); 1026 local_irq_restore(flags);
1061 return -EBUSY; 1027 return -EBUSY;
1062 } 1028 }
@@ -1082,14 +1048,12 @@ void gpio_free(unsigned gpio)
1082 local_irq_save(flags); 1048 local_irq_save(flags);
1083 1049
1084 if (unlikely(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)))) { 1050 if (unlikely(!(reserved_gpio_map[gpio_bank(gpio)] & gpio_bit(gpio)))) {
1085 gpio_error(gpio);
1086 dump_stack(); 1051 dump_stack();
1052 gpio_error(gpio);
1087 local_irq_restore(flags); 1053 local_irq_restore(flags);
1088 return; 1054 return;
1089 } 1055 }
1090 1056
1091 default_gpio(gpio);
1092
1093 reserved_gpio_map[gpio_bank(gpio)] &= ~gpio_bit(gpio); 1057 reserved_gpio_map[gpio_bank(gpio)] &= ~gpio_bit(gpio);
1094 1058
1095 set_label(gpio, "free"); 1059 set_label(gpio, "free");
@@ -1152,6 +1116,18 @@ int gpio_get_value(unsigned gpio)
1152} 1116}
1153EXPORT_SYMBOL(gpio_get_value); 1117EXPORT_SYMBOL(gpio_get_value);
1154 1118
1119void bfin_gpio_irq_prepare(unsigned gpio)
1120{
1121 unsigned long flags;
1122
1123 port_setup(gpio, GPIO_USAGE);
1124
1125 local_irq_save(flags);
1126 gpio_array[gpio_bank(gpio)]->port_dir_clear = gpio_bit(gpio);
1127 gpio_array[gpio_bank(gpio)]->port_inen |= gpio_bit(gpio);
1128 local_irq_restore(flags);
1129}
1130
1155#else 1131#else
1156 1132
1157int gpio_direction_input(unsigned gpio) 1133int gpio_direction_input(unsigned gpio)
@@ -1218,6 +1194,11 @@ void bfin_gpio_reset_spi0_ssel1(void)
1218 udelay(1); 1194 udelay(1);
1219} 1195}
1220 1196
1197void bfin_gpio_irq_prepare(unsigned gpio)
1198{
1199 port_setup(gpio, GPIO_USAGE);
1200}
1201
1221#endif /*BF548_FAMILY */ 1202#endif /*BF548_FAMILY */
1222 1203
1223#if defined(CONFIG_PROC_FS) 1204#if defined(CONFIG_PROC_FS)
diff --git a/arch/blackfin/kernel/cplb-mpu/cplbinfo.c b/arch/blackfin/kernel/cplb-mpu/cplbinfo.c
index bd072299f7f2..822beefa3a4b 100644
--- a/arch/blackfin/kernel/cplb-mpu/cplbinfo.c
+++ b/arch/blackfin/kernel/cplb-mpu/cplbinfo.c
@@ -39,14 +39,6 @@
39#include <asm/cplbinit.h> 39#include <asm/cplbinit.h>
40#include <asm/blackfin.h> 40#include <asm/blackfin.h>
41 41
42#define CPLB_I 1
43#define CPLB_D 2
44
45#define SYNC_SYS SSYNC()
46#define SYNC_CORE CSYNC()
47
48#define CPLB_BIT_PAGESIZE 0x30000
49
50static char page_size_string_table[][4] = { "1K", "4K", "1M", "4M" }; 42static char page_size_string_table[][4] = { "1K", "4K", "1M", "4M" };
51 43
52static char *cplb_print_entry(char *buf, struct cplb_entry *tbl, int switched) 44static char *cplb_print_entry(char *buf, struct cplb_entry *tbl, int switched)
diff --git a/arch/blackfin/kernel/cplb-mpu/cplbinit.c b/arch/blackfin/kernel/cplb-mpu/cplbinit.c
index dc6e8a7a8bda..48060105346a 100644
--- a/arch/blackfin/kernel/cplb-mpu/cplbinit.c
+++ b/arch/blackfin/kernel/cplb-mpu/cplbinit.c
@@ -43,13 +43,15 @@ void __init generate_cpl_tables(void)
43 unsigned long d_data, i_data; 43 unsigned long d_data, i_data;
44 unsigned long d_cache = 0, i_cache = 0; 44 unsigned long d_cache = 0, i_cache = 0;
45 45
46 printk(KERN_INFO "MPU: setting up cplb tables with memory protection\n");
47
46#ifdef CONFIG_BFIN_ICACHE 48#ifdef CONFIG_BFIN_ICACHE
47 i_cache = CPLB_L1_CHBL | ANOMALY_05000158_WORKAROUND; 49 i_cache = CPLB_L1_CHBL | ANOMALY_05000158_WORKAROUND;
48#endif 50#endif
49 51
50#ifdef CONFIG_BFIN_DCACHE 52#ifdef CONFIG_BFIN_DCACHE
51 d_cache = CPLB_L1_CHBL; 53 d_cache = CPLB_L1_CHBL;
52#ifdef CONFIG_BLKFIN_WT 54#ifdef CONFIG_BFIN_WT
53 d_cache |= CPLB_L1_AOW | CPLB_WT; 55 d_cache |= CPLB_L1_AOW | CPLB_WT;
54#endif 56#endif
55#endif 57#endif
diff --git a/arch/blackfin/kernel/cplb-mpu/cplbmgr.c b/arch/blackfin/kernel/cplb-mpu/cplbmgr.c
index c426a22f9907..99f2831e2964 100644
--- a/arch/blackfin/kernel/cplb-mpu/cplbmgr.c
+++ b/arch/blackfin/kernel/cplb-mpu/cplbmgr.c
@@ -24,8 +24,6 @@
24#include <asm/cplbinit.h> 24#include <asm/cplbinit.h>
25#include <asm/mmu_context.h> 25#include <asm/mmu_context.h>
26 26
27#ifdef CONFIG_BFIN_ICACHE
28
29#define FAULT_RW (1 << 16) 27#define FAULT_RW (1 << 16)
30#define FAULT_USERSUPV (1 << 17) 28#define FAULT_USERSUPV (1 << 17)
31 29
@@ -143,30 +141,48 @@ static noinline int dcplb_miss(void)
143 unsigned long d_data; 141 unsigned long d_data;
144 142
145 nr_dcplb_miss++; 143 nr_dcplb_miss++;
146 if (addr >= _ramend)
147 return CPLB_PROT_VIOL;
148 144
149 d_data = CPLB_SUPV_WR | CPLB_VALID | CPLB_DIRTY | PAGE_SIZE_4KB; 145 d_data = CPLB_SUPV_WR | CPLB_VALID | CPLB_DIRTY | PAGE_SIZE_4KB;
150#ifdef CONFIG_BFIN_DCACHE 146#ifdef CONFIG_BFIN_DCACHE
151 d_data |= CPLB_L1_CHBL | ANOMALY_05000158_WORKAROUND; 147 if (addr < _ramend - DMA_UNCACHED_REGION ||
152#ifdef CONFIG_BLKFIN_WT 148 (reserved_mem_dcache_on && addr >= _ramend &&
153 d_data |= CPLB_L1_AOW | CPLB_WT; 149 addr < physical_mem_end)) {
154#endif 150 d_data |= CPLB_L1_CHBL | ANOMALY_05000158_WORKAROUND;
151#ifdef CONFIG_BFIN_WT
152 d_data |= CPLB_L1_AOW | CPLB_WT;
155#endif 153#endif
156 mask = current_rwx_mask;
157 if (mask) {
158 int page = addr >> PAGE_SHIFT;
159 int offs = page >> 5;
160 int bit = 1 << (page & 31);
161
162 if (mask[offs] & bit)
163 d_data |= CPLB_USER_RD;
164
165 mask += page_mask_nelts;
166 if (mask[offs] & bit)
167 d_data |= CPLB_USER_WR;
168 } 154 }
155#endif
156 if (addr >= physical_mem_end) {
157 if (addr >= ASYNC_BANK0_BASE && addr < ASYNC_BANK3_BASE + ASYNC_BANK3_SIZE
158 && (status & FAULT_USERSUPV)) {
159 addr &= ~0x3fffff;
160 d_data &= ~PAGE_SIZE_4KB;
161 d_data |= PAGE_SIZE_4MB;
162 } else if (addr >= BOOT_ROM_START && addr < BOOT_ROM_START + BOOT_ROM_LENGTH
163 && (status & (FAULT_RW | FAULT_USERSUPV)) == FAULT_USERSUPV) {
164 addr &= ~(1 * 1024 * 1024 - 1);
165 d_data &= ~PAGE_SIZE_4KB;
166 d_data |= PAGE_SIZE_1MB;
167 } else
168 return CPLB_PROT_VIOL;
169 } else if (addr >= _ramend) {
170 d_data |= CPLB_USER_RD | CPLB_USER_WR;
171 } else {
172 mask = current_rwx_mask;
173 if (mask) {
174 int page = addr >> PAGE_SHIFT;
175 int offs = page >> 5;
176 int bit = 1 << (page & 31);
177
178 if (mask[offs] & bit)
179 d_data |= CPLB_USER_RD;
169 180
181 mask += page_mask_nelts;
182 if (mask[offs] & bit)
183 d_data |= CPLB_USER_WR;
184 }
185 }
170 idx = evict_one_dcplb(); 186 idx = evict_one_dcplb();
171 187
172 addr &= PAGE_MASK; 188 addr &= PAGE_MASK;
@@ -189,12 +205,14 @@ static noinline int icplb_miss(void)
189 unsigned long i_data; 205 unsigned long i_data;
190 206
191 nr_icplb_miss++; 207 nr_icplb_miss++;
192 if (status & FAULT_USERSUPV)
193 nr_icplb_supv_miss++;
194 208
195 if (addr >= _ramend) 209 /* If inside the uncached DMA region, fault. */
210 if (addr >= _ramend - DMA_UNCACHED_REGION && addr < _ramend)
196 return CPLB_PROT_VIOL; 211 return CPLB_PROT_VIOL;
197 212
213 if (status & FAULT_USERSUPV)
214 nr_icplb_supv_miss++;
215
198 /* 216 /*
199 * First, try to find a CPLB that matches this address. If we 217 * First, try to find a CPLB that matches this address. If we
200 * find one, then the fact that we're in the miss handler means 218 * find one, then the fact that we're in the miss handler means
@@ -211,30 +229,48 @@ static noinline int icplb_miss(void)
211 } 229 }
212 230
213 i_data = CPLB_VALID | CPLB_PORTPRIO | PAGE_SIZE_4KB; 231 i_data = CPLB_VALID | CPLB_PORTPRIO | PAGE_SIZE_4KB;
214#ifdef CONFIG_BFIN_ICACHE
215 i_data |= CPLB_L1_CHBL | ANOMALY_05000158_WORKAROUND;
216#endif
217 232
233#ifdef CONFIG_BFIN_ICACHE
218 /* 234 /*
219 * Two cases to distinguish - a supervisor access must necessarily 235 * Normal RAM, and possibly the reserved memory area, are
220 * be for a module page; we grant it unconditionally (could do better 236 * cacheable.
221 * here in the future). Otherwise, check the x bitmap of the current
222 * process.
223 */ 237 */
224 if (!(status & FAULT_USERSUPV)) { 238 if (addr < _ramend ||
225 unsigned long *mask = current_rwx_mask; 239 (addr < physical_mem_end && reserved_mem_icache_on))
226 240 i_data |= CPLB_L1_CHBL | ANOMALY_05000158_WORKAROUND;
227 if (mask) { 241#endif
228 int page = addr >> PAGE_SHIFT;
229 int offs = page >> 5;
230 int bit = 1 << (page & 31);
231 242
232 mask += 2 * page_mask_nelts; 243 if (addr >= physical_mem_end) {
233 if (mask[offs] & bit) 244 if (addr >= BOOT_ROM_START && addr < BOOT_ROM_START + BOOT_ROM_LENGTH
234 i_data |= CPLB_USER_RD; 245 && (status & FAULT_USERSUPV)) {
246 addr &= ~(1 * 1024 * 1024 - 1);
247 i_data &= ~PAGE_SIZE_4KB;
248 i_data |= PAGE_SIZE_1MB;
249 } else
250 return CPLB_PROT_VIOL;
251 } else if (addr >= _ramend) {
252 i_data |= CPLB_USER_RD;
253 } else {
254 /*
255 * Two cases to distinguish - a supervisor access must
256 * necessarily be for a module page; we grant it
257 * unconditionally (could do better here in the future).
258 * Otherwise, check the x bitmap of the current process.
259 */
260 if (!(status & FAULT_USERSUPV)) {
261 unsigned long *mask = current_rwx_mask;
262
263 if (mask) {
264 int page = addr >> PAGE_SHIFT;
265 int offs = page >> 5;
266 int bit = 1 << (page & 31);
267
268 mask += 2 * page_mask_nelts;
269 if (mask[offs] & bit)
270 i_data |= CPLB_USER_RD;
271 }
235 } 272 }
236 } 273 }
237
238 idx = evict_one_icplb(); 274 idx = evict_one_icplb();
239 addr &= PAGE_MASK; 275 addr &= PAGE_MASK;
240 icplb_tbl[idx].addr = addr; 276 icplb_tbl[idx].addr = addr;
@@ -250,7 +286,6 @@ static noinline int icplb_miss(void)
250 286
251static noinline int dcplb_protection_fault(void) 287static noinline int dcplb_protection_fault(void)
252{ 288{
253 unsigned long addr = bfin_read_DCPLB_FAULT_ADDR();
254 int status = bfin_read_DCPLB_STATUS(); 289 int status = bfin_read_DCPLB_STATUS();
255 290
256 nr_dcplb_prot++; 291 nr_dcplb_prot++;
@@ -280,8 +315,7 @@ int cplb_hdr(int seqstat, struct pt_regs *regs)
280 case 0x26: 315 case 0x26:
281 return dcplb_miss(); 316 return dcplb_miss();
282 default: 317 default:
283 return 1; 318 return 1;
284 panic_cplb_error(seqstat, regs);
285 } 319 }
286} 320}
287 321
@@ -299,7 +333,7 @@ void flush_switched_cplbs(void)
299 enable_icplb(); 333 enable_icplb();
300 334
301 disable_dcplb(); 335 disable_dcplb();
302 for (i = first_mask_dcplb; i < MAX_CPLBS; i++) { 336 for (i = first_switched_dcplb; i < MAX_CPLBS; i++) {
303 dcplb_tbl[i].data = 0; 337 dcplb_tbl[i].data = 0;
304 bfin_write32(DCPLB_DATA0 + i * 4, 0); 338 bfin_write32(DCPLB_DATA0 + i * 4, 0);
305 } 339 }
@@ -319,7 +353,7 @@ void set_mask_dcplbs(unsigned long *masks)
319 d_data = CPLB_SUPV_WR | CPLB_VALID | CPLB_DIRTY | PAGE_SIZE_4KB; 353 d_data = CPLB_SUPV_WR | CPLB_VALID | CPLB_DIRTY | PAGE_SIZE_4KB;
320#ifdef CONFIG_BFIN_DCACHE 354#ifdef CONFIG_BFIN_DCACHE
321 d_data |= CPLB_L1_CHBL; 355 d_data |= CPLB_L1_CHBL;
322#ifdef CONFIG_BLKFIN_WT 356#ifdef CONFIG_BFIN_WT
323 d_data |= CPLB_L1_AOW | CPLB_WT; 357 d_data |= CPLB_L1_AOW | CPLB_WT;
324#endif 358#endif
325#endif 359#endif
@@ -334,5 +368,3 @@ void set_mask_dcplbs(unsigned long *masks)
334 } 368 }
335 enable_dcplb(); 369 enable_dcplb();
336} 370}
337
338#endif
diff --git a/arch/blackfin/kernel/cplb-nompu/cplbinfo.c b/arch/blackfin/kernel/cplb-nompu/cplbinfo.c
index a4f0b428a34d..1e74f0b97996 100644
--- a/arch/blackfin/kernel/cplb-nompu/cplbinfo.c
+++ b/arch/blackfin/kernel/cplb-nompu/cplbinfo.c
@@ -33,9 +33,7 @@
33#include <linux/proc_fs.h> 33#include <linux/proc_fs.h>
34#include <linux/uaccess.h> 34#include <linux/uaccess.h>
35 35
36#include <asm/current.h> 36#include <asm/cplbinit.h>
37#include <asm/system.h>
38#include <asm/cplb.h>
39#include <asm/blackfin.h> 37#include <asm/blackfin.h>
40 38
41#define CPLB_I 1 39#define CPLB_I 1
@@ -174,16 +172,6 @@ static int cplbinfo_read_proc(char *page, char **start, off_t off,
174 return len; 172 return len;
175} 173}
176 174
177static int cplbinfo_write_proc(struct file *file, const char __user *buffer,
178 unsigned long count, void *data)
179{
180 printk(KERN_INFO "Reset the CPLB swap in/out counts.\n");
181 memset(ipdt_swapcount_table, 0, MAX_SWITCH_I_CPLBS * sizeof(unsigned long));
182 memset(dpdt_swapcount_table, 0, MAX_SWITCH_D_CPLBS * sizeof(unsigned long));
183
184 return count;
185}
186
187static int __init cplbinfo_init(void) 175static int __init cplbinfo_init(void)
188{ 176{
189 struct proc_dir_entry *entry; 177 struct proc_dir_entry *entry;
@@ -193,7 +181,6 @@ static int __init cplbinfo_init(void)
193 return -ENOMEM; 181 return -ENOMEM;
194 182
195 entry->read_proc = cplbinfo_read_proc; 183 entry->read_proc = cplbinfo_read_proc;
196 entry->write_proc = cplbinfo_write_proc;
197 entry->data = NULL; 184 entry->data = NULL;
198 185
199 return 0; 186 return 0;
diff --git a/arch/blackfin/kernel/cplb-nompu/cplbinit.c b/arch/blackfin/kernel/cplb-nompu/cplbinit.c
index 6320bc45fbba..917325bfbd84 100644
--- a/arch/blackfin/kernel/cplb-nompu/cplbinit.c
+++ b/arch/blackfin/kernel/cplb-nompu/cplbinit.c
@@ -26,6 +26,35 @@
26#include <asm/cplb.h> 26#include <asm/cplb.h>
27#include <asm/cplbinit.h> 27#include <asm/cplbinit.h>
28 28
29#ifdef CONFIG_MAX_MEM_SIZE
30# define CPLB_MEM CONFIG_MAX_MEM_SIZE
31#else
32# define CPLB_MEM CONFIG_MEM_SIZE
33#endif
34
35/*
36* Number of required data CPLB switchtable entries
37* MEMSIZE / 4 (we mostly install 4M page size CPLBs
38* approx 16 for smaller 1MB page size CPLBs for allignment purposes
39* 1 for L1 Data Memory
40* possibly 1 for L2 Data Memory
41* 1 for CONFIG_DEBUG_HUNT_FOR_ZERO
42* 1 for ASYNC Memory
43*/
44#define MAX_SWITCH_D_CPLBS (((CPLB_MEM / 4) + 16 + 1 + 1 + 1 \
45 + ASYNC_MEMORY_CPLB_COVERAGE) * 2)
46
47/*
48* Number of required instruction CPLB switchtable entries
49* MEMSIZE / 4 (we mostly install 4M page size CPLBs
50* approx 12 for smaller 1MB page size CPLBs for allignment purposes
51* 1 for L1 Instruction Memory
52* possibly 1 for L2 Instruction Memory
53* 1 for CONFIG_DEBUG_HUNT_FOR_ZERO
54*/
55#define MAX_SWITCH_I_CPLBS (((CPLB_MEM / 4) + 12 + 1 + 1 + 1) * 2)
56
57
29u_long icplb_table[MAX_CPLBS + 1]; 58u_long icplb_table[MAX_CPLBS + 1];
30u_long dcplb_table[MAX_CPLBS + 1]; 59u_long dcplb_table[MAX_CPLBS + 1];
31 60
@@ -295,6 +324,8 @@ void __init generate_cpl_tables(void)
295 struct cplb_tab *t_d = NULL; 324 struct cplb_tab *t_d = NULL;
296 struct s_cplb cplb; 325 struct s_cplb cplb;
297 326
327 printk(KERN_INFO "NOMPU: setting up cplb tables for global access\n");
328
298 cplb.init_i.size = MAX_CPLBS; 329 cplb.init_i.size = MAX_CPLBS;
299 cplb.init_d.size = MAX_CPLBS; 330 cplb.init_d.size = MAX_CPLBS;
300 cplb.switch_i.size = MAX_SWITCH_I_CPLBS; 331 cplb.switch_i.size = MAX_SWITCH_I_CPLBS;
diff --git a/arch/blackfin/kernel/dma-mapping.c b/arch/blackfin/kernel/dma-mapping.c
index d6b61d56b656..2f62a9f4058a 100644
--- a/arch/blackfin/kernel/dma-mapping.c
+++ b/arch/blackfin/kernel/dma-mapping.c
@@ -59,7 +59,7 @@ void dma_alloc_init(unsigned long start, unsigned long end)
59 memset((void *)dma_base, 0, DMA_UNCACHED_REGION); 59 memset((void *)dma_base, 0, DMA_UNCACHED_REGION);
60 dma_initialized = 1; 60 dma_initialized = 1;
61 61
62 printk(KERN_INFO "%s: dma_page @ 0x%p - %d pages at 0x%08lx\n", __FUNCTION__, 62 printk(KERN_INFO "%s: dma_page @ 0x%p - %d pages at 0x%08lx\n", __func__,
63 dma_page, dma_pages, dma_base); 63 dma_page, dma_pages, dma_base);
64} 64}
65 65
@@ -100,7 +100,7 @@ static void __free_dma_pages(unsigned long addr, unsigned int pages)
100 int i; 100 int i;
101 101
102 if ((page + pages) > dma_pages) { 102 if ((page + pages) > dma_pages) {
103 printk(KERN_ERR "%s: freeing outside range.\n", __FUNCTION__); 103 printk(KERN_ERR "%s: freeing outside range.\n", __func__);
104 BUG(); 104 BUG();
105 } 105 }
106 106
diff --git a/arch/blackfin/kernel/gptimers.c b/arch/blackfin/kernel/gptimers.c
index 1904d8b53328..e698554895a7 100644
--- a/arch/blackfin/kernel/gptimers.c
+++ b/arch/blackfin/kernel/gptimers.c
@@ -52,12 +52,14 @@ static volatile GPTIMER_timer_regs *const timer_regs[MAX_BLACKFIN_GPTIMERS] =
52 (GPTIMER_timer_regs *)TIMER5_CONFIG, 52 (GPTIMER_timer_regs *)TIMER5_CONFIG,
53 (GPTIMER_timer_regs *)TIMER6_CONFIG, 53 (GPTIMER_timer_regs *)TIMER6_CONFIG,
54 (GPTIMER_timer_regs *)TIMER7_CONFIG, 54 (GPTIMER_timer_regs *)TIMER7_CONFIG,
55#endif 55# if (MAX_BLACKFIN_GPTIMERS > 8)
56#if (MAX_BLACKFIN_GPTIMERS > 8)
57 (GPTIMER_timer_regs *)TIMER8_CONFIG, 56 (GPTIMER_timer_regs *)TIMER8_CONFIG,
58 (GPTIMER_timer_regs *)TIMER9_CONFIG, 57 (GPTIMER_timer_regs *)TIMER9_CONFIG,
59 (GPTIMER_timer_regs *)TIMER10_CONFIG, 58 (GPTIMER_timer_regs *)TIMER10_CONFIG,
59# if (MAX_BLACKFIN_GPTIMERS > 11)
60 (GPTIMER_timer_regs *)TIMER11_CONFIG, 60 (GPTIMER_timer_regs *)TIMER11_CONFIG,
61# endif
62# endif
61#endif 63#endif
62}; 64};
63 65
@@ -80,12 +82,14 @@ static uint32_t const trun_mask[MAX_BLACKFIN_GPTIMERS] =
80 TIMER_STATUS_TRUN5, 82 TIMER_STATUS_TRUN5,
81 TIMER_STATUS_TRUN6, 83 TIMER_STATUS_TRUN6,
82 TIMER_STATUS_TRUN7, 84 TIMER_STATUS_TRUN7,
83#endif 85# if (MAX_BLACKFIN_GPTIMERS > 8)
84#if (MAX_BLACKFIN_GPTIMERS > 8)
85 TIMER_STATUS_TRUN8, 86 TIMER_STATUS_TRUN8,
86 TIMER_STATUS_TRUN9, 87 TIMER_STATUS_TRUN9,
87 TIMER_STATUS_TRUN10, 88 TIMER_STATUS_TRUN10,
89# if (MAX_BLACKFIN_GPTIMERS > 11)
88 TIMER_STATUS_TRUN11, 90 TIMER_STATUS_TRUN11,
91# endif
92# endif
89#endif 93#endif
90}; 94};
91 95
@@ -100,12 +104,14 @@ static uint32_t const tovf_mask[MAX_BLACKFIN_GPTIMERS] =
100 TIMER_STATUS_TOVF5, 104 TIMER_STATUS_TOVF5,
101 TIMER_STATUS_TOVF6, 105 TIMER_STATUS_TOVF6,
102 TIMER_STATUS_TOVF7, 106 TIMER_STATUS_TOVF7,
103#endif 107# if (MAX_BLACKFIN_GPTIMERS > 8)
104#if (MAX_BLACKFIN_GPTIMERS > 8)
105 TIMER_STATUS_TOVF8, 108 TIMER_STATUS_TOVF8,
106 TIMER_STATUS_TOVF9, 109 TIMER_STATUS_TOVF9,
107 TIMER_STATUS_TOVF10, 110 TIMER_STATUS_TOVF10,
111# if (MAX_BLACKFIN_GPTIMERS > 11)
108 TIMER_STATUS_TOVF11, 112 TIMER_STATUS_TOVF11,
113# endif
114# endif
109#endif 115#endif
110}; 116};
111 117
@@ -120,12 +126,14 @@ static uint32_t const timil_mask[MAX_BLACKFIN_GPTIMERS] =
120 TIMER_STATUS_TIMIL5, 126 TIMER_STATUS_TIMIL5,
121 TIMER_STATUS_TIMIL6, 127 TIMER_STATUS_TIMIL6,
122 TIMER_STATUS_TIMIL7, 128 TIMER_STATUS_TIMIL7,
123#endif 129# if (MAX_BLACKFIN_GPTIMERS > 8)
124#if (MAX_BLACKFIN_GPTIMERS > 8)
125 TIMER_STATUS_TIMIL8, 130 TIMER_STATUS_TIMIL8,
126 TIMER_STATUS_TIMIL9, 131 TIMER_STATUS_TIMIL9,
127 TIMER_STATUS_TIMIL10, 132 TIMER_STATUS_TIMIL10,
133# if (MAX_BLACKFIN_GPTIMERS > 11)
128 TIMER_STATUS_TIMIL11, 134 TIMER_STATUS_TIMIL11,
135# endif
136# endif
129#endif 137#endif
130}; 138};
131 139
diff --git a/arch/blackfin/kernel/process.c b/arch/blackfin/kernel/process.c
index 6b8459c66163..be9fdd00d7cb 100644
--- a/arch/blackfin/kernel/process.c
+++ b/arch/blackfin/kernel/process.c
@@ -32,6 +32,8 @@
32#include <linux/unistd.h> 32#include <linux/unistd.h>
33#include <linux/user.h> 33#include <linux/user.h>
34#include <linux/uaccess.h> 34#include <linux/uaccess.h>
35#include <linux/sched.h>
36#include <linux/tick.h>
35#include <linux/fs.h> 37#include <linux/fs.h>
36#include <linux/err.h> 38#include <linux/err.h>
37 39
@@ -69,33 +71,44 @@ EXPORT_SYMBOL(pm_power_off);
69 * The idle loop on BFIN 71 * The idle loop on BFIN
70 */ 72 */
71#ifdef CONFIG_IDLE_L1 73#ifdef CONFIG_IDLE_L1
72void default_idle(void)__attribute__((l1_text)); 74static void default_idle(void)__attribute__((l1_text));
73void cpu_idle(void)__attribute__((l1_text)); 75void cpu_idle(void)__attribute__((l1_text));
74#endif 76#endif
75 77
76void default_idle(void) 78/*
79 * This is our default idle handler. We need to disable
80 * interrupts here to ensure we don't miss a wakeup call.
81 */
82static void default_idle(void)
77{ 83{
78 while (!need_resched()) { 84 local_irq_disable();
79 local_irq_disable(); 85 if (!need_resched())
80 if (likely(!need_resched())) 86 idle_with_irq_disabled();
81 idle_with_irq_disabled();
82 local_irq_enable();
83 }
84}
85 87
86void (*idle)(void) = default_idle; 88 local_irq_enable();
89}
87 90
88/* 91/*
89 * The idle thread. There's no useful work to be 92 * The idle thread. We try to conserve power, while trying to keep
90 * done, so just try to conserve power and have a 93 * overall latency low. The architecture specific idle is passed
91 * low exit latency (ie sit in a loop waiting for 94 * a value to indicate the level of "idleness" of the system.
92 * somebody to say that they'd like to reschedule)
93 */ 95 */
94void cpu_idle(void) 96void cpu_idle(void)
95{ 97{
96 /* endless idle loop with no priority at all */ 98 /* endless idle loop with no priority at all */
97 while (1) { 99 while (1) {
98 idle(); 100 void (*idle)(void) = pm_idle;
101
102#ifdef CONFIG_HOTPLUG_CPU
103 if (cpu_is_offline(smp_processor_id()))
104 cpu_die();
105#endif
106 if (!idle)
107 idle = default_idle;
108 tick_nohz_stop_sched_tick();
109 while (!need_resched())
110 idle();
111 tick_nohz_restart_sched_tick();
99 preempt_enable_no_resched(); 112 preempt_enable_no_resched();
100 schedule(); 113 schedule();
101 preempt_disable(); 114 preempt_disable();
@@ -189,7 +202,7 @@ copy_thread(int nr, unsigned long clone_flags,
189 * sys_execve() executes a new program. 202 * sys_execve() executes a new program.
190 */ 203 */
191 204
192asmlinkage int sys_execve(char *name, char **argv, char **envp) 205asmlinkage int sys_execve(char __user *name, char __user * __user *argv, char __user * __user *envp)
193{ 206{
194 int error; 207 int error;
195 char *filename; 208 char *filename;
@@ -232,23 +245,25 @@ unsigned long get_wchan(struct task_struct *p)
232 245
233void finish_atomic_sections (struct pt_regs *regs) 246void finish_atomic_sections (struct pt_regs *regs)
234{ 247{
248 int __user *up0 = (int __user *)&regs->p0;
249
235 if (regs->pc < ATOMIC_SEQS_START || regs->pc >= ATOMIC_SEQS_END) 250 if (regs->pc < ATOMIC_SEQS_START || regs->pc >= ATOMIC_SEQS_END)
236 return; 251 return;
237 252
238 switch (regs->pc) { 253 switch (regs->pc) {
239 case ATOMIC_XCHG32 + 2: 254 case ATOMIC_XCHG32 + 2:
240 put_user(regs->r1, (int *)regs->p0); 255 put_user(regs->r1, up0);
241 regs->pc += 2; 256 regs->pc += 2;
242 break; 257 break;
243 258
244 case ATOMIC_CAS32 + 2: 259 case ATOMIC_CAS32 + 2:
245 case ATOMIC_CAS32 + 4: 260 case ATOMIC_CAS32 + 4:
246 if (regs->r0 == regs->r1) 261 if (regs->r0 == regs->r1)
247 put_user(regs->r2, (int *)regs->p0); 262 put_user(regs->r2, up0);
248 regs->pc = ATOMIC_CAS32 + 8; 263 regs->pc = ATOMIC_CAS32 + 8;
249 break; 264 break;
250 case ATOMIC_CAS32 + 6: 265 case ATOMIC_CAS32 + 6:
251 put_user(regs->r2, (int *)regs->p0); 266 put_user(regs->r2, up0);
252 regs->pc += 2; 267 regs->pc += 2;
253 break; 268 break;
254 269
@@ -256,7 +271,7 @@ void finish_atomic_sections (struct pt_regs *regs)
256 regs->r0 = regs->r1 + regs->r0; 271 regs->r0 = regs->r1 + regs->r0;
257 /* fall through */ 272 /* fall through */
258 case ATOMIC_ADD32 + 4: 273 case ATOMIC_ADD32 + 4:
259 put_user(regs->r0, (int *)regs->p0); 274 put_user(regs->r0, up0);
260 regs->pc = ATOMIC_ADD32 + 6; 275 regs->pc = ATOMIC_ADD32 + 6;
261 break; 276 break;
262 277
@@ -264,7 +279,7 @@ void finish_atomic_sections (struct pt_regs *regs)
264 regs->r0 = regs->r1 - regs->r0; 279 regs->r0 = regs->r1 - regs->r0;
265 /* fall through */ 280 /* fall through */
266 case ATOMIC_SUB32 + 4: 281 case ATOMIC_SUB32 + 4:
267 put_user(regs->r0, (int *)regs->p0); 282 put_user(regs->r0, up0);
268 regs->pc = ATOMIC_SUB32 + 6; 283 regs->pc = ATOMIC_SUB32 + 6;
269 break; 284 break;
270 285
@@ -272,7 +287,7 @@ void finish_atomic_sections (struct pt_regs *regs)
272 regs->r0 = regs->r1 | regs->r0; 287 regs->r0 = regs->r1 | regs->r0;
273 /* fall through */ 288 /* fall through */
274 case ATOMIC_IOR32 + 4: 289 case ATOMIC_IOR32 + 4:
275 put_user(regs->r0, (int *)regs->p0); 290 put_user(regs->r0, up0);
276 regs->pc = ATOMIC_IOR32 + 6; 291 regs->pc = ATOMIC_IOR32 + 6;
277 break; 292 break;
278 293
@@ -280,7 +295,7 @@ void finish_atomic_sections (struct pt_regs *regs)
280 regs->r0 = regs->r1 & regs->r0; 295 regs->r0 = regs->r1 & regs->r0;
281 /* fall through */ 296 /* fall through */
282 case ATOMIC_AND32 + 4: 297 case ATOMIC_AND32 + 4:
283 put_user(regs->r0, (int *)regs->p0); 298 put_user(regs->r0, up0);
284 regs->pc = ATOMIC_AND32 + 6; 299 regs->pc = ATOMIC_AND32 + 6;
285 break; 300 break;
286 301
@@ -288,7 +303,7 @@ void finish_atomic_sections (struct pt_regs *regs)
288 regs->r0 = regs->r1 ^ regs->r0; 303 regs->r0 = regs->r1 ^ regs->r0;
289 /* fall through */ 304 /* fall through */
290 case ATOMIC_XOR32 + 4: 305 case ATOMIC_XOR32 + 4:
291 put_user(regs->r0, (int *)regs->p0); 306 put_user(regs->r0, up0);
292 regs->pc = ATOMIC_XOR32 + 6; 307 regs->pc = ATOMIC_XOR32 + 6;
293 break; 308 break;
294 } 309 }
@@ -309,6 +324,12 @@ int _access_ok(unsigned long addr, unsigned long size)
309 return 1; 324 return 1;
310 if (addr >= memory_mtd_end && (addr + size) <= physical_mem_end) 325 if (addr >= memory_mtd_end && (addr + size) <= physical_mem_end)
311 return 1; 326 return 1;
327
328#ifdef CONFIG_ROMFS_MTD_FS
329 /* For XIP, allow user space to use pointers within the ROMFS. */
330 if (addr >= memory_mtd_start && (addr + size) <= memory_mtd_end)
331 return 1;
332#endif
312#else 333#else
313 if (addr >= memory_start && (addr + size) <= physical_mem_end) 334 if (addr >= memory_start && (addr + size) <= physical_mem_end)
314 return 1; 335 return 1;
diff --git a/arch/blackfin/kernel/ptrace.c b/arch/blackfin/kernel/ptrace.c
index 85caf9b711a1..b4f062c172c6 100644
--- a/arch/blackfin/kernel/ptrace.c
+++ b/arch/blackfin/kernel/ptrace.c
@@ -193,6 +193,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
193{ 193{
194 int ret; 194 int ret;
195 int add = 0; 195 int add = 0;
196 unsigned long __user *datap = (unsigned long __user *)data;
196 197
197 switch (request) { 198 switch (request) {
198 /* when I and D space are separate, these will need to be fixed. */ 199 /* when I and D space are separate, these will need to be fixed. */
@@ -229,7 +230,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
229 pr_debug("ptrace: copied size %d [0x%08lx]\n", copied, tmp); 230 pr_debug("ptrace: copied size %d [0x%08lx]\n", copied, tmp);
230 if (copied != sizeof(tmp)) 231 if (copied != sizeof(tmp))
231 break; 232 break;
232 ret = put_user(tmp, (unsigned long *)data); 233 ret = put_user(tmp, datap);
233 break; 234 break;
234 } 235 }
235 236
@@ -263,7 +264,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
263 } else { 264 } else {
264 tmp = get_reg(child, addr); 265 tmp = get_reg(child, addr);
265 } 266 }
266 ret = put_user(tmp, (unsigned long *)data); 267 ret = put_user(tmp, datap);
267 break; 268 break;
268 } 269 }
269 270
@@ -389,7 +390,7 @@ long arch_ptrace(struct task_struct *child, long request, long addr, long data)
389 { 390 {
390 391
391 /* Get all gp regs from the child. */ 392 /* Get all gp regs from the child. */
392 ret = ptrace_getregs(child, (void __user *)data); 393 ret = ptrace_getregs(child, datap);
393 break; 394 break;
394 } 395 }
395 396
diff --git a/arch/blackfin/kernel/reboot.c b/arch/blackfin/kernel/reboot.c
index 483f93dfc1b5..367e2dc09881 100644
--- a/arch/blackfin/kernel/reboot.c
+++ b/arch/blackfin/kernel/reboot.c
@@ -11,45 +11,56 @@
11#include <asm/reboot.h> 11#include <asm/reboot.h>
12#include <asm/system.h> 12#include <asm/system.h>
13 13
14#if defined(BF537_FAMILY) || defined(BF533_FAMILY) || defined(BF527_FAMILY) 14/* A system soft reset makes external memory unusable so force
15#define SYSCR_VAL 0x0 15 * this function into L1. We use the compiler ssync here rather
16#elif defined(BF561_FAMILY) 16 * than SSYNC() because it's safe (no interrupts and such) and
17#define SYSCR_VAL 0x20 17 * we save some L1. We do not need to force sanity in the SYSCR
18#elif defined(BF548_FAMILY) 18 * register as the BMODE selection bit is cleared by the soft
19#define SYSCR_VAL 0x10 19 * reset while the Core B bit (on dual core parts) is cleared by
20#endif 20 * the core reset.
21
22/*
23 * Delay min 5 SCLK cycles using worst case CCLK/SCLK ratio (15)
24 */
25#define SWRST_DELAY (5 * 15)
26
27/* A system soft reset makes external memory unusable
28 * so force this function into L1.
29 */ 21 */
30__attribute__((l1_text)) 22__attribute__((l1_text))
31void bfin_reset(void) 23void bfin_reset(void)
32{ 24{
33 /* force BMODE and disable Core B (as needed) */ 25 /* Wait for completion of "system" events such as cache line
34 bfin_write_SYSCR(SYSCR_VAL); 26 * line fills so that we avoid infinite stalls later on as
35 27 * much as possible. This code is in L1, so it won't trigger
36 /* we use asm ssync here because it's save and we save some L1 */ 28 * any such event after this point in time.
37 asm("ssync;"); 29 */
30 __builtin_bfin_ssync();
38 31
39 while (1) { 32 while (1) {
40 /* initiate system soft reset with magic 0x7 */ 33 /* Initiate System software reset. */
41 bfin_write_SWRST(0x7); 34 bfin_write_SWRST(0x7);
42 35
43 /* Wait for System reset to actually reset, needs to be 5 SCLKs, */ 36 /* Due to the way reset is handled in the hardware, we need
44 /* Assume CCLK / SCLK ratio is worst case (15), and use 5*15 */ 37 * to delay for 7 SCLKS. The only reliable way to do this is
45 38 * to calculate the CCLK/SCLK ratio and multiply 7. For now,
46 asm("LSETUP(.Lfoo,.Lfoo) LC0 = %0\n .Lfoo: NOP;\n" 39 * we'll assume worse case which is a 1:15 ratio.
47 : : "a" (SWRST_DELAY) : "LC0", "LT0", "LB0"); 40 */
41 asm(
42 "LSETUP (1f, 1f) LC0 = %0\n"
43 "1: nop;"
44 :
45 : "a" (15 * 7)
46 : "LC0", "LB0", "LT0"
47 );
48 48
49 /* clear system soft reset */ 49 /* Clear System software reset */
50 bfin_write_SWRST(0); 50 bfin_write_SWRST(0);
51 asm("ssync;"); 51
52 /* issue core reset */ 52 /* Wait for the SWRST write to complete. Cannot rely on SSYNC
53 * though as the System state is all reset now.
54 */
55 asm(
56 "LSETUP (1f, 1f) LC1 = %0\n"
57 "1: nop;"
58 :
59 : "a" (15 * 1)
60 : "LC1", "LB1", "LT1"
61 );
62
63 /* Issue core reset */
53 asm("raise 1"); 64 asm("raise 1");
54 } 65 }
55} 66}
diff --git a/arch/blackfin/kernel/setup.c b/arch/blackfin/kernel/setup.c
index 2255c289a714..8efea004aecb 100644
--- a/arch/blackfin/kernel/setup.c
+++ b/arch/blackfin/kernel/setup.c
@@ -35,6 +35,7 @@ u16 _bfin_swrst;
35EXPORT_SYMBOL(_bfin_swrst); 35EXPORT_SYMBOL(_bfin_swrst);
36 36
37unsigned long memory_start, memory_end, physical_mem_end; 37unsigned long memory_start, memory_end, physical_mem_end;
38unsigned long _rambase, _ramstart, _ramend;
38unsigned long reserved_mem_dcache_on; 39unsigned long reserved_mem_dcache_on;
39unsigned long reserved_mem_icache_on; 40unsigned long reserved_mem_icache_on;
40EXPORT_SYMBOL(memory_start); 41EXPORT_SYMBOL(memory_start);
@@ -106,7 +107,7 @@ void __init bf53x_relocate_l1_mem(void)
106 107
107 l1_code_length = _etext_l1 - _stext_l1; 108 l1_code_length = _etext_l1 - _stext_l1;
108 if (l1_code_length > L1_CODE_LENGTH) 109 if (l1_code_length > L1_CODE_LENGTH)
109 l1_code_length = L1_CODE_LENGTH; 110 panic("L1 Instruction SRAM Overflow\n");
110 /* cannot complain as printk is not available as yet. 111 /* cannot complain as printk is not available as yet.
111 * But we can continue booting and complain later! 112 * But we can continue booting and complain later!
112 */ 113 */
@@ -116,19 +117,18 @@ void __init bf53x_relocate_l1_mem(void)
116 117
117 l1_data_a_length = _ebss_l1 - _sdata_l1; 118 l1_data_a_length = _ebss_l1 - _sdata_l1;
118 if (l1_data_a_length > L1_DATA_A_LENGTH) 119 if (l1_data_a_length > L1_DATA_A_LENGTH)
119 l1_data_a_length = L1_DATA_A_LENGTH; 120 panic("L1 Data SRAM Bank A Overflow\n");
120 121
121 /* Copy _sdata_l1 to _ebss_l1 to L1 data bank A SRAM */ 122 /* Copy _sdata_l1 to _ebss_l1 to L1 data bank A SRAM */
122 dma_memcpy(_sdata_l1, _l1_lma_start + l1_code_length, l1_data_a_length); 123 dma_memcpy(_sdata_l1, _l1_lma_start + l1_code_length, l1_data_a_length);
123 124
124 l1_data_b_length = _ebss_b_l1 - _sdata_b_l1; 125 l1_data_b_length = _ebss_b_l1 - _sdata_b_l1;
125 if (l1_data_b_length > L1_DATA_B_LENGTH) 126 if (l1_data_b_length > L1_DATA_B_LENGTH)
126 l1_data_b_length = L1_DATA_B_LENGTH; 127 panic("L1 Data SRAM Bank B Overflow\n");
127 128
128 /* Copy _sdata_b_l1 to _ebss_b_l1 to L1 data bank B SRAM */ 129 /* Copy _sdata_b_l1 to _ebss_b_l1 to L1 data bank B SRAM */
129 dma_memcpy(_sdata_b_l1, _l1_lma_start + l1_code_length + 130 dma_memcpy(_sdata_b_l1, _l1_lma_start + l1_code_length +
130 l1_data_a_length, l1_data_b_length); 131 l1_data_a_length, l1_data_b_length);
131
132} 132}
133 133
134/* add_memory_region to memmap */ 134/* add_memory_region to memmap */
@@ -547,11 +547,38 @@ static __init void memory_setup(void)
547 ); 547 );
548} 548}
549 549
550/*
551 * Find the lowest, highest page frame number we have available
552 */
553void __init find_min_max_pfn(void)
554{
555 int i;
556
557 max_pfn = 0;
558 min_low_pfn = memory_end;
559
560 for (i = 0; i < bfin_memmap.nr_map; i++) {
561 unsigned long start, end;
562 /* RAM? */
563 if (bfin_memmap.map[i].type != BFIN_MEMMAP_RAM)
564 continue;
565 start = PFN_UP(bfin_memmap.map[i].addr);
566 end = PFN_DOWN(bfin_memmap.map[i].addr +
567 bfin_memmap.map[i].size);
568 if (start >= end)
569 continue;
570 if (end > max_pfn)
571 max_pfn = end;
572 if (start < min_low_pfn)
573 min_low_pfn = start;
574 }
575}
576
550static __init void setup_bootmem_allocator(void) 577static __init void setup_bootmem_allocator(void)
551{ 578{
552 int bootmap_size; 579 int bootmap_size;
553 int i; 580 int i;
554 unsigned long min_pfn, max_pfn; 581 unsigned long start_pfn, end_pfn;
555 unsigned long curr_pfn, last_pfn, size; 582 unsigned long curr_pfn, last_pfn, size;
556 583
557 /* mark memory between memory_start and memory_end usable */ 584 /* mark memory between memory_start and memory_end usable */
@@ -561,8 +588,19 @@ static __init void setup_bootmem_allocator(void)
561 sanitize_memmap(bfin_memmap.map, &bfin_memmap.nr_map); 588 sanitize_memmap(bfin_memmap.map, &bfin_memmap.nr_map);
562 print_memory_map("boot memmap"); 589 print_memory_map("boot memmap");
563 590
564 min_pfn = PAGE_OFFSET >> PAGE_SHIFT; 591 /* intialize globals in linux/bootmem.h */
565 max_pfn = memory_end >> PAGE_SHIFT; 592 find_min_max_pfn();
593 /* pfn of the last usable page frame */
594 if (max_pfn > memory_end >> PAGE_SHIFT)
595 max_pfn = memory_end >> PAGE_SHIFT;
596 /* pfn of last page frame directly mapped by kernel */
597 max_low_pfn = max_pfn;
598 /* pfn of the first usable page frame after kernel image*/
599 if (min_low_pfn < memory_start >> PAGE_SHIFT)
600 min_low_pfn = memory_start >> PAGE_SHIFT;
601
602 start_pfn = PAGE_OFFSET >> PAGE_SHIFT;
603 end_pfn = memory_end >> PAGE_SHIFT;
566 604
567 /* 605 /*
568 * give all the memory to the bootmap allocator, tell it to put the 606 * give all the memory to the bootmap allocator, tell it to put the
@@ -570,7 +608,7 @@ static __init void setup_bootmem_allocator(void)
570 */ 608 */
571 bootmap_size = init_bootmem_node(NODE_DATA(0), 609 bootmap_size = init_bootmem_node(NODE_DATA(0),
572 memory_start >> PAGE_SHIFT, /* map goes here */ 610 memory_start >> PAGE_SHIFT, /* map goes here */
573 min_pfn, max_pfn); 611 start_pfn, end_pfn);
574 612
575 /* register the memmap regions with the bootmem allocator */ 613 /* register the memmap regions with the bootmem allocator */
576 for (i = 0; i < bfin_memmap.nr_map; i++) { 614 for (i = 0; i < bfin_memmap.nr_map; i++) {
@@ -583,7 +621,7 @@ static __init void setup_bootmem_allocator(void)
583 * We are rounding up the start address of usable memory: 621 * We are rounding up the start address of usable memory:
584 */ 622 */
585 curr_pfn = PFN_UP(bfin_memmap.map[i].addr); 623 curr_pfn = PFN_UP(bfin_memmap.map[i].addr);
586 if (curr_pfn >= max_pfn) 624 if (curr_pfn >= end_pfn)
587 continue; 625 continue;
588 /* 626 /*
589 * ... and at the end of the usable range downwards: 627 * ... and at the end of the usable range downwards:
@@ -591,8 +629,8 @@ static __init void setup_bootmem_allocator(void)
591 last_pfn = PFN_DOWN(bfin_memmap.map[i].addr + 629 last_pfn = PFN_DOWN(bfin_memmap.map[i].addr +
592 bfin_memmap.map[i].size); 630 bfin_memmap.map[i].size);
593 631
594 if (last_pfn > max_pfn) 632 if (last_pfn > end_pfn)
595 last_pfn = max_pfn; 633 last_pfn = end_pfn;
596 634
597 /* 635 /*
598 * .. finally, did all the rounding and playing 636 * .. finally, did all the rounding and playing
@@ -611,9 +649,59 @@ static __init void setup_bootmem_allocator(void)
611 BOOTMEM_DEFAULT); 649 BOOTMEM_DEFAULT);
612} 650}
613 651
652#define EBSZ_TO_MEG(ebsz) \
653({ \
654 int meg = 0; \
655 switch (ebsz & 0xf) { \
656 case 0x1: meg = 16; break; \
657 case 0x3: meg = 32; break; \
658 case 0x5: meg = 64; break; \
659 case 0x7: meg = 128; break; \
660 case 0x9: meg = 256; break; \
661 case 0xb: meg = 512; break; \
662 } \
663 meg; \
664})
665static inline int __init get_mem_size(void)
666{
667#ifdef CONFIG_MEM_SIZE
668 return CONFIG_MEM_SIZE;
669#else
670# if defined(EBIU_SDBCTL)
671# if defined(BF561_FAMILY)
672 int ret = 0;
673 u32 sdbctl = bfin_read_EBIU_SDBCTL();
674 ret += EBSZ_TO_MEG(sdbctl >> 0);
675 ret += EBSZ_TO_MEG(sdbctl >> 8);
676 ret += EBSZ_TO_MEG(sdbctl >> 16);
677 ret += EBSZ_TO_MEG(sdbctl >> 24);
678 return ret;
679# else
680 return EBSZ_TO_MEG(bfin_read_EBIU_SDBCTL());
681# endif
682# elif defined(EBIU_DDRCTL1)
683 u32 ddrctl = bfin_read_EBIU_DDRCTL1();
684 int ret = 0;
685 switch (ddrctl & 0xc0000) {
686 case DEVSZ_64: ret = 64 / 8;
687 case DEVSZ_128: ret = 128 / 8;
688 case DEVSZ_256: ret = 256 / 8;
689 case DEVSZ_512: ret = 512 / 8;
690 }
691 switch (ddrctl & 0x30000) {
692 case DEVWD_4: ret *= 2;
693 case DEVWD_8: ret *= 2;
694 case DEVWD_16: break;
695 }
696 return ret;
697# endif
698#endif
699 BUG();
700}
701
614void __init setup_arch(char **cmdline_p) 702void __init setup_arch(char **cmdline_p)
615{ 703{
616 unsigned long l1_length, sclk, cclk; 704 unsigned long sclk, cclk;
617 705
618#ifdef CONFIG_DUMMY_CONSOLE 706#ifdef CONFIG_DUMMY_CONSOLE
619 conswitchp = &dummy_con; 707 conswitchp = &dummy_con;
@@ -631,7 +719,7 @@ void __init setup_arch(char **cmdline_p)
631 719
632 /* setup memory defaults from the user config */ 720 /* setup memory defaults from the user config */
633 physical_mem_end = 0; 721 physical_mem_end = 0;
634 _ramend = CONFIG_MEM_SIZE * 1024 * 1024; 722 _ramend = get_mem_size() * 1024 * 1024;
635 723
636 memset(&bfin_memmap, 0, sizeof(bfin_memmap)); 724 memset(&bfin_memmap, 0, sizeof(bfin_memmap));
637 725
@@ -712,15 +800,6 @@ void __init setup_arch(char **cmdline_p)
712 800
713 paging_init(); 801 paging_init();
714 802
715 /* check the size of the l1 area */
716 l1_length = _etext_l1 - _stext_l1;
717 if (l1_length > L1_CODE_LENGTH)
718 panic("L1 code memory overflow\n");
719
720 l1_length = _ebss_l1 - _sdata_l1;
721 if (l1_length > L1_DATA_A_LENGTH)
722 panic("L1 data memory overflow\n");
723
724 /* Copy atomic sequences to their fixed location, and sanity check that 803 /* Copy atomic sequences to their fixed location, and sanity check that
725 these locations are the ones that we advertise to userspace. */ 804 these locations are the ones that we advertise to userspace. */
726 memcpy((void *)FIXED_CODE_START, &fixed_code_start, 805 memcpy((void *)FIXED_CODE_START, &fixed_code_start,
@@ -859,12 +938,17 @@ static int show_cpuinfo(struct seq_file *m, void *v)
859 seq_printf(m, "processor\t: %d\n" 938 seq_printf(m, "processor\t: %d\n"
860 "vendor_id\t: %s\n" 939 "vendor_id\t: %s\n"
861 "cpu family\t: 0x%x\n" 940 "cpu family\t: 0x%x\n"
862 "model name\t: ADSP-%s %lu(MHz CCLK) %lu(MHz SCLK)\n" 941 "model name\t: ADSP-%s %lu(MHz CCLK) %lu(MHz SCLK) (%s)\n"
863 "stepping\t: %d\n", 942 "stepping\t: %d\n",
864 0, 943 0,
865 vendor, 944 vendor,
866 (bfin_read_CHIPID() & CHIPID_FAMILY), 945 (bfin_read_CHIPID() & CHIPID_FAMILY),
867 cpu, cclk/1000000, sclk/1000000, 946 cpu, cclk/1000000, sclk/1000000,
947#ifdef CONFIG_MPU
948 "mpu on",
949#else
950 "mpu off",
951#endif
868 revid); 952 revid);
869 953
870 seq_printf(m, "cpu MHz\t\t: %lu.%03lu/%lu.%03lu\n", 954 seq_printf(m, "cpu MHz\t\t: %lu.%03lu/%lu.%03lu\n",
@@ -973,7 +1057,6 @@ static int show_cpuinfo(struct seq_file *m, void *v)
973 seq_printf(m, "No Ways are locked\n"); 1057 seq_printf(m, "No Ways are locked\n");
974 } 1058 }
975#endif 1059#endif
976
977 seq_printf(m, "board name\t: %s\n", bfin_board_name); 1060 seq_printf(m, "board name\t: %s\n", bfin_board_name);
978 seq_printf(m, "board memory\t: %ld kB (0x%p -> 0x%p)\n", 1061 seq_printf(m, "board memory\t: %ld kB (0x%p -> 0x%p)\n",
979 physical_mem_end >> 10, (void *)0, (void *)physical_mem_end); 1062 physical_mem_end >> 10, (void *)0, (void *)physical_mem_end);
diff --git a/arch/blackfin/kernel/signal.c b/arch/blackfin/kernel/signal.c
index 5564c9588aa8..d1fa24401dc6 100644
--- a/arch/blackfin/kernel/signal.c
+++ b/arch/blackfin/kernel/signal.c
@@ -38,6 +38,7 @@
38 38
39#include <asm/cacheflush.h> 39#include <asm/cacheflush.h>
40#include <asm/ucontext.h> 40#include <asm/ucontext.h>
41#include <asm/fixed_code.h>
41 42
42#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP))) 43#define _BLOCKABLE (~(sigmask(SIGKILL) | sigmask(SIGSTOP)))
43 44
@@ -50,18 +51,20 @@ struct rt_sigframe {
50 int sig; 51 int sig;
51 struct siginfo *pinfo; 52 struct siginfo *pinfo;
52 void *puc; 53 void *puc;
54 /* This is no longer needed by the kernel, but unfortunately userspace
55 * code expects it to be there. */
53 char retcode[8]; 56 char retcode[8];
54 struct siginfo info; 57 struct siginfo info;
55 struct ucontext uc; 58 struct ucontext uc;
56}; 59};
57 60
58asmlinkage int sys_sigaltstack(const stack_t * uss, stack_t * uoss) 61asmlinkage int sys_sigaltstack(const stack_t __user *uss, stack_t __user *uoss)
59{ 62{
60 return do_sigaltstack(uss, uoss, rdusp()); 63 return do_sigaltstack(uss, uoss, rdusp());
61} 64}
62 65
63static inline int 66static inline int
64rt_restore_sigcontext(struct pt_regs *regs, struct sigcontext *sc, int *pr0) 67rt_restore_sigcontext(struct pt_regs *regs, struct sigcontext __user *sc, int *pr0)
65{ 68{
66 unsigned long usp = 0; 69 unsigned long usp = 0;
67 int err = 0; 70 int err = 0;
@@ -159,11 +162,6 @@ static inline int rt_setup_sigcontext(struct sigcontext *sc, struct pt_regs *reg
159 return err; 162 return err;
160} 163}
161 164
162static inline void push_cache(unsigned long vaddr, unsigned int len)
163{
164 flush_icache_range(vaddr, vaddr + len);
165}
166
167static inline void *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, 165static inline void *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
168 size_t frame_size) 166 size_t frame_size)
169{ 167{
@@ -209,19 +207,9 @@ setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t * info,
209 err |= rt_setup_sigcontext(&frame->uc.uc_mcontext, regs); 207 err |= rt_setup_sigcontext(&frame->uc.uc_mcontext, regs);
210 err |= copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set)); 208 err |= copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
211 209
212 /* Set up to return from userspace. */
213 err |= __put_user(0x28, &(frame->retcode[0]));
214 err |= __put_user(0xe1, &(frame->retcode[1]));
215 err |= __put_user(0xad, &(frame->retcode[2]));
216 err |= __put_user(0x00, &(frame->retcode[3]));
217 err |= __put_user(0xa0, &(frame->retcode[4]));
218 err |= __put_user(0x00, &(frame->retcode[5]));
219
220 if (err) 210 if (err)
221 goto give_sigsegv; 211 goto give_sigsegv;
222 212
223 push_cache((unsigned long)&frame->retcode, sizeof(frame->retcode));
224
225 /* Set up registers for signal handler */ 213 /* Set up registers for signal handler */
226 wrusp((unsigned long)frame); 214 wrusp((unsigned long)frame);
227 if (get_personality & FDPIC_FUNCPTRS) { 215 if (get_personality & FDPIC_FUNCPTRS) {
@@ -231,7 +219,7 @@ setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t * info,
231 __get_user(regs->p3, &funcptr->GOT); 219 __get_user(regs->p3, &funcptr->GOT);
232 } else 220 } else
233 regs->pc = (unsigned long)ka->sa.sa_handler; 221 regs->pc = (unsigned long)ka->sa.sa_handler;
234 regs->rets = (unsigned long)(frame->retcode); 222 regs->rets = SIGRETURN_STUB;
235 223
236 regs->r0 = frame->sig; 224 regs->r0 = frame->sig;
237 regs->r1 = (unsigned long)(&frame->info); 225 regs->r1 = (unsigned long)(&frame->info);
diff --git a/arch/blackfin/kernel/sys_bfin.c b/arch/blackfin/kernel/sys_bfin.c
index abcd14817d0e..efb7b25a2633 100644
--- a/arch/blackfin/kernel/sys_bfin.c
+++ b/arch/blackfin/kernel/sys_bfin.c
@@ -49,7 +49,7 @@
49 * sys_pipe() is the normal C calling standard for creating 49 * sys_pipe() is the normal C calling standard for creating
50 * a pipe. It's not the way unix traditionally does this, though. 50 * a pipe. It's not the way unix traditionally does this, though.
51 */ 51 */
52asmlinkage int sys_pipe(unsigned long *fildes) 52asmlinkage int sys_pipe(unsigned long __user *fildes)
53{ 53{
54 int fd[2]; 54 int fd[2];
55 int error; 55 int error;
diff --git a/arch/blackfin/kernel/time-ts.c b/arch/blackfin/kernel/time-ts.c
new file mode 100644
index 000000000000..4482c47c09e5
--- /dev/null
+++ b/arch/blackfin/kernel/time-ts.c
@@ -0,0 +1,219 @@
1/*
2 * linux/arch/kernel/time-ts.c
3 *
4 * Based on arm clockevents implementation and old bfin time tick.
5 *
6 * Copyright(C) 2008, GeoTechnologies, Vitja Makarov
7 *
8 * This code is licenced under the GPL version 2. For details see
9 * kernel-base/COPYING.
10 */
11#include <linux/module.h>
12#include <linux/profile.h>
13#include <linux/interrupt.h>
14#include <linux/time.h>
15#include <linux/timex.h>
16#include <linux/irq.h>
17#include <linux/clocksource.h>
18#include <linux/clockchips.h>
19#include <linux/cpufreq.h>
20
21#include <asm/blackfin.h>
22#include <asm/time.h>
23
24#ifdef CONFIG_CYCLES_CLOCKSOURCE
25
26/* Accelerators for sched_clock()
27 * convert from cycles(64bits) => nanoseconds (64bits)
28 * basic equation:
29 * ns = cycles / (freq / ns_per_sec)
30 * ns = cycles * (ns_per_sec / freq)
31 * ns = cycles * (10^9 / (cpu_khz * 10^3))
32 * ns = cycles * (10^6 / cpu_khz)
33 *
34 * Then we use scaling math (suggested by george@mvista.com) to get:
35 * ns = cycles * (10^6 * SC / cpu_khz) / SC
36 * ns = cycles * cyc2ns_scale / SC
37 *
38 * And since SC is a constant power of two, we can convert the div
39 * into a shift.
40 *
41 * We can use khz divisor instead of mhz to keep a better precision, since
42 * cyc2ns_scale is limited to 10^6 * 2^10, which fits in 32 bits.
43 * (mathieu.desnoyers@polymtl.ca)
44 *
45 * -johnstul@us.ibm.com "math is hard, lets go shopping!"
46 */
47
48static unsigned long cyc2ns_scale;
49#define CYC2NS_SCALE_FACTOR 10 /* 2^10, carefully chosen */
50
51static inline void set_cyc2ns_scale(unsigned long cpu_khz)
52{
53 cyc2ns_scale = (1000000 << CYC2NS_SCALE_FACTOR) / cpu_khz;
54}
55
56static inline unsigned long long cycles_2_ns(cycle_t cyc)
57{
58 return (cyc * cyc2ns_scale) >> CYC2NS_SCALE_FACTOR;
59}
60
61static cycle_t read_cycles(void)
62{
63 return get_cycles();
64}
65
66unsigned long long sched_clock(void)
67{
68 return cycles_2_ns(read_cycles());
69}
70
71static struct clocksource clocksource_bfin = {
72 .name = "bfin_cycles",
73 .rating = 350,
74 .read = read_cycles,
75 .mask = CLOCKSOURCE_MASK(64),
76 .shift = 22,
77 .flags = CLOCK_SOURCE_IS_CONTINUOUS,
78};
79
80static int __init bfin_clocksource_init(void)
81{
82 set_cyc2ns_scale(get_cclk() / 1000);
83
84 clocksource_bfin.mult = clocksource_hz2mult(get_cclk(), clocksource_bfin.shift);
85
86 if (clocksource_register(&clocksource_bfin))
87 panic("failed to register clocksource");
88
89 return 0;
90}
91
92#else
93# define bfin_clocksource_init()
94#endif
95
96static int bfin_timer_set_next_event(unsigned long cycles,
97 struct clock_event_device *evt)
98{
99 bfin_write_TCOUNT(cycles);
100 CSYNC();
101 return 0;
102}
103
104static void bfin_timer_set_mode(enum clock_event_mode mode,
105 struct clock_event_device *evt)
106{
107 switch (mode) {
108 case CLOCK_EVT_MODE_PERIODIC: {
109 unsigned long tcount = ((get_cclk() / (HZ * TIME_SCALE)) - 1);
110 bfin_write_TCNTL(TMPWR);
111 bfin_write_TSCALE(TIME_SCALE - 1);
112 CSYNC();
113 bfin_write_TPERIOD(tcount);
114 bfin_write_TCOUNT(tcount);
115 bfin_write_TCNTL(TMPWR | TMREN | TAUTORLD);
116 CSYNC();
117 break;
118 }
119 case CLOCK_EVT_MODE_ONESHOT:
120 bfin_write_TSCALE(0);
121 bfin_write_TCOUNT(0);
122 bfin_write_TCNTL(TMPWR | TMREN);
123 CSYNC();
124 break;
125 case CLOCK_EVT_MODE_UNUSED:
126 case CLOCK_EVT_MODE_SHUTDOWN:
127 bfin_write_TCNTL(0);
128 CSYNC();
129 break;
130 case CLOCK_EVT_MODE_RESUME:
131 break;
132 }
133}
134
135static void __init bfin_timer_init(void)
136{
137 /* power up the timer, but don't enable it just yet */
138 bfin_write_TCNTL(TMPWR);
139 CSYNC();
140
141 /*
142 * the TSCALE prescaler counter.
143 */
144 bfin_write_TSCALE(TIME_SCALE - 1);
145 bfin_write_TPERIOD(0);
146 bfin_write_TCOUNT(0);
147
148 /* now enable the timer */
149 CSYNC();
150}
151
152/*
153 * timer_interrupt() needs to keep up the real-time clock,
154 * as well as call the "do_timer()" routine every clocktick
155 */
156#ifdef CONFIG_CORE_TIMER_IRQ_L1
157__attribute__((l1_text))
158#endif
159irqreturn_t timer_interrupt(int irq, void *dev_id);
160
161static struct clock_event_device clockevent_bfin = {
162 .name = "bfin_core_timer",
163 .features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT,
164 .shift = 32,
165 .cpumask = CPU_MASK_CPU0,
166 .set_next_event = bfin_timer_set_next_event,
167 .set_mode = bfin_timer_set_mode,
168};
169
170static struct irqaction bfin_timer_irq = {
171 .name = "Blackfin Core Timer",
172 .flags = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
173 .handler = timer_interrupt,
174 .dev_id = &clockevent_bfin,
175};
176
177irqreturn_t timer_interrupt(int irq, void *dev_id)
178{
179 struct clock_event_device *evt = dev_id;
180 evt->event_handler(evt);
181 return IRQ_HANDLED;
182}
183
184static int __init bfin_clockevent_init(void)
185{
186 setup_irq(IRQ_CORETMR, &bfin_timer_irq);
187 bfin_timer_init();
188
189 clockevent_bfin.mult = div_sc(get_cclk(), NSEC_PER_SEC, clockevent_bfin.shift);
190 clockevent_bfin.max_delta_ns = clockevent_delta2ns(-1, &clockevent_bfin);
191 clockevent_bfin.min_delta_ns = clockevent_delta2ns(100, &clockevent_bfin);
192 clockevents_register_device(&clockevent_bfin);
193
194 return 0;
195}
196
197void __init time_init(void)
198{
199 time_t secs_since_1970 = (365 * 37 + 9) * 24 * 60 * 60; /* 1 Jan 2007 */
200
201#ifdef CONFIG_RTC_DRV_BFIN
202 /* [#2663] hack to filter junk RTC values that would cause
203 * userspace to have to deal with time values greater than
204 * 2^31 seconds (which uClibc cannot cope with yet)
205 */
206 if ((bfin_read_RTC_STAT() & 0xC0000000) == 0xC0000000) {
207 printk(KERN_NOTICE "bfin-rtc: invalid date; resetting\n");
208 bfin_write_RTC_STAT(0);
209 }
210#endif
211
212 /* Initialize xtime. From now on, xtime is updated with timer interrupts */
213 xtime.tv_sec = secs_since_1970;
214 xtime.tv_nsec = 0;
215 set_normalized_timespec(&wall_to_monotonic, -xtime.tv_sec, -xtime.tv_nsec);
216
217 bfin_clocksource_init();
218 bfin_clockevent_init();
219}
diff --git a/arch/blackfin/kernel/time.c b/arch/blackfin/kernel/time.c
index 715b3945e4c7..eb2352320454 100644
--- a/arch/blackfin/kernel/time.c
+++ b/arch/blackfin/kernel/time.c
@@ -6,9 +6,10 @@
6 * Created: 6 * Created:
7 * Description: This file contains the bfin-specific time handling details. 7 * Description: This file contains the bfin-specific time handling details.
8 * Most of the stuff is located in the machine specific files. 8 * Most of the stuff is located in the machine specific files.
9 * FIXME: (This file is subject for removal)
9 * 10 *
10 * Modified: 11 * Modified:
11 * Copyright 2004-2006 Analog Devices Inc. 12 * Copyright 2004-2008 Analog Devices Inc.
12 * 13 *
13 * Bugs: Enter bugs at http://blackfin.uclinux.org/ 14 * Bugs: Enter bugs at http://blackfin.uclinux.org/
14 * 15 *
@@ -35,6 +36,7 @@
35#include <linux/irq.h> 36#include <linux/irq.h>
36 37
37#include <asm/blackfin.h> 38#include <asm/blackfin.h>
39#include <asm/time.h>
38 40
39/* This is an NTP setting */ 41/* This is an NTP setting */
40#define TICK_SIZE (tick_nsec / 1000) 42#define TICK_SIZE (tick_nsec / 1000)
@@ -47,21 +49,6 @@ static struct irqaction bfin_timer_irq = {
47 .flags = IRQF_DISABLED 49 .flags = IRQF_DISABLED
48}; 50};
49 51
50/*
51 * The way that the Blackfin core timer works is:
52 * - CCLK is divided by a programmable 8-bit pre-scaler (TSCALE)
53 * - Every time TSCALE ticks, a 32bit is counted down (TCOUNT)
54 *
55 * If you take the fastest clock (1ns, or 1GHz to make the math work easier)
56 * 10ms is 10,000,000 clock ticks, which fits easy into a 32-bit counter
57 * (32 bit counter is 4,294,967,296ns or 4.2 seconds) so, we don't need
58 * to use TSCALE, and program it to zero (which is pass CCLK through).
59 * If you feel like using it, try to keep HZ * TIMESCALE to some
60 * value that divides easy (like power of 2).
61 */
62
63#define TIME_SCALE 1
64
65static void 52static void
66time_sched_init(irq_handler_t timer_routine) 53time_sched_init(irq_handler_t timer_routine)
67{ 54{
diff --git a/arch/blackfin/kernel/traps.c b/arch/blackfin/kernel/traps.c
index 56a67ab698c7..5b847070dae5 100644
--- a/arch/blackfin/kernel/traps.c
+++ b/arch/blackfin/kernel/traps.c
@@ -67,6 +67,8 @@ void __init trap_init(void)
67 CSYNC(); 67 CSYNC();
68} 68}
69 69
70void *saved_icplb_fault_addr, *saved_dcplb_fault_addr;
71
70int kstack_depth_to_print = 48; 72int kstack_depth_to_print = 48;
71 73
72static void decode_address(char *buf, unsigned long address) 74static void decode_address(char *buf, unsigned long address)
@@ -75,7 +77,7 @@ static void decode_address(char *buf, unsigned long address)
75 struct task_struct *p; 77 struct task_struct *p;
76 struct mm_struct *mm; 78 struct mm_struct *mm;
77 unsigned long flags, offset; 79 unsigned long flags, offset;
78 unsigned int in_exception = bfin_read_IPEND() & 0x10; 80 unsigned char in_atomic = (bfin_read_IPEND() & 0x10) || in_atomic();
79 81
80#ifdef CONFIG_KALLSYMS 82#ifdef CONFIG_KALLSYMS
81 unsigned long symsize; 83 unsigned long symsize;
@@ -117,7 +119,7 @@ static void decode_address(char *buf, unsigned long address)
117 */ 119 */
118 write_lock_irqsave(&tasklist_lock, flags); 120 write_lock_irqsave(&tasklist_lock, flags);
119 for_each_process(p) { 121 for_each_process(p) {
120 mm = (in_exception ? p->mm : get_task_mm(p)); 122 mm = (in_atomic ? p->mm : get_task_mm(p));
121 if (!mm) 123 if (!mm)
122 continue; 124 continue;
123 125
@@ -137,23 +139,36 @@ static void decode_address(char *buf, unsigned long address)
137 /* FLAT does not have its text aligned to the start of 139 /* FLAT does not have its text aligned to the start of
138 * the map while FDPIC ELF does ... 140 * the map while FDPIC ELF does ...
139 */ 141 */
140 if (current->mm && 142
141 (address > current->mm->start_code) && 143 /* before we can check flat/fdpic, we need to
142 (address < current->mm->end_code)) 144 * make sure current is valid
143 offset = address - current->mm->start_code; 145 */
144 else 146 if ((unsigned long)current >= FIXED_CODE_START &&
145 offset = (address - vma->vm_start) + (vma->vm_pgoff << PAGE_SHIFT); 147 !((unsigned long)current & 0x3)) {
146 148 if (current->mm &&
147 sprintf(buf, "<0x%p> [ %s + 0x%lx ]", 149 (address > current->mm->start_code) &&
148 (void *)address, name, offset); 150 (address < current->mm->end_code))
149 if (!in_exception) 151 offset = address - current->mm->start_code;
152 else
153 offset = (address - vma->vm_start) +
154 (vma->vm_pgoff << PAGE_SHIFT);
155
156 sprintf(buf, "<0x%p> [ %s + 0x%lx ]",
157 (void *)address, name, offset);
158 } else
159 sprintf(buf, "<0x%p> [ %s vma:0x%lx-0x%lx]",
160 (void *)address, name,
161 vma->vm_start, vma->vm_end);
162
163 if (!in_atomic)
150 mmput(mm); 164 mmput(mm);
165
151 goto done; 166 goto done;
152 } 167 }
153 168
154 vml = vml->next; 169 vml = vml->next;
155 } 170 }
156 if (!in_exception) 171 if (!in_atomic)
157 mmput(mm); 172 mmput(mm);
158 } 173 }
159 174
@@ -506,7 +521,7 @@ asmlinkage void trap_c(struct pt_regs *fp)
506 521
507 info.si_signo = sig; 522 info.si_signo = sig;
508 info.si_errno = 0; 523 info.si_errno = 0;
509 info.si_addr = (void *)fp->pc; 524 info.si_addr = (void __user *)fp->pc;
510 force_sig_info(sig, &info, current); 525 force_sig_info(sig, &info, current);
511 526
512 trace_buffer_restore(j); 527 trace_buffer_restore(j);
@@ -655,21 +670,31 @@ void dump_bfin_process(struct pt_regs *fp)
655 else if (context & 0x8000) 670 else if (context & 0x8000)
656 printk(KERN_NOTICE "Kernel process context\n"); 671 printk(KERN_NOTICE "Kernel process context\n");
657 672
658 if (current->pid && current->mm) { 673 /* Because we are crashing, and pointers could be bad, we check things
674 * pretty closely before we use them
675 */
676 if ((unsigned long)current >= FIXED_CODE_START &&
677 !((unsigned long)current & 0x3) && current->pid) {
659 printk(KERN_NOTICE "CURRENT PROCESS:\n"); 678 printk(KERN_NOTICE "CURRENT PROCESS:\n");
660 printk(KERN_NOTICE "COMM=%s PID=%d\n", 679 if (current->comm >= (char *)FIXED_CODE_START)
661 current->comm, current->pid); 680 printk(KERN_NOTICE "COMM=%s PID=%d\n",
662 681 current->comm, current->pid);
663 printk(KERN_NOTICE "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n" 682 else
664 KERN_NOTICE "BSS = 0x%p-0x%p USER-STACK = 0x%p\n" 683 printk(KERN_NOTICE "COMM= invalid\n");
665 KERN_NOTICE "\n", 684
666 (void *)current->mm->start_code, 685 if (!((unsigned long)current->mm & 0x3) && (unsigned long)current->mm >= FIXED_CODE_START)
667 (void *)current->mm->end_code, 686 printk(KERN_NOTICE "TEXT = 0x%p-0x%p DATA = 0x%p-0x%p\n"
668 (void *)current->mm->start_data, 687 KERN_NOTICE " BSS = 0x%p-0x%p USER-STACK = 0x%p\n"
669 (void *)current->mm->end_data, 688 KERN_NOTICE "\n",
670 (void *)current->mm->end_data, 689 (void *)current->mm->start_code,
671 (void *)current->mm->brk, 690 (void *)current->mm->end_code,
672 (void *)current->mm->start_stack); 691 (void *)current->mm->start_data,
692 (void *)current->mm->end_data,
693 (void *)current->mm->end_data,
694 (void *)current->mm->brk,
695 (void *)current->mm->start_stack);
696 else
697 printk(KERN_NOTICE "invalid mm\n");
673 } else 698 } else
674 printk(KERN_NOTICE "\n" KERN_NOTICE 699 printk(KERN_NOTICE "\n" KERN_NOTICE
675 "No Valid process in current context\n"); 700 "No Valid process in current context\n");
@@ -680,10 +705,7 @@ void dump_bfin_mem(struct pt_regs *fp)
680 unsigned short *addr, *erraddr, val = 0, err = 0; 705 unsigned short *addr, *erraddr, val = 0, err = 0;
681 char sti = 0, buf[6]; 706 char sti = 0, buf[6];
682 707
683 if (unlikely((fp->seqstat & SEQSTAT_EXCAUSE) == VEC_HWERR)) 708 erraddr = (void *)fp->pc;
684 erraddr = (void *)fp->pc;
685 else
686 erraddr = (void *)fp->retx;
687 709
688 printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr); 710 printk(KERN_NOTICE "return address: [0x%p]; contents of:", erraddr);
689 711
@@ -807,9 +829,9 @@ unlock:
807 829
808 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) && 830 if (((long)fp->seqstat & SEQSTAT_EXCAUSE) &&
809 (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) { 831 (((long)fp->seqstat & SEQSTAT_EXCAUSE) != VEC_HWERR)) {
810 decode_address(buf, bfin_read_DCPLB_FAULT_ADDR()); 832 decode_address(buf, saved_dcplb_fault_addr);
811 printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf); 833 printk(KERN_NOTICE "DCPLB_FAULT_ADDR: %s\n", buf);
812 decode_address(buf, bfin_read_ICPLB_FAULT_ADDR()); 834 decode_address(buf, saved_icplb_fault_addr);
813 printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf); 835 printk(KERN_NOTICE "ICPLB_FAULT_ADDR: %s\n", buf);
814 } 836 }
815 837
@@ -917,8 +939,8 @@ void panic_cplb_error(int cplb_panic, struct pt_regs *fp)
917 939
918 oops_in_progress = 1; 940 oops_in_progress = 1;
919 941
920 printk(KERN_EMERG "DCPLB_FAULT_ADDR=%p\n", (void *)bfin_read_DCPLB_FAULT_ADDR()); 942 printk(KERN_EMERG "DCPLB_FAULT_ADDR=%p\n", saved_dcplb_fault_addr);
921 printk(KERN_EMERG "ICPLB_FAULT_ADDR=%p\n", (void *)bfin_read_ICPLB_FAULT_ADDR()); 943 printk(KERN_EMERG "ICPLB_FAULT_ADDR=%p\n", saved_icplb_fault_addr);
922 dump_bfin_process(fp); 944 dump_bfin_process(fp);
923 dump_bfin_mem(fp); 945 dump_bfin_mem(fp);
924 show_regs(fp); 946 show_regs(fp);
diff --git a/arch/blackfin/kernel/vmlinux.lds.S b/arch/blackfin/kernel/vmlinux.lds.S
index cb01a9de2680..3ecc64cab3be 100644
--- a/arch/blackfin/kernel/vmlinux.lds.S
+++ b/arch/blackfin/kernel/vmlinux.lds.S
@@ -56,6 +56,10 @@ SECTIONS
56 *(.text.*) 56 *(.text.*)
57 *(.fixup) 57 *(.fixup)
58 58
59#if !L1_CODE_LENGTH
60 *(.l1.text)
61#endif
62
59 . = ALIGN(16); 63 . = ALIGN(16);
60 ___start___ex_table = .; 64 ___start___ex_table = .;
61 *(__ex_table) 65 *(__ex_table)
@@ -73,6 +77,12 @@ SECTIONS
73 ___bss_start = .; 77 ___bss_start = .;
74 *(.bss .bss.*) 78 *(.bss .bss.*)
75 *(COMMON) 79 *(COMMON)
80#if !L1_DATA_A_LENGTH
81 *(.l1.bss)
82#endif
83#if !L1_DATA_B_LENGTH
84 *(.l1.bss.B)
85#endif
76 ___bss_stop = .; 86 ___bss_stop = .;
77 } 87 }
78 88
@@ -83,6 +93,15 @@ SECTIONS
83 . = ALIGN(32); 93 . = ALIGN(32);
84 *(.data.cacheline_aligned) 94 *(.data.cacheline_aligned)
85 95
96#if !L1_DATA_A_LENGTH
97 . = ALIGN(32);
98 *(.data_l1.cacheline_aligned)
99 *(.l1.data)
100#endif
101#if !L1_DATA_B_LENGTH
102 *(.l1.data.B)
103#endif
104
86 DATA_DATA 105 DATA_DATA
87 *(.data.*) 106 *(.data.*)
88 CONSTRUCTORS 107 CONSTRUCTORS
@@ -147,64 +166,43 @@ SECTIONS
147 166
148 __l1_lma_start = .; 167 __l1_lma_start = .;
149 168
150#if L1_CODE_LENGTH
151# define LDS_L1_CODE *(.l1.text)
152#else
153# define LDS_L1_CODE
154#endif
155 .text_l1 L1_CODE_START : AT(LOADADDR(.init.ramfs) + SIZEOF(.init.ramfs)) 169 .text_l1 L1_CODE_START : AT(LOADADDR(.init.ramfs) + SIZEOF(.init.ramfs))
156 { 170 {
157 . = ALIGN(4); 171 . = ALIGN(4);
158 __stext_l1 = .; 172 __stext_l1 = .;
159 LDS_L1_CODE 173 *(.l1.text)
160 . = ALIGN(4); 174 . = ALIGN(4);
161 __etext_l1 = .; 175 __etext_l1 = .;
162 } 176 }
163 177
164#if L1_DATA_A_LENGTH
165# define LDS_L1_A_DATA *(.l1.data)
166# define LDS_L1_A_BSS *(.l1.bss)
167# define LDS_L1_A_CACHE *(.data_l1.cacheline_aligned)
168#else
169# define LDS_L1_A_DATA
170# define LDS_L1_A_BSS
171# define LDS_L1_A_CACHE
172#endif
173 .data_l1 L1_DATA_A_START : AT(LOADADDR(.text_l1) + SIZEOF(.text_l1)) 178 .data_l1 L1_DATA_A_START : AT(LOADADDR(.text_l1) + SIZEOF(.text_l1))
174 { 179 {
175 . = ALIGN(4); 180 . = ALIGN(4);
176 __sdata_l1 = .; 181 __sdata_l1 = .;
177 LDS_L1_A_DATA 182 *(.l1.data)
178 __edata_l1 = .; 183 __edata_l1 = .;
179 184
180 . = ALIGN(4); 185 . = ALIGN(4);
181 __sbss_l1 = .; 186 __sbss_l1 = .;
182 LDS_L1_A_BSS 187 *(.l1.bss)
183 188
184 . = ALIGN(32); 189 . = ALIGN(32);
185 LDS_L1_A_CACHE 190 *(.data_l1.cacheline_aligned)
186 191
187 . = ALIGN(4); 192 . = ALIGN(4);
188 __ebss_l1 = .; 193 __ebss_l1 = .;
189 } 194 }
190 195
191#if L1_DATA_B_LENGTH
192# define LDS_L1_B_DATA *(.l1.data.B)
193# define LDS_L1_B_BSS *(.l1.bss.B)
194#else
195# define LDS_L1_B_DATA
196# define LDS_L1_B_BSS
197#endif
198 .data_b_l1 L1_DATA_B_START : AT(LOADADDR(.data_l1) + SIZEOF(.data_l1)) 196 .data_b_l1 L1_DATA_B_START : AT(LOADADDR(.data_l1) + SIZEOF(.data_l1))
199 { 197 {
200 . = ALIGN(4); 198 . = ALIGN(4);
201 __sdata_b_l1 = .; 199 __sdata_b_l1 = .;
202 LDS_L1_B_DATA 200 *(.l1.data.B)
203 __edata_b_l1 = .; 201 __edata_b_l1 = .;
204 202
205 . = ALIGN(4); 203 . = ALIGN(4);
206 __sbss_b_l1 = .; 204 __sbss_b_l1 = .;
207 LDS_L1_B_BSS 205 *(.l1.bss.B)
208 206
209 . = ALIGN(4); 207 . = ALIGN(4);
210 __ebss_b_l1 = .; 208 __ebss_b_l1 = .;
@@ -223,8 +221,6 @@ SECTIONS
223 221
224 DWARF_DEBUG 222 DWARF_DEBUG
225 223
226 NOTES
227
228 /DISCARD/ : 224 /DISCARD/ :
229 { 225 {
230 EXIT_TEXT 226 EXIT_TEXT
diff --git a/arch/blackfin/mach-bf527/Makefile b/arch/blackfin/mach-bf527/Makefile
index 9f99f5d0bcd1..4eddb580319c 100644
--- a/arch/blackfin/mach-bf527/Makefile
+++ b/arch/blackfin/mach-bf527/Makefile
@@ -5,5 +5,3 @@
5extra-y := head.o 5extra-y := head.o
6 6
7obj-y := ints-priority.o dma.o 7obj-y := ints-priority.o dma.o
8
9obj-$(CONFIG_CPU_FREQ) += cpu.o
diff --git a/arch/blackfin/mach-bf527/boards/ezkit.c b/arch/blackfin/mach-bf527/boards/ezkit.c
index cf4bc0d83355..583d53811f03 100644
--- a/arch/blackfin/mach-bf527/boards/ezkit.c
+++ b/arch/blackfin/mach-bf527/boards/ezkit.c
@@ -94,7 +94,7 @@ int __init bfin_isp1761_init(void)
94{ 94{
95 unsigned int num_devices = ARRAY_SIZE(bfin_isp1761_devices); 95 unsigned int num_devices = ARRAY_SIZE(bfin_isp1761_devices);
96 96
97 printk(KERN_INFO "%s(): registering device resources\n", __FUNCTION__); 97 printk(KERN_INFO "%s(): registering device resources\n", __func__);
98 set_irq_type(ISP1761_IRQ, IRQF_TRIGGER_FALLING); 98 set_irq_type(ISP1761_IRQ, IRQF_TRIGGER_FALLING);
99 99
100 return platform_add_devices(bfin_isp1761_devices, num_devices); 100 return platform_add_devices(bfin_isp1761_devices, num_devices);
@@ -416,7 +416,7 @@ static struct platform_device net2272_bfin_device = {
416static struct mtd_partition bfin_spi_flash_partitions[] = { 416static struct mtd_partition bfin_spi_flash_partitions[] = {
417 { 417 {
418 .name = "bootloader", 418 .name = "bootloader",
419 .size = 0x00020000, 419 .size = 0x00040000,
420 .offset = 0, 420 .offset = 0,
421 .mask_flags = MTD_CAP_ROM 421 .mask_flags = MTD_CAP_ROM
422 }, { 422 }, {
@@ -707,6 +707,32 @@ static struct platform_device bfin_uart_device = {
707}; 707};
708#endif 708#endif
709 709
710#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
711static struct resource bfin_sir_resources[] = {
712#ifdef CONFIG_BFIN_SIR0
713 {
714 .start = 0xFFC00400,
715 .end = 0xFFC004FF,
716 .flags = IORESOURCE_MEM,
717 },
718#endif
719#ifdef CONFIG_BFIN_SIR1
720 {
721 .start = 0xFFC02000,
722 .end = 0xFFC020FF,
723 .flags = IORESOURCE_MEM,
724 },
725#endif
726};
727
728static struct platform_device bfin_sir_device = {
729 .name = "bfin_sir",
730 .id = 0,
731 .num_resources = ARRAY_SIZE(bfin_sir_resources),
732 .resource = bfin_sir_resources,
733};
734#endif
735
710#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE) 736#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
711static struct resource bfin_twi0_resource[] = { 737static struct resource bfin_twi0_resource[] = {
712 [0] = { 738 [0] = {
@@ -874,6 +900,10 @@ static struct platform_device *stamp_devices[] __initdata = {
874 &bfin_uart_device, 900 &bfin_uart_device,
875#endif 901#endif
876 902
903#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
904 &bfin_sir_device,
905#endif
906
877#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE) 907#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
878 &i2c_bfin_twi_device, 908 &i2c_bfin_twi_device,
879#endif 909#endif
@@ -896,7 +926,7 @@ static struct platform_device *stamp_devices[] __initdata = {
896 926
897static int __init stamp_init(void) 927static int __init stamp_init(void)
898{ 928{
899 printk(KERN_INFO "%s(): registering device resources\n", __FUNCTION__); 929 printk(KERN_INFO "%s(): registering device resources\n", __func__);
900 platform_add_devices(stamp_devices, ARRAY_SIZE(stamp_devices)); 930 platform_add_devices(stamp_devices, ARRAY_SIZE(stamp_devices));
901#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 931#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
902 spi_register_board_info(bfin_spi_board_info, 932 spi_register_board_info(bfin_spi_board_info,
diff --git a/arch/blackfin/mach-bf527/cpu.c b/arch/blackfin/mach-bf527/cpu.c
deleted file mode 100644
index 1975402b1dbc..000000000000
--- a/arch/blackfin/mach-bf527/cpu.c
+++ /dev/null
@@ -1,161 +0,0 @@
1/*
2 * File: arch/blackfin/mach-bf527/cpu.c
3 * Based on: arch/blackfin/mach-bf537/cpu.c
4 * Author: michael.kang@analog.com
5 *
6 * Created:
7 * Description: clock scaling for the bf527
8 *
9 * Modified:
10 * Copyright 2004-2007 Analog Devices Inc.
11 *
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see the file COPYING, or write
26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */
29
30#include <linux/kernel.h>
31#include <linux/types.h>
32#include <linux/init.h>
33#include <linux/cpufreq.h>
34#include <asm/dpmc.h>
35#include <linux/fs.h>
36#include <asm/bfin-global.h>
37
38/* CONFIG_CLKIN_HZ=11059200 */
39#define VCO5 (CONFIG_CLKIN_HZ*45) /*497664000 */
40#define VCO4 (CONFIG_CLKIN_HZ*36) /*398131200 */
41#define VCO3 (CONFIG_CLKIN_HZ*27) /*298598400 */
42#define VCO2 (CONFIG_CLKIN_HZ*18) /*199065600 */
43#define VCO1 (CONFIG_CLKIN_HZ*9) /*99532800 */
44#define VCO(x) VCO##x
45
46#define MFREQ(x) {VCO(x), VCO(x)/4}, {VCO(x), VCO(x)/2}, {VCO(x), VCO(x)}
47/* frequency */
48static struct cpufreq_frequency_table bf527_freq_table[] = {
49 MFREQ(1),
50 MFREQ(3),
51 {VCO4, VCO4 / 2}, {VCO4, VCO4},
52 MFREQ(5),
53 {0, CPUFREQ_TABLE_END},
54};
55
56/*
57 * dpmc_fops->ioctl()
58 * static int dpmc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
59 */
60static int bf527_getfreq(unsigned int cpu)
61{
62 unsigned long cclk_mhz;
63
64 /* The driver only support single cpu */
65 if (cpu == 0)
66 dpmc_fops.ioctl(NULL, NULL, IOCTL_GET_CORECLOCK, &cclk_mhz);
67 else
68 cclk_mhz = -1;
69
70 return cclk_mhz;
71}
72
73static int bf527_target(struct cpufreq_policy *policy,
74 unsigned int target_freq, unsigned int relation)
75{
76 unsigned long cclk_mhz;
77 unsigned long vco_mhz;
78 unsigned long flags;
79 unsigned int index;
80 struct cpufreq_freqs freqs;
81
82 if (cpufreq_frequency_table_target
83 (policy, bf527_freq_table, target_freq, relation, &index))
84 return -EINVAL;
85
86 cclk_mhz = bf527_freq_table[index].frequency;
87 vco_mhz = bf527_freq_table[index].index;
88
89 dpmc_fops.ioctl(NULL, NULL, IOCTL_CHANGE_FREQUENCY, &vco_mhz);
90 freqs.old = bf527_getfreq(0);
91 freqs.new = cclk_mhz;
92 freqs.cpu = 0;
93
94 pr_debug
95 ("cclk begin change to cclk %d,vco=%d,index=%d,target=%d,oldfreq=%d\n",
96 cclk_mhz, vco_mhz, index, target_freq, freqs.old);
97
98 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
99 local_irq_save(flags);
100 dpmc_fops.ioctl(NULL, NULL, IOCTL_SET_CCLK, &cclk_mhz);
101 local_irq_restore(flags);
102 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
103
104 vco_mhz = get_vco();
105 cclk_mhz = get_cclk();
106 return 0;
107}
108
109/* make sure that only the "userspace" governor is run -- anything else wouldn't make sense on
110 * this platform, anyway.
111 */
112static int bf527_verify_speed(struct cpufreq_policy *policy)
113{
114 return cpufreq_frequency_table_verify(policy, &bf527_freq_table);
115}
116
117static int __init __bf527_cpu_init(struct cpufreq_policy *policy)
118{
119 if (policy->cpu != 0)
120 return -EINVAL;
121
122 policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
123
124 policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
125 /*Now ,only support one cpu */
126 policy->cur = bf527_getfreq(0);
127 cpufreq_frequency_table_get_attr(bf527_freq_table, policy->cpu);
128 return cpufreq_frequency_table_cpuinfo(policy, bf527_freq_table);
129}
130
131static struct freq_attr *bf527_freq_attr[] = {
132 &cpufreq_freq_attr_scaling_available_freqs,
133 NULL,
134};
135
136static struct cpufreq_driver bf527_driver = {
137 .verify = bf527_verify_speed,
138 .target = bf527_target,
139 .get = bf527_getfreq,
140 .init = __bf527_cpu_init,
141 .name = "bf527",
142 .owner = THIS_MODULE,
143 .attr = bf527_freq_attr,
144};
145
146static int __init bf527_cpu_init(void)
147{
148 return cpufreq_register_driver(&bf527_driver);
149}
150
151static void __exit bf527_cpu_exit(void)
152{
153 cpufreq_unregister_driver(&bf527_driver);
154}
155
156MODULE_AUTHOR("Mickael Kang");
157MODULE_DESCRIPTION("cpufreq driver for bf527 CPU");
158MODULE_LICENSE("GPL");
159
160module_init(bf527_cpu_init);
161module_exit(bf527_cpu_exit);
diff --git a/arch/blackfin/mach-bf527/dma.c b/arch/blackfin/mach-bf527/dma.c
index 522de24cc394..dfd080cda787 100644
--- a/arch/blackfin/mach-bf527/dma.c
+++ b/arch/blackfin/mach-bf527/dma.c
@@ -26,10 +26,12 @@
26 * to the Free Software Foundation, Inc., 26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */ 28 */
29#include <linux/module.h>
30
29#include <asm/blackfin.h> 31#include <asm/blackfin.h>
30#include <asm/dma.h> 32#include <asm/dma.h>
31 33
32struct dma_register *base_addr[MAX_BLACKFIN_DMA_CHANNEL] = { 34struct dma_register *dma_io_base_addr[MAX_BLACKFIN_DMA_CHANNEL] = {
33 (struct dma_register *) DMA0_NEXT_DESC_PTR, 35 (struct dma_register *) DMA0_NEXT_DESC_PTR,
34 (struct dma_register *) DMA1_NEXT_DESC_PTR, 36 (struct dma_register *) DMA1_NEXT_DESC_PTR,
35 (struct dma_register *) DMA2_NEXT_DESC_PTR, 37 (struct dma_register *) DMA2_NEXT_DESC_PTR,
@@ -47,6 +49,7 @@ struct dma_register *base_addr[MAX_BLACKFIN_DMA_CHANNEL] = {
47 (struct dma_register *) MDMA_D1_NEXT_DESC_PTR, 49 (struct dma_register *) MDMA_D1_NEXT_DESC_PTR,
48 (struct dma_register *) MDMA_S1_NEXT_DESC_PTR, 50 (struct dma_register *) MDMA_S1_NEXT_DESC_PTR,
49}; 51};
52EXPORT_SYMBOL(dma_io_base_addr);
50 53
51int channel2irq(unsigned int channel) 54int channel2irq(unsigned int channel)
52{ 55{
diff --git a/arch/blackfin/mach-bf527/head.S b/arch/blackfin/mach-bf527/head.S
index cdb00a084965..57bdb3ba2fed 100644
--- a/arch/blackfin/mach-bf527/head.S
+++ b/arch/blackfin/mach-bf527/head.S
@@ -37,9 +37,6 @@
37#include <asm/mach/mem_init.h> 37#include <asm/mach/mem_init.h>
38#endif 38#endif
39 39
40.global __rambase
41.global __ramstart
42.global __ramend
43.extern ___bss_stop 40.extern ___bss_stop
44.extern ___bss_start 41.extern ___bss_start
45.extern _bf53x_relocate_l1_mem 42.extern _bf53x_relocate_l1_mem
@@ -439,18 +436,3 @@ ENTRY(_start_dma_code)
439 RTS; 436 RTS;
440ENDPROC(_start_dma_code) 437ENDPROC(_start_dma_code)
441#endif /* CONFIG_BFIN_KERNEL_CLOCK */ 438#endif /* CONFIG_BFIN_KERNEL_CLOCK */
442
443.data
444
445/*
446 * Set up the usable of RAM stuff. Size of RAM is determined then
447 * an initial stack set up at the end.
448 */
449
450.align 4
451__rambase:
452.long 0
453__ramstart:
454.long 0
455__ramend:
456.long 0
diff --git a/arch/blackfin/mach-bf533/Makefile b/arch/blackfin/mach-bf533/Makefile
index 8cce1736360d..aa9f2647ee0c 100644
--- a/arch/blackfin/mach-bf533/Makefile
+++ b/arch/blackfin/mach-bf533/Makefile
@@ -5,5 +5,3 @@
5extra-y := head.o 5extra-y := head.o
6 6
7obj-y := ints-priority.o dma.o 7obj-y := ints-priority.o dma.o
8
9obj-$(CONFIG_CPU_FREQ) += cpu.o
diff --git a/arch/blackfin/mach-bf533/boards/H8606.c b/arch/blackfin/mach-bf533/boards/H8606.c
index 97378b0a9753..7cc4864f6aaf 100644
--- a/arch/blackfin/mach-bf533/boards/H8606.c
+++ b/arch/blackfin/mach-bf533/boards/H8606.c
@@ -304,6 +304,25 @@ static struct platform_device bfin_uart_device = {
304}; 304};
305#endif 305#endif
306 306
307#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
308static struct resource bfin_sir_resources[] = {
309#ifdef CONFIG_BFIN_SIR0
310 {
311 .start = 0xFFC00400,
312 .end = 0xFFC004FF,
313 .flags = IORESOURCE_MEM,
314 },
315#endif
316};
317
318static struct platform_device bfin_sir_device = {
319 .name = "bfin_sir",
320 .id = 0,
321 .num_resources = ARRAY_SIZE(bfin_sir_resources),
322 .resource = bfin_sir_resources,
323};
324#endif
325
307#if defined(CONFIG_SERIAL_8250) || defined(CONFIG_SERIAL_8250_MODULE) 326#if defined(CONFIG_SERIAL_8250) || defined(CONFIG_SERIAL_8250_MODULE)
308 327
309#include <linux/serial_8250.h> 328#include <linux/serial_8250.h>
@@ -403,6 +422,10 @@ static struct platform_device *h8606_devices[] __initdata = {
403 &serial8250_device, 422 &serial8250_device,
404#endif 423#endif
405 424
425#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
426 &bfin_sir_device,
427#endif
428
406#if defined(CONFIG_KEYBOARD_OPENCORES) || defined(CONFIG_KEYBOARD_OPENCORES_MODULE) 429#if defined(CONFIG_KEYBOARD_OPENCORES) || defined(CONFIG_KEYBOARD_OPENCORES_MODULE)
407 &opencores_kbd_device, 430 &opencores_kbd_device,
408#endif 431#endif
@@ -411,7 +434,7 @@ static struct platform_device *h8606_devices[] __initdata = {
411static int __init H8606_init(void) 434static int __init H8606_init(void)
412{ 435{
413 printk(KERN_INFO "HV Sistemas H8606 board support by http://www.hvsistemas.com\n"); 436 printk(KERN_INFO "HV Sistemas H8606 board support by http://www.hvsistemas.com\n");
414 printk(KERN_INFO "%s(): registering device resources\n", __FUNCTION__); 437 printk(KERN_INFO "%s(): registering device resources\n", __func__);
415 platform_add_devices(h8606_devices, ARRAY_SIZE(h8606_devices)); 438 platform_add_devices(h8606_devices, ARRAY_SIZE(h8606_devices));
416#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 439#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
417 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info)); 440 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
diff --git a/arch/blackfin/mach-bf533/boards/Kconfig b/arch/blackfin/mach-bf533/boards/Kconfig
index 751de5110afc..840059241fbe 100644
--- a/arch/blackfin/mach-bf533/boards/Kconfig
+++ b/arch/blackfin/mach-bf533/boards/Kconfig
@@ -26,6 +26,12 @@ config H8606_HVSISTEMAS
26 help 26 help
27 HV Sistemas H8606 board support. 27 HV Sistemas H8606 board support.
28 28
29config BFIN532_IP0X
30 bool "IP04/IP08 IP-PBX"
31 depends on (BF532)
32 help
33 Core support for IP04/IP04 open hardware IP-PBX.
34
29config GENERIC_BF533_BOARD 35config GENERIC_BF533_BOARD
30 bool "Generic" 36 bool "Generic"
31 help 37 help
diff --git a/arch/blackfin/mach-bf533/boards/Makefile b/arch/blackfin/mach-bf533/boards/Makefile
index 54f57fb9791e..b7a1a1d79bda 100644
--- a/arch/blackfin/mach-bf533/boards/Makefile
+++ b/arch/blackfin/mach-bf533/boards/Makefile
@@ -4,6 +4,7 @@
4 4
5obj-$(CONFIG_GENERIC_BF533_BOARD) += generic_board.o 5obj-$(CONFIG_GENERIC_BF533_BOARD) += generic_board.o
6obj-$(CONFIG_BFIN533_STAMP) += stamp.o 6obj-$(CONFIG_BFIN533_STAMP) += stamp.o
7obj-$(CONFIG_BFIN532_IP0X) += ip0x.o
7obj-$(CONFIG_BFIN533_EZKIT) += ezkit.o 8obj-$(CONFIG_BFIN533_EZKIT) += ezkit.o
8obj-$(CONFIG_BFIN533_BLUETECHNIX_CM) += cm_bf533.o 9obj-$(CONFIG_BFIN533_BLUETECHNIX_CM) += cm_bf533.o
9obj-$(CONFIG_H8606_HVSISTEMAS) += H8606.o 10obj-$(CONFIG_H8606_HVSISTEMAS) += H8606.o
diff --git a/arch/blackfin/mach-bf533/boards/cm_bf533.c b/arch/blackfin/mach-bf533/boards/cm_bf533.c
index 886f260d9359..a03149c72681 100644
--- a/arch/blackfin/mach-bf533/boards/cm_bf533.c
+++ b/arch/blackfin/mach-bf533/boards/cm_bf533.c
@@ -234,6 +234,25 @@ static struct platform_device bfin_uart_device = {
234}; 234};
235#endif 235#endif
236 236
237#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
238static struct resource bfin_sir_resources[] = {
239#ifdef CONFIG_BFIN_SIR0
240 {
241 .start = 0xFFC00400,
242 .end = 0xFFC004FF,
243 .flags = IORESOURCE_MEM,
244 },
245#endif
246};
247
248static struct platform_device bfin_sir_device = {
249 .name = "bfin_sir",
250 .id = 0,
251 .num_resources = ARRAY_SIZE(bfin_sir_resources),
252 .resource = bfin_sir_resources,
253};
254#endif
255
237#if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE) 256#if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
238static struct platform_device bfin_sport0_uart_device = { 257static struct platform_device bfin_sport0_uart_device = {
239 .name = "bfin-sport-uart", 258 .name = "bfin-sport-uart",
@@ -327,6 +346,10 @@ static struct platform_device *cm_bf533_devices[] __initdata = {
327 &bfin_uart_device, 346 &bfin_uart_device,
328#endif 347#endif
329 348
349#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
350 &bfin_sir_device,
351#endif
352
330#if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE) 353#if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
331 &bfin_sport0_uart_device, 354 &bfin_sport0_uart_device,
332 &bfin_sport1_uart_device, 355 &bfin_sport1_uart_device,
@@ -355,7 +378,7 @@ static struct platform_device *cm_bf533_devices[] __initdata = {
355 378
356static int __init cm_bf533_init(void) 379static int __init cm_bf533_init(void)
357{ 380{
358 printk(KERN_INFO "%s(): registering device resources\n", __FUNCTION__); 381 printk(KERN_INFO "%s(): registering device resources\n", __func__);
359 platform_add_devices(cm_bf533_devices, ARRAY_SIZE(cm_bf533_devices)); 382 platform_add_devices(cm_bf533_devices, ARRAY_SIZE(cm_bf533_devices));
360#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 383#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
361 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info)); 384 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
diff --git a/arch/blackfin/mach-bf533/boards/ezkit.c b/arch/blackfin/mach-bf533/boards/ezkit.c
index 241b5a20a36a..08a7943949ae 100644
--- a/arch/blackfin/mach-bf533/boards/ezkit.c
+++ b/arch/blackfin/mach-bf533/boards/ezkit.c
@@ -237,6 +237,25 @@ static struct platform_device bfin_uart_device = {
237}; 237};
238#endif 238#endif
239 239
240#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
241static struct resource bfin_sir_resources[] = {
242#ifdef CONFIG_BFIN_SIR0
243 {
244 .start = 0xFFC00400,
245 .end = 0xFFC004FF,
246 .flags = IORESOURCE_MEM,
247 },
248#endif
249};
250
251static struct platform_device bfin_sir_device = {
252 .name = "bfin_sir",
253 .id = 0,
254 .num_resources = ARRAY_SIZE(bfin_sir_resources),
255 .resource = bfin_sir_resources,
256};
257#endif
258
240#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE) 259#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
241#define PATA_INT 55 260#define PATA_INT 55
242 261
@@ -352,6 +371,10 @@ static struct platform_device *ezkit_devices[] __initdata = {
352 &bfin_uart_device, 371 &bfin_uart_device,
353#endif 372#endif
354 373
374#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
375 &bfin_sir_device,
376#endif
377
355#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE) 378#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
356 &bfin_pata_device, 379 &bfin_pata_device,
357#endif 380#endif
@@ -369,7 +392,7 @@ static struct platform_device *ezkit_devices[] __initdata = {
369 392
370static int __init ezkit_init(void) 393static int __init ezkit_init(void)
371{ 394{
372 printk(KERN_INFO "%s(): registering device resources\n", __FUNCTION__); 395 printk(KERN_INFO "%s(): registering device resources\n", __func__);
373 platform_add_devices(ezkit_devices, ARRAY_SIZE(ezkit_devices)); 396 platform_add_devices(ezkit_devices, ARRAY_SIZE(ezkit_devices));
374#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 397#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
375 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info)); 398 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
diff --git a/arch/blackfin/mach-bf533/boards/generic_board.c b/arch/blackfin/mach-bf533/boards/generic_board.c
index e359a0d6467f..82b1f6a60e3f 100644
--- a/arch/blackfin/mach-bf533/boards/generic_board.c
+++ b/arch/blackfin/mach-bf533/boards/generic_board.c
@@ -84,7 +84,7 @@ static struct platform_device *generic_board_devices[] __initdata = {
84 84
85static int __init generic_board_init(void) 85static int __init generic_board_init(void)
86{ 86{
87 printk(KERN_INFO "%s(): registering device resources\n", __FUNCTION__); 87 printk(KERN_INFO "%s(): registering device resources\n", __func__);
88 return platform_add_devices(generic_board_devices, ARRAY_SIZE(generic_board_devices)); 88 return platform_add_devices(generic_board_devices, ARRAY_SIZE(generic_board_devices));
89} 89}
90 90
diff --git a/arch/blackfin/mach-bf533/boards/ip0x.c b/arch/blackfin/mach-bf533/boards/ip0x.c
new file mode 100644
index 000000000000..5864892de314
--- /dev/null
+++ b/arch/blackfin/mach-bf533/boards/ip0x.c
@@ -0,0 +1,303 @@
1/*
2 * File: arch/blackfin/mach-bf533/ip0x.c
3 * Based on: arch/blackfin/mach-bf533/bf1.c
4 * Based on: arch/blackfin/mach-bf533/stamp.c
5 * Author: Ivan Danov <idanov@gmail.com>
6 * Modified for IP0X David Rowe
7 *
8 * Created: 2007
9 * Description: Board info file for the IP04/IP08 boards, which
10 * are derived from the BlackfinOne V2.0 boards.
11 *
12 * Modified:
13 * COpyright 2007 David Rowe
14 * Copyright 2006 Intratrade Ltd.
15 * Copyright 2005 National ICT Australia (NICTA)
16 * Copyright 2004-2006 Analog Devices Inc.
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, see the file COPYING, or write
30 * to the Free Software Foundation, Inc.,
31 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
32 */
33
34#include <linux/device.h>
35#include <linux/platform_device.h>
36#include <linux/mtd/mtd.h>
37#include <linux/mtd/partitions.h>
38#include <linux/spi/spi.h>
39#include <linux/spi/flash.h>
40#if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE)
41#include <linux/usb/isp1362.h>
42#endif
43#include <asm/irq.h>
44#include <asm/bfin5xx_spi.h>
45
46/*
47 * Name the Board for the /proc/cpuinfo
48 */
49const char bfin_board_name[] = "IP04/IP08";
50
51/*
52 * Driver needs to know address, irq and flag pin.
53 */
54#if defined(CONFIG_BFIN532_IP0X)
55#if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE)
56
57#include <linux/dm9000.h>
58
59static struct resource dm9000_resource1[] = {
60 {
61 .start = 0x20100000,
62 .end = 0x20100000 + 1,
63 .flags = IORESOURCE_MEM
64 },{
65 .start = 0x20100000 + 2,
66 .end = 0x20100000 + 3,
67 .flags = IORESOURCE_MEM
68 },{
69 .start = IRQ_PF15,
70 .end = IRQ_PF15,
71 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE
72 }
73};
74
75static struct resource dm9000_resource2[] = {
76 {
77 .start = 0x20200000,
78 .end = 0x20200000 + 1,
79 .flags = IORESOURCE_MEM
80 },{
81 .start = 0x20200000 + 2,
82 .end = 0x20200000 + 3,
83 .flags = IORESOURCE_MEM
84 },{
85 .start = IRQ_PF14,
86 .end = IRQ_PF14,
87 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHEDGE
88 }
89};
90
91/*
92* for the moment we limit ourselves to 16bit IO until some
93* better IO routines can be written and tested
94*/
95static struct dm9000_plat_data dm9000_platdata1 = {
96 .flags = DM9000_PLATF_16BITONLY,
97};
98
99static struct platform_device dm9000_device1 = {
100 .name = "dm9000",
101 .id = 0,
102 .num_resources = ARRAY_SIZE(dm9000_resource1),
103 .resource = dm9000_resource1,
104 .dev = {
105 .platform_data = &dm9000_platdata1,
106 }
107};
108
109static struct dm9000_plat_data dm9000_platdata2 = {
110 .flags = DM9000_PLATF_16BITONLY,
111};
112
113static struct platform_device dm9000_device2 = {
114 .name = "dm9000",
115 .id = 1,
116 .num_resources = ARRAY_SIZE(dm9000_resource2),
117 .resource = dm9000_resource2,
118 .dev = {
119 .platform_data = &dm9000_platdata2,
120 }
121};
122
123#endif
124#endif
125
126
127#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
128/* all SPI peripherals info goes here */
129
130#if defined(CONFIG_SPI_MMC) || defined(CONFIG_SPI_MMC_MODULE)
131static struct bfin5xx_spi_chip spi_mmc_chip_info = {
132/*
133 * CPOL (Clock Polarity)
134 * 0 - Active high SCK
135 * 1 - Active low SCK
136 * CPHA (Clock Phase) Selects transfer format and operation mode
137 * 0 - SCLK toggles from middle of the first data bit, slave select
138 * pins controlled by hardware.
139 * 1 - SCLK toggles from beginning of first data bit, slave select
140 * pins controller by user software.
141 * .ctl_reg = 0x1c00, * CPOL=1,CPHA=1,Sandisk 1G work
142 * NO NO .ctl_reg = 0x1800, * CPOL=1,CPHA=0
143 * NO NO .ctl_reg = 0x1400, * CPOL=0,CPHA=1
144 */
145 .ctl_reg = 0x1000, /* CPOL=0,CPHA=0,Sandisk 1G work */
146 .enable_dma = 0, /* if 1 - block!!! */
147 .bits_per_word = 8,
148 .cs_change_per_word = 0,
149};
150#endif
151
152/* Notice: for blackfin, the speed_hz is the value of register
153 * SPI_BAUD, not the real baudrate */
154static struct spi_board_info bfin_spi_board_info[] __initdata = {
155#if defined(CONFIG_SPI_MMC) || defined(CONFIG_SPI_MMC_MODULE)
156 {
157 .modalias = "spi_mmc",
158 .max_speed_hz = 2,
159 .bus_num = 1,
160 .chip_select = CONFIG_SPI_MMC_CS_CHAN,
161 .platform_data = NULL,
162 .controller_data = &spi_mmc_chip_info,
163 },
164#endif
165};
166
167/* SPI controller data */
168static struct bfin5xx_spi_master spi_bfin_master_info = {
169 .num_chipselect = 8,
170 .enable_dma = 1, /* master has the ability to do dma transfer */
171};
172
173static struct platform_device spi_bfin_master_device = {
174 .name = "bfin-spi-master",
175 .id = 1, /* Bus number */
176 .dev = {
177 .platform_data = &spi_bfin_master_info, /* Passed to driver */
178 },
179};
180#endif /* spi master and devices */
181
182#if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
183static struct resource bfin_uart_resources[] = {
184 {
185 .start = 0xFFC00400,
186 .end = 0xFFC004FF,
187 .flags = IORESOURCE_MEM,
188 },
189};
190
191static struct platform_device bfin_uart_device = {
192 .name = "bfin-uart",
193 .id = 1,
194 .num_resources = ARRAY_SIZE(bfin_uart_resources),
195 .resource = bfin_uart_resources,
196};
197#endif
198
199#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
200static struct resource bfin_sir_resources[] = {
201#ifdef CONFIG_BFIN_SIR0
202 {
203 .start = 0xFFC00400,
204 .end = 0xFFC004FF,
205 .flags = IORESOURCE_MEM,
206 },
207#endif
208};
209
210static struct platform_device bfin_sir_device = {
211 .name = "bfin_sir",
212 .id = 0,
213 .num_resources = ARRAY_SIZE(bfin_sir_resources),
214 .resource = bfin_sir_resources,
215};
216#endif
217
218#if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE)
219static struct resource isp1362_hcd_resources[] = {
220 {
221 .start = 0x20300000,
222 .end = 0x20300000 + 1,
223 .flags = IORESOURCE_MEM,
224 },{
225 .start = 0x20300000 + 2,
226 .end = 0x20300000 + 3,
227 .flags = IORESOURCE_MEM,
228 },{
229 .start = IRQ_PF11,
230 .end = IRQ_PF11,
231 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
232 },
233};
234
235static struct isp1362_platform_data isp1362_priv = {
236 .sel15Kres = 1,
237 .clknotstop = 0,
238 .oc_enable = 0, /* external OC */
239 .int_act_high = 0,
240 .int_edge_triggered = 0,
241 .remote_wakeup_connected = 0,
242 .no_power_switching = 1,
243 .power_switching_mode = 0,
244};
245
246static struct platform_device isp1362_hcd_device = {
247 .name = "isp1362-hcd",
248 .id = 0,
249 .dev = {
250 .platform_data = &isp1362_priv,
251 },
252 .num_resources = ARRAY_SIZE(isp1362_hcd_resources),
253 .resource = isp1362_hcd_resources,
254};
255#endif
256
257
258static struct platform_device *ip0x_devices[] __initdata = {
259#if defined(CONFIG_BFIN532_IP0X)
260#if defined(CONFIG_DM9000) || defined(CONFIG_DM9000_MODULE)
261 &dm9000_device1,
262 &dm9000_device2,
263#endif
264#endif
265
266#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
267 &spi_bfin_master_device,
268#endif
269
270#if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
271 &bfin_uart_device,
272#endif
273
274#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
275 &bfin_sir_device,
276#endif
277
278#if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE)
279 &isp1362_hcd_device,
280#endif
281};
282
283static int __init ip0x_init(void)
284{
285 int i;
286
287 printk(KERN_INFO "%s(): registering device resources\n", __func__);
288 platform_add_devices(ip0x_devices, ARRAY_SIZE(ip0x_devices));
289
290#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
291 for (i = 0; i < ARRAY_SIZE(bfin_spi_board_info); ++i) {
292 int j = 1 << bfin_spi_board_info[i].chip_select;
293 /* set spi cs to 1 */
294 bfin_write_FIO_DIR(bfin_read_FIO_DIR() | j);
295 bfin_write_FIO_FLAG_S(j);
296 }
297 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
298#endif
299
300 return 0;
301}
302
303arch_initcall(ip0x_init);
diff --git a/arch/blackfin/mach-bf533/boards/stamp.c b/arch/blackfin/mach-bf533/boards/stamp.c
index b2ac4816ae62..fddce32901a2 100644
--- a/arch/blackfin/mach-bf533/boards/stamp.c
+++ b/arch/blackfin/mach-bf533/boards/stamp.c
@@ -40,6 +40,7 @@
40#endif 40#endif
41#include <linux/ata_platform.h> 41#include <linux/ata_platform.h>
42#include <linux/irq.h> 42#include <linux/irq.h>
43#include <linux/i2c.h>
43#include <asm/dma.h> 44#include <asm/dma.h>
44#include <asm/bfin5xx_spi.h> 45#include <asm/bfin5xx_spi.h>
45#include <asm/reboot.h> 46#include <asm/reboot.h>
@@ -109,6 +110,7 @@ static struct platform_device net2272_bfin_device = {
109}; 110};
110#endif 111#endif
111 112
113#if defined(CONFIG_MTD_BF5xx) || defined(CONFIG_MTD_BF5xx_MODULE)
112static struct mtd_partition stamp_partitions[] = { 114static struct mtd_partition stamp_partitions[] = {
113 { 115 {
114 .name = "Bootloader", 116 .name = "Bootloader",
@@ -152,6 +154,7 @@ static struct platform_device stamp_flash_device = {
152 .num_resources = ARRAY_SIZE(stamp_flash_resource), 154 .num_resources = ARRAY_SIZE(stamp_flash_resource),
153 .resource = stamp_flash_resource, 155 .resource = stamp_flash_resource,
154}; 156};
157#endif
155 158
156#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 159#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
157/* all SPI peripherals info goes here */ 160/* all SPI peripherals info goes here */
@@ -367,6 +370,25 @@ static struct platform_device bfin_uart_device = {
367}; 370};
368#endif 371#endif
369 372
373#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
374static struct resource bfin_sir_resources[] = {
375#ifdef CONFIG_BFIN_SIR0
376 {
377 .start = 0xFFC00400,
378 .end = 0xFFC004FF,
379 .flags = IORESOURCE_MEM,
380 },
381#endif
382};
383
384static struct platform_device bfin_sir_device = {
385 .name = "bfin_sir",
386 .id = 0,
387 .num_resources = ARRAY_SIZE(bfin_sir_resources),
388 .resource = bfin_sir_resources,
389};
390#endif
391
370#if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE) 392#if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
371static struct platform_device bfin_sport0_uart_device = { 393static struct platform_device bfin_sport0_uart_device = {
372 .name = "bfin-sport-uart", 394 .name = "bfin-sport-uart",
@@ -472,6 +494,31 @@ static struct platform_device i2c_gpio_device = {
472}; 494};
473#endif 495#endif
474 496
497#ifdef CONFIG_I2C_BOARDINFO
498static struct i2c_board_info __initdata bfin_i2c_board_info[] = {
499#if defined(CONFIG_JOYSTICK_AD7142) || defined(CONFIG_JOYSTICK_AD7142_MODULE)
500 {
501 I2C_BOARD_INFO("ad7142_joystick", 0x2C),
502 .type = "ad7142_joystick",
503 .irq = 39,
504 },
505#endif
506#if defined(CONFIG_TWI_LCD) || defined(CONFIG_TWI_LCD_MODULE)
507 {
508 I2C_BOARD_INFO("pcf8574_lcd", 0x22),
509 .type = "pcf8574_lcd",
510 },
511#endif
512#if defined(CONFIG_TWI_KEYPAD) || defined(CONFIG_TWI_KEYPAD_MODULE)
513 {
514 I2C_BOARD_INFO("pcf8574_keypad", 0x27),
515 .type = "pcf8574_keypad",
516 .irq = 39,
517 },
518#endif
519};
520#endif
521
475static struct platform_device *stamp_devices[] __initdata = { 522static struct platform_device *stamp_devices[] __initdata = {
476#if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE) 523#if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
477 &rtc_device, 524 &rtc_device,
@@ -497,6 +544,10 @@ static struct platform_device *stamp_devices[] __initdata = {
497 &bfin_uart_device, 544 &bfin_uart_device,
498#endif 545#endif
499 546
547#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
548 &bfin_sir_device,
549#endif
550
500#if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE) 551#if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
501 &bfin_sport0_uart_device, 552 &bfin_sport0_uart_device,
502 &bfin_sport1_uart_device, 553 &bfin_sport1_uart_device,
@@ -515,14 +566,23 @@ static struct platform_device *stamp_devices[] __initdata = {
515#endif 566#endif
516 567
517 &bfin_gpios_device, 568 &bfin_gpios_device,
569
570#if defined(CONFIG_MTD_BF5xx) || defined(CONFIG_MTD_BF5xx_MODULE)
518 &stamp_flash_device, 571 &stamp_flash_device,
572#endif
519}; 573};
520 574
521static int __init stamp_init(void) 575static int __init stamp_init(void)
522{ 576{
523 int ret; 577 int ret;
524 578
525 printk(KERN_INFO "%s(): registering device resources\n", __FUNCTION__); 579 printk(KERN_INFO "%s(): registering device resources\n", __func__);
580
581#ifdef CONFIG_I2C_BOARDINFO
582 i2c_register_board_info(0, bfin_i2c_board_info,
583 ARRAY_SIZE(bfin_i2c_board_info));
584#endif
585
526 ret = platform_add_devices(stamp_devices, ARRAY_SIZE(stamp_devices)); 586 ret = platform_add_devices(stamp_devices, ARRAY_SIZE(stamp_devices));
527 if (ret < 0) 587 if (ret < 0)
528 return ret; 588 return ret;
diff --git a/arch/blackfin/mach-bf533/cpu.c b/arch/blackfin/mach-bf533/cpu.c
deleted file mode 100644
index b7a0e0fbd9af..000000000000
--- a/arch/blackfin/mach-bf533/cpu.c
+++ /dev/null
@@ -1,158 +0,0 @@
1/*
2 * File: arch/blackfin/mach-bf533/cpu.c
3 * Based on:
4 * Author: michael.kang@analog.com
5 *
6 * Created:
7 * Description: clock scaling for the bf533
8 *
9 * Modified:
10 * Copyright 2004-2006 Analog Devices Inc.
11 *
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see the file COPYING, or write
26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */
29
30#include <linux/kernel.h>
31#include <linux/types.h>
32#include <linux/init.h>
33#include <linux/cpufreq.h>
34#include <asm/dpmc.h>
35#include <linux/fs.h>
36#include <asm/bfin-global.h>
37
38/* CONFIG_CLKIN_HZ=11059200 */
39#define VCO5 (CONFIG_CLKIN_HZ*45) /*497664000 */
40#define VCO4 (CONFIG_CLKIN_HZ*36) /*398131200 */
41#define VCO3 (CONFIG_CLKIN_HZ*27) /*298598400 */
42#define VCO2 (CONFIG_CLKIN_HZ*18) /*199065600 */
43#define VCO1 (CONFIG_CLKIN_HZ*9) /*99532800 */
44#define VCO(x) VCO##x
45
46#define FREQ(x) {VCO(x),VCO(x)/4},{VCO(x),VCO(x)/2},{VCO(x),VCO(x)}
47/* frequency */
48static struct cpufreq_frequency_table bf533_freq_table[] = {
49 FREQ(1),
50 FREQ(3),
51 {VCO4, VCO4 / 2}, {VCO4, VCO4},
52 FREQ(5),
53 {0, CPUFREQ_TABLE_END},
54};
55
56/*
57 * dpmc_fops->ioctl()
58 * static int dpmc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
59 */
60static int bf533_getfreq(unsigned int cpu)
61{
62 unsigned long cclk_mhz, vco_mhz;
63
64 /* The driver only support single cpu */
65 if (cpu == 0)
66 dpmc_fops.ioctl(NULL, NULL, IOCTL_GET_CORECLOCK, &cclk_mhz);
67 else
68 cclk_mhz = -1;
69 return cclk_mhz;
70}
71
72static int bf533_target(struct cpufreq_policy *policy,
73 unsigned int target_freq, unsigned int relation)
74{
75 unsigned long cclk_mhz;
76 unsigned long vco_mhz;
77 unsigned long flags;
78 unsigned int index, vco_index;
79 int i;
80
81 struct cpufreq_freqs freqs;
82 if (cpufreq_frequency_table_target(policy, bf533_freq_table, target_freq, relation, &index))
83 return -EINVAL;
84 cclk_mhz = bf533_freq_table[index].frequency;
85 vco_mhz = bf533_freq_table[index].index;
86
87 dpmc_fops.ioctl(NULL, NULL, IOCTL_CHANGE_FREQUENCY, &vco_mhz);
88 freqs.old = bf533_getfreq(0);
89 freqs.new = cclk_mhz;
90 freqs.cpu = 0;
91
92 pr_debug("cclk begin change to cclk %d,vco=%d,index=%d,target=%d,oldfreq=%d\n",
93 cclk_mhz, vco_mhz, index, target_freq, freqs.old);
94
95 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
96 local_irq_save(flags);
97 dpmc_fops.ioctl(NULL, NULL, IOCTL_SET_CCLK, &cclk_mhz);
98 local_irq_restore(flags);
99 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
100
101 vco_mhz = get_vco();
102 cclk_mhz = get_cclk();
103 return 0;
104}
105
106/* make sure that only the "userspace" governor is run -- anything else wouldn't make sense on
107 * this platform, anyway.
108 */
109static int bf533_verify_speed(struct cpufreq_policy *policy)
110{
111 return cpufreq_frequency_table_verify(policy, &bf533_freq_table);
112}
113
114static int __init __bf533_cpu_init(struct cpufreq_policy *policy)
115{
116 int result;
117
118 if (policy->cpu != 0)
119 return -EINVAL;
120
121 policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
122 /*Now ,only support one cpu */
123 policy->cur = bf533_getfreq(0);
124 cpufreq_frequency_table_get_attr(bf533_freq_table, policy->cpu);
125 return cpufreq_frequency_table_cpuinfo(policy, bf533_freq_table);
126}
127
128static struct freq_attr *bf533_freq_attr[] = {
129 &cpufreq_freq_attr_scaling_available_freqs,
130 NULL,
131};
132
133static struct cpufreq_driver bf533_driver = {
134 .verify = bf533_verify_speed,
135 .target = bf533_target,
136 .get = bf533_getfreq,
137 .init = __bf533_cpu_init,
138 .name = "bf533",
139 .owner = THIS_MODULE,
140 .attr = bf533_freq_attr,
141};
142
143static int __init bf533_cpu_init(void)
144{
145 return cpufreq_register_driver(&bf533_driver);
146}
147
148static void __exit bf533_cpu_exit(void)
149{
150 cpufreq_unregister_driver(&bf533_driver);
151}
152
153MODULE_AUTHOR("Mickael Kang");
154MODULE_DESCRIPTION("cpufreq driver for BF533 CPU");
155MODULE_LICENSE("GPL");
156
157module_init(bf533_cpu_init);
158module_exit(bf533_cpu_exit);
diff --git a/arch/blackfin/mach-bf533/dma.c b/arch/blackfin/mach-bf533/dma.c
index 6c909cf4f7bf..28655c1cb7dc 100644
--- a/arch/blackfin/mach-bf533/dma.c
+++ b/arch/blackfin/mach-bf533/dma.c
@@ -26,10 +26,12 @@
26 * to the Free Software Foundation, Inc., 26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */ 28 */
29#include <linux/module.h>
30
29#include <asm/blackfin.h> 31#include <asm/blackfin.h>
30#include <asm/dma.h> 32#include <asm/dma.h>
31 33
32struct dma_register *base_addr[MAX_BLACKFIN_DMA_CHANNEL] = { 34struct dma_register *dma_io_base_addr[MAX_BLACKFIN_DMA_CHANNEL] = {
33 (struct dma_register *) DMA0_NEXT_DESC_PTR, 35 (struct dma_register *) DMA0_NEXT_DESC_PTR,
34 (struct dma_register *) DMA1_NEXT_DESC_PTR, 36 (struct dma_register *) DMA1_NEXT_DESC_PTR,
35 (struct dma_register *) DMA2_NEXT_DESC_PTR, 37 (struct dma_register *) DMA2_NEXT_DESC_PTR,
@@ -43,6 +45,7 @@ struct dma_register *base_addr[MAX_BLACKFIN_DMA_CHANNEL] = {
43 (struct dma_register *) MDMA_D1_NEXT_DESC_PTR, 45 (struct dma_register *) MDMA_D1_NEXT_DESC_PTR,
44 (struct dma_register *) MDMA_S1_NEXT_DESC_PTR, 46 (struct dma_register *) MDMA_S1_NEXT_DESC_PTR,
45}; 47};
48EXPORT_SYMBOL(dma_io_base_addr);
46 49
47int channel2irq(unsigned int channel) 50int channel2irq(unsigned int channel)
48{ 51{
diff --git a/arch/blackfin/mach-bf533/head.S b/arch/blackfin/mach-bf533/head.S
index 1ded945a6fa0..1295deac00a4 100644
--- a/arch/blackfin/mach-bf533/head.S
+++ b/arch/blackfin/mach-bf533/head.S
@@ -36,9 +36,6 @@
36#include <asm/mach/mem_init.h> 36#include <asm/mach/mem_init.h>
37#endif 37#endif
38 38
39.global __rambase
40.global __ramstart
41.global __ramend
42.extern ___bss_stop 39.extern ___bss_stop
43.extern ___bss_start 40.extern ___bss_start
44.extern _bf53x_relocate_l1_mem 41.extern _bf53x_relocate_l1_mem
@@ -151,26 +148,26 @@ ENTRY(__start)
151 148
152 /* Initialise UART - when booting from u-boot, the UART is not disabled 149 /* Initialise UART - when booting from u-boot, the UART is not disabled
153 * so if we dont initalize here, our serial console gets hosed */ 150 * so if we dont initalize here, our serial console gets hosed */
154 p0.h = hi(UART_LCR); 151 p0.h = hi(BFIN_UART_LCR);
155 p0.l = lo(UART_LCR); 152 p0.l = lo(BFIN_UART_LCR);
156 r0 = 0x0(Z); 153 r0 = 0x0(Z);
157 w[p0] = r0.L; /* To enable DLL writes */ 154 w[p0] = r0.L; /* To enable DLL writes */
158 ssync; 155 ssync;
159 156
160 p0.h = hi(UART_DLL); 157 p0.h = hi(BFIN_UART_DLL);
161 p0.l = lo(UART_DLL); 158 p0.l = lo(BFIN_UART_DLL);
162 r0 = 0x0(Z); 159 r0 = 0x0(Z);
163 w[p0] = r0.L; 160 w[p0] = r0.L;
164 ssync; 161 ssync;
165 162
166 p0.h = hi(UART_DLH); 163 p0.h = hi(BFIN_UART_DLH);
167 p0.l = lo(UART_DLH); 164 p0.l = lo(BFIN_UART_DLH);
168 r0 = 0x00(Z); 165 r0 = 0x00(Z);
169 w[p0] = r0.L; 166 w[p0] = r0.L;
170 ssync; 167 ssync;
171 168
172 p0.h = hi(UART_GCTL); 169 p0.h = hi(BFIN_UART_GCTL);
173 p0.l = lo(UART_GCTL); 170 p0.l = lo(BFIN_UART_GCTL);
174 r0 = 0x0(Z); 171 r0 = 0x0(Z);
175 w[p0] = r0.L; /* To enable UART clock */ 172 w[p0] = r0.L; /* To enable UART clock */
176 ssync; 173 ssync;
@@ -431,18 +428,3 @@ ENTRY(_start_dma_code)
431 RTS; 428 RTS;
432ENDPROC(_start_dma_code) 429ENDPROC(_start_dma_code)
433#endif /* CONFIG_BFIN_KERNEL_CLOCK */ 430#endif /* CONFIG_BFIN_KERNEL_CLOCK */
434
435.data
436
437/*
438 * Set up the usable of RAM stuff. Size of RAM is determined then
439 * an initial stack set up at the end.
440 */
441
442.align 4
443__rambase:
444.long 0
445__ramstart:
446.long 0
447__ramend:
448.long 0
diff --git a/arch/blackfin/mach-bf537/Makefile b/arch/blackfin/mach-bf537/Makefile
index 7e7c9c8ac5b2..68e5478e95a9 100644
--- a/arch/blackfin/mach-bf537/Makefile
+++ b/arch/blackfin/mach-bf537/Makefile
@@ -5,5 +5,3 @@
5extra-y := head.o 5extra-y := head.o
6 6
7obj-y := ints-priority.o dma.o 7obj-y := ints-priority.o dma.o
8
9obj-$(CONFIG_CPU_FREQ) += cpu.o
diff --git a/arch/blackfin/mach-bf537/boards/cm_bf537.c b/arch/blackfin/mach-bf537/boards/cm_bf537.c
index f7c1f964f13b..d8a23cd9b9ed 100644
--- a/arch/blackfin/mach-bf537/boards/cm_bf537.c
+++ b/arch/blackfin/mach-bf537/boards/cm_bf537.c
@@ -325,6 +325,54 @@ static struct platform_device bfin_uart_device = {
325}; 325};
326#endif 326#endif
327 327
328#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
329static struct resource bfin_sir_resources[] = {
330#ifdef CONFIG_BFIN_SIR0
331 {
332 .start = 0xFFC00400,
333 .end = 0xFFC004FF,
334 .flags = IORESOURCE_MEM,
335 },
336#endif
337#ifdef CONFIG_BFIN_SIR1
338 {
339 .start = 0xFFC02000,
340 .end = 0xFFC020FF,
341 .flags = IORESOURCE_MEM,
342 },
343#endif
344};
345
346static struct platform_device bfin_sir_device = {
347 .name = "bfin_sir",
348 .id = 0,
349 .num_resources = ARRAY_SIZE(bfin_sir_resources),
350 .resource = bfin_sir_resources,
351};
352#endif
353
354#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
355static struct resource bfin_twi0_resource[] = {
356 [0] = {
357 .start = TWI0_REGBASE,
358 .end = TWI0_REGBASE,
359 .flags = IORESOURCE_MEM,
360 },
361 [1] = {
362 .start = IRQ_TWI,
363 .end = IRQ_TWI,
364 .flags = IORESOURCE_IRQ,
365 },
366};
367
368static struct platform_device i2c_bfin_twi_device = {
369 .name = "i2c-bfin-twi",
370 .id = 0,
371 .num_resources = ARRAY_SIZE(bfin_twi0_resource),
372 .resource = bfin_twi0_resource,
373};
374#endif
375
328#if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE) 376#if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
329static struct platform_device bfin_sport0_uart_device = { 377static struct platform_device bfin_sport0_uart_device = {
330 .name = "bfin-sport-uart", 378 .name = "bfin-sport-uart",
@@ -393,6 +441,14 @@ static struct platform_device *cm_bf537_devices[] __initdata = {
393 &bfin_uart_device, 441 &bfin_uart_device,
394#endif 442#endif
395 443
444#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
445 &bfin_sir_device,
446#endif
447
448#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
449 &i2c_bfin_twi_device,
450#endif
451
396#if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE) 452#if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
397 &bfin_sport0_uart_device, 453 &bfin_sport0_uart_device,
398 &bfin_sport1_uart_device, 454 &bfin_sport1_uart_device,
@@ -425,7 +481,7 @@ static struct platform_device *cm_bf537_devices[] __initdata = {
425 481
426static int __init cm_bf537_init(void) 482static int __init cm_bf537_init(void)
427{ 483{
428 printk(KERN_INFO "%s(): registering device resources\n", __FUNCTION__); 484 printk(KERN_INFO "%s(): registering device resources\n", __func__);
429 platform_add_devices(cm_bf537_devices, ARRAY_SIZE(cm_bf537_devices)); 485 platform_add_devices(cm_bf537_devices, ARRAY_SIZE(cm_bf537_devices));
430#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 486#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
431 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info)); 487 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
diff --git a/arch/blackfin/mach-bf537/boards/generic_board.c b/arch/blackfin/mach-bf537/boards/generic_board.c
index c95395ba7bfa..7d250828dad8 100644
--- a/arch/blackfin/mach-bf537/boards/generic_board.c
+++ b/arch/blackfin/mach-bf537/boards/generic_board.c
@@ -90,7 +90,7 @@ int __init bfin_isp1761_init(void)
90{ 90{
91 unsigned int num_devices = ARRAY_SIZE(bfin_isp1761_devices); 91 unsigned int num_devices = ARRAY_SIZE(bfin_isp1761_devices);
92 92
93 printk(KERN_INFO "%s(): registering device resources\n", __FUNCTION__); 93 printk(KERN_INFO "%s(): registering device resources\n", __func__);
94 set_irq_type(ISP1761_IRQ, IRQF_TRIGGER_FALLING); 94 set_irq_type(ISP1761_IRQ, IRQF_TRIGGER_FALLING);
95 95
96 return platform_add_devices(bfin_isp1761_devices, num_devices); 96 return platform_add_devices(bfin_isp1761_devices, num_devices);
@@ -554,6 +554,32 @@ static struct platform_device bfin_uart_device = {
554}; 554};
555#endif 555#endif
556 556
557#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
558static struct resource bfin_sir_resources[] = {
559#ifdef CONFIG_BFIN_SIR0
560 {
561 .start = 0xFFC00400,
562 .end = 0xFFC004FF,
563 .flags = IORESOURCE_MEM,
564 },
565#endif
566#ifdef CONFIG_BFIN_SIR1
567 {
568 .start = 0xFFC02000,
569 .end = 0xFFC020FF,
570 .flags = IORESOURCE_MEM,
571 },
572#endif
573};
574
575static struct platform_device bfin_sir_device = {
576 .name = "bfin_sir",
577 .id = 0,
578 .num_resources = ARRAY_SIZE(bfin_sir_resources),
579 .resource = bfin_sir_resources,
580};
581#endif
582
557#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE) 583#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
558static struct resource bfin_twi0_resource[] = { 584static struct resource bfin_twi0_resource[] = {
559 [0] = { 585 [0] = {
@@ -674,6 +700,10 @@ static struct platform_device *stamp_devices[] __initdata = {
674 &bfin_uart_device, 700 &bfin_uart_device,
675#endif 701#endif
676 702
703#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
704 &bfin_sir_device,
705#endif
706
677#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE) 707#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
678 &i2c_bfin_twi_device, 708 &i2c_bfin_twi_device,
679#endif 709#endif
@@ -690,7 +720,7 @@ static struct platform_device *stamp_devices[] __initdata = {
690 720
691static int __init stamp_init(void) 721static int __init stamp_init(void)
692{ 722{
693 printk(KERN_INFO "%s(): registering device resources\n", __FUNCTION__); 723 printk(KERN_INFO "%s(): registering device resources\n", __func__);
694 platform_add_devices(stamp_devices, ARRAY_SIZE(stamp_devices)); 724 platform_add_devices(stamp_devices, ARRAY_SIZE(stamp_devices));
695#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 725#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
696 spi_register_board_info(bfin_spi_board_info, 726 spi_register_board_info(bfin_spi_board_info,
diff --git a/arch/blackfin/mach-bf537/boards/minotaur.c b/arch/blackfin/mach-bf537/boards/minotaur.c
index d71e0be33921..18ddf7a52005 100644
--- a/arch/blackfin/mach-bf537/boards/minotaur.c
+++ b/arch/blackfin/mach-bf537/boards/minotaur.c
@@ -8,12 +8,12 @@
8#include <linux/spi/spi.h> 8#include <linux/spi/spi.h>
9#include <linux/spi/flash.h> 9#include <linux/spi/flash.h>
10#if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE) 10#if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE)
11#include <linux/usb_isp1362.h> 11#include <linux/usb/isp1362.h>
12#endif 12#endif
13#include <linux/ata_platform.h> 13#include <linux/ata_platform.h>
14#include <linux/irq.h> 14#include <linux/irq.h>
15#include <linux/interrupt.h> 15#include <linux/interrupt.h>
16#include <linux/usb_sl811.h> 16#include <linux/usb/sl811.h>
17#include <asm/dma.h> 17#include <asm/dma.h>
18#include <asm/bfin5xx_spi.h> 18#include <asm/bfin5xx_spi.h>
19#include <asm/reboot.h> 19#include <asm/reboot.h>
@@ -225,6 +225,32 @@ static struct platform_device bfin_uart_device = {
225}; 225};
226#endif 226#endif
227 227
228#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
229static struct resource bfin_sir_resources[] = {
230#ifdef CONFIG_BFIN_SIR0
231 {
232 .start = 0xFFC00400,
233 .end = 0xFFC004FF,
234 .flags = IORESOURCE_MEM,
235 },
236#endif
237#ifdef CONFIG_BFIN_SIR1
238 {
239 .start = 0xFFC02000,
240 .end = 0xFFC020FF,
241 .flags = IORESOURCE_MEM,
242 },
243#endif
244};
245
246static struct platform_device bfin_sir_device = {
247 .name = "bfin_sir",
248 .id = 0,
249 .num_resources = ARRAY_SIZE(bfin_sir_resources),
250 .resource = bfin_sir_resources,
251};
252#endif
253
228#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE) 254#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
229static struct resource bfin_twi0_resource[] = { 255static struct resource bfin_twi0_resource[] = {
230 [0] = { 256 [0] = {
@@ -284,6 +310,10 @@ static struct platform_device *minotaur_devices[] __initdata = {
284 &bfin_uart_device, 310 &bfin_uart_device,
285#endif 311#endif
286 312
313#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
314 &bfin_sir_device,
315#endif
316
287#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE) 317#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
288 &i2c_bfin_twi_device, 318 &i2c_bfin_twi_device,
289#endif 319#endif
@@ -297,7 +327,7 @@ static struct platform_device *minotaur_devices[] __initdata = {
297 327
298static int __init minotaur_init(void) 328static int __init minotaur_init(void)
299{ 329{
300 printk(KERN_INFO "%s(): registering device resources\n", __FUNCTION__); 330 printk(KERN_INFO "%s(): registering device resources\n", __func__);
301 platform_add_devices(minotaur_devices, ARRAY_SIZE(minotaur_devices)); 331 platform_add_devices(minotaur_devices, ARRAY_SIZE(minotaur_devices));
302#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 332#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
303 spi_register_board_info(bfin_spi_board_info, 333 spi_register_board_info(bfin_spi_board_info,
diff --git a/arch/blackfin/mach-bf537/boards/pnav10.c b/arch/blackfin/mach-bf537/boards/pnav10.c
index 509a8a236fd0..51c3bab14a69 100644
--- a/arch/blackfin/mach-bf537/boards/pnav10.c
+++ b/arch/blackfin/mach-bf537/boards/pnav10.c
@@ -452,6 +452,31 @@ static struct platform_device bfin_uart_device = {
452}; 452};
453#endif 453#endif
454 454
455#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
456static struct resource bfin_sir_resources[] = {
457#ifdef CONFIG_BFIN_SIR0
458 {
459 .start = 0xFFC00400,
460 .end = 0xFFC004FF,
461 .flags = IORESOURCE_MEM,
462 },
463#endif
464#ifdef CONFIG_BFIN_SIR1
465 {
466 .start = 0xFFC02000,
467 .end = 0xFFC020FF,
468 .flags = IORESOURCE_MEM,
469 },
470#endif
471};
472
473static struct platform_device bfin_sir_device = {
474 .name = "bfin_sir",
475 .id = 0,
476 .num_resources = ARRAY_SIZE(bfin_sir_resources),
477 .resource = bfin_sir_resources,
478};
479#endif
455 480
456static struct platform_device *stamp_devices[] __initdata = { 481static struct platform_device *stamp_devices[] __initdata = {
457#if defined(CONFIG_BFIN_CFPCMCIA) || defined(CONFIG_BFIN_CFPCMCIA_MODULE) 482#if defined(CONFIG_BFIN_CFPCMCIA) || defined(CONFIG_BFIN_CFPCMCIA_MODULE)
@@ -493,11 +518,15 @@ static struct platform_device *stamp_devices[] __initdata = {
493#if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE) 518#if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
494 &bfin_uart_device, 519 &bfin_uart_device,
495#endif 520#endif
521
522#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
523 &bfin_sir_device,
524#endif
496}; 525};
497 526
498static int __init stamp_init(void) 527static int __init stamp_init(void)
499{ 528{
500 printk(KERN_INFO "%s(): registering device resources\n", __FUNCTION__); 529 printk(KERN_INFO "%s(): registering device resources\n", __func__);
501 platform_add_devices(stamp_devices, ARRAY_SIZE(stamp_devices)); 530 platform_add_devices(stamp_devices, ARRAY_SIZE(stamp_devices));
502#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 531#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
503 spi_register_board_info(bfin_spi_board_info, 532 spi_register_board_info(bfin_spi_board_info,
diff --git a/arch/blackfin/mach-bf537/boards/stamp.c b/arch/blackfin/mach-bf537/boards/stamp.c
index ea83148993da..0cec14b1ef5c 100644
--- a/arch/blackfin/mach-bf537/boards/stamp.c
+++ b/arch/blackfin/mach-bf537/boards/stamp.c
@@ -41,6 +41,7 @@
41#include <linux/ata_platform.h> 41#include <linux/ata_platform.h>
42#include <linux/irq.h> 42#include <linux/irq.h>
43#include <linux/interrupt.h> 43#include <linux/interrupt.h>
44#include <linux/i2c.h>
44#include <linux/usb/sl811.h> 45#include <linux/usb/sl811.h>
45#include <asm/dma.h> 46#include <asm/dma.h>
46#include <asm/bfin5xx_spi.h> 47#include <asm/bfin5xx_spi.h>
@@ -90,7 +91,7 @@ int __init bfin_isp1761_init(void)
90{ 91{
91 unsigned int num_devices = ARRAY_SIZE(bfin_isp1761_devices); 92 unsigned int num_devices = ARRAY_SIZE(bfin_isp1761_devices);
92 93
93 printk(KERN_INFO "%s(): registering device resources\n", __FUNCTION__); 94 printk(KERN_INFO "%s(): registering device resources\n", __func__);
94 set_irq_type(ISP1761_IRQ, IRQF_TRIGGER_FALLING); 95 set_irq_type(ISP1761_IRQ, IRQF_TRIGGER_FALLING);
95 96
96 return platform_add_devices(bfin_isp1761_devices, num_devices); 97 return platform_add_devices(bfin_isp1761_devices, num_devices);
@@ -353,6 +354,7 @@ static struct platform_device net2272_bfin_device = {
353}; 354};
354#endif 355#endif
355 356
357#if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
356static struct mtd_partition stamp_partitions[] = { 358static struct mtd_partition stamp_partitions[] = {
357 { 359 {
358 .name = "Bootloader", 360 .name = "Bootloader",
@@ -395,6 +397,7 @@ static struct platform_device stamp_flash_device = {
395 .num_resources = 1, 397 .num_resources = 1,
396 .resource = &stamp_flash_resource, 398 .resource = &stamp_flash_resource,
397}; 399};
400#endif
398 401
399#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 402#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
400/* all SPI peripherals info goes here */ 403/* all SPI peripherals info goes here */
@@ -500,6 +503,15 @@ static struct bfin5xx_spi_chip spidev_chip_info = {
500}; 503};
501#endif 504#endif
502 505
506#if defined(CONFIG_MTD_DATAFLASH) \
507 || defined(CONFIG_MTD_DATAFLASH_MODULE)
508/* DataFlash chip */
509static struct bfin5xx_spi_chip data_flash_chip_info = {
510 .enable_dma = 0, /* use dma transfer with this chip*/
511 .bits_per_word = 8,
512};
513#endif
514
503static struct spi_board_info bfin_spi_board_info[] __initdata = { 515static struct spi_board_info bfin_spi_board_info[] __initdata = {
504#if defined(CONFIG_MTD_M25P80) \ 516#if defined(CONFIG_MTD_M25P80) \
505 || defined(CONFIG_MTD_M25P80_MODULE) 517 || defined(CONFIG_MTD_M25P80_MODULE)
@@ -514,7 +526,17 @@ static struct spi_board_info bfin_spi_board_info[] __initdata = {
514 .mode = SPI_MODE_3, 526 .mode = SPI_MODE_3,
515 }, 527 },
516#endif 528#endif
517 529#if defined(CONFIG_MTD_DATAFLASH) \
530 || defined(CONFIG_MTD_DATAFLASH_MODULE)
531 { /* DataFlash chip */
532 .modalias = "mtd_dataflash",
533 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
534 .bus_num = 0, /* Framework bus number */
535 .chip_select = 1, /* Framework chip select. On STAMP537 it is SPISSEL1*/
536 .controller_data = &data_flash_chip_info,
537 .mode = SPI_MODE_3,
538 },
539#endif
518#if defined(CONFIG_SPI_ADC_BF533) \ 540#if defined(CONFIG_SPI_ADC_BF533) \
519 || defined(CONFIG_SPI_ADC_BF533_MODULE) 541 || defined(CONFIG_SPI_ADC_BF533_MODULE)
520 { 542 {
@@ -676,6 +698,32 @@ static struct platform_device bfin_uart_device = {
676}; 698};
677#endif 699#endif
678 700
701#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
702static struct resource bfin_sir_resources[] = {
703#ifdef CONFIG_BFIN_SIR0
704 {
705 .start = 0xFFC00400,
706 .end = 0xFFC004FF,
707 .flags = IORESOURCE_MEM,
708 },
709#endif
710#ifdef CONFIG_BFIN_SIR1
711 {
712 .start = 0xFFC02000,
713 .end = 0xFFC020FF,
714 .flags = IORESOURCE_MEM,
715 },
716#endif
717};
718
719static struct platform_device bfin_sir_device = {
720 .name = "bfin_sir",
721 .id = 0,
722 .num_resources = ARRAY_SIZE(bfin_sir_resources),
723 .resource = bfin_sir_resources,
724};
725#endif
726
679#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE) 727#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
680static struct resource bfin_twi0_resource[] = { 728static struct resource bfin_twi0_resource[] = {
681 [0] = { 729 [0] = {
@@ -698,6 +746,31 @@ static struct platform_device i2c_bfin_twi_device = {
698}; 746};
699#endif 747#endif
700 748
749#ifdef CONFIG_I2C_BOARDINFO
750static struct i2c_board_info __initdata bfin_i2c_board_info[] = {
751#if defined(CONFIG_JOYSTICK_AD7142) || defined(CONFIG_JOYSTICK_AD7142_MODULE)
752 {
753 I2C_BOARD_INFO("ad7142_joystick", 0x2C),
754 .type = "ad7142_joystick",
755 .irq = 55,
756 },
757#endif
758#if defined(CONFIG_TWI_LCD) || defined(CONFIG_TWI_LCD_MODULE)
759 {
760 I2C_BOARD_INFO("pcf8574_lcd", 0x22),
761 .type = "pcf8574_lcd",
762 },
763#endif
764#if defined(CONFIG_TWI_KEYPAD) || defined(CONFIG_TWI_KEYPAD_MODULE)
765 {
766 I2C_BOARD_INFO("pcf8574_keypad", 0x27),
767 .type = "pcf8574_keypad",
768 .irq = 72,
769 },
770#endif
771};
772#endif
773
701#if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE) 774#if defined(CONFIG_SERIAL_BFIN_SPORT) || defined(CONFIG_SERIAL_BFIN_SPORT_MODULE)
702static struct platform_device bfin_sport0_uart_device = { 775static struct platform_device bfin_sport0_uart_device = {
703 .name = "bfin-sport-uart", 776 .name = "bfin-sport-uart",
@@ -800,6 +873,10 @@ static struct platform_device *stamp_devices[] __initdata = {
800 &bfin_uart_device, 873 &bfin_uart_device,
801#endif 874#endif
802 875
876#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
877 &bfin_sir_device,
878#endif
879
803#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE) 880#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
804 &i2c_bfin_twi_device, 881 &i2c_bfin_twi_device,
805#endif 882#endif
@@ -818,12 +895,21 @@ static struct platform_device *stamp_devices[] __initdata = {
818#endif 895#endif
819 896
820 &bfin_gpios_device, 897 &bfin_gpios_device,
898
899#if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
821 &stamp_flash_device, 900 &stamp_flash_device,
901#endif
822}; 902};
823 903
824static int __init stamp_init(void) 904static int __init stamp_init(void)
825{ 905{
826 printk(KERN_INFO "%s(): registering device resources\n", __FUNCTION__); 906 printk(KERN_INFO "%s(): registering device resources\n", __func__);
907
908#ifdef CONFIG_I2C_BOARDINFO
909 i2c_register_board_info(0, bfin_i2c_board_info,
910 ARRAY_SIZE(bfin_i2c_board_info));
911#endif
912
827 platform_add_devices(stamp_devices, ARRAY_SIZE(stamp_devices)); 913 platform_add_devices(stamp_devices, ARRAY_SIZE(stamp_devices));
828#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 914#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
829 spi_register_board_info(bfin_spi_board_info, 915 spi_register_board_info(bfin_spi_board_info,
@@ -833,6 +919,7 @@ static int __init stamp_init(void)
833#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE) 919#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
834 irq_desc[PATA_INT].status |= IRQ_NOAUTOEN; 920 irq_desc[PATA_INT].status |= IRQ_NOAUTOEN;
835#endif 921#endif
922
836 return 0; 923 return 0;
837} 924}
838 925
diff --git a/arch/blackfin/mach-bf537/cpu.c b/arch/blackfin/mach-bf537/cpu.c
deleted file mode 100644
index 0442c4c7f723..000000000000
--- a/arch/blackfin/mach-bf537/cpu.c
+++ /dev/null
@@ -1,159 +0,0 @@
1/*
2 * File: arch/blackfin/mach-bf537/cpu.c
3 * Based on:
4 * Author: michael.kang@analog.com
5 *
6 * Created:
7 * Description: clock scaling for the bf537
8 *
9 * Modified:
10 * Copyright 2004-2006 Analog Devices Inc.
11 *
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see the file COPYING, or write
26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */
29
30#include <linux/kernel.h>
31#include <linux/types.h>
32#include <linux/init.h>
33#include <linux/cpufreq.h>
34#include <asm/dpmc.h>
35#include <linux/fs.h>
36#include <asm/bfin-global.h>
37
38/* CONFIG_CLKIN_HZ=11059200 */
39#define VCO5 (CONFIG_CLKIN_HZ*45) /*497664000 */
40#define VCO4 (CONFIG_CLKIN_HZ*36) /*398131200 */
41#define VCO3 (CONFIG_CLKIN_HZ*27) /*298598400 */
42#define VCO2 (CONFIG_CLKIN_HZ*18) /*199065600 */
43#define VCO1 (CONFIG_CLKIN_HZ*9) /*99532800 */
44#define VCO(x) VCO##x
45
46#define MFREQ(x) {VCO(x),VCO(x)/4},{VCO(x),VCO(x)/2},{VCO(x),VCO(x)}
47/* frequency */
48static struct cpufreq_frequency_table bf537_freq_table[] = {
49 MFREQ(1),
50 MFREQ(3),
51 {VCO4, VCO4 / 2}, {VCO4, VCO4},
52 MFREQ(5),
53 {0, CPUFREQ_TABLE_END},
54};
55
56/*
57 * dpmc_fops->ioctl()
58 * static int dpmc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
59 */
60static int bf537_getfreq(unsigned int cpu)
61{
62 unsigned long cclk_mhz;
63
64 /* The driver only support single cpu */
65 if (cpu == 0)
66 dpmc_fops.ioctl(NULL, NULL, IOCTL_GET_CORECLOCK, &cclk_mhz);
67 else
68 cclk_mhz = -1;
69
70 return cclk_mhz;
71}
72
73static int bf537_target(struct cpufreq_policy *policy,
74 unsigned int target_freq, unsigned int relation)
75{
76 unsigned long cclk_mhz;
77 unsigned long vco_mhz;
78 unsigned long flags;
79 unsigned int index;
80 struct cpufreq_freqs freqs;
81
82 if (cpufreq_frequency_table_target(policy, bf537_freq_table, target_freq, relation, &index))
83 return -EINVAL;
84
85 cclk_mhz = bf537_freq_table[index].frequency;
86 vco_mhz = bf537_freq_table[index].index;
87
88 dpmc_fops.ioctl(NULL, NULL, IOCTL_CHANGE_FREQUENCY, &vco_mhz);
89 freqs.old = bf537_getfreq(0);
90 freqs.new = cclk_mhz;
91 freqs.cpu = 0;
92
93 pr_debug("cclk begin change to cclk %d,vco=%d,index=%d,target=%d,oldfreq=%d\n",
94 cclk_mhz, vco_mhz, index, target_freq, freqs.old);
95
96 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
97 local_irq_save(flags);
98 dpmc_fops.ioctl(NULL, NULL, IOCTL_SET_CCLK, &cclk_mhz);
99 local_irq_restore(flags);
100 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
101
102 vco_mhz = get_vco();
103 cclk_mhz = get_cclk();
104 return 0;
105}
106
107/* make sure that only the "userspace" governor is run -- anything else wouldn't make sense on
108 * this platform, anyway.
109 */
110static int bf537_verify_speed(struct cpufreq_policy *policy)
111{
112 return cpufreq_frequency_table_verify(policy, &bf537_freq_table);
113}
114
115static int __init __bf537_cpu_init(struct cpufreq_policy *policy)
116{
117 if (policy->cpu != 0)
118 return -EINVAL;
119
120 policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
121
122 policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
123 /*Now ,only support one cpu */
124 policy->cur = bf537_getfreq(0);
125 cpufreq_frequency_table_get_attr(bf537_freq_table, policy->cpu);
126 return cpufreq_frequency_table_cpuinfo(policy, bf537_freq_table);
127}
128
129static struct freq_attr *bf537_freq_attr[] = {
130 &cpufreq_freq_attr_scaling_available_freqs,
131 NULL,
132};
133
134static struct cpufreq_driver bf537_driver = {
135 .verify = bf537_verify_speed,
136 .target = bf537_target,
137 .get = bf537_getfreq,
138 .init = __bf537_cpu_init,
139 .name = "bf537",
140 .owner = THIS_MODULE,
141 .attr = bf537_freq_attr,
142};
143
144static int __init bf537_cpu_init(void)
145{
146 return cpufreq_register_driver(&bf537_driver);
147}
148
149static void __exit bf537_cpu_exit(void)
150{
151 cpufreq_unregister_driver(&bf537_driver);
152}
153
154MODULE_AUTHOR("Mickael Kang");
155MODULE_DESCRIPTION("cpufreq driver for BF537 CPU");
156MODULE_LICENSE("GPL");
157
158module_init(bf537_cpu_init);
159module_exit(bf537_cpu_exit);
diff --git a/arch/blackfin/mach-bf537/dma.c b/arch/blackfin/mach-bf537/dma.c
index 706cb97b0265..4edb363ff99c 100644
--- a/arch/blackfin/mach-bf537/dma.c
+++ b/arch/blackfin/mach-bf537/dma.c
@@ -26,10 +26,12 @@
26 * to the Free Software Foundation, Inc., 26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */ 28 */
29#include <linux/module.h>
30
29#include <asm/blackfin.h> 31#include <asm/blackfin.h>
30#include <asm/dma.h> 32#include <asm/dma.h>
31 33
32struct dma_register *base_addr[MAX_BLACKFIN_DMA_CHANNEL] = { 34struct dma_register *dma_io_base_addr[MAX_BLACKFIN_DMA_CHANNEL] = {
33 (struct dma_register *) DMA0_NEXT_DESC_PTR, 35 (struct dma_register *) DMA0_NEXT_DESC_PTR,
34 (struct dma_register *) DMA1_NEXT_DESC_PTR, 36 (struct dma_register *) DMA1_NEXT_DESC_PTR,
35 (struct dma_register *) DMA2_NEXT_DESC_PTR, 37 (struct dma_register *) DMA2_NEXT_DESC_PTR,
@@ -47,6 +49,7 @@ struct dma_register *base_addr[MAX_BLACKFIN_DMA_CHANNEL] = {
47 (struct dma_register *) MDMA_D1_NEXT_DESC_PTR, 49 (struct dma_register *) MDMA_D1_NEXT_DESC_PTR,
48 (struct dma_register *) MDMA_S1_NEXT_DESC_PTR, 50 (struct dma_register *) MDMA_S1_NEXT_DESC_PTR,
49}; 51};
52EXPORT_SYMBOL(dma_io_base_addr);
50 53
51int channel2irq(unsigned int channel) 54int channel2irq(unsigned int channel)
52{ 55{
diff --git a/arch/blackfin/mach-bf537/head.S b/arch/blackfin/mach-bf537/head.S
index 3014fe8dd155..48cd58a410a0 100644
--- a/arch/blackfin/mach-bf537/head.S
+++ b/arch/blackfin/mach-bf537/head.S
@@ -37,9 +37,6 @@
37#include <asm/mach/mem_init.h> 37#include <asm/mach/mem_init.h>
38#endif 38#endif
39 39
40.global __rambase
41.global __ramstart
42.global __ramend
43.extern ___bss_stop 40.extern ___bss_stop
44.extern ___bss_start 41.extern ___bss_start
45.extern _bf53x_relocate_l1_mem 42.extern _bf53x_relocate_l1_mem
@@ -180,40 +177,28 @@ ENTRY(__start)
180 SSYNC; 177 SSYNC;
181#endif 178#endif
182 179
183#ifdef CONFIG_BF537_PORT_H
184 p0.h = hi(PORTH_FER);
185 p0.l = lo(PORTH_FER);
186 R0.L = W[P0]; /* Read */
187 SSYNC;
188 R0 = 0x0000;
189 W[P0] = R0.L; /* Write */
190 SSYNC;
191 W[P0] = R0.L; /* Disable peripheral function of PORTH */
192 SSYNC;
193#endif
194
195 /* Initialise UART - when booting from u-boot, the UART is not disabled 180 /* Initialise UART - when booting from u-boot, the UART is not disabled
196 * so if we dont initalize here, our serial console gets hosed */ 181 * so if we dont initalize here, our serial console gets hosed */
197 p0.h = hi(UART_LCR); 182 p0.h = hi(BFIN_UART_LCR);
198 p0.l = lo(UART_LCR); 183 p0.l = lo(BFIN_UART_LCR);
199 r0 = 0x0(Z); 184 r0 = 0x0(Z);
200 w[p0] = r0.L; /* To enable DLL writes */ 185 w[p0] = r0.L; /* To enable DLL writes */
201 ssync; 186 ssync;
202 187
203 p0.h = hi(UART_DLL); 188 p0.h = hi(BFIN_UART_DLL);
204 p0.l = lo(UART_DLL); 189 p0.l = lo(BFIN_UART_DLL);
205 r0 = 0x0(Z); 190 r0 = 0x0(Z);
206 w[p0] = r0.L; 191 w[p0] = r0.L;
207 ssync; 192 ssync;
208 193
209 p0.h = hi(UART_DLH); 194 p0.h = hi(BFIN_UART_DLH);
210 p0.l = lo(UART_DLH); 195 p0.l = lo(BFIN_UART_DLH);
211 r0 = 0x00(Z); 196 r0 = 0x00(Z);
212 w[p0] = r0.L; 197 w[p0] = r0.L;
213 ssync; 198 ssync;
214 199
215 p0.h = hi(UART_GCTL); 200 p0.h = hi(BFIN_UART_GCTL);
216 p0.l = lo(UART_GCTL); 201 p0.l = lo(BFIN_UART_GCTL);
217 r0 = 0x0(Z); 202 r0 = 0x0(Z);
218 w[p0] = r0.L; /* To enable UART clock */ 203 w[p0] = r0.L; /* To enable UART clock */
219 ssync; 204 ssync;
@@ -483,18 +468,3 @@ ENTRY(_start_dma_code)
483 RTS; 468 RTS;
484ENDPROC(_start_dma_code) 469ENDPROC(_start_dma_code)
485#endif /* CONFIG_BFIN_KERNEL_CLOCK */ 470#endif /* CONFIG_BFIN_KERNEL_CLOCK */
486
487.data
488
489/*
490 * Set up the usable of RAM stuff. Size of RAM is determined then
491 * an initial stack set up at the end.
492 */
493
494.align 4
495__rambase:
496.long 0
497__ramstart:
498.long 0
499__ramend:
500.long 0
diff --git a/arch/blackfin/mach-bf548/Makefile b/arch/blackfin/mach-bf548/Makefile
index 7e7c9c8ac5b2..68e5478e95a9 100644
--- a/arch/blackfin/mach-bf548/Makefile
+++ b/arch/blackfin/mach-bf548/Makefile
@@ -5,5 +5,3 @@
5extra-y := head.o 5extra-y := head.o
6 6
7obj-y := ints-priority.o dma.o 7obj-y := ints-priority.o dma.o
8
9obj-$(CONFIG_CPU_FREQ) += cpu.o
diff --git a/arch/blackfin/mach-bf548/boards/Kconfig b/arch/blackfin/mach-bf548/boards/Kconfig
index 057129064037..d38e52671853 100644
--- a/arch/blackfin/mach-bf548/boards/Kconfig
+++ b/arch/blackfin/mach-bf548/boards/Kconfig
@@ -8,5 +8,11 @@ config BFIN548_EZKIT
8 bool "BF548-EZKIT" 8 bool "BF548-EZKIT"
9 help 9 help
10 BFIN548-EZKIT board support. 10 BFIN548-EZKIT board support.
11
12config BFIN548_BLUETECHNIX_CM
13 bool "Bluetechnix CM-BF548"
14 depends on (BF548)
15 help
16 CM-BF548 support for DEV-Board.
11 17
12endchoice 18endchoice
diff --git a/arch/blackfin/mach-bf548/boards/Makefile b/arch/blackfin/mach-bf548/boards/Makefile
index a444cc739578..eed161dd7845 100644
--- a/arch/blackfin/mach-bf548/boards/Makefile
+++ b/arch/blackfin/mach-bf548/boards/Makefile
@@ -3,3 +3,4 @@
3# 3#
4 4
5obj-$(CONFIG_BFIN548_EZKIT) += ezkit.o led.o 5obj-$(CONFIG_BFIN548_EZKIT) += ezkit.o led.o
6obj-$(CONFIG_BFIN548_BLUETECHNIX_CM) += cm_bf548.o
diff --git a/arch/blackfin/mach-bf548/boards/cm_bf548.c b/arch/blackfin/mach-bf548/boards/cm_bf548.c
new file mode 100644
index 000000000000..e3e8479fffb5
--- /dev/null
+++ b/arch/blackfin/mach-bf548/boards/cm_bf548.c
@@ -0,0 +1,664 @@
1/*
2 * File: arch/blackfin/mach-bf548/boards/cm_bf548.c
3 * Based on: arch/blackfin/mach-bf537/boards/ezkit.c
4 * Author: Aidan Williams <aidan@nicta.com.au>
5 *
6 * Created:
7 * Description:
8 *
9 * Modified:
10 * Copyright 2005 National ICT Australia (NICTA)
11 * Copyright 2004-2008 Analog Devices Inc.
12 *
13 * Bugs: Enter bugs at http://blackfin.uclinux.org/
14 *
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
19 *
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
24 *
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, see the file COPYING, or write
27 * to the Free Software Foundation, Inc.,
28 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 */
30
31#include <linux/device.h>
32#include <linux/platform_device.h>
33#include <linux/mtd/mtd.h>
34#include <linux/mtd/partitions.h>
35#include <linux/spi/spi.h>
36#include <linux/spi/flash.h>
37#include <linux/irq.h>
38#include <linux/interrupt.h>
39#include <linux/usb/musb.h>
40#include <asm/bfin5xx_spi.h>
41#include <asm/cplb.h>
42#include <asm/dma.h>
43#include <asm/gpio.h>
44#include <asm/nand.h>
45#include <asm/portmux.h>
46#include <asm/mach/bf54x_keys.h>
47#include <linux/input.h>
48#include <linux/spi/ad7877.h>
49
50/*
51 * Name the Board for the /proc/cpuinfo
52 */
53const char bfin_board_name[] = "Bluetechnix CM-BF548";
54
55/*
56 * Driver needs to know address, irq and flag pin.
57 */
58
59#if defined(CONFIG_FB_BF54X_LQ043) || defined(CONFIG_FB_BF54X_LQ043_MODULE)
60
61#include <asm/mach/bf54x-lq043.h>
62
63static struct bfin_bf54xfb_mach_info bf54x_lq043_data = {
64 .width = 480,
65 .height = 272,
66 .xres = {480, 480, 480},
67 .yres = {272, 272, 272},
68 .bpp = {24, 24, 24},
69 .disp = GPIO_PE3,
70};
71
72static struct resource bf54x_lq043_resources[] = {
73 {
74 .start = IRQ_EPPI0_ERR,
75 .end = IRQ_EPPI0_ERR,
76 .flags = IORESOURCE_IRQ,
77 },
78};
79
80static struct platform_device bf54x_lq043_device = {
81 .name = "bf54x-lq043",
82 .id = -1,
83 .num_resources = ARRAY_SIZE(bf54x_lq043_resources),
84 .resource = bf54x_lq043_resources,
85 .dev = {
86 .platform_data = &bf54x_lq043_data,
87 },
88};
89#endif
90
91#if defined(CONFIG_KEYBOARD_BFIN) || defined(CONFIG_KEYBOARD_BFIN_MODULE)
92static unsigned int bf548_keymap[] = {
93 KEYVAL(0, 0, KEY_ENTER),
94 KEYVAL(0, 1, KEY_HELP),
95 KEYVAL(0, 2, KEY_0),
96 KEYVAL(0, 3, KEY_BACKSPACE),
97 KEYVAL(1, 0, KEY_TAB),
98 KEYVAL(1, 1, KEY_9),
99 KEYVAL(1, 2, KEY_8),
100 KEYVAL(1, 3, KEY_7),
101 KEYVAL(2, 0, KEY_DOWN),
102 KEYVAL(2, 1, KEY_6),
103 KEYVAL(2, 2, KEY_5),
104 KEYVAL(2, 3, KEY_4),
105 KEYVAL(3, 0, KEY_UP),
106 KEYVAL(3, 1, KEY_3),
107 KEYVAL(3, 2, KEY_2),
108 KEYVAL(3, 3, KEY_1),
109};
110
111static struct bfin_kpad_platform_data bf54x_kpad_data = {
112 .rows = 4,
113 .cols = 4,
114 .keymap = bf548_keymap,
115 .keymapsize = ARRAY_SIZE(bf548_keymap),
116 .repeat = 0,
117 .debounce_time = 5000, /* ns (5ms) */
118 .coldrive_time = 1000, /* ns (1ms) */
119 .keyup_test_interval = 50, /* ms (50ms) */
120};
121
122static struct resource bf54x_kpad_resources[] = {
123 {
124 .start = IRQ_KEY,
125 .end = IRQ_KEY,
126 .flags = IORESOURCE_IRQ,
127 },
128};
129
130static struct platform_device bf54x_kpad_device = {
131 .name = "bf54x-keys",
132 .id = -1,
133 .num_resources = ARRAY_SIZE(bf54x_kpad_resources),
134 .resource = bf54x_kpad_resources,
135 .dev = {
136 .platform_data = &bf54x_kpad_data,
137 },
138};
139#endif
140
141#if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
142static struct platform_device rtc_device = {
143 .name = "rtc-bfin",
144 .id = -1,
145};
146#endif
147
148#if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
149static struct resource bfin_uart_resources[] = {
150#ifdef CONFIG_SERIAL_BFIN_UART0
151 {
152 .start = 0xFFC00400,
153 .end = 0xFFC004FF,
154 .flags = IORESOURCE_MEM,
155 },
156#endif
157#ifdef CONFIG_SERIAL_BFIN_UART1
158 {
159 .start = 0xFFC02000,
160 .end = 0xFFC020FF,
161 .flags = IORESOURCE_MEM,
162 },
163#endif
164#ifdef CONFIG_SERIAL_BFIN_UART2
165 {
166 .start = 0xFFC02100,
167 .end = 0xFFC021FF,
168 .flags = IORESOURCE_MEM,
169 },
170#endif
171#ifdef CONFIG_SERIAL_BFIN_UART3
172 {
173 .start = 0xFFC03100,
174 .end = 0xFFC031FF,
175 },
176#endif
177};
178
179static struct platform_device bfin_uart_device = {
180 .name = "bfin-uart",
181 .id = 1,
182 .num_resources = ARRAY_SIZE(bfin_uart_resources),
183 .resource = bfin_uart_resources,
184};
185#endif
186
187#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
188static struct resource bfin_sir_resources[] = {
189#ifdef CONFIG_BFIN_SIR0
190 {
191 .start = 0xFFC00400,
192 .end = 0xFFC004FF,
193 .flags = IORESOURCE_MEM,
194 },
195#endif
196#ifdef CONFIG_BFIN_SIR1
197 {
198 .start = 0xFFC02000,
199 .end = 0xFFC020FF,
200 .flags = IORESOURCE_MEM,
201 },
202#endif
203#ifdef CONFIG_BFIN_SIR2
204 {
205 .start = 0xFFC02100,
206 .end = 0xFFC021FF,
207 .flags = IORESOURCE_MEM,
208 },
209#endif
210#ifdef CONFIG_BFIN_SIR3
211 {
212 .start = 0xFFC03100,
213 .end = 0xFFC031FF,
214 .flags = IORESOURCE_MEM,
215 },
216#endif
217};
218
219static struct platform_device bfin_sir_device = {
220 .name = "bfin_sir",
221 .id = 0,
222 .num_resources = ARRAY_SIZE(bfin_sir_resources),
223 .resource = bfin_sir_resources,
224};
225#endif
226
227#if defined(CONFIG_SMSC911X) || defined(CONFIG_SMSC911X_MODULE)
228static struct resource smsc911x_resources[] = {
229 {
230 .name = "smsc911x-memory",
231 .start = 0x24000000,
232 .end = 0x24000000 + 0xFF,
233 .flags = IORESOURCE_MEM,
234 },
235 {
236 .start = IRQ_PE6,
237 .end = IRQ_PE6,
238 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_LOWLEVEL,
239 },
240};
241static struct platform_device smsc911x_device = {
242 .name = "smsc911x",
243 .id = 0,
244 .num_resources = ARRAY_SIZE(smsc911x_resources),
245 .resource = smsc911x_resources,
246};
247#endif
248
249#if defined(CONFIG_USB_MUSB_HDRC) || defined(CONFIG_USB_MUSB_HDRC_MODULE)
250static struct resource musb_resources[] = {
251 [0] = {
252 .start = 0xFFC03C00,
253 .end = 0xFFC040FF,
254 .flags = IORESOURCE_MEM,
255 },
256 [1] = { /* general IRQ */
257 .start = IRQ_USB_INT0,
258 .end = IRQ_USB_INT0,
259 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
260 },
261 [2] = { /* DMA IRQ */
262 .start = IRQ_USB_DMA,
263 .end = IRQ_USB_DMA,
264 .flags = IORESOURCE_IRQ | IORESOURCE_IRQ_HIGHLEVEL,
265 },
266};
267
268static struct musb_hdrc_platform_data musb_plat = {
269#if defined(CONFIG_USB_MUSB_OTG)
270 .mode = MUSB_OTG,
271#elif defined(CONFIG_USB_MUSB_HDRC_HCD)
272 .mode = MUSB_HOST,
273#elif defined(CONFIG_USB_GADGET_MUSB_HDRC)
274 .mode = MUSB_PERIPHERAL,
275#endif
276 .multipoint = 0,
277};
278
279static u64 musb_dmamask = ~(u32)0;
280
281static struct platform_device musb_device = {
282 .name = "musb_hdrc",
283 .id = 0,
284 .dev = {
285 .dma_mask = &musb_dmamask,
286 .coherent_dma_mask = 0xffffffff,
287 .platform_data = &musb_plat,
288 },
289 .num_resources = ARRAY_SIZE(musb_resources),
290 .resource = musb_resources,
291};
292#endif
293
294#if defined(CONFIG_PATA_BF54X) || defined(CONFIG_PATA_BF54X_MODULE)
295static struct resource bfin_atapi_resources[] = {
296 {
297 .start = 0xFFC03800,
298 .end = 0xFFC0386F,
299 .flags = IORESOURCE_MEM,
300 },
301 {
302 .start = IRQ_ATAPI_ERR,
303 .end = IRQ_ATAPI_ERR,
304 .flags = IORESOURCE_IRQ,
305 },
306};
307
308static struct platform_device bfin_atapi_device = {
309 .name = "pata-bf54x",
310 .id = -1,
311 .num_resources = ARRAY_SIZE(bfin_atapi_resources),
312 .resource = bfin_atapi_resources,
313};
314#endif
315
316#if defined(CONFIG_MTD_NAND_BF5XX) || defined(CONFIG_MTD_NAND_BF5XX_MODULE)
317static struct mtd_partition partition_info[] = {
318 {
319 .name = "Linux Kernel",
320 .offset = 0,
321 .size = 4 * SIZE_1M,
322 },
323 {
324 .name = "File System",
325 .offset = 4 * SIZE_1M,
326 .size = (256 - 4) * SIZE_1M,
327 },
328};
329
330static struct bf5xx_nand_platform bf5xx_nand_platform = {
331 .page_size = NFC_PG_SIZE_256,
332 .data_width = NFC_NWIDTH_8,
333 .partitions = partition_info,
334 .nr_partitions = ARRAY_SIZE(partition_info),
335 .rd_dly = 3,
336 .wr_dly = 3,
337};
338
339static struct resource bf5xx_nand_resources[] = {
340 {
341 .start = 0xFFC03B00,
342 .end = 0xFFC03B4F,
343 .flags = IORESOURCE_MEM,
344 },
345 {
346 .start = CH_NFC,
347 .end = CH_NFC,
348 .flags = IORESOURCE_IRQ,
349 },
350};
351
352static struct platform_device bf5xx_nand_device = {
353 .name = "bf5xx-nand",
354 .id = 0,
355 .num_resources = ARRAY_SIZE(bf5xx_nand_resources),
356 .resource = bf5xx_nand_resources,
357 .dev = {
358 .platform_data = &bf5xx_nand_platform,
359 },
360};
361#endif
362
363#if defined(CONFIG_SDH_BFIN) || defined(CONFIG_SDH_BFIN_MODULE)
364static struct platform_device bf54x_sdh_device = {
365 .name = "bfin-sdh",
366 .id = 0,
367};
368#endif
369
370#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
371/* all SPI peripherals info goes here */
372#if defined(CONFIG_MTD_M25P80) \
373 || defined(CONFIG_MTD_M25P80_MODULE)
374/* SPI flash chip (m25p16) */
375static struct mtd_partition bfin_spi_flash_partitions[] = {
376 {
377 .name = "bootloader",
378 .size = 0x00040000,
379 .offset = 0,
380 .mask_flags = MTD_CAP_ROM
381 }, {
382 .name = "linux kernel",
383 .size = 0x1c0000,
384 .offset = 0x40000
385 }
386};
387
388static struct flash_platform_data bfin_spi_flash_data = {
389 .name = "m25p80",
390 .parts = bfin_spi_flash_partitions,
391 .nr_parts = ARRAY_SIZE(bfin_spi_flash_partitions),
392 .type = "m25p16",
393};
394
395static struct bfin5xx_spi_chip spi_flash_chip_info = {
396 .enable_dma = 0, /* use dma transfer with this chip*/
397 .bits_per_word = 8,
398 .cs_change_per_word = 0,
399};
400#endif
401
402#if defined(CONFIG_TOUCHSCREEN_AD7877) || defined(CONFIG_TOUCHSCREEN_AD7877_MODULE)
403static struct bfin5xx_spi_chip spi_ad7877_chip_info = {
404 .cs_change_per_word = 0,
405 .enable_dma = 0,
406 .bits_per_word = 16,
407};
408
409static const struct ad7877_platform_data bfin_ad7877_ts_info = {
410 .model = 7877,
411 .vref_delay_usecs = 50, /* internal, no capacitor */
412 .x_plate_ohms = 419,
413 .y_plate_ohms = 486,
414 .pressure_max = 1000,
415 .pressure_min = 0,
416 .stopacq_polarity = 1,
417 .first_conversion_delay = 3,
418 .acquisition_time = 1,
419 .averaging = 1,
420 .pen_down_acc_interval = 1,
421};
422#endif
423
424#if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
425static struct bfin5xx_spi_chip spidev_chip_info = {
426 .enable_dma = 0,
427 .bits_per_word = 8,
428};
429#endif
430
431static struct spi_board_info bf54x_spi_board_info[] __initdata = {
432#if defined(CONFIG_MTD_M25P80) \
433 || defined(CONFIG_MTD_M25P80_MODULE)
434 {
435 /* the modalias must be the same as spi device driver name */
436 .modalias = "m25p80", /* Name of spi_driver for this device */
437 .max_speed_hz = 25000000, /* max spi clock (SCK) speed in HZ */
438 .bus_num = 0, /* Framework bus number */
439 .chip_select = 1, /* SPI_SSEL1*/
440 .platform_data = &bfin_spi_flash_data,
441 .controller_data = &spi_flash_chip_info,
442 .mode = SPI_MODE_3,
443 },
444#endif
445#if defined(CONFIG_TOUCHSCREEN_AD7877) || defined(CONFIG_TOUCHSCREEN_AD7877_MODULE)
446{
447 .modalias = "ad7877",
448 .platform_data = &bfin_ad7877_ts_info,
449 .irq = IRQ_PJ11,
450 .max_speed_hz = 12500000, /* max spi clock (SCK) speed in HZ */
451 .bus_num = 0,
452 .chip_select = 2,
453 .controller_data = &spi_ad7877_chip_info,
454},
455#endif
456#if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
457 {
458 .modalias = "spidev",
459 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */
460 .bus_num = 0,
461 .chip_select = 1,
462 .controller_data = &spidev_chip_info,
463 },
464#endif
465};
466
467/* SPI (0) */
468static struct resource bfin_spi0_resource[] = {
469 [0] = {
470 .start = SPI0_REGBASE,
471 .end = SPI0_REGBASE + 0xFF,
472 .flags = IORESOURCE_MEM,
473 },
474 [1] = {
475 .start = CH_SPI0,
476 .end = CH_SPI0,
477 .flags = IORESOURCE_IRQ,
478 }
479};
480
481/* SPI (1) */
482static struct resource bfin_spi1_resource[] = {
483 [0] = {
484 .start = SPI1_REGBASE,
485 .end = SPI1_REGBASE + 0xFF,
486 .flags = IORESOURCE_MEM,
487 },
488 [1] = {
489 .start = CH_SPI1,
490 .end = CH_SPI1,
491 .flags = IORESOURCE_IRQ,
492 }
493};
494
495/* SPI controller data */
496static struct bfin5xx_spi_master bf54x_spi_master_info0 = {
497 .num_chipselect = 8,
498 .enable_dma = 1, /* master has the ability to do dma transfer */
499 .pin_req = {P_SPI0_SCK, P_SPI0_MISO, P_SPI0_MOSI, 0},
500};
501
502static struct platform_device bf54x_spi_master0 = {
503 .name = "bfin-spi",
504 .id = 0, /* Bus number */
505 .num_resources = ARRAY_SIZE(bfin_spi0_resource),
506 .resource = bfin_spi0_resource,
507 .dev = {
508 .platform_data = &bf54x_spi_master_info0, /* Passed to driver */
509 },
510};
511
512static struct bfin5xx_spi_master bf54x_spi_master_info1 = {
513 .num_chipselect = 8,
514 .enable_dma = 1, /* master has the ability to do dma transfer */
515 .pin_req = {P_SPI1_SCK, P_SPI1_MISO, P_SPI1_MOSI, 0},
516};
517
518static struct platform_device bf54x_spi_master1 = {
519 .name = "bfin-spi",
520 .id = 1, /* Bus number */
521 .num_resources = ARRAY_SIZE(bfin_spi1_resource),
522 .resource = bfin_spi1_resource,
523 .dev = {
524 .platform_data = &bf54x_spi_master_info1, /* Passed to driver */
525 },
526};
527#endif /* spi master and devices */
528
529#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
530static struct resource bfin_twi0_resource[] = {
531 [0] = {
532 .start = TWI0_REGBASE,
533 .end = TWI0_REGBASE + 0xFF,
534 .flags = IORESOURCE_MEM,
535 },
536 [1] = {
537 .start = IRQ_TWI0,
538 .end = IRQ_TWI0,
539 .flags = IORESOURCE_IRQ,
540 },
541};
542
543static struct platform_device i2c_bfin_twi0_device = {
544 .name = "i2c-bfin-twi",
545 .id = 0,
546 .num_resources = ARRAY_SIZE(bfin_twi0_resource),
547 .resource = bfin_twi0_resource,
548};
549
550#if !defined(CONFIG_BF542) /* The BF542 only has 1 TWI */
551static struct resource bfin_twi1_resource[] = {
552 [0] = {
553 .start = TWI1_REGBASE,
554 .end = TWI1_REGBASE + 0xFF,
555 .flags = IORESOURCE_MEM,
556 },
557 [1] = {
558 .start = IRQ_TWI1,
559 .end = IRQ_TWI1,
560 .flags = IORESOURCE_IRQ,
561 },
562};
563
564static struct platform_device i2c_bfin_twi1_device = {
565 .name = "i2c-bfin-twi",
566 .id = 1,
567 .num_resources = ARRAY_SIZE(bfin_twi1_resource),
568 .resource = bfin_twi1_resource,
569};
570#endif
571#endif
572
573#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
574#include <linux/gpio_keys.h>
575
576static struct gpio_keys_button bfin_gpio_keys_table[] = {
577 {BTN_0, GPIO_PH7, 1, "gpio-keys: BTN0"},
578};
579
580static struct gpio_keys_platform_data bfin_gpio_keys_data = {
581 .buttons = bfin_gpio_keys_table,
582 .nbuttons = ARRAY_SIZE(bfin_gpio_keys_table),
583};
584
585static struct platform_device bfin_device_gpiokeys = {
586 .name = "gpio-keys",
587 .dev = {
588 .platform_data = &bfin_gpio_keys_data,
589 },
590};
591#endif
592
593static struct platform_device *cm_bf548_devices[] __initdata = {
594#if defined(CONFIG_RTC_DRV_BFIN) || defined(CONFIG_RTC_DRV_BFIN_MODULE)
595 &rtc_device,
596#endif
597
598#if defined(CONFIG_SERIAL_BFIN) || defined(CONFIG_SERIAL_BFIN_MODULE)
599 &bfin_uart_device,
600#endif
601
602#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
603 &bfin_sir_device,
604#endif
605
606#if defined(CONFIG_FB_BF54X_LQ043) || defined(CONFIG_FB_BF54X_LQ043_MODULE)
607 &bf54x_lq043_device,
608#endif
609
610#if defined(CONFIG_SMSC911X) || defined(CONFIG_SMSC911X_MODULE)
611 &smsc911x_device,
612#endif
613
614#if defined(CONFIG_USB_MUSB_HDRC) || defined(CONFIG_USB_MUSB_HDRC_MODULE)
615 &musb_device,
616#endif
617
618#if defined(CONFIG_PATA_BF54X) || defined(CONFIG_PATA_BF54X_MODULE)
619 &bfin_atapi_device,
620#endif
621
622#if defined(CONFIG_MTD_NAND_BF5XX) || defined(CONFIG_MTD_NAND_BF5XX_MODULE)
623 &bf5xx_nand_device,
624#endif
625
626#if defined(CONFIG_SDH_BFIN) || defined(CONFIG_SDH_BFIN_MODULE)
627 &bf54x_sdh_device,
628#endif
629
630#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
631 &bf54x_spi_master0,
632 &bf54x_spi_master1,
633#endif
634
635#if defined(CONFIG_KEYBOARD_BFIN) || defined(CONFIG_KEYBOARD_BFIN_MODULE)
636 &bf54x_kpad_device,
637#endif
638
639#if defined(CONFIG_I2C_BLACKFIN_TWI) || defined(CONFIG_I2C_BLACKFIN_TWI_MODULE)
640/* &i2c_bfin_twi0_device, */
641#if !defined(CONFIG_BF542)
642 &i2c_bfin_twi1_device,
643#endif
644#endif
645
646#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
647 &bfin_device_gpiokeys,
648#endif
649};
650
651static int __init cm_bf548_init(void)
652{
653 printk(KERN_INFO "%s(): registering device resources\n", __FUNCTION__);
654 platform_add_devices(cm_bf548_devices, ARRAY_SIZE(cm_bf548_devices));
655
656#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
657 spi_register_board_info(bf54x_spi_board_info,
658 ARRAY_SIZE(bf54x_spi_board_info));
659#endif
660
661 return 0;
662}
663
664arch_initcall(cm_bf548_init);
diff --git a/arch/blackfin/mach-bf548/boards/ezkit.c b/arch/blackfin/mach-bf548/boards/ezkit.c
index 40846aa034c4..231dfbd3bc1f 100644
--- a/arch/blackfin/mach-bf548/boards/ezkit.c
+++ b/arch/blackfin/mach-bf548/boards/ezkit.c
@@ -36,6 +36,7 @@
36#include <linux/spi/spi.h> 36#include <linux/spi/spi.h>
37#include <linux/spi/flash.h> 37#include <linux/spi/flash.h>
38#include <linux/irq.h> 38#include <linux/irq.h>
39#include <linux/i2c.h>
39#include <linux/interrupt.h> 40#include <linux/interrupt.h>
40#if defined(CONFIG_USB_MUSB_HDRC) || defined(CONFIG_USB_MUSB_HDRC_MODULE) 41#if defined(CONFIG_USB_MUSB_HDRC) || defined(CONFIG_USB_MUSB_HDRC_MODULE)
41#include <linux/usb/musb.h> 42#include <linux/usb/musb.h>
@@ -187,6 +188,46 @@ static struct platform_device bfin_uart_device = {
187}; 188};
188#endif 189#endif
189 190
191#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
192static struct resource bfin_sir_resources[] = {
193#ifdef CONFIG_BFIN_SIR0
194 {
195 .start = 0xFFC00400,
196 .end = 0xFFC004FF,
197 .flags = IORESOURCE_MEM,
198 },
199#endif
200#ifdef CONFIG_BFIN_SIR1
201 {
202 .start = 0xFFC02000,
203 .end = 0xFFC020FF,
204 .flags = IORESOURCE_MEM,
205 },
206#endif
207#ifdef CONFIG_BFIN_SIR2
208 {
209 .start = 0xFFC02100,
210 .end = 0xFFC021FF,
211 .flags = IORESOURCE_MEM,
212 },
213#endif
214#ifdef CONFIG_BFIN_SIR3
215 {
216 .start = 0xFFC03100,
217 .end = 0xFFC031FF,
218 .flags = IORESOURCE_MEM,
219 },
220#endif
221};
222
223static struct platform_device bfin_sir_device = {
224 .name = "bfin_sir",
225 .id = 0,
226 .num_resources = ARRAY_SIZE(bfin_sir_resources),
227 .resource = bfin_sir_resources,
228};
229#endif
230
190#if defined(CONFIG_SMSC911X) || defined(CONFIG_SMSC911X_MODULE) 231#if defined(CONFIG_SMSC911X) || defined(CONFIG_SMSC911X_MODULE)
191static struct resource smsc911x_resources[] = { 232static struct resource smsc911x_resources[] = {
192 { 233 {
@@ -330,6 +371,7 @@ static struct platform_device bf54x_sdh_device = {
330}; 371};
331#endif 372#endif
332 373
374#if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
333static struct mtd_partition ezkit_partitions[] = { 375static struct mtd_partition ezkit_partitions[] = {
334 { 376 {
335 .name = "Bootloader", 377 .name = "Bootloader",
@@ -337,7 +379,7 @@ static struct mtd_partition ezkit_partitions[] = {
337 .offset = 0, 379 .offset = 0,
338 }, { 380 }, {
339 .name = "Kernel", 381 .name = "Kernel",
340 .size = 0xE0000, 382 .size = 0x1C0000,
341 .offset = MTDPART_OFS_APPEND, 383 .offset = MTDPART_OFS_APPEND,
342 }, { 384 }, {
343 .name = "RootFS", 385 .name = "RootFS",
@@ -367,6 +409,7 @@ static struct platform_device ezkit_flash_device = {
367 .num_resources = 1, 409 .num_resources = 1,
368 .resource = &ezkit_flash_resource, 410 .resource = &ezkit_flash_resource,
369}; 411};
412#endif
370 413
371#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 414#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
372/* all SPI peripherals info goes here */ 415/* all SPI peripherals info goes here */
@@ -400,6 +443,14 @@ static struct bfin5xx_spi_chip spi_flash_chip_info = {
400}; 443};
401#endif 444#endif
402 445
446#if defined(CONFIG_SND_BLACKFIN_AD1836) \
447 || defined(CONFIG_SND_BLACKFIN_AD1836_MODULE)
448static struct bfin5xx_spi_chip ad1836_spi_chip_info = {
449 .enable_dma = 0,
450 .bits_per_word = 16,
451};
452#endif
453
403#if defined(CONFIG_TOUCHSCREEN_AD7877) || defined(CONFIG_TOUCHSCREEN_AD7877_MODULE) 454#if defined(CONFIG_TOUCHSCREEN_AD7877) || defined(CONFIG_TOUCHSCREEN_AD7877_MODULE)
404static struct bfin5xx_spi_chip spi_ad7877_chip_info = { 455static struct bfin5xx_spi_chip spi_ad7877_chip_info = {
405 .cs_change_per_word = 0, 456 .cs_change_per_word = 0,
@@ -443,6 +494,16 @@ static struct spi_board_info bf54x_spi_board_info[] __initdata = {
443 .mode = SPI_MODE_3, 494 .mode = SPI_MODE_3,
444 }, 495 },
445#endif 496#endif
497#if defined(CONFIG_SND_BLACKFIN_AD1836) \
498 || defined(CONFIG_SND_BLACKFIN_AD1836_MODULE)
499 {
500 .modalias = "ad1836-spi",
501 .max_speed_hz = 3125000, /* max spi clock (SCK) speed in HZ */
502 .bus_num = 1,
503 .chip_select = CONFIG_SND_BLACKFIN_SPI_PFBIT,
504 .controller_data = &ad1836_spi_chip_info,
505 },
506#endif
446#if defined(CONFIG_TOUCHSCREEN_AD7877) || defined(CONFIG_TOUCHSCREEN_AD7877_MODULE) 507#if defined(CONFIG_TOUCHSCREEN_AD7877) || defined(CONFIG_TOUCHSCREEN_AD7877_MODULE)
447{ 508{
448 .modalias = "ad7877", 509 .modalias = "ad7877",
@@ -571,6 +632,29 @@ static struct platform_device i2c_bfin_twi1_device = {
571#endif 632#endif
572#endif 633#endif
573 634
635#ifdef CONFIG_I2C_BOARDINFO
636static struct i2c_board_info __initdata bfin_i2c_board_info0[] = {
637};
638
639#if !defined(CONFIG_BF542) /* The BF542 only has 1 TWI */
640static struct i2c_board_info __initdata bfin_i2c_board_info1[] = {
641#if defined(CONFIG_TWI_LCD) || defined(CONFIG_TWI_LCD_MODULE)
642 {
643 I2C_BOARD_INFO("pcf8574_lcd", 0x22),
644 .type = "pcf8574_lcd",
645 },
646#endif
647#if defined(CONFIG_TWI_KEYPAD) || defined(CONFIG_TWI_KEYPAD_MODULE)
648 {
649 I2C_BOARD_INFO("pcf8574_keypad", 0x27),
650 .type = "pcf8574_keypad",
651 .irq = 212,
652 },
653#endif
654};
655#endif
656#endif
657
574#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE) 658#if defined(CONFIG_KEYBOARD_GPIO) || defined(CONFIG_KEYBOARD_GPIO_MODULE)
575#include <linux/gpio_keys.h> 659#include <linux/gpio_keys.h>
576 660
@@ -616,6 +700,10 @@ static struct platform_device *ezkit_devices[] __initdata = {
616 &bfin_uart_device, 700 &bfin_uart_device,
617#endif 701#endif
618 702
703#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
704 &bfin_sir_device,
705#endif
706
619#if defined(CONFIG_FB_BF54X_LQ043) || defined(CONFIG_FB_BF54X_LQ043_MODULE) 707#if defined(CONFIG_FB_BF54X_LQ043) || defined(CONFIG_FB_BF54X_LQ043_MODULE)
620 &bf54x_lq043_device, 708 &bf54x_lq043_device,
621#endif 709#endif
@@ -661,12 +749,25 @@ static struct platform_device *ezkit_devices[] __initdata = {
661#endif 749#endif
662 750
663 &bfin_gpios_device, 751 &bfin_gpios_device,
752
753#if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
664 &ezkit_flash_device, 754 &ezkit_flash_device,
755#endif
665}; 756};
666 757
667static int __init ezkit_init(void) 758static int __init ezkit_init(void)
668{ 759{
669 printk(KERN_INFO "%s(): registering device resources\n", __FUNCTION__); 760 printk(KERN_INFO "%s(): registering device resources\n", __func__);
761
762#ifdef CONFIG_I2C_BOARDINFO
763 i2c_register_board_info(0, bfin_i2c_board_info0,
764 ARRAY_SIZE(bfin_i2c_board_info0));
765#if !defined(CONFIG_BF542) /* The BF542 only has 1 TWI */
766 i2c_register_board_info(1, bfin_i2c_board_info1,
767 ARRAY_SIZE(bfin_i2c_board_info1));
768#endif
769#endif
770
670 platform_add_devices(ezkit_devices, ARRAY_SIZE(ezkit_devices)); 771 platform_add_devices(ezkit_devices, ARRAY_SIZE(ezkit_devices));
671 772
672#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 773#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
diff --git a/arch/blackfin/mach-bf548/cpu.c b/arch/blackfin/mach-bf548/cpu.c
deleted file mode 100644
index 4298a3ccfbfc..000000000000
--- a/arch/blackfin/mach-bf548/cpu.c
+++ /dev/null
@@ -1,159 +0,0 @@
1/*
2 * File: arch/blackfin/mach-bf548/cpu.c
3 * Based on:
4 * Author:
5 *
6 * Created:
7 * Description: clock scaling for the bf54x
8 *
9 * Modified:
10 * Copyright 2004-2007 Analog Devices Inc.
11 *
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see the file COPYING, or write
26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */
29
30#include <linux/kernel.h>
31#include <linux/types.h>
32#include <linux/init.h>
33#include <linux/cpufreq.h>
34#include <asm/dpmc.h>
35#include <linux/fs.h>
36#include <asm/bfin-global.h>
37
38/* CONFIG_CLKIN_HZ=25000000 */
39#define VCO5 (CONFIG_CLKIN_HZ*45)
40#define VCO4 (CONFIG_CLKIN_HZ*36)
41#define VCO3 (CONFIG_CLKIN_HZ*27)
42#define VCO2 (CONFIG_CLKIN_HZ*18)
43#define VCO1 (CONFIG_CLKIN_HZ*9)
44#define VCO(x) VCO##x
45
46#define MFREQ(x) {VCO(x),VCO(x)/4},{VCO(x),VCO(x)/2},{VCO(x),VCO(x)}
47/* frequency */
48static struct cpufreq_frequency_table bf548_freq_table[] = {
49 MFREQ(1),
50 MFREQ(3),
51 {VCO4, VCO4 / 2}, {VCO4, VCO4},
52 MFREQ(5),
53 {0, CPUFREQ_TABLE_END},
54};
55
56/*
57 * dpmc_fops->ioctl()
58 * static int dpmc_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg)
59 */
60static int bf548_getfreq(unsigned int cpu)
61{
62 unsigned long cclk_mhz;
63
64 /* The driver only support single cpu */
65 if (cpu == 0)
66 dpmc_fops.ioctl(NULL, NULL, IOCTL_GET_CORECLOCK, &cclk_mhz);
67 else
68 cclk_mhz = -1;
69
70 return cclk_mhz;
71}
72
73static int bf548_target(struct cpufreq_policy *policy,
74 unsigned int target_freq, unsigned int relation)
75{
76 unsigned long cclk_mhz;
77 unsigned long vco_mhz;
78 unsigned long flags;
79 unsigned int index;
80 struct cpufreq_freqs freqs;
81
82 if (cpufreq_frequency_table_target(policy, bf548_freq_table, target_freq, relation, &index))
83 return -EINVAL;
84
85 cclk_mhz = bf548_freq_table[index].frequency;
86 vco_mhz = bf548_freq_table[index].index;
87
88 dpmc_fops.ioctl(NULL, NULL, IOCTL_CHANGE_FREQUENCY, &vco_mhz);
89 freqs.old = bf548_getfreq(0);
90 freqs.new = cclk_mhz;
91 freqs.cpu = 0;
92
93 pr_debug("cclk begin change to cclk %d,vco=%d,index=%d,target=%d,oldfreq=%d\n",
94 cclk_mhz, vco_mhz, index, target_freq, freqs.old);
95
96 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
97 local_irq_save(flags);
98 dpmc_fops.ioctl(NULL, NULL, IOCTL_SET_CCLK, &cclk_mhz);
99 local_irq_restore(flags);
100 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
101
102 vco_mhz = get_vco();
103 cclk_mhz = get_cclk();
104 return 0;
105}
106
107/* make sure that only the "userspace" governor is run -- anything else wouldn't make sense on
108 * this platform, anyway.
109 */
110static int bf548_verify_speed(struct cpufreq_policy *policy)
111{
112 return cpufreq_frequency_table_verify(policy, &bf548_freq_table);
113}
114
115static int __init __bf548_cpu_init(struct cpufreq_policy *policy)
116{
117 if (policy->cpu != 0)
118 return -EINVAL;
119
120 policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
121
122 policy->cpuinfo.transition_latency = CPUFREQ_ETERNAL;
123 /*Now ,only support one cpu */
124 policy->cur = bf548_getfreq(0);
125 cpufreq_frequency_table_get_attr(bf548_freq_table, policy->cpu);
126 return cpufreq_frequency_table_cpuinfo(policy, bf548_freq_table);
127}
128
129static struct freq_attr *bf548_freq_attr[] = {
130 &cpufreq_freq_attr_scaling_available_freqs,
131 NULL,
132};
133
134static struct cpufreq_driver bf548_driver = {
135 .verify = bf548_verify_speed,
136 .target = bf548_target,
137 .get = bf548_getfreq,
138 .init = __bf548_cpu_init,
139 .name = "bf548",
140 .owner = THIS_MODULE,
141 .attr = bf548_freq_attr,
142};
143
144static int __init bf548_cpu_init(void)
145{
146 return cpufreq_register_driver(&bf548_driver);
147}
148
149static void __exit bf548_cpu_exit(void)
150{
151 cpufreq_unregister_driver(&bf548_driver);
152}
153
154MODULE_AUTHOR("Mickael Kang");
155MODULE_DESCRIPTION("cpufreq driver for BF548 CPU");
156MODULE_LICENSE("GPL");
157
158module_init(bf548_cpu_init);
159module_exit(bf548_cpu_exit);
diff --git a/arch/blackfin/mach-bf548/dma.c b/arch/blackfin/mach-bf548/dma.c
index f5479298bb79..74730eb8ae1b 100644
--- a/arch/blackfin/mach-bf548/dma.c
+++ b/arch/blackfin/mach-bf548/dma.c
@@ -32,7 +32,7 @@
32#include <asm/blackfin.h> 32#include <asm/blackfin.h>
33#include <asm/dma.h> 33#include <asm/dma.h>
34 34
35 struct dma_register *base_addr[MAX_BLACKFIN_DMA_CHANNEL] = { 35struct dma_register *dma_io_base_addr[MAX_BLACKFIN_DMA_CHANNEL] = {
36 (struct dma_register *) DMA0_NEXT_DESC_PTR, 36 (struct dma_register *) DMA0_NEXT_DESC_PTR,
37 (struct dma_register *) DMA1_NEXT_DESC_PTR, 37 (struct dma_register *) DMA1_NEXT_DESC_PTR,
38 (struct dma_register *) DMA2_NEXT_DESC_PTR, 38 (struct dma_register *) DMA2_NEXT_DESC_PTR,
@@ -66,7 +66,7 @@
66 (struct dma_register *) MDMA_D3_NEXT_DESC_PTR, 66 (struct dma_register *) MDMA_D3_NEXT_DESC_PTR,
67 (struct dma_register *) MDMA_S3_NEXT_DESC_PTR, 67 (struct dma_register *) MDMA_S3_NEXT_DESC_PTR,
68}; 68};
69EXPORT_SYMBOL(base_addr); 69EXPORT_SYMBOL(dma_io_base_addr);
70 70
71int channel2irq(unsigned int channel) 71int channel2irq(unsigned int channel)
72{ 72{
diff --git a/arch/blackfin/mach-bf548/head.S b/arch/blackfin/mach-bf548/head.S
index 46222a75321a..f7191141a3ce 100644
--- a/arch/blackfin/mach-bf548/head.S
+++ b/arch/blackfin/mach-bf548/head.S
@@ -36,9 +36,6 @@
36#include <asm/mach/mem_init.h> 36#include <asm/mach/mem_init.h>
37#endif 37#endif
38 38
39.global __rambase
40.global __ramstart
41.global __ramend
42.extern ___bss_stop 39.extern ___bss_stop
43.extern ___bss_start 40.extern ___bss_start
44.extern _bf53x_relocate_l1_mem 41.extern _bf53x_relocate_l1_mem
@@ -456,18 +453,3 @@ ENTRY(_start_dma_code)
456 RTS; 453 RTS;
457ENDPROC(_start_dma_code) 454ENDPROC(_start_dma_code)
458#endif /* CONFIG_BFIN_KERNEL_CLOCK */ 455#endif /* CONFIG_BFIN_KERNEL_CLOCK */
459
460.data
461
462/*
463 * Set up the usable of RAM stuff. Size of RAM is determined then
464 * an initial stack set up at the end.
465 */
466
467.align 4
468__rambase:
469.long 0
470__ramstart:
471.long 0
472__ramend:
473.long 0
diff --git a/arch/blackfin/mach-bf561/boards/cm_bf561.c b/arch/blackfin/mach-bf561/boards/cm_bf561.c
index bf9e738a7c64..9fd580952fd8 100644
--- a/arch/blackfin/mach-bf561/boards/cm_bf561.c
+++ b/arch/blackfin/mach-bf561/boards/cm_bf561.c
@@ -283,6 +283,25 @@ static struct platform_device bfin_uart_device = {
283}; 283};
284#endif 284#endif
285 285
286#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
287static struct resource bfin_sir_resources[] = {
288#ifdef CONFIG_BFIN_SIR0
289 {
290 .start = 0xFFC00400,
291 .end = 0xFFC004FF,
292 .flags = IORESOURCE_MEM,
293 },
294#endif
295};
296
297static struct platform_device bfin_sir_device = {
298 .name = "bfin_sir",
299 .id = 0,
300 .num_resources = ARRAY_SIZE(bfin_sir_resources),
301 .resource = bfin_sir_resources,
302};
303#endif
304
286#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE) 305#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
287#define PATA_INT 119 306#define PATA_INT 119
288 307
@@ -330,6 +349,10 @@ static struct platform_device *cm_bf561_devices[] __initdata = {
330 &bfin_uart_device, 349 &bfin_uart_device,
331#endif 350#endif
332 351
352#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
353 &bfin_sir_device,
354#endif
355
333#if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE) 356#if defined(CONFIG_USB_ISP1362_HCD) || defined(CONFIG_USB_ISP1362_HCD_MODULE)
334 &isp1362_hcd_device, 357 &isp1362_hcd_device,
335#endif 358#endif
@@ -349,7 +372,7 @@ static struct platform_device *cm_bf561_devices[] __initdata = {
349 372
350static int __init cm_bf561_init(void) 373static int __init cm_bf561_init(void)
351{ 374{
352 printk(KERN_INFO "%s(): registering device resources\n", __FUNCTION__); 375 printk(KERN_INFO "%s(): registering device resources\n", __func__);
353 platform_add_devices(cm_bf561_devices, ARRAY_SIZE(cm_bf561_devices)); 376 platform_add_devices(cm_bf561_devices, ARRAY_SIZE(cm_bf561_devices));
354#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE) 377#if defined(CONFIG_SPI_BFIN) || defined(CONFIG_SPI_BFIN_MODULE)
355 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info)); 378 spi_register_board_info(bfin_spi_board_info, ARRAY_SIZE(bfin_spi_board_info));
diff --git a/arch/blackfin/mach-bf561/boards/ezkit.c b/arch/blackfin/mach-bf561/boards/ezkit.c
index d357f648d963..0d74b7d99209 100644
--- a/arch/blackfin/mach-bf561/boards/ezkit.c
+++ b/arch/blackfin/mach-bf561/boards/ezkit.c
@@ -78,7 +78,7 @@ int __init bfin_isp1761_init(void)
78{ 78{
79 unsigned int num_devices = ARRAY_SIZE(bfin_isp1761_devices); 79 unsigned int num_devices = ARRAY_SIZE(bfin_isp1761_devices);
80 80
81 printk(KERN_INFO "%s(): registering device resources\n", __FUNCTION__); 81 printk(KERN_INFO "%s(): registering device resources\n", __func__);
82 set_irq_type(ISP1761_IRQ, IRQF_TRIGGER_FALLING); 82 set_irq_type(ISP1761_IRQ, IRQF_TRIGGER_FALLING);
83 83
84 return platform_add_devices(bfin_isp1761_devices, num_devices); 84 return platform_add_devices(bfin_isp1761_devices, num_devices);
@@ -220,6 +220,26 @@ static struct platform_device bfin_uart_device = {
220}; 220};
221#endif 221#endif
222 222
223#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
224static struct resource bfin_sir_resources[] = {
225#ifdef CONFIG_BFIN_SIR0
226 {
227 .start = 0xFFC00400,
228 .end = 0xFFC004FF,
229 .flags = IORESOURCE_MEM,
230 },
231#endif
232};
233
234static struct platform_device bfin_sir_device = {
235 .name = "bfin_sir",
236 .id = 0,
237 .num_resources = ARRAY_SIZE(bfin_sir_resources),
238 .resource = bfin_sir_resources,
239};
240#endif
241
242#if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
223static struct mtd_partition ezkit_partitions[] = { 243static struct mtd_partition ezkit_partitions[] = {
224 { 244 {
225 .name = "Bootloader", 245 .name = "Bootloader",
@@ -227,7 +247,7 @@ static struct mtd_partition ezkit_partitions[] = {
227 .offset = 0, 247 .offset = 0,
228 }, { 248 }, {
229 .name = "Kernel", 249 .name = "Kernel",
230 .size = 0xE0000, 250 .size = 0x1C0000,
231 .offset = MTDPART_OFS_APPEND, 251 .offset = MTDPART_OFS_APPEND,
232 }, { 252 }, {
233 .name = "RootFS", 253 .name = "RootFS",
@@ -257,6 +277,7 @@ static struct platform_device ezkit_flash_device = {
257 .num_resources = 1, 277 .num_resources = 1,
258 .resource = &ezkit_flash_resource, 278 .resource = &ezkit_flash_resource,
259}; 279};
280#endif
260 281
261#ifdef CONFIG_SPI_BFIN 282#ifdef CONFIG_SPI_BFIN
262#if defined(CONFIG_SND_BLACKFIN_AD1836) \ 283#if defined(CONFIG_SND_BLACKFIN_AD1836) \
@@ -443,6 +464,10 @@ static struct platform_device *ezkit_devices[] __initdata = {
443 &bfin_uart_device, 464 &bfin_uart_device,
444#endif 465#endif
445 466
467#if defined(CONFIG_BFIN_SIR) || defined(CONFIG_BFIN_SIR_MODULE)
468 &bfin_sir_device,
469#endif
470
446#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE) 471#if defined(CONFIG_PATA_PLATFORM) || defined(CONFIG_PATA_PLATFORM_MODULE)
447 &bfin_pata_device, 472 &bfin_pata_device,
448#endif 473#endif
@@ -460,7 +485,10 @@ static struct platform_device *ezkit_devices[] __initdata = {
460#endif 485#endif
461 486
462 &bfin_gpios_device, 487 &bfin_gpios_device,
488
489#if defined(CONFIG_MTD_PHYSMAP) || defined(CONFIG_MTD_PHYSMAP_MODULE)
463 &ezkit_flash_device, 490 &ezkit_flash_device,
491#endif
464}; 492};
465 493
466static int __init ezkit_init(void) 494static int __init ezkit_init(void)
diff --git a/arch/blackfin/mach-bf561/boards/generic_board.c b/arch/blackfin/mach-bf561/boards/generic_board.c
index fc80c5d059f8..2faa0072d614 100644
--- a/arch/blackfin/mach-bf561/boards/generic_board.c
+++ b/arch/blackfin/mach-bf561/boards/generic_board.c
@@ -70,7 +70,7 @@ static struct platform_device *generic_board_devices[] __initdata = {
70 70
71static int __init generic_board_init(void) 71static int __init generic_board_init(void)
72{ 72{
73 printk(KERN_INFO "%s(): registering device resources\n", __FUNCTION__); 73 printk(KERN_INFO "%s(): registering device resources\n", __func__);
74 return platform_add_devices(generic_board_devices, 74 return platform_add_devices(generic_board_devices,
75 ARRAY_SIZE(generic_board_devices)); 75 ARRAY_SIZE(generic_board_devices));
76} 76}
diff --git a/arch/blackfin/mach-bf561/boards/tepla.c b/arch/blackfin/mach-bf561/boards/tepla.c
index ec6a2207c202..c9174b39f98d 100644
--- a/arch/blackfin/mach-bf561/boards/tepla.c
+++ b/arch/blackfin/mach-bf561/boards/tepla.c
@@ -50,7 +50,7 @@ static struct platform_device *tepla_devices[] __initdata = {
50 50
51static int __init tepla_init(void) 51static int __init tepla_init(void)
52{ 52{
53 printk(KERN_INFO "%s(): registering device resources\n", __FUNCTION__); 53 printk(KERN_INFO "%s(): registering device resources\n", __func__);
54 return platform_add_devices(tepla_devices, ARRAY_SIZE(tepla_devices)); 54 return platform_add_devices(tepla_devices, ARRAY_SIZE(tepla_devices));
55} 55}
56 56
diff --git a/arch/blackfin/mach-bf561/dma.c b/arch/blackfin/mach-bf561/dma.c
index 89c65bb0bed3..24415eb82698 100644
--- a/arch/blackfin/mach-bf561/dma.c
+++ b/arch/blackfin/mach-bf561/dma.c
@@ -26,10 +26,12 @@
26 * to the Free Software Foundation, Inc., 26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */ 28 */
29#include <linux/module.h>
30
29#include <asm/blackfin.h> 31#include <asm/blackfin.h>
30#include <asm/dma.h> 32#include <asm/dma.h>
31 33
32struct dma_register *base_addr[MAX_BLACKFIN_DMA_CHANNEL] = { 34struct dma_register *dma_io_base_addr[MAX_BLACKFIN_DMA_CHANNEL] = {
33 (struct dma_register *) DMA1_0_NEXT_DESC_PTR, 35 (struct dma_register *) DMA1_0_NEXT_DESC_PTR,
34 (struct dma_register *) DMA1_1_NEXT_DESC_PTR, 36 (struct dma_register *) DMA1_1_NEXT_DESC_PTR,
35 (struct dma_register *) DMA1_2_NEXT_DESC_PTR, 37 (struct dma_register *) DMA1_2_NEXT_DESC_PTR,
@@ -67,6 +69,7 @@ struct dma_register *base_addr[MAX_BLACKFIN_DMA_CHANNEL] = {
67 (struct dma_register *) IMDMA_D1_NEXT_DESC_PTR, 69 (struct dma_register *) IMDMA_D1_NEXT_DESC_PTR,
68 (struct dma_register *) IMDMA_S1_NEXT_DESC_PTR, 70 (struct dma_register *) IMDMA_S1_NEXT_DESC_PTR,
69}; 71};
72EXPORT_SYMBOL(dma_io_base_addr);
70 73
71int channel2irq(unsigned int channel) 74int channel2irq(unsigned int channel)
72{ 75{
diff --git a/arch/blackfin/mach-bf561/head.S b/arch/blackfin/mach-bf561/head.S
index 96a3d456fb6d..5b8bd40851dd 100644
--- a/arch/blackfin/mach-bf561/head.S
+++ b/arch/blackfin/mach-bf561/head.S
@@ -37,9 +37,6 @@
37#include <asm/mach/mem_init.h> 37#include <asm/mach/mem_init.h>
38#endif 38#endif
39 39
40.global __rambase
41.global __ramstart
42.global __ramend
43.extern ___bss_stop 40.extern ___bss_stop
44.extern ___bss_start 41.extern ___bss_start
45.extern _bf53x_relocate_l1_mem 42.extern _bf53x_relocate_l1_mem
@@ -139,26 +136,26 @@ ENTRY(__start)
139 136
140 /* Initialise UART - when booting from u-boot, the UART is not disabled 137 /* Initialise UART - when booting from u-boot, the UART is not disabled
141 * so if we dont initalize here, our serial console gets hosed */ 138 * so if we dont initalize here, our serial console gets hosed */
142 p0.h = hi(UART_LCR); 139 p0.h = hi(BFIN_UART_LCR);
143 p0.l = lo(UART_LCR); 140 p0.l = lo(BFIN_UART_LCR);
144 r0 = 0x0(Z); 141 r0 = 0x0(Z);
145 w[p0] = r0.L; /* To enable DLL writes */ 142 w[p0] = r0.L; /* To enable DLL writes */
146 ssync; 143 ssync;
147 144
148 p0.h = hi(UART_DLL); 145 p0.h = hi(BFIN_UART_DLL);
149 p0.l = lo(UART_DLL); 146 p0.l = lo(BFIN_UART_DLL);
150 r0 = 0x0(Z); 147 r0 = 0x0(Z);
151 w[p0] = r0.L; 148 w[p0] = r0.L;
152 ssync; 149 ssync;
153 150
154 p0.h = hi(UART_DLH); 151 p0.h = hi(BFIN_UART_DLH);
155 p0.l = lo(UART_DLH); 152 p0.l = lo(BFIN_UART_DLH);
156 r0 = 0x00(Z); 153 r0 = 0x00(Z);
157 w[p0] = r0.L; 154 w[p0] = r0.L;
158 ssync; 155 ssync;
159 156
160 p0.h = hi(UART_GCTL); 157 p0.h = hi(BFIN_UART_GCTL);
161 p0.l = lo(UART_GCTL); 158 p0.l = lo(BFIN_UART_GCTL);
162 r0 = 0x0(Z); 159 r0 = 0x0(Z);
163 w[p0] = r0.L; /* To enable UART clock */ 160 w[p0] = r0.L; /* To enable UART clock */
164 ssync; 161 ssync;
@@ -411,18 +408,3 @@ ENTRY(_start_dma_code)
411 RTS; 408 RTS;
412ENDPROC(_start_dma_code) 409ENDPROC(_start_dma_code)
413#endif /* CONFIG_BFIN_KERNEL_CLOCK */ 410#endif /* CONFIG_BFIN_KERNEL_CLOCK */
414
415.data
416
417/*
418 * Set up the usable of RAM stuff. Size of RAM is determined then
419 * an initial stack set up at the end.
420 */
421
422.align 4
423__rambase:
424.long 0
425__ramstart:
426.long 0
427__ramend:
428.long 0
diff --git a/arch/blackfin/mach-common/Makefile b/arch/blackfin/mach-common/Makefile
index 15e33ca1ce80..393081e9b680 100644
--- a/arch/blackfin/mach-common/Makefile
+++ b/arch/blackfin/mach-common/Makefile
@@ -6,4 +6,5 @@ obj-y := \
6 cache.o cacheinit.o entry.o \ 6 cache.o cacheinit.o entry.o \
7 interrupt.o lock.o irqpanic.o arch_checks.o ints-priority.o 7 interrupt.o lock.o irqpanic.o arch_checks.o ints-priority.o
8 8
9obj-$(CONFIG_PM) += pm.o dpmc.o 9obj-$(CONFIG_PM) += pm.o dpmc.o
10obj-$(CONFIG_CPU_FREQ) += cpufreq.o
diff --git a/arch/blackfin/mach-common/arch_checks.c b/arch/blackfin/mach-common/arch_checks.c
index 2f6ce397780f..caaab49e9cfa 100644
--- a/arch/blackfin/mach-common/arch_checks.c
+++ b/arch/blackfin/mach-common/arch_checks.c
@@ -54,7 +54,8 @@
54 54
55#endif /* CONFIG_BFIN_KERNEL_CLOCK */ 55#endif /* CONFIG_BFIN_KERNEL_CLOCK */
56 56
57#ifdef CONFIG_MEM_SIZE
57#if (CONFIG_MEM_SIZE % 4) 58#if (CONFIG_MEM_SIZE % 4)
58#error "SDRAM mem size must be multible of 4MB" 59#error "SDRAM mem size must be multible of 4MB"
59#endif 60#endif
60 61#endif
diff --git a/arch/blackfin/mach-common/cpufreq.c b/arch/blackfin/mach-common/cpufreq.c
new file mode 100644
index 000000000000..ed81e00d20e1
--- /dev/null
+++ b/arch/blackfin/mach-common/cpufreq.c
@@ -0,0 +1,194 @@
1/*
2 * File: arch/blackfin/mach-common/cpufreq.c
3 * Based on:
4 * Author:
5 *
6 * Created:
7 * Description: Blackfin core clock scaling
8 *
9 * Modified:
10 * Copyright 2004-2008 Analog Devices Inc.
11 *
12 * Bugs: Enter bugs at http://blackfin.uclinux.org/
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
18 *
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, see the file COPYING, or write
26 * to the Free Software Foundation, Inc.,
27 * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
28 */
29
30#include <linux/kernel.h>
31#include <linux/types.h>
32#include <linux/init.h>
33#include <linux/cpufreq.h>
34#include <linux/fs.h>
35#include <asm/blackfin.h>
36#include <asm/time.h>
37
38
39/* this is the table of CCLK frequencies, in Hz */
40/* .index is the entry in the auxillary dpm_state_table[] */
41static struct cpufreq_frequency_table bfin_freq_table[] = {
42 {
43 .frequency = CPUFREQ_TABLE_END,
44 .index = 0,
45 },
46 {
47 .frequency = CPUFREQ_TABLE_END,
48 .index = 1,
49 },
50 {
51 .frequency = CPUFREQ_TABLE_END,
52 .index = 2,
53 },
54 {
55 .frequency = CPUFREQ_TABLE_END,
56 .index = 0,
57 },
58};
59
60static struct bfin_dpm_state {
61 unsigned int csel; /* system clock divider */
62 unsigned int tscale; /* change the divider on the core timer interrupt */
63} dpm_state_table[3];
64
65/**************************************************************************/
66
67static unsigned int bfin_getfreq(unsigned int cpu)
68{
69 /* The driver only support single cpu */
70 if (cpu != 0)
71 return -1;
72
73 return get_cclk();
74}
75
76
77static int bfin_target(struct cpufreq_policy *policy,
78 unsigned int target_freq, unsigned int relation)
79{
80 unsigned int index, plldiv, tscale;
81 unsigned long flags, cclk_hz;
82 struct cpufreq_freqs freqs;
83
84 if (cpufreq_frequency_table_target(policy, bfin_freq_table,
85 target_freq, relation, &index))
86 return -EINVAL;
87
88 cclk_hz = bfin_freq_table[index].frequency;
89
90 freqs.old = bfin_getfreq(0);
91 freqs.new = cclk_hz;
92 freqs.cpu = 0;
93
94 pr_debug("cpufreq: changing cclk to %lu; target = %u, oldfreq = %u\n",
95 cclk_hz, target_freq, freqs.old);
96
97 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
98 local_irq_save(flags);
99 plldiv = (bfin_read_PLL_DIV() & SSEL) | dpm_state_table[index].csel;
100 tscale = dpm_state_table[index].tscale;
101 bfin_write_PLL_DIV(plldiv);
102 /* we have to adjust the core timer, because it is using cclk */
103 bfin_write_TSCALE(tscale);
104 SSYNC();
105 local_irq_restore(flags);
106 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
107
108 return 0;
109}
110
111static int bfin_verify_speed(struct cpufreq_policy *policy)
112{
113 return cpufreq_frequency_table_verify(policy, bfin_freq_table);
114}
115
116static int __init __bfin_cpu_init(struct cpufreq_policy *policy)
117{
118
119 unsigned long cclk, sclk, csel, min_cclk;
120 int index;
121
122#ifdef CONFIG_CYCLES_CLOCKSOURCE
123/*
124 * Clocksource CYCLES is still CONTINUOUS but not longer MONOTONIC in case we enable
125 * CPU frequency scaling, since CYCLES runs off Core Clock.
126 */
127 printk(KERN_WARNING "CPU frequency scaling not supported: Clocksource not suitable\n"
128 return -ENODEV;
129#endif
130
131 if (policy->cpu != 0)
132 return -EINVAL;
133
134 cclk = get_cclk();
135 sclk = get_sclk();
136
137#if ANOMALY_05000273
138 min_cclk = sclk * 2;
139#else
140 min_cclk = sclk;
141#endif
142 csel = ((bfin_read_PLL_DIV() & CSEL) >> 4);
143
144 for (index = 0; (cclk >> index) >= min_cclk && csel <= 3; index++, csel++) {
145 bfin_freq_table[index].frequency = cclk >> index;
146 dpm_state_table[index].csel = csel << 4; /* Shift now into PLL_DIV bitpos */
147 dpm_state_table[index].tscale = (TIME_SCALE / (1 << csel)) - 1;
148
149 pr_debug("cpufreq: freq:%d csel:%d tscale:%d\n",
150 bfin_freq_table[index].frequency,
151 dpm_state_table[index].csel,
152 dpm_state_table[index].tscale);
153 }
154
155 policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
156
157 policy->cpuinfo.transition_latency = (bfin_read_PLL_LOCKCNT() / (sclk / 1000000)) * 1000;
158 /*Now ,only support one cpu */
159 policy->cur = cclk;
160 cpufreq_frequency_table_get_attr(bfin_freq_table, policy->cpu);
161 return cpufreq_frequency_table_cpuinfo(policy, bfin_freq_table);
162}
163
164static struct freq_attr *bfin_freq_attr[] = {
165 &cpufreq_freq_attr_scaling_available_freqs,
166 NULL,
167};
168
169static struct cpufreq_driver bfin_driver = {
170 .verify = bfin_verify_speed,
171 .target = bfin_target,
172 .get = bfin_getfreq,
173 .init = __bfin_cpu_init,
174 .name = "bfin cpufreq",
175 .owner = THIS_MODULE,
176 .attr = bfin_freq_attr,
177};
178
179static int __init bfin_cpu_init(void)
180{
181 return cpufreq_register_driver(&bfin_driver);
182}
183
184static void __exit bfin_cpu_exit(void)
185{
186 cpufreq_unregister_driver(&bfin_driver);
187}
188
189MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
190MODULE_DESCRIPTION("cpufreq driver for Blackfin");
191MODULE_LICENSE("GPL");
192
193module_init(bfin_cpu_init);
194module_exit(bfin_cpu_exit);
diff --git a/arch/blackfin/mach-common/entry.S b/arch/blackfin/mach-common/entry.S
index cee54cebbc65..f2fb87e9a46e 100644
--- a/arch/blackfin/mach-common/entry.S
+++ b/arch/blackfin/mach-common/entry.S
@@ -38,6 +38,7 @@
38#include <linux/unistd.h> 38#include <linux/unistd.h>
39#include <asm/blackfin.h> 39#include <asm/blackfin.h>
40#include <asm/errno.h> 40#include <asm/errno.h>
41#include <asm/fixed_code.h>
41#include <asm/thread_info.h> /* TIF_NEED_RESCHED */ 42#include <asm/thread_info.h> /* TIF_NEED_RESCHED */
42#include <asm/asm-offsets.h> 43#include <asm/asm-offsets.h>
43#include <asm/trace.h> 44#include <asm/trace.h>
@@ -52,15 +53,6 @@
52# define EX_SCRATCH_REG CYCLES 53# define EX_SCRATCH_REG CYCLES
53#endif 54#endif
54 55
55#if ANOMALY_05000281
56ENTRY(_safe_speculative_execution)
57 NOP;
58 NOP;
59 NOP;
60 jump _safe_speculative_execution;
61ENDPROC(_safe_speculative_execution)
62#endif
63
64#ifdef CONFIG_EXCPT_IRQ_SYSC_L1 56#ifdef CONFIG_EXCPT_IRQ_SYSC_L1
65.section .l1.text 57.section .l1.text
66#else 58#else
@@ -121,10 +113,14 @@ ENTRY(_ex_icplb_miss)
121 (R7:6,P5:4) = [sp++]; 113 (R7:6,P5:4) = [sp++];
122 ASTAT = [sp++]; 114 ASTAT = [sp++];
123 SAVE_ALL_SYS 115 SAVE_ALL_SYS
124 DEBUG_HWTRACE_SAVE(p5, r7)
125#ifdef CONFIG_MPU 116#ifdef CONFIG_MPU
117 /* We must load R1 here, _before_ DEBUG_HWTRACE_SAVE, since that
118 * will change the stack pointer. */
126 R0 = SEQSTAT; 119 R0 = SEQSTAT;
127 R1 = SP; 120 R1 = SP;
121#endif
122 DEBUG_HWTRACE_SAVE(p5, r7)
123#ifdef CONFIG_MPU
128 sp += -12; 124 sp += -12;
129 call _cplb_hdr; 125 call _cplb_hdr;
130 sp += 12; 126 sp += 12;
@@ -191,6 +187,7 @@ ENTRY(_bfin_return_from_exception)
191ENDPROC(_bfin_return_from_exception) 187ENDPROC(_bfin_return_from_exception)
192 188
193ENTRY(_handle_bad_cplb) 189ENTRY(_handle_bad_cplb)
190 DEBUG_HWTRACE_RESTORE(p5, r7)
194 /* To get here, we just tried and failed to change a CPLB 191 /* To get here, we just tried and failed to change a CPLB
195 * so, handle things in trap_c (C code), by lowering to 192 * so, handle things in trap_c (C code), by lowering to
196 * IRQ5, just like we normally do. Since this is not a 193 * IRQ5, just like we normally do. Since this is not a
@@ -225,6 +222,26 @@ ENTRY(_ex_trap_c)
225 [p4] = p5; 222 [p4] = p5;
226 csync; 223 csync;
227 224
225 p4.l = lo(DCPLB_FAULT_ADDR);
226 p4.h = hi(DCPLB_FAULT_ADDR);
227 r7 = [p4];
228 p5.h = _saved_dcplb_fault_addr;
229 p5.l = _saved_dcplb_fault_addr;
230 [p5] = r7;
231
232 r7 = [p4 + (ICPLB_FAULT_ADDR - DCPLB_FAULT_ADDR)];
233 p5.h = _saved_icplb_fault_addr;
234 p5.l = _saved_icplb_fault_addr;
235 [p5] = r7;
236
237 p4.l = __retx;
238 p4.h = __retx;
239 r6 = retx;
240 [p4] = r6;
241 p4.l = lo(SAFE_USER_INSTRUCTION);
242 p4.h = hi(SAFE_USER_INSTRUCTION);
243 retx = p4;
244
228 /* Disable all interrupts, but make sure level 5 is enabled so 245 /* Disable all interrupts, but make sure level 5 is enabled so
229 * we can switch to that level. Save the old mask. */ 246 * we can switch to that level. Save the old mask. */
230 cli r6; 247 cli r6;
@@ -234,23 +251,6 @@ ENTRY(_ex_trap_c)
234 r6 = 0x3f; 251 r6 = 0x3f;
235 sti r6; 252 sti r6;
236 253
237 /* Save the excause into a circular buffer, in case the instruction
238 * which caused this excecptions causes others.
239 */
240 P5.l = _in_ptr_excause;
241 P5.h = _in_ptr_excause;
242 R7 = [P5];
243 R7 += 4;
244 R6 = 0xF;
245 R7 = R7 & R6;
246 [P5] = R7;
247 R6.l = _excause_circ_buf;
248 R6.h = _excause_circ_buf;
249 R7 = R7 + R6;
250 p5 = R7;
251 R6 = SEQSTAT;
252 [P5] = R6;
253
254 (R7:6,P5:4) = [sp++]; 254 (R7:6,P5:4) = [sp++];
255 ASTAT = [sp++]; 255 ASTAT = [sp++];
256 SP = EX_SCRATCH_REG; 256 SP = EX_SCRATCH_REG;
@@ -307,6 +307,11 @@ ENDPROC(_double_fault)
307ENTRY(_exception_to_level5) 307ENTRY(_exception_to_level5)
308 SAVE_ALL_SYS 308 SAVE_ALL_SYS
309 309
310 p4.l = __retx;
311 p4.h = __retx;
312 r6 = [p4];
313 [sp + PT_PC] = r6;
314
310 /* Restore interrupt mask. We haven't pushed RETI, so this 315 /* Restore interrupt mask. We haven't pushed RETI, so this
311 * doesn't enable interrupts until we return from this handler. */ 316 * doesn't enable interrupts until we return from this handler. */
312 p4.l = _excpt_saved_imask; 317 p4.l = _excpt_saved_imask;
@@ -328,42 +333,11 @@ ENTRY(_exception_to_level5)
328 r0 = [p2]; /* Read current IPEND */ 333 r0 = [p2]; /* Read current IPEND */
329 [sp + PT_IPEND] = r0; /* Store IPEND */ 334 [sp + PT_IPEND] = r0; /* Store IPEND */
330 335
331 /* Pop the excause from the circular buffer and push it on the stack
332 * (in the right place - if you change the location of SEQSTAT, you
333 * must change this offset.
334 */
335.L_excep_to_5_again:
336 P5.l = _out_ptr_excause;
337 P5.h = _out_ptr_excause;
338 R7 = [P5];
339 R7 += 4;
340 R6 = 0xF;
341 R7 = R7 & R6;
342 [P5] = R7;
343 R6.l = _excause_circ_buf;
344 R6.h = _excause_circ_buf;
345 R7 = R7 + R6;
346 P5 = R7;
347 R1 = [P5];
348 [SP + PT_SEQSTAT] = r1;
349
350 r0 = sp; /* stack frame pt_regs pointer argument ==> r0 */ 336 r0 = sp; /* stack frame pt_regs pointer argument ==> r0 */
351 SP += -12; 337 SP += -12;
352 call _trap_c; 338 call _trap_c;
353 SP += 12; 339 SP += 12;
354 340
355 /* See if anything else is in the exception buffer
356 * if there is, process it
357 */
358 P5.l = _out_ptr_excause;
359 P5.h = _out_ptr_excause;
360 P4.l = _in_ptr_excause;
361 P4.h = _in_ptr_excause;
362 R6 = [P5];
363 R7 = [P4];
364 CC = R6 == R7;
365 if ! CC JUMP .L_excep_to_5_again
366
367 call _ret_from_exception; 341 call _ret_from_exception;
368 RESTORE_ALL_SYS 342 RESTORE_ALL_SYS
369 rti; 343 rti;
@@ -727,8 +701,8 @@ ENTRY(_return_from_int)
727 [p0] = p1; 701 [p0] = p1;
728 csync; 702 csync;
729#if ANOMALY_05000281 703#if ANOMALY_05000281
730 r0.l = _safe_speculative_execution; 704 r0.l = lo(SAFE_USER_INSTRUCTION);
731 r0.h = _safe_speculative_execution; 705 r0.h = hi(SAFE_USER_INSTRUCTION);
732 reti = r0; 706 reti = r0;
733#endif 707#endif
734 r0 = 0x801f (z); 708 r0 = 0x801f (z);
@@ -741,8 +715,8 @@ ENDPROC(_return_from_int)
741 715
742ENTRY(_lower_to_irq14) 716ENTRY(_lower_to_irq14)
743#if ANOMALY_05000281 717#if ANOMALY_05000281
744 r0.l = _safe_speculative_execution; 718 r0.l = lo(SAFE_USER_INSTRUCTION);
745 r0.h = _safe_speculative_execution; 719 r0.h = hi(SAFE_USER_INSTRUCTION);
746 reti = r0; 720 reti = r0;
747#endif 721#endif
748 r0 = 0x401f; 722 r0 = 0x401f;
@@ -809,20 +783,6 @@ _schedule_and_signal:
809 rti; 783 rti;
810ENDPROC(_lower_to_irq14) 784ENDPROC(_lower_to_irq14)
811 785
812/* Make sure when we start, that the circular buffer is initialized properly
813 * R0 and P0 are call clobbered, so we can use them here.
814 */
815ENTRY(_init_exception_buff)
816 r0 = 0;
817 p0.h = _in_ptr_excause;
818 p0.l = _in_ptr_excause;
819 [p0] = r0;
820 p0.h = _out_ptr_excause;
821 p0.l = _out_ptr_excause;
822 [p0] = r0;
823 rts;
824ENDPROC(_init_exception_buff)
825
826/* We handle this 100% in exception space - to reduce overhead 786/* We handle this 100% in exception space - to reduce overhead
827 * Only potiential problem is if the software buffer gets swapped out of the 787 * Only potiential problem is if the software buffer gets swapped out of the
828 * CPLB table - then double fault. - so we don't let this happen in other places 788 * CPLB table - then double fault. - so we don't let this happen in other places
@@ -1398,17 +1358,7 @@ _exception_stack_top:
1398_last_cplb_fault_retx: 1358_last_cplb_fault_retx:
1399 .long 0; 1359 .long 0;
1400#endif 1360#endif
1401/* 1361 /* Used to save the real RETX when temporarily storing a safe
1402 * Single instructions can have multiple faults, which need to be 1362 * return address. */
1403 * handled by traps.c, in irq5. We store the exception cause to ensure 1363__retx:
1404 * we don't miss a double fault condition
1405 */
1406ENTRY(_in_ptr_excause)
1407 .long 0; 1364 .long 0;
1408ENTRY(_out_ptr_excause)
1409 .long 0;
1410ALIGN
1411ENTRY(_excause_circ_buf)
1412 .rept 4
1413 .long 0
1414 .endr
diff --git a/arch/blackfin/mach-common/ints-priority.c b/arch/blackfin/mach-common/ints-priority.c
index 225ef14af75e..f5fd768022ea 100644
--- a/arch/blackfin/mach-common/ints-priority.c
+++ b/arch/blackfin/mach-common/ints-priority.c
@@ -316,7 +316,7 @@ static void bfin_demux_error_irq(unsigned int int_err_irq,
316 printk(KERN_ERR 316 printk(KERN_ERR
317 "%s : %s : LINE %d :\nIRQ ?: PERIPHERAL ERROR" 317 "%s : %s : LINE %d :\nIRQ ?: PERIPHERAL ERROR"
318 " INTERRUPT ASSERTED BUT NO SOURCE FOUND\n", 318 " INTERRUPT ASSERTED BUT NO SOURCE FOUND\n",
319 __FUNCTION__, __FILE__, __LINE__); 319 __func__, __FILE__, __LINE__);
320 320
321} 321}
322#endif /* BF537_GENERIC_ERROR_INT_DEMUX */ 322#endif /* BF537_GENERIC_ERROR_INT_DEMUX */
@@ -326,6 +326,7 @@ static void bfin_demux_error_irq(unsigned int int_err_irq,
326static unsigned short gpio_enabled[gpio_bank(MAX_BLACKFIN_GPIOS)]; 326static unsigned short gpio_enabled[gpio_bank(MAX_BLACKFIN_GPIOS)];
327static unsigned short gpio_edge_triggered[gpio_bank(MAX_BLACKFIN_GPIOS)]; 327static unsigned short gpio_edge_triggered[gpio_bank(MAX_BLACKFIN_GPIOS)];
328 328
329extern void bfin_gpio_irq_prepare(unsigned gpio);
329 330
330static void bfin_gpio_ack_irq(unsigned int irq) 331static void bfin_gpio_ack_irq(unsigned int irq)
331{ 332{
@@ -364,35 +365,25 @@ static void bfin_gpio_unmask_irq(unsigned int irq)
364 365
365static unsigned int bfin_gpio_irq_startup(unsigned int irq) 366static unsigned int bfin_gpio_irq_startup(unsigned int irq)
366{ 367{
367 unsigned int ret;
368 u16 gpionr = irq - IRQ_PF0; 368 u16 gpionr = irq - IRQ_PF0;
369 char buf[8];
370 369
371 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) { 370 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)))
372 snprintf(buf, sizeof buf, "IRQ %d", irq); 371 bfin_gpio_irq_prepare(gpionr);
373 ret = gpio_request(gpionr, buf);
374 if (ret)
375 return ret;
376 }
377 372
378 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr); 373 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
379 bfin_gpio_unmask_irq(irq); 374 bfin_gpio_unmask_irq(irq);
380 375
381 return ret; 376 return 0;
382} 377}
383 378
384static void bfin_gpio_irq_shutdown(unsigned int irq) 379static void bfin_gpio_irq_shutdown(unsigned int irq)
385{ 380{
386 bfin_gpio_mask_irq(irq); 381 bfin_gpio_mask_irq(irq);
387 gpio_free(irq - IRQ_PF0);
388 gpio_enabled[gpio_bank(irq - IRQ_PF0)] &= ~gpio_bit(irq - IRQ_PF0); 382 gpio_enabled[gpio_bank(irq - IRQ_PF0)] &= ~gpio_bit(irq - IRQ_PF0);
389} 383}
390 384
391static int bfin_gpio_irq_type(unsigned int irq, unsigned int type) 385static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
392{ 386{
393
394 unsigned int ret;
395 char buf[8];
396 u16 gpionr = irq - IRQ_PF0; 387 u16 gpionr = irq - IRQ_PF0;
397 388
398 if (type == IRQ_TYPE_PROBE) { 389 if (type == IRQ_TYPE_PROBE) {
@@ -404,12 +395,8 @@ static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
404 395
405 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING | 396 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
406 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) { 397 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
407 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) { 398 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)))
408 snprintf(buf, sizeof buf, "IRQ %d", irq); 399 bfin_gpio_irq_prepare(gpionr);
409 ret = gpio_request(gpionr, buf);
410 if (ret)
411 return ret;
412 }
413 400
414 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr); 401 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
415 } else { 402 } else {
@@ -595,6 +582,8 @@ static struct pin_int_t *pint[NR_PINT_SYS_IRQS] = {
595 (struct pin_int_t *)PINT3_MASK_SET, 582 (struct pin_int_t *)PINT3_MASK_SET,
596}; 583};
597 584
585extern void bfin_gpio_irq_prepare(unsigned gpio);
586
598inline unsigned short get_irq_base(u8 bank, u8 bmap) 587inline unsigned short get_irq_base(u8 bank, u8 bmap)
599{ 588{
600 589
@@ -697,8 +686,6 @@ static void bfin_gpio_unmask_irq(unsigned int irq)
697 686
698static unsigned int bfin_gpio_irq_startup(unsigned int irq) 687static unsigned int bfin_gpio_irq_startup(unsigned int irq)
699{ 688{
700 unsigned int ret;
701 char buf[8];
702 u16 gpionr = irq_to_gpio(irq); 689 u16 gpionr = irq_to_gpio(irq);
703 u8 pint_val = irq2pint_lut[irq - SYS_IRQS]; 690 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
704 691
@@ -709,17 +696,13 @@ static unsigned int bfin_gpio_irq_startup(unsigned int irq)
709 return -ENODEV; 696 return -ENODEV;
710 } 697 }
711 698
712 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) { 699 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)))
713 snprintf(buf, sizeof buf, "IRQ %d", irq); 700 bfin_gpio_irq_prepare(gpionr);
714 ret = gpio_request(gpionr, buf);
715 if (ret)
716 return ret;
717 }
718 701
719 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr); 702 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
720 bfin_gpio_unmask_irq(irq); 703 bfin_gpio_unmask_irq(irq);
721 704
722 return ret; 705 return 0;
723} 706}
724 707
725static void bfin_gpio_irq_shutdown(unsigned int irq) 708static void bfin_gpio_irq_shutdown(unsigned int irq)
@@ -727,15 +710,12 @@ static void bfin_gpio_irq_shutdown(unsigned int irq)
727 u16 gpionr = irq_to_gpio(irq); 710 u16 gpionr = irq_to_gpio(irq);
728 711
729 bfin_gpio_mask_irq(irq); 712 bfin_gpio_mask_irq(irq);
730 gpio_free(gpionr);
731 gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr); 713 gpio_enabled[gpio_bank(gpionr)] &= ~gpio_bit(gpionr);
732} 714}
733 715
734static int bfin_gpio_irq_type(unsigned int irq, unsigned int type) 716static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
735{ 717{
736 718
737 unsigned int ret;
738 char buf[8];
739 u16 gpionr = irq_to_gpio(irq); 719 u16 gpionr = irq_to_gpio(irq);
740 u8 pint_val = irq2pint_lut[irq - SYS_IRQS]; 720 u8 pint_val = irq2pint_lut[irq - SYS_IRQS];
741 u32 pintbit = PINT_BIT(pint_val); 721 u32 pintbit = PINT_BIT(pint_val);
@@ -753,12 +733,8 @@ static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
753 733
754 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING | 734 if (type & (IRQ_TYPE_EDGE_RISING | IRQ_TYPE_EDGE_FALLING |
755 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) { 735 IRQ_TYPE_LEVEL_HIGH | IRQ_TYPE_LEVEL_LOW)) {
756 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr))) { 736 if (!(gpio_enabled[gpio_bank(gpionr)] & gpio_bit(gpionr)))
757 snprintf(buf, sizeof buf, "IRQ %d", irq); 737 bfin_gpio_irq_prepare(gpionr);
758 ret = gpio_request(gpionr, buf);
759 if (ret)
760 return ret;
761 }
762 738
763 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr); 739 gpio_enabled[gpio_bank(gpionr)] |= gpio_bit(gpionr);
764 } else { 740 } else {
@@ -766,8 +742,6 @@ static int bfin_gpio_irq_type(unsigned int irq, unsigned int type)
766 return 0; 742 return 0;
767 } 743 }
768 744
769 gpio_direction_input(gpionr);
770
771 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW))) 745 if ((type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_LEVEL_LOW)))
772 pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */ 746 pint[bank]->invert_set = pintbit; /* low or falling edge denoted by one */
773 else 747 else
@@ -965,8 +939,6 @@ int __init init_arch_irq(void)
965 939
966 local_irq_disable(); 940 local_irq_disable();
967 941
968 init_exception_buff();
969
970#ifdef CONFIG_BF54x 942#ifdef CONFIG_BF54x
971# ifdef CONFIG_PINTx_REASSIGN 943# ifdef CONFIG_PINTx_REASSIGN
972 pint[0]->assign = CONFIG_PINT0_ASSIGN; 944 pint[0]->assign = CONFIG_PINT0_ASSIGN;
diff --git a/arch/blackfin/mach-common/lock.S b/arch/blackfin/mach-common/lock.S
index 28b87fe9ce3c..30b887e67dd6 100644
--- a/arch/blackfin/mach-common/lock.S
+++ b/arch/blackfin/mach-common/lock.S
@@ -174,7 +174,7 @@ ENTRY(_cache_lock)
174 CLI R3; 174 CLI R3;
175 175
176 R7 = [P1]; 176 R7 = [P1];
177 R2 = 0xFFFFFF87 (X); 177 R2 = ~(0x78) (X); /* mask out ILOC */
178 R7 = R7 & R2; 178 R7 = R7 & R2;
179 R0 = R0 << 3; 179 R0 = R0 << 3;
180 R7 = R0 | R7; 180 R7 = R0 | R7;
diff --git a/arch/blackfin/mm/blackfin_sram.c b/arch/blackfin/mm/blackfin_sram.c
index e41f0e8ecacb..3246f91c7baa 100644
--- a/arch/blackfin/mm/blackfin_sram.c
+++ b/arch/blackfin/mm/blackfin_sram.c
@@ -401,7 +401,7 @@ EXPORT_SYMBOL(l1_data_sram_free);
401 401
402void *l1_inst_sram_alloc(size_t size) 402void *l1_inst_sram_alloc(size_t size)
403{ 403{
404#if L1_DATA_A_LENGTH != 0 404#if L1_CODE_LENGTH != 0
405 unsigned flags; 405 unsigned flags;
406 void *addr; 406 void *addr;
407 407
diff --git a/arch/blackfin/oprofile/common.c b/arch/blackfin/oprofile/common.c
index cb8b8d5af34f..0f6d303a8891 100644
--- a/arch/blackfin/oprofile/common.c
+++ b/arch/blackfin/oprofile/common.c
@@ -75,7 +75,7 @@ static int op_bfin_start(void)
75{ 75{
76 int ret = -EBUSY; 76 int ret = -EBUSY;
77 77
78 printk(KERN_INFO "KSDBG:in %s\n", __FUNCTION__); 78 printk(KERN_INFO "KSDBG:in %s\n", __func__);
79 mutex_lock(&pfmon_lock); 79 mutex_lock(&pfmon_lock);
80 if (!pfmon_enabled) { 80 if (!pfmon_enabled) {
81 ret = model->start(ctr); 81 ret = model->start(ctr);
diff --git a/arch/blackfin/oprofile/op_model_bf533.c b/arch/blackfin/oprofile/op_model_bf533.c
index 872dffe33623..d1c698bb9ee5 100644
--- a/arch/blackfin/oprofile/op_model_bf533.c
+++ b/arch/blackfin/oprofile/op_model_bf533.c
@@ -125,7 +125,7 @@ int pm_overflow_handler(int irq, struct pt_regs *regs)
125 unsigned int pc, pfctl; 125 unsigned int pc, pfctl;
126 unsigned int count[2]; 126 unsigned int count[2];
127 127
128 pr_debug("get interrupt in %s\n", __FUNCTION__); 128 pr_debug("get interrupt in %s\n", __func__);
129 if (oprofile_running == 0) { 129 if (oprofile_running == 0) {
130 pr_debug("error: entering interrupt when oprofile is stopped.\n\r"); 130 pr_debug("error: entering interrupt when oprofile is stopped.\n\r");
131 return -1; 131 return -1;
diff --git a/arch/sparc/kernel/entry.S b/arch/sparc/kernel/entry.S
index 135644f8add7..484c83d23eef 100644
--- a/arch/sparc/kernel/entry.S
+++ b/arch/sparc/kernel/entry.S
@@ -1409,7 +1409,6 @@ syscall_is_too_hard:
1409 1409
1410 st %o0, [%sp + STACKFRAME_SZ + PT_I0] 1410 st %o0, [%sp + STACKFRAME_SZ + PT_I0]
1411 1411
1412 .globl ret_sys_call
1413ret_sys_call: 1412ret_sys_call:
1414 ld [%curptr + TI_FLAGS], %l6 1413 ld [%curptr + TI_FLAGS], %l6
1415 cmp %o0, -ERESTART_RESTARTBLOCK 1414 cmp %o0, -ERESTART_RESTARTBLOCK
diff --git a/arch/sparc/kernel/signal.c b/arch/sparc/kernel/signal.c
index 1f730619a24a..3e849e8e3480 100644
--- a/arch/sparc/kernel/signal.c
+++ b/arch/sparc/kernel/signal.c
@@ -105,11 +105,6 @@ static int _sigpause_common(old_sigset_t set)
105 return -ERESTARTNOHAND; 105 return -ERESTARTNOHAND;
106} 106}
107 107
108asmlinkage int sys_sigpause(unsigned int set)
109{
110 return _sigpause_common(set);
111}
112
113asmlinkage int sys_sigsuspend(old_sigset_t set) 108asmlinkage int sys_sigsuspend(old_sigset_t set)
114{ 109{
115 return _sigpause_common(set); 110 return _sigpause_common(set);
diff --git a/arch/sparc64/Kconfig b/arch/sparc64/Kconfig
index df3eacb5ca15..8acc5cc38621 100644
--- a/arch/sparc64/Kconfig
+++ b/arch/sparc64/Kconfig
@@ -250,6 +250,26 @@ endchoice
250 250
251endmenu 251endmenu
252 252
253config NUMA
254 bool "NUMA support"
255
256config NODES_SHIFT
257 int
258 default "4"
259 depends on NEED_MULTIPLE_NODES
260
261# Some NUMA nodes have memory ranges that span
262# other nodes. Even though a pfn is valid and
263# between a node's start and end pfns, it may not
264# reside on that node. See memmap_init_zone()
265# for details.
266config NODES_SPAN_OTHER_NODES
267 def_bool y
268 depends on NEED_MULTIPLE_NODES
269
270config ARCH_POPULATES_NODE_MAP
271 def_bool y
272
253config ARCH_SELECT_MEMORY_MODEL 273config ARCH_SELECT_MEMORY_MODEL
254 def_bool y 274 def_bool y
255 275
diff --git a/arch/sparc64/defconfig b/arch/sparc64/defconfig
index e1835868ad36..92f79680f70d 100644
--- a/arch/sparc64/defconfig
+++ b/arch/sparc64/defconfig
@@ -1,7 +1,7 @@
1# 1#
2# Automatically generated make config: don't edit 2# Automatically generated make config: don't edit
3# Linux kernel version: 2.6.25 3# Linux kernel version: 2.6.25-numa
4# Sun Apr 20 01:33:21 2008 4# Wed Apr 23 04:49:08 2008
5# 5#
6CONFIG_SPARC=y 6CONFIG_SPARC=y
7CONFIG_SPARC64=y 7CONFIG_SPARC64=y
@@ -152,6 +152,8 @@ CONFIG_GENERIC_CALIBRATE_DELAY=y
152CONFIG_HUGETLB_PAGE_SIZE_4MB=y 152CONFIG_HUGETLB_PAGE_SIZE_4MB=y
153# CONFIG_HUGETLB_PAGE_SIZE_512K is not set 153# CONFIG_HUGETLB_PAGE_SIZE_512K is not set
154# CONFIG_HUGETLB_PAGE_SIZE_64K is not set 154# CONFIG_HUGETLB_PAGE_SIZE_64K is not set
155# CONFIG_NUMA is not set
156CONFIG_ARCH_POPULATES_NODE_MAP=y
155CONFIG_ARCH_SELECT_MEMORY_MODEL=y 157CONFIG_ARCH_SELECT_MEMORY_MODEL=y
156CONFIG_ARCH_SPARSEMEM_ENABLE=y 158CONFIG_ARCH_SPARSEMEM_ENABLE=y
157CONFIG_ARCH_SPARSEMEM_DEFAULT=y 159CONFIG_ARCH_SPARSEMEM_DEFAULT=y
@@ -787,7 +789,6 @@ CONFIG_I2C_ALGOBIT=y
787# CONFIG_SENSORS_PCF8574 is not set 789# CONFIG_SENSORS_PCF8574 is not set
788# CONFIG_PCF8575 is not set 790# CONFIG_PCF8575 is not set
789# CONFIG_SENSORS_PCF8591 is not set 791# CONFIG_SENSORS_PCF8591 is not set
790# CONFIG_TPS65010 is not set
791# CONFIG_SENSORS_MAX6875 is not set 792# CONFIG_SENSORS_MAX6875 is not set
792# CONFIG_SENSORS_TSL2550 is not set 793# CONFIG_SENSORS_TSL2550 is not set
793# CONFIG_I2C_DEBUG_CORE is not set 794# CONFIG_I2C_DEBUG_CORE is not set
@@ -869,6 +870,7 @@ CONFIG_SSB_POSSIBLE=y
869# Multifunction device drivers 870# Multifunction device drivers
870# 871#
871# CONFIG_MFD_SM501 is not set 872# CONFIG_MFD_SM501 is not set
873# CONFIG_HTC_PASIC3 is not set
872 874
873# 875#
874# Multimedia devices 876# Multimedia devices
@@ -1219,10 +1221,6 @@ CONFIG_USB_STORAGE=m
1219# CONFIG_NEW_LEDS is not set 1221# CONFIG_NEW_LEDS is not set
1220# CONFIG_INFINIBAND is not set 1222# CONFIG_INFINIBAND is not set
1221# CONFIG_RTC_CLASS is not set 1223# CONFIG_RTC_CLASS is not set
1222
1223#
1224# Userspace I/O
1225#
1226# CONFIG_UIO is not set 1224# CONFIG_UIO is not set
1227 1225
1228# 1226#
@@ -1399,6 +1397,7 @@ CONFIG_SCHEDSTATS=y
1399CONFIG_DEBUG_BUGVERBOSE=y 1397CONFIG_DEBUG_BUGVERBOSE=y
1400# CONFIG_DEBUG_INFO is not set 1398# CONFIG_DEBUG_INFO is not set
1401# CONFIG_DEBUG_VM is not set 1399# CONFIG_DEBUG_VM is not set
1400# CONFIG_DEBUG_WRITECOUNT is not set
1402# CONFIG_DEBUG_LIST is not set 1401# CONFIG_DEBUG_LIST is not set
1403# CONFIG_DEBUG_SG is not set 1402# CONFIG_DEBUG_SG is not set
1404# CONFIG_BOOT_PRINTK_DELAY is not set 1403# CONFIG_BOOT_PRINTK_DELAY is not set
@@ -1425,53 +1424,82 @@ CONFIG_ASYNC_CORE=m
1425CONFIG_ASYNC_MEMCPY=m 1424CONFIG_ASYNC_MEMCPY=m
1426CONFIG_ASYNC_XOR=m 1425CONFIG_ASYNC_XOR=m
1427CONFIG_CRYPTO=y 1426CONFIG_CRYPTO=y
1427
1428#
1429# Crypto core or helper
1430#
1428CONFIG_CRYPTO_ALGAPI=y 1431CONFIG_CRYPTO_ALGAPI=y
1429CONFIG_CRYPTO_AEAD=y 1432CONFIG_CRYPTO_AEAD=y
1430CONFIG_CRYPTO_BLKCIPHER=y 1433CONFIG_CRYPTO_BLKCIPHER=y
1431# CONFIG_CRYPTO_SEQIV is not set
1432CONFIG_CRYPTO_HASH=y 1434CONFIG_CRYPTO_HASH=y
1433CONFIG_CRYPTO_MANAGER=y 1435CONFIG_CRYPTO_MANAGER=y
1436CONFIG_CRYPTO_GF128MUL=m
1437CONFIG_CRYPTO_NULL=m
1438# CONFIG_CRYPTO_CRYPTD is not set
1439CONFIG_CRYPTO_AUTHENC=y
1440CONFIG_CRYPTO_TEST=m
1441
1442#
1443# Authenticated Encryption with Associated Data
1444#
1445# CONFIG_CRYPTO_CCM is not set
1446# CONFIG_CRYPTO_GCM is not set
1447# CONFIG_CRYPTO_SEQIV is not set
1448
1449#
1450# Block modes
1451#
1452CONFIG_CRYPTO_CBC=y
1453# CONFIG_CRYPTO_CTR is not set
1454# CONFIG_CRYPTO_CTS is not set
1455CONFIG_CRYPTO_ECB=m
1456CONFIG_CRYPTO_LRW=m
1457CONFIG_CRYPTO_PCBC=m
1458CONFIG_CRYPTO_XTS=m
1459
1460#
1461# Hash modes
1462#
1434CONFIG_CRYPTO_HMAC=y 1463CONFIG_CRYPTO_HMAC=y
1435CONFIG_CRYPTO_XCBC=y 1464CONFIG_CRYPTO_XCBC=y
1436CONFIG_CRYPTO_NULL=m 1465
1466#
1467# Digest
1468#
1469CONFIG_CRYPTO_CRC32C=m
1437CONFIG_CRYPTO_MD4=y 1470CONFIG_CRYPTO_MD4=y
1438CONFIG_CRYPTO_MD5=y 1471CONFIG_CRYPTO_MD5=y
1472CONFIG_CRYPTO_MICHAEL_MIC=m
1439CONFIG_CRYPTO_SHA1=y 1473CONFIG_CRYPTO_SHA1=y
1440CONFIG_CRYPTO_SHA256=m 1474CONFIG_CRYPTO_SHA256=m
1441CONFIG_CRYPTO_SHA512=m 1475CONFIG_CRYPTO_SHA512=m
1442CONFIG_CRYPTO_WP512=m
1443CONFIG_CRYPTO_TGR192=m 1476CONFIG_CRYPTO_TGR192=m
1444CONFIG_CRYPTO_GF128MUL=m 1477CONFIG_CRYPTO_WP512=m
1445CONFIG_CRYPTO_ECB=m 1478
1446CONFIG_CRYPTO_CBC=y 1479#
1447CONFIG_CRYPTO_PCBC=m 1480# Ciphers
1448CONFIG_CRYPTO_LRW=m 1481#
1449CONFIG_CRYPTO_XTS=m
1450# CONFIG_CRYPTO_CTR is not set
1451# CONFIG_CRYPTO_GCM is not set
1452# CONFIG_CRYPTO_CCM is not set
1453# CONFIG_CRYPTO_CRYPTD is not set
1454CONFIG_CRYPTO_DES=y
1455CONFIG_CRYPTO_FCRYPT=m
1456CONFIG_CRYPTO_BLOWFISH=m
1457CONFIG_CRYPTO_TWOFISH=m
1458CONFIG_CRYPTO_TWOFISH_COMMON=m
1459CONFIG_CRYPTO_SERPENT=m
1460CONFIG_CRYPTO_AES=m 1482CONFIG_CRYPTO_AES=m
1483CONFIG_CRYPTO_ANUBIS=m
1484CONFIG_CRYPTO_ARC4=m
1485CONFIG_CRYPTO_BLOWFISH=m
1486CONFIG_CRYPTO_CAMELLIA=m
1461CONFIG_CRYPTO_CAST5=m 1487CONFIG_CRYPTO_CAST5=m
1462CONFIG_CRYPTO_CAST6=m 1488CONFIG_CRYPTO_CAST6=m
1463CONFIG_CRYPTO_TEA=m 1489CONFIG_CRYPTO_DES=y
1464CONFIG_CRYPTO_ARC4=m 1490CONFIG_CRYPTO_FCRYPT=m
1465CONFIG_CRYPTO_KHAZAD=m 1491CONFIG_CRYPTO_KHAZAD=m
1466CONFIG_CRYPTO_ANUBIS=m
1467CONFIG_CRYPTO_SEED=m
1468# CONFIG_CRYPTO_SALSA20 is not set 1492# CONFIG_CRYPTO_SALSA20 is not set
1493CONFIG_CRYPTO_SEED=m
1494CONFIG_CRYPTO_SERPENT=m
1495CONFIG_CRYPTO_TEA=m
1496CONFIG_CRYPTO_TWOFISH=m
1497CONFIG_CRYPTO_TWOFISH_COMMON=m
1498
1499#
1500# Compression
1501#
1469CONFIG_CRYPTO_DEFLATE=y 1502CONFIG_CRYPTO_DEFLATE=y
1470CONFIG_CRYPTO_MICHAEL_MIC=m
1471CONFIG_CRYPTO_CRC32C=m
1472CONFIG_CRYPTO_CAMELLIA=m
1473CONFIG_CRYPTO_TEST=m
1474CONFIG_CRYPTO_AUTHENC=y
1475# CONFIG_CRYPTO_LZO is not set 1503# CONFIG_CRYPTO_LZO is not set
1476CONFIG_CRYPTO_HW=y 1504CONFIG_CRYPTO_HW=y
1477# CONFIG_CRYPTO_DEV_HIFN_795X is not set 1505# CONFIG_CRYPTO_DEV_HIFN_795X is not set
@@ -1492,3 +1520,4 @@ CONFIG_PLIST=y
1492CONFIG_HAS_IOMEM=y 1520CONFIG_HAS_IOMEM=y
1493CONFIG_HAS_IOPORT=y 1521CONFIG_HAS_IOPORT=y
1494CONFIG_HAS_DMA=y 1522CONFIG_HAS_DMA=y
1523CONFIG_HAVE_LMB=y
diff --git a/arch/sparc64/kernel/ebus.c b/arch/sparc64/kernel/ebus.c
index 04ab81cb4f48..bc2632274840 100644
--- a/arch/sparc64/kernel/ebus.c
+++ b/arch/sparc64/kernel/ebus.c
@@ -396,6 +396,7 @@ static void __init fill_ebus_device(struct device_node *dp, struct linux_ebus_de
396 sd->op = &dev->ofdev; 396 sd->op = &dev->ofdev;
397 sd->iommu = dev->bus->ofdev.dev.parent->archdata.iommu; 397 sd->iommu = dev->bus->ofdev.dev.parent->archdata.iommu;
398 sd->stc = dev->bus->ofdev.dev.parent->archdata.stc; 398 sd->stc = dev->bus->ofdev.dev.parent->archdata.stc;
399 sd->numa_node = dev->bus->ofdev.dev.parent->archdata.numa_node;
399 400
400 dev->ofdev.node = dp; 401 dev->ofdev.node = dp;
401 dev->ofdev.dev.parent = &dev->bus->ofdev.dev; 402 dev->ofdev.dev.parent = &dev->bus->ofdev.dev;
diff --git a/arch/sparc64/kernel/entry.S b/arch/sparc64/kernel/entry.S
index fb43c76bdc26..fd06e937ae1e 100644
--- a/arch/sparc64/kernel/entry.S
+++ b/arch/sparc64/kernel/entry.S
@@ -47,7 +47,7 @@ do_fpdis:
47 ba,pt %xcc, etrap 47 ba,pt %xcc, etrap
48109: or %g7, %lo(109b), %g7 48109: or %g7, %lo(109b), %g7
49 add %g0, %g0, %g0 49 add %g0, %g0, %g0
50 ba,a,pt %xcc, rtrap_clr_l6 50 ba,a,pt %xcc, rtrap
51 51
521: TRAP_LOAD_THREAD_REG(%g6, %g1) 521: TRAP_LOAD_THREAD_REG(%g6, %g1)
53 ldub [%g6 + TI_FPSAVED], %g5 53 ldub [%g6 + TI_FPSAVED], %g5
@@ -226,7 +226,7 @@ fp_other_bounce:
226 call do_fpother 226 call do_fpother
227 add %sp, PTREGS_OFF, %o0 227 add %sp, PTREGS_OFF, %o0
228 ba,pt %xcc, rtrap 228 ba,pt %xcc, rtrap
229 clr %l6 229 nop
230 230
231 .globl do_fpother_check_fitos 231 .globl do_fpother_check_fitos
232 .align 32 232 .align 32
@@ -489,7 +489,7 @@ utrap_trap: /* %g3=handler,%g4=level */
489 call bad_trap 489 call bad_trap
490 add %sp, PTREGS_OFF, %o0 490 add %sp, PTREGS_OFF, %o0
491 ba,pt %xcc, rtrap 491 ba,pt %xcc, rtrap
492 clr %l6 492 nop
493 493
494invoke_utrap: 494invoke_utrap:
495 sllx %g3, 3, %g3 495 sllx %g3, 3, %g3
@@ -607,7 +607,7 @@ __spitfire_cee_trap_continue:
607 call spitfire_access_error 607 call spitfire_access_error
608 add %sp, PTREGS_OFF, %o0 608 add %sp, PTREGS_OFF, %o0
609 ba,pt %xcc, rtrap 609 ba,pt %xcc, rtrap
610 clr %l6 610 nop
611 611
612 /* This is the trap handler entry point for ECC correctable 612 /* This is the trap handler entry point for ECC correctable
613 * errors. They are corrected, but we listen for the trap 613 * errors. They are corrected, but we listen for the trap
@@ -686,7 +686,7 @@ __spitfire_data_access_exception_tl1:
686 call spitfire_data_access_exception_tl1 686 call spitfire_data_access_exception_tl1
687 add %sp, PTREGS_OFF, %o0 687 add %sp, PTREGS_OFF, %o0
688 ba,pt %xcc, rtrap 688 ba,pt %xcc, rtrap
689 clr %l6 689 nop
690 690
691__spitfire_data_access_exception: 691__spitfire_data_access_exception:
692 rdpr %pstate, %g4 692 rdpr %pstate, %g4
@@ -705,7 +705,7 @@ __spitfire_data_access_exception:
705 call spitfire_data_access_exception 705 call spitfire_data_access_exception
706 add %sp, PTREGS_OFF, %o0 706 add %sp, PTREGS_OFF, %o0
707 ba,pt %xcc, rtrap 707 ba,pt %xcc, rtrap
708 clr %l6 708 nop
709 709
710 .globl __spitfire_insn_access_exception 710 .globl __spitfire_insn_access_exception
711 .globl __spitfire_insn_access_exception_tl1 711 .globl __spitfire_insn_access_exception_tl1
@@ -725,7 +725,7 @@ __spitfire_insn_access_exception_tl1:
725 call spitfire_insn_access_exception_tl1 725 call spitfire_insn_access_exception_tl1
726 add %sp, PTREGS_OFF, %o0 726 add %sp, PTREGS_OFF, %o0
727 ba,pt %xcc, rtrap 727 ba,pt %xcc, rtrap
728 clr %l6 728 nop
729 729
730__spitfire_insn_access_exception: 730__spitfire_insn_access_exception:
731 rdpr %pstate, %g4 731 rdpr %pstate, %g4
@@ -743,7 +743,7 @@ __spitfire_insn_access_exception:
743 call spitfire_insn_access_exception 743 call spitfire_insn_access_exception
744 add %sp, PTREGS_OFF, %o0 744 add %sp, PTREGS_OFF, %o0
745 ba,pt %xcc, rtrap 745 ba,pt %xcc, rtrap
746 clr %l6 746 nop
747 747
748 /* These get patched into the trap table at boot time 748 /* These get patched into the trap table at boot time
749 * once we know we have a cheetah processor. 749 * once we know we have a cheetah processor.
@@ -937,7 +937,7 @@ do_dcpe_tl1_fatal:
937 call cheetah_plus_parity_error 937 call cheetah_plus_parity_error
938 add %sp, PTREGS_OFF, %o1 938 add %sp, PTREGS_OFF, %o1
939 ba,pt %xcc, rtrap 939 ba,pt %xcc, rtrap
940 clr %l6 940 nop
941 941
942do_icpe_tl1: 942do_icpe_tl1:
943 rdpr %tl, %g1 ! Save original trap level 943 rdpr %tl, %g1 ! Save original trap level
@@ -979,7 +979,7 @@ do_icpe_tl1_fatal:
979 call cheetah_plus_parity_error 979 call cheetah_plus_parity_error
980 add %sp, PTREGS_OFF, %o1 980 add %sp, PTREGS_OFF, %o1
981 ba,pt %xcc, rtrap 981 ba,pt %xcc, rtrap
982 clr %l6 982 nop
983 983
984dcpe_icpe_tl1_common: 984dcpe_icpe_tl1_common:
985 /* Flush D-cache, re-enable D/I caches in DCU and finally 985 /* Flush D-cache, re-enable D/I caches in DCU and finally
@@ -1281,7 +1281,7 @@ __do_privact:
1281 call do_privact 1281 call do_privact
1282 add %sp, PTREGS_OFF, %o0 1282 add %sp, PTREGS_OFF, %o0
1283 ba,pt %xcc, rtrap 1283 ba,pt %xcc, rtrap
1284 clr %l6 1284 nop
1285 1285
1286 .globl do_mna 1286 .globl do_mna
1287do_mna: 1287do_mna:
@@ -1308,7 +1308,7 @@ do_mna:
1308 call mem_address_unaligned 1308 call mem_address_unaligned
1309 add %sp, PTREGS_OFF, %o0 1309 add %sp, PTREGS_OFF, %o0
1310 ba,pt %xcc, rtrap 1310 ba,pt %xcc, rtrap
1311 clr %l6 1311 nop
1312 1312
1313 .globl do_lddfmna 1313 .globl do_lddfmna
1314do_lddfmna: 1314do_lddfmna:
@@ -1326,7 +1326,7 @@ do_lddfmna:
1326 call handle_lddfmna 1326 call handle_lddfmna
1327 add %sp, PTREGS_OFF, %o0 1327 add %sp, PTREGS_OFF, %o0
1328 ba,pt %xcc, rtrap 1328 ba,pt %xcc, rtrap
1329 clr %l6 1329 nop
1330 1330
1331 .globl do_stdfmna 1331 .globl do_stdfmna
1332do_stdfmna: 1332do_stdfmna:
@@ -1344,7 +1344,7 @@ do_stdfmna:
1344 call handle_stdfmna 1344 call handle_stdfmna
1345 add %sp, PTREGS_OFF, %o0 1345 add %sp, PTREGS_OFF, %o0
1346 ba,pt %xcc, rtrap 1346 ba,pt %xcc, rtrap
1347 clr %l6 1347 nop
1348 1348
1349 .globl breakpoint_trap 1349 .globl breakpoint_trap
1350breakpoint_trap: 1350breakpoint_trap:
@@ -1424,13 +1424,13 @@ sys32_rt_sigreturn:
14241: ldx [%curptr + TI_FLAGS], %l5 14241: ldx [%curptr + TI_FLAGS], %l5
1425 andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0 1425 andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT), %g0
1426 be,pt %icc, rtrap 1426 be,pt %icc, rtrap
1427 clr %l6 1427 nop
1428 add %sp, PTREGS_OFF, %o0 1428 add %sp, PTREGS_OFF, %o0
1429 call syscall_trace 1429 call syscall_trace
1430 mov 1, %o1 1430 mov 1, %o1
1431 1431
1432 ba,pt %xcc, rtrap 1432 ba,pt %xcc, rtrap
1433 clr %l6 1433 nop
1434 1434
1435 /* This is how fork() was meant to be done, 8 instruction entry. 1435 /* This is how fork() was meant to be done, 8 instruction entry.
1436 * 1436 *
@@ -1559,7 +1559,7 @@ linux_sparc_syscall32:
1559 1559
1560 /* Linux native system calls enter here... */ 1560 /* Linux native system calls enter here... */
1561 .align 32 1561 .align 32
1562 .globl linux_sparc_syscall, ret_sys_call 1562 .globl linux_sparc_syscall
1563linux_sparc_syscall: 1563linux_sparc_syscall:
1564 /* Direct access to user regs, much faster. */ 1564 /* Direct access to user regs, much faster. */
1565 cmp %g1, NR_SYSCALLS ! IEU1 Group 1565 cmp %g1, NR_SYSCALLS ! IEU1 Group
@@ -1605,7 +1605,7 @@ ret_sys_call:
1605 bne,pn %icc, linux_syscall_trace2 1605 bne,pn %icc, linux_syscall_trace2
1606 add %l1, 0x4, %l2 ! npc = npc+4 1606 add %l1, 0x4, %l2 ! npc = npc+4
1607 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC] 1607 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]
1608 ba,pt %xcc, rtrap_clr_l6 1608 ba,pt %xcc, rtrap
1609 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC] 1609 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]
1610 1610
16111: 16111:
@@ -1616,7 +1616,6 @@ ret_sys_call:
1616 sub %g0, %o0, %o0 1616 sub %g0, %o0, %o0
1617 or %g3, %g2, %g3 1617 or %g3, %g2, %g3
1618 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0] 1618 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
1619 mov 1, %l6
1620 stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE] 1619 stx %g3, [%sp + PTREGS_OFF + PT_V9_TSTATE]
1621 bne,pn %icc, linux_syscall_trace2 1620 bne,pn %icc, linux_syscall_trace2
1622 add %l1, 0x4, %l2 ! npc = npc+4 1621 add %l1, 0x4, %l2 ! npc = npc+4
diff --git a/arch/sparc64/kernel/entry.h b/arch/sparc64/kernel/entry.h
index 4a91e9c6d31b..32fbab620852 100644
--- a/arch/sparc64/kernel/entry.h
+++ b/arch/sparc64/kernel/entry.h
@@ -20,7 +20,6 @@ extern void timer_interrupt(int irq, struct pt_regs *regs);
20 20
21extern void do_notify_resume(struct pt_regs *regs, 21extern void do_notify_resume(struct pt_regs *regs,
22 unsigned long orig_i0, 22 unsigned long orig_i0,
23 int restart_syscall,
24 unsigned long thread_info_flags); 23 unsigned long thread_info_flags);
25 24
26extern asmlinkage void syscall_trace(struct pt_regs *regs, 25extern asmlinkage void syscall_trace(struct pt_regs *regs,
diff --git a/arch/sparc64/kernel/etrap.S b/arch/sparc64/kernel/etrap.S
index 4b2bf9eb447a..b49d3b60bc0c 100644
--- a/arch/sparc64/kernel/etrap.S
+++ b/arch/sparc64/kernel/etrap.S
@@ -53,7 +53,11 @@ etrap_irq:
53 stx %g3, [%g2 + STACKFRAME_SZ + PT_V9_TPC] 53 stx %g3, [%g2 + STACKFRAME_SZ + PT_V9_TPC]
54 rd %y, %g3 54 rd %y, %g3
55 stx %g1, [%g2 + STACKFRAME_SZ + PT_V9_TNPC] 55 stx %g1, [%g2 + STACKFRAME_SZ + PT_V9_TNPC]
56 rdpr %tt, %g1
56 st %g3, [%g2 + STACKFRAME_SZ + PT_V9_Y] 57 st %g3, [%g2 + STACKFRAME_SZ + PT_V9_Y]
58 sethi %hi(PT_REGS_MAGIC), %g3
59 or %g3, %g1, %g1
60 st %g1, [%g2 + STACKFRAME_SZ + PT_V9_MAGIC]
57 61
58 rdpr %cansave, %g1 62 rdpr %cansave, %g1
59 brnz,pt %g1, etrap_save 63 brnz,pt %g1, etrap_save
diff --git a/arch/sparc64/kernel/iommu.c b/arch/sparc64/kernel/iommu.c
index 756fa24eeefa..2a37a6ca2a16 100644
--- a/arch/sparc64/kernel/iommu.c
+++ b/arch/sparc64/kernel/iommu.c
@@ -173,9 +173,11 @@ void iommu_range_free(struct iommu *iommu, dma_addr_t dma_addr, unsigned long np
173} 173}
174 174
175int iommu_table_init(struct iommu *iommu, int tsbsize, 175int iommu_table_init(struct iommu *iommu, int tsbsize,
176 u32 dma_offset, u32 dma_addr_mask) 176 u32 dma_offset, u32 dma_addr_mask,
177 int numa_node)
177{ 178{
178 unsigned long i, tsbbase, order, sz, num_tsb_entries; 179 unsigned long i, order, sz, num_tsb_entries;
180 struct page *page;
179 181
180 num_tsb_entries = tsbsize / sizeof(iopte_t); 182 num_tsb_entries = tsbsize / sizeof(iopte_t);
181 183
@@ -188,11 +190,12 @@ int iommu_table_init(struct iommu *iommu, int tsbsize,
188 /* Allocate and initialize the free area map. */ 190 /* Allocate and initialize the free area map. */
189 sz = num_tsb_entries / 8; 191 sz = num_tsb_entries / 8;
190 sz = (sz + 7UL) & ~7UL; 192 sz = (sz + 7UL) & ~7UL;
191 iommu->arena.map = kzalloc(sz, GFP_KERNEL); 193 iommu->arena.map = kmalloc_node(sz, GFP_KERNEL, numa_node);
192 if (!iommu->arena.map) { 194 if (!iommu->arena.map) {
193 printk(KERN_ERR "IOMMU: Error, kmalloc(arena.map) failed.\n"); 195 printk(KERN_ERR "IOMMU: Error, kmalloc(arena.map) failed.\n");
194 return -ENOMEM; 196 return -ENOMEM;
195 } 197 }
198 memset(iommu->arena.map, 0, sz);
196 iommu->arena.limit = num_tsb_entries; 199 iommu->arena.limit = num_tsb_entries;
197 200
198 if (tlb_type != hypervisor) 201 if (tlb_type != hypervisor)
@@ -201,21 +204,23 @@ int iommu_table_init(struct iommu *iommu, int tsbsize,
201 /* Allocate and initialize the dummy page which we 204 /* Allocate and initialize the dummy page which we
202 * set inactive IO PTEs to point to. 205 * set inactive IO PTEs to point to.
203 */ 206 */
204 iommu->dummy_page = get_zeroed_page(GFP_KERNEL); 207 page = alloc_pages_node(numa_node, GFP_KERNEL, 0);
205 if (!iommu->dummy_page) { 208 if (!page) {
206 printk(KERN_ERR "IOMMU: Error, gfp(dummy_page) failed.\n"); 209 printk(KERN_ERR "IOMMU: Error, gfp(dummy_page) failed.\n");
207 goto out_free_map; 210 goto out_free_map;
208 } 211 }
212 iommu->dummy_page = (unsigned long) page_address(page);
213 memset((void *)iommu->dummy_page, 0, PAGE_SIZE);
209 iommu->dummy_page_pa = (unsigned long) __pa(iommu->dummy_page); 214 iommu->dummy_page_pa = (unsigned long) __pa(iommu->dummy_page);
210 215
211 /* Now allocate and setup the IOMMU page table itself. */ 216 /* Now allocate and setup the IOMMU page table itself. */
212 order = get_order(tsbsize); 217 order = get_order(tsbsize);
213 tsbbase = __get_free_pages(GFP_KERNEL, order); 218 page = alloc_pages_node(numa_node, GFP_KERNEL, order);
214 if (!tsbbase) { 219 if (!page) {
215 printk(KERN_ERR "IOMMU: Error, gfp(tsb) failed.\n"); 220 printk(KERN_ERR "IOMMU: Error, gfp(tsb) failed.\n");
216 goto out_free_dummy_page; 221 goto out_free_dummy_page;
217 } 222 }
218 iommu->page_table = (iopte_t *)tsbbase; 223 iommu->page_table = (iopte_t *)page_address(page);
219 224
220 for (i = 0; i < num_tsb_entries; i++) 225 for (i = 0; i < num_tsb_entries; i++)
221 iopte_make_dummy(iommu, &iommu->page_table[i]); 226 iopte_make_dummy(iommu, &iommu->page_table[i]);
@@ -276,20 +281,24 @@ static inline void iommu_free_ctx(struct iommu *iommu, int ctx)
276static void *dma_4u_alloc_coherent(struct device *dev, size_t size, 281static void *dma_4u_alloc_coherent(struct device *dev, size_t size,
277 dma_addr_t *dma_addrp, gfp_t gfp) 282 dma_addr_t *dma_addrp, gfp_t gfp)
278{ 283{
284 unsigned long flags, order, first_page;
279 struct iommu *iommu; 285 struct iommu *iommu;
286 struct page *page;
287 int npages, nid;
280 iopte_t *iopte; 288 iopte_t *iopte;
281 unsigned long flags, order, first_page;
282 void *ret; 289 void *ret;
283 int npages;
284 290
285 size = IO_PAGE_ALIGN(size); 291 size = IO_PAGE_ALIGN(size);
286 order = get_order(size); 292 order = get_order(size);
287 if (order >= 10) 293 if (order >= 10)
288 return NULL; 294 return NULL;
289 295
290 first_page = __get_free_pages(gfp, order); 296 nid = dev->archdata.numa_node;
291 if (first_page == 0UL) 297 page = alloc_pages_node(nid, gfp, order);
298 if (unlikely(!page))
292 return NULL; 299 return NULL;
300
301 first_page = (unsigned long) page_address(page);
293 memset((char *)first_page, 0, PAGE_SIZE << order); 302 memset((char *)first_page, 0, PAGE_SIZE << order);
294 303
295 iommu = dev->archdata.iommu; 304 iommu = dev->archdata.iommu;
diff --git a/arch/sparc64/kernel/isa.c b/arch/sparc64/kernel/isa.c
index b5f7b354084f..a2af5ed784c9 100644
--- a/arch/sparc64/kernel/isa.c
+++ b/arch/sparc64/kernel/isa.c
@@ -92,6 +92,7 @@ static void __init isa_fill_devices(struct sparc_isa_bridge *isa_br)
92 sd->op = &isa_dev->ofdev; 92 sd->op = &isa_dev->ofdev;
93 sd->iommu = isa_br->ofdev.dev.parent->archdata.iommu; 93 sd->iommu = isa_br->ofdev.dev.parent->archdata.iommu;
94 sd->stc = isa_br->ofdev.dev.parent->archdata.stc; 94 sd->stc = isa_br->ofdev.dev.parent->archdata.stc;
95 sd->numa_node = isa_br->ofdev.dev.parent->archdata.numa_node;
95 96
96 isa_dev->ofdev.node = dp; 97 isa_dev->ofdev.node = dp;
97 isa_dev->ofdev.dev.parent = &isa_br->ofdev.dev; 98 isa_dev->ofdev.dev.parent = &isa_br->ofdev.dev;
diff --git a/arch/sparc64/kernel/mdesc.c b/arch/sparc64/kernel/mdesc.c
index 910083589569..dde52bcf5c64 100644
--- a/arch/sparc64/kernel/mdesc.c
+++ b/arch/sparc64/kernel/mdesc.c
@@ -1,10 +1,10 @@
1/* mdesc.c: Sun4V machine description handling. 1/* mdesc.c: Sun4V machine description handling.
2 * 2 *
3 * Copyright (C) 2007 David S. Miller <davem@davemloft.net> 3 * Copyright (C) 2007, 2008 David S. Miller <davem@davemloft.net>
4 */ 4 */
5#include <linux/kernel.h> 5#include <linux/kernel.h>
6#include <linux/types.h> 6#include <linux/types.h>
7#include <linux/bootmem.h> 7#include <linux/lmb.h>
8#include <linux/log2.h> 8#include <linux/log2.h>
9#include <linux/list.h> 9#include <linux/list.h>
10#include <linux/slab.h> 10#include <linux/slab.h>
@@ -84,24 +84,28 @@ static void mdesc_handle_init(struct mdesc_handle *hp,
84 hp->handle_size = handle_size; 84 hp->handle_size = handle_size;
85} 85}
86 86
87static struct mdesc_handle * __init mdesc_bootmem_alloc(unsigned int mdesc_size) 87static struct mdesc_handle * __init mdesc_lmb_alloc(unsigned int mdesc_size)
88{ 88{
89 struct mdesc_handle *hp;
90 unsigned int handle_size, alloc_size; 89 unsigned int handle_size, alloc_size;
90 struct mdesc_handle *hp;
91 unsigned long paddr;
91 92
92 handle_size = (sizeof(struct mdesc_handle) - 93 handle_size = (sizeof(struct mdesc_handle) -
93 sizeof(struct mdesc_hdr) + 94 sizeof(struct mdesc_hdr) +
94 mdesc_size); 95 mdesc_size);
95 alloc_size = PAGE_ALIGN(handle_size); 96 alloc_size = PAGE_ALIGN(handle_size);
96 97
97 hp = __alloc_bootmem(alloc_size, PAGE_SIZE, 0UL); 98 paddr = lmb_alloc(alloc_size, PAGE_SIZE);
98 if (hp)
99 mdesc_handle_init(hp, handle_size, hp);
100 99
100 hp = NULL;
101 if (paddr) {
102 hp = __va(paddr);
103 mdesc_handle_init(hp, handle_size, hp);
104 }
101 return hp; 105 return hp;
102} 106}
103 107
104static void mdesc_bootmem_free(struct mdesc_handle *hp) 108static void mdesc_lmb_free(struct mdesc_handle *hp)
105{ 109{
106 unsigned int alloc_size, handle_size = hp->handle_size; 110 unsigned int alloc_size, handle_size = hp->handle_size;
107 unsigned long start, end; 111 unsigned long start, end;
@@ -124,9 +128,9 @@ static void mdesc_bootmem_free(struct mdesc_handle *hp)
124 } 128 }
125} 129}
126 130
127static struct mdesc_mem_ops bootmem_mdesc_ops = { 131static struct mdesc_mem_ops lmb_mdesc_ops = {
128 .alloc = mdesc_bootmem_alloc, 132 .alloc = mdesc_lmb_alloc,
129 .free = mdesc_bootmem_free, 133 .free = mdesc_lmb_free,
130}; 134};
131 135
132static struct mdesc_handle *mdesc_kmalloc(unsigned int mdesc_size) 136static struct mdesc_handle *mdesc_kmalloc(unsigned int mdesc_size)
@@ -888,7 +892,7 @@ void __init sun4v_mdesc_init(void)
888 892
889 printk("MDESC: Size is %lu bytes.\n", len); 893 printk("MDESC: Size is %lu bytes.\n", len);
890 894
891 hp = mdesc_alloc(len, &bootmem_mdesc_ops); 895 hp = mdesc_alloc(len, &lmb_mdesc_ops);
892 if (hp == NULL) { 896 if (hp == NULL) {
893 prom_printf("MDESC: alloc of %lu bytes failed.\n", len); 897 prom_printf("MDESC: alloc of %lu bytes failed.\n", len);
894 prom_halt(); 898 prom_halt();
diff --git a/arch/sparc64/kernel/of_device.c b/arch/sparc64/kernel/of_device.c
index 0fd9db95b896..9e58e8cba1c3 100644
--- a/arch/sparc64/kernel/of_device.c
+++ b/arch/sparc64/kernel/of_device.c
@@ -6,6 +6,7 @@
6#include <linux/mod_devicetable.h> 6#include <linux/mod_devicetable.h>
7#include <linux/slab.h> 7#include <linux/slab.h>
8#include <linux/errno.h> 8#include <linux/errno.h>
9#include <linux/irq.h>
9#include <linux/of_device.h> 10#include <linux/of_device.h>
10#include <linux/of_platform.h> 11#include <linux/of_platform.h>
11 12
@@ -660,6 +661,7 @@ static unsigned int __init build_one_device_irq(struct of_device *op,
660 struct device_node *dp = op->node; 661 struct device_node *dp = op->node;
661 struct device_node *pp, *ip; 662 struct device_node *pp, *ip;
662 unsigned int orig_irq = irq; 663 unsigned int orig_irq = irq;
664 int nid;
663 665
664 if (irq == 0xffffffff) 666 if (irq == 0xffffffff)
665 return irq; 667 return irq;
@@ -672,7 +674,7 @@ static unsigned int __init build_one_device_irq(struct of_device *op,
672 printk("%s: direct translate %x --> %x\n", 674 printk("%s: direct translate %x --> %x\n",
673 dp->full_name, orig_irq, irq); 675 dp->full_name, orig_irq, irq);
674 676
675 return irq; 677 goto out;
676 } 678 }
677 679
678 /* Something more complicated. Walk up to the root, applying 680 /* Something more complicated. Walk up to the root, applying
@@ -744,6 +746,14 @@ static unsigned int __init build_one_device_irq(struct of_device *op,
744 printk("%s: Apply IRQ trans [%s] %x --> %x\n", 746 printk("%s: Apply IRQ trans [%s] %x --> %x\n",
745 op->node->full_name, ip->full_name, orig_irq, irq); 747 op->node->full_name, ip->full_name, orig_irq, irq);
746 748
749out:
750 nid = of_node_to_nid(dp);
751 if (nid != -1) {
752 cpumask_t numa_mask = node_to_cpumask(nid);
753
754 irq_set_affinity(irq, numa_mask);
755 }
756
747 return irq; 757 return irq;
748} 758}
749 759
diff --git a/arch/sparc64/kernel/pci.c b/arch/sparc64/kernel/pci.c
index 545356b00e2e..49f912766519 100644
--- a/arch/sparc64/kernel/pci.c
+++ b/arch/sparc64/kernel/pci.c
@@ -369,10 +369,12 @@ struct pci_dev *of_create_pci_dev(struct pci_pbm_info *pbm,
369 sd->host_controller = pbm; 369 sd->host_controller = pbm;
370 sd->prom_node = node; 370 sd->prom_node = node;
371 sd->op = of_find_device_by_node(node); 371 sd->op = of_find_device_by_node(node);
372 sd->numa_node = pbm->numa_node;
372 373
373 sd = &sd->op->dev.archdata; 374 sd = &sd->op->dev.archdata;
374 sd->iommu = pbm->iommu; 375 sd->iommu = pbm->iommu;
375 sd->stc = &pbm->stc; 376 sd->stc = &pbm->stc;
377 sd->numa_node = pbm->numa_node;
376 378
377 type = of_get_property(node, "device_type", NULL); 379 type = of_get_property(node, "device_type", NULL);
378 if (type == NULL) 380 if (type == NULL)
@@ -1159,6 +1161,16 @@ int pci_mmap_page_range(struct pci_dev *dev, struct vm_area_struct *vma,
1159 return 0; 1161 return 0;
1160} 1162}
1161 1163
1164#ifdef CONFIG_NUMA
1165int pcibus_to_node(struct pci_bus *pbus)
1166{
1167 struct pci_pbm_info *pbm = pbus->sysdata;
1168
1169 return pbm->numa_node;
1170}
1171EXPORT_SYMBOL(pcibus_to_node);
1172#endif
1173
1162/* Return the domain nuber for this pci bus */ 1174/* Return the domain nuber for this pci bus */
1163 1175
1164int pci_domain_nr(struct pci_bus *pbus) 1176int pci_domain_nr(struct pci_bus *pbus)
diff --git a/arch/sparc64/kernel/pci_fire.c b/arch/sparc64/kernel/pci_fire.c
index 7571ed563147..d23bb6f53cda 100644
--- a/arch/sparc64/kernel/pci_fire.c
+++ b/arch/sparc64/kernel/pci_fire.c
@@ -71,7 +71,8 @@ static int pci_fire_pbm_iommu_init(struct pci_pbm_info *pbm)
71 */ 71 */
72 fire_write(iommu->iommu_flushinv, ~(u64)0); 72 fire_write(iommu->iommu_flushinv, ~(u64)0);
73 73
74 err = iommu_table_init(iommu, tsbsize * 8 * 1024, vdma[0], dma_mask); 74 err = iommu_table_init(iommu, tsbsize * 8 * 1024, vdma[0], dma_mask,
75 pbm->numa_node);
75 if (err) 76 if (err)
76 return err; 77 return err;
77 78
@@ -449,6 +450,8 @@ static int __init pci_fire_pbm_init(struct pci_controller_info *p,
449 pbm->next = pci_pbm_root; 450 pbm->next = pci_pbm_root;
450 pci_pbm_root = pbm; 451 pci_pbm_root = pbm;
451 452
453 pbm->numa_node = -1;
454
452 pbm->scan_bus = pci_fire_scan_bus; 455 pbm->scan_bus = pci_fire_scan_bus;
453 pbm->pci_ops = &sun4u_pci_ops; 456 pbm->pci_ops = &sun4u_pci_ops;
454 pbm->config_space_reg_bits = 12; 457 pbm->config_space_reg_bits = 12;
diff --git a/arch/sparc64/kernel/pci_impl.h b/arch/sparc64/kernel/pci_impl.h
index 4a50da13ce48..218bac4ff79b 100644
--- a/arch/sparc64/kernel/pci_impl.h
+++ b/arch/sparc64/kernel/pci_impl.h
@@ -148,6 +148,8 @@ struct pci_pbm_info {
148 struct pci_bus *pci_bus; 148 struct pci_bus *pci_bus;
149 void (*scan_bus)(struct pci_pbm_info *); 149 void (*scan_bus)(struct pci_pbm_info *);
150 struct pci_ops *pci_ops; 150 struct pci_ops *pci_ops;
151
152 int numa_node;
151}; 153};
152 154
153struct pci_controller_info { 155struct pci_controller_info {
@@ -161,8 +163,6 @@ extern struct pci_pbm_info *pci_pbm_root;
161extern int pci_num_pbms; 163extern int pci_num_pbms;
162 164
163/* PCI bus scanning and fixup support. */ 165/* PCI bus scanning and fixup support. */
164extern void pci_iommu_table_init(struct iommu *iommu, int tsbsize,
165 u32 dma_offset, u32 dma_addr_mask);
166extern void pci_get_pbm_props(struct pci_pbm_info *pbm); 166extern void pci_get_pbm_props(struct pci_pbm_info *pbm);
167extern struct pci_bus *pci_scan_one_pbm(struct pci_pbm_info *pbm); 167extern struct pci_bus *pci_scan_one_pbm(struct pci_pbm_info *pbm);
168extern void pci_determine_mem_io_space(struct pci_pbm_info *pbm); 168extern void pci_determine_mem_io_space(struct pci_pbm_info *pbm);
diff --git a/arch/sparc64/kernel/pci_msi.c b/arch/sparc64/kernel/pci_msi.c
index d6d64b44af63..db5e8fd8f674 100644
--- a/arch/sparc64/kernel/pci_msi.c
+++ b/arch/sparc64/kernel/pci_msi.c
@@ -279,11 +279,17 @@ static int bringup_one_msi_queue(struct pci_pbm_info *pbm,
279 unsigned long devino) 279 unsigned long devino)
280{ 280{
281 int irq = ops->msiq_build_irq(pbm, msiqid, devino); 281 int irq = ops->msiq_build_irq(pbm, msiqid, devino);
282 int err; 282 int err, nid;
283 283
284 if (irq < 0) 284 if (irq < 0)
285 return irq; 285 return irq;
286 286
287 nid = pbm->numa_node;
288 if (nid != -1) {
289 cpumask_t numa_mask = node_to_cpumask(nid);
290
291 irq_set_affinity(irq, numa_mask);
292 }
287 err = request_irq(irq, sparc64_msiq_interrupt, 0, 293 err = request_irq(irq, sparc64_msiq_interrupt, 0,
288 "MSIQ", 294 "MSIQ",
289 &pbm->msiq_irq_cookies[msiqid - pbm->msiq_first]); 295 &pbm->msiq_irq_cookies[msiqid - pbm->msiq_first]);
diff --git a/arch/sparc64/kernel/pci_psycho.c b/arch/sparc64/kernel/pci_psycho.c
index 0bad96e5d184..994dbe0603da 100644
--- a/arch/sparc64/kernel/pci_psycho.c
+++ b/arch/sparc64/kernel/pci_psycho.c
@@ -848,7 +848,8 @@ static int psycho_iommu_init(struct pci_pbm_info *pbm)
848 /* Leave diag mode enabled for full-flushing done 848 /* Leave diag mode enabled for full-flushing done
849 * in pci_iommu.c 849 * in pci_iommu.c
850 */ 850 */
851 err = iommu_table_init(iommu, IO_TSB_SIZE, 0xc0000000, 0xffffffff); 851 err = iommu_table_init(iommu, IO_TSB_SIZE, 0xc0000000, 0xffffffff,
852 pbm->numa_node);
852 if (err) 853 if (err)
853 return err; 854 return err;
854 855
@@ -979,6 +980,8 @@ static void __init psycho_pbm_init(struct pci_controller_info *p,
979 pbm->next = pci_pbm_root; 980 pbm->next = pci_pbm_root;
980 pci_pbm_root = pbm; 981 pci_pbm_root = pbm;
981 982
983 pbm->numa_node = -1;
984
982 pbm->scan_bus = psycho_scan_bus; 985 pbm->scan_bus = psycho_scan_bus;
983 pbm->pci_ops = &sun4u_pci_ops; 986 pbm->pci_ops = &sun4u_pci_ops;
984 pbm->config_space_reg_bits = 8; 987 pbm->config_space_reg_bits = 8;
diff --git a/arch/sparc64/kernel/pci_sabre.c b/arch/sparc64/kernel/pci_sabre.c
index 1c5f5fa2339f..4c34195baf37 100644
--- a/arch/sparc64/kernel/pci_sabre.c
+++ b/arch/sparc64/kernel/pci_sabre.c
@@ -704,7 +704,7 @@ static int sabre_iommu_init(struct pci_pbm_info *pbm,
704 * in pci_iommu.c 704 * in pci_iommu.c
705 */ 705 */
706 err = iommu_table_init(iommu, tsbsize * 1024 * 8, 706 err = iommu_table_init(iommu, tsbsize * 1024 * 8,
707 dvma_offset, dma_mask); 707 dvma_offset, dma_mask, pbm->numa_node);
708 if (err) 708 if (err)
709 return err; 709 return err;
710 710
@@ -737,6 +737,8 @@ static void __init sabre_pbm_init(struct pci_controller_info *p,
737 pbm->name = dp->full_name; 737 pbm->name = dp->full_name;
738 printk("%s: SABRE PCI Bus Module\n", pbm->name); 738 printk("%s: SABRE PCI Bus Module\n", pbm->name);
739 739
740 pbm->numa_node = -1;
741
740 pbm->scan_bus = sabre_scan_bus; 742 pbm->scan_bus = sabre_scan_bus;
741 pbm->pci_ops = &sun4u_pci_ops; 743 pbm->pci_ops = &sun4u_pci_ops;
742 pbm->config_space_reg_bits = 8; 744 pbm->config_space_reg_bits = 8;
diff --git a/arch/sparc64/kernel/pci_schizo.c b/arch/sparc64/kernel/pci_schizo.c
index e30609362322..615edd9c8e2a 100644
--- a/arch/sparc64/kernel/pci_schizo.c
+++ b/arch/sparc64/kernel/pci_schizo.c
@@ -1220,7 +1220,8 @@ static int schizo_pbm_iommu_init(struct pci_pbm_info *pbm)
1220 /* Leave diag mode enabled for full-flushing done 1220 /* Leave diag mode enabled for full-flushing done
1221 * in pci_iommu.c 1221 * in pci_iommu.c
1222 */ 1222 */
1223 err = iommu_table_init(iommu, tsbsize * 8 * 1024, vdma[0], dma_mask); 1223 err = iommu_table_init(iommu, tsbsize * 8 * 1024, vdma[0], dma_mask,
1224 pbm->numa_node);
1224 if (err) 1225 if (err)
1225 return err; 1226 return err;
1226 1227
@@ -1379,6 +1380,8 @@ static int __init schizo_pbm_init(struct pci_controller_info *p,
1379 pbm->next = pci_pbm_root; 1380 pbm->next = pci_pbm_root;
1380 pci_pbm_root = pbm; 1381 pci_pbm_root = pbm;
1381 1382
1383 pbm->numa_node = -1;
1384
1382 pbm->scan_bus = schizo_scan_bus; 1385 pbm->scan_bus = schizo_scan_bus;
1383 pbm->pci_ops = &sun4u_pci_ops; 1386 pbm->pci_ops = &sun4u_pci_ops;
1384 pbm->config_space_reg_bits = 8; 1387 pbm->config_space_reg_bits = 8;
diff --git a/arch/sparc64/kernel/pci_sun4v.c b/arch/sparc64/kernel/pci_sun4v.c
index 01839706bd52..e2bb9790039c 100644
--- a/arch/sparc64/kernel/pci_sun4v.c
+++ b/arch/sparc64/kernel/pci_sun4v.c
@@ -127,10 +127,12 @@ static inline long iommu_batch_end(void)
127static void *dma_4v_alloc_coherent(struct device *dev, size_t size, 127static void *dma_4v_alloc_coherent(struct device *dev, size_t size,
128 dma_addr_t *dma_addrp, gfp_t gfp) 128 dma_addr_t *dma_addrp, gfp_t gfp)
129{ 129{
130 struct iommu *iommu;
131 unsigned long flags, order, first_page, npages, n; 130 unsigned long flags, order, first_page, npages, n;
131 struct iommu *iommu;
132 struct page *page;
132 void *ret; 133 void *ret;
133 long entry; 134 long entry;
135 int nid;
134 136
135 size = IO_PAGE_ALIGN(size); 137 size = IO_PAGE_ALIGN(size);
136 order = get_order(size); 138 order = get_order(size);
@@ -139,10 +141,12 @@ static void *dma_4v_alloc_coherent(struct device *dev, size_t size,
139 141
140 npages = size >> IO_PAGE_SHIFT; 142 npages = size >> IO_PAGE_SHIFT;
141 143
142 first_page = __get_free_pages(gfp, order); 144 nid = dev->archdata.numa_node;
143 if (unlikely(first_page == 0UL)) 145 page = alloc_pages_node(nid, gfp, order);
146 if (unlikely(!page))
144 return NULL; 147 return NULL;
145 148
149 first_page = (unsigned long) page_address(page);
146 memset((char *)first_page, 0, PAGE_SIZE << order); 150 memset((char *)first_page, 0, PAGE_SIZE << order);
147 151
148 iommu = dev->archdata.iommu; 152 iommu = dev->archdata.iommu;
@@ -899,6 +903,8 @@ static void __init pci_sun4v_pbm_init(struct pci_controller_info *p,
899 pbm->next = pci_pbm_root; 903 pbm->next = pci_pbm_root;
900 pci_pbm_root = pbm; 904 pci_pbm_root = pbm;
901 905
906 pbm->numa_node = of_node_to_nid(dp);
907
902 pbm->scan_bus = pci_sun4v_scan_bus; 908 pbm->scan_bus = pci_sun4v_scan_bus;
903 pbm->pci_ops = &sun4v_pci_ops; 909 pbm->pci_ops = &sun4v_pci_ops;
904 pbm->config_space_reg_bits = 12; 910 pbm->config_space_reg_bits = 12;
@@ -913,6 +919,7 @@ static void __init pci_sun4v_pbm_init(struct pci_controller_info *p,
913 pbm->name = dp->full_name; 919 pbm->name = dp->full_name;
914 920
915 printk("%s: SUN4V PCI Bus Module\n", pbm->name); 921 printk("%s: SUN4V PCI Bus Module\n", pbm->name);
922 printk("%s: On NUMA node %d\n", pbm->name, pbm->numa_node);
916 923
917 pci_determine_mem_io_space(pbm); 924 pci_determine_mem_io_space(pbm);
918 925
diff --git a/arch/sparc64/kernel/prom.c b/arch/sparc64/kernel/prom.c
index 68964ddcde1e..ed03a18d3b36 100644
--- a/arch/sparc64/kernel/prom.c
+++ b/arch/sparc64/kernel/prom.c
@@ -19,8 +19,8 @@
19#include <linux/types.h> 19#include <linux/types.h>
20#include <linux/string.h> 20#include <linux/string.h>
21#include <linux/mm.h> 21#include <linux/mm.h>
22#include <linux/bootmem.h>
23#include <linux/module.h> 22#include <linux/module.h>
23#include <linux/lmb.h>
24 24
25#include <asm/prom.h> 25#include <asm/prom.h>
26#include <asm/of_device.h> 26#include <asm/of_device.h>
@@ -122,16 +122,20 @@ int of_find_in_proplist(const char *list, const char *match, int len)
122} 122}
123EXPORT_SYMBOL(of_find_in_proplist); 123EXPORT_SYMBOL(of_find_in_proplist);
124 124
125static unsigned int prom_early_allocated; 125static unsigned int prom_early_allocated __initdata;
126 126
127static void * __init prom_early_alloc(unsigned long size) 127static void * __init prom_early_alloc(unsigned long size)
128{ 128{
129 unsigned long paddr = lmb_alloc(size, SMP_CACHE_BYTES);
129 void *ret; 130 void *ret;
130 131
131 ret = __alloc_bootmem(size, SMP_CACHE_BYTES, 0UL); 132 if (!paddr) {
132 if (ret != NULL) 133 prom_printf("prom_early_alloc(%lu) failed\n");
133 memset(ret, 0, size); 134 prom_halt();
135 }
134 136
137 ret = __va(paddr);
138 memset(ret, 0, size);
135 prom_early_allocated += size; 139 prom_early_allocated += size;
136 140
137 return ret; 141 return ret;
diff --git a/arch/sparc64/kernel/rtrap.S b/arch/sparc64/kernel/rtrap.S
index 079d18a11d24..ecf6753b204a 100644
--- a/arch/sparc64/kernel/rtrap.S
+++ b/arch/sparc64/kernel/rtrap.S
@@ -18,12 +18,6 @@
18#define RTRAP_PSTATE_IRQOFF (PSTATE_RMO|PSTATE_PEF|PSTATE_PRIV) 18#define RTRAP_PSTATE_IRQOFF (PSTATE_RMO|PSTATE_PEF|PSTATE_PRIV)
19#define RTRAP_PSTATE_AG_IRQOFF (PSTATE_RMO|PSTATE_PEF|PSTATE_PRIV|PSTATE_AG) 19#define RTRAP_PSTATE_AG_IRQOFF (PSTATE_RMO|PSTATE_PEF|PSTATE_PRIV|PSTATE_AG)
20 20
21 /* Register %l6 keeps track of whether we are returning
22 * from a system call or not. It is cleared if we call
23 * do_notify_resume, and it must not be otherwise modified
24 * until we fully commit to returning to userspace.
25 */
26
27 .text 21 .text
28 .align 32 22 .align 32
29__handle_softirq: 23__handle_softirq:
@@ -56,14 +50,12 @@ __handle_user_windows:
56 be,pt %xcc, __handle_user_windows_continue 50 be,pt %xcc, __handle_user_windows_continue
57 nop 51 nop
58 mov %l5, %o1 52 mov %l5, %o1
59 mov %l6, %o2
60 add %sp, PTREGS_OFF, %o0 53 add %sp, PTREGS_OFF, %o0
61 mov %l0, %o3 54 mov %l0, %o2
62 55
63 call do_notify_resume 56 call do_notify_resume
64 wrpr %g0, RTRAP_PSTATE, %pstate 57 wrpr %g0, RTRAP_PSTATE, %pstate
65 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate 58 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
66 clr %l6
67 /* Signal delivery can modify pt_regs tstate, so we must 59 /* Signal delivery can modify pt_regs tstate, so we must
68 * reload it. 60 * reload it.
69 */ 61 */
@@ -99,14 +91,12 @@ __handle_perfctrs:
99 be,pt %xcc, __handle_perfctrs_continue 91 be,pt %xcc, __handle_perfctrs_continue
100 sethi %hi(TSTATE_PEF), %o0 92 sethi %hi(TSTATE_PEF), %o0
101 mov %l5, %o1 93 mov %l5, %o1
102 mov %l6, %o2
103 add %sp, PTREGS_OFF, %o0 94 add %sp, PTREGS_OFF, %o0
104 mov %l0, %o3 95 mov %l0, %o2
105 call do_notify_resume 96 call do_notify_resume
106 97
107 wrpr %g0, RTRAP_PSTATE, %pstate 98 wrpr %g0, RTRAP_PSTATE, %pstate
108 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate 99 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
109 clr %l6
110 /* Signal delivery can modify pt_regs tstate, so we must 100 /* Signal delivery can modify pt_regs tstate, so we must
111 * reload it. 101 * reload it.
112 */ 102 */
@@ -127,13 +117,11 @@ __handle_userfpu:
127 117
128__handle_signal: 118__handle_signal:
129 mov %l5, %o1 119 mov %l5, %o1
130 mov %l6, %o2
131 add %sp, PTREGS_OFF, %o0 120 add %sp, PTREGS_OFF, %o0
132 mov %l0, %o3 121 mov %l0, %o2
133 call do_notify_resume 122 call do_notify_resume
134 wrpr %g0, RTRAP_PSTATE, %pstate 123 wrpr %g0, RTRAP_PSTATE, %pstate
135 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate 124 wrpr %g0, RTRAP_PSTATE_IRQOFF, %pstate
136 clr %l6
137 125
138 /* Signal delivery can modify pt_regs tstate, so we must 126 /* Signal delivery can modify pt_regs tstate, so we must
139 * reload it. 127 * reload it.
@@ -145,9 +133,8 @@ __handle_signal:
145 andn %l1, %l4, %l1 133 andn %l1, %l4, %l1
146 134
147 .align 64 135 .align 64
148 .globl rtrap_irq, rtrap_clr_l6, rtrap, irqsz_patchme, rtrap_xcall 136 .globl rtrap_irq, rtrap, irqsz_patchme, rtrap_xcall
149rtrap_irq: 137rtrap_irq:
150rtrap_clr_l6: clr %l6
151rtrap: 138rtrap:
152#ifndef CONFIG_SMP 139#ifndef CONFIG_SMP
153 sethi %hi(per_cpu____cpu_data), %l0 140 sethi %hi(per_cpu____cpu_data), %l0
diff --git a/arch/sparc64/kernel/sbus.c b/arch/sparc64/kernel/sbus.c
index d1fb13ba02b5..fa2827c4a3ad 100644
--- a/arch/sparc64/kernel/sbus.c
+++ b/arch/sparc64/kernel/sbus.c
@@ -544,6 +544,7 @@ static void __init sbus_iommu_init(int __node, struct sbus_bus *sbus)
544 544
545 sbus->ofdev.dev.archdata.iommu = iommu; 545 sbus->ofdev.dev.archdata.iommu = iommu;
546 sbus->ofdev.dev.archdata.stc = strbuf; 546 sbus->ofdev.dev.archdata.stc = strbuf;
547 sbus->ofdev.dev.archdata.numa_node = -1;
547 548
548 reg_base = regs + SYSIO_IOMMUREG_BASE; 549 reg_base = regs + SYSIO_IOMMUREG_BASE;
549 iommu->iommu_control = reg_base + IOMMU_CONTROL; 550 iommu->iommu_control = reg_base + IOMMU_CONTROL;
@@ -575,7 +576,7 @@ static void __init sbus_iommu_init(int __node, struct sbus_bus *sbus)
575 sbus->portid, regs); 576 sbus->portid, regs);
576 577
577 /* Setup for TSB_SIZE=7, TBW_SIZE=0, MMU_DE=1, MMU_EN=1 */ 578 /* Setup for TSB_SIZE=7, TBW_SIZE=0, MMU_DE=1, MMU_EN=1 */
578 if (iommu_table_init(iommu, IO_TSB_SIZE, MAP_BASE, 0xffffffff)) 579 if (iommu_table_init(iommu, IO_TSB_SIZE, MAP_BASE, 0xffffffff, -1))
579 goto fatal_memory_error; 580 goto fatal_memory_error;
580 581
581 control = upa_readq(iommu->iommu_control); 582 control = upa_readq(iommu->iommu_control);
diff --git a/arch/sparc64/kernel/setup.c b/arch/sparc64/kernel/setup.c
index 6acb4c51cfe4..da5e6ee0c661 100644
--- a/arch/sparc64/kernel/setup.c
+++ b/arch/sparc64/kernel/setup.c
@@ -82,7 +82,7 @@ unsigned long cmdline_memory_size = 0;
82static struct console prom_early_console = { 82static struct console prom_early_console = {
83 .name = "earlyprom", 83 .name = "earlyprom",
84 .write = prom_console_write, 84 .write = prom_console_write,
85 .flags = CON_PRINTBUFFER | CON_BOOT, 85 .flags = CON_PRINTBUFFER | CON_BOOT | CON_ANYTIME,
86 .index = -1, 86 .index = -1,
87}; 87};
88 88
@@ -281,6 +281,7 @@ void __init setup_arch(char **cmdline_p)
281 /* Initialize PROM console and command line. */ 281 /* Initialize PROM console and command line. */
282 *cmdline_p = prom_getbootargs(); 282 *cmdline_p = prom_getbootargs();
283 strcpy(boot_command_line, *cmdline_p); 283 strcpy(boot_command_line, *cmdline_p);
284 parse_early_param();
284 285
285 boot_flags_init(*cmdline_p); 286 boot_flags_init(*cmdline_p);
286 register_console(&prom_early_console); 287 register_console(&prom_early_console);
diff --git a/arch/sparc64/kernel/signal.c b/arch/sparc64/kernel/signal.c
index 1c47009eb5ec..77a3e8592cbc 100644
--- a/arch/sparc64/kernel/signal.c
+++ b/arch/sparc64/kernel/signal.c
@@ -510,15 +510,20 @@ static inline void syscall_restart(unsigned long orig_i0, struct pt_regs *regs,
510 * want to handle. Thus you cannot kill init even with a SIGKILL even by 510 * want to handle. Thus you cannot kill init even with a SIGKILL even by
511 * mistake. 511 * mistake.
512 */ 512 */
513static void do_signal(struct pt_regs *regs, unsigned long orig_i0, int restart_syscall) 513static void do_signal(struct pt_regs *regs, unsigned long orig_i0)
514{ 514{
515 siginfo_t info;
516 struct signal_deliver_cookie cookie; 515 struct signal_deliver_cookie cookie;
517 struct k_sigaction ka; 516 struct k_sigaction ka;
518 int signr;
519 sigset_t *oldset; 517 sigset_t *oldset;
518 siginfo_t info;
519 int signr, tt;
520 520
521 cookie.restart_syscall = restart_syscall; 521 tt = regs->magic & 0x1ff;
522 if (tt == 0x110 || tt == 0x111 || tt == 0x16d) {
523 regs->magic &= ~0x1ff;
524 cookie.restart_syscall = 1;
525 } else
526 cookie.restart_syscall = 0;
522 cookie.orig_i0 = orig_i0; 527 cookie.orig_i0 = orig_i0;
523 528
524 if (test_thread_flag(TIF_RESTORE_SIGMASK)) 529 if (test_thread_flag(TIF_RESTORE_SIGMASK))
@@ -529,9 +534,8 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0, int restart_s
529#ifdef CONFIG_SPARC32_COMPAT 534#ifdef CONFIG_SPARC32_COMPAT
530 if (test_thread_flag(TIF_32BIT)) { 535 if (test_thread_flag(TIF_32BIT)) {
531 extern void do_signal32(sigset_t *, struct pt_regs *, 536 extern void do_signal32(sigset_t *, struct pt_regs *,
532 unsigned long, int); 537 struct signal_deliver_cookie *);
533 do_signal32(oldset, regs, orig_i0, 538 do_signal32(oldset, regs, &cookie);
534 cookie.restart_syscall);
535 return; 539 return;
536 } 540 }
537#endif 541#endif
@@ -539,7 +543,7 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0, int restart_s
539 signr = get_signal_to_deliver(&info, &ka, regs, &cookie); 543 signr = get_signal_to_deliver(&info, &ka, regs, &cookie);
540 if (signr > 0) { 544 if (signr > 0) {
541 if (cookie.restart_syscall) 545 if (cookie.restart_syscall)
542 syscall_restart(orig_i0, regs, &ka.sa); 546 syscall_restart(cookie.orig_i0, regs, &ka.sa);
543 handle_signal(signr, &ka, &info, oldset, regs); 547 handle_signal(signr, &ka, &info, oldset, regs);
544 548
545 /* a signal was successfully delivered; the saved 549 /* a signal was successfully delivered; the saved
@@ -576,11 +580,10 @@ static void do_signal(struct pt_regs *regs, unsigned long orig_i0, int restart_s
576 } 580 }
577} 581}
578 582
579void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, int restart_syscall, 583void do_notify_resume(struct pt_regs *regs, unsigned long orig_i0, unsigned long thread_info_flags)
580 unsigned long thread_info_flags)
581{ 584{
582 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)) 585 if (thread_info_flags & (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK))
583 do_signal(regs, orig_i0, restart_syscall); 586 do_signal(regs, orig_i0);
584} 587}
585 588
586void ptrace_signal_deliver(struct pt_regs *regs, void *cookie) 589void ptrace_signal_deliver(struct pt_regs *regs, void *cookie)
diff --git a/arch/sparc64/kernel/signal32.c b/arch/sparc64/kernel/signal32.c
index 74e0512f135c..43cdec64d9c9 100644
--- a/arch/sparc64/kernel/signal32.c
+++ b/arch/sparc64/kernel/signal32.c
@@ -982,20 +982,16 @@ static inline void syscall_restart32(unsigned long orig_i0, struct pt_regs *regs
982 * mistake. 982 * mistake.
983 */ 983 */
984void do_signal32(sigset_t *oldset, struct pt_regs * regs, 984void do_signal32(sigset_t *oldset, struct pt_regs * regs,
985 unsigned long orig_i0, int restart_syscall) 985 struct signal_deliver_cookie *cookie)
986{ 986{
987 siginfo_t info;
988 struct signal_deliver_cookie cookie;
989 struct k_sigaction ka; 987 struct k_sigaction ka;
988 siginfo_t info;
990 int signr; 989 int signr;
991 990
992 cookie.restart_syscall = restart_syscall; 991 signr = get_signal_to_deliver(&info, &ka, regs, cookie);
993 cookie.orig_i0 = orig_i0;
994
995 signr = get_signal_to_deliver(&info, &ka, regs, &cookie);
996 if (signr > 0) { 992 if (signr > 0) {
997 if (cookie.restart_syscall) 993 if (cookie->restart_syscall)
998 syscall_restart32(orig_i0, regs, &ka.sa); 994 syscall_restart32(cookie->orig_i0, regs, &ka.sa);
999 handle_signal32(signr, &ka, &info, oldset, regs); 995 handle_signal32(signr, &ka, &info, oldset, regs);
1000 996
1001 /* a signal was successfully delivered; the saved 997 /* a signal was successfully delivered; the saved
@@ -1007,16 +1003,16 @@ void do_signal32(sigset_t *oldset, struct pt_regs * regs,
1007 clear_thread_flag(TIF_RESTORE_SIGMASK); 1003 clear_thread_flag(TIF_RESTORE_SIGMASK);
1008 return; 1004 return;
1009 } 1005 }
1010 if (cookie.restart_syscall && 1006 if (cookie->restart_syscall &&
1011 (regs->u_regs[UREG_I0] == ERESTARTNOHAND || 1007 (regs->u_regs[UREG_I0] == ERESTARTNOHAND ||
1012 regs->u_regs[UREG_I0] == ERESTARTSYS || 1008 regs->u_regs[UREG_I0] == ERESTARTSYS ||
1013 regs->u_regs[UREG_I0] == ERESTARTNOINTR)) { 1009 regs->u_regs[UREG_I0] == ERESTARTNOINTR)) {
1014 /* replay the system call when we are done */ 1010 /* replay the system call when we are done */
1015 regs->u_regs[UREG_I0] = cookie.orig_i0; 1011 regs->u_regs[UREG_I0] = cookie->orig_i0;
1016 regs->tpc -= 4; 1012 regs->tpc -= 4;
1017 regs->tnpc -= 4; 1013 regs->tnpc -= 4;
1018 } 1014 }
1019 if (cookie.restart_syscall && 1015 if (cookie->restart_syscall &&
1020 regs->u_regs[UREG_I0] == ERESTART_RESTARTBLOCK) { 1016 regs->u_regs[UREG_I0] == ERESTART_RESTARTBLOCK) {
1021 regs->u_regs[UREG_G1] = __NR_restart_syscall; 1017 regs->u_regs[UREG_G1] = __NR_restart_syscall;
1022 regs->tpc -= 4; 1018 regs->tpc -= 4;
diff --git a/arch/sparc64/kernel/smp.c b/arch/sparc64/kernel/smp.c
index 59f020d69d4c..524b88920947 100644
--- a/arch/sparc64/kernel/smp.c
+++ b/arch/sparc64/kernel/smp.c
@@ -20,7 +20,7 @@
20#include <linux/cache.h> 20#include <linux/cache.h>
21#include <linux/jiffies.h> 21#include <linux/jiffies.h>
22#include <linux/profile.h> 22#include <linux/profile.h>
23#include <linux/bootmem.h> 23#include <linux/lmb.h>
24 24
25#include <asm/head.h> 25#include <asm/head.h>
26#include <asm/ptrace.h> 26#include <asm/ptrace.h>
@@ -1431,7 +1431,7 @@ EXPORT_SYMBOL(__per_cpu_shift);
1431 1431
1432void __init real_setup_per_cpu_areas(void) 1432void __init real_setup_per_cpu_areas(void)
1433{ 1433{
1434 unsigned long goal, size, i; 1434 unsigned long paddr, goal, size, i;
1435 char *ptr; 1435 char *ptr;
1436 1436
1437 /* Copy section for each CPU (we discard the original) */ 1437 /* Copy section for each CPU (we discard the original) */
@@ -1441,8 +1441,13 @@ void __init real_setup_per_cpu_areas(void)
1441 for (size = PAGE_SIZE; size < goal; size <<= 1UL) 1441 for (size = PAGE_SIZE; size < goal; size <<= 1UL)
1442 __per_cpu_shift++; 1442 __per_cpu_shift++;
1443 1443
1444 ptr = alloc_bootmem_pages(size * NR_CPUS); 1444 paddr = lmb_alloc(size * NR_CPUS, PAGE_SIZE);
1445 if (!paddr) {
1446 prom_printf("Cannot allocate per-cpu memory.\n");
1447 prom_halt();
1448 }
1445 1449
1450 ptr = __va(paddr);
1446 __per_cpu_base = ptr - __per_cpu_start; 1451 __per_cpu_base = ptr - __per_cpu_start;
1447 1452
1448 for (i = 0; i < NR_CPUS; i++, ptr += size) 1453 for (i = 0; i < NR_CPUS; i++, ptr += size)
diff --git a/arch/sparc64/kernel/sparc64_ksyms.c b/arch/sparc64/kernel/sparc64_ksyms.c
index 38736460b8db..66336590e830 100644
--- a/arch/sparc64/kernel/sparc64_ksyms.c
+++ b/arch/sparc64/kernel/sparc64_ksyms.c
@@ -68,8 +68,6 @@ extern void *__memscan_zero(void *, size_t);
68extern void *__memscan_generic(void *, int, size_t); 68extern void *__memscan_generic(void *, int, size_t);
69extern int __memcmp(const void *, const void *, __kernel_size_t); 69extern int __memcmp(const void *, const void *, __kernel_size_t);
70extern __kernel_size_t strlen(const char *); 70extern __kernel_size_t strlen(const char *);
71extern void linux_sparc_syscall(void);
72extern void rtrap(void);
73extern void show_regs(struct pt_regs *); 71extern void show_regs(struct pt_regs *);
74extern void syscall_trace(struct pt_regs *, int); 72extern void syscall_trace(struct pt_regs *, int);
75extern void sys_sigsuspend(void); 73extern void sys_sigsuspend(void);
diff --git a/arch/sparc64/kernel/stacktrace.c b/arch/sparc64/kernel/stacktrace.c
index 84d39e873e88..01b52f561af4 100644
--- a/arch/sparc64/kernel/stacktrace.c
+++ b/arch/sparc64/kernel/stacktrace.c
@@ -20,6 +20,8 @@ void save_stack_trace(struct stack_trace *trace)
20 thread_base = (unsigned long) tp; 20 thread_base = (unsigned long) tp;
21 do { 21 do {
22 struct reg_window *rw; 22 struct reg_window *rw;
23 struct pt_regs *regs;
24 unsigned long pc;
23 25
24 /* Bogus frame pointer? */ 26 /* Bogus frame pointer? */
25 if (fp < (thread_base + sizeof(struct thread_info)) || 27 if (fp < (thread_base + sizeof(struct thread_info)) ||
@@ -27,11 +29,19 @@ void save_stack_trace(struct stack_trace *trace)
27 break; 29 break;
28 30
29 rw = (struct reg_window *) fp; 31 rw = (struct reg_window *) fp;
32 regs = (struct pt_regs *) (rw + 1);
33
34 if ((regs->magic & ~0x1ff) == PT_REGS_MAGIC) {
35 pc = regs->tpc;
36 fp = regs->u_regs[UREG_I6] + STACK_BIAS;
37 } else {
38 pc = rw->ins[7];
39 fp = rw->ins[6] + STACK_BIAS;
40 }
41
30 if (trace->skip > 0) 42 if (trace->skip > 0)
31 trace->skip--; 43 trace->skip--;
32 else 44 else
33 trace->entries[trace->nr_entries++] = rw->ins[7]; 45 trace->entries[trace->nr_entries++] = pc;
34
35 fp = rw->ins[6] + STACK_BIAS;
36 } while (trace->nr_entries < trace->max_entries); 46 } while (trace->nr_entries < trace->max_entries);
37} 47}
diff --git a/arch/sparc64/kernel/sun4v_tlb_miss.S b/arch/sparc64/kernel/sun4v_tlb_miss.S
index fd9430562e0b..e1fbf8c75787 100644
--- a/arch/sparc64/kernel/sun4v_tlb_miss.S
+++ b/arch/sparc64/kernel/sun4v_tlb_miss.S
@@ -262,7 +262,7 @@ sun4v_iacc:
262 mov %l5, %o2 262 mov %l5, %o2
263 call sun4v_insn_access_exception 263 call sun4v_insn_access_exception
264 add %sp, PTREGS_OFF, %o0 264 add %sp, PTREGS_OFF, %o0
265 ba,a,pt %xcc, rtrap_clr_l6 265 ba,a,pt %xcc, rtrap
266 266
267 /* Instruction Access Exception, tl1. */ 267 /* Instruction Access Exception, tl1. */
268sun4v_iacc_tl1: 268sun4v_iacc_tl1:
@@ -278,7 +278,7 @@ sun4v_iacc_tl1:
278 mov %l5, %o2 278 mov %l5, %o2
279 call sun4v_insn_access_exception_tl1 279 call sun4v_insn_access_exception_tl1
280 add %sp, PTREGS_OFF, %o0 280 add %sp, PTREGS_OFF, %o0
281 ba,a,pt %xcc, rtrap_clr_l6 281 ba,a,pt %xcc, rtrap
282 282
283 /* Data Access Exception, tl0. */ 283 /* Data Access Exception, tl0. */
284sun4v_dacc: 284sun4v_dacc:
@@ -294,7 +294,7 @@ sun4v_dacc:
294 mov %l5, %o2 294 mov %l5, %o2
295 call sun4v_data_access_exception 295 call sun4v_data_access_exception
296 add %sp, PTREGS_OFF, %o0 296 add %sp, PTREGS_OFF, %o0
297 ba,a,pt %xcc, rtrap_clr_l6 297 ba,a,pt %xcc, rtrap
298 298
299 /* Data Access Exception, tl1. */ 299 /* Data Access Exception, tl1. */
300sun4v_dacc_tl1: 300sun4v_dacc_tl1:
@@ -310,7 +310,7 @@ sun4v_dacc_tl1:
310 mov %l5, %o2 310 mov %l5, %o2
311 call sun4v_data_access_exception_tl1 311 call sun4v_data_access_exception_tl1
312 add %sp, PTREGS_OFF, %o0 312 add %sp, PTREGS_OFF, %o0
313 ba,a,pt %xcc, rtrap_clr_l6 313 ba,a,pt %xcc, rtrap
314 314
315 /* Memory Address Unaligned. */ 315 /* Memory Address Unaligned. */
316sun4v_mna: 316sun4v_mna:
@@ -344,7 +344,7 @@ sun4v_mna:
344 mov %l5, %o2 344 mov %l5, %o2
345 call sun4v_do_mna 345 call sun4v_do_mna
346 add %sp, PTREGS_OFF, %o0 346 add %sp, PTREGS_OFF, %o0
347 ba,a,pt %xcc, rtrap_clr_l6 347 ba,a,pt %xcc, rtrap
348 348
349 /* Privileged Action. */ 349 /* Privileged Action. */
350sun4v_privact: 350sun4v_privact:
@@ -352,7 +352,7 @@ sun4v_privact:
352 rd %pc, %g7 352 rd %pc, %g7
353 call do_privact 353 call do_privact
354 add %sp, PTREGS_OFF, %o0 354 add %sp, PTREGS_OFF, %o0
355 ba,a,pt %xcc, rtrap_clr_l6 355 ba,a,pt %xcc, rtrap
356 356
357 /* Unaligned ldd float, tl0. */ 357 /* Unaligned ldd float, tl0. */
358sun4v_lddfmna: 358sun4v_lddfmna:
@@ -368,7 +368,7 @@ sun4v_lddfmna:
368 mov %l5, %o2 368 mov %l5, %o2
369 call handle_lddfmna 369 call handle_lddfmna
370 add %sp, PTREGS_OFF, %o0 370 add %sp, PTREGS_OFF, %o0
371 ba,a,pt %xcc, rtrap_clr_l6 371 ba,a,pt %xcc, rtrap
372 372
373 /* Unaligned std float, tl0. */ 373 /* Unaligned std float, tl0. */
374sun4v_stdfmna: 374sun4v_stdfmna:
@@ -384,7 +384,7 @@ sun4v_stdfmna:
384 mov %l5, %o2 384 mov %l5, %o2
385 call handle_stdfmna 385 call handle_stdfmna
386 add %sp, PTREGS_OFF, %o0 386 add %sp, PTREGS_OFF, %o0
387 ba,a,pt %xcc, rtrap_clr_l6 387 ba,a,pt %xcc, rtrap
388 388
389#define BRANCH_ALWAYS 0x10680000 389#define BRANCH_ALWAYS 0x10680000
390#define NOP 0x01000000 390#define NOP 0x01000000
diff --git a/arch/sparc64/kernel/sysfs.c b/arch/sparc64/kernel/sysfs.c
index 52816c7be0b9..e885034a6b73 100644
--- a/arch/sparc64/kernel/sysfs.c
+++ b/arch/sparc64/kernel/sysfs.c
@@ -273,10 +273,22 @@ static void __init check_mmu_stats(void)
273 mmu_stats_supported = 1; 273 mmu_stats_supported = 1;
274} 274}
275 275
276static void register_nodes(void)
277{
278#ifdef CONFIG_NUMA
279 int i;
280
281 for (i = 0; i < MAX_NUMNODES; i++)
282 register_one_node(i);
283#endif
284}
285
276static int __init topology_init(void) 286static int __init topology_init(void)
277{ 287{
278 int cpu; 288 int cpu;
279 289
290 register_nodes();
291
280 check_mmu_stats(); 292 check_mmu_stats();
281 293
282 register_cpu_notifier(&sysfs_cpu_nb); 294 register_cpu_notifier(&sysfs_cpu_nb);
diff --git a/arch/sparc64/kernel/traps.c b/arch/sparc64/kernel/traps.c
index 96da847023f3..d9b8d46707d1 100644
--- a/arch/sparc64/kernel/traps.c
+++ b/arch/sparc64/kernel/traps.c
@@ -2091,9 +2091,8 @@ static void user_instruction_dump(unsigned int __user *pc)
2091 2091
2092void show_stack(struct task_struct *tsk, unsigned long *_ksp) 2092void show_stack(struct task_struct *tsk, unsigned long *_ksp)
2093{ 2093{
2094 unsigned long pc, fp, thread_base, ksp; 2094 unsigned long fp, thread_base, ksp;
2095 struct thread_info *tp; 2095 struct thread_info *tp;
2096 struct reg_window *rw;
2097 int count = 0; 2096 int count = 0;
2098 2097
2099 ksp = (unsigned long) _ksp; 2098 ksp = (unsigned long) _ksp;
@@ -2117,15 +2116,27 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
2117 printk("\n"); 2116 printk("\n");
2118#endif 2117#endif
2119 do { 2118 do {
2119 struct reg_window *rw;
2120 struct pt_regs *regs;
2121 unsigned long pc;
2122
2120 /* Bogus frame pointer? */ 2123 /* Bogus frame pointer? */
2121 if (fp < (thread_base + sizeof(struct thread_info)) || 2124 if (fp < (thread_base + sizeof(struct thread_info)) ||
2122 fp >= (thread_base + THREAD_SIZE)) 2125 fp >= (thread_base + THREAD_SIZE))
2123 break; 2126 break;
2124 rw = (struct reg_window *)fp; 2127 rw = (struct reg_window *)fp;
2125 pc = rw->ins[7]; 2128 regs = (struct pt_regs *) (rw + 1);
2129
2130 if ((regs->magic & ~0x1ff) == PT_REGS_MAGIC) {
2131 pc = regs->tpc;
2132 fp = regs->u_regs[UREG_I6] + STACK_BIAS;
2133 } else {
2134 pc = rw->ins[7];
2135 fp = rw->ins[6] + STACK_BIAS;
2136 }
2137
2126 printk(" [%016lx] ", pc); 2138 printk(" [%016lx] ", pc);
2127 print_symbol("%s\n", pc); 2139 print_symbol("%s\n", pc);
2128 fp = rw->ins[6] + STACK_BIAS;
2129 } while (++count < 16); 2140 } while (++count < 16);
2130#ifndef CONFIG_KALLSYMS 2141#ifndef CONFIG_KALLSYMS
2131 printk("\n"); 2142 printk("\n");
diff --git a/arch/sparc64/kernel/tsb.S b/arch/sparc64/kernel/tsb.S
index 10adb2fb8ffe..c499214b501d 100644
--- a/arch/sparc64/kernel/tsb.S
+++ b/arch/sparc64/kernel/tsb.S
@@ -275,7 +275,7 @@ sparc64_realfault_common:
275 stx %l5, [%g6 + TI_FAULT_ADDR] ! Save fault address 275 stx %l5, [%g6 + TI_FAULT_ADDR] ! Save fault address
276 call do_sparc64_fault ! Call fault handler 276 call do_sparc64_fault ! Call fault handler
277 add %sp, PTREGS_OFF, %o0 ! Compute pt_regs arg 277 add %sp, PTREGS_OFF, %o0 ! Compute pt_regs arg
278 ba,pt %xcc, rtrap_clr_l6 ! Restore cpu state 278 ba,pt %xcc, rtrap ! Restore cpu state
279 nop ! Delay slot (fill me) 279 nop ! Delay slot (fill me)
280 280
281winfix_trampoline: 281winfix_trampoline:
diff --git a/arch/sparc64/kernel/winfixup.S b/arch/sparc64/kernel/winfixup.S
index c4aa110a10e5..a6b0863c27df 100644
--- a/arch/sparc64/kernel/winfixup.S
+++ b/arch/sparc64/kernel/winfixup.S
@@ -32,7 +32,7 @@ fill_fixup:
32 rd %pc, %g7 32 rd %pc, %g7
33 call do_sparc64_fault 33 call do_sparc64_fault
34 add %sp, PTREGS_OFF, %o0 34 add %sp, PTREGS_OFF, %o0
35 ba,pt %xcc, rtrap_clr_l6 35 ba,pt %xcc, rtrap
36 nop 36 nop
37 37
38 /* Be very careful about usage of the trap globals here. 38 /* Be very careful about usage of the trap globals here.
@@ -100,7 +100,7 @@ spill_fixup_dax:
100 rd %pc, %g7 100 rd %pc, %g7
101 call do_sparc64_fault 101 call do_sparc64_fault
102 add %sp, PTREGS_OFF, %o0 102 add %sp, PTREGS_OFF, %o0
103 ba,a,pt %xcc, rtrap_clr_l6 103 ba,a,pt %xcc, rtrap
104 104
105winfix_mna: 105winfix_mna:
106 andn %g3, 0x7f, %g3 106 andn %g3, 0x7f, %g3
@@ -122,12 +122,12 @@ fill_fixup_mna:
122 mov %l4, %o2 122 mov %l4, %o2
123 call sun4v_do_mna 123 call sun4v_do_mna
124 mov %l5, %o1 124 mov %l5, %o1
125 ba,a,pt %xcc, rtrap_clr_l6 125 ba,a,pt %xcc, rtrap
1261: mov %l4, %o1 1261: mov %l4, %o1
127 mov %l5, %o2 127 mov %l5, %o2
128 call mem_address_unaligned 128 call mem_address_unaligned
129 nop 129 nop
130 ba,a,pt %xcc, rtrap_clr_l6 130 ba,a,pt %xcc, rtrap
131 131
132winfix_dax: 132winfix_dax:
133 andn %g3, 0x7f, %g3 133 andn %g3, 0x7f, %g3
@@ -150,7 +150,7 @@ fill_fixup_dax:
150 add %sp, PTREGS_OFF, %o0 150 add %sp, PTREGS_OFF, %o0
151 call sun4v_data_access_exception 151 call sun4v_data_access_exception
152 nop 152 nop
153 ba,a,pt %xcc, rtrap_clr_l6 153 ba,a,pt %xcc, rtrap
1541: call spitfire_data_access_exception 1541: call spitfire_data_access_exception
155 nop 155 nop
156 ba,a,pt %xcc, rtrap_clr_l6 156 ba,a,pt %xcc, rtrap
diff --git a/arch/sparc64/mm/init.c b/arch/sparc64/mm/init.c
index f37078d96407..177d8aaeec42 100644
--- a/arch/sparc64/mm/init.c
+++ b/arch/sparc64/mm/init.c
@@ -24,6 +24,8 @@
24#include <linux/cache.h> 24#include <linux/cache.h>
25#include <linux/sort.h> 25#include <linux/sort.h>
26#include <linux/percpu.h> 26#include <linux/percpu.h>
27#include <linux/lmb.h>
28#include <linux/mmzone.h>
27 29
28#include <asm/head.h> 30#include <asm/head.h>
29#include <asm/system.h> 31#include <asm/system.h>
@@ -72,9 +74,7 @@ extern struct tsb swapper_4m_tsb[KERNEL_TSB4M_NENTRIES];
72#define MAX_BANKS 32 74#define MAX_BANKS 32
73 75
74static struct linux_prom64_registers pavail[MAX_BANKS] __initdata; 76static struct linux_prom64_registers pavail[MAX_BANKS] __initdata;
75static struct linux_prom64_registers pavail_rescan[MAX_BANKS] __initdata;
76static int pavail_ents __initdata; 77static int pavail_ents __initdata;
77static int pavail_rescan_ents __initdata;
78 78
79static int cmp_p64(const void *a, const void *b) 79static int cmp_p64(const void *a, const void *b)
80{ 80{
@@ -715,285 +715,684 @@ out:
715 smp_new_mmu_context_version(); 715 smp_new_mmu_context_version();
716} 716}
717 717
718/* Find a free area for the bootmem map, avoiding the kernel image 718static int numa_enabled = 1;
719 * and the initial ramdisk. 719static int numa_debug;
720 */ 720
721static unsigned long __init choose_bootmap_pfn(unsigned long start_pfn, 721static int __init early_numa(char *p)
722 unsigned long end_pfn)
723{ 722{
724 unsigned long avoid_start, avoid_end, bootmap_size; 723 if (!p)
725 int i; 724 return 0;
725
726 if (strstr(p, "off"))
727 numa_enabled = 0;
728
729 if (strstr(p, "debug"))
730 numa_debug = 1;
731
732 return 0;
733}
734early_param("numa", early_numa);
726 735
727 bootmap_size = bootmem_bootmap_pages(end_pfn - start_pfn); 736#define numadbg(f, a...) \
728 bootmap_size <<= PAGE_SHIFT; 737do { if (numa_debug) \
738 printk(KERN_INFO f, ## a); \
739} while (0)
729 740
730 avoid_start = avoid_end = 0; 741static void __init find_ramdisk(unsigned long phys_base)
742{
731#ifdef CONFIG_BLK_DEV_INITRD 743#ifdef CONFIG_BLK_DEV_INITRD
732 avoid_start = initrd_start; 744 if (sparc_ramdisk_image || sparc_ramdisk_image64) {
733 avoid_end = PAGE_ALIGN(initrd_end); 745 unsigned long ramdisk_image;
746
747 /* Older versions of the bootloader only supported a
748 * 32-bit physical address for the ramdisk image
749 * location, stored at sparc_ramdisk_image. Newer
750 * SILO versions set sparc_ramdisk_image to zero and
751 * provide a full 64-bit physical address at
752 * sparc_ramdisk_image64.
753 */
754 ramdisk_image = sparc_ramdisk_image;
755 if (!ramdisk_image)
756 ramdisk_image = sparc_ramdisk_image64;
757
758 /* Another bootloader quirk. The bootloader normalizes
759 * the physical address to KERNBASE, so we have to
760 * factor that back out and add in the lowest valid
761 * physical page address to get the true physical address.
762 */
763 ramdisk_image -= KERNBASE;
764 ramdisk_image += phys_base;
765
766 numadbg("Found ramdisk at physical address 0x%lx, size %u\n",
767 ramdisk_image, sparc_ramdisk_size);
768
769 initrd_start = ramdisk_image;
770 initrd_end = ramdisk_image + sparc_ramdisk_size;
771
772 lmb_reserve(initrd_start, initrd_end);
773 }
734#endif 774#endif
775}
735 776
736 for (i = 0; i < pavail_ents; i++) { 777struct node_mem_mask {
737 unsigned long start, end; 778 unsigned long mask;
779 unsigned long val;
780 unsigned long bootmem_paddr;
781};
782static struct node_mem_mask node_masks[MAX_NUMNODES];
783static int num_node_masks;
738 784
739 start = pavail[i].phys_addr; 785int numa_cpu_lookup_table[NR_CPUS];
740 end = start + pavail[i].reg_size; 786cpumask_t numa_cpumask_lookup_table[MAX_NUMNODES];
741 787
742 while (start < end) { 788#ifdef CONFIG_NEED_MULTIPLE_NODES
743 if (start >= kern_base && 789static bootmem_data_t plat_node_bdata[MAX_NUMNODES];
744 start < PAGE_ALIGN(kern_base + kern_size)) {
745 start = PAGE_ALIGN(kern_base + kern_size);
746 continue;
747 }
748 if (start >= avoid_start && start < avoid_end) {
749 start = avoid_end;
750 continue;
751 }
752 790
753 if ((end - start) < bootmap_size) 791struct mdesc_mblock {
754 break; 792 u64 base;
793 u64 size;
794 u64 offset; /* RA-to-PA */
795};
796static struct mdesc_mblock *mblocks;
797static int num_mblocks;
755 798
756 if (start < kern_base && 799static unsigned long ra_to_pa(unsigned long addr)
757 (start + bootmap_size) > kern_base) { 800{
758 start = PAGE_ALIGN(kern_base + kern_size); 801 int i;
759 continue;
760 }
761 802
762 if (start < avoid_start && 803 for (i = 0; i < num_mblocks; i++) {
763 (start + bootmap_size) > avoid_start) { 804 struct mdesc_mblock *m = &mblocks[i];
764 start = avoid_end;
765 continue;
766 }
767 805
768 /* OK, it doesn't overlap anything, use it. */ 806 if (addr >= m->base &&
769 return start >> PAGE_SHIFT; 807 addr < (m->base + m->size)) {
808 addr += m->offset;
809 break;
770 } 810 }
771 } 811 }
772 812 return addr;
773 prom_printf("Cannot find free area for bootmap, aborting.\n");
774 prom_halt();
775} 813}
776 814
777static void __init trim_pavail(unsigned long *cur_size_p, 815static int find_node(unsigned long addr)
778 unsigned long *end_of_phys_p)
779{ 816{
780 unsigned long to_trim = *cur_size_p - cmdline_memory_size;
781 unsigned long avoid_start, avoid_end;
782 int i; 817 int i;
783 818
784 to_trim = PAGE_ALIGN(to_trim); 819 addr = ra_to_pa(addr);
820 for (i = 0; i < num_node_masks; i++) {
821 struct node_mem_mask *p = &node_masks[i];
785 822
786 avoid_start = avoid_end = 0; 823 if ((addr & p->mask) == p->val)
787#ifdef CONFIG_BLK_DEV_INITRD 824 return i;
788 avoid_start = initrd_start; 825 }
789 avoid_end = PAGE_ALIGN(initrd_end); 826 return -1;
827}
828
829static unsigned long nid_range(unsigned long start, unsigned long end,
830 int *nid)
831{
832 *nid = find_node(start);
833 start += PAGE_SIZE;
834 while (start < end) {
835 int n = find_node(start);
836
837 if (n != *nid)
838 break;
839 start += PAGE_SIZE;
840 }
841
842 return start;
843}
844#else
845static unsigned long nid_range(unsigned long start, unsigned long end,
846 int *nid)
847{
848 *nid = 0;
849 return end;
850}
790#endif 851#endif
791 852
792 /* Trim some pavail[] entries in order to satisfy the 853/* This must be invoked after performing all of the necessary
793 * requested "mem=xxx" kernel command line specification. 854 * add_active_range() calls for 'nid'. We need to be able to get
794 * 855 * correct data from get_pfn_range_for_nid().
795 * We must not trim off the kernel image area nor the 856 */
796 * initial ramdisk range (if any). Also, we must not trim 857static void __init allocate_node_data(int nid)
797 * any pavail[] entry down to zero in order to preserve 858{
798 * the invariant that all pavail[] entries have a non-zero 859 unsigned long paddr, num_pages, start_pfn, end_pfn;
799 * size which is assumed by all of the code in here. 860 struct pglist_data *p;
800 */ 861
801 for (i = 0; i < pavail_ents; i++) { 862#ifdef CONFIG_NEED_MULTIPLE_NODES
802 unsigned long start, end, kern_end; 863 paddr = lmb_alloc_nid(sizeof(struct pglist_data),
803 unsigned long trim_low, trim_high, n; 864 SMP_CACHE_BYTES, nid, nid_range);
865 if (!paddr) {
866 prom_printf("Cannot allocate pglist_data for nid[%d]\n", nid);
867 prom_halt();
868 }
869 NODE_DATA(nid) = __va(paddr);
870 memset(NODE_DATA(nid), 0, sizeof(struct pglist_data));
804 871
805 kern_end = PAGE_ALIGN(kern_base + kern_size); 872 NODE_DATA(nid)->bdata = &plat_node_bdata[nid];
873#endif
806 874
807 trim_low = start = pavail[i].phys_addr; 875 p = NODE_DATA(nid);
808 trim_high = end = start + pavail[i].reg_size;
809 876
810 if (kern_base >= start && 877 get_pfn_range_for_nid(nid, &start_pfn, &end_pfn);
811 kern_base < end) { 878 p->node_start_pfn = start_pfn;
812 trim_low = kern_base; 879 p->node_spanned_pages = end_pfn - start_pfn;
813 if (kern_end >= end) 880
814 continue; 881 if (p->node_spanned_pages) {
815 } 882 num_pages = bootmem_bootmap_pages(p->node_spanned_pages);
816 if (kern_end >= start && 883
817 kern_end < end) { 884 paddr = lmb_alloc_nid(num_pages << PAGE_SHIFT, PAGE_SIZE, nid,
818 trim_high = kern_end; 885 nid_range);
819 } 886 if (!paddr) {
820 if (avoid_start && 887 prom_printf("Cannot allocate bootmap for nid[%d]\n",
821 avoid_start >= start && 888 nid);
822 avoid_start < end) { 889 prom_halt();
823 if (trim_low > avoid_start)
824 trim_low = avoid_start;
825 if (avoid_end >= end)
826 continue;
827 }
828 if (avoid_end &&
829 avoid_end >= start &&
830 avoid_end < end) {
831 if (trim_high < avoid_end)
832 trim_high = avoid_end;
833 } 890 }
891 node_masks[nid].bootmem_paddr = paddr;
892 }
893}
894
895static void init_node_masks_nonnuma(void)
896{
897 int i;
898
899 numadbg("Initializing tables for non-numa.\n");
900
901 node_masks[0].mask = node_masks[0].val = 0;
902 num_node_masks = 1;
903
904 for (i = 0; i < NR_CPUS; i++)
905 numa_cpu_lookup_table[i] = 0;
906
907 numa_cpumask_lookup_table[0] = CPU_MASK_ALL;
908}
909
910#ifdef CONFIG_NEED_MULTIPLE_NODES
911struct pglist_data *node_data[MAX_NUMNODES];
912
913EXPORT_SYMBOL(numa_cpu_lookup_table);
914EXPORT_SYMBOL(numa_cpumask_lookup_table);
915EXPORT_SYMBOL(node_data);
916
917struct mdesc_mlgroup {
918 u64 node;
919 u64 latency;
920 u64 match;
921 u64 mask;
922};
923static struct mdesc_mlgroup *mlgroups;
924static int num_mlgroups;
925
926static int scan_pio_for_cfg_handle(struct mdesc_handle *md, u64 pio,
927 u32 cfg_handle)
928{
929 u64 arc;
834 930
835 if (trim_high <= trim_low) 931 mdesc_for_each_arc(arc, md, pio, MDESC_ARC_TYPE_FWD) {
932 u64 target = mdesc_arc_target(md, arc);
933 const u64 *val;
934
935 val = mdesc_get_property(md, target,
936 "cfg-handle", NULL);
937 if (val && *val == cfg_handle)
938 return 0;
939 }
940 return -ENODEV;
941}
942
943static int scan_arcs_for_cfg_handle(struct mdesc_handle *md, u64 grp,
944 u32 cfg_handle)
945{
946 u64 arc, candidate, best_latency = ~(u64)0;
947
948 candidate = MDESC_NODE_NULL;
949 mdesc_for_each_arc(arc, md, grp, MDESC_ARC_TYPE_FWD) {
950 u64 target = mdesc_arc_target(md, arc);
951 const char *name = mdesc_node_name(md, target);
952 const u64 *val;
953
954 if (strcmp(name, "pio-latency-group"))
836 continue; 955 continue;
837 956
838 if (trim_low == start && trim_high == end) { 957 val = mdesc_get_property(md, target, "latency", NULL);
839 /* Whole chunk is available for trimming. 958 if (!val)
840 * Trim all except one page, in order to keep 959 continue;
841 * entry non-empty. 960
842 */ 961 if (*val < best_latency) {
843 n = (end - start) - PAGE_SIZE; 962 candidate = target;
844 if (n > to_trim) 963 best_latency = *val;
845 n = to_trim;
846
847 if (n) {
848 pavail[i].phys_addr += n;
849 pavail[i].reg_size -= n;
850 to_trim -= n;
851 }
852 } else {
853 n = (trim_low - start);
854 if (n > to_trim)
855 n = to_trim;
856
857 if (n) {
858 pavail[i].phys_addr += n;
859 pavail[i].reg_size -= n;
860 to_trim -= n;
861 }
862 if (to_trim) {
863 n = end - trim_high;
864 if (n > to_trim)
865 n = to_trim;
866 if (n) {
867 pavail[i].reg_size -= n;
868 to_trim -= n;
869 }
870 }
871 } 964 }
965 }
966
967 if (candidate == MDESC_NODE_NULL)
968 return -ENODEV;
969
970 return scan_pio_for_cfg_handle(md, candidate, cfg_handle);
971}
972
973int of_node_to_nid(struct device_node *dp)
974{
975 const struct linux_prom64_registers *regs;
976 struct mdesc_handle *md;
977 u32 cfg_handle;
978 int count, nid;
979 u64 grp;
872 980
873 if (!to_trim) 981 if (!mlgroups)
982 return -1;
983
984 regs = of_get_property(dp, "reg", NULL);
985 if (!regs)
986 return -1;
987
988 cfg_handle = (regs->phys_addr >> 32UL) & 0x0fffffff;
989
990 md = mdesc_grab();
991
992 count = 0;
993 nid = -1;
994 mdesc_for_each_node_by_name(md, grp, "group") {
995 if (!scan_arcs_for_cfg_handle(md, grp, cfg_handle)) {
996 nid = count;
874 break; 997 break;
998 }
999 count++;
875 } 1000 }
876 1001
877 /* Recalculate. */ 1002 mdesc_release(md);
878 *cur_size_p = 0UL; 1003
879 for (i = 0; i < pavail_ents; i++) { 1004 return nid;
880 *end_of_phys_p = pavail[i].phys_addr +
881 pavail[i].reg_size;
882 *cur_size_p += pavail[i].reg_size;
883 }
884} 1005}
885 1006
886/* About pages_avail, this is the value we will use to calculate 1007static void add_node_ranges(void)
887 * the zholes_size[] argument given to free_area_init_node(). The
888 * page allocator uses this to calculate nr_kernel_pages,
889 * nr_all_pages and zone->present_pages. On NUMA it is used
890 * to calculate zone->min_unmapped_pages and zone->min_slab_pages.
891 *
892 * So this number should really be set to what the page allocator
893 * actually ends up with. This means:
894 * 1) It should include bootmem map pages, we'll release those.
895 * 2) It should not include the kernel image, except for the
896 * __init sections which we will also release.
897 * 3) It should include the initrd image, since we'll release
898 * that too.
899 */
900static unsigned long __init bootmem_init(unsigned long *pages_avail,
901 unsigned long phys_base)
902{ 1008{
903 unsigned long bootmap_size, end_pfn;
904 unsigned long end_of_phys_memory = 0UL;
905 unsigned long bootmap_pfn, bytes_avail, size;
906 int i; 1009 int i;
907 1010
908 bytes_avail = 0UL; 1011 for (i = 0; i < lmb.memory.cnt; i++) {
909 for (i = 0; i < pavail_ents; i++) { 1012 unsigned long size = lmb_size_bytes(&lmb.memory, i);
910 end_of_phys_memory = pavail[i].phys_addr + 1013 unsigned long start, end;
911 pavail[i].reg_size; 1014
912 bytes_avail += pavail[i].reg_size; 1015 start = lmb.memory.region[i].base;
1016 end = start + size;
1017 while (start < end) {
1018 unsigned long this_end;
1019 int nid;
1020
1021 this_end = nid_range(start, end, &nid);
1022
1023 numadbg("Adding active range nid[%d] "
1024 "start[%lx] end[%lx]\n",
1025 nid, start, this_end);
1026
1027 add_active_range(nid,
1028 start >> PAGE_SHIFT,
1029 this_end >> PAGE_SHIFT);
1030
1031 start = this_end;
1032 }
913 } 1033 }
1034}
914 1035
915 /* Determine the location of the initial ramdisk before trying 1036static int __init grab_mlgroups(struct mdesc_handle *md)
916 * to honor the "mem=xxx" command line argument. We must know 1037{
917 * where the kernel image and the ramdisk image are so that we 1038 unsigned long paddr;
918 * do not trim those two areas from the physical memory map. 1039 int count = 0;
919 */ 1040 u64 node;
1041
1042 mdesc_for_each_node_by_name(md, node, "memory-latency-group")
1043 count++;
1044 if (!count)
1045 return -ENOENT;
1046
1047 paddr = lmb_alloc(count * sizeof(struct mdesc_mlgroup),
1048 SMP_CACHE_BYTES);
1049 if (!paddr)
1050 return -ENOMEM;
1051
1052 mlgroups = __va(paddr);
1053 num_mlgroups = count;
1054
1055 count = 0;
1056 mdesc_for_each_node_by_name(md, node, "memory-latency-group") {
1057 struct mdesc_mlgroup *m = &mlgroups[count++];
1058 const u64 *val;
1059
1060 m->node = node;
1061
1062 val = mdesc_get_property(md, node, "latency", NULL);
1063 m->latency = *val;
1064 val = mdesc_get_property(md, node, "address-match", NULL);
1065 m->match = *val;
1066 val = mdesc_get_property(md, node, "address-mask", NULL);
1067 m->mask = *val;
1068
1069 numadbg("MLGROUP[%d]: node[%lx] latency[%lx] "
1070 "match[%lx] mask[%lx]\n",
1071 count - 1, m->node, m->latency, m->match, m->mask);
1072 }
920 1073
921#ifdef CONFIG_BLK_DEV_INITRD 1074 return 0;
922 /* Now have to check initial ramdisk, so that bootmap does not overwrite it */ 1075}
923 if (sparc_ramdisk_image || sparc_ramdisk_image64) { 1076
924 unsigned long ramdisk_image = sparc_ramdisk_image ? 1077static int __init grab_mblocks(struct mdesc_handle *md)
925 sparc_ramdisk_image : sparc_ramdisk_image64; 1078{
926 ramdisk_image -= KERNBASE; 1079 unsigned long paddr;
927 initrd_start = ramdisk_image + phys_base; 1080 int count = 0;
928 initrd_end = initrd_start + sparc_ramdisk_size; 1081 u64 node;
929 if (initrd_end > end_of_phys_memory) { 1082
930 printk(KERN_CRIT "initrd extends beyond end of memory " 1083 mdesc_for_each_node_by_name(md, node, "mblock")
931 "(0x%016lx > 0x%016lx)\ndisabling initrd\n", 1084 count++;
932 initrd_end, end_of_phys_memory); 1085 if (!count)
933 initrd_start = 0; 1086 return -ENOENT;
934 initrd_end = 0; 1087
1088 paddr = lmb_alloc(count * sizeof(struct mdesc_mblock),
1089 SMP_CACHE_BYTES);
1090 if (!paddr)
1091 return -ENOMEM;
1092
1093 mblocks = __va(paddr);
1094 num_mblocks = count;
1095
1096 count = 0;
1097 mdesc_for_each_node_by_name(md, node, "mblock") {
1098 struct mdesc_mblock *m = &mblocks[count++];
1099 const u64 *val;
1100
1101 val = mdesc_get_property(md, node, "base", NULL);
1102 m->base = *val;
1103 val = mdesc_get_property(md, node, "size", NULL);
1104 m->size = *val;
1105 val = mdesc_get_property(md, node,
1106 "address-congruence-offset", NULL);
1107 m->offset = *val;
1108
1109 numadbg("MBLOCK[%d]: base[%lx] size[%lx] offset[%lx]\n",
1110 count - 1, m->base, m->size, m->offset);
1111 }
1112
1113 return 0;
1114}
1115
1116static void __init numa_parse_mdesc_group_cpus(struct mdesc_handle *md,
1117 u64 grp, cpumask_t *mask)
1118{
1119 u64 arc;
1120
1121 cpus_clear(*mask);
1122
1123 mdesc_for_each_arc(arc, md, grp, MDESC_ARC_TYPE_BACK) {
1124 u64 target = mdesc_arc_target(md, arc);
1125 const char *name = mdesc_node_name(md, target);
1126 const u64 *id;
1127
1128 if (strcmp(name, "cpu"))
1129 continue;
1130 id = mdesc_get_property(md, target, "id", NULL);
1131 if (*id < NR_CPUS)
1132 cpu_set(*id, *mask);
1133 }
1134}
1135
1136static struct mdesc_mlgroup * __init find_mlgroup(u64 node)
1137{
1138 int i;
1139
1140 for (i = 0; i < num_mlgroups; i++) {
1141 struct mdesc_mlgroup *m = &mlgroups[i];
1142 if (m->node == node)
1143 return m;
1144 }
1145 return NULL;
1146}
1147
1148static int __init numa_attach_mlgroup(struct mdesc_handle *md, u64 grp,
1149 int index)
1150{
1151 struct mdesc_mlgroup *candidate = NULL;
1152 u64 arc, best_latency = ~(u64)0;
1153 struct node_mem_mask *n;
1154
1155 mdesc_for_each_arc(arc, md, grp, MDESC_ARC_TYPE_FWD) {
1156 u64 target = mdesc_arc_target(md, arc);
1157 struct mdesc_mlgroup *m = find_mlgroup(target);
1158 if (!m)
1159 continue;
1160 if (m->latency < best_latency) {
1161 candidate = m;
1162 best_latency = m->latency;
935 } 1163 }
936 } 1164 }
937#endif 1165 if (!candidate)
1166 return -ENOENT;
1167
1168 if (num_node_masks != index) {
1169 printk(KERN_ERR "Inconsistent NUMA state, "
1170 "index[%d] != num_node_masks[%d]\n",
1171 index, num_node_masks);
1172 return -EINVAL;
1173 }
938 1174
939 if (cmdline_memory_size && 1175 n = &node_masks[num_node_masks++];
940 bytes_avail > cmdline_memory_size)
941 trim_pavail(&bytes_avail,
942 &end_of_phys_memory);
943 1176
944 *pages_avail = bytes_avail >> PAGE_SHIFT; 1177 n->mask = candidate->mask;
1178 n->val = candidate->match;
945 1179
946 end_pfn = end_of_phys_memory >> PAGE_SHIFT; 1180 numadbg("NUMA NODE[%d]: mask[%lx] val[%lx] (latency[%lx])\n",
1181 index, n->mask, n->val, candidate->latency);
947 1182
948 /* Initialize the boot-time allocator. */ 1183 return 0;
949 max_pfn = max_low_pfn = end_pfn; 1184}
950 min_low_pfn = (phys_base >> PAGE_SHIFT); 1185
1186static int __init numa_parse_mdesc_group(struct mdesc_handle *md, u64 grp,
1187 int index)
1188{
1189 cpumask_t mask;
1190 int cpu;
951 1191
952 bootmap_pfn = choose_bootmap_pfn(min_low_pfn, end_pfn); 1192 numa_parse_mdesc_group_cpus(md, grp, &mask);
953 1193
954 bootmap_size = init_bootmem_node(NODE_DATA(0), bootmap_pfn, 1194 for_each_cpu_mask(cpu, mask)
955 min_low_pfn, end_pfn); 1195 numa_cpu_lookup_table[cpu] = index;
1196 numa_cpumask_lookup_table[index] = mask;
956 1197
957 /* Now register the available physical memory with the 1198 if (numa_debug) {
958 * allocator. 1199 printk(KERN_INFO "NUMA GROUP[%d]: cpus [ ", index);
959 */ 1200 for_each_cpu_mask(cpu, mask)
960 for (i = 0; i < pavail_ents; i++) 1201 printk("%d ", cpu);
961 free_bootmem(pavail[i].phys_addr, pavail[i].reg_size); 1202 printk("]\n");
1203 }
962 1204
963#ifdef CONFIG_BLK_DEV_INITRD 1205 return numa_attach_mlgroup(md, grp, index);
964 if (initrd_start) { 1206}
965 size = initrd_end - initrd_start; 1207
1208static int __init numa_parse_mdesc(void)
1209{
1210 struct mdesc_handle *md = mdesc_grab();
1211 int i, err, count;
1212 u64 node;
1213
1214 node = mdesc_node_by_name(md, MDESC_NODE_NULL, "latency-groups");
1215 if (node == MDESC_NODE_NULL) {
1216 mdesc_release(md);
1217 return -ENOENT;
1218 }
1219
1220 err = grab_mblocks(md);
1221 if (err < 0)
1222 goto out;
1223
1224 err = grab_mlgroups(md);
1225 if (err < 0)
1226 goto out;
1227
1228 count = 0;
1229 mdesc_for_each_node_by_name(md, node, "group") {
1230 err = numa_parse_mdesc_group(md, node, count);
1231 if (err < 0)
1232 break;
1233 count++;
1234 }
1235
1236 add_node_ranges();
1237
1238 for (i = 0; i < num_node_masks; i++) {
1239 allocate_node_data(i);
1240 node_set_online(i);
1241 }
1242
1243 err = 0;
1244out:
1245 mdesc_release(md);
1246 return err;
1247}
1248
1249static int __init numa_parse_sun4u(void)
1250{
1251 return -1;
1252}
966 1253
967 /* Reserve the initrd image area. */ 1254static int __init bootmem_init_numa(void)
968 reserve_bootmem(initrd_start, size, BOOTMEM_DEFAULT); 1255{
1256 int err = -1;
969 1257
970 initrd_start += PAGE_OFFSET; 1258 numadbg("bootmem_init_numa()\n");
971 initrd_end += PAGE_OFFSET; 1259
1260 if (numa_enabled) {
1261 if (tlb_type == hypervisor)
1262 err = numa_parse_mdesc();
1263 else
1264 err = numa_parse_sun4u();
972 } 1265 }
1266 return err;
1267}
1268
1269#else
1270
1271static int bootmem_init_numa(void)
1272{
1273 return -1;
1274}
1275
973#endif 1276#endif
974 /* Reserve the kernel text/data/bss. */
975 reserve_bootmem(kern_base, kern_size, BOOTMEM_DEFAULT);
976 *pages_avail -= PAGE_ALIGN(kern_size) >> PAGE_SHIFT;
977
978 /* Add back in the initmem pages. */
979 size = ((unsigned long)(__init_end) & PAGE_MASK) -
980 PAGE_ALIGN((unsigned long)__init_begin);
981 *pages_avail += size >> PAGE_SHIFT;
982
983 /* Reserve the bootmem map. We do not account for it
984 * in pages_avail because we will release that memory
985 * in free_all_bootmem.
986 */
987 size = bootmap_size;
988 reserve_bootmem((bootmap_pfn << PAGE_SHIFT), size, BOOTMEM_DEFAULT);
989 1277
990 for (i = 0; i < pavail_ents; i++) { 1278static void __init bootmem_init_nonnuma(void)
1279{
1280 unsigned long top_of_ram = lmb_end_of_DRAM();
1281 unsigned long total_ram = lmb_phys_mem_size();
1282 unsigned int i;
1283
1284 numadbg("bootmem_init_nonnuma()\n");
1285
1286 printk(KERN_INFO "Top of RAM: 0x%lx, Total RAM: 0x%lx\n",
1287 top_of_ram, total_ram);
1288 printk(KERN_INFO "Memory hole size: %ldMB\n",
1289 (top_of_ram - total_ram) >> 20);
1290
1291 init_node_masks_nonnuma();
1292
1293 for (i = 0; i < lmb.memory.cnt; i++) {
1294 unsigned long size = lmb_size_bytes(&lmb.memory, i);
991 unsigned long start_pfn, end_pfn; 1295 unsigned long start_pfn, end_pfn;
992 1296
993 start_pfn = pavail[i].phys_addr >> PAGE_SHIFT; 1297 if (!size)
994 end_pfn = (start_pfn + (pavail[i].reg_size >> PAGE_SHIFT)); 1298 continue;
995 memory_present(0, start_pfn, end_pfn); 1299
1300 start_pfn = lmb.memory.region[i].base >> PAGE_SHIFT;
1301 end_pfn = start_pfn + lmb_size_pages(&lmb.memory, i);
1302 add_active_range(0, start_pfn, end_pfn);
1303 }
1304
1305 allocate_node_data(0);
1306
1307 node_set_online(0);
1308}
1309
1310static void __init reserve_range_in_node(int nid, unsigned long start,
1311 unsigned long end)
1312{
1313 numadbg(" reserve_range_in_node(nid[%d],start[%lx],end[%lx]\n",
1314 nid, start, end);
1315 while (start < end) {
1316 unsigned long this_end;
1317 int n;
1318
1319 this_end = nid_range(start, end, &n);
1320 if (n == nid) {
1321 numadbg(" MATCH reserving range [%lx:%lx]\n",
1322 start, this_end);
1323 reserve_bootmem_node(NODE_DATA(nid), start,
1324 (this_end - start), BOOTMEM_DEFAULT);
1325 } else
1326 numadbg(" NO MATCH, advancing start to %lx\n",
1327 this_end);
1328
1329 start = this_end;
1330 }
1331}
1332
1333static void __init trim_reserved_in_node(int nid)
1334{
1335 int i;
1336
1337 numadbg(" trim_reserved_in_node(%d)\n", nid);
1338
1339 for (i = 0; i < lmb.reserved.cnt; i++) {
1340 unsigned long start = lmb.reserved.region[i].base;
1341 unsigned long size = lmb_size_bytes(&lmb.reserved, i);
1342 unsigned long end = start + size;
1343
1344 reserve_range_in_node(nid, start, end);
1345 }
1346}
1347
1348static void __init bootmem_init_one_node(int nid)
1349{
1350 struct pglist_data *p;
1351
1352 numadbg("bootmem_init_one_node(%d)\n", nid);
1353
1354 p = NODE_DATA(nid);
1355
1356 if (p->node_spanned_pages) {
1357 unsigned long paddr = node_masks[nid].bootmem_paddr;
1358 unsigned long end_pfn;
1359
1360 end_pfn = p->node_start_pfn + p->node_spanned_pages;
1361
1362 numadbg(" init_bootmem_node(%d, %lx, %lx, %lx)\n",
1363 nid, paddr >> PAGE_SHIFT, p->node_start_pfn, end_pfn);
1364
1365 init_bootmem_node(p, paddr >> PAGE_SHIFT,
1366 p->node_start_pfn, end_pfn);
1367
1368 numadbg(" free_bootmem_with_active_regions(%d, %lx)\n",
1369 nid, end_pfn);
1370 free_bootmem_with_active_regions(nid, end_pfn);
1371
1372 trim_reserved_in_node(nid);
1373
1374 numadbg(" sparse_memory_present_with_active_regions(%d)\n",
1375 nid);
1376 sparse_memory_present_with_active_regions(nid);
996 } 1377 }
1378}
1379
1380static unsigned long __init bootmem_init(unsigned long phys_base)
1381{
1382 unsigned long end_pfn;
1383 int nid;
1384
1385 end_pfn = lmb_end_of_DRAM() >> PAGE_SHIFT;
1386 max_pfn = max_low_pfn = end_pfn;
1387 min_low_pfn = (phys_base >> PAGE_SHIFT);
1388
1389 if (bootmem_init_numa() < 0)
1390 bootmem_init_nonnuma();
1391
1392 /* XXX cpu notifier XXX */
1393
1394 for_each_online_node(nid)
1395 bootmem_init_one_node(nid);
997 1396
998 sparse_init(); 1397 sparse_init();
999 1398
@@ -1289,7 +1688,7 @@ void __init setup_per_cpu_areas(void)
1289 1688
1290void __init paging_init(void) 1689void __init paging_init(void)
1291{ 1690{
1292 unsigned long end_pfn, pages_avail, shift, phys_base; 1691 unsigned long end_pfn, shift, phys_base;
1293 unsigned long real_end, i; 1692 unsigned long real_end, i;
1294 1693
1295 /* These build time checkes make sure that the dcache_dirty_cpu() 1694 /* These build time checkes make sure that the dcache_dirty_cpu()
@@ -1330,12 +1729,26 @@ void __init paging_init(void)
1330 sun4v_ktsb_init(); 1729 sun4v_ktsb_init();
1331 } 1730 }
1332 1731
1732 lmb_init();
1733
1333 /* Find available physical memory... */ 1734 /* Find available physical memory... */
1334 read_obp_memory("available", &pavail[0], &pavail_ents); 1735 read_obp_memory("available", &pavail[0], &pavail_ents);
1335 1736
1336 phys_base = 0xffffffffffffffffUL; 1737 phys_base = 0xffffffffffffffffUL;
1337 for (i = 0; i < pavail_ents; i++) 1738 for (i = 0; i < pavail_ents; i++) {
1338 phys_base = min(phys_base, pavail[i].phys_addr); 1739 phys_base = min(phys_base, pavail[i].phys_addr);
1740 lmb_add(pavail[i].phys_addr, pavail[i].reg_size);
1741 }
1742
1743 lmb_reserve(kern_base, kern_size);
1744
1745 find_ramdisk(phys_base);
1746
1747 if (cmdline_memory_size)
1748 lmb_enforce_memory_limit(phys_base + cmdline_memory_size);
1749
1750 lmb_analyze();
1751 lmb_dump_all();
1339 1752
1340 set_bit(0, mmu_context_bmap); 1753 set_bit(0, mmu_context_bmap);
1341 1754
@@ -1371,14 +1784,10 @@ void __init paging_init(void)
1371 if (tlb_type == hypervisor) 1784 if (tlb_type == hypervisor)
1372 sun4v_ktsb_register(); 1785 sun4v_ktsb_register();
1373 1786
1374 /* Setup bootmem... */ 1787 /* We must setup the per-cpu areas before we pull in the
1375 pages_avail = 0; 1788 * PROM and the MDESC. The code there fills in cpu and
1376 last_valid_pfn = end_pfn = bootmem_init(&pages_avail, phys_base); 1789 * other information into per-cpu data structures.
1377 1790 */
1378 max_mapnr = last_valid_pfn;
1379
1380 kernel_physical_mapping_init();
1381
1382 real_setup_per_cpu_areas(); 1791 real_setup_per_cpu_areas();
1383 1792
1384 prom_build_devicetree(); 1793 prom_build_devicetree();
@@ -1386,20 +1795,22 @@ void __init paging_init(void)
1386 if (tlb_type == hypervisor) 1795 if (tlb_type == hypervisor)
1387 sun4v_mdesc_init(); 1796 sun4v_mdesc_init();
1388 1797
1798 /* Setup bootmem... */
1799 last_valid_pfn = end_pfn = bootmem_init(phys_base);
1800
1801#ifndef CONFIG_NEED_MULTIPLE_NODES
1802 max_mapnr = last_valid_pfn;
1803#endif
1804 kernel_physical_mapping_init();
1805
1389 { 1806 {
1390 unsigned long zones_size[MAX_NR_ZONES]; 1807 unsigned long max_zone_pfns[MAX_NR_ZONES];
1391 unsigned long zholes_size[MAX_NR_ZONES];
1392 int znum;
1393 1808
1394 for (znum = 0; znum < MAX_NR_ZONES; znum++) 1809 memset(max_zone_pfns, 0, sizeof(max_zone_pfns));
1395 zones_size[znum] = zholes_size[znum] = 0;
1396 1810
1397 zones_size[ZONE_NORMAL] = end_pfn; 1811 max_zone_pfns[ZONE_NORMAL] = end_pfn;
1398 zholes_size[ZONE_NORMAL] = end_pfn - pages_avail;
1399 1812
1400 free_area_init_node(0, &contig_page_data, zones_size, 1813 free_area_init_nodes(max_zone_pfns);
1401 __pa(PAGE_OFFSET) >> PAGE_SHIFT,
1402 zholes_size);
1403 } 1814 }
1404 1815
1405 printk("Booting Linux...\n"); 1816 printk("Booting Linux...\n");
@@ -1408,21 +1819,52 @@ void __init paging_init(void)
1408 cpu_probe(); 1819 cpu_probe();
1409} 1820}
1410 1821
1411static void __init taint_real_pages(void) 1822int __init page_in_phys_avail(unsigned long paddr)
1823{
1824 int i;
1825
1826 paddr &= PAGE_MASK;
1827
1828 for (i = 0; i < pavail_ents; i++) {
1829 unsigned long start, end;
1830
1831 start = pavail[i].phys_addr;
1832 end = start + pavail[i].reg_size;
1833
1834 if (paddr >= start && paddr < end)
1835 return 1;
1836 }
1837 if (paddr >= kern_base && paddr < (kern_base + kern_size))
1838 return 1;
1839#ifdef CONFIG_BLK_DEV_INITRD
1840 if (paddr >= __pa(initrd_start) &&
1841 paddr < __pa(PAGE_ALIGN(initrd_end)))
1842 return 1;
1843#endif
1844
1845 return 0;
1846}
1847
1848static struct linux_prom64_registers pavail_rescan[MAX_BANKS] __initdata;
1849static int pavail_rescan_ents __initdata;
1850
1851/* Certain OBP calls, such as fetching "available" properties, can
1852 * claim physical memory. So, along with initializing the valid
1853 * address bitmap, what we do here is refetch the physical available
1854 * memory list again, and make sure it provides at least as much
1855 * memory as 'pavail' does.
1856 */
1857static void setup_valid_addr_bitmap_from_pavail(void)
1412{ 1858{
1413 int i; 1859 int i;
1414 1860
1415 read_obp_memory("available", &pavail_rescan[0], &pavail_rescan_ents); 1861 read_obp_memory("available", &pavail_rescan[0], &pavail_rescan_ents);
1416 1862
1417 /* Find changes discovered in the physmem available rescan and
1418 * reserve the lost portions in the bootmem maps.
1419 */
1420 for (i = 0; i < pavail_ents; i++) { 1863 for (i = 0; i < pavail_ents; i++) {
1421 unsigned long old_start, old_end; 1864 unsigned long old_start, old_end;
1422 1865
1423 old_start = pavail[i].phys_addr; 1866 old_start = pavail[i].phys_addr;
1424 old_end = old_start + 1867 old_end = old_start + pavail[i].reg_size;
1425 pavail[i].reg_size;
1426 while (old_start < old_end) { 1868 while (old_start < old_end) {
1427 int n; 1869 int n;
1428 1870
@@ -1440,7 +1882,16 @@ static void __init taint_real_pages(void)
1440 goto do_next_page; 1882 goto do_next_page;
1441 } 1883 }
1442 } 1884 }
1443 reserve_bootmem(old_start, PAGE_SIZE, BOOTMEM_DEFAULT); 1885
1886 prom_printf("mem_init: Lost memory in pavail\n");
1887 prom_printf("mem_init: OLD start[%lx] size[%lx]\n",
1888 pavail[i].phys_addr,
1889 pavail[i].reg_size);
1890 prom_printf("mem_init: NEW start[%lx] size[%lx]\n",
1891 pavail_rescan[i].phys_addr,
1892 pavail_rescan[i].reg_size);
1893 prom_printf("mem_init: Cannot continue, aborting.\n");
1894 prom_halt();
1444 1895
1445 do_next_page: 1896 do_next_page:
1446 old_start += PAGE_SIZE; 1897 old_start += PAGE_SIZE;
@@ -1448,32 +1899,6 @@ static void __init taint_real_pages(void)
1448 } 1899 }
1449} 1900}
1450 1901
1451int __init page_in_phys_avail(unsigned long paddr)
1452{
1453 int i;
1454
1455 paddr &= PAGE_MASK;
1456
1457 for (i = 0; i < pavail_rescan_ents; i++) {
1458 unsigned long start, end;
1459
1460 start = pavail_rescan[i].phys_addr;
1461 end = start + pavail_rescan[i].reg_size;
1462
1463 if (paddr >= start && paddr < end)
1464 return 1;
1465 }
1466 if (paddr >= kern_base && paddr < (kern_base + kern_size))
1467 return 1;
1468#ifdef CONFIG_BLK_DEV_INITRD
1469 if (paddr >= __pa(initrd_start) &&
1470 paddr < __pa(PAGE_ALIGN(initrd_end)))
1471 return 1;
1472#endif
1473
1474 return 0;
1475}
1476
1477void __init mem_init(void) 1902void __init mem_init(void)
1478{ 1903{
1479 unsigned long codepages, datapages, initpages; 1904 unsigned long codepages, datapages, initpages;
@@ -1496,14 +1921,26 @@ void __init mem_init(void)
1496 addr += PAGE_SIZE; 1921 addr += PAGE_SIZE;
1497 } 1922 }
1498 1923
1499 taint_real_pages(); 1924 setup_valid_addr_bitmap_from_pavail();
1500 1925
1501 high_memory = __va(last_valid_pfn << PAGE_SHIFT); 1926 high_memory = __va(last_valid_pfn << PAGE_SHIFT);
1502 1927
1928#ifdef CONFIG_NEED_MULTIPLE_NODES
1929 for_each_online_node(i) {
1930 if (NODE_DATA(i)->node_spanned_pages != 0) {
1931 totalram_pages +=
1932 free_all_bootmem_node(NODE_DATA(i));
1933 }
1934 }
1935#else
1936 totalram_pages = free_all_bootmem();
1937#endif
1938
1503 /* We subtract one to account for the mem_map_zero page 1939 /* We subtract one to account for the mem_map_zero page
1504 * allocated below. 1940 * allocated below.
1505 */ 1941 */
1506 totalram_pages = num_physpages = free_all_bootmem() - 1; 1942 totalram_pages -= 1;
1943 num_physpages = totalram_pages;
1507 1944
1508 /* 1945 /*
1509 * Set up the zero page, mark it reserved, so that page count 1946 * Set up the zero page, mark it reserved, so that page count
diff --git a/arch/sparc64/mm/tsb.c b/arch/sparc64/mm/tsb.c
index a3e6e4b635b3..fe70c8a557b5 100644
--- a/arch/sparc64/mm/tsb.c
+++ b/arch/sparc64/mm/tsb.c
@@ -321,7 +321,8 @@ retry_tsb_alloc:
321 if (new_size > (PAGE_SIZE * 2)) 321 if (new_size > (PAGE_SIZE * 2))
322 gfp_flags = __GFP_NOWARN | __GFP_NORETRY; 322 gfp_flags = __GFP_NOWARN | __GFP_NORETRY;
323 323
324 new_tsb = kmem_cache_alloc(tsb_caches[new_cache_index], gfp_flags); 324 new_tsb = kmem_cache_alloc_node(tsb_caches[new_cache_index],
325 gfp_flags, numa_node_id());
325 if (unlikely(!new_tsb)) { 326 if (unlikely(!new_tsb)) {
326 /* Not being able to fork due to a high-order TSB 327 /* Not being able to fork due to a high-order TSB
327 * allocation failure is very bad behavior. Just back 328 * allocation failure is very bad behavior. Just back
diff --git a/arch/sparc64/mm/ultra.S b/arch/sparc64/mm/ultra.S
index 2865c105b6a4..e686a67561af 100644
--- a/arch/sparc64/mm/ultra.S
+++ b/arch/sparc64/mm/ultra.S
@@ -476,7 +476,6 @@ xcall_sync_tick:
476#endif 476#endif
477 call smp_synchronize_tick_client 477 call smp_synchronize_tick_client
478 nop 478 nop
479 clr %l6
480 b rtrap_xcall 479 b rtrap_xcall
481 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1 480 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
482 481
@@ -511,7 +510,6 @@ xcall_report_regs:
511#endif 510#endif
512 call __show_regs 511 call __show_regs
513 add %sp, PTREGS_OFF, %o0 512 add %sp, PTREGS_OFF, %o0
514 clr %l6
515 /* Has to be a non-v9 branch due to the large distance. */ 513 /* Has to be a non-v9 branch due to the large distance. */
516 b rtrap_xcall 514 b rtrap_xcall
517 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1 515 ldx [%sp + PTREGS_OFF + PT_V9_TSTATE], %l1
@@ -576,7 +574,7 @@ __hypervisor_tlb_xcall_error:
576 mov %l4, %o0 574 mov %l4, %o0
577 call hypervisor_tlbop_error_xcall 575 call hypervisor_tlbop_error_xcall
578 mov %l5, %o1 576 mov %l5, %o1
579 ba,a,pt %xcc, rtrap_clr_l6 577 ba,a,pt %xcc, rtrap
580 578
581 .globl __hypervisor_xcall_flush_tlb_mm 579 .globl __hypervisor_xcall_flush_tlb_mm
582__hypervisor_xcall_flush_tlb_mm: /* 21 insns */ 580__hypervisor_xcall_flush_tlb_mm: /* 21 insns */
diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
index a87b89db08e9..2906ee7bd298 100644
--- a/drivers/char/Kconfig
+++ b/drivers/char/Kconfig
@@ -481,6 +481,34 @@ config BRIQ_PANEL
481 481
482 It's safe to say N here. 482 It's safe to say N here.
483 483
484config BFIN_OTP
485 tristate "Blackfin On-Chip OTP Memory Support"
486 depends on BLACKFIN && (BF52x || BF54x)
487 default y
488 help
489 If you say Y here, you will get support for a character device
490 interface into the One Time Programmable memory pages that are
491 stored on the Blackfin processor. This will not get you access
492 to the secure memory pages however. You will need to write your
493 own secure code and reader for that.
494
495 To compile this driver as a module, choose M here: the module
496 will be called bfin-otp.
497
498 If unsure, it is safe to say Y.
499
500config BFIN_OTP_WRITE_ENABLE
501 bool "Enable writing support of OTP pages"
502 depends on BFIN_OTP
503 default n
504 help
505 If you say Y here, you will enable support for writing of the
506 OTP pages. This is dangerous by nature as you can only program
507 the pages once, so only enable this option when you actually
508 need it so as to not inadvertently clobber data.
509
510 If unsure, say N.
511
484config PRINTER 512config PRINTER
485 tristate "Parallel printer support" 513 tristate "Parallel printer support"
486 depends on PARPORT 514 depends on PARPORT
diff --git a/drivers/char/Makefile b/drivers/char/Makefile
index 5407b7615614..4c1c584e9eb6 100644
--- a/drivers/char/Makefile
+++ b/drivers/char/Makefile
@@ -59,6 +59,7 @@ obj-$(CONFIG_VIOTAPE) += viotape.o
59obj-$(CONFIG_HVCS) += hvcs.o 59obj-$(CONFIG_HVCS) += hvcs.o
60obj-$(CONFIG_SGI_MBCS) += mbcs.o 60obj-$(CONFIG_SGI_MBCS) += mbcs.o
61obj-$(CONFIG_BRIQ_PANEL) += briq_panel.o 61obj-$(CONFIG_BRIQ_PANEL) += briq_panel.o
62obj-$(CONFIG_BFIN_OTP) += bfin-otp.o
62 63
63obj-$(CONFIG_PRINTER) += lp.o 64obj-$(CONFIG_PRINTER) += lp.o
64obj-$(CONFIG_TIPAR) += tipar.o 65obj-$(CONFIG_TIPAR) += tipar.o
diff --git a/drivers/char/bfin-otp.c b/drivers/char/bfin-otp.c
new file mode 100644
index 000000000000..0a01329451e4
--- /dev/null
+++ b/drivers/char/bfin-otp.c
@@ -0,0 +1,189 @@
1/*
2 * Blackfin On-Chip OTP Memory Interface
3 * Supports BF52x/BF54x
4 *
5 * Copyright 2007-2008 Analog Devices Inc.
6 *
7 * Enter bugs at http://blackfin.uclinux.org/
8 *
9 * Licensed under the GPL-2 or later.
10 */
11
12#include <linux/device.h>
13#include <linux/errno.h>
14#include <linux/fs.h>
15#include <linux/init.h>
16#include <linux/miscdevice.h>
17#include <linux/module.h>
18#include <linux/mutex.h>
19#include <linux/types.h>
20
21#include <asm/blackfin.h>
22#include <asm/uaccess.h>
23
24#define stamp(fmt, args...) pr_debug("%s:%i: " fmt "\n", __func__, __LINE__, ## args)
25#define stampit() stamp("here i am")
26#define pr_init(fmt, args...) ({ static const __initconst char __fmt[] = fmt; printk(__fmt, ## args); })
27
28#define DRIVER_NAME "bfin-otp"
29#define PFX DRIVER_NAME ": "
30
31static DEFINE_MUTEX(bfin_otp_lock);
32
33/* OTP Boot ROM functions */
34#define _BOOTROM_OTP_COMMAND 0xEF000018
35#define _BOOTROM_OTP_READ 0xEF00001A
36#define _BOOTROM_OTP_WRITE 0xEF00001C
37
38static u32 (* const otp_command)(u32 command, u32 value) = (void *)_BOOTROM_OTP_COMMAND;
39static u32 (* const otp_read)(u32 page, u32 flags, u64 *page_content) = (void *)_BOOTROM_OTP_READ;
40static u32 (* const otp_write)(u32 page, u32 flags, u64 *page_content) = (void *)_BOOTROM_OTP_WRITE;
41
42/* otp_command(): defines for "command" */
43#define OTP_INIT 0x00000001
44#define OTP_CLOSE 0x00000002
45
46/* otp_{read,write}(): defines for "flags" */
47#define OTP_LOWER_HALF 0x00000000 /* select upper/lower 64-bit half (bit 0) */
48#define OTP_UPPER_HALF 0x00000001
49#define OTP_NO_ECC 0x00000010 /* do not use ECC */
50#define OTP_LOCK 0x00000020 /* sets page protection bit for page */
51#define OTP_ACCESS_READ 0x00001000
52#define OTP_ACCESS_READWRITE 0x00002000
53
54/* Return values for all functions */
55#define OTP_SUCCESS 0x00000000
56#define OTP_MASTER_ERROR 0x001
57#define OTP_WRITE_ERROR 0x003
58#define OTP_READ_ERROR 0x005
59#define OTP_ACC_VIO_ERROR 0x009
60#define OTP_DATA_MULT_ERROR 0x011
61#define OTP_ECC_MULT_ERROR 0x021
62#define OTP_PREV_WR_ERROR 0x041
63#define OTP_DATA_SB_WARN 0x100
64#define OTP_ECC_SB_WARN 0x200
65
66/**
67 * bfin_otp_read - Read OTP pages
68 *
69 * All reads must be in half page chunks (half page == 64 bits).
70 */
71static ssize_t bfin_otp_read(struct file *file, char __user *buff, size_t count, loff_t *pos)
72{
73 ssize_t bytes_done;
74 u32 page, flags, ret;
75 u64 content;
76
77 stampit();
78
79 if (count % sizeof(u64))
80 return -EMSGSIZE;
81
82 if (mutex_lock_interruptible(&bfin_otp_lock))
83 return -ERESTARTSYS;
84
85 bytes_done = 0;
86 page = *pos / (sizeof(u64) * 2);
87 while (bytes_done < count) {
88 flags = (*pos % (sizeof(u64) * 2) ? OTP_UPPER_HALF : OTP_LOWER_HALF);
89 stamp("processing page %i (%s)", page, (flags == OTP_UPPER_HALF ? "upper" : "lower"));
90 ret = otp_read(page, flags, &content);
91 if (ret & OTP_MASTER_ERROR) {
92 bytes_done = -EIO;
93 break;
94 }
95 if (copy_to_user(buff + bytes_done, &content, sizeof(content))) {
96 bytes_done = -EFAULT;
97 break;
98 }
99 if (flags == OTP_UPPER_HALF)
100 ++page;
101 bytes_done += sizeof(content);
102 *pos += sizeof(content);
103 }
104
105 mutex_unlock(&bfin_otp_lock);
106
107 return bytes_done;
108}
109
110#ifdef CONFIG_BFIN_OTP_WRITE_ENABLE
111/**
112 * bfin_otp_write - Write OTP pages
113 *
114 * All writes must be in half page chunks (half page == 64 bits).
115 */
116static ssize_t bfin_otp_write(struct file *filp, const char __user *buff, size_t count, loff_t *pos)
117{
118 stampit();
119
120 if (count % sizeof(u64))
121 return -EMSGSIZE;
122
123 if (mutex_lock_interruptible(&bfin_otp_lock))
124 return -ERESTARTSYS;
125
126 /* need otp_init() documentation before this can be implemented */
127
128 mutex_unlock(&bfin_otp_lock);
129
130 return -EINVAL;
131}
132#else
133# define bfin_otp_write NULL
134#endif
135
136static struct file_operations bfin_otp_fops = {
137 .owner = THIS_MODULE,
138 .read = bfin_otp_read,
139 .write = bfin_otp_write,
140};
141
142static struct miscdevice bfin_otp_misc_device = {
143 .minor = MISC_DYNAMIC_MINOR,
144 .name = DRIVER_NAME,
145 .fops = &bfin_otp_fops,
146};
147
148/**
149 * bfin_otp_init - Initialize module
150 *
151 * Registers the device and notifier handler. Actual device
152 * initialization is handled by bfin_otp_open().
153 */
154static int __init bfin_otp_init(void)
155{
156 int ret;
157
158 stampit();
159
160 ret = misc_register(&bfin_otp_misc_device);
161 if (ret) {
162 pr_init(KERN_ERR PFX "unable to register a misc device\n");
163 return ret;
164 }
165
166 pr_init(KERN_INFO PFX "initialized\n");
167
168 return 0;
169}
170
171/**
172 * bfin_otp_exit - Deinitialize module
173 *
174 * Unregisters the device and notifier handler. Actual device
175 * deinitialization is handled by bfin_otp_close().
176 */
177static void __exit bfin_otp_exit(void)
178{
179 stampit();
180
181 misc_deregister(&bfin_otp_misc_device);
182}
183
184module_init(bfin_otp_init);
185module_exit(bfin_otp_exit);
186
187MODULE_AUTHOR("Mike Frysinger <vapier@gentoo.org>");
188MODULE_DESCRIPTION("Blackfin OTP Memory Interface");
189MODULE_LICENSE("GPL");
diff --git a/drivers/char/mwave/tp3780i.c b/drivers/char/mwave/tp3780i.c
index 37fe80df0b91..f282976daaac 100644
--- a/drivers/char/mwave/tp3780i.c
+++ b/drivers/char/mwave/tp3780i.c
@@ -97,24 +97,20 @@ static void EnableSRAM(THINKPAD_BD_DATA * pBDData)
97 97
98static irqreturn_t UartInterrupt(int irq, void *dev_id) 98static irqreturn_t UartInterrupt(int irq, void *dev_id)
99{ 99{
100 int irqno = (int)(unsigned long) dev_id;
101
102 PRINTK_3(TRACE_TP3780I, 100 PRINTK_3(TRACE_TP3780I,
103 "tp3780i::UartInterrupt entry irq %x dev_id %p\n", irqno, dev_id); 101 "tp3780i::UartInterrupt entry irq %x dev_id %p\n", irq, dev_id);
104 return IRQ_HANDLED; 102 return IRQ_HANDLED;
105} 103}
106 104
107static irqreturn_t DspInterrupt(int irq, void *dev_id) 105static irqreturn_t DspInterrupt(int irq, void *dev_id)
108{ 106{
109 int irqno = (int)(unsigned long) dev_id;
110
111 pMWAVE_DEVICE_DATA pDrvData = &mwave_s_mdd; 107 pMWAVE_DEVICE_DATA pDrvData = &mwave_s_mdd;
112 DSP_3780I_CONFIG_SETTINGS *pSettings = &pDrvData->rBDData.rDspSettings; 108 DSP_3780I_CONFIG_SETTINGS *pSettings = &pDrvData->rBDData.rDspSettings;
113 unsigned short usDspBaseIO = pSettings->usDspBaseIO; 109 unsigned short usDspBaseIO = pSettings->usDspBaseIO;
114 unsigned short usIPCSource = 0, usIsolationMask, usPCNum; 110 unsigned short usIPCSource = 0, usIsolationMask, usPCNum;
115 111
116 PRINTK_3(TRACE_TP3780I, 112 PRINTK_3(TRACE_TP3780I,
117 "tp3780i::DspInterrupt entry irq %x dev_id %p\n", irqno, dev_id); 113 "tp3780i::DspInterrupt entry irq %x dev_id %p\n", irq, dev_id);
118 114
119 if (dsp3780I_GetIPCSource(usDspBaseIO, &usIPCSource) == 0) { 115 if (dsp3780I_GetIPCSource(usDspBaseIO, &usIPCSource) == 0) {
120 PRINTK_2(TRACE_TP3780I, 116 PRINTK_2(TRACE_TP3780I,
@@ -365,16 +361,14 @@ int tp3780I_EnableDSP(THINKPAD_BD_DATA * pBDData)
365 pSettings->bPllBypass = TP_CFG_PllBypass; 361 pSettings->bPllBypass = TP_CFG_PllBypass;
366 pSettings->usChipletEnable = TP_CFG_ChipletEnable; 362 pSettings->usChipletEnable = TP_CFG_ChipletEnable;
367 363
368 if (request_irq(pSettings->usUartIrq, &UartInterrupt, 0, "mwave_uart", 364 if (request_irq(pSettings->usUartIrq, &UartInterrupt, 0, "mwave_uart", NULL)) {
369 (void *)(unsigned long) pSettings->usUartIrq)) {
370 PRINTK_ERROR(KERN_ERR_MWAVE "tp3780i::tp3780I_EnableDSP: Error: Could not get UART IRQ %x\n", pSettings->usUartIrq); 365 PRINTK_ERROR(KERN_ERR_MWAVE "tp3780i::tp3780I_EnableDSP: Error: Could not get UART IRQ %x\n", pSettings->usUartIrq);
371 goto exit_cleanup; 366 goto exit_cleanup;
372 } else { /* no conflict just release */ 367 } else { /* no conflict just release */
373 free_irq(pSettings->usUartIrq, NULL); 368 free_irq(pSettings->usUartIrq, NULL);
374 } 369 }
375 370
376 if (request_irq(pSettings->usDspIrq, &DspInterrupt, 0, "mwave_3780i", 371 if (request_irq(pSettings->usDspIrq, &DspInterrupt, 0, "mwave_3780i", NULL)) {
377 (void *)(unsigned long) pSettings->usDspIrq)) {
378 PRINTK_ERROR("tp3780i::tp3780I_EnableDSP: Error: Could not get 3780i IRQ %x\n", pSettings->usDspIrq); 372 PRINTK_ERROR("tp3780i::tp3780I_EnableDSP: Error: Could not get 3780i IRQ %x\n", pSettings->usDspIrq);
379 goto exit_cleanup; 373 goto exit_cleanup;
380 } else { 374 } else {
diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig
index c5263d63aca3..92b683411d5a 100644
--- a/drivers/input/misc/Kconfig
+++ b/drivers/input/misc/Kconfig
@@ -15,6 +15,7 @@ if INPUT_MISC
15config INPUT_PCSPKR 15config INPUT_PCSPKR
16 tristate "PC Speaker support" 16 tristate "PC Speaker support"
17 depends on ALPHA || X86 || MIPS || PPC_PREP || PPC_CHRP || PPC_PSERIES 17 depends on ALPHA || X86 || MIPS || PPC_PREP || PPC_CHRP || PPC_PSERIES
18 depends on SND_PCSP=n
18 help 19 help
19 Say Y here if you want the standard PC Speaker to be used for 20 Say Y here if you want the standard PC Speaker to be used for
20 bells and whistles. 21 bells and whistles.
diff --git a/drivers/media/Kconfig b/drivers/media/Kconfig
index 11950698a2e7..128bb9cd5755 100644
--- a/drivers/media/Kconfig
+++ b/drivers/media/Kconfig
@@ -30,7 +30,7 @@ config VIDEO_V4L2_COMMON
30 depends on (I2C || I2C=n) && VIDEO_DEV 30 depends on (I2C || I2C=n) && VIDEO_DEV
31 default (I2C || I2C=n) && VIDEO_DEV 31 default (I2C || I2C=n) && VIDEO_DEV
32 32
33config VIDEO_V4L1 33config VIDEO_ALLOW_V4L1
34 bool "Enable Video For Linux API 1 (DEPRECATED)" 34 bool "Enable Video For Linux API 1 (DEPRECATED)"
35 depends on VIDEO_DEV && VIDEO_V4L2_COMMON 35 depends on VIDEO_DEV && VIDEO_V4L2_COMMON
36 default VIDEO_DEV && VIDEO_V4L2_COMMON 36 default VIDEO_DEV && VIDEO_V4L2_COMMON
@@ -59,10 +59,15 @@ config VIDEO_V4L1_COMPAT
59 If you are unsure as to whether this is required, answer Y. 59 If you are unsure as to whether this is required, answer Y.
60 60
61config VIDEO_V4L2 61config VIDEO_V4L2
62 bool 62 tristate
63 depends on VIDEO_DEV && VIDEO_V4L2_COMMON 63 depends on VIDEO_DEV && VIDEO_V4L2_COMMON
64 default VIDEO_DEV && VIDEO_V4L2_COMMON 64 default VIDEO_DEV && VIDEO_V4L2_COMMON
65 65
66config VIDEO_V4L1
67 tristate
68 depends on VIDEO_DEV && VIDEO_V4L2_COMMON && VIDEO_ALLOW_V4L1
69 default VIDEO_DEV && VIDEO_V4L2_COMMON && VIDEO_ALLOW_V4L1
70
66source "drivers/media/video/Kconfig" 71source "drivers/media/video/Kconfig"
67 72
68source "drivers/media/radio/Kconfig" 73source "drivers/media/radio/Kconfig"
@@ -155,7 +160,7 @@ config VIDEOBUF_GEN
155 tristate 160 tristate
156 161
157config VIDEOBUF_DMA_SG 162config VIDEOBUF_DMA_SG
158 depends on PCI 163 depends on HAS_DMA
159 select VIDEOBUF_GEN 164 select VIDEOBUF_GEN
160 tristate 165 tristate
161 166
diff --git a/drivers/media/common/ir-functions.c b/drivers/media/common/ir-functions.c
index bb2a027b9483..266505207925 100644
--- a/drivers/media/common/ir-functions.c
+++ b/drivers/media/common/ir-functions.c
@@ -34,7 +34,7 @@ static int repeat = 1;
34module_param(repeat, int, 0444); 34module_param(repeat, int, 0444);
35MODULE_PARM_DESC(repeat,"auto-repeat for IR keys (default: on)"); 35MODULE_PARM_DESC(repeat,"auto-repeat for IR keys (default: on)");
36 36
37static int debug = 0; /* debug level (0,1,2) */ 37static int debug; /* debug level (0,1,2) */
38module_param(debug, int, 0644); 38module_param(debug, int, 0644);
39 39
40#define dprintk(level, fmt, arg...) if (debug >= level) \ 40#define dprintk(level, fmt, arg...) if (debug >= level) \
diff --git a/drivers/media/common/ir-keymaps.c b/drivers/media/common/ir-keymaps.c
index 2ab5a120470d..a3485817e46c 100644
--- a/drivers/media/common/ir-keymaps.c
+++ b/drivers/media/common/ir-keymaps.c
@@ -212,6 +212,51 @@ IR_KEYTAB_TYPE ir_codes_pixelview[IR_KEYTAB_SIZE] = {
212 212
213EXPORT_SYMBOL_GPL(ir_codes_pixelview); 213EXPORT_SYMBOL_GPL(ir_codes_pixelview);
214 214
215/*
216 Mauro Carvalho Chehab <mchehab@infradead.org>
217 present on PV MPEG 8000GT
218 */
219IR_KEYTAB_TYPE ir_codes_pixelview_new[IR_KEYTAB_SIZE] = {
220 [0x3c] = KEY_PAUSE, /* Timeshift */
221 [0x12] = KEY_POWER,
222
223 [0x3d] = KEY_1,
224 [0x38] = KEY_2,
225 [0x18] = KEY_3,
226 [0x35] = KEY_4,
227 [0x39] = KEY_5,
228 [0x15] = KEY_6,
229 [0x36] = KEY_7,
230 [0x3a] = KEY_8,
231 [0x1e] = KEY_9,
232 [0x3e] = KEY_0,
233
234 [0x1c] = KEY_AGAIN, /* LOOP */
235 [0x3f] = KEY_MEDIA, /* Source */
236 [0x1f] = KEY_LAST, /* +100 */
237 [0x1b] = KEY_MUTE,
238
239 [0x17] = KEY_CHANNELDOWN,
240 [0x16] = KEY_CHANNELUP,
241 [0x10] = KEY_VOLUMEUP,
242 [0x14] = KEY_VOLUMEDOWN,
243 [0x13] = KEY_ZOOM,
244
245 [0x19] = KEY_SHUFFLE, /* SNAPSHOT */
246 [0x1a] = KEY_SEARCH, /* scan */
247
248 [0x37] = KEY_REWIND, /* << */
249 [0x32] = KEY_RECORD, /* o (red) */
250 [0x33] = KEY_FORWARD, /* >> */
251 [0x11] = KEY_STOP, /* square */
252 [0x3b] = KEY_PLAY, /* > */
253 [0x30] = KEY_PLAYPAUSE, /* || */
254
255 [0x31] = KEY_TV,
256 [0x34] = KEY_RADIO,
257};
258EXPORT_SYMBOL_GPL(ir_codes_pixelview_new);
259
215IR_KEYTAB_TYPE ir_codes_nebula[IR_KEYTAB_SIZE] = { 260IR_KEYTAB_TYPE ir_codes_nebula[IR_KEYTAB_SIZE] = {
216 [ 0x00 ] = KEY_0, 261 [ 0x00 ] = KEY_0,
217 [ 0x01 ] = KEY_1, 262 [ 0x01 ] = KEY_1,
@@ -726,7 +771,11 @@ IR_KEYTAB_TYPE ir_codes_flyvideo[IR_KEYTAB_SIZE] = {
726 [ 0x12 ] = KEY_CHANNELUP, // Channel + 771 [ 0x12 ] = KEY_CHANNELUP, // Channel +
727 [ 0x13 ] = KEY_CHANNELDOWN, // Channel - 772 [ 0x13 ] = KEY_CHANNELDOWN, // Channel -
728 [ 0x06 ] = KEY_AGAIN, // Recall 773 [ 0x06 ] = KEY_AGAIN, // Recall
729 [ 0x10 ] = KEY_ENTER, // Enter 774 [ 0x10 ] = KEY_ENTER, // Enter
775
776 [ 0x19 ] = KEY_BACK, // Rewind ( <<< )
777 [ 0x1f ] = KEY_FORWARD, // Forward ( >>> )
778 [ 0x0a ] = KEY_ANGLE, // (no label, may be used as the PAUSE button)
730}; 779};
731 780
732EXPORT_SYMBOL_GPL(ir_codes_flyvideo); 781EXPORT_SYMBOL_GPL(ir_codes_flyvideo);
@@ -1157,7 +1206,8 @@ EXPORT_SYMBOL_GPL(ir_codes_purpletv);
1157 1206
1158/* Mapping for the 28 key remote control as seen at 1207/* Mapping for the 28 key remote control as seen at
1159 http://www.sednacomputer.com/photo/cardbus-tv.jpg 1208 http://www.sednacomputer.com/photo/cardbus-tv.jpg
1160 Pavel Mihaylov <bin@bash.info> */ 1209 Pavel Mihaylov <bin@bash.info>
1210 Also for the remote bundled with Kozumi KTV-01C card */
1161IR_KEYTAB_TYPE ir_codes_pctv_sedna[IR_KEYTAB_SIZE] = { 1211IR_KEYTAB_TYPE ir_codes_pctv_sedna[IR_KEYTAB_SIZE] = {
1162 [ 0x00 ] = KEY_0, 1212 [ 0x00 ] = KEY_0,
1163 [ 0x01 ] = KEY_1, 1213 [ 0x01 ] = KEY_1,
@@ -1188,6 +1238,11 @@ IR_KEYTAB_TYPE ir_codes_pctv_sedna[IR_KEYTAB_SIZE] = {
1188 [ 0x1c ] = KEY_RADIO, /* FM Radio */ 1238 [ 0x1c ] = KEY_RADIO, /* FM Radio */
1189 [ 0x1d ] = KEY_RECORD, 1239 [ 0x1d ] = KEY_RECORD,
1190 [ 0x1e ] = KEY_PAUSE, 1240 [ 0x1e ] = KEY_PAUSE,
1241 /* additional codes for Kozumi's remote */
1242 [0x14] = KEY_INFO, /* OSD */
1243 [0x16] = KEY_OK, /* OK */
1244 [0x17] = KEY_DIGITS, /* Plus */
1245 [0x1f] = KEY_PLAY, /* Play */
1191}; 1246};
1192 1247
1193EXPORT_SYMBOL_GPL(ir_codes_pctv_sedna); 1248EXPORT_SYMBOL_GPL(ir_codes_pctv_sedna);
@@ -1988,6 +2043,76 @@ IR_KEYTAB_TYPE ir_codes_behold[IR_KEYTAB_SIZE] = {
1988 2043
1989EXPORT_SYMBOL_GPL(ir_codes_behold); 2044EXPORT_SYMBOL_GPL(ir_codes_behold);
1990 2045
2046/* Beholder Intl. Ltd. 2008
2047 * Dmitry Belimov d.belimov@google.com
2048 * Keytable is used by BeholdTV Columbus
2049 * The "ascii-art picture" below (in comments, first row
2050 * is the keycode in hex, and subsequent row(s) shows
2051 * the button labels (several variants when appropriate)
2052 * helps to descide which keycodes to assign to the buttons.
2053 */
2054IR_KEYTAB_TYPE ir_codes_behold_columbus[IR_KEYTAB_SIZE] = {
2055
2056 /* 0x13 0x11 0x1C 0x12 *
2057 * Mute Source TV/FM Power *
2058 * */
2059
2060 [0x13] = KEY_MUTE,
2061 [0x11] = KEY_PROPS,
2062 [0x1C] = KEY_TUNER, /* KEY_TV/KEY_RADIO */
2063 [0x12] = KEY_POWER,
2064
2065 /* 0x01 0x02 0x03 0x0D *
2066 * 1 2 3 Stereo *
2067 * *
2068 * 0x04 0x05 0x06 0x19 *
2069 * 4 5 6 Snapshot *
2070 * *
2071 * 0x07 0x08 0x09 0x10 *
2072 * 7 8 9 Zoom *
2073 * */
2074 [0x01] = KEY_1,
2075 [0x02] = KEY_2,
2076 [0x03] = KEY_3,
2077 [0x0D] = KEY_SETUP, /* Setup key */
2078 [0x04] = KEY_4,
2079 [0x05] = KEY_5,
2080 [0x06] = KEY_6,
2081 [0x19] = KEY_BOOKMARKS, /* Snapshot key */
2082 [0x07] = KEY_7,
2083 [0x08] = KEY_8,
2084 [0x09] = KEY_9,
2085 [0x10] = KEY_ZOOM,
2086
2087 /* 0x0A 0x00 0x0B 0x0C *
2088 * RECALL 0 ChannelUp VolumeUp *
2089 * */
2090 [0x0A] = KEY_AGAIN,
2091 [0x00] = KEY_0,
2092 [0x0B] = KEY_CHANNELUP,
2093 [0x0C] = KEY_VOLUMEUP,
2094
2095 /* 0x1B 0x1D 0x15 0x18 *
2096 * Timeshift Record ChannelDown VolumeDown *
2097 * */
2098
2099 [0x1B] = KEY_REWIND,
2100 [0x1D] = KEY_RECORD,
2101 [0x15] = KEY_CHANNELDOWN,
2102 [0x18] = KEY_VOLUMEDOWN,
2103
2104 /* 0x0E 0x1E 0x0F 0x1A *
2105 * Stop Pause Previouse Next *
2106 * */
2107
2108 [0x0E] = KEY_STOP,
2109 [0x1E] = KEY_PAUSE,
2110 [0x0F] = KEY_PREVIOUS,
2111 [0x1A] = KEY_NEXT,
2112
2113};
2114EXPORT_SYMBOL_GPL(ir_codes_behold_columbus);
2115
1991/* 2116/*
1992 * Remote control for the Genius TVGO A11MCE 2117 * Remote control for the Genius TVGO A11MCE
1993 * Adrian Pardini <pardo.bsso@gmail.com> 2118 * Adrian Pardini <pardo.bsso@gmail.com>
@@ -2033,3 +2158,46 @@ IR_KEYTAB_TYPE ir_codes_genius_tvgo_a11mce[IR_KEYTAB_SIZE] = {
2033 [0x50] = KEY_BLUE, 2158 [0x50] = KEY_BLUE,
2034}; 2159};
2035EXPORT_SYMBOL_GPL(ir_codes_genius_tvgo_a11mce); 2160EXPORT_SYMBOL_GPL(ir_codes_genius_tvgo_a11mce);
2161
2162/*
2163 * Remote control for Powercolor Real Angel 330
2164 * Daniel Fraga <fragabr@gmail.com>
2165 */
2166IR_KEYTAB_TYPE ir_codes_powercolor_real_angel[IR_KEYTAB_SIZE] = {
2167 [0x38] = KEY_SWITCHVIDEOMODE, /* switch inputs */
2168 [0x0c] = KEY_MEDIA, /* Turn ON/OFF App */
2169 [0x00] = KEY_0,
2170 [0x01] = KEY_1,
2171 [0x02] = KEY_2,
2172 [0x03] = KEY_3,
2173 [0x04] = KEY_4,
2174 [0x05] = KEY_5,
2175 [0x06] = KEY_6,
2176 [0x07] = KEY_7,
2177 [0x08] = KEY_8,
2178 [0x09] = KEY_9,
2179 [0x0a] = KEY_DIGITS, /* single, double, tripple digit */
2180 [0x29] = KEY_PREVIOUS, /* previous channel */
2181 [0x12] = KEY_BRIGHTNESSUP,
2182 [0x13] = KEY_BRIGHTNESSDOWN,
2183 [0x2b] = KEY_MODE, /* stereo/mono */
2184 [0x2c] = KEY_TEXT, /* teletext */
2185 [0x20] = KEY_UP, /* channel up */
2186 [0x21] = KEY_DOWN, /* channel down */
2187 [0x10] = KEY_RIGHT, /* volume up */
2188 [0x11] = KEY_LEFT, /* volume down */
2189 [0x0d] = KEY_MUTE,
2190 [0x1f] = KEY_RECORD,
2191 [0x17] = KEY_PLAY,
2192 [0x16] = KEY_PAUSE,
2193 [0x0b] = KEY_STOP,
2194 [0x27] = KEY_FASTFORWARD,
2195 [0x26] = KEY_REWIND,
2196 [0x1e] = KEY_SEARCH, /* autoscan */
2197 [0x0e] = KEY_SHUFFLE, /* snapshot */
2198 [0x2d] = KEY_SETUP,
2199 [0x0f] = KEY_SCREEN, /* full screen */
2200 [0x14] = KEY_RADIO, /* FM radio */
2201 [0x25] = KEY_POWER, /* power */
2202};
2203EXPORT_SYMBOL_GPL(ir_codes_powercolor_real_angel);
diff --git a/drivers/media/common/saa7146_core.c b/drivers/media/common/saa7146_core.c
index 7707b8c7394b..89c7660b85d6 100644
--- a/drivers/media/common/saa7146_core.c
+++ b/drivers/media/common/saa7146_core.c
@@ -74,7 +74,7 @@ static inline int saa7146_wait_for_debi_done_sleep(struct saa7146_dev *dev,
74 if (err) { 74 if (err) {
75 printk(KERN_ERR "%s: %s timed out while waiting for " 75 printk(KERN_ERR "%s: %s timed out while waiting for "
76 "registers getting programmed\n", 76 "registers getting programmed\n",
77 dev->name, __FUNCTION__); 77 dev->name, __func__);
78 return -ETIMEDOUT; 78 return -ETIMEDOUT;
79 } 79 }
80 msleep(1); 80 msleep(1);
@@ -89,7 +89,7 @@ static inline int saa7146_wait_for_debi_done_sleep(struct saa7146_dev *dev,
89 saa7146_read(dev, MC2); 89 saa7146_read(dev, MC2);
90 if (err) { 90 if (err) {
91 DEB_S(("%s: %s timed out while waiting for transfer " 91 DEB_S(("%s: %s timed out while waiting for transfer "
92 "completion\n", dev->name, __FUNCTION__)); 92 "completion\n", dev->name, __func__));
93 return -ETIMEDOUT; 93 return -ETIMEDOUT;
94 } 94 }
95 msleep(1); 95 msleep(1);
@@ -111,7 +111,7 @@ static inline int saa7146_wait_for_debi_done_busyloop(struct saa7146_dev *dev,
111 if (!loops--) { 111 if (!loops--) {
112 printk(KERN_ERR "%s: %s timed out while waiting for " 112 printk(KERN_ERR "%s: %s timed out while waiting for "
113 "registers getting programmed\n", 113 "registers getting programmed\n",
114 dev->name, __FUNCTION__); 114 dev->name, __func__);
115 return -ETIMEDOUT; 115 return -ETIMEDOUT;
116 } 116 }
117 udelay(1); 117 udelay(1);
@@ -125,7 +125,7 @@ static inline int saa7146_wait_for_debi_done_busyloop(struct saa7146_dev *dev,
125 saa7146_read(dev, MC2); 125 saa7146_read(dev, MC2);
126 if (!loops--) { 126 if (!loops--) {
127 DEB_S(("%s: %s timed out while waiting for transfer " 127 DEB_S(("%s: %s timed out while waiting for transfer "
128 "completion\n", dev->name, __FUNCTION__)); 128 "completion\n", dev->name, __func__));
129 return -ETIMEDOUT; 129 return -ETIMEDOUT;
130 } 130 }
131 udelay(5); 131 udelay(5);
diff --git a/drivers/media/common/saa7146_i2c.c b/drivers/media/common/saa7146_i2c.c
index 7e7689afae62..35b01ec40a51 100644
--- a/drivers/media/common/saa7146_i2c.c
+++ b/drivers/media/common/saa7146_i2c.c
@@ -203,7 +203,7 @@ static int saa7146_i2c_writeout(struct saa7146_dev *dev, u32* dword, int short_d
203 return -ERESTARTSYS; 203 return -ERESTARTSYS;
204 204
205 printk(KERN_WARNING "%s %s [irq]: timed out waiting for end of xfer\n", 205 printk(KERN_WARNING "%s %s [irq]: timed out waiting for end of xfer\n",
206 dev->name, __FUNCTION__); 206 dev->name, __func__);
207 return -EIO; 207 return -EIO;
208 } 208 }
209 status = saa7146_read(dev, I2C_STATUS); 209 status = saa7146_read(dev, I2C_STATUS);
@@ -221,7 +221,7 @@ static int saa7146_i2c_writeout(struct saa7146_dev *dev, u32* dword, int short_d
221 } 221 }
222 if (time_after(jiffies,timeout)) { 222 if (time_after(jiffies,timeout)) {
223 printk(KERN_WARNING "%s %s: timed out waiting for MC2\n", 223 printk(KERN_WARNING "%s %s: timed out waiting for MC2\n",
224 dev->name, __FUNCTION__); 224 dev->name, __func__);
225 return -EIO; 225 return -EIO;
226 } 226 }
227 } 227 }
@@ -238,7 +238,7 @@ static int saa7146_i2c_writeout(struct saa7146_dev *dev, u32* dword, int short_d
238 * (no answer from nonexisistant device...) 238 * (no answer from nonexisistant device...)
239 */ 239 */
240 printk(KERN_WARNING "%s %s [poll]: timed out waiting for end of xfer\n", 240 printk(KERN_WARNING "%s %s [poll]: timed out waiting for end of xfer\n",
241 dev->name, __FUNCTION__); 241 dev->name, __func__);
242 return -EIO; 242 return -EIO;
243 } 243 }
244 if (++trial < 50 && short_delay) 244 if (++trial < 50 && short_delay)
diff --git a/drivers/media/common/saa7146_vbi.c b/drivers/media/common/saa7146_vbi.c
index bfbd5a841ebf..74e2b56ecb5b 100644
--- a/drivers/media/common/saa7146_vbi.c
+++ b/drivers/media/common/saa7146_vbi.c
@@ -407,8 +407,8 @@ static int vbi_open(struct saa7146_dev *dev, struct file *file)
407 fh->vbi_fmt.start[1] = 312; 407 fh->vbi_fmt.start[1] = 312;
408 fh->vbi_fmt.count[1] = 16; 408 fh->vbi_fmt.count[1] = 16;
409 409
410 videobuf_queue_pci_init(&fh->vbi_q, &vbi_qops, 410 videobuf_queue_sg_init(&fh->vbi_q, &vbi_qops,
411 dev->pci, &dev->slock, 411 &dev->pci->dev, &dev->slock,
412 V4L2_BUF_TYPE_VBI_CAPTURE, 412 V4L2_BUF_TYPE_VBI_CAPTURE,
413 V4L2_FIELD_SEQ_TB, // FIXME: does this really work? 413 V4L2_FIELD_SEQ_TB, // FIXME: does this really work?
414 sizeof(struct saa7146_buf), 414 sizeof(struct saa7146_buf),
diff --git a/drivers/media/common/saa7146_video.c b/drivers/media/common/saa7146_video.c
index 66fdbd0e6a6d..3cbc6ebbe649 100644
--- a/drivers/media/common/saa7146_video.c
+++ b/drivers/media/common/saa7146_video.c
@@ -1410,8 +1410,8 @@ static int video_open(struct saa7146_dev *dev, struct file *file)
1410 sfmt = format_by_fourcc(dev,fh->video_fmt.pixelformat); 1410 sfmt = format_by_fourcc(dev,fh->video_fmt.pixelformat);
1411 fh->video_fmt.sizeimage = (fh->video_fmt.width * fh->video_fmt.height * sfmt->depth)/8; 1411 fh->video_fmt.sizeimage = (fh->video_fmt.width * fh->video_fmt.height * sfmt->depth)/8;
1412 1412
1413 videobuf_queue_pci_init(&fh->video_q, &video_qops, 1413 videobuf_queue_sg_init(&fh->video_q, &video_qops,
1414 dev->pci, &dev->slock, 1414 &dev->pci->dev, &dev->slock,
1415 V4L2_BUF_TYPE_VIDEO_CAPTURE, 1415 V4L2_BUF_TYPE_VIDEO_CAPTURE,
1416 V4L2_FIELD_INTERLACED, 1416 V4L2_FIELD_INTERLACED,
1417 sizeof(struct saa7146_buf), 1417 sizeof(struct saa7146_buf),
diff --git a/drivers/media/dvb/b2c2/Kconfig b/drivers/media/dvb/b2c2/Kconfig
index 3197aeb61d1f..6ec5afba1ca7 100644
--- a/drivers/media/dvb/b2c2/Kconfig
+++ b/drivers/media/dvb/b2c2/Kconfig
@@ -9,6 +9,11 @@ config DVB_B2C2_FLEXCOP
9 select DVB_STV0297 if !DVB_FE_CUSTOMISE 9 select DVB_STV0297 if !DVB_FE_CUSTOMISE
10 select DVB_BCM3510 if !DVB_FE_CUSTOMISE 10 select DVB_BCM3510 if !DVB_FE_CUSTOMISE
11 select DVB_LGDT330X if !DVB_FE_CUSTOMISE 11 select DVB_LGDT330X if !DVB_FE_CUSTOMISE
12 select TUNER_SIMPLE if !DVB_FE_CUSTOMISE
13 select DVB_S5H1420 if !DVB_FE_CUSTOMISE
14 select DVB_TUNER_ITD1000 if !DVB_FE_CUSTOMISE
15 select DVB_ISL6421 if !DVB_FE_CUSTOMISE
16 select DVB_CX24123 if !DVB_FE_CUSTOMISE
12 help 17 help
13 Support for the digital TV receiver chip made by B2C2 Inc. included in 18 Support for the digital TV receiver chip made by B2C2 Inc. included in
14 Technisats PCI cards and USB boxes. 19 Technisats PCI cards and USB boxes.
diff --git a/drivers/media/dvb/b2c2/Makefile b/drivers/media/dvb/b2c2/Makefile
index e97ff60a1eff..870e2848c296 100644
--- a/drivers/media/dvb/b2c2/Makefile
+++ b/drivers/media/dvb/b2c2/Makefile
@@ -2,6 +2,7 @@ b2c2-flexcop-objs = flexcop.o flexcop-fe-tuner.o flexcop-i2c.o \
2 flexcop-sram.o flexcop-eeprom.o flexcop-misc.o flexcop-hw-filter.o 2 flexcop-sram.o flexcop-eeprom.o flexcop-misc.o flexcop-hw-filter.o
3obj-$(CONFIG_DVB_B2C2_FLEXCOP) += b2c2-flexcop.o 3obj-$(CONFIG_DVB_B2C2_FLEXCOP) += b2c2-flexcop.o
4 4
5
5ifneq ($(CONFIG_DVB_B2C2_FLEXCOP_PCI),) 6ifneq ($(CONFIG_DVB_B2C2_FLEXCOP_PCI),)
6b2c2-flexcop-objs += flexcop-dma.o 7b2c2-flexcop-objs += flexcop-dma.o
7endif 8endif
@@ -13,3 +14,4 @@ b2c2-flexcop-usb-objs = flexcop-usb.o
13obj-$(CONFIG_DVB_B2C2_FLEXCOP_USB) += b2c2-flexcop-usb.o 14obj-$(CONFIG_DVB_B2C2_FLEXCOP_USB) += b2c2-flexcop-usb.o
14 15
15EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/ 16EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
17EXTRA_CFLAGS += -Idrivers/media/video/
diff --git a/drivers/media/dvb/b2c2/flexcop-common.h b/drivers/media/dvb/b2c2/flexcop-common.h
index 5a6c4fe249e7..8ce06336e76f 100644
--- a/drivers/media/dvb/b2c2/flexcop-common.h
+++ b/drivers/media/dvb/b2c2/flexcop-common.h
@@ -44,6 +44,14 @@ struct flexcop_dma {
44 u32 size; /* size of each address in bytes */ 44 u32 size; /* size of each address in bytes */
45}; 45};
46 46
47struct flexcop_i2c_adapter {
48 struct flexcop_device *fc;
49 struct i2c_adapter i2c_adap;
50
51 u8 no_base_addr;
52 flexcop_i2c_port_t port;
53};
54
47/* Control structure for data definitions that are common to 55/* Control structure for data definitions that are common to
48 * the B2C2-based PCI and USB devices. 56 * the B2C2-based PCI and USB devices.
49 */ 57 */
@@ -72,7 +80,7 @@ struct flexcop_device {
72 struct dmx_frontend mem_frontend; 80 struct dmx_frontend mem_frontend;
73 int (*fe_sleep) (struct dvb_frontend *); 81 int (*fe_sleep) (struct dvb_frontend *);
74 82
75 struct i2c_adapter i2c_adap; 83 struct flexcop_i2c_adapter fc_i2c_adap[3];
76 struct mutex i2c_mutex; 84 struct mutex i2c_mutex;
77 struct module *owner; 85 struct module *owner;
78 86
@@ -87,7 +95,8 @@ struct flexcop_device {
87 int (*write_ibi_reg) (struct flexcop_device *, flexcop_ibi_register, flexcop_ibi_value); 95 int (*write_ibi_reg) (struct flexcop_device *, flexcop_ibi_register, flexcop_ibi_value);
88 96
89 97
90 int (*i2c_request) (struct flexcop_device*, flexcop_access_op_t, flexcop_i2c_port_t, u8 chipaddr, u8 addr, u8 *buf, u16 len); 98 int (*i2c_request) (struct flexcop_i2c_adapter*,
99 flexcop_access_op_t, u8 chipaddr, u8 addr, u8 *buf, u16 len);
91 int (*stream_control) (struct flexcop_device*, int); 100 int (*stream_control) (struct flexcop_device*, int);
92 101
93 int (*get_mac_addr) (struct flexcop_device *fc, int extended); 102 int (*get_mac_addr) (struct flexcop_device *fc, int extended);
@@ -128,8 +137,8 @@ int flexcop_eeprom_check_mac_addr(struct flexcop_device *fc, int extended);
128 * one. We have it in flexcop-i2c.c, because it is going via the actual 137 * one. We have it in flexcop-i2c.c, because it is going via the actual
129 * I2C-channel of the flexcop. 138 * I2C-channel of the flexcop.
130 */ 139 */
131int flexcop_i2c_request(struct flexcop_device*, flexcop_access_op_t, 140int flexcop_i2c_request(struct flexcop_i2c_adapter*, flexcop_access_op_t,
132 flexcop_i2c_port_t, u8 chipaddr, u8 addr, u8 *buf, u16 len); 141 u8 chipaddr, u8 addr, u8 *buf, u16 len);
133 142
134/* from flexcop-sram.c */ 143/* from flexcop-sram.c */
135int flexcop_sram_set_dest(struct flexcop_device *fc, flexcop_sram_dest_t dest, flexcop_sram_dest_target_t target); 144int flexcop_sram_set_dest(struct flexcop_device *fc, flexcop_sram_dest_t dest, flexcop_sram_dest_target_t target);
diff --git a/drivers/media/dvb/b2c2/flexcop-dma.c b/drivers/media/dvb/b2c2/flexcop-dma.c
index 6f592bc32d22..a91ed28f03a4 100644
--- a/drivers/media/dvb/b2c2/flexcop-dma.c
+++ b/drivers/media/dvb/b2c2/flexcop-dma.c
@@ -112,7 +112,7 @@ static int flexcop_dma_remap(struct flexcop_device *fc,
112{ 112{
113 flexcop_ibi_register r = (dma_idx & FC_DMA_1) ? dma1_00c : dma2_01c; 113 flexcop_ibi_register r = (dma_idx & FC_DMA_1) ? dma1_00c : dma2_01c;
114 flexcop_ibi_value v = fc->read_ibi_reg(fc,r); 114 flexcop_ibi_value v = fc->read_ibi_reg(fc,r);
115 deb_info("%s\n",__FUNCTION__); 115 deb_info("%s\n",__func__);
116 v.dma_0xc.remap_enable = onoff; 116 v.dma_0xc.remap_enable = onoff;
117 fc->write_ibi_reg(fc,r,v); 117 fc->write_ibi_reg(fc,r,v);
118 return 0; 118 return 0;
@@ -162,7 +162,7 @@ int flexcop_dma_config_timer(struct flexcop_device *fc,
162 162
163 flexcop_dma_remap(fc,dma_idx,0); 163 flexcop_dma_remap(fc,dma_idx,0);
164 164
165 deb_info("%s\n",__FUNCTION__); 165 deb_info("%s\n",__func__);
166 v.dma_0x4_write.dmatimer = cycles; 166 v.dma_0x4_write.dmatimer = cycles;
167 fc->write_ibi_reg(fc,r,v); 167 fc->write_ibi_reg(fc,r,v);
168 return 0; 168 return 0;
diff --git a/drivers/media/dvb/b2c2/flexcop-eeprom.c b/drivers/media/dvb/b2c2/flexcop-eeprom.c
index bbcf070a178d..8a8ae8a3e6ba 100644
--- a/drivers/media/dvb/b2c2/flexcop-eeprom.c
+++ b/drivers/media/dvb/b2c2/flexcop-eeprom.c
@@ -114,15 +114,18 @@ static int flexcop_eeprom_request(struct flexcop_device *fc, flexcop_access_op_t
114{ 114{
115 int i,ret = 0; 115 int i,ret = 0;
116 u8 chipaddr = 0x50 | ((addr >> 8) & 3); 116 u8 chipaddr = 0x50 | ((addr >> 8) & 3);
117 for (i = 0; i < retries; i++) 117 for (i = 0; i < retries; i++) {
118 if ((ret = fc->i2c_request(fc,op,FC_I2C_PORT_EEPROM,chipaddr,addr & 0xff,buf,len)) == 0) 118 ret = fc->i2c_request(&fc->fc_i2c_adap[1], op, chipaddr,
119 addr & 0xff, buf, len);
120 if (ret == 0)
119 break; 121 break;
122 }
120 return ret; 123 return ret;
121} 124}
122 125
123static int flexcop_eeprom_lrc_read(struct flexcop_device *fc, u16 addr, u8 *buf, u16 len, int retries) 126static int flexcop_eeprom_lrc_read(struct flexcop_device *fc, u16 addr, u8 *buf, u16 len, int retries)
124{ 127{
125 int ret = flexcop_eeprom_request(fc,FC_READ,addr,buf,len,retries); 128 int ret = flexcop_eeprom_request(fc, FC_READ, addr, buf, len, retries);
126 if (ret == 0) 129 if (ret == 0)
127 if (calc_lrc(buf, len - 1) != buf[len - 1]) 130 if (calc_lrc(buf, len - 1) != buf[len - 1])
128 ret = -EINVAL; 131 ret = -EINVAL;
diff --git a/drivers/media/dvb/b2c2/flexcop-fe-tuner.c b/drivers/media/dvb/b2c2/flexcop-fe-tuner.c
index 0378fd646591..7b0ea3bdfafb 100644
--- a/drivers/media/dvb/b2c2/flexcop-fe-tuner.c
+++ b/drivers/media/dvb/b2c2/flexcop-fe-tuner.c
@@ -5,6 +5,8 @@
5 * 5 *
6 * see flexcop.c for copyright information. 6 * see flexcop.c for copyright information.
7 */ 7 */
8#include <media/tuner.h>
9
8#include "flexcop.h" 10#include "flexcop.h"
9 11
10#include "stv0299.h" 12#include "stv0299.h"
@@ -15,6 +17,15 @@
15#include "mt312.h" 17#include "mt312.h"
16#include "lgdt330x.h" 18#include "lgdt330x.h"
17#include "dvb-pll.h" 19#include "dvb-pll.h"
20#include "tuner-simple.h"
21
22#include "s5h1420.h"
23#include "itd1000.h"
24
25#include "cx24123.h"
26#include "cx24113.h"
27
28#include "isl6421.h"
18 29
19/* lnb control */ 30/* lnb control */
20 31
@@ -180,13 +191,13 @@ static int samsung_tbmu24112_tuner_set_params(struct dvb_frontend* fe, struct dv
180 buf[2] = 0x84; /* 0xC4 */ 191 buf[2] = 0x84; /* 0xC4 */
181 buf[3] = 0x08; 192 buf[3] = 0x08;
182 193
183 if (params->frequency < 1500000) buf[3] |= 0x10; 194 if (params->frequency < 1500000)
195 buf[3] |= 0x10;
184 196
185 if (fe->ops.i2c_gate_ctrl) 197 if (fe->ops.i2c_gate_ctrl)
186 fe->ops.i2c_gate_ctrl(fe, 1); 198 fe->ops.i2c_gate_ctrl(fe, 1);
187 if (i2c_transfer(&fc->i2c_adap, &msg, 1) != 1) { 199 if (i2c_transfer(&fc->fc_i2c_adap[0].i2c_adap, &msg, 1) != 1)
188 return -EIO; 200 return -EIO;
189 }
190 return 0; 201 return 0;
191} 202}
192 203
@@ -241,7 +252,7 @@ static struct stv0299_config samsung_tbmu24112_config = {
241 .mclk = 88000000UL, 252 .mclk = 88000000UL,
242 .invert = 0, 253 .invert = 0,
243 .skip_reinit = 0, 254 .skip_reinit = 0,
244 .lock_output = STV0229_LOCKOUTPUT_LK, 255 .lock_output = STV0299_LOCKOUTPUT_LK,
245 .volt13_op0_op1 = STV0299_VOLT13_OP1, 256 .volt13_op0_op1 = STV0299_VOLT13_OP1,
246 .min_delay_ms = 100, 257 .min_delay_ms = 100,
247 .set_symbol_rate = samsung_tbmu24112_set_symbol_rate, 258 .set_symbol_rate = samsung_tbmu24112_set_symbol_rate,
@@ -337,7 +348,7 @@ static int skystar23_samsung_tbdu18132_tuner_set_params(struct dvb_frontend* fe,
337 348
338 if (fe->ops.i2c_gate_ctrl) 349 if (fe->ops.i2c_gate_ctrl)
339 fe->ops.i2c_gate_ctrl(fe, 1); 350 fe->ops.i2c_gate_ctrl(fe, 1);
340 if (i2c_transfer(&fc->i2c_adap, &msg, 1) != 1) 351 if (i2c_transfer(&fc->fc_i2c_adap[0].i2c_adap, &msg, 1) != 1)
341 return -EIO; 352 return -EIO;
342 return 0; 353 return 0;
343} 354}
@@ -386,10 +397,11 @@ static int alps_tdee4_stv0297_tuner_set_params(struct dvb_frontend* fe,
386 if (fe->ops.i2c_gate_ctrl) 397 if (fe->ops.i2c_gate_ctrl)
387 fe->ops.i2c_gate_ctrl(fe, 0); 398 fe->ops.i2c_gate_ctrl(fe, 0);
388 deb_tuner("tuner buffer for %d Hz: %x %x %x %x\n",fep->frequency, buf[0],buf[1],buf[2],buf[3]); 399 deb_tuner("tuner buffer for %d Hz: %x %x %x %x\n",fep->frequency, buf[0],buf[1],buf[2],buf[3]);
389 ret = fc->i2c_request(fc, FC_WRITE, FC_I2C_PORT_TUNER, 0x61, buf[0], &buf[1], 3); 400 ret = fc->i2c_request(&fc->fc_i2c_adap[2],
401 FC_WRITE, 0x61, buf[0], &buf[1], 3);
390 deb_tuner("tuner write returned: %d\n",ret); 402 deb_tuner("tuner write returned: %d\n",ret);
391 403
392 return 0; 404 return ret;
393} 405}
394 406
395static u8 alps_tdee4_stv0297_inittab[] = { 407static u8 alps_tdee4_stv0297_inittab[] = {
@@ -472,56 +484,159 @@ static struct stv0297_config alps_tdee4_stv0297_config = {
472// .pll_set = alps_tdee4_stv0297_pll_set, 484// .pll_set = alps_tdee4_stv0297_pll_set,
473}; 485};
474 486
487
488/* SkyStar2 rev2.7 (a/u) */
489static struct s5h1420_config skystar2_rev2_7_s5h1420_config = {
490 .demod_address = 0x53,
491 .invert = 1,
492 .repeated_start_workaround = 1,
493};
494
495static struct itd1000_config skystar2_rev2_7_itd1000_config = {
496 .i2c_address = 0x61,
497};
498
499/* SkyStar2 rev2.8 */
500static struct cx24123_config skystar2_rev2_8_cx24123_config = {
501 .demod_address = 0x55,
502 .dont_use_pll = 1,
503 .agc_callback = cx24113_agc_callback,
504};
505
506static const struct cx24113_config skystar2_rev2_8_cx24113_config = {
507 .i2c_addr = 0x54,
508 .xtal_khz = 10111,
509};
510
475/* try to figure out the frontend, each card/box can have on of the following list */ 511/* try to figure out the frontend, each card/box can have on of the following list */
476int flexcop_frontend_init(struct flexcop_device *fc) 512int flexcop_frontend_init(struct flexcop_device *fc)
477{ 513{
478 struct dvb_frontend_ops *ops; 514 struct dvb_frontend_ops *ops;
515 struct i2c_adapter *i2c = &fc->fc_i2c_adap[0].i2c_adap;
516 struct i2c_adapter *i2c_tuner;
517
518 /* enable no_base_addr - no repeated start when reading */
519 fc->fc_i2c_adap[0].no_base_addr = 1;
520 fc->fe = dvb_attach(s5h1420_attach, &skystar2_rev2_7_s5h1420_config, i2c);
521 if (fc->fe != NULL) {
522 flexcop_ibi_value r108;
523 i2c_tuner = s5h1420_get_tuner_i2c_adapter(fc->fe);
524 ops = &fc->fe->ops;
525
526 fc->fe_sleep = ops->sleep;
527 ops->sleep = flexcop_sleep;
528
529 fc->dev_type = FC_SKY_REV27;
530
531 /* enable no_base_addr - no repeated start when reading */
532 fc->fc_i2c_adap[2].no_base_addr = 1;
533 if (dvb_attach(isl6421_attach, fc->fe, &fc->fc_i2c_adap[2].i2c_adap, 0x08, 1, 1) == NULL)
534 err("ISL6421 could NOT be attached");
535 else
536 info("ISL6421 successfully attached");
537
538 /* the ITD1000 requires a lower i2c clock - it slows down the stuff for everyone - but is it a problem ? */
539 r108.raw = 0x00000506;
540 fc->write_ibi_reg(fc, tw_sm_c_108, r108);
541 if (i2c_tuner) {
542 if (dvb_attach(itd1000_attach, fc->fe, i2c_tuner, &skystar2_rev2_7_itd1000_config) == NULL)
543 err("ITD1000 could NOT be attached");
544 else
545 info("ITD1000 successfully attached");
546 }
547 goto fe_found;
548 }
549 fc->fc_i2c_adap[0].no_base_addr = 0; /* for the next devices we need it again */
550
551 /* try the sky v2.8 (cx24123, isl6421) */
552 fc->fe = dvb_attach(cx24123_attach,
553 &skystar2_rev2_8_cx24123_config, i2c);
554 if (fc->fe != NULL) {
555 i2c_tuner = cx24123_get_tuner_i2c_adapter(fc->fe);
556 if (i2c_tuner != NULL) {
557 if (dvb_attach(cx24113_attach, fc->fe,
558 &skystar2_rev2_8_cx24113_config,
559 i2c_tuner) == NULL)
560 err("CX24113 could NOT be attached");
561 else
562 info("CX24113 successfully attached");
563 }
564
565 fc->dev_type = FC_SKY_REV28;
566
567 fc->fc_i2c_adap[2].no_base_addr = 1;
568 if (dvb_attach(isl6421_attach, fc->fe,
569 &fc->fc_i2c_adap[2].i2c_adap, 0x08, 0, 0) == NULL)
570 err("ISL6421 could NOT be attached");
571 else
572 info("ISL6421 successfully attached");
573
574 /* TODO on i2c_adap[1] addr 0x11 (EEPROM) there seems to be an
575 * IR-receiver (PIC16F818) - but the card has no input for
576 * that ??? */
577
578 goto fe_found;
579 }
479 580
480 /* try the sky v2.6 (stv0299/Samsung tbmu24112(sl1935)) */ 581 /* try the sky v2.6 (stv0299/Samsung tbmu24112(sl1935)) */
481 if ((fc->fe = dvb_attach(stv0299_attach, &samsung_tbmu24112_config, &fc->i2c_adap)) != NULL) { 582 fc->fe = dvb_attach(stv0299_attach, &samsung_tbmu24112_config, i2c);
583 if (fc->fe != NULL) {
482 ops = &fc->fe->ops; 584 ops = &fc->fe->ops;
483 585
484 ops->tuner_ops.set_params = samsung_tbmu24112_tuner_set_params; 586 ops->tuner_ops.set_params = samsung_tbmu24112_tuner_set_params;
485 587
486 ops->set_voltage = flexcop_set_voltage; 588 ops->set_voltage = flexcop_set_voltage;
487 589
488 fc->fe_sleep = ops->sleep; 590 fc->fe_sleep = ops->sleep;
489 ops->sleep = flexcop_sleep; 591 ops->sleep = flexcop_sleep;
592
593 fc->dev_type = FC_SKY;
594 goto fe_found;
595 }
490 596
491 fc->dev_type = FC_SKY;
492 info("found the stv0299 at i2c address: 0x%02x",samsung_tbmu24112_config.demod_address);
493 } else
494 /* try the air dvb-t (mt352/Samsung tdtc9251dh0(??)) */ 597 /* try the air dvb-t (mt352/Samsung tdtc9251dh0(??)) */
495 if ((fc->fe = dvb_attach(mt352_attach, &samsung_tdtc9251dh0_config, &fc->i2c_adap)) != NULL ) { 598 fc->fe = dvb_attach(mt352_attach, &samsung_tdtc9251dh0_config, i2c);
496 fc->dev_type = FC_AIR_DVB; 599 if (fc->fe != NULL) {
600 fc->dev_type = FC_AIR_DVB;
497 fc->fe->ops.tuner_ops.calc_regs = samsung_tdtc9251dh0_calc_regs; 601 fc->fe->ops.tuner_ops.calc_regs = samsung_tdtc9251dh0_calc_regs;
498 info("found the mt352 at i2c address: 0x%02x",samsung_tdtc9251dh0_config.demod_address); 602 goto fe_found;
499 } else 603 }
604
500 /* try the air atsc 2nd generation (nxt2002) */ 605 /* try the air atsc 2nd generation (nxt2002) */
501 if ((fc->fe = dvb_attach(nxt200x_attach, &samsung_tbmv_config, &fc->i2c_adap)) != NULL) { 606 fc->fe = dvb_attach(nxt200x_attach, &samsung_tbmv_config, i2c);
502 fc->dev_type = FC_AIR_ATSC2; 607 if (fc->fe != NULL) {
608 fc->dev_type = FC_AIR_ATSC2;
503 dvb_attach(dvb_pll_attach, fc->fe, 0x61, NULL, DVB_PLL_SAMSUNG_TBMV); 609 dvb_attach(dvb_pll_attach, fc->fe, 0x61, NULL, DVB_PLL_SAMSUNG_TBMV);
504 info("found the nxt2002 at i2c address: 0x%02x",samsung_tbmv_config.demod_address); 610 goto fe_found;
505 } else 611 }
506 /* try the air atsc 3nd generation (lgdt3303) */ 612
507 if ((fc->fe = dvb_attach(lgdt330x_attach, &air2pc_atsc_hd5000_config, &fc->i2c_adap)) != NULL) { 613 fc->fe = dvb_attach(lgdt330x_attach, &air2pc_atsc_hd5000_config, i2c);
508 fc->dev_type = FC_AIR_ATSC3; 614 if (fc->fe != NULL) {
509 dvb_attach(dvb_pll_attach, fc->fe, 0x61, &fc->i2c_adap, DVB_PLL_LG_TDVS_H06XF); 615 fc->dev_type = FC_AIR_ATSC3;
510 info("found the lgdt3303 at i2c address: 0x%02x",air2pc_atsc_hd5000_config.demod_address); 616 dvb_attach(simple_tuner_attach, fc->fe, i2c, 0x61,
511 } else 617 TUNER_LG_TDVS_H06XF);
618 goto fe_found;
619 }
620
512 /* try the air atsc 1nd generation (bcm3510)/panasonic ct10s */ 621 /* try the air atsc 1nd generation (bcm3510)/panasonic ct10s */
513 if ((fc->fe = dvb_attach(bcm3510_attach, &air2pc_atsc_first_gen_config, &fc->i2c_adap)) != NULL) { 622 fc->fe = dvb_attach(bcm3510_attach, &air2pc_atsc_first_gen_config, i2c);
514 fc->dev_type = FC_AIR_ATSC1; 623 if (fc->fe != NULL) {
515 info("found the bcm3510 at i2c address: 0x%02x",air2pc_atsc_first_gen_config.demod_address); 624 fc->dev_type = FC_AIR_ATSC1;
516 } else 625 goto fe_found;
626 }
627
517 /* try the cable dvb (stv0297) */ 628 /* try the cable dvb (stv0297) */
518 if ((fc->fe = dvb_attach(stv0297_attach, &alps_tdee4_stv0297_config, &fc->i2c_adap)) != NULL) { 629 fc->fe = dvb_attach(stv0297_attach, &alps_tdee4_stv0297_config, i2c);
519 fc->dev_type = FC_CABLE; 630 if (fc->fe != NULL) {
631 fc->dev_type = FC_CABLE;
520 fc->fe->ops.tuner_ops.set_params = alps_tdee4_stv0297_tuner_set_params; 632 fc->fe->ops.tuner_ops.set_params = alps_tdee4_stv0297_tuner_set_params;
521 info("found the stv0297 at i2c address: 0x%02x",alps_tdee4_stv0297_config.demod_address); 633 goto fe_found;
522 } else 634 }
635
523 /* try the sky v2.3 (vp310/Samsung tbdu18132(tsa5059)) */ 636 /* try the sky v2.3 (vp310/Samsung tbdu18132(tsa5059)) */
524 if ((fc->fe = dvb_attach(vp310_mt312_attach, &skystar23_samsung_tbdu18132_config, &fc->i2c_adap)) != NULL) { 637 fc->fe = dvb_attach(vp310_mt312_attach,
638 &skystar23_samsung_tbdu18132_config, i2c);
639 if (fc->fe != NULL) {
525 ops = &fc->fe->ops; 640 ops = &fc->fe->ops;
526 641
527 ops->tuner_ops.set_params = skystar23_samsung_tbdu18132_tuner_set_params; 642 ops->tuner_ops.set_params = skystar23_samsung_tbdu18132_tuner_set_params;
@@ -535,19 +650,21 @@ int flexcop_frontend_init(struct flexcop_device *fc)
535 ops->sleep = flexcop_sleep; 650 ops->sleep = flexcop_sleep;
536 651
537 fc->dev_type = FC_SKY_OLD; 652 fc->dev_type = FC_SKY_OLD;
538 info("found the vp310 (aka mt312) at i2c address: 0x%02x",skystar23_samsung_tbdu18132_config.demod_address); 653 goto fe_found;
539 } 654 }
540 655
541 if (fc->fe == NULL) { 656 err("no frontend driver found for this B2C2/FlexCop adapter");
542 err("no frontend driver found for this B2C2/FlexCop adapter"); 657 return -ENODEV;
543 return -ENODEV; 658
544 } else { 659fe_found:
545 if (dvb_register_frontend(&fc->dvb_adapter, fc->fe)) { 660 info("found '%s' .", fc->fe->ops.info.name);
546 err("frontend registration failed!"); 661 if (dvb_register_frontend(&fc->dvb_adapter, fc->fe)) {
547 dvb_frontend_detach(fc->fe); 662 err("frontend registration failed!");
548 fc->fe = NULL; 663 ops = &fc->fe->ops;
549 return -EINVAL; 664 if (ops->release != NULL)
550 } 665 ops->release(fc->fe);
666 fc->fe = NULL;
667 return -EINVAL;
551 } 668 }
552 fc->init_state |= FC_STATE_FE_INIT; 669 fc->init_state |= FC_STATE_FE_INIT;
553 return 0; 670 return 0;
diff --git a/drivers/media/dvb/b2c2/flexcop-i2c.c b/drivers/media/dvb/b2c2/flexcop-i2c.c
index 6bf858a436c9..55973eaf3711 100644
--- a/drivers/media/dvb/b2c2/flexcop-i2c.c
+++ b/drivers/media/dvb/b2c2/flexcop-i2c.c
@@ -9,6 +9,8 @@
9 9
10#define FC_MAX_I2C_RETRIES 100000 10#define FC_MAX_I2C_RETRIES 100000
11 11
12/* #define DUMP_I2C_MESSAGES */
13
12static int flexcop_i2c_operation(struct flexcop_device *fc, flexcop_ibi_value *r100) 14static int flexcop_i2c_operation(struct flexcop_device *fc, flexcop_ibi_value *r100)
13{ 15{
14 int i; 16 int i;
@@ -38,30 +40,25 @@ static int flexcop_i2c_operation(struct flexcop_device *fc, flexcop_ibi_value *r
38 return -EREMOTEIO; 40 return -EREMOTEIO;
39} 41}
40 42
41static int flexcop_i2c_read4(struct flexcop_device *fc, flexcop_ibi_value r100, u8 *buf) 43static int flexcop_i2c_read4(struct flexcop_i2c_adapter *i2c,
44 flexcop_ibi_value r100, u8 *buf)
42{ 45{
43 flexcop_ibi_value r104; 46 flexcop_ibi_value r104;
44 int len = r100.tw_sm_c_100.total_bytes, /* remember total_bytes is buflen-1 */ 47 int len = r100.tw_sm_c_100.total_bytes, /* remember total_bytes is buflen-1 */
45 ret; 48 ret;
46 49
47 if ((ret = flexcop_i2c_operation(fc,&r100)) != 0) { 50 r100.tw_sm_c_100.no_base_addr_ack_error = i2c->no_base_addr;
48 /* The Cablestar needs a different kind of i2c-transfer (does not 51 ret = flexcop_i2c_operation(i2c->fc, &r100);
49 * support "Repeat Start"): 52 if (ret != 0) {
50 * wait for the ACK failure, 53 deb_i2c("read failed. %d\n", ret);
51 * and do a subsequent read with the Bit 30 enabled 54 return ret;
52 */
53 r100.tw_sm_c_100.no_base_addr_ack_error = 1;
54 if ((ret = flexcop_i2c_operation(fc,&r100)) != 0) {
55 deb_i2c("no_base_addr read failed. %d\n",ret);
56 return ret;
57 }
58 } 55 }
59 56
60 buf[0] = r100.tw_sm_c_100.data1_reg; 57 buf[0] = r100.tw_sm_c_100.data1_reg;
61 58
62 if (len > 0) { 59 if (len > 0) {
63 r104 = fc->read_ibi_reg(fc,tw_sm_c_104); 60 r104 = i2c->fc->read_ibi_reg(i2c->fc, tw_sm_c_104);
64 deb_i2c("read: r100: %08x, r104: %08x\n",r100.raw,r104.raw); 61 deb_i2c("read: r100: %08x, r104: %08x\n", r100.raw, r104.raw);
65 62
66 /* there is at least one more byte, otherwise we wouldn't be here */ 63 /* there is at least one more byte, otherwise we wouldn't be here */
67 buf[1] = r104.tw_sm_c_104.data2_reg; 64 buf[1] = r104.tw_sm_c_104.data2_reg;
@@ -85,17 +82,22 @@ static int flexcop_i2c_write4(struct flexcop_device *fc, flexcop_ibi_value r100,
85 r104.tw_sm_c_104.data3_reg = len > 1 ? buf[2] : 0; 82 r104.tw_sm_c_104.data3_reg = len > 1 ? buf[2] : 0;
86 r104.tw_sm_c_104.data4_reg = len > 2 ? buf[3] : 0; 83 r104.tw_sm_c_104.data4_reg = len > 2 ? buf[3] : 0;
87 84
88 deb_i2c("write: r100: %08x, r104: %08x\n",r100.raw,r104.raw); 85 deb_i2c("write: r100: %08x, r104: %08x\n", r100.raw, r104.raw);
89 86
90 /* write the additional i2c data before doing the actual i2c operation */ 87 /* write the additional i2c data before doing the actual i2c operation */
91 fc->write_ibi_reg(fc,tw_sm_c_104,r104); 88 fc->write_ibi_reg(fc, tw_sm_c_104, r104);
92 return flexcop_i2c_operation(fc,&r100); 89 return flexcop_i2c_operation(fc, &r100);
93} 90}
94 91
95int flexcop_i2c_request(struct flexcop_device *fc, flexcop_access_op_t op, 92int flexcop_i2c_request(struct flexcop_i2c_adapter *i2c,
96 flexcop_i2c_port_t port, u8 chipaddr, u8 addr, u8 *buf, u16 len) 93 flexcop_access_op_t op, u8 chipaddr, u8 addr, u8 *buf, u16 len)
97{ 94{
98 int ret; 95 int ret;
96
97#ifdef DUMP_I2C_MESSAGES
98 int i;
99#endif
100
99 u16 bytes_to_transfer; 101 u16 bytes_to_transfer;
100 flexcop_ibi_value r100; 102 flexcop_ibi_value r100;
101 103
@@ -103,7 +105,25 @@ int flexcop_i2c_request(struct flexcop_device *fc, flexcop_access_op_t op,
103 r100.raw = 0; 105 r100.raw = 0;
104 r100.tw_sm_c_100.chipaddr = chipaddr; 106 r100.tw_sm_c_100.chipaddr = chipaddr;
105 r100.tw_sm_c_100.twoWS_rw = op; 107 r100.tw_sm_c_100.twoWS_rw = op;
106 r100.tw_sm_c_100.twoWS_port_reg = port; 108 r100.tw_sm_c_100.twoWS_port_reg = i2c->port;
109
110#ifdef DUMP_I2C_MESSAGES
111 printk(KERN_DEBUG "%d ", i2c->port);
112 if (op == FC_READ)
113 printk("rd(");
114 else
115 printk("wr(");
116
117 printk("%02x): %02x ", chipaddr, addr);
118#endif
119
120 /* in that case addr is the only value ->
121 * we write it twice as baseaddr and val0
122 * BBTI is doing it like that for ISL6421 at least */
123 if (i2c->no_base_addr && len == 0 && op == FC_WRITE) {
124 buf = &addr;
125 len = 1;
126 }
107 127
108 while (len != 0) { 128 while (len != 0) {
109 bytes_to_transfer = len > 4 ? 4 : len; 129 bytes_to_transfer = len > 4 ? 4 : len;
@@ -112,9 +132,14 @@ int flexcop_i2c_request(struct flexcop_device *fc, flexcop_access_op_t op,
112 r100.tw_sm_c_100.baseaddr = addr; 132 r100.tw_sm_c_100.baseaddr = addr;
113 133
114 if (op == FC_READ) 134 if (op == FC_READ)
115 ret = flexcop_i2c_read4(fc, r100, buf); 135 ret = flexcop_i2c_read4(i2c, r100, buf);
116 else 136 else
117 ret = flexcop_i2c_write4(fc,r100, buf); 137 ret = flexcop_i2c_write4(i2c->fc, r100, buf);
138
139#ifdef DUMP_I2C_MESSAGES
140 for (i = 0; i < bytes_to_transfer; i++)
141 printk("%02x ", buf[i]);
142#endif
118 143
119 if (ret < 0) 144 if (ret < 0)
120 return ret; 145 return ret;
@@ -122,7 +147,11 @@ int flexcop_i2c_request(struct flexcop_device *fc, flexcop_access_op_t op,
122 buf += bytes_to_transfer; 147 buf += bytes_to_transfer;
123 addr += bytes_to_transfer; 148 addr += bytes_to_transfer;
124 len -= bytes_to_transfer; 149 len -= bytes_to_transfer;
125 }; 150 }
151
152#ifdef DUMP_I2C_MESSAGES
153 printk("\n");
154#endif
126 155
127 return 0; 156 return 0;
128} 157}
@@ -132,7 +161,7 @@ EXPORT_SYMBOL(flexcop_i2c_request);
132/* master xfer callback for demodulator */ 161/* master xfer callback for demodulator */
133static int flexcop_master_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num) 162static int flexcop_master_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msgs[], int num)
134{ 163{
135 struct flexcop_device *fc = i2c_get_adapdata(i2c_adap); 164 struct flexcop_i2c_adapter *i2c = i2c_get_adapdata(i2c_adap);
136 int i, ret = 0; 165 int i, ret = 0;
137 166
138 /* Some drivers use 1 byte or 0 byte reads as probes, which this 167 /* Some drivers use 1 byte or 0 byte reads as probes, which this
@@ -142,34 +171,29 @@ static int flexcop_master_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msgs
142 if (num == 1 && msgs[0].flags == I2C_M_RD && msgs[0].len <= 1) 171 if (num == 1 && msgs[0].flags == I2C_M_RD && msgs[0].len <= 1)
143 return 1; 172 return 1;
144 173
145 if (mutex_lock_interruptible(&fc->i2c_mutex)) 174 if (mutex_lock_interruptible(&i2c->fc->i2c_mutex))
146 return -ERESTARTSYS; 175 return -ERESTARTSYS;
147 176
148 /* reading */ 177 for (i = 0; i < num; i++) {
149 if (num == 2 && 178 /* reading */
150 msgs[0].flags == 0 && 179 if (i+1 < num && (msgs[i+1].flags == I2C_M_RD)) {
151 msgs[1].flags == I2C_M_RD && 180 ret = i2c->fc->i2c_request(i2c, FC_READ, msgs[i].addr,
152 msgs[0].buf != NULL && 181 msgs[i].buf[0], msgs[i+1].buf, msgs[i+1].len);
153 msgs[1].buf != NULL) { 182 i++; /* skip the following message */
154 183 } else /* writing */
155 ret = fc->i2c_request(fc, FC_READ, FC_I2C_PORT_DEMOD, msgs[0].addr, msgs[0].buf[0], msgs[1].buf, msgs[1].len); 184 ret = i2c->fc->i2c_request(i2c, FC_WRITE, msgs[i].addr,
156 185 msgs[i].buf[0], &msgs[i].buf[1],
157 } else for (i = 0; i < num; i++) { /* writing command */ 186 msgs[i].len - 1);
158 if (msgs[i].flags != 0 || msgs[i].buf == NULL || msgs[i].len < 2) { 187 if (ret < 0) {
159 ret = -EINVAL; 188 err("i2c master_xfer failed");
160 break; 189 break;
161 } 190 }
162
163 ret = fc->i2c_request(fc, FC_WRITE, FC_I2C_PORT_DEMOD, msgs[i].addr, msgs[i].buf[0], &msgs[i].buf[1], msgs[i].len - 1);
164 } 191 }
165 192
166 if (ret < 0) 193 mutex_unlock(&i2c->fc->i2c_mutex);
167 err("i2c master_xfer failed");
168 else
169 ret = num;
170
171 mutex_unlock(&fc->i2c_mutex);
172 194
195 if (ret == 0)
196 ret = num;
173 return ret; 197 return ret;
174} 198}
175 199
@@ -189,28 +213,68 @@ int flexcop_i2c_init(struct flexcop_device *fc)
189 213
190 mutex_init(&fc->i2c_mutex); 214 mutex_init(&fc->i2c_mutex);
191 215
192 memset(&fc->i2c_adap, 0, sizeof(struct i2c_adapter)); 216 fc->fc_i2c_adap[0].fc = fc;
193 strncpy(fc->i2c_adap.name, "B2C2 FlexCop device", 217 fc->fc_i2c_adap[1].fc = fc;
194 sizeof(fc->i2c_adap.name)); 218 fc->fc_i2c_adap[2].fc = fc;
195 219
196 i2c_set_adapdata(&fc->i2c_adap,fc); 220 fc->fc_i2c_adap[0].port = FC_I2C_PORT_DEMOD;
221 fc->fc_i2c_adap[1].port = FC_I2C_PORT_EEPROM;
222 fc->fc_i2c_adap[2].port = FC_I2C_PORT_TUNER;
223
224 strncpy(fc->fc_i2c_adap[0].i2c_adap.name,
225 "B2C2 FlexCop I2C to demod", I2C_NAME_SIZE);
226 strncpy(fc->fc_i2c_adap[1].i2c_adap.name,
227 "B2C2 FlexCop I2C to eeprom", I2C_NAME_SIZE);
228 strncpy(fc->fc_i2c_adap[2].i2c_adap.name,
229 "B2C2 FlexCop I2C to tuner", I2C_NAME_SIZE);
230
231 i2c_set_adapdata(&fc->fc_i2c_adap[0].i2c_adap, &fc->fc_i2c_adap[0]);
232 i2c_set_adapdata(&fc->fc_i2c_adap[1].i2c_adap, &fc->fc_i2c_adap[1]);
233 i2c_set_adapdata(&fc->fc_i2c_adap[2].i2c_adap, &fc->fc_i2c_adap[2]);
234
235 fc->fc_i2c_adap[0].i2c_adap.class =
236 fc->fc_i2c_adap[1].i2c_adap.class =
237 fc->fc_i2c_adap[2].i2c_adap.class = I2C_CLASS_TV_DIGITAL;
238 fc->fc_i2c_adap[0].i2c_adap.algo =
239 fc->fc_i2c_adap[1].i2c_adap.algo =
240 fc->fc_i2c_adap[2].i2c_adap.algo = &flexcop_algo;
241 fc->fc_i2c_adap[0].i2c_adap.algo_data =
242 fc->fc_i2c_adap[1].i2c_adap.algo_data =
243 fc->fc_i2c_adap[2].i2c_adap.algo_data = NULL;
244 fc->fc_i2c_adap[0].i2c_adap.dev.parent =
245 fc->fc_i2c_adap[1].i2c_adap.dev.parent =
246 fc->fc_i2c_adap[2].i2c_adap.dev.parent = fc->dev;
247
248 ret = i2c_add_adapter(&fc->fc_i2c_adap[0].i2c_adap);
249 if (ret < 0)
250 return ret;
197 251
198 fc->i2c_adap.class = I2C_CLASS_TV_DIGITAL; 252 ret = i2c_add_adapter(&fc->fc_i2c_adap[1].i2c_adap);
199 fc->i2c_adap.algo = &flexcop_algo; 253 if (ret < 0)
200 fc->i2c_adap.algo_data = NULL; 254 goto adap_1_failed;
201 fc->i2c_adap.dev.parent = fc->dev;
202 255
203 if ((ret = i2c_add_adapter(&fc->i2c_adap)) < 0) 256 ret = i2c_add_adapter(&fc->fc_i2c_adap[2].i2c_adap);
204 return ret; 257 if (ret < 0)
258 goto adap_2_failed;
205 259
206 fc->init_state |= FC_STATE_I2C_INIT; 260 fc->init_state |= FC_STATE_I2C_INIT;
207 return 0; 261 return 0;
262
263adap_2_failed:
264 i2c_del_adapter(&fc->fc_i2c_adap[1].i2c_adap);
265adap_1_failed:
266 i2c_del_adapter(&fc->fc_i2c_adap[0].i2c_adap);
267
268 return ret;
208} 269}
209 270
210void flexcop_i2c_exit(struct flexcop_device *fc) 271void flexcop_i2c_exit(struct flexcop_device *fc)
211{ 272{
212 if (fc->init_state & FC_STATE_I2C_INIT) 273 if (fc->init_state & FC_STATE_I2C_INIT) {
213 i2c_del_adapter(&fc->i2c_adap); 274 i2c_del_adapter(&fc->fc_i2c_adap[2].i2c_adap);
275 i2c_del_adapter(&fc->fc_i2c_adap[1].i2c_adap);
276 i2c_del_adapter(&fc->fc_i2c_adap[0].i2c_adap);
277 }
214 278
215 fc->init_state &= ~FC_STATE_I2C_INIT; 279 fc->init_state &= ~FC_STATE_I2C_INIT;
216} 280}
diff --git a/drivers/media/dvb/b2c2/flexcop-misc.c b/drivers/media/dvb/b2c2/flexcop-misc.c
index 167583bf0621..93d20e56f909 100644
--- a/drivers/media/dvb/b2c2/flexcop-misc.c
+++ b/drivers/media/dvb/b2c2/flexcop-misc.c
@@ -52,6 +52,8 @@ static const char *flexcop_device_names[] = {
52 "Sky2PC/SkyStar 2 DVB-S (old version)", 52 "Sky2PC/SkyStar 2 DVB-S (old version)",
53 "Cable2PC/CableStar 2 DVB-C", 53 "Cable2PC/CableStar 2 DVB-C",
54 "Air2PC/AirStar 2 ATSC 3rd generation (HD5000)", 54 "Air2PC/AirStar 2 ATSC 3rd generation (HD5000)",
55 "Sky2PC/SkyStar 2 DVB-S rev 2.7a/u",
56 "Sky2PC/SkyStar 2 DVB-S rev 2.8",
55}; 57};
56 58
57static const char *flexcop_bus_names[] = { 59static const char *flexcop_bus_names[] = {
diff --git a/drivers/media/dvb/b2c2/flexcop-pci.c b/drivers/media/dvb/b2c2/flexcop-pci.c
index 01af4d237eb1..5b30dfc7846b 100644
--- a/drivers/media/dvb/b2c2/flexcop-pci.c
+++ b/drivers/media/dvb/b2c2/flexcop-pci.c
@@ -32,7 +32,7 @@ MODULE_PARM_DESC(irq_chk_intv, "set the interval for IRQ watchdog (currently jus
32#define deb_irq(args...) dprintk(0x08,args) 32#define deb_irq(args...) dprintk(0x08,args)
33#define deb_chk(args...) dprintk(0x10,args) 33#define deb_chk(args...) dprintk(0x10,args)
34 34
35static int debug = 0; 35static int debug;
36module_param(debug, int, 0644); 36module_param(debug, int, 0644);
37MODULE_PARM_DESC(debug, "set debug level (1=info,2=regs,4=TS,8=irqdma (|-able))." DEBSTATUS); 37MODULE_PARM_DESC(debug, "set debug level (1=info,2=regs,4=TS,8=irqdma (|-able))." DEBSTATUS);
38 38
diff --git a/drivers/media/dvb/b2c2/flexcop-reg.h b/drivers/media/dvb/b2c2/flexcop-reg.h
index 491f9bd6e195..7599fccc1a5b 100644
--- a/drivers/media/dvb/b2c2/flexcop-reg.h
+++ b/drivers/media/dvb/b2c2/flexcop-reg.h
@@ -25,6 +25,8 @@ typedef enum {
25 FC_SKY_OLD, 25 FC_SKY_OLD,
26 FC_CABLE, 26 FC_CABLE,
27 FC_AIR_ATSC3, 27 FC_AIR_ATSC3,
28 FC_SKY_REV27,
29 FC_SKY_REV28,
28} flexcop_device_type_t; 30} flexcop_device_type_t;
29 31
30typedef enum { 32typedef enum {
diff --git a/drivers/media/dvb/b2c2/flexcop-sram.c b/drivers/media/dvb/b2c2/flexcop-sram.c
index 01570ec80962..cda69528548a 100644
--- a/drivers/media/dvb/b2c2/flexcop-sram.c
+++ b/drivers/media/dvb/b2c2/flexcop-sram.c
@@ -90,7 +90,7 @@ static void flexcop_sram_write(struct adapter *adapter, u32 bank, u32 addr, u8 *
90 }; 90 };
91 91
92 if (retries == 0) 92 if (retries == 0)
93 printk("%s: SRAM timeout\n", __FUNCTION__); 93 printk("%s: SRAM timeout\n", __func__);
94 94
95 write_reg_dw(adapter, 0x700, command); 95 write_reg_dw(adapter, 0x700, command);
96 96
@@ -115,7 +115,7 @@ static void flex_sram_read(struct adapter *adapter, u32 bank, u32 addr, u8 *buf,
115 }; 115 };
116 116
117 if (retries == 0) 117 if (retries == 0)
118 printk("%s: SRAM timeout\n", __FUNCTION__); 118 printk("%s: SRAM timeout\n", __func__);
119 119
120 write_reg_dw(adapter, 0x700, command); 120 write_reg_dw(adapter, 0x700, command);
121 121
@@ -127,7 +127,7 @@ static void flex_sram_read(struct adapter *adapter, u32 bank, u32 addr, u8 *buf,
127 }; 127 };
128 128
129 if (retries == 0) 129 if (retries == 0)
130 printk("%s: SRAM timeout\n", __FUNCTION__); 130 printk("%s: SRAM timeout\n", __func__);
131 131
132 value = read_reg_dw(adapter, 0x700) >> 0x10; 132 value = read_reg_dw(adapter, 0x700) >> 0x10;
133 133
@@ -240,13 +240,13 @@ static void sram_init(struct adapter *adapter)
240 240
241 adapter->dw_sram_type = tmp & 0x30000; 241 adapter->dw_sram_type = tmp & 0x30000;
242 242
243 ddprintk("%s: dw_sram_type = %x\n", __FUNCTION__, adapter->dw_sram_type); 243 ddprintk("%s: dw_sram_type = %x\n", __func__, adapter->dw_sram_type);
244 244
245 } else { 245 } else {
246 246
247 adapter->dw_sram_type = 0x10000; 247 adapter->dw_sram_type = 0x10000;
248 248
249 ddprintk("%s: dw_sram_type = %x\n", __FUNCTION__, adapter->dw_sram_type); 249 ddprintk("%s: dw_sram_type = %x\n", __func__, adapter->dw_sram_type);
250 } 250 }
251 251
252 /* return value is never used? */ 252 /* return value is never used? */
@@ -257,7 +257,7 @@ static int sram_test_location(struct adapter *adapter, u32 mask, u32 addr)
257{ 257{
258 u8 tmp1, tmp2; 258 u8 tmp1, tmp2;
259 259
260 dprintk("%s: mask = %x, addr = %x\n", __FUNCTION__, mask, addr); 260 dprintk("%s: mask = %x, addr = %x\n", __func__, mask, addr);
261 261
262 sram_set_size(adapter, mask); 262 sram_set_size(adapter, mask);
263 sram_init(adapter); 263 sram_init(adapter);
@@ -275,7 +275,7 @@ static int sram_test_location(struct adapter *adapter, u32 mask, u32 addr)
275 sram_read(adapter, addr, &tmp2, 1); 275 sram_read(adapter, addr, &tmp2, 1);
276 sram_read(adapter, addr, &tmp2, 1); 276 sram_read(adapter, addr, &tmp2, 1);
277 277
278 dprintk("%s: wrote 0xa5, read 0x%2x\n", __FUNCTION__, tmp2); 278 dprintk("%s: wrote 0xa5, read 0x%2x\n", __func__, tmp2);
279 279
280 if (tmp2 != 0xa5) 280 if (tmp2 != 0xa5)
281 return 0; 281 return 0;
@@ -293,7 +293,7 @@ static int sram_test_location(struct adapter *adapter, u32 mask, u32 addr)
293 sram_read(adapter, addr, &tmp2, 1); 293 sram_read(adapter, addr, &tmp2, 1);
294 sram_read(adapter, addr, &tmp2, 1); 294 sram_read(adapter, addr, &tmp2, 1);
295 295
296 dprintk("%s: wrote 0x5a, read 0x%2x\n", __FUNCTION__, tmp2); 296 dprintk("%s: wrote 0x5a, read 0x%2x\n", __func__, tmp2);
297 297
298 if (tmp2 != 0x5a) 298 if (tmp2 != 0x5a)
299 return 0; 299 return 0;
@@ -340,7 +340,7 @@ static int flexcop_sram_detect(struct flexcop_device *fc)
340 340
341 tmp3 = read_reg_dw(adapter, 0x71c); 341 tmp3 = read_reg_dw(adapter, 0x71c);
342 342
343 dprintk("%s: tmp3 = %x\n", __FUNCTION__, tmp3); 343 dprintk("%s: tmp3 = %x\n", __func__, tmp3);
344 344
345 write_reg_dw(adapter, 0x71c, tmp2); 345 write_reg_dw(adapter, 0x71c, tmp2);
346 346
@@ -351,7 +351,7 @@ static int flexcop_sram_detect(struct flexcop_device *fc)
351 sram_init(adapter); 351 sram_init(adapter);
352 write_reg_dw(adapter, 0x208, tmp); 352 write_reg_dw(adapter, 0x208, tmp);
353 353
354 dprintk("%s: sram size = 32K\n", __FUNCTION__); 354 dprintk("%s: sram size = 32K\n", __func__);
355 355
356 return 32; 356 return 32;
357 } 357 }
@@ -361,7 +361,7 @@ static int flexcop_sram_detect(struct flexcop_device *fc)
361 sram_init(adapter); 361 sram_init(adapter);
362 write_reg_dw(adapter, 0x208, tmp); 362 write_reg_dw(adapter, 0x208, tmp);
363 363
364 dprintk("%s: sram size = 128K\n", __FUNCTION__); 364 dprintk("%s: sram size = 128K\n", __func__);
365 365
366 return 128; 366 return 128;
367 } 367 }
@@ -371,7 +371,7 @@ static int flexcop_sram_detect(struct flexcop_device *fc)
371 sram_init(adapter); 371 sram_init(adapter);
372 write_reg_dw(adapter, 0x208, tmp); 372 write_reg_dw(adapter, 0x208, tmp);
373 373
374 dprintk("%s: sram size = 64K\n", __FUNCTION__); 374 dprintk("%s: sram size = 64K\n", __func__);
375 375
376 return 64; 376 return 64;
377 } 377 }
@@ -381,7 +381,7 @@ static int flexcop_sram_detect(struct flexcop_device *fc)
381 sram_init(adapter); 381 sram_init(adapter);
382 write_reg_dw(adapter, 0x208, tmp); 382 write_reg_dw(adapter, 0x208, tmp);
383 383
384 dprintk("%s: sram size = 32K\n", __FUNCTION__); 384 dprintk("%s: sram size = 32K\n", __func__);
385 385
386 return 32; 386 return 32;
387 } 387 }
@@ -390,7 +390,7 @@ static int flexcop_sram_detect(struct flexcop_device *fc)
390 sram_init(adapter); 390 sram_init(adapter);
391 write_reg_dw(adapter, 0x208, tmp); 391 write_reg_dw(adapter, 0x208, tmp);
392 392
393 dprintk("%s: SRAM detection failed. Set to 32K \n", __FUNCTION__); 393 dprintk("%s: SRAM detection failed. Set to 32K \n", __func__);
394 394
395 return 0; 395 return 0;
396} 396}
diff --git a/drivers/media/dvb/b2c2/flexcop-usb.c b/drivers/media/dvb/b2c2/flexcop-usb.c
index 87fb75f0d1cf..449fb5c3d0b1 100644
--- a/drivers/media/dvb/b2c2/flexcop-usb.c
+++ b/drivers/media/dvb/b2c2/flexcop-usb.c
@@ -211,10 +211,11 @@ static int flexcop_usb_utility_req(struct flexcop_usb *fc_usb, int set,
211#endif 211#endif
212 212
213/* usb i2c stuff */ 213/* usb i2c stuff */
214static int flexcop_usb_i2c_req(struct flexcop_usb *fc_usb, 214static int flexcop_usb_i2c_req(struct flexcop_i2c_adapter *i2c,
215 flexcop_usb_request_t req, flexcop_usb_i2c_function_t func, 215 flexcop_usb_request_t req, flexcop_usb_i2c_function_t func,
216 flexcop_i2c_port_t port, u8 chipaddr, u8 addr, u8 *buf, u8 buflen) 216 u8 chipaddr, u8 addr, u8 *buf, u8 buflen)
217{ 217{
218 struct flexcop_usb *fc_usb = i2c->fc->bus_specific;
218 u16 wValue, wIndex; 219 u16 wValue, wIndex;
219 int nWaitTime,pipe,len; 220 int nWaitTime,pipe,len;
220// u8 dwRequestType; 221// u8 dwRequestType;
@@ -242,7 +243,7 @@ static int flexcop_usb_i2c_req(struct flexcop_usb *fc_usb,
242 deb_info("unsupported function for i2c_req %x\n",func); 243 deb_info("unsupported function for i2c_req %x\n",func);
243 return -EINVAL; 244 return -EINVAL;
244 } 245 }
245 wValue = (func << 8 ) | (port << 4); 246 wValue = (func << 8) | (i2c->port << 4);
246 wIndex = (chipaddr << 8 ) | addr; 247 wIndex = (chipaddr << 8 ) | addr;
247 248
248 deb_i2c("i2c %2d: %02x %02x %02x %02x %02x %02x\n",func,request_type,req, 249 deb_i2c("i2c %2d: %02x %02x %02x %02x %02x %02x\n",func,request_type,req,
@@ -274,13 +275,15 @@ static int flexcop_usb_write_ibi_reg(struct flexcop_device *fc, flexcop_ibi_regi
274 return flexcop_usb_readwrite_dw(fc,reg, &val.raw, 0); 275 return flexcop_usb_readwrite_dw(fc,reg, &val.raw, 0);
275} 276}
276 277
277static int flexcop_usb_i2c_request(struct flexcop_device *fc, flexcop_access_op_t op, 278static int flexcop_usb_i2c_request(struct flexcop_i2c_adapter *i2c,
278 flexcop_i2c_port_t port, u8 chipaddr, u8 addr, u8 *buf, u16 len) 279 flexcop_access_op_t op, u8 chipaddr, u8 addr, u8 *buf, u16 len)
279{ 280{
280 if (op == FC_READ) 281 if (op == FC_READ)
281 return flexcop_usb_i2c_req(fc->bus_specific,B2C2_USB_I2C_REQUEST,USB_FUNC_I2C_READ,port,chipaddr,addr,buf,len); 282 return flexcop_usb_i2c_req(i2c, B2C2_USB_I2C_REQUEST,
283 USB_FUNC_I2C_READ, chipaddr, addr, buf, len);
282 else 284 else
283 return flexcop_usb_i2c_req(fc->bus_specific,B2C2_USB_I2C_REQUEST,USB_FUNC_I2C_WRITE,port,chipaddr,addr,buf,len); 285 return flexcop_usb_i2c_req(i2c, B2C2_USB_I2C_REQUEST,
286 USB_FUNC_I2C_WRITE, chipaddr, addr, buf, len);
284} 287}
285 288
286static void flexcop_usb_process_frame(struct flexcop_usb *fc_usb, u8 *buffer, int buffer_length) 289static void flexcop_usb_process_frame(struct flexcop_usb *fc_usb, u8 *buffer, int buffer_length)
diff --git a/drivers/media/dvb/b2c2/flexcop.c b/drivers/media/dvb/b2c2/flexcop.c
index 2ddafd071c97..5f79c8dc3836 100644
--- a/drivers/media/dvb/b2c2/flexcop.c
+++ b/drivers/media/dvb/b2c2/flexcop.c
@@ -49,6 +49,8 @@ module_param_named(debug, b2c2_flexcop_debug, int, 0644);
49MODULE_PARM_DESC(debug, "set debug level (1=info,2=tuner,4=i2c,8=ts,16=sram,32=reg (|-able))." DEBSTATUS); 49MODULE_PARM_DESC(debug, "set debug level (1=info,2=tuner,4=i2c,8=ts,16=sram,32=reg (|-able))." DEBSTATUS);
50#undef DEBSTATUS 50#undef DEBSTATUS
51 51
52DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
53
52/* global zero for ibi values */ 54/* global zero for ibi values */
53flexcop_ibi_value ibi_zero; 55flexcop_ibi_value ibi_zero;
54 56
@@ -66,8 +68,10 @@ static int flexcop_dvb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
66 68
67static int flexcop_dvb_init(struct flexcop_device *fc) 69static int flexcop_dvb_init(struct flexcop_device *fc)
68{ 70{
69 int ret; 71 int ret = dvb_register_adapter(&fc->dvb_adapter,
70 if ((ret = dvb_register_adapter(&fc->dvb_adapter,"FlexCop Digital TV device",fc->owner,fc->dev)) < 0) { 72 "FlexCop Digital TV device", fc->owner,
73 fc->dev, adapter_nr);
74 if (ret < 0) {
71 err("error registering DVB adapter"); 75 err("error registering DVB adapter");
72 return ret; 76 return ret;
73 } 77 }
@@ -257,6 +261,12 @@ int flexcop_device_initialize(struct flexcop_device *fc)
257 if ((ret = flexcop_dvb_init(fc))) 261 if ((ret = flexcop_dvb_init(fc)))
258 goto error; 262 goto error;
259 263
264 /* i2c has to be done before doing EEProm stuff -
265 * because the EEProm is accessed via i2c */
266 ret = flexcop_i2c_init(fc);
267 if (ret)
268 goto error;
269
260 /* do the MAC address reading after initializing the dvb_adapter */ 270 /* do the MAC address reading after initializing the dvb_adapter */
261 if (fc->get_mac_addr(fc, 0) == 0) { 271 if (fc->get_mac_addr(fc, 0) == 0) {
262 u8 *b = fc->dvb_adapter.proposed_mac; 272 u8 *b = fc->dvb_adapter.proposed_mac;
@@ -266,10 +276,6 @@ int flexcop_device_initialize(struct flexcop_device *fc)
266 } else 276 } else
267 warn("reading of MAC address failed.\n"); 277 warn("reading of MAC address failed.\n");
268 278
269
270 if ((ret = flexcop_i2c_init(fc)))
271 goto error;
272
273 if ((ret = flexcop_frontend_init(fc))) 279 if ((ret = flexcop_frontend_init(fc)))
274 goto error; 280 goto error;
275 281
diff --git a/drivers/media/dvb/bt8xx/Kconfig b/drivers/media/dvb/bt8xx/Kconfig
index ea666174e988..902c762e0b7f 100644
--- a/drivers/media/dvb/bt8xx/Kconfig
+++ b/drivers/media/dvb/bt8xx/Kconfig
@@ -7,8 +7,8 @@ config DVB_BT8XX
7 select DVB_CX24110 if !DVB_FE_CUSTOMISE 7 select DVB_CX24110 if !DVB_FE_CUSTOMISE
8 select DVB_OR51211 if !DVB_FE_CUSTOMISE 8 select DVB_OR51211 if !DVB_FE_CUSTOMISE
9 select DVB_LGDT330X if !DVB_FE_CUSTOMISE 9 select DVB_LGDT330X if !DVB_FE_CUSTOMISE
10 select DVB_PLL if !DVB_FE_CUSTOMISE
11 select DVB_ZL10353 if !DVB_FE_CUSTOMISE 10 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
11 select TUNER_SIMPLE if !DVB_FE_CUSTOMISE
12 select FW_LOADER 12 select FW_LOADER
13 help 13 help
14 Support for PCI cards based on the Bt8xx PCI bridge. Examples are 14 Support for PCI cards based on the Bt8xx PCI bridge. Examples are
diff --git a/drivers/media/dvb/bt8xx/Makefile b/drivers/media/dvb/bt8xx/Makefile
index 84cf70504d17..9d3e68b5d6eb 100644
--- a/drivers/media/dvb/bt8xx/Makefile
+++ b/drivers/media/dvb/bt8xx/Makefile
@@ -1,3 +1,6 @@
1obj-$(CONFIG_DVB_BT8XX) += bt878.o dvb-bt8xx.o dst.o dst_ca.o 1obj-$(CONFIG_DVB_BT8XX) += bt878.o dvb-bt8xx.o dst.o dst_ca.o
2 2
3EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/video/bt8xx -Idrivers/media/dvb/frontends 3EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
4EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
5EXTRA_CFLAGS += -Idrivers/media/video/bt8xx
6EXTRA_CFLAGS += -Idrivers/media/video
diff --git a/drivers/media/dvb/bt8xx/dst.c b/drivers/media/dvb/bt8xx/dst.c
index 307ff35bdf13..75711bde23ad 100644
--- a/drivers/media/dvb/bt8xx/dst.c
+++ b/drivers/media/dvb/bt8xx/dst.c
@@ -1290,7 +1290,7 @@ static int dst_get_signal(struct dst_state *state)
1290{ 1290{
1291 int retval; 1291 int retval;
1292 u8 get_signal[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb }; 1292 u8 get_signal[] = { 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfb };
1293 //dprintk("%s: Getting Signal strength and other parameters\n", __FUNCTION__); 1293 //dprintk("%s: Getting Signal strength and other parameters\n", __func__);
1294 if ((state->diseq_flags & ATTEMPT_TUNE) == 0) { 1294 if ((state->diseq_flags & ATTEMPT_TUNE) == 0) {
1295 state->decode_lock = state->decode_strength = state->decode_snr = 0; 1295 state->decode_lock = state->decode_strength = state->decode_snr = 0;
1296 return 0; 1296 return 0;
diff --git a/drivers/media/dvb/bt8xx/dst_ca.c b/drivers/media/dvb/bt8xx/dst_ca.c
index 50bc32a8bd55..0258451423ad 100644
--- a/drivers/media/dvb/bt8xx/dst_ca.c
+++ b/drivers/media/dvb/bt8xx/dst_ca.c
@@ -36,13 +36,13 @@
36#define dprintk(x, y, z, format, arg...) do { \ 36#define dprintk(x, y, z, format, arg...) do { \
37 if (z) { \ 37 if (z) { \
38 if ((x > DST_CA_ERROR) && (x > y)) \ 38 if ((x > DST_CA_ERROR) && (x > y)) \
39 printk(KERN_ERR "%s: " format "\n", __FUNCTION__ , ##arg); \ 39 printk(KERN_ERR "%s: " format "\n", __func__ , ##arg); \
40 else if ((x > DST_CA_NOTICE) && (x > y)) \ 40 else if ((x > DST_CA_NOTICE) && (x > y)) \
41 printk(KERN_NOTICE "%s: " format "\n", __FUNCTION__ , ##arg); \ 41 printk(KERN_NOTICE "%s: " format "\n", __func__ , ##arg); \
42 else if ((x > DST_CA_INFO) && (x > y)) \ 42 else if ((x > DST_CA_INFO) && (x > y)) \
43 printk(KERN_INFO "%s: " format "\n", __FUNCTION__ , ##arg); \ 43 printk(KERN_INFO "%s: " format "\n", __func__ , ##arg); \
44 else if ((x > DST_CA_DEBUG) && (x > y)) \ 44 else if ((x > DST_CA_DEBUG) && (x > y)) \
45 printk(KERN_DEBUG "%s: " format "\n", __FUNCTION__ , ##arg); \ 45 printk(KERN_DEBUG "%s: " format "\n", __func__ , ##arg); \
46 } else { \ 46 } else { \
47 if (x > y) \ 47 if (x > y) \
48 printk(format, ## arg); \ 48 printk(format, ## arg); \
@@ -162,7 +162,7 @@ static int ca_get_app_info(struct dst_state *state)
162 dprintk(verbose, DST_CA_INFO, 1, " ================================ CI Module Application Info ======================================"); 162 dprintk(verbose, DST_CA_INFO, 1, " ================================ CI Module Application Info ======================================");
163 dprintk(verbose, DST_CA_INFO, 1, " Application Type=[%d], Application Vendor=[%d], Vendor Code=[%d]\n%s: Application info=[%s]", 163 dprintk(verbose, DST_CA_INFO, 1, " Application Type=[%d], Application Vendor=[%d], Vendor Code=[%d]\n%s: Application info=[%s]",
164 state->messages[7], (state->messages[8] << 8) | state->messages[9], 164 state->messages[7], (state->messages[8] << 8) | state->messages[9],
165 (state->messages[10] << 8) | state->messages[11], __FUNCTION__, (char *)(&state->messages[12])); 165 (state->messages[10] << 8) | state->messages[11], __func__, (char *)(&state->messages[12]));
166 dprintk(verbose, DST_CA_INFO, 1, " =================================================================================================="); 166 dprintk(verbose, DST_CA_INFO, 1, " ==================================================================================================");
167 167
168 // Transform dst message to correct application_info message 168 // Transform dst message to correct application_info message
diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.c b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
index dedd30a8356b..6afbfbbef0ce 100644
--- a/drivers/media/dvb/bt8xx/dvb-bt8xx.c
+++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.c
@@ -40,10 +40,12 @@ static int debug;
40module_param(debug, int, 0644); 40module_param(debug, int, 0644);
41MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off)."); 41MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
42 42
43DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
44
43#define dprintk( args... ) \ 45#define dprintk( args... ) \
44 do \ 46 do { \
45 if (debug) printk(KERN_DEBUG args); \ 47 if (debug) printk(KERN_DEBUG args); \
46 while (0) 48 } while (0)
47 49
48#define IF_FREQUENCYx6 217 /* 6 * 36.16666666667MHz */ 50#define IF_FREQUENCYx6 217 /* 6 * 36.16666666667MHz */
49 51
@@ -609,8 +611,9 @@ static void frontend_init(struct dvb_bt8xx_card *card, u32 type)
609 lgdt330x_reset(card); 611 lgdt330x_reset(card);
610 card->fe = dvb_attach(lgdt330x_attach, &tdvs_tua6034_config, card->i2c_adapter); 612 card->fe = dvb_attach(lgdt330x_attach, &tdvs_tua6034_config, card->i2c_adapter);
611 if (card->fe != NULL) { 613 if (card->fe != NULL) {
612 dvb_attach(dvb_pll_attach, card->fe, 0x61, 614 dvb_attach(simple_tuner_attach, card->fe,
613 card->i2c_adapter, DVB_PLL_LG_TDVS_H06XF); 615 card->i2c_adapter, 0x61,
616 TUNER_LG_TDVS_H06XF);
614 dprintk ("dvb_bt8xx: lgdt330x detected\n"); 617 dprintk ("dvb_bt8xx: lgdt330x detected\n");
615 } 618 }
616 break; 619 break;
@@ -670,7 +673,7 @@ static void frontend_init(struct dvb_bt8xx_card *card, u32 type)
670 state->dst_ca = NULL; 673 state->dst_ca = NULL;
671 /* DST is not a frontend, attaching the ASIC */ 674 /* DST is not a frontend, attaching the ASIC */
672 if (dvb_attach(dst_attach, state, &card->dvb_adapter) == NULL) { 675 if (dvb_attach(dst_attach, state, &card->dvb_adapter) == NULL) {
673 printk("%s: Could not find a Twinhan DST.\n", __FUNCTION__); 676 printk("%s: Could not find a Twinhan DST.\n", __func__);
674 break; 677 break;
675 } 678 }
676 /* Attach other DST peripherals if any */ 679 /* Attach other DST peripherals if any */
@@ -692,8 +695,9 @@ static void frontend_init(struct dvb_bt8xx_card *card, u32 type)
692 case BTTV_BOARD_PC_HDTV: 695 case BTTV_BOARD_PC_HDTV:
693 card->fe = dvb_attach(or51211_attach, &or51211_config, card->i2c_adapter); 696 card->fe = dvb_attach(or51211_attach, &or51211_config, card->i2c_adapter);
694 if (card->fe != NULL) 697 if (card->fe != NULL)
695 dvb_attach(dvb_pll_attach, card->fe, 0x61, 698 dvb_attach(simple_tuner_attach, card->fe,
696 card->i2c_adapter, DVB_PLL_FCV1236D); 699 card->i2c_adapter, 0x61,
700 TUNER_PHILIPS_FCV1236D);
697 break; 701 break;
698 } 702 }
699 703
@@ -715,7 +719,10 @@ static int __devinit dvb_bt8xx_load_card(struct dvb_bt8xx_card *card, u32 type)
715{ 719{
716 int result; 720 int result;
717 721
718 if ((result = dvb_register_adapter(&card->dvb_adapter, card->card_name, THIS_MODULE, &card->bt->dev->dev)) < 0) { 722 result = dvb_register_adapter(&card->dvb_adapter, card->card_name,
723 THIS_MODULE, &card->bt->dev->dev,
724 adapter_nr);
725 if (result < 0) {
719 printk("dvb_bt8xx: dvb_register_adapter failed (errno = %d)\n", result); 726 printk("dvb_bt8xx: dvb_register_adapter failed (errno = %d)\n", result);
720 return result; 727 return result;
721 } 728 }
diff --git a/drivers/media/dvb/bt8xx/dvb-bt8xx.h b/drivers/media/dvb/bt8xx/dvb-bt8xx.h
index 436880e68672..4499ed2ac0ed 100644
--- a/drivers/media/dvb/bt8xx/dvb-bt8xx.h
+++ b/drivers/media/dvb/bt8xx/dvb-bt8xx.h
@@ -38,7 +38,7 @@
38#include "or51211.h" 38#include "or51211.h"
39#include "lgdt330x.h" 39#include "lgdt330x.h"
40#include "zl10353.h" 40#include "zl10353.h"
41#include "dvb-pll.h" 41#include "tuner-simple.h"
42 42
43struct dvb_bt8xx_card { 43struct dvb_bt8xx_card {
44 struct mutex lock; 44 struct mutex lock;
diff --git a/drivers/media/dvb/cinergyT2/cinergyT2.c b/drivers/media/dvb/cinergyT2/cinergyT2.c
index db08b0a8888a..f5010e8671b8 100644
--- a/drivers/media/dvb/cinergyT2/cinergyT2.c
+++ b/drivers/media/dvb/cinergyT2/cinergyT2.c
@@ -58,11 +58,13 @@ static int debug;
58module_param_named(debug, debug, int, 0644); 58module_param_named(debug, debug, int, 0644);
59MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off)."); 59MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
60 60
61DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
62
61#define dprintk(level, args...) \ 63#define dprintk(level, args...) \
62do { \ 64do { \
63 if ((debug & level)) { \ 65 if ((debug & level)) { \
64 printk("%s: %s(): ", KBUILD_MODNAME, \ 66 printk("%s: %s(): ", KBUILD_MODNAME, \
65 __FUNCTION__); \ 67 __func__); \
66 printk(args); } \ 68 printk(args); } \
67} while (0) 69} while (0)
68 70
@@ -938,7 +940,10 @@ static int cinergyt2_probe (struct usb_interface *intf,
938 return -ENOMEM; 940 return -ENOMEM;
939 } 941 }
940 942
941 if ((err = dvb_register_adapter(&cinergyt2->adapter, DRIVER_NAME, THIS_MODULE, &cinergyt2->udev->dev)) < 0) { 943 err = dvb_register_adapter(&cinergyt2->adapter, DRIVER_NAME,
944 THIS_MODULE, &cinergyt2->udev->dev,
945 adapter_nr);
946 if (err < 0) {
942 kfree(cinergyt2); 947 kfree(cinergyt2);
943 return err; 948 return err;
944 } 949 }
diff --git a/drivers/media/dvb/dvb-core/demux.h b/drivers/media/dvb/dvb-core/demux.h
index 0c1d87c5227a..b0d347daae47 100644
--- a/drivers/media/dvb/dvb-core/demux.h
+++ b/drivers/media/dvb/dvb-core/demux.h
@@ -80,6 +80,8 @@ enum dmx_success {
80#define TS_PAYLOAD_ONLY 2 /* in case TS_PACKET is set, only send the TS 80#define TS_PAYLOAD_ONLY 2 /* in case TS_PACKET is set, only send the TS
81 payload (<=184 bytes per packet) to callback */ 81 payload (<=184 bytes per packet) to callback */
82#define TS_DECODER 4 /* send stream to built-in decoder (if present) */ 82#define TS_DECODER 4 /* send stream to built-in decoder (if present) */
83#define TS_DEMUX 8 /* in case TS_PACKET is set, send the TS to
84 the demux device, not to the dvr device */
83 85
84/* PES type for filters which write to built-in decoder */ 86/* PES type for filters which write to built-in decoder */
85/* these should be kept identical to the types in dmx.h */ 87/* these should be kept identical to the types in dmx.h */
diff --git a/drivers/media/dvb/dvb-core/dmxdev.c b/drivers/media/dvb/dvb-core/dmxdev.c
index f94bc31e3b33..df5bef6a2517 100644
--- a/drivers/media/dvb/dvb-core/dmxdev.c
+++ b/drivers/media/dvb/dvb-core/dmxdev.c
@@ -126,7 +126,7 @@ static int dvb_dvr_open(struct inode *inode, struct file *file)
126 struct dmxdev *dmxdev = dvbdev->priv; 126 struct dmxdev *dmxdev = dvbdev->priv;
127 struct dmx_frontend *front; 127 struct dmx_frontend *front;
128 128
129 dprintk("function : %s\n", __FUNCTION__); 129 dprintk("function : %s\n", __func__);
130 130
131 if (mutex_lock_interruptible(&dmxdev->mutex)) 131 if (mutex_lock_interruptible(&dmxdev->mutex))
132 return -ERESTARTSYS; 132 return -ERESTARTSYS;
@@ -259,6 +259,39 @@ static ssize_t dvb_dvr_read(struct file *file, char __user *buf, size_t count,
259 return ret; 259 return ret;
260} 260}
261 261
262static int dvb_dvr_set_buffer_size(struct dmxdev *dmxdev,
263 unsigned long size)
264{
265 struct dvb_ringbuffer *buf = &dmxdev->dvr_buffer;
266 void *newmem;
267 void *oldmem;
268
269 dprintk("function : %s\n", __func__);
270
271 if (buf->size == size)
272 return 0;
273 if (!size)
274 return -EINVAL;
275
276 newmem = vmalloc(size);
277 if (!newmem)
278 return -ENOMEM;
279
280 oldmem = buf->data;
281
282 spin_lock_irq(&dmxdev->lock);
283 buf->data = newmem;
284 buf->size = size;
285
286 /* reset and not flush in case the buffer shrinks */
287 dvb_ringbuffer_reset(buf);
288 spin_unlock_irq(&dmxdev->lock);
289
290 vfree(oldmem);
291
292 return 0;
293}
294
262static inline void dvb_dmxdev_filter_state_set(struct dmxdev_filter 295static inline void dvb_dmxdev_filter_state_set(struct dmxdev_filter
263 *dmxdevfilter, int state) 296 *dmxdevfilter, int state)
264{ 297{
@@ -271,28 +304,32 @@ static int dvb_dmxdev_set_buffer_size(struct dmxdev_filter *dmxdevfilter,
271 unsigned long size) 304 unsigned long size)
272{ 305{
273 struct dvb_ringbuffer *buf = &dmxdevfilter->buffer; 306 struct dvb_ringbuffer *buf = &dmxdevfilter->buffer;
274 void *mem; 307 void *newmem;
308 void *oldmem;
275 309
276 if (buf->size == size) 310 if (buf->size == size)
277 return 0; 311 return 0;
312 if (!size)
313 return -EINVAL;
278 if (dmxdevfilter->state >= DMXDEV_STATE_GO) 314 if (dmxdevfilter->state >= DMXDEV_STATE_GO)
279 return -EBUSY; 315 return -EBUSY;
316
317 newmem = vmalloc(size);
318 if (!newmem)
319 return -ENOMEM;
320
321 oldmem = buf->data;
322
280 spin_lock_irq(&dmxdevfilter->dev->lock); 323 spin_lock_irq(&dmxdevfilter->dev->lock);
281 mem = buf->data; 324 buf->data = newmem;
282 buf->data = NULL;
283 buf->size = size; 325 buf->size = size;
284 dvb_ringbuffer_flush(buf); 326
327 /* reset and not flush in case the buffer shrinks */
328 dvb_ringbuffer_reset(buf);
285 spin_unlock_irq(&dmxdevfilter->dev->lock); 329 spin_unlock_irq(&dmxdevfilter->dev->lock);
286 vfree(mem);
287 330
288 if (buf->size) { 331 vfree(oldmem);
289 mem = vmalloc(dmxdevfilter->buffer.size); 332
290 if (!mem)
291 return -ENOMEM;
292 spin_lock_irq(&dmxdevfilter->dev->lock);
293 buf->data = mem;
294 spin_unlock_irq(&dmxdevfilter->dev->lock);
295 }
296 return 0; 333 return 0;
297} 334}
298 335
@@ -374,7 +411,8 @@ static int dvb_dmxdev_ts_callback(const u8 *buffer1, size_t buffer1_len,
374 return 0; 411 return 0;
375 } 412 }
376 413
377 if (dmxdevfilter->params.pes.output == DMX_OUT_TAP) 414 if (dmxdevfilter->params.pes.output == DMX_OUT_TAP
415 || dmxdevfilter->params.pes.output == DMX_OUT_TSDEMUX_TAP)
378 buffer = &dmxdevfilter->buffer; 416 buffer = &dmxdevfilter->buffer;
379 else 417 else
380 buffer = &dmxdevfilter->dev->dvr_buffer; 418 buffer = &dmxdevfilter->dev->dvr_buffer;
@@ -550,7 +588,7 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter)
550 dvb_dmxdev_section_callback); 588 dvb_dmxdev_section_callback);
551 if (ret < 0) { 589 if (ret < 0) {
552 printk("DVB (%s): could not alloc feed\n", 590 printk("DVB (%s): could not alloc feed\n",
553 __FUNCTION__); 591 __func__);
554 return ret; 592 return ret;
555 } 593 }
556 594
@@ -558,7 +596,7 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter)
558 (para->flags & DMX_CHECK_CRC) ? 1 : 0); 596 (para->flags & DMX_CHECK_CRC) ? 1 : 0);
559 if (ret < 0) { 597 if (ret < 0) {
560 printk("DVB (%s): could not set feed\n", 598 printk("DVB (%s): could not set feed\n",
561 __FUNCTION__); 599 __func__);
562 dvb_dmxdev_feed_restart(filter); 600 dvb_dmxdev_feed_restart(filter);
563 return ret; 601 return ret;
564 } 602 }
@@ -620,9 +658,10 @@ static int dvb_dmxdev_filter_start(struct dmxdev_filter *filter)
620 658
621 if (otype == DMX_OUT_TS_TAP) 659 if (otype == DMX_OUT_TS_TAP)
622 ts_type |= TS_PACKET; 660 ts_type |= TS_PACKET;
623 661 else if (otype == DMX_OUT_TSDEMUX_TAP)
624 if (otype == DMX_OUT_TAP) 662 ts_type |= TS_PACKET | TS_DEMUX;
625 ts_type |= TS_PAYLOAD_ONLY | TS_PACKET; 663 else if (otype == DMX_OUT_TAP)
664 ts_type |= TS_PACKET | TS_DEMUX | TS_PAYLOAD_ONLY;
626 665
627 ret = dmxdev->demux->allocate_ts_feed(dmxdev->demux, 666 ret = dmxdev->demux->allocate_ts_feed(dmxdev->demux,
628 tsfeed, 667 tsfeed,
@@ -732,7 +771,7 @@ static int dvb_dmxdev_filter_set(struct dmxdev *dmxdev,
732 struct dmxdev_filter *dmxdevfilter, 771 struct dmxdev_filter *dmxdevfilter,
733 struct dmx_sct_filter_params *params) 772 struct dmx_sct_filter_params *params)
734{ 773{
735 dprintk("function : %s\n", __FUNCTION__); 774 dprintk("function : %s\n", __func__);
736 775
737 dvb_dmxdev_filter_stop(dmxdevfilter); 776 dvb_dmxdev_filter_stop(dmxdevfilter);
738 777
@@ -1007,6 +1046,7 @@ static int dvb_dvr_do_ioctl(struct inode *inode, struct file *file,
1007{ 1046{
1008 struct dvb_device *dvbdev = file->private_data; 1047 struct dvb_device *dvbdev = file->private_data;
1009 struct dmxdev *dmxdev = dvbdev->priv; 1048 struct dmxdev *dmxdev = dvbdev->priv;
1049 unsigned long arg = (unsigned long)parg;
1010 int ret; 1050 int ret;
1011 1051
1012 if (mutex_lock_interruptible(&dmxdev->mutex)) 1052 if (mutex_lock_interruptible(&dmxdev->mutex))
@@ -1014,8 +1054,7 @@ static int dvb_dvr_do_ioctl(struct inode *inode, struct file *file,
1014 1054
1015 switch (cmd) { 1055 switch (cmd) {
1016 case DMX_SET_BUFFER_SIZE: 1056 case DMX_SET_BUFFER_SIZE:
1017 // FIXME: implement 1057 ret = dvb_dvr_set_buffer_size(dmxdev, arg);
1018 ret = 0;
1019 break; 1058 break;
1020 1059
1021 default: 1060 default:
@@ -1038,7 +1077,7 @@ static unsigned int dvb_dvr_poll(struct file *file, poll_table *wait)
1038 struct dmxdev *dmxdev = dvbdev->priv; 1077 struct dmxdev *dmxdev = dvbdev->priv;
1039 unsigned int mask = 0; 1078 unsigned int mask = 0;
1040 1079
1041 dprintk("function : %s\n", __FUNCTION__); 1080 dprintk("function : %s\n", __func__);
1042 1081
1043 poll_wait(file, &dmxdev->dvr_buffer.queue, wait); 1082 poll_wait(file, &dmxdev->dvr_buffer.queue, wait);
1044 1083
diff --git a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
index 89437fdab8be..8cbdb0ec67e2 100644
--- a/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
+++ b/drivers/media/dvb/dvb-core/dvb_ca_en50221.c
@@ -250,7 +250,7 @@ static int dvb_ca_en50221_wait_if_status(struct dvb_ca_private *ca, int slot,
250 unsigned long timeout; 250 unsigned long timeout;
251 unsigned long start; 251 unsigned long start;
252 252
253 dprintk("%s\n", __FUNCTION__); 253 dprintk("%s\n", __func__);
254 254
255 /* loop until timeout elapsed */ 255 /* loop until timeout elapsed */
256 start = jiffies; 256 start = jiffies;
@@ -263,7 +263,7 @@ static int dvb_ca_en50221_wait_if_status(struct dvb_ca_private *ca, int slot,
263 263
264 /* if we got the flags, it was successful! */ 264 /* if we got the flags, it was successful! */
265 if (res & waitfor) { 265 if (res & waitfor) {
266 dprintk("%s succeeded timeout:%lu\n", __FUNCTION__, jiffies - start); 266 dprintk("%s succeeded timeout:%lu\n", __func__, jiffies - start);
267 return 0; 267 return 0;
268 } 268 }
269 269
@@ -276,7 +276,7 @@ static int dvb_ca_en50221_wait_if_status(struct dvb_ca_private *ca, int slot,
276 msleep(1); 276 msleep(1);
277 } 277 }
278 278
279 dprintk("%s failed timeout:%lu\n", __FUNCTION__, jiffies - start); 279 dprintk("%s failed timeout:%lu\n", __func__, jiffies - start);
280 280
281 /* if we get here, we've timed out */ 281 /* if we get here, we've timed out */
282 return -ETIMEDOUT; 282 return -ETIMEDOUT;
@@ -297,7 +297,7 @@ static int dvb_ca_en50221_link_init(struct dvb_ca_private *ca, int slot)
297 int buf_size; 297 int buf_size;
298 u8 buf[2]; 298 u8 buf[2];
299 299
300 dprintk("%s\n", __FUNCTION__); 300 dprintk("%s\n", __func__);
301 301
302 /* we'll be determining these during this function */ 302 /* we'll be determining these during this function */
303 ca->slot_info[slot].da_irq_supported = 0; 303 ca->slot_info[slot].da_irq_supported = 0;
@@ -549,7 +549,7 @@ static int dvb_ca_en50221_set_configoption(struct dvb_ca_private *ca, int slot)
549{ 549{
550 int configoption; 550 int configoption;
551 551
552 dprintk("%s\n", __FUNCTION__); 552 dprintk("%s\n", __func__);
553 553
554 /* set the config option */ 554 /* set the config option */
555 ca->pub->write_attribute_mem(ca->pub, slot, 555 ca->pub->write_attribute_mem(ca->pub, slot,
@@ -587,7 +587,7 @@ static int dvb_ca_en50221_read_data(struct dvb_ca_private *ca, int slot, u8 * eb
587 u8 buf[HOST_LINK_BUF_SIZE]; 587 u8 buf[HOST_LINK_BUF_SIZE];
588 int i; 588 int i;
589 589
590 dprintk("%s\n", __FUNCTION__); 590 dprintk("%s\n", __func__);
591 591
592 /* check if we have space for a link buf in the rx_buffer */ 592 /* check if we have space for a link buf in the rx_buffer */
593 if (ebuf == NULL) { 593 if (ebuf == NULL) {
@@ -708,7 +708,7 @@ static int dvb_ca_en50221_write_data(struct dvb_ca_private *ca, int slot, u8 * b
708 int status; 708 int status;
709 int i; 709 int i;
710 710
711 dprintk("%s\n", __FUNCTION__); 711 dprintk("%s\n", __func__);
712 712
713 713
714 // sanity check 714 // sanity check
@@ -785,7 +785,7 @@ EXPORT_SYMBOL(dvb_ca_en50221_camchange_irq);
785 */ 785 */
786static int dvb_ca_en50221_slot_shutdown(struct dvb_ca_private *ca, int slot) 786static int dvb_ca_en50221_slot_shutdown(struct dvb_ca_private *ca, int slot)
787{ 787{
788 dprintk("%s\n", __FUNCTION__); 788 dprintk("%s\n", __func__);
789 789
790 ca->pub->slot_shutdown(ca->pub, slot); 790 ca->pub->slot_shutdown(ca->pub, slot);
791 ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_NONE; 791 ca->slot_info[slot].slot_state = DVB_CA_SLOTSTATE_NONE;
@@ -892,7 +892,7 @@ void dvb_ca_en50221_frda_irq(struct dvb_ca_en50221 *pubca, int slot)
892static void dvb_ca_en50221_thread_wakeup(struct dvb_ca_private *ca) 892static void dvb_ca_en50221_thread_wakeup(struct dvb_ca_private *ca)
893{ 893{
894 894
895 dprintk("%s\n", __FUNCTION__); 895 dprintk("%s\n", __func__);
896 896
897 ca->wakeup = 1; 897 ca->wakeup = 1;
898 mb(); 898 mb();
@@ -964,7 +964,7 @@ static int dvb_ca_en50221_thread(void *data)
964 int pktcount; 964 int pktcount;
965 void *rxbuf; 965 void *rxbuf;
966 966
967 dprintk("%s\n", __FUNCTION__); 967 dprintk("%s\n", __func__);
968 968
969 /* choose the correct initial delay */ 969 /* choose the correct initial delay */
970 dvb_ca_en50221_thread_update_delay(ca); 970 dvb_ca_en50221_thread_update_delay(ca);
@@ -1172,7 +1172,7 @@ static int dvb_ca_en50221_io_do_ioctl(struct inode *inode, struct file *file,
1172 int err = 0; 1172 int err = 0;
1173 int slot; 1173 int slot;
1174 1174
1175 dprintk("%s\n", __FUNCTION__); 1175 dprintk("%s\n", __func__);
1176 1176
1177 switch (cmd) { 1177 switch (cmd) {
1178 case CA_RESET: 1178 case CA_RESET:
@@ -1266,7 +1266,7 @@ static ssize_t dvb_ca_en50221_io_write(struct file *file,
1266 unsigned long timeout; 1266 unsigned long timeout;
1267 int written; 1267 int written;
1268 1268
1269 dprintk("%s\n", __FUNCTION__); 1269 dprintk("%s\n", __func__);
1270 1270
1271 /* Incoming packet has a 2 byte header. hdr[0] = slot_id, hdr[1] = connection_id */ 1271 /* Incoming packet has a 2 byte header. hdr[0] = slot_id, hdr[1] = connection_id */
1272 if (count < 2) 1272 if (count < 2)
@@ -1401,7 +1401,7 @@ static ssize_t dvb_ca_en50221_io_read(struct file *file, char __user * buf,
1401 int pktlen; 1401 int pktlen;
1402 int dispose = 0; 1402 int dispose = 0;
1403 1403
1404 dprintk("%s\n", __FUNCTION__); 1404 dprintk("%s\n", __func__);
1405 1405
1406 /* Outgoing packet has a 2 byte header. hdr[0] = slot_id, hdr[1] = connection_id */ 1406 /* Outgoing packet has a 2 byte header. hdr[0] = slot_id, hdr[1] = connection_id */
1407 if (count < 2) 1407 if (count < 2)
@@ -1490,7 +1490,7 @@ static int dvb_ca_en50221_io_open(struct inode *inode, struct file *file)
1490 int err; 1490 int err;
1491 int i; 1491 int i;
1492 1492
1493 dprintk("%s\n", __FUNCTION__); 1493 dprintk("%s\n", __func__);
1494 1494
1495 if (!try_module_get(ca->pub->owner)) 1495 if (!try_module_get(ca->pub->owner))
1496 return -EIO; 1496 return -EIO;
@@ -1534,7 +1534,7 @@ static int dvb_ca_en50221_io_release(struct inode *inode, struct file *file)
1534 struct dvb_ca_private *ca = dvbdev->priv; 1534 struct dvb_ca_private *ca = dvbdev->priv;
1535 int err; 1535 int err;
1536 1536
1537 dprintk("%s\n", __FUNCTION__); 1537 dprintk("%s\n", __func__);
1538 1538
1539 /* mark the CA device as closed */ 1539 /* mark the CA device as closed */
1540 ca->open = 0; 1540 ca->open = 0;
@@ -1564,7 +1564,7 @@ static unsigned int dvb_ca_en50221_io_poll(struct file *file, poll_table * wait)
1564 int slot; 1564 int slot;
1565 int result = 0; 1565 int result = 0;
1566 1566
1567 dprintk("%s\n", __FUNCTION__); 1567 dprintk("%s\n", __func__);
1568 1568
1569 if (dvb_ca_en50221_io_read_condition(ca, &result, &slot) == 1) { 1569 if (dvb_ca_en50221_io_read_condition(ca, &result, &slot) == 1) {
1570 mask |= POLLIN; 1570 mask |= POLLIN;
@@ -1626,7 +1626,7 @@ int dvb_ca_en50221_init(struct dvb_adapter *dvb_adapter,
1626 struct dvb_ca_private *ca = NULL; 1626 struct dvb_ca_private *ca = NULL;
1627 int i; 1627 int i;
1628 1628
1629 dprintk("%s\n", __FUNCTION__); 1629 dprintk("%s\n", __func__);
1630 1630
1631 if (slot_count < 1) 1631 if (slot_count < 1)
1632 return -EINVAL; 1632 return -EINVAL;
@@ -1704,7 +1704,7 @@ void dvb_ca_en50221_release(struct dvb_ca_en50221 *pubca)
1704 struct dvb_ca_private *ca = pubca->private; 1704 struct dvb_ca_private *ca = pubca->private;
1705 int i; 1705 int i;
1706 1706
1707 dprintk("%s\n", __FUNCTION__); 1707 dprintk("%s\n", __func__);
1708 1708
1709 /* shutdown the thread if there was one */ 1709 /* shutdown the thread if there was one */
1710 kthread_stop(ca->thread); 1710 kthread_stop(ca->thread);
diff --git a/drivers/media/dvb/dvb-core/dvb_demux.c b/drivers/media/dvb/dvb-core/dvb_demux.c
index 7959020f9317..934e15fffc56 100644
--- a/drivers/media/dvb/dvb-core/dvb_demux.c
+++ b/drivers/media/dvb/dvb-core/dvb_demux.c
@@ -368,7 +368,7 @@ static inline void dvb_dmx_swfilter_packet_type(struct dvb_demux_feed *feed,
368#define DVR_FEED(f) \ 368#define DVR_FEED(f) \
369 (((f)->type == DMX_TYPE_TS) && \ 369 (((f)->type == DMX_TYPE_TS) && \
370 ((f)->feed.ts.is_filtering) && \ 370 ((f)->feed.ts.is_filtering) && \
371 (((f)->ts_type & (TS_PACKET|TS_PAYLOAD_ONLY)) == TS_PACKET)) 371 (((f)->ts_type & (TS_PACKET | TS_DEMUX)) == TS_PACKET))
372 372
373static void dvb_dmx_swfilter_packet(struct dvb_demux *demux, const u8 *buf) 373static void dvb_dmx_swfilter_packet(struct dvb_demux *demux, const u8 *buf)
374{ 374{
@@ -553,7 +553,7 @@ static void dvb_demux_feed_add(struct dvb_demux_feed *feed)
553 spin_lock_irq(&feed->demux->lock); 553 spin_lock_irq(&feed->demux->lock);
554 if (dvb_demux_feed_find(feed)) { 554 if (dvb_demux_feed_find(feed)) {
555 printk(KERN_ERR "%s: feed already in list (type=%x state=%x pid=%x)\n", 555 printk(KERN_ERR "%s: feed already in list (type=%x state=%x pid=%x)\n",
556 __FUNCTION__, feed->type, feed->state, feed->pid); 556 __func__, feed->type, feed->state, feed->pid);
557 goto out; 557 goto out;
558 } 558 }
559 559
@@ -567,7 +567,7 @@ static void dvb_demux_feed_del(struct dvb_demux_feed *feed)
567 spin_lock_irq(&feed->demux->lock); 567 spin_lock_irq(&feed->demux->lock);
568 if (!(dvb_demux_feed_find(feed))) { 568 if (!(dvb_demux_feed_find(feed))) {
569 printk(KERN_ERR "%s: feed not in list (type=%x state=%x pid=%x)\n", 569 printk(KERN_ERR "%s: feed not in list (type=%x state=%x pid=%x)\n",
570 __FUNCTION__, feed->type, feed->state, feed->pid); 570 __func__, feed->type, feed->state, feed->pid);
571 goto out; 571 goto out;
572 } 572 }
573 573
diff --git a/drivers/media/dvb/dvb-core/dvb_frontend.c b/drivers/media/dvb/dvb-core/dvb_frontend.c
index 925cfa6221ad..2dddd08c5445 100644
--- a/drivers/media/dvb/dvb-core/dvb_frontend.c
+++ b/drivers/media/dvb/dvb-core/dvb_frontend.c
@@ -135,7 +135,7 @@ static void dvb_frontend_add_event(struct dvb_frontend *fe, fe_status_t status)
135 struct dvb_frontend_event *e; 135 struct dvb_frontend_event *e;
136 int wp; 136 int wp;
137 137
138 dprintk ("%s\n", __FUNCTION__); 138 dprintk ("%s\n", __func__);
139 139
140 if (mutex_lock_interruptible (&events->mtx)) 140 if (mutex_lock_interruptible (&events->mtx))
141 return; 141 return;
@@ -171,7 +171,7 @@ static int dvb_frontend_get_event(struct dvb_frontend *fe,
171 struct dvb_frontend_private *fepriv = fe->frontend_priv; 171 struct dvb_frontend_private *fepriv = fe->frontend_priv;
172 struct dvb_fe_events *events = &fepriv->events; 172 struct dvb_fe_events *events = &fepriv->events;
173 173
174 dprintk ("%s\n", __FUNCTION__); 174 dprintk ("%s\n", __func__);
175 175
176 if (events->overflow) { 176 if (events->overflow) {
177 events->overflow = 0; 177 events->overflow = 0;
@@ -237,7 +237,7 @@ static void dvb_frontend_swzigzag_update_delay(struct dvb_frontend_private *fepr
237{ 237{
238 int q2; 238 int q2;
239 239
240 dprintk ("%s\n", __FUNCTION__); 240 dprintk ("%s\n", __func__);
241 241
242 if (locked) 242 if (locked)
243 (fepriv->quality) = (fepriv->quality * 220 + 36*256) / 256; 243 (fepriv->quality) = (fepriv->quality * 220 + 36*256) / 256;
@@ -329,7 +329,7 @@ static int dvb_frontend_swzigzag_autotune(struct dvb_frontend *fe, int check_wra
329 329
330 dprintk("%s: drift:%i inversion:%i auto_step:%i " 330 dprintk("%s: drift:%i inversion:%i auto_step:%i "
331 "auto_sub_step:%i started_auto_step:%i\n", 331 "auto_sub_step:%i started_auto_step:%i\n",
332 __FUNCTION__, fepriv->lnb_drift, fepriv->inversion, 332 __func__, fepriv->lnb_drift, fepriv->inversion,
333 fepriv->auto_step, fepriv->auto_sub_step, fepriv->started_auto_step); 333 fepriv->auto_step, fepriv->auto_sub_step, fepriv->started_auto_step);
334 334
335 /* set the frontend itself */ 335 /* set the frontend itself */
@@ -511,7 +511,7 @@ static int dvb_frontend_thread(void *data)
511 fe_status_t s; 511 fe_status_t s;
512 struct dvb_frontend_parameters *params; 512 struct dvb_frontend_parameters *params;
513 513
514 dprintk("%s\n", __FUNCTION__); 514 dprintk("%s\n", __func__);
515 515
516 fepriv->check_wrapped = 0; 516 fepriv->check_wrapped = 0;
517 fepriv->quality = 0; 517 fepriv->quality = 0;
@@ -597,7 +597,7 @@ static void dvb_frontend_stop(struct dvb_frontend *fe)
597{ 597{
598 struct dvb_frontend_private *fepriv = fe->frontend_priv; 598 struct dvb_frontend_private *fepriv = fe->frontend_priv;
599 599
600 dprintk ("%s\n", __FUNCTION__); 600 dprintk ("%s\n", __func__);
601 601
602 fepriv->exit = 1; 602 fepriv->exit = 1;
603 mb(); 603 mb();
@@ -665,7 +665,7 @@ static int dvb_frontend_start(struct dvb_frontend *fe)
665 struct dvb_frontend_private *fepriv = fe->frontend_priv; 665 struct dvb_frontend_private *fepriv = fe->frontend_priv;
666 struct task_struct *fe_thread; 666 struct task_struct *fe_thread;
667 667
668 dprintk ("%s\n", __FUNCTION__); 668 dprintk ("%s\n", __func__);
669 669
670 if (fepriv->thread) { 670 if (fepriv->thread) {
671 if (!fepriv->exit) 671 if (!fepriv->exit)
@@ -763,7 +763,7 @@ static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
763 struct dvb_frontend_private *fepriv = fe->frontend_priv; 763 struct dvb_frontend_private *fepriv = fe->frontend_priv;
764 int err = -EOPNOTSUPP; 764 int err = -EOPNOTSUPP;
765 765
766 dprintk ("%s\n", __FUNCTION__); 766 dprintk ("%s\n", __func__);
767 767
768 if (fepriv->exit) 768 if (fepriv->exit)
769 return -ENODEV; 769 return -ENODEV;
@@ -895,7 +895,7 @@ static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
895 int i; 895 int i;
896 u8 last = 1; 896 u8 last = 1;
897 if (dvb_frontend_debug) 897 if (dvb_frontend_debug)
898 printk("%s switch command: 0x%04lx\n", __FUNCTION__, cmd); 898 printk("%s switch command: 0x%04lx\n", __func__, cmd);
899 do_gettimeofday(&nexttime); 899 do_gettimeofday(&nexttime);
900 if (dvb_frontend_debug) 900 if (dvb_frontend_debug)
901 memcpy(&tv[0], &nexttime, sizeof(struct timeval)); 901 memcpy(&tv[0], &nexttime, sizeof(struct timeval));
@@ -919,7 +919,7 @@ static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
919 } 919 }
920 if (dvb_frontend_debug) { 920 if (dvb_frontend_debug) {
921 printk("%s(%d): switch delay (should be 32k followed by all 8k\n", 921 printk("%s(%d): switch delay (should be 32k followed by all 8k\n",
922 __FUNCTION__, fe->dvb->num); 922 __func__, fe->dvb->num);
923 for (i = 1; i < 10; i++) 923 for (i = 1; i < 10; i++)
924 printk("%d: %d\n", i, timeval_usec_diff(tv[i-1] , tv[i])); 924 printk("%d: %d\n", i, timeval_usec_diff(tv[i-1] , tv[i]));
925 } 925 }
@@ -1037,7 +1037,7 @@ static unsigned int dvb_frontend_poll(struct file *file, struct poll_table_struc
1037 struct dvb_frontend *fe = dvbdev->priv; 1037 struct dvb_frontend *fe = dvbdev->priv;
1038 struct dvb_frontend_private *fepriv = fe->frontend_priv; 1038 struct dvb_frontend_private *fepriv = fe->frontend_priv;
1039 1039
1040 dprintk ("%s\n", __FUNCTION__); 1040 dprintk ("%s\n", __func__);
1041 1041
1042 poll_wait (file, &fepriv->events.wait_queue, wait); 1042 poll_wait (file, &fepriv->events.wait_queue, wait);
1043 1043
@@ -1054,7 +1054,7 @@ static int dvb_frontend_open(struct inode *inode, struct file *file)
1054 struct dvb_frontend_private *fepriv = fe->frontend_priv; 1054 struct dvb_frontend_private *fepriv = fe->frontend_priv;
1055 int ret; 1055 int ret;
1056 1056
1057 dprintk ("%s\n", __FUNCTION__); 1057 dprintk ("%s\n", __func__);
1058 1058
1059 if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl) { 1059 if (dvbdev->users == -1 && fe->ops.ts_bus_ctrl) {
1060 if ((ret = fe->ops.ts_bus_ctrl(fe, 1)) < 0) 1060 if ((ret = fe->ops.ts_bus_ctrl(fe, 1)) < 0)
@@ -1095,7 +1095,7 @@ static int dvb_frontend_release(struct inode *inode, struct file *file)
1095 struct dvb_frontend_private *fepriv = fe->frontend_priv; 1095 struct dvb_frontend_private *fepriv = fe->frontend_priv;
1096 int ret; 1096 int ret;
1097 1097
1098 dprintk ("%s\n", __FUNCTION__); 1098 dprintk ("%s\n", __func__);
1099 1099
1100 if ((file->f_flags & O_ACCMODE) != O_RDONLY) 1100 if ((file->f_flags & O_ACCMODE) != O_RDONLY)
1101 fepriv->release_jiffies = jiffies; 1101 fepriv->release_jiffies = jiffies;
@@ -1135,7 +1135,7 @@ int dvb_register_frontend(struct dvb_adapter* dvb,
1135 .kernel_ioctl = dvb_frontend_ioctl 1135 .kernel_ioctl = dvb_frontend_ioctl
1136 }; 1136 };
1137 1137
1138 dprintk ("%s\n", __FUNCTION__); 1138 dprintk ("%s\n", __func__);
1139 1139
1140 if (mutex_lock_interruptible(&frontend_mutex)) 1140 if (mutex_lock_interruptible(&frontend_mutex))
1141 return -ERESTARTSYS; 1141 return -ERESTARTSYS;
@@ -1169,7 +1169,7 @@ EXPORT_SYMBOL(dvb_register_frontend);
1169int dvb_unregister_frontend(struct dvb_frontend* fe) 1169int dvb_unregister_frontend(struct dvb_frontend* fe)
1170{ 1170{
1171 struct dvb_frontend_private *fepriv = fe->frontend_priv; 1171 struct dvb_frontend_private *fepriv = fe->frontend_priv;
1172 dprintk ("%s\n", __FUNCTION__); 1172 dprintk ("%s\n", __func__);
1173 1173
1174 mutex_lock(&frontend_mutex); 1174 mutex_lock(&frontend_mutex);
1175 dvb_frontend_stop (fe); 1175 dvb_frontend_stop (fe);
diff --git a/drivers/media/dvb/dvb-core/dvb_net.c b/drivers/media/dvb/dvb-core/dvb_net.c
index 4c8b62e2c035..56d871cfd7fc 100644
--- a/drivers/media/dvb/dvb-core/dvb_net.c
+++ b/drivers/media/dvb/dvb-core/dvb_net.c
@@ -354,7 +354,7 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
354#ifdef ULE_DEBUG 354#ifdef ULE_DEBUG
355 /* The code inside ULE_DEBUG keeps a history of the last 100 TS cells processed. */ 355 /* The code inside ULE_DEBUG keeps a history of the last 100 TS cells processed. */
356 static unsigned char ule_hist[100*TS_SZ]; 356 static unsigned char ule_hist[100*TS_SZ];
357 static unsigned char *ule_where = ule_hist, ule_dump = 0; 357 static unsigned char *ule_where = ule_hist, ule_dump;
358#endif 358#endif
359 359
360 /* For all TS cells in current buffer. 360 /* For all TS cells in current buffer.
@@ -965,17 +965,17 @@ static int dvb_net_feed_start(struct net_device *dev)
965 struct dmx_demux *demux = priv->demux; 965 struct dmx_demux *demux = priv->demux;
966 unsigned char *mac = (unsigned char *) dev->dev_addr; 966 unsigned char *mac = (unsigned char *) dev->dev_addr;
967 967
968 dprintk("%s: rx_mode %i\n", __FUNCTION__, priv->rx_mode); 968 dprintk("%s: rx_mode %i\n", __func__, priv->rx_mode);
969 mutex_lock(&priv->mutex); 969 mutex_lock(&priv->mutex);
970 if (priv->tsfeed || priv->secfeed || priv->secfilter || priv->multi_secfilter[0]) 970 if (priv->tsfeed || priv->secfeed || priv->secfilter || priv->multi_secfilter[0])
971 printk("%s: BUG %d\n", __FUNCTION__, __LINE__); 971 printk("%s: BUG %d\n", __func__, __LINE__);
972 972
973 priv->secfeed=NULL; 973 priv->secfeed=NULL;
974 priv->secfilter=NULL; 974 priv->secfilter=NULL;
975 priv->tsfeed = NULL; 975 priv->tsfeed = NULL;
976 976
977 if (priv->feedtype == DVB_NET_FEEDTYPE_MPE) { 977 if (priv->feedtype == DVB_NET_FEEDTYPE_MPE) {
978 dprintk("%s: alloc secfeed\n", __FUNCTION__); 978 dprintk("%s: alloc secfeed\n", __func__);
979 ret=demux->allocate_section_feed(demux, &priv->secfeed, 979 ret=demux->allocate_section_feed(demux, &priv->secfeed,
980 dvb_net_sec_callback); 980 dvb_net_sec_callback);
981 if (ret<0) { 981 if (ret<0) {
@@ -993,38 +993,38 @@ static int dvb_net_feed_start(struct net_device *dev)
993 } 993 }
994 994
995 if (priv->rx_mode != RX_MODE_PROMISC) { 995 if (priv->rx_mode != RX_MODE_PROMISC) {
996 dprintk("%s: set secfilter\n", __FUNCTION__); 996 dprintk("%s: set secfilter\n", __func__);
997 dvb_net_filter_sec_set(dev, &priv->secfilter, mac, mask_normal); 997 dvb_net_filter_sec_set(dev, &priv->secfilter, mac, mask_normal);
998 } 998 }
999 999
1000 switch (priv->rx_mode) { 1000 switch (priv->rx_mode) {
1001 case RX_MODE_MULTI: 1001 case RX_MODE_MULTI:
1002 for (i = 0; i < priv->multi_num; i++) { 1002 for (i = 0; i < priv->multi_num; i++) {
1003 dprintk("%s: set multi_secfilter[%d]\n", __FUNCTION__, i); 1003 dprintk("%s: set multi_secfilter[%d]\n", __func__, i);
1004 dvb_net_filter_sec_set(dev, &priv->multi_secfilter[i], 1004 dvb_net_filter_sec_set(dev, &priv->multi_secfilter[i],
1005 priv->multi_macs[i], mask_normal); 1005 priv->multi_macs[i], mask_normal);
1006 } 1006 }
1007 break; 1007 break;
1008 case RX_MODE_ALL_MULTI: 1008 case RX_MODE_ALL_MULTI:
1009 priv->multi_num=1; 1009 priv->multi_num=1;
1010 dprintk("%s: set multi_secfilter[0]\n", __FUNCTION__); 1010 dprintk("%s: set multi_secfilter[0]\n", __func__);
1011 dvb_net_filter_sec_set(dev, &priv->multi_secfilter[0], 1011 dvb_net_filter_sec_set(dev, &priv->multi_secfilter[0],
1012 mac_allmulti, mask_allmulti); 1012 mac_allmulti, mask_allmulti);
1013 break; 1013 break;
1014 case RX_MODE_PROMISC: 1014 case RX_MODE_PROMISC:
1015 priv->multi_num=0; 1015 priv->multi_num=0;
1016 dprintk("%s: set secfilter\n", __FUNCTION__); 1016 dprintk("%s: set secfilter\n", __func__);
1017 dvb_net_filter_sec_set(dev, &priv->secfilter, mac, mask_promisc); 1017 dvb_net_filter_sec_set(dev, &priv->secfilter, mac, mask_promisc);
1018 break; 1018 break;
1019 } 1019 }
1020 1020
1021 dprintk("%s: start filtering\n", __FUNCTION__); 1021 dprintk("%s: start filtering\n", __func__);
1022 priv->secfeed->start_filtering(priv->secfeed); 1022 priv->secfeed->start_filtering(priv->secfeed);
1023 } else if (priv->feedtype == DVB_NET_FEEDTYPE_ULE) { 1023 } else if (priv->feedtype == DVB_NET_FEEDTYPE_ULE) {
1024 struct timespec timeout = { 0, 10000000 }; // 10 msec 1024 struct timespec timeout = { 0, 10000000 }; // 10 msec
1025 1025
1026 /* we have payloads encapsulated in TS */ 1026 /* we have payloads encapsulated in TS */
1027 dprintk("%s: alloc tsfeed\n", __FUNCTION__); 1027 dprintk("%s: alloc tsfeed\n", __func__);
1028 ret = demux->allocate_ts_feed(demux, &priv->tsfeed, dvb_net_ts_callback); 1028 ret = demux->allocate_ts_feed(demux, &priv->tsfeed, dvb_net_ts_callback);
1029 if (ret < 0) { 1029 if (ret < 0) {
1030 printk("%s: could not allocate ts feed\n", dev->name); 1030 printk("%s: could not allocate ts feed\n", dev->name);
@@ -1048,7 +1048,7 @@ static int dvb_net_feed_start(struct net_device *dev)
1048 goto error; 1048 goto error;
1049 } 1049 }
1050 1050
1051 dprintk("%s: start filtering\n", __FUNCTION__); 1051 dprintk("%s: start filtering\n", __func__);
1052 priv->tsfeed->start_filtering(priv->tsfeed); 1052 priv->tsfeed->start_filtering(priv->tsfeed);
1053 } else 1053 } else
1054 ret = -EINVAL; 1054 ret = -EINVAL;
@@ -1063,17 +1063,17 @@ static int dvb_net_feed_stop(struct net_device *dev)
1063 struct dvb_net_priv *priv = dev->priv; 1063 struct dvb_net_priv *priv = dev->priv;
1064 int i, ret = 0; 1064 int i, ret = 0;
1065 1065
1066 dprintk("%s\n", __FUNCTION__); 1066 dprintk("%s\n", __func__);
1067 mutex_lock(&priv->mutex); 1067 mutex_lock(&priv->mutex);
1068 if (priv->feedtype == DVB_NET_FEEDTYPE_MPE) { 1068 if (priv->feedtype == DVB_NET_FEEDTYPE_MPE) {
1069 if (priv->secfeed) { 1069 if (priv->secfeed) {
1070 if (priv->secfeed->is_filtering) { 1070 if (priv->secfeed->is_filtering) {
1071 dprintk("%s: stop secfeed\n", __FUNCTION__); 1071 dprintk("%s: stop secfeed\n", __func__);
1072 priv->secfeed->stop_filtering(priv->secfeed); 1072 priv->secfeed->stop_filtering(priv->secfeed);
1073 } 1073 }
1074 1074
1075 if (priv->secfilter) { 1075 if (priv->secfilter) {
1076 dprintk("%s: release secfilter\n", __FUNCTION__); 1076 dprintk("%s: release secfilter\n", __func__);
1077 priv->secfeed->release_filter(priv->secfeed, 1077 priv->secfeed->release_filter(priv->secfeed,
1078 priv->secfilter); 1078 priv->secfilter);
1079 priv->secfilter=NULL; 1079 priv->secfilter=NULL;
@@ -1082,7 +1082,7 @@ static int dvb_net_feed_stop(struct net_device *dev)
1082 for (i=0; i<priv->multi_num; i++) { 1082 for (i=0; i<priv->multi_num; i++) {
1083 if (priv->multi_secfilter[i]) { 1083 if (priv->multi_secfilter[i]) {
1084 dprintk("%s: release multi_filter[%d]\n", 1084 dprintk("%s: release multi_filter[%d]\n",
1085 __FUNCTION__, i); 1085 __func__, i);
1086 priv->secfeed->release_filter(priv->secfeed, 1086 priv->secfeed->release_filter(priv->secfeed,
1087 priv->multi_secfilter[i]); 1087 priv->multi_secfilter[i]);
1088 priv->multi_secfilter[i] = NULL; 1088 priv->multi_secfilter[i] = NULL;
@@ -1096,7 +1096,7 @@ static int dvb_net_feed_stop(struct net_device *dev)
1096 } else if (priv->feedtype == DVB_NET_FEEDTYPE_ULE) { 1096 } else if (priv->feedtype == DVB_NET_FEEDTYPE_ULE) {
1097 if (priv->tsfeed) { 1097 if (priv->tsfeed) {
1098 if (priv->tsfeed->is_filtering) { 1098 if (priv->tsfeed->is_filtering) {
1099 dprintk("%s: stop tsfeed\n", __FUNCTION__); 1099 dprintk("%s: stop tsfeed\n", __func__);
1100 priv->tsfeed->stop_filtering(priv->tsfeed); 1100 priv->tsfeed->stop_filtering(priv->tsfeed);
1101 } 1101 }
1102 priv->demux->release_ts_feed(priv->demux, priv->tsfeed); 1102 priv->demux->release_ts_feed(priv->demux, priv->tsfeed);
diff --git a/drivers/media/dvb/dvb-core/dvb_ringbuffer.c b/drivers/media/dvb/dvb-core/dvb_ringbuffer.c
index ac9d93cf83c6..872985b7912d 100644
--- a/drivers/media/dvb/dvb-core/dvb_ringbuffer.c
+++ b/drivers/media/dvb/dvb-core/dvb_ringbuffer.c
@@ -90,7 +90,11 @@ void dvb_ringbuffer_flush(struct dvb_ringbuffer *rbuf)
90 rbuf->error = 0; 90 rbuf->error = 0;
91} 91}
92 92
93 93void dvb_ringbuffer_reset(struct dvb_ringbuffer *rbuf)
94{
95 rbuf->pread = rbuf->pwrite = 0;
96 rbuf->error = 0;
97}
94 98
95void dvb_ringbuffer_flush_spinlock_wakeup(struct dvb_ringbuffer *rbuf) 99void dvb_ringbuffer_flush_spinlock_wakeup(struct dvb_ringbuffer *rbuf)
96{ 100{
diff --git a/drivers/media/dvb/dvb-core/dvb_ringbuffer.h b/drivers/media/dvb/dvb-core/dvb_ringbuffer.h
index d97714e75736..890826262966 100644
--- a/drivers/media/dvb/dvb-core/dvb_ringbuffer.h
+++ b/drivers/media/dvb/dvb-core/dvb_ringbuffer.h
@@ -69,6 +69,7 @@ struct dvb_ringbuffer {
69** to lock read or write operations. 69** to lock read or write operations.
70** Two or more readers must be locked against each other. 70** Two or more readers must be locked against each other.
71** Flushing the buffer counts as a read operation. 71** Flushing the buffer counts as a read operation.
72** Resetting the buffer counts as a read and write operation.
72** Two or more writers must be locked against each other. 73** Two or more writers must be locked against each other.
73*/ 74*/
74 75
@@ -85,6 +86,13 @@ extern ssize_t dvb_ringbuffer_free(struct dvb_ringbuffer *rbuf);
85extern ssize_t dvb_ringbuffer_avail(struct dvb_ringbuffer *rbuf); 86extern ssize_t dvb_ringbuffer_avail(struct dvb_ringbuffer *rbuf);
86 87
87 88
89/*
90** Reset the read and write pointers to zero and flush the buffer
91** This counts as a read and write operation
92*/
93extern void dvb_ringbuffer_reset(struct dvb_ringbuffer *rbuf);
94
95
88/* read routines & macros */ 96/* read routines & macros */
89/* ---------------------- */ 97/* ---------------------- */
90/* flush buffer */ 98/* flush buffer */
diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
index 18738faecbbc..8b56d929f7fd 100644
--- a/drivers/media/dvb/dvb-core/dvbdev.c
+++ b/drivers/media/dvb/dvb-core/dvbdev.c
@@ -49,7 +49,6 @@ static const char * const dnames[] = {
49 "net", "osd" 49 "net", "osd"
50}; 50};
51 51
52#define DVB_MAX_ADAPTERS 8
53#define DVB_MAX_IDS 4 52#define DVB_MAX_IDS 4
54#define nums2minor(num,type,id) ((num << 6) | (id << 4) | type) 53#define nums2minor(num,type,id) ((num << 6) | (id << 4) | type)
55#define MAX_DVB_MINORS (DVB_MAX_ADAPTERS*64) 54#define MAX_DVB_MINORS (DVB_MAX_ADAPTERS*64)
@@ -97,7 +96,7 @@ static int dvb_device_open(struct inode *inode, struct file *file)
97} 96}
98 97
99 98
100static struct file_operations dvb_device_fops = 99static const struct file_operations dvb_device_fops =
101{ 100{
102 .owner = THIS_MODULE, 101 .owner = THIS_MODULE,
103 .open = dvb_device_open, 102 .open = dvb_device_open,
@@ -196,7 +195,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
196 if ((id = dvbdev_get_free_id (adap, type)) < 0){ 195 if ((id = dvbdev_get_free_id (adap, type)) < 0){
197 mutex_unlock(&dvbdev_register_lock); 196 mutex_unlock(&dvbdev_register_lock);
198 *pdvbdev = NULL; 197 *pdvbdev = NULL;
199 printk(KERN_ERR "%s: couldn't find free device id\n", __FUNCTION__); 198 printk(KERN_ERR "%s: couldn't find free device id\n", __func__);
200 return -ENFILE; 199 return -ENFILE;
201 } 200 }
202 201
@@ -235,7 +234,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
235 "dvb%d.%s%d", adap->num, dnames[type], id); 234 "dvb%d.%s%d", adap->num, dnames[type], id);
236 if (IS_ERR(clsdev)) { 235 if (IS_ERR(clsdev)) {
237 printk(KERN_ERR "%s: failed to create device dvb%d.%s%d (%ld)\n", 236 printk(KERN_ERR "%s: failed to create device dvb%d.%s%d (%ld)\n",
238 __FUNCTION__, adap->num, dnames[type], id, PTR_ERR(clsdev)); 237 __func__, adap->num, dnames[type], id, PTR_ERR(clsdev));
239 return PTR_ERR(clsdev); 238 return PTR_ERR(clsdev);
240 } 239 }
241 240
@@ -262,18 +261,25 @@ void dvb_unregister_device(struct dvb_device *dvbdev)
262} 261}
263EXPORT_SYMBOL(dvb_unregister_device); 262EXPORT_SYMBOL(dvb_unregister_device);
264 263
264static int dvbdev_check_free_adapter_num(int num)
265{
266 struct list_head *entry;
267 list_for_each(entry, &dvb_adapter_list) {
268 struct dvb_adapter *adap;
269 adap = list_entry(entry, struct dvb_adapter, list_head);
270 if (adap->num == num)
271 return 0;
272 }
273 return 1;
274}
265 275
266static int dvbdev_get_free_adapter_num (void) 276static int dvbdev_get_free_adapter_num (void)
267{ 277{
268 int num = 0; 278 int num = 0;
269 279
270 while (num < DVB_MAX_ADAPTERS) { 280 while (num < DVB_MAX_ADAPTERS) {
271 struct dvb_adapter *adap; 281 if (dvbdev_check_free_adapter_num(num))
272 list_for_each_entry(adap, &dvb_adapter_list, list_head) 282 return num;
273 if (adap->num == num)
274 goto skip;
275 return num;
276skip:
277 num++; 283 num++;
278 } 284 }
279 285
@@ -281,13 +287,28 @@ skip:
281} 287}
282 288
283 289
284int dvb_register_adapter(struct dvb_adapter *adap, const char *name, struct module *module, struct device *device) 290int dvb_register_adapter(struct dvb_adapter *adap, const char *name,
291 struct module *module, struct device *device,
292 short *adapter_nums)
285{ 293{
286 int num; 294 int i, num;
287 295
288 mutex_lock(&dvbdev_register_lock); 296 mutex_lock(&dvbdev_register_lock);
289 297
290 if ((num = dvbdev_get_free_adapter_num ()) < 0) { 298 for (i = 0; i < DVB_MAX_ADAPTERS; ++i) {
299 num = adapter_nums[i];
300 if (num >= 0 && num < DVB_MAX_ADAPTERS) {
301 /* use the one the driver asked for */
302 if (dvbdev_check_free_adapter_num(num))
303 break;
304 } else {
305 num = dvbdev_get_free_adapter_num();
306 break;
307 }
308 num = -1;
309 }
310
311 if (num < 0) {
291 mutex_unlock(&dvbdev_register_lock); 312 mutex_unlock(&dvbdev_register_lock);
292 return -ENFILE; 313 return -ENFILE;
293 } 314 }
diff --git a/drivers/media/dvb/dvb-core/dvbdev.h b/drivers/media/dvb/dvb-core/dvbdev.h
index 6dff10ebf470..5f9a737c6de1 100644
--- a/drivers/media/dvb/dvb-core/dvbdev.h
+++ b/drivers/media/dvb/dvb-core/dvbdev.h
@@ -31,6 +31,10 @@
31 31
32#define DVB_MAJOR 212 32#define DVB_MAJOR 212
33 33
34#define DVB_MAX_ADAPTERS 8
35
36#define DVB_UNSET (-1)
37
34#define DVB_DEVICE_VIDEO 0 38#define DVB_DEVICE_VIDEO 0
35#define DVB_DEVICE_AUDIO 1 39#define DVB_DEVICE_AUDIO 1
36#define DVB_DEVICE_SEC 2 40#define DVB_DEVICE_SEC 2
@@ -41,6 +45,11 @@
41#define DVB_DEVICE_NET 7 45#define DVB_DEVICE_NET 7
42#define DVB_DEVICE_OSD 8 46#define DVB_DEVICE_OSD 8
43 47
48#define DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr) \
49 static short adapter_nr[] = \
50 {[0 ... (DVB_MAX_ADAPTERS - 1)] = DVB_UNSET }; \
51 module_param_array(adapter_nr, short, NULL, 0444); \
52 MODULE_PARM_DESC(adapter_nr, "DVB adapter numbers")
44 53
45struct dvb_adapter { 54struct dvb_adapter {
46 int num; 55 int num;
@@ -78,7 +87,9 @@ struct dvb_device {
78}; 87};
79 88
80 89
81extern int dvb_register_adapter (struct dvb_adapter *adap, const char *name, struct module *module, struct device *device); 90extern int dvb_register_adapter(struct dvb_adapter *adap, const char *name,
91 struct module *module, struct device *device,
92 short *adapter_nums);
82extern int dvb_unregister_adapter (struct dvb_adapter *adap); 93extern int dvb_unregister_adapter (struct dvb_adapter *adap);
83 94
84extern int dvb_register_device (struct dvb_adapter *adap, 95extern int dvb_register_device (struct dvb_adapter *adap,
diff --git a/drivers/media/dvb/dvb-usb/Kconfig b/drivers/media/dvb/dvb-usb/Kconfig
index d73934dd4c57..3c8493d2026d 100644
--- a/drivers/media/dvb/dvb-usb/Kconfig
+++ b/drivers/media/dvb/dvb-usb/Kconfig
@@ -105,6 +105,7 @@ config DVB_USB_CXUSB
105 select DVB_LGDT330X if !DVB_FE_CUSTOMISE 105 select DVB_LGDT330X if !DVB_FE_CUSTOMISE
106 select DVB_MT352 if !DVB_FE_CUSTOMISE 106 select DVB_MT352 if !DVB_FE_CUSTOMISE
107 select DVB_ZL10353 if !DVB_FE_CUSTOMISE 107 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
108 select TUNER_SIMPLE if !DVB_FE_CUSTOMISE
108 help 109 help
109 Say Y here to support the Conexant USB2.0 hybrid reference design. 110 Say Y here to support the Conexant USB2.0 hybrid reference design.
110 Currently, only DVB and ATSC modes are supported, analog mode 111 Currently, only DVB and ATSC modes are supported, analog mode
diff --git a/drivers/media/dvb/dvb-usb/a800.c b/drivers/media/dvb/dvb-usb/a800.c
index a6c5f19f680d..dc8c8784caa8 100644
--- a/drivers/media/dvb/dvb-usb/a800.c
+++ b/drivers/media/dvb/dvb-usb/a800.c
@@ -18,6 +18,9 @@
18static int debug; 18static int debug;
19module_param(debug, int, 0644); 19module_param(debug, int, 0644);
20MODULE_PARM_DESC(debug, "set debugging level (rc=1 (or-able))." DVB_USB_DEBUG_STATUS); 20MODULE_PARM_DESC(debug, "set debugging level (rc=1 (or-able))." DVB_USB_DEBUG_STATUS);
21
22DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
23
21#define deb_rc(args...) dprintk(debug,0x01,args) 24#define deb_rc(args...) dprintk(debug,0x01,args)
22 25
23static int a800_power_ctrl(struct dvb_usb_device *d, int onoff) 26static int a800_power_ctrl(struct dvb_usb_device *d, int onoff)
@@ -94,7 +97,8 @@ static struct dvb_usb_device_properties a800_properties;
94static int a800_probe(struct usb_interface *intf, 97static int a800_probe(struct usb_interface *intf,
95 const struct usb_device_id *id) 98 const struct usb_device_id *id)
96{ 99{
97 return dvb_usb_device_init(intf,&a800_properties,THIS_MODULE,NULL); 100 return dvb_usb_device_init(intf, &a800_properties,
101 THIS_MODULE, NULL, adapter_nr);
98} 102}
99 103
100/* do not change the order of the ID table */ 104/* do not change the order of the ID table */
diff --git a/drivers/media/dvb/dvb-usb/af9005.c b/drivers/media/dvb/dvb-usb/af9005.c
index e7f76f515b4f..cfe71feefcad 100644
--- a/drivers/media/dvb/dvb-usb/af9005.c
+++ b/drivers/media/dvb/dvb-usb/af9005.c
@@ -39,6 +39,8 @@ int dvb_usb_af9005_dump_eeprom = 0;
39module_param_named(dump_eeprom, dvb_usb_af9005_dump_eeprom, int, 0); 39module_param_named(dump_eeprom, dvb_usb_af9005_dump_eeprom, int, 0);
40MODULE_PARM_DESC(dump_eeprom, "dump contents of the eeprom."); 40MODULE_PARM_DESC(dump_eeprom, "dump contents of the eeprom.");
41 41
42DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
43
42/* remote control decoder */ 44/* remote control decoder */
43int (*rc_decode) (struct dvb_usb_device * d, u8 * data, int len, u32 * event, 45int (*rc_decode) (struct dvb_usb_device * d, u8 * data, int len, u32 * event,
44 int *state); 46 int *state);
@@ -1020,7 +1022,8 @@ static struct dvb_usb_device_properties af9005_properties;
1020static int af9005_usb_probe(struct usb_interface *intf, 1022static int af9005_usb_probe(struct usb_interface *intf,
1021 const struct usb_device_id *id) 1023 const struct usb_device_id *id)
1022{ 1024{
1023 return dvb_usb_device_init(intf, &af9005_properties, THIS_MODULE, NULL); 1025 return dvb_usb_device_init(intf, &af9005_properties,
1026 THIS_MODULE, NULL, adapter_nr);
1024} 1027}
1025 1028
1026static struct usb_device_id af9005_usb_table[] = { 1029static struct usb_device_id af9005_usb_table[] = {
diff --git a/drivers/media/dvb/dvb-usb/au6610.c b/drivers/media/dvb/dvb-usb/au6610.c
index f3ff81314696..2ccb90fa60c8 100644
--- a/drivers/media/dvb/dvb-usb/au6610.c
+++ b/drivers/media/dvb/dvb-usb/au6610.c
@@ -19,6 +19,8 @@ static int dvb_usb_au6610_debug;
19module_param_named(debug, dvb_usb_au6610_debug, int, 0644); 19module_param_named(debug, dvb_usb_au6610_debug, int, 0644);
20MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS); 20MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
21 21
22DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
23
22static int au6610_usb_msg(struct dvb_usb_device *d, u8 operation, u8 addr, 24static int au6610_usb_msg(struct dvb_usb_device *d, u8 operation, u8 addr,
23 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen) 25 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
24{ 26{
@@ -163,7 +165,9 @@ static int au6610_probe(struct usb_interface *intf,
163 if (intf->num_altsetting < AU6610_ALTSETTING_COUNT) 165 if (intf->num_altsetting < AU6610_ALTSETTING_COUNT)
164 return -ENODEV; 166 return -ENODEV;
165 167
166 if ((ret = dvb_usb_device_init(intf, &au6610_properties, THIS_MODULE, &d)) == 0) { 168 ret = dvb_usb_device_init(intf, &au6610_properties, THIS_MODULE, &d,
169 adapter_nr);
170 if (ret == 0) {
167 alt = usb_altnum_to_altsetting(intf, AU6610_ALTSETTING); 171 alt = usb_altnum_to_altsetting(intf, AU6610_ALTSETTING);
168 172
169 if (alt == NULL) { 173 if (alt == NULL) {
diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
index c58365005ac1..720fcd1c3c1d 100644
--- a/drivers/media/dvb/dvb-usb/cxusb.c
+++ b/drivers/media/dvb/dvb-usb/cxusb.c
@@ -23,6 +23,8 @@
23 * 23 *
24 * see Documentation/dvb/README.dvb-usb for more information 24 * see Documentation/dvb/README.dvb-usb for more information
25 */ 25 */
26#include <media/tuner.h>
27
26#include "cxusb.h" 28#include "cxusb.h"
27 29
28#include "cx22702.h" 30#include "cx22702.h"
@@ -31,12 +33,15 @@
31#include "mt352_priv.h" 33#include "mt352_priv.h"
32#include "zl10353.h" 34#include "zl10353.h"
33#include "tuner-xc2028.h" 35#include "tuner-xc2028.h"
34#include "tuner-xc2028-types.h" 36#include "tuner-simple.h"
35 37
36/* debug */ 38/* debug */
37static int dvb_usb_cxusb_debug; 39static int dvb_usb_cxusb_debug;
38module_param_named(debug, dvb_usb_cxusb_debug, int, 0644); 40module_param_named(debug, dvb_usb_cxusb_debug, int, 0644);
39MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS); 41MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
42
43DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
44
40#define deb_info(args...) dprintk(dvb_usb_cxusb_debug,0x01,args) 45#define deb_info(args...) dprintk(dvb_usb_cxusb_debug,0x01,args)
41#define deb_i2c(args...) if (d->udev->descriptor.idVendor == USB_VID_MEDION) \ 46#define deb_i2c(args...) if (d->udev->descriptor.idVendor == USB_VID_MEDION) \
42 dprintk(dvb_usb_cxusb_debug,0x01,args) 47 dprintk(dvb_usb_cxusb_debug,0x01,args)
@@ -450,8 +455,9 @@ static struct mt352_config cxusb_mt352_xc3028_config = {
450/* Callbacks for DVB USB */ 455/* Callbacks for DVB USB */
451static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap) 456static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
452{ 457{
453 dvb_attach(dvb_pll_attach, adap->fe, 0x61, &adap->dev->i2c_adap, 458 dvb_attach(simple_tuner_attach, adap->fe,
454 DVB_PLL_FMD1216ME); 459 &adap->dev->i2c_adap, 0x61,
460 TUNER_PHILIPS_FMD1216ME_MK3);
455 return 0; 461 return 0;
456} 462}
457 463
@@ -477,8 +483,8 @@ static int cxusb_dtt7579_tuner_attach(struct dvb_usb_adapter *adap)
477 483
478static int cxusb_lgh064f_tuner_attach(struct dvb_usb_adapter *adap) 484static int cxusb_lgh064f_tuner_attach(struct dvb_usb_adapter *adap)
479{ 485{
480 dvb_attach(dvb_pll_attach, adap->fe, 0x61, &adap->dev->i2c_adap, 486 dvb_attach(simple_tuner_attach, adap->fe,
481 DVB_PLL_LG_TDVS_H06XF); 487 &adap->dev->i2c_adap, 0x61, TUNER_LG_TDVS_H06XF);
482 return 0; 488 return 0;
483} 489}
484 490
@@ -488,14 +494,14 @@ static int dvico_bluebird_xc2028_callback(void *ptr, int command, int arg)
488 494
489 switch (command) { 495 switch (command) {
490 case XC2028_TUNER_RESET: 496 case XC2028_TUNER_RESET:
491 deb_info("%s: XC2028_TUNER_RESET %d\n", __FUNCTION__, arg); 497 deb_info("%s: XC2028_TUNER_RESET %d\n", __func__, arg);
492 cxusb_bluebird_gpio_pulse(d, 0x01, 1); 498 cxusb_bluebird_gpio_pulse(d, 0x01, 1);
493 break; 499 break;
494 case XC2028_RESET_CLK: 500 case XC2028_RESET_CLK:
495 deb_info("%s: XC2028_RESET_CLK %d\n", __FUNCTION__, arg); 501 deb_info("%s: XC2028_RESET_CLK %d\n", __func__, arg);
496 break; 502 break;
497 default: 503 default:
498 deb_info("%s: unknown command %d, arg %d\n", __FUNCTION__, 504 deb_info("%s: unknown command %d, arg %d\n", __func__,
499 command, arg); 505 command, arg);
500 return -EINVAL; 506 return -EINVAL;
501 } 507 }
@@ -509,13 +515,12 @@ static int cxusb_dvico_xc3028_tuner_attach(struct dvb_usb_adapter *adap)
509 struct xc2028_config cfg = { 515 struct xc2028_config cfg = {
510 .i2c_adap = &adap->dev->i2c_adap, 516 .i2c_adap = &adap->dev->i2c_adap,
511 .i2c_addr = 0x61, 517 .i2c_addr = 0x61,
512 .video_dev = adap->dev,
513 .callback = dvico_bluebird_xc2028_callback, 518 .callback = dvico_bluebird_xc2028_callback,
514 }; 519 };
515 static struct xc2028_ctrl ctl = { 520 static struct xc2028_ctrl ctl = {
516 .fname = "xc3028-dvico-au-01.fw", 521 .fname = "xc3028-dvico-au-01.fw",
517 .max_len = 64, 522 .max_len = 64,
518 .scode_table = ZARLINK456, 523 .scode_table = XC3028_FE_ZARLINK456,
519 }; 524 };
520 525
521 fe = dvb_attach(xc2028_attach, adap->fe, &cfg); 526 fe = dvb_attach(xc2028_attach, adap->fe, &cfg);
@@ -720,16 +725,24 @@ static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_prope
720static int cxusb_probe(struct usb_interface *intf, 725static int cxusb_probe(struct usb_interface *intf,
721 const struct usb_device_id *id) 726 const struct usb_device_id *id)
722{ 727{
723 if (dvb_usb_device_init(intf,&cxusb_medion_properties,THIS_MODULE,NULL) == 0 || 728 if (0 == dvb_usb_device_init(intf, &cxusb_medion_properties,
724 dvb_usb_device_init(intf,&cxusb_bluebird_lgh064f_properties,THIS_MODULE,NULL) == 0 || 729 THIS_MODULE, NULL, adapter_nr) ||
725 dvb_usb_device_init(intf,&cxusb_bluebird_dee1601_properties,THIS_MODULE,NULL) == 0 || 730 0 == dvb_usb_device_init(intf, &cxusb_bluebird_lgh064f_properties,
726 dvb_usb_device_init(intf,&cxusb_bluebird_lgz201_properties,THIS_MODULE,NULL) == 0 || 731 THIS_MODULE, NULL, adapter_nr) ||
727 dvb_usb_device_init(intf,&cxusb_bluebird_dtt7579_properties,THIS_MODULE,NULL) == 0 || 732 0 == dvb_usb_device_init(intf, &cxusb_bluebird_dee1601_properties,
728 dvb_usb_device_init(intf,&cxusb_bluebird_dualdig4_properties,THIS_MODULE,NULL) == 0 || 733 THIS_MODULE, NULL, adapter_nr) ||
729 dvb_usb_device_init(intf,&cxusb_bluebird_nano2_properties,THIS_MODULE,NULL) == 0 || 734 0 == dvb_usb_device_init(intf, &cxusb_bluebird_lgz201_properties,
730 dvb_usb_device_init(intf,&cxusb_bluebird_nano2_needsfirmware_properties,THIS_MODULE,NULL) == 0) { 735 THIS_MODULE, NULL, adapter_nr) ||
736 0 == dvb_usb_device_init(intf, &cxusb_bluebird_dtt7579_properties,
737 THIS_MODULE, NULL, adapter_nr) ||
738 0 == dvb_usb_device_init(intf, &cxusb_bluebird_dualdig4_properties,
739 THIS_MODULE, NULL, adapter_nr) ||
740 0 == dvb_usb_device_init(intf, &cxusb_bluebird_nano2_properties,
741 THIS_MODULE, NULL, adapter_nr) ||
742 0 == dvb_usb_device_init(intf,
743 &cxusb_bluebird_nano2_needsfirmware_properties,
744 THIS_MODULE, NULL, adapter_nr))
731 return 0; 745 return 0;
732 }
733 746
734 return -EINVAL; 747 return -EINVAL;
735} 748}
diff --git a/drivers/media/dvb/dvb-usb/dib0700.h b/drivers/media/dvb/dvb-usb/dib0700.h
index 4a903ea95896..66d4dc6ba46f 100644
--- a/drivers/media/dvb/dvb-usb/dib0700.h
+++ b/drivers/media/dvb/dvb-usb/dib0700.h
@@ -37,6 +37,7 @@ struct dib0700_state {
37 u8 channel_state; 37 u8 channel_state;
38 u16 mt2060_if1[2]; 38 u16 mt2060_if1[2];
39 u8 rc_toggle; 39 u8 rc_toggle;
40 u8 rc_counter;
40 u8 is_dib7000pc; 41 u8 is_dib7000pc;
41}; 42};
42 43
@@ -44,12 +45,15 @@ extern int dib0700_set_gpio(struct dvb_usb_device *, enum dib07x0_gpios gpio, u8
44extern int dib0700_ctrl_clock(struct dvb_usb_device *d, u32 clk_MHz, u8 clock_out_gp3); 45extern int dib0700_ctrl_clock(struct dvb_usb_device *d, u32 clk_MHz, u8 clock_out_gp3);
45extern int dib0700_ctrl_rd(struct dvb_usb_device *d, u8 *tx, u8 txlen, u8 *rx, u8 rxlen); 46extern int dib0700_ctrl_rd(struct dvb_usb_device *d, u8 *tx, u8 txlen, u8 *rx, u8 rxlen);
46extern int dib0700_download_firmware(struct usb_device *udev, const struct firmware *fw); 47extern int dib0700_download_firmware(struct usb_device *udev, const struct firmware *fw);
48extern int dib0700_rc_setup(struct dvb_usb_device *d);
47extern int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff); 49extern int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff);
48extern struct i2c_algorithm dib0700_i2c_algo; 50extern struct i2c_algorithm dib0700_i2c_algo;
49extern int dib0700_identify_state(struct usb_device *udev, struct dvb_usb_device_properties *props, 51extern int dib0700_identify_state(struct usb_device *udev, struct dvb_usb_device_properties *props,
50 struct dvb_usb_device_description **desc, int *cold); 52 struct dvb_usb_device_description **desc, int *cold);
51 53
52extern int dib0700_device_count; 54extern int dib0700_device_count;
55extern int dvb_usb_dib0700_ir_proto;
53extern struct dvb_usb_device_properties dib0700_devices[]; 56extern struct dvb_usb_device_properties dib0700_devices[];
54extern struct usb_device_id dib0700_usb_id_table[]; 57extern struct usb_device_id dib0700_usb_id_table[];
58
55#endif 59#endif
diff --git a/drivers/media/dvb/dvb-usb/dib0700_core.c b/drivers/media/dvb/dvb-usb/dib0700_core.c
index c9857d5c6982..595a04696c87 100644
--- a/drivers/media/dvb/dvb-usb/dib0700_core.c
+++ b/drivers/media/dvb/dvb-usb/dib0700_core.c
@@ -13,10 +13,12 @@ int dvb_usb_dib0700_debug;
13module_param_named(debug,dvb_usb_dib0700_debug, int, 0644); 13module_param_named(debug,dvb_usb_dib0700_debug, int, 0644);
14MODULE_PARM_DESC(debug, "set debugging level (1=info,2=fw,4=fwdata,8=data (or-able))." DVB_USB_DEBUG_STATUS); 14MODULE_PARM_DESC(debug, "set debugging level (1=info,2=fw,4=fwdata,8=data (or-able))." DVB_USB_DEBUG_STATUS);
15 15
16static int dvb_usb_dib0700_ir_proto = 1; 16int dvb_usb_dib0700_ir_proto = 1;
17module_param(dvb_usb_dib0700_ir_proto, int, 0644); 17module_param(dvb_usb_dib0700_ir_proto, int, 0644);
18MODULE_PARM_DESC(dvb_usb_dib0700_ir_proto, "set ir protocol (0=NEC, 1=RC5 (default), 2=RC6)."); 18MODULE_PARM_DESC(dvb_usb_dib0700_ir_proto, "set ir protocol (0=NEC, 1=RC5 (default), 2=RC6).");
19 19
20DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
21
20/* expecting rx buffer: request data[0] data[1] ... data[2] */ 22/* expecting rx buffer: request data[0] data[1] ... data[2] */
21static int dib0700_ctrl_wr(struct dvb_usb_device *d, u8 *tx, u8 txlen) 23static int dib0700_ctrl_wr(struct dvb_usb_device *d, u8 *tx, u8 txlen)
22{ 24{
@@ -261,7 +263,7 @@ int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
261 return dib0700_ctrl_wr(adap->dev, b, 4); 263 return dib0700_ctrl_wr(adap->dev, b, 4);
262} 264}
263 265
264static int dib0700_rc_setup(struct dvb_usb_device *d) 266int dib0700_rc_setup(struct dvb_usb_device *d)
265{ 267{
266 u8 rc_setup[3] = {REQUEST_SET_RC, dvb_usb_dib0700_ir_proto, 0}; 268 u8 rc_setup[3] = {REQUEST_SET_RC, dvb_usb_dib0700_ir_proto, 0};
267 int i = dib0700_ctrl_wr(d, rc_setup, 3); 269 int i = dib0700_ctrl_wr(d, rc_setup, 3);
@@ -279,7 +281,8 @@ static int dib0700_probe(struct usb_interface *intf,
279 struct dvb_usb_device *dev; 281 struct dvb_usb_device *dev;
280 282
281 for (i = 0; i < dib0700_device_count; i++) 283 for (i = 0; i < dib0700_device_count; i++)
282 if (dvb_usb_device_init(intf, &dib0700_devices[i], THIS_MODULE, &dev) == 0) 284 if (dvb_usb_device_init(intf, &dib0700_devices[i], THIS_MODULE,
285 &dev, adapter_nr) == 0)
283 { 286 {
284 dib0700_rc_setup(dev); 287 dib0700_rc_setup(dev);
285 return 0; 288 return 0;
diff --git a/drivers/media/dvb/dvb-usb/dib0700_devices.c b/drivers/media/dvb/dvb-usb/dib0700_devices.c
index e7093826e975..6477fc66cc23 100644
--- a/drivers/media/dvb/dvb-usb/dib0700_devices.c
+++ b/drivers/media/dvb/dvb-usb/dib0700_devices.c
@@ -13,6 +13,7 @@
13#include "dib7000p.h" 13#include "dib7000p.h"
14#include "mt2060.h" 14#include "mt2060.h"
15#include "mt2266.h" 15#include "mt2266.h"
16#include "tuner-xc2028.h"
16#include "dib0070.h" 17#include "dib0070.h"
17 18
18static int force_lna_activation; 19static int force_lna_activation;
@@ -297,10 +298,156 @@ static int stk7700d_tuner_attach(struct dvb_usb_adapter *adap)
297 &stk7700d_mt2266_config[adap->id]) == NULL ? -ENODEV : 0;; 298 &stk7700d_mt2266_config[adap->id]) == NULL ? -ENODEV : 0;;
298} 299}
299 300
301/* STK7700-PH: Digital/Analog Hybrid Tuner, e.h. Cinergy HT USB HE */
302struct dibx000_agc_config xc3028_agc_config = {
303 BAND_VHF | BAND_UHF, /* band_caps */
304
305 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=0,
306 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
307 * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=2, P_agc_write=0 */
308 (0 << 15) | (0 << 14) | (0 << 11) | (0 << 10) | (0 << 9) | (0 << 8) |
309 (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), /* setup */
310
311 712, /* inv_gain */
312 21, /* time_stabiliz */
313
314 0, /* alpha_level */
315 118, /* thlock */
316
317 0, /* wbd_inv */
318 2867, /* wbd_ref */
319 0, /* wbd_sel */
320 2, /* wbd_alpha */
321
322 0, /* agc1_max */
323 0, /* agc1_min */
324 39718, /* agc2_max */
325 9930, /* agc2_min */
326 0, /* agc1_pt1 */
327 0, /* agc1_pt2 */
328 0, /* agc1_pt3 */
329 0, /* agc1_slope1 */
330 0, /* agc1_slope2 */
331 0, /* agc2_pt1 */
332 128, /* agc2_pt2 */
333 29, /* agc2_slope1 */
334 29, /* agc2_slope2 */
335
336 17, /* alpha_mant */
337 27, /* alpha_exp */
338 23, /* beta_mant */
339 51, /* beta_exp */
340
341 1, /* perform_agc_softsplit */
342};
343
344/* PLL Configuration for COFDM BW_MHz = 8.00 with external clock = 30.00 */
345struct dibx000_bandwidth_config xc3028_bw_config = {
346 60000, 30000, /* internal, sampling */
347 1, 8, 3, 1, 0, /* pll_cfg: prediv, ratio, range, reset, bypass */
348 0, 0, 1, 1, 0, /* misc: refdiv, bypclk_div, IO_CLK_en_core, ADClkSrc,
349 modulo */
350 (3 << 14) | (1 << 12) | (524 << 0), /* sad_cfg: refsel, sel, freq_15k */
351 (1 << 25) | 5816102, /* ifreq = 5.200000 MHz */
352 20452225, /* timf */
353 30000000, /* xtal_hz */
354};
355
356static struct dib7000p_config stk7700ph_dib7700_xc3028_config = {
357 .output_mpeg2_in_188_bytes = 1,
358 .tuner_is_baseband = 1,
359
360 .agc_config_count = 1,
361 .agc = &xc3028_agc_config,
362 .bw = &xc3028_bw_config,
363
364 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
365 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
366 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
367};
368
369static int stk7700ph_xc3028_callback(void *ptr, int command, int arg)
370{
371 struct dvb_usb_adapter *adap = ptr;
372
373 switch (command) {
374 case XC2028_TUNER_RESET:
375 /* Send the tuner in then out of reset */
376 dib7000p_set_gpio(adap->fe, 8, 0, 0); msleep(10);
377 dib7000p_set_gpio(adap->fe, 8, 0, 1);
378 break;
379 case XC2028_RESET_CLK:
380 break;
381 default:
382 err("%s: unknown command %d, arg %d\n", __func__,
383 command, arg);
384 return -EINVAL;
385 }
386 return 0;
387}
388
389static struct xc2028_ctrl stk7700ph_xc3028_ctrl = {
390 .fname = XC2028_DEFAULT_FIRMWARE,
391 .max_len = 64,
392 .demod = XC3028_FE_DIBCOM52,
393};
394
395static struct xc2028_config stk7700ph_xc3028_config = {
396 .i2c_addr = 0x61,
397 .callback = stk7700ph_xc3028_callback,
398 .ctrl = &stk7700ph_xc3028_ctrl,
399};
400
401static int stk7700ph_frontend_attach(struct dvb_usb_adapter *adap)
402{
403 struct usb_device_descriptor *desc = &adap->dev->udev->descriptor;
404
405 if (desc->idVendor == USB_VID_PINNACLE &&
406 desc->idProduct == USB_PID_PINNACLE_EXPRESSCARD_320CX)
407 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
408 else
409 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
410 msleep(20);
411 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
412 dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
413 dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
414 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
415 msleep(10);
416 dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
417 msleep(20);
418 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
419 msleep(10);
420
421 dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
422 &stk7700ph_dib7700_xc3028_config);
423
424 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80,
425 &stk7700ph_dib7700_xc3028_config);
426
427 return adap->fe == NULL ? -ENODEV : 0;
428}
429
430static int stk7700ph_tuner_attach(struct dvb_usb_adapter *adap)
431{
432 struct i2c_adapter *tun_i2c;
433
434 tun_i2c = dib7000p_get_i2c_master(adap->fe,
435 DIBX000_I2C_INTERFACE_TUNER, 1);
436
437 stk7700ph_xc3028_config.i2c_adap = tun_i2c;
438 stk7700ph_xc3028_config.video_dev = adap;
439
440 return dvb_attach(xc2028_attach, adap->fe, &stk7700ph_xc3028_config)
441 == NULL ? -ENODEV : 0;
442}
443
300#define DEFAULT_RC_INTERVAL 150 444#define DEFAULT_RC_INTERVAL 150
301 445
302static u8 rc_request[] = { REQUEST_POLL_RC, 0 }; 446static u8 rc_request[] = { REQUEST_POLL_RC, 0 };
303 447
448/* Number of keypresses to ignore before start repeating */
449#define RC_REPEAT_DELAY 2
450
304static int dib0700_rc_query(struct dvb_usb_device *d, u32 *event, int *state) 451static int dib0700_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
305{ 452{
306 u8 key[4]; 453 u8 key[4];
@@ -314,18 +461,67 @@ static int dib0700_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
314 err("RC Query Failed"); 461 err("RC Query Failed");
315 return -1; 462 return -1;
316 } 463 }
464
465 /* losing half of KEY_0 events from Philipps rc5 remotes.. */
317 if (key[0]==0 && key[1]==0 && key[2]==0 && key[3]==0) return 0; 466 if (key[0]==0 && key[1]==0 && key[2]==0 && key[3]==0) return 0;
318 if (key[3-1]!=st->rc_toggle) { 467
468 /* info("%d: %2X %2X %2X %2X",dvb_usb_dib0700_ir_proto,(int)key[3-2],(int)key[3-3],(int)key[3-1],(int)key[3]); */
469
470 dib0700_rc_setup(d); /* reset ir sensor data to prevent false events */
471
472 switch (dvb_usb_dib0700_ir_proto) {
473 case 0: {
474 /* NEC protocol sends repeat code as 0 0 0 FF */
475 if ((key[3-2] == 0x00) && (key[3-3] == 0x00) &&
476 (key[3] == 0xFF)) {
477 st->rc_counter++;
478 if (st->rc_counter > RC_REPEAT_DELAY) {
479 *event = d->last_event;
480 *state = REMOTE_KEY_PRESSED;
481 st->rc_counter = RC_REPEAT_DELAY;
482 }
483 return 0;
484 }
319 for (i=0;i<d->props.rc_key_map_size; i++) { 485 for (i=0;i<d->props.rc_key_map_size; i++) {
320 if (keymap[i].custom == key[3-2] && keymap[i].data == key[3-3]) { 486 if (keymap[i].custom == key[3-2] && keymap[i].data == key[3-3]) {
487 st->rc_counter = 0;
488 *event = keymap[i].event;
489 *state = REMOTE_KEY_PRESSED;
490 d->last_event = keymap[i].event;
491 return 0;
492 }
493 }
494 break;
495 }
496 default: {
497 /* RC-5 protocol changes toggle bit on new keypress */
498 for (i = 0; i < d->props.rc_key_map_size; i++) {
499 if (keymap[i].custom == key[3-2] && keymap[i].data == key[3-3]) {
500 if (d->last_event == keymap[i].event &&
501 key[3-1] == st->rc_toggle) {
502 st->rc_counter++;
503 /* prevents unwanted double hits */
504 if (st->rc_counter > RC_REPEAT_DELAY) {
505 *event = d->last_event;
506 *state = REMOTE_KEY_PRESSED;
507 st->rc_counter = RC_REPEAT_DELAY;
508 }
509
510 return 0;
511 }
512 st->rc_counter = 0;
321 *event = keymap[i].event; 513 *event = keymap[i].event;
322 *state = REMOTE_KEY_PRESSED; 514 *state = REMOTE_KEY_PRESSED;
323 st->rc_toggle=key[3-1]; 515 st->rc_toggle = key[3-1];
516 d->last_event = keymap[i].event;
324 return 0; 517 return 0;
325 } 518 }
326 } 519 }
327 err("Unknown remote controller key : %2X %2X",(int)key[3-2],(int)key[3-3]); 520 break;
328 } 521 }
522 }
523 err("Unknown remote controller key: %2X %2X %2X %2X", (int) key[3-2], (int) key[3-3], (int) key[3-1], (int) key[3]);
524 d->last_event = 0;
329 return 0; 525 return 0;
330} 526}
331 527
@@ -794,6 +990,10 @@ static struct dib7000p_config dib7070p_dib7000p_config = {
794/* STK7070P */ 990/* STK7070P */
795static int stk7070p_frontend_attach(struct dvb_usb_adapter *adap) 991static int stk7070p_frontend_attach(struct dvb_usb_adapter *adap)
796{ 992{
993 if (adap->dev->udev->descriptor.idVendor == USB_VID_PINNACLE &&
994 adap->dev->udev->descriptor.idProduct == USB_PID_PINNACLE_PCTV72E)
995 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 0);
996 else
797 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1); 997 dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
798 msleep(10); 998 msleep(10);
799 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1); 999 dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
@@ -808,9 +1008,11 @@ static int stk7070p_frontend_attach(struct dvb_usb_adapter *adap)
808 msleep(10); 1008 msleep(10);
809 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1); 1009 dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
810 1010
811 dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 18, &dib7070p_dib7000p_config); 1011 dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
1012 &dib7070p_dib7000p_config);
812 1013
813 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80, &dib7070p_dib7000p_config); 1014 adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80,
1015 &dib7070p_dib7000p_config);
814 return adap->fe == NULL ? -ENODEV : 0; 1016 return adap->fe == NULL ? -ENODEV : 0;
815} 1017}
816 1018
@@ -878,34 +1080,43 @@ static int stk7070pd_frontend_attach1(struct dvb_usb_adapter *adap)
878/* DVB-USB and USB stuff follows */ 1080/* DVB-USB and USB stuff follows */
879struct usb_device_id dib0700_usb_id_table[] = { 1081struct usb_device_id dib0700_usb_id_table[] = {
880/* 0 */ { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700P) }, 1082/* 0 */ { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700P) },
881 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700P_PC) }, 1083 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700P_PC) },
882 1084 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500) },
883 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500) }, 1085 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500_2) },
884 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500_2) }, 1086 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK) },
885 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK) },
886/* 5 */ { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR) }, 1087/* 5 */ { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR) },
887 { USB_DEVICE(USB_VID_COMPRO, USB_PID_COMPRO_VIDEOMATE_U500) }, 1088 { USB_DEVICE(USB_VID_COMPRO, USB_PID_COMPRO_VIDEOMATE_U500) },
888 { USB_DEVICE(USB_VID_UNIWILL, USB_PID_UNIWILL_STK7700P) }, 1089 { USB_DEVICE(USB_VID_UNIWILL, USB_PID_UNIWILL_STK7700P) },
889 { USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_STK7700P) }, 1090 { USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_STK7700P) },
890 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK_2) }, 1091 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK_2) },
891/* 10 */{ USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_2) }, 1092/* 10 */{ USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_2) },
892 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV2000E) }, 1093 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV2000E) },
893 { USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY) }, 1094 { USB_DEVICE(USB_VID_TERRATEC,
894 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_TD_STICK) }, 1095 USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY) },
895 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700D) }, 1096 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_TD_STICK) },
1097 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7700D) },
896/* 15 */{ USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7070P) }, 1098/* 15 */{ USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7070P) },
897 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV_DVB_T_FLASH) }, 1099 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV_DVB_T_FLASH) },
898 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7070PD) }, 1100 { USB_DEVICE(USB_VID_DIBCOM, USB_PID_DIBCOM_STK7070PD) },
899 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV_DUAL_DIVERSITY_DVB_T) }, 1101 { USB_DEVICE(USB_VID_PINNACLE,
900 { USB_DEVICE(USB_VID_COMPRO, USB_PID_COMPRO_VIDEOMATE_U500_PC) }, 1102 USB_PID_PINNACLE_PCTV_DUAL_DIVERSITY_DVB_T) },
1103 { USB_DEVICE(USB_VID_COMPRO, USB_PID_COMPRO_VIDEOMATE_U500_PC) },
901/* 20 */{ USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_EXPRESS) }, 1104/* 20 */{ USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_EXPRESS) },
902 { USB_DEVICE(USB_VID_GIGABYTE, USB_PID_GIGABYTE_U7000) }, 1105 { USB_DEVICE(USB_VID_GIGABYTE, USB_PID_GIGABYTE_U7000) },
903 { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ARTEC_T14BR) }, 1106 { USB_DEVICE(USB_VID_ULTIMA_ELECTRONIC, USB_PID_ARTEC_T14BR) },
904 { USB_DEVICE(USB_VID_ASUS, USB_PID_ASUS_U3000) }, 1107 { USB_DEVICE(USB_VID_ASUS, USB_PID_ASUS_U3000) },
905 { USB_DEVICE(USB_VID_ASUS, USB_PID_ASUS_U3100) }, 1108 { USB_DEVICE(USB_VID_ASUS, USB_PID_ASUS_U3100) },
906/* 25 */ { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK_3) }, 1109/* 25 */{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_STICK_3) },
907 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_MYTV_T) }, 1110 { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_MYTV_T) },
908 { 0 } /* Terminating entry */ 1111 { USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_HT_USB_XE) },
1112 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_EXPRESSCARD_320CX) },
1113 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV72E) },
1114/* 30 */{ USB_DEVICE(USB_VID_PINNACLE, USB_PID_PINNACLE_PCTV73E) },
1115 { USB_DEVICE(USB_VID_YUAN, USB_PID_YUAN_EC372S) },
1116 { USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_HT_EXPRESS) },
1117 { USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_XXS) },
1118 { USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_STK7700P_2) },
1119 { 0 } /* Terminating entry */
909}; 1120};
910MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table); 1121MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table);
911 1122
@@ -969,7 +1180,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
969 { NULL }, 1180 { NULL },
970 }, 1181 },
971 { "Leadtek Winfast DTV Dongle (STK7700P based)", 1182 { "Leadtek Winfast DTV Dongle (STK7700P based)",
972 { &dib0700_usb_id_table[8], NULL }, 1183 { &dib0700_usb_id_table[8], &dib0700_usb_id_table[34] },
973 { NULL }, 1184 { NULL },
974 }, 1185 },
975 { "AVerMedia AVerTV DVB-T Express", 1186 { "AVerMedia AVerTV DVB-T Express",
@@ -1069,12 +1280,16 @@ struct dvb_usb_device_properties dib0700_devices[] = {
1069 }, 1280 },
1070 }, 1281 },
1071 1282
1072 .num_device_descs = 1, 1283 .num_device_descs = 2,
1073 .devices = { 1284 .devices = {
1074 { "ASUS My Cinema U3000 Mini DVBT Tuner", 1285 { "ASUS My Cinema U3000 Mini DVBT Tuner",
1075 { &dib0700_usb_id_table[23], NULL }, 1286 { &dib0700_usb_id_table[23], NULL },
1076 { NULL }, 1287 { NULL },
1077 }, 1288 },
1289 { "Yuan EC372S",
1290 { &dib0700_usb_id_table[31], NULL },
1291 { NULL },
1292 }
1078 } 1293 }
1079 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES, 1294 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
1080 1295
@@ -1090,7 +1305,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
1090 }, 1305 },
1091 }, 1306 },
1092 1307
1093 .num_device_descs = 6, 1308 .num_device_descs = 9,
1094 .devices = { 1309 .devices = {
1095 { "DiBcom STK7070P reference design", 1310 { "DiBcom STK7070P reference design",
1096 { &dib0700_usb_id_table[15], NULL }, 1311 { &dib0700_usb_id_table[15], NULL },
@@ -1116,6 +1331,18 @@ struct dvb_usb_device_properties dib0700_devices[] = {
1116 { &dib0700_usb_id_table[26], NULL }, 1331 { &dib0700_usb_id_table[26], NULL },
1117 { NULL }, 1332 { NULL },
1118 }, 1333 },
1334 { "Pinnacle PCTV 72e",
1335 { &dib0700_usb_id_table[29], NULL },
1336 { NULL },
1337 },
1338 { "Pinnacle PCTV 73e",
1339 { &dib0700_usb_id_table[30], NULL },
1340 { NULL },
1341 },
1342 { "Terratec Cinergy T USB XXS",
1343 { &dib0700_usb_id_table[33], NULL },
1344 { NULL },
1345 },
1119 }, 1346 },
1120 1347
1121 .rc_interval = DEFAULT_RC_INTERVAL, 1348 .rc_interval = DEFAULT_RC_INTERVAL,
@@ -1155,6 +1382,40 @@ struct dvb_usb_device_properties dib0700_devices[] = {
1155 { NULL }, 1382 { NULL },
1156 } 1383 }
1157 } 1384 }
1385 }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
1386
1387 .num_adapters = 1,
1388 .adapter = {
1389 {
1390 .frontend_attach = stk7700ph_frontend_attach,
1391 .tuner_attach = stk7700ph_tuner_attach,
1392
1393 DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
1394
1395 .size_of_priv = sizeof(struct
1396 dib0700_adapter_state),
1397 },
1398 },
1399
1400 .num_device_descs = 3,
1401 .devices = {
1402 { "Terratec Cinergy HT USB XE",
1403 { &dib0700_usb_id_table[27], NULL },
1404 { NULL },
1405 },
1406 { "Pinnacle Expresscard 320cx",
1407 { &dib0700_usb_id_table[28], NULL },
1408 { NULL },
1409 },
1410 { "Terratec Cinergy HT Express",
1411 { &dib0700_usb_id_table[32], NULL },
1412 { NULL },
1413 },
1414 },
1415 .rc_interval = DEFAULT_RC_INTERVAL,
1416 .rc_key_map = dib0700_rc_keys,
1417 .rc_key_map_size = ARRAY_SIZE(dib0700_rc_keys),
1418 .rc_query = dib0700_rc_query
1158 }, 1419 },
1159}; 1420};
1160 1421
diff --git a/drivers/media/dvb/dvb-usb/dibusb-mb.c b/drivers/media/dvb/dvb-usb/dibusb-mb.c
index 043cadae0859..eeef50bff4f9 100644
--- a/drivers/media/dvb/dvb-usb/dibusb-mb.c
+++ b/drivers/media/dvb/dvb-usb/dibusb-mb.c
@@ -14,6 +14,8 @@
14 */ 14 */
15#include "dibusb.h" 15#include "dibusb.h"
16 16
17DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
18
17static int dib3000mb_i2c_gate_ctrl(struct dvb_frontend* fe, int enable) 19static int dib3000mb_i2c_gate_ctrl(struct dvb_frontend* fe, int enable)
18{ 20{
19 struct dvb_usb_adapter *adap = fe->dvb->priv; 21 struct dvb_usb_adapter *adap = fe->dvb->priv;
@@ -107,10 +109,14 @@ static struct dvb_usb_device_properties artec_t1_usb2_properties;
107static int dibusb_probe(struct usb_interface *intf, 109static int dibusb_probe(struct usb_interface *intf,
108 const struct usb_device_id *id) 110 const struct usb_device_id *id)
109{ 111{
110 if (dvb_usb_device_init(intf,&dibusb1_1_properties,THIS_MODULE,NULL) == 0 || 112 if (0 == dvb_usb_device_init(intf, &dibusb1_1_properties,
111 dvb_usb_device_init(intf,&dibusb1_1_an2235_properties,THIS_MODULE,NULL) == 0 || 113 THIS_MODULE, NULL, adapter_nr) ||
112 dvb_usb_device_init(intf,&dibusb2_0b_properties,THIS_MODULE,NULL) == 0 || 114 0 == dvb_usb_device_init(intf, &dibusb1_1_an2235_properties,
113 dvb_usb_device_init(intf,&artec_t1_usb2_properties,THIS_MODULE,NULL) == 0) 115 THIS_MODULE, NULL, adapter_nr) ||
116 0 == dvb_usb_device_init(intf, &dibusb2_0b_properties,
117 THIS_MODULE, NULL, adapter_nr) ||
118 0 == dvb_usb_device_init(intf, &artec_t1_usb2_properties,
119 THIS_MODULE, NULL, adapter_nr))
114 return 0; 120 return 0;
115 121
116 return -EINVAL; 122 return -EINVAL;
diff --git a/drivers/media/dvb/dvb-usb/dibusb-mc.c b/drivers/media/dvb/dvb-usb/dibusb-mc.c
index e7ea3e753d6d..059cec955318 100644
--- a/drivers/media/dvb/dvb-usb/dibusb-mc.c
+++ b/drivers/media/dvb/dvb-usb/dibusb-mc.c
@@ -14,13 +14,16 @@
14 */ 14 */
15#include "dibusb.h" 15#include "dibusb.h"
16 16
17DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
18
17/* USB Driver stuff */ 19/* USB Driver stuff */
18static struct dvb_usb_device_properties dibusb_mc_properties; 20static struct dvb_usb_device_properties dibusb_mc_properties;
19 21
20static int dibusb_mc_probe(struct usb_interface *intf, 22static int dibusb_mc_probe(struct usb_interface *intf,
21 const struct usb_device_id *id) 23 const struct usb_device_id *id)
22{ 24{
23 return dvb_usb_device_init(intf,&dibusb_mc_properties,THIS_MODULE,NULL); 25 return dvb_usb_device_init(intf, &dibusb_mc_properties, THIS_MODULE,
26 NULL, adapter_nr);
24} 27}
25 28
26/* do not change the order of the ID table */ 29/* do not change the order of the ID table */
diff --git a/drivers/media/dvb/dvb-usb/digitv.c b/drivers/media/dvb/dvb-usb/digitv.c
index 3acbda4aa27e..b545cf3eab2e 100644
--- a/drivers/media/dvb/dvb-usb/digitv.c
+++ b/drivers/media/dvb/dvb-usb/digitv.c
@@ -20,6 +20,9 @@
20static int dvb_usb_digitv_debug; 20static int dvb_usb_digitv_debug;
21module_param_named(debug,dvb_usb_digitv_debug, int, 0644); 21module_param_named(debug,dvb_usb_digitv_debug, int, 0644);
22MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS); 22MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
23
24DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
25
23#define deb_rc(args...) dprintk(dvb_usb_digitv_debug,0x01,args) 26#define deb_rc(args...) dprintk(dvb_usb_digitv_debug,0x01,args)
24 27
25static int digitv_ctrl_msg(struct dvb_usb_device *d, 28static int digitv_ctrl_msg(struct dvb_usb_device *d,
@@ -256,8 +259,9 @@ static int digitv_probe(struct usb_interface *intf,
256 const struct usb_device_id *id) 259 const struct usb_device_id *id)
257{ 260{
258 struct dvb_usb_device *d; 261 struct dvb_usb_device *d;
259 int ret; 262 int ret = dvb_usb_device_init(intf, &digitv_properties, THIS_MODULE, &d,
260 if ((ret = dvb_usb_device_init(intf,&digitv_properties,THIS_MODULE,&d)) == 0) { 263 adapter_nr);
264 if (ret == 0) {
261 u8 b[4] = { 0 }; 265 u8 b[4] = { 0 };
262 266
263 if (d != NULL) { /* do that only when the firmware is loaded */ 267 if (d != NULL) { /* do that only when the firmware is loaded */
diff --git a/drivers/media/dvb/dvb-usb/dtt200u.c b/drivers/media/dvb/dvb-usb/dtt200u.c
index d86cf9bee91c..81a6cbf60160 100644
--- a/drivers/media/dvb/dvb-usb/dtt200u.c
+++ b/drivers/media/dvb/dvb-usb/dtt200u.c
@@ -18,6 +18,8 @@ int dvb_usb_dtt200u_debug;
18module_param_named(debug,dvb_usb_dtt200u_debug, int, 0644); 18module_param_named(debug,dvb_usb_dtt200u_debug, int, 0644);
19MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2 (or-able))." DVB_USB_DEBUG_STATUS); 19MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2 (or-able))." DVB_USB_DEBUG_STATUS);
20 20
21DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
22
21static int dtt200u_power_ctrl(struct dvb_usb_device *d, int onoff) 23static int dtt200u_power_ctrl(struct dvb_usb_device *d, int onoff)
22{ 24{
23 u8 b = SET_INIT; 25 u8 b = SET_INIT;
@@ -101,11 +103,16 @@ static struct dvb_usb_device_properties wt220u_miglia_properties;
101static int dtt200u_usb_probe(struct usb_interface *intf, 103static int dtt200u_usb_probe(struct usb_interface *intf,
102 const struct usb_device_id *id) 104 const struct usb_device_id *id)
103{ 105{
104 if (dvb_usb_device_init(intf,&dtt200u_properties,THIS_MODULE,NULL) == 0 || 106 if (0 == dvb_usb_device_init(intf, &dtt200u_properties,
105 dvb_usb_device_init(intf,&wt220u_properties,THIS_MODULE,NULL) == 0 || 107 THIS_MODULE, NULL, adapter_nr) ||
106 dvb_usb_device_init(intf,&wt220u_fc_properties,THIS_MODULE,NULL) == 0 || 108 0 == dvb_usb_device_init(intf, &wt220u_properties,
107 dvb_usb_device_init(intf,&wt220u_zl0353_properties,THIS_MODULE,NULL) == 0 || 109 THIS_MODULE, NULL, adapter_nr) ||
108 dvb_usb_device_init(intf,&wt220u_miglia_properties,THIS_MODULE,NULL) == 0) 110 0 == dvb_usb_device_init(intf, &wt220u_fc_properties,
111 THIS_MODULE, NULL, adapter_nr) ||
112 0 == dvb_usb_device_init(intf, &wt220u_zl0353_properties,
113 THIS_MODULE, NULL, adapter_nr) ||
114 0 == dvb_usb_device_init(intf, &wt220u_miglia_properties,
115 THIS_MODULE, NULL, adapter_nr))
109 return 0; 116 return 0;
110 117
111 return -ENODEV; 118 return -ENODEV;
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-common.h b/drivers/media/dvb/dvb-usb/dvb-usb-common.h
index 35ab68f6dcf6..6b7b2a89242e 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-common.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-common.h
@@ -40,7 +40,8 @@ extern int dvb_usb_adapter_stream_exit(struct dvb_usb_adapter *adap);
40extern int dvb_usb_i2c_init(struct dvb_usb_device *); 40extern int dvb_usb_i2c_init(struct dvb_usb_device *);
41extern int dvb_usb_i2c_exit(struct dvb_usb_device *); 41extern int dvb_usb_i2c_exit(struct dvb_usb_device *);
42 42
43extern int dvb_usb_adapter_dvb_init(struct dvb_usb_adapter *adap); 43extern int dvb_usb_adapter_dvb_init(struct dvb_usb_adapter *adap,
44 short *adapter_nums);
44extern int dvb_usb_adapter_dvb_exit(struct dvb_usb_adapter *adap); 45extern int dvb_usb_adapter_dvb_exit(struct dvb_usb_adapter *adap);
45extern int dvb_usb_adapter_frontend_init(struct dvb_usb_adapter *adap); 46extern int dvb_usb_adapter_frontend_init(struct dvb_usb_adapter *adap);
46extern int dvb_usb_adapter_frontend_exit(struct dvb_usb_adapter *adap); 47extern int dvb_usb_adapter_frontend_exit(struct dvb_usb_adapter *adap);
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c b/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c
index 4561a672da92..ce8cd0c5d831 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-dvb.c
@@ -77,12 +77,13 @@ static int dvb_usb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
77 return dvb_usb_ctrl_feed(dvbdmxfeed,0); 77 return dvb_usb_ctrl_feed(dvbdmxfeed,0);
78} 78}
79 79
80int dvb_usb_adapter_dvb_init(struct dvb_usb_adapter *adap) 80int dvb_usb_adapter_dvb_init(struct dvb_usb_adapter *adap, short *adapter_nums)
81{ 81{
82 int ret; 82 int ret = dvb_register_adapter(&adap->dvb_adap, adap->dev->desc->name,
83 adap->dev->owner, &adap->dev->udev->dev,
84 adapter_nums);
83 85
84 if ((ret = dvb_register_adapter(&adap->dvb_adap, adap->dev->desc->name, 86 if (ret < 0) {
85 adap->dev->owner, &adap->dev->udev->dev)) < 0) {
86 deb_info("dvb_register_adapter failed: error %d", ret); 87 deb_info("dvb_register_adapter failed: error %d", ret);
87 goto err; 88 goto err;
88 } 89 }
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
index aa4844ef875e..34245d1b7dd9 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-ids.h
@@ -40,14 +40,15 @@
40#define USB_VID_MSI 0x0db0 40#define USB_VID_MSI 0x0db0
41#define USB_VID_OPERA1 0x695c 41#define USB_VID_OPERA1 0x695c
42#define USB_VID_PINNACLE 0x2304 42#define USB_VID_PINNACLE 0x2304
43#define USB_VID_TECHNOTREND 0x0b48
43#define USB_VID_TERRATEC 0x0ccd 44#define USB_VID_TERRATEC 0x0ccd
44#define USB_VID_VISIONPLUS 0x13d3 45#define USB_VID_VISIONPLUS 0x13d3
45#define USB_VID_TWINHAN 0x1822 46#define USB_VID_TWINHAN 0x1822
46#define USB_VID_ULTIMA_ELECTRONIC 0x05d8 47#define USB_VID_ULTIMA_ELECTRONIC 0x05d8
47#define USB_VID_UNIWILL 0x1584 48#define USB_VID_UNIWILL 0x1584
48#define USB_VID_WIDEVIEW 0x14aa 49#define USB_VID_WIDEVIEW 0x14aa
49/* dom : pour gigabyte u7000 */
50#define USB_VID_GIGABYTE 0x1044 50#define USB_VID_GIGABYTE 0x1044
51#define USB_VID_YUAN 0x1164
51 52
52 53
53/* Product IDs */ 54/* Product IDs */
@@ -134,10 +135,17 @@
134#define USB_PID_AVERMEDIA_EXPRESS 0xb568 135#define USB_PID_AVERMEDIA_EXPRESS 0xb568
135#define USB_PID_AVERMEDIA_VOLAR 0xa807 136#define USB_PID_AVERMEDIA_VOLAR 0xa807
136#define USB_PID_AVERMEDIA_VOLAR_2 0xb808 137#define USB_PID_AVERMEDIA_VOLAR_2 0xb808
138#define USB_PID_TECHNOTREND_CONNECT_S2400 0x3006
137#define USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY 0x005a 139#define USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY 0x005a
140#define USB_PID_TERRATEC_CINERGY_HT_USB_XE 0x0058
141#define USB_PID_TERRATEC_CINERGY_HT_EXPRESS 0x0060
142#define USB_PID_TERRATEC_CINERGY_T_XXS 0x0078
143#define USB_PID_PINNACLE_EXPRESSCARD_320CX 0x022e
138#define USB_PID_PINNACLE_PCTV2000E 0x022c 144#define USB_PID_PINNACLE_PCTV2000E 0x022c
139#define USB_PID_PINNACLE_PCTV_DVB_T_FLASH 0x0228 145#define USB_PID_PINNACLE_PCTV_DVB_T_FLASH 0x0228
140#define USB_PID_PINNACLE_PCTV_DUAL_DIVERSITY_DVB_T 0x0229 146#define USB_PID_PINNACLE_PCTV_DUAL_DIVERSITY_DVB_T 0x0229
147#define USB_PID_PINNACLE_PCTV72E 0x0236
148#define USB_PID_PINNACLE_PCTV73E 0x0237
141#define USB_PID_PCTV_200E 0x020e 149#define USB_PID_PCTV_200E 0x020e
142#define USB_PID_PCTV_400E 0x020f 150#define USB_PID_PCTV_400E 0x020f
143#define USB_PID_PCTV_450E 0x0222 151#define USB_PID_PCTV_450E 0x0222
@@ -172,6 +180,7 @@
172#define USB_PID_WINFAST_DTV_DONGLE_COLD 0x6025 180#define USB_PID_WINFAST_DTV_DONGLE_COLD 0x6025
173#define USB_PID_WINFAST_DTV_DONGLE_WARM 0x6026 181#define USB_PID_WINFAST_DTV_DONGLE_WARM 0x6026
174#define USB_PID_WINFAST_DTV_DONGLE_STK7700P 0x6f00 182#define USB_PID_WINFAST_DTV_DONGLE_STK7700P 0x6f00
183#define USB_PID_WINFAST_DTV_DONGLE_STK7700P_2 0x6f01
175#define USB_PID_GENPIX_8PSK_REV_1_COLD 0x0200 184#define USB_PID_GENPIX_8PSK_REV_1_COLD 0x0200
176#define USB_PID_GENPIX_8PSK_REV_1_WARM 0x0201 185#define USB_PID_GENPIX_8PSK_REV_1_WARM 0x0201
177#define USB_PID_GENPIX_8PSK_REV_2 0x0202 186#define USB_PID_GENPIX_8PSK_REV_2 0x0202
@@ -183,9 +192,9 @@
183#define USB_PID_OPERA1_WARM 0x3829 192#define USB_PID_OPERA1_WARM 0x3829
184#define USB_PID_LIFEVIEW_TV_WALKER_TWIN_COLD 0x0514 193#define USB_PID_LIFEVIEW_TV_WALKER_TWIN_COLD 0x0514
185#define USB_PID_LIFEVIEW_TV_WALKER_TWIN_WARM 0x0513 194#define USB_PID_LIFEVIEW_TV_WALKER_TWIN_WARM 0x0513
186/* dom pour gigabyte u7000 */
187#define USB_PID_GIGABYTE_U7000 0x7001 195#define USB_PID_GIGABYTE_U7000 0x7001
188#define USB_PID_ASUS_U3000 0x171f 196#define USB_PID_ASUS_U3000 0x171f
189#define USB_PID_ASUS_U3100 0x173f 197#define USB_PID_ASUS_U3100 0x173f
198#define USB_PID_YUAN_EC372S 0x1edc
190 199
191#endif 200#endif
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb-init.c b/drivers/media/dvb/dvb-usb/dvb-usb-init.c
index cdd717c3fe45..e331db8c77b2 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb-init.c
+++ b/drivers/media/dvb/dvb-usb/dvb-usb-init.c
@@ -26,7 +26,7 @@ static int dvb_usb_force_pid_filter_usage;
26module_param_named(force_pid_filter_usage, dvb_usb_force_pid_filter_usage, int, 0444); 26module_param_named(force_pid_filter_usage, dvb_usb_force_pid_filter_usage, int, 0444);
27MODULE_PARM_DESC(force_pid_filter_usage, "force all dvb-usb-devices to use a PID filter, if any (default: 0)."); 27MODULE_PARM_DESC(force_pid_filter_usage, "force all dvb-usb-devices to use a PID filter, if any (default: 0).");
28 28
29static int dvb_usb_adapter_init(struct dvb_usb_device *d) 29static int dvb_usb_adapter_init(struct dvb_usb_device *d, short *adapter_nrs)
30{ 30{
31 struct dvb_usb_adapter *adap; 31 struct dvb_usb_adapter *adap;
32 int ret,n; 32 int ret,n;
@@ -72,7 +72,7 @@ static int dvb_usb_adapter_init(struct dvb_usb_device *d)
72 } 72 }
73 73
74 if ((ret = dvb_usb_adapter_stream_init(adap)) || 74 if ((ret = dvb_usb_adapter_stream_init(adap)) ||
75 (ret = dvb_usb_adapter_dvb_init(adap)) || 75 (ret = dvb_usb_adapter_dvb_init(adap, adapter_nrs)) ||
76 (ret = dvb_usb_adapter_frontend_init(adap))) { 76 (ret = dvb_usb_adapter_frontend_init(adap))) {
77 return ret; 77 return ret;
78 } 78 }
@@ -122,7 +122,7 @@ static int dvb_usb_exit(struct dvb_usb_device *d)
122 return 0; 122 return 0;
123} 123}
124 124
125static int dvb_usb_init(struct dvb_usb_device *d) 125static int dvb_usb_init(struct dvb_usb_device *d, short *adapter_nums)
126{ 126{
127 int ret = 0; 127 int ret = 0;
128 128
@@ -143,7 +143,7 @@ static int dvb_usb_init(struct dvb_usb_device *d)
143 dvb_usb_device_power_ctrl(d, 1); 143 dvb_usb_device_power_ctrl(d, 1);
144 144
145 if ((ret = dvb_usb_i2c_init(d)) || 145 if ((ret = dvb_usb_i2c_init(d)) ||
146 (ret = dvb_usb_adapter_init(d))) { 146 (ret = dvb_usb_adapter_init(d, adapter_nums))) {
147 dvb_usb_exit(d); 147 dvb_usb_exit(d);
148 return ret; 148 return ret;
149 } 149 }
@@ -213,8 +213,10 @@ int dvb_usb_device_power_ctrl(struct dvb_usb_device *d, int onoff)
213/* 213/*
214 * USB 214 * USB
215 */ 215 */
216int dvb_usb_device_init(struct usb_interface *intf, struct dvb_usb_device_properties 216int dvb_usb_device_init(struct usb_interface *intf,
217 *props, struct module *owner,struct dvb_usb_device **du) 217 struct dvb_usb_device_properties *props,
218 struct module *owner, struct dvb_usb_device **du,
219 short *adapter_nums)
218{ 220{
219 struct usb_device *udev = interface_to_usbdev(intf); 221 struct usb_device *udev = interface_to_usbdev(intf);
220 struct dvb_usb_device *d = NULL; 222 struct dvb_usb_device *d = NULL;
@@ -254,7 +256,7 @@ int dvb_usb_device_init(struct usb_interface *intf, struct dvb_usb_device_proper
254 if (du != NULL) 256 if (du != NULL)
255 *du = d; 257 *du = d;
256 258
257 ret = dvb_usb_init(d); 259 ret = dvb_usb_init(d, adapter_nums);
258 260
259 if (ret == 0) 261 if (ret == 0)
260 info("%s successfully initialized and connected.",desc->name); 262 info("%s successfully initialized and connected.",desc->name);
diff --git a/drivers/media/dvb/dvb-usb/dvb-usb.h b/drivers/media/dvb/dvb-usb/dvb-usb.h
index d1b3c7b81fff..b1de0f7e26e8 100644
--- a/drivers/media/dvb/dvb-usb/dvb-usb.h
+++ b/drivers/media/dvb/dvb-usb/dvb-usb.h
@@ -372,7 +372,10 @@ struct dvb_usb_device {
372 void *priv; 372 void *priv;
373}; 373};
374 374
375extern int dvb_usb_device_init(struct usb_interface *, struct dvb_usb_device_properties *, struct module *, struct dvb_usb_device **); 375extern int dvb_usb_device_init(struct usb_interface *,
376 struct dvb_usb_device_properties *,
377 struct module *, struct dvb_usb_device **,
378 short *adapter_nums);
376extern void dvb_usb_device_exit(struct usb_interface *); 379extern void dvb_usb_device_exit(struct usb_interface *);
377 380
378/* the generic read/write method for device control */ 381/* the generic read/write method for device control */
diff --git a/drivers/media/dvb/dvb-usb/gl861.c b/drivers/media/dvb/dvb-usb/gl861.c
index 6b99d9f4d5b3..0a8ac64a4e33 100644
--- a/drivers/media/dvb/dvb-usb/gl861.c
+++ b/drivers/media/dvb/dvb-usb/gl861.c
@@ -16,6 +16,8 @@ static int dvb_usb_gl861_debug;
16module_param_named(debug,dvb_usb_gl861_debug, int, 0644); 16module_param_named(debug,dvb_usb_gl861_debug, int, 0644);
17MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS); 17MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
18 18
19DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
20
19static int gl861_i2c_msg(struct dvb_usb_device *d, u8 addr, 21static int gl861_i2c_msg(struct dvb_usb_device *d, u8 addr,
20 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen) 22 u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
21{ 23{
@@ -140,7 +142,9 @@ static int gl861_probe(struct usb_interface *intf,
140 if (intf->num_altsetting < 2) 142 if (intf->num_altsetting < 2)
141 return -ENODEV; 143 return -ENODEV;
142 144
143 if ((ret = dvb_usb_device_init(intf, &gl861_properties, THIS_MODULE, &d)) == 0) { 145 ret = dvb_usb_device_init(intf, &gl861_properties, THIS_MODULE, &d,
146 adapter_nr);
147 if (ret == 0) {
144 alt = usb_altnum_to_altsetting(intf, 0); 148 alt = usb_altnum_to_altsetting(intf, 0);
145 149
146 if (alt == NULL) { 150 if (alt == NULL) {
diff --git a/drivers/media/dvb/dvb-usb/gp8psk-fe.c b/drivers/media/dvb/dvb-usb/gp8psk-fe.c
index e37142d9271a..262a858c3068 100644
--- a/drivers/media/dvb/dvb-usb/gp8psk-fe.c
+++ b/drivers/media/dvb/dvb-usb/gp8psk-fe.c
@@ -152,7 +152,7 @@ static int gp8psk_fe_send_diseqc_msg (struct dvb_frontend* fe,
152{ 152{
153 struct gp8psk_fe_state *st = fe->demodulator_priv; 153 struct gp8psk_fe_state *st = fe->demodulator_priv;
154 154
155 deb_fe("%s\n",__FUNCTION__); 155 deb_fe("%s\n",__func__);
156 156
157 if (gp8psk_usb_out_op(st->d,SEND_DISEQC_COMMAND, m->msg[0], 0, 157 if (gp8psk_usb_out_op(st->d,SEND_DISEQC_COMMAND, m->msg[0], 0,
158 m->msg, m->msg_len)) { 158 m->msg, m->msg_len)) {
@@ -167,7 +167,7 @@ static int gp8psk_fe_send_diseqc_burst (struct dvb_frontend* fe,
167 struct gp8psk_fe_state *st = fe->demodulator_priv; 167 struct gp8psk_fe_state *st = fe->demodulator_priv;
168 u8 cmd; 168 u8 cmd;
169 169
170 deb_fe("%s\n",__FUNCTION__); 170 deb_fe("%s\n",__func__);
171 171
172 /* These commands are certainly wrong */ 172 /* These commands are certainly wrong */
173 cmd = (burst == SEC_MINI_A) ? 0x00 : 0x01; 173 cmd = (burst == SEC_MINI_A) ? 0x00 : 0x01;
diff --git a/drivers/media/dvb/dvb-usb/gp8psk.c b/drivers/media/dvb/dvb-usb/gp8psk.c
index 83e8535014c6..9a942afaf0af 100644
--- a/drivers/media/dvb/dvb-usb/gp8psk.c
+++ b/drivers/media/dvb/dvb-usb/gp8psk.c
@@ -22,6 +22,8 @@ int dvb_usb_gp8psk_debug;
22module_param_named(debug,dvb_usb_gp8psk_debug, int, 0644); 22module_param_named(debug,dvb_usb_gp8psk_debug, int, 0644);
23MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DVB_USB_DEBUG_STATUS); 23MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DVB_USB_DEBUG_STATUS);
24 24
25DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
26
25int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen) 27int gp8psk_usb_in_op(struct dvb_usb_device *d, u8 req, u16 value, u16 index, u8 *b, int blen)
26{ 28{
27 int ret = 0,try = 0; 29 int ret = 0,try = 0;
@@ -190,7 +192,8 @@ static int gp8psk_usb_probe(struct usb_interface *intf,
190{ 192{
191 int ret; 193 int ret;
192 struct usb_device *udev = interface_to_usbdev(intf); 194 struct usb_device *udev = interface_to_usbdev(intf);
193 ret = dvb_usb_device_init(intf,&gp8psk_properties,THIS_MODULE,NULL); 195 ret = dvb_usb_device_init(intf, &gp8psk_properties,
196 THIS_MODULE, NULL, adapter_nr);
194 if (ret == 0) { 197 if (ret == 0) {
195 info("found Genpix USB device pID = %x (hex)", 198 info("found Genpix USB device pID = %x (hex)",
196 le16_to_cpu(udev->descriptor.idProduct)); 199 le16_to_cpu(udev->descriptor.idProduct));
diff --git a/drivers/media/dvb/dvb-usb/m920x.c b/drivers/media/dvb/dvb-usb/m920x.c
index a956bc503a4c..a12e6f784fda 100644
--- a/drivers/media/dvb/dvb-usb/m920x.c
+++ b/drivers/media/dvb/dvb-usb/m920x.c
@@ -22,6 +22,8 @@ static int dvb_usb_m920x_debug;
22module_param_named(debug,dvb_usb_m920x_debug, int, 0644); 22module_param_named(debug,dvb_usb_m920x_debug, int, 0644);
23MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS); 23MODULE_PARM_DESC(debug, "set debugging level (1=rc (or-able))." DVB_USB_DEBUG_STATUS);
24 24
25DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
26
25static int m920x_set_filter(struct dvb_usb_device *d, int type, int idx, int pid); 27static int m920x_set_filter(struct dvb_usb_device *d, int type, int idx, int pid);
26 28
27static inline int m920x_read(struct usb_device *udev, u8 request, u16 value, 29static inline int m920x_read(struct usb_device *udev, u8 request, u16 value,
@@ -477,7 +479,7 @@ static struct qt1010_config m920x_qt1010_config = {
477/* Callbacks for DVB USB */ 479/* Callbacks for DVB USB */
478static int m920x_mt352_frontend_attach(struct dvb_usb_adapter *adap) 480static int m920x_mt352_frontend_attach(struct dvb_usb_adapter *adap)
479{ 481{
480 deb("%s\n",__FUNCTION__); 482 deb("%s\n",__func__);
481 483
482 if ((adap->fe = dvb_attach(mt352_attach, 484 if ((adap->fe = dvb_attach(mt352_attach,
483 &m920x_mt352_config, 485 &m920x_mt352_config,
@@ -489,7 +491,7 @@ static int m920x_mt352_frontend_attach(struct dvb_usb_adapter *adap)
489 491
490static int m920x_tda10046_08_frontend_attach(struct dvb_usb_adapter *adap) 492static int m920x_tda10046_08_frontend_attach(struct dvb_usb_adapter *adap)
491{ 493{
492 deb("%s\n",__FUNCTION__); 494 deb("%s\n",__func__);
493 495
494 if ((adap->fe = dvb_attach(tda10046_attach, 496 if ((adap->fe = dvb_attach(tda10046_attach,
495 &m920x_tda10046_08_config, 497 &m920x_tda10046_08_config,
@@ -501,7 +503,7 @@ static int m920x_tda10046_08_frontend_attach(struct dvb_usb_adapter *adap)
501 503
502static int m920x_tda10046_0b_frontend_attach(struct dvb_usb_adapter *adap) 504static int m920x_tda10046_0b_frontend_attach(struct dvb_usb_adapter *adap)
503{ 505{
504 deb("%s\n",__FUNCTION__); 506 deb("%s\n",__func__);
505 507
506 if ((adap->fe = dvb_attach(tda10046_attach, 508 if ((adap->fe = dvb_attach(tda10046_attach,
507 &m920x_tda10046_0b_config, 509 &m920x_tda10046_0b_config,
@@ -513,7 +515,7 @@ static int m920x_tda10046_0b_frontend_attach(struct dvb_usb_adapter *adap)
513 515
514static int m920x_qt1010_tuner_attach(struct dvb_usb_adapter *adap) 516static int m920x_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
515{ 517{
516 deb("%s\n",__FUNCTION__); 518 deb("%s\n",__func__);
517 519
518 if (dvb_attach(qt1010_attach, adap->fe, &adap->dev->i2c_adap, &m920x_qt1010_config) == NULL) 520 if (dvb_attach(qt1010_attach, adap->fe, &adap->dev->i2c_adap, &m920x_qt1010_config) == NULL)
519 return -ENODEV; 521 return -ENODEV;
@@ -523,7 +525,7 @@ static int m920x_qt1010_tuner_attach(struct dvb_usb_adapter *adap)
523 525
524static int m920x_tda8275_60_tuner_attach(struct dvb_usb_adapter *adap) 526static int m920x_tda8275_60_tuner_attach(struct dvb_usb_adapter *adap)
525{ 527{
526 deb("%s\n",__FUNCTION__); 528 deb("%s\n",__func__);
527 529
528 if (dvb_attach(tda827x_attach, adap->fe, 0x60, &adap->dev->i2c_adap, NULL) == NULL) 530 if (dvb_attach(tda827x_attach, adap->fe, 0x60, &adap->dev->i2c_adap, NULL) == NULL)
529 return -ENODEV; 531 return -ENODEV;
@@ -533,7 +535,7 @@ static int m920x_tda8275_60_tuner_attach(struct dvb_usb_adapter *adap)
533 535
534static int m920x_tda8275_61_tuner_attach(struct dvb_usb_adapter *adap) 536static int m920x_tda8275_61_tuner_attach(struct dvb_usb_adapter *adap)
535{ 537{
536 deb("%s\n",__FUNCTION__); 538 deb("%s\n",__func__);
537 539
538 if (dvb_attach(tda827x_attach, adap->fe, 0x61, &adap->dev->i2c_adap, NULL) == NULL) 540 if (dvb_attach(tda827x_attach, adap->fe, 0x61, &adap->dev->i2c_adap, NULL) == NULL)
539 return -ENODEV; 541 return -ENODEV;
@@ -618,27 +620,31 @@ static int m920x_probe(struct usb_interface *intf,
618 * multi-tuner device 620 * multi-tuner device
619 */ 621 */
620 622
621 if ((ret = dvb_usb_device_init(intf, &megasky_properties, 623 ret = dvb_usb_device_init(intf, &megasky_properties,
622 THIS_MODULE, &d)) == 0) { 624 THIS_MODULE, &d, adapter_nr);
625 if (ret == 0) {
623 rc_init_seq = megasky_rc_init; 626 rc_init_seq = megasky_rc_init;
624 goto found; 627 goto found;
625 } 628 }
626 629
627 if ((ret = dvb_usb_device_init(intf, &digivox_mini_ii_properties, 630 ret = dvb_usb_device_init(intf, &digivox_mini_ii_properties,
628 THIS_MODULE, &d)) == 0) { 631 THIS_MODULE, &d, adapter_nr);
632 if (ret == 0) {
629 /* No remote control, so no rc_init_seq */ 633 /* No remote control, so no rc_init_seq */
630 goto found; 634 goto found;
631 } 635 }
632 636
633 /* This configures both tuners on the TV Walker Twin */ 637 /* This configures both tuners on the TV Walker Twin */
634 if ((ret = dvb_usb_device_init(intf, &tvwalkertwin_properties, 638 ret = dvb_usb_device_init(intf, &tvwalkertwin_properties,
635 THIS_MODULE, &d)) == 0) { 639 THIS_MODULE, &d, adapter_nr);
640 if (ret == 0) {
636 rc_init_seq = tvwalkertwin_rc_init; 641 rc_init_seq = tvwalkertwin_rc_init;
637 goto found; 642 goto found;
638 } 643 }
639 644
640 if ((ret = dvb_usb_device_init(intf, &dposh_properties, 645 ret = dvb_usb_device_init(intf, &dposh_properties,
641 THIS_MODULE, &d)) == 0) { 646 THIS_MODULE, &d, adapter_nr);
647 if (ret == 0) {
642 /* Remote controller not supported yet. */ 648 /* Remote controller not supported yet. */
643 goto found; 649 goto found;
644 } 650 }
diff --git a/drivers/media/dvb/dvb-usb/nova-t-usb2.c b/drivers/media/dvb/dvb-usb/nova-t-usb2.c
index badc468170ea..07fb843c7c2b 100644
--- a/drivers/media/dvb/dvb-usb/nova-t-usb2.c
+++ b/drivers/media/dvb/dvb-usb/nova-t-usb2.c
@@ -15,6 +15,8 @@ static int debug;
15module_param(debug, int, 0644); 15module_param(debug, int, 0644);
16MODULE_PARM_DESC(debug, "set debugging level (1=rc,2=eeprom (|-able))." DVB_USB_DEBUG_STATUS); 16MODULE_PARM_DESC(debug, "set debugging level (1=rc,2=eeprom (|-able))." DVB_USB_DEBUG_STATUS);
17 17
18DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
19
18#define deb_rc(args...) dprintk(debug,0x01,args) 20#define deb_rc(args...) dprintk(debug,0x01,args)
19#define deb_ee(args...) dprintk(debug,0x02,args) 21#define deb_ee(args...) dprintk(debug,0x02,args)
20 22
@@ -142,7 +144,8 @@ static struct dvb_usb_device_properties nova_t_properties;
142static int nova_t_probe(struct usb_interface *intf, 144static int nova_t_probe(struct usb_interface *intf,
143 const struct usb_device_id *id) 145 const struct usb_device_id *id)
144{ 146{
145 return dvb_usb_device_init(intf,&nova_t_properties,THIS_MODULE,NULL); 147 return dvb_usb_device_init(intf, &nova_t_properties,
148 THIS_MODULE, NULL, adapter_nr);
146} 149}
147 150
148/* do not change the order of the ID table */ 151/* do not change the order of the ID table */
diff --git a/drivers/media/dvb/dvb-usb/opera1.c b/drivers/media/dvb/dvb-usb/opera1.c
index 302cc67407c3..7e32d11f32b0 100644
--- a/drivers/media/dvb/dvb-usb/opera1.c
+++ b/drivers/media/dvb/dvb-usb/opera1.c
@@ -46,6 +46,9 @@ MODULE_PARM_DESC(debug,
46 "set debugging level (1=info,xfer=2,pll=4,ts=8,err=16,rc=32,fw=64 (or-able))." 46 "set debugging level (1=info,xfer=2,pll=4,ts=8,err=16,rc=32,fw=64 (or-able))."
47 DVB_USB_DEBUG_STATUS); 47 DVB_USB_DEBUG_STATUS);
48 48
49DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
50
51
49static int opera1_xilinx_rw(struct usb_device *dev, u8 request, u16 value, 52static int opera1_xilinx_rw(struct usb_device *dev, u8 request, u16 value,
50 u8 * data, u16 len, int flags) 53 u8 * data, u16 len, int flags)
51{ 54{
@@ -243,7 +246,7 @@ static struct stv0299_config opera1_stv0299_config = {
243 .mclk = 88000000UL, 246 .mclk = 88000000UL,
244 .invert = 1, 247 .invert = 1,
245 .skip_reinit = 0, 248 .skip_reinit = 0,
246 .lock_output = STV0229_LOCKOUTPUT_0, 249 .lock_output = STV0299_LOCKOUTPUT_0,
247 .volt13_op0_op1 = STV0299_VOLT13_OP0, 250 .volt13_op0_op1 = STV0299_VOLT13_OP0,
248 .inittab = opera1_inittab, 251 .inittab = opera1_inittab,
249 .set_symbol_rate = opera1_stv0299_set_symbol_rate, 252 .set_symbol_rate = opera1_stv0299_set_symbol_rate,
@@ -548,7 +551,8 @@ static int opera1_probe(struct usb_interface *intf,
548 return -EINVAL; 551 return -EINVAL;
549 } 552 }
550 553
551 if (dvb_usb_device_init(intf, &opera1_properties, THIS_MODULE, NULL) != 0) 554 if (0 != dvb_usb_device_init(intf, &opera1_properties,
555 THIS_MODULE, NULL, adapter_nr))
552 return -EINVAL; 556 return -EINVAL;
553 return 0; 557 return 0;
554} 558}
diff --git a/drivers/media/dvb/dvb-usb/ttusb2.c b/drivers/media/dvb/dvb-usb/ttusb2.c
index 3b9da9c25c6e..20ca9d9ee99b 100644
--- a/drivers/media/dvb/dvb-usb/ttusb2.c
+++ b/drivers/media/dvb/dvb-usb/ttusb2.c
@@ -37,6 +37,8 @@ static int dvb_usb_ttusb2_debug;
37module_param_named(debug,dvb_usb_ttusb2_debug, int, 0644); 37module_param_named(debug,dvb_usb_ttusb2_debug, int, 0644);
38MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able))." DVB_USB_DEBUG_STATUS); 38MODULE_PARM_DESC(debug, "set debugging level (1=info (or-able))." DVB_USB_DEBUG_STATUS);
39 39
40DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
41
40struct ttusb2_state { 42struct ttusb2_state {
41 u8 id; 43 u8 id;
42}; 44};
@@ -145,6 +147,7 @@ static struct tda10086_config tda10086_config = {
145 .demod_address = 0x0e, 147 .demod_address = 0x0e,
146 .invert = 0, 148 .invert = 0,
147 .diseqc_tone = 1, 149 .diseqc_tone = 1,
150 .xtal_freq = TDA10086_XTAL_16M,
148}; 151};
149 152
150static int ttusb2_frontend_attach(struct dvb_usb_adapter *adap) 153static int ttusb2_frontend_attach(struct dvb_usb_adapter *adap)
@@ -176,17 +179,25 @@ static int ttusb2_tuner_attach(struct dvb_usb_adapter *adap)
176 179
177/* DVB USB Driver stuff */ 180/* DVB USB Driver stuff */
178static struct dvb_usb_device_properties ttusb2_properties; 181static struct dvb_usb_device_properties ttusb2_properties;
182static struct dvb_usb_device_properties ttusb2_properties_s2400;
179 183
180static int ttusb2_probe(struct usb_interface *intf, 184static int ttusb2_probe(struct usb_interface *intf,
181 const struct usb_device_id *id) 185 const struct usb_device_id *id)
182{ 186{
183 return dvb_usb_device_init(intf,&ttusb2_properties,THIS_MODULE,NULL); 187 if (0 == dvb_usb_device_init(intf, &ttusb2_properties,
188 THIS_MODULE, NULL, adapter_nr) ||
189 0 == dvb_usb_device_init(intf, &ttusb2_properties_s2400,
190 THIS_MODULE, NULL, adapter_nr))
191 return 0;
192 return -ENODEV;
184} 193}
185 194
186static struct usb_device_id ttusb2_table [] = { 195static struct usb_device_id ttusb2_table [] = {
187 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PCTV_400E) }, 196 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PCTV_400E) },
188 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PCTV_450E) }, 197 { USB_DEVICE(USB_VID_PINNACLE, USB_PID_PCTV_450E) },
189 {} /* Terminating entry */ 198 { USB_DEVICE(USB_VID_TECHNOTREND,
199 USB_PID_TECHNOTREND_CONNECT_S2400) },
200 {} /* Terminating entry */
190}; 201};
191MODULE_DEVICE_TABLE (usb, ttusb2_table); 202MODULE_DEVICE_TABLE (usb, ttusb2_table);
192 203
@@ -242,6 +253,54 @@ static struct dvb_usb_device_properties ttusb2_properties = {
242 } 253 }
243}; 254};
244 255
256static struct dvb_usb_device_properties ttusb2_properties_s2400 = {
257 .caps = DVB_USB_IS_AN_I2C_ADAPTER,
258
259 .usb_ctrl = CYPRESS_FX2,
260 .firmware = "dvb-usb-tt-s2400-01.fw",
261
262 .size_of_priv = sizeof(struct ttusb2_state),
263
264 .num_adapters = 1,
265 .adapter = {
266 {
267 .streaming_ctrl = NULL,
268
269 .frontend_attach = ttusb2_frontend_attach,
270 .tuner_attach = ttusb2_tuner_attach,
271
272 /* parameter for the MPEG2-data transfer */
273 .stream = {
274 .type = USB_ISOC,
275 .count = 5,
276 .endpoint = 0x02,
277 .u = {
278 .isoc = {
279 .framesperurb = 4,
280 .framesize = 940,
281 .interval = 1,
282 }
283 }
284 }
285 }
286 },
287
288 .power_ctrl = ttusb2_power_ctrl,
289 .identify_state = ttusb2_identify_state,
290
291 .i2c_algo = &ttusb2_i2c_algo,
292
293 .generic_bulk_ctrl_endpoint = 0x01,
294
295 .num_device_descs = 1,
296 .devices = {
297 { "Technotrend TT-connect S-2400",
298 { &ttusb2_table[2], NULL },
299 { NULL },
300 },
301 }
302};
303
245static struct usb_driver ttusb2_driver = { 304static struct usb_driver ttusb2_driver = {
246 .name = "dvb_usb_ttusb2", 305 .name = "dvb_usb_ttusb2",
247 .probe = ttusb2_probe, 306 .probe = ttusb2_probe,
diff --git a/drivers/media/dvb/dvb-usb/umt-010.c b/drivers/media/dvb/dvb-usb/umt-010.c
index 0dcab3d4e236..9e7653bb3b66 100644
--- a/drivers/media/dvb/dvb-usb/umt-010.c
+++ b/drivers/media/dvb/dvb-usb/umt-010.c
@@ -13,6 +13,8 @@
13 13
14#include "mt352.h" 14#include "mt352.h"
15 15
16DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
17
16static int umt_mt352_demod_init(struct dvb_frontend *fe) 18static int umt_mt352_demod_init(struct dvb_frontend *fe)
17{ 19{
18 static u8 mt352_clock_config[] = { 0x89, 0xb8, 0x2d }; 20 static u8 mt352_clock_config[] = { 0x89, 0xb8, 0x2d };
@@ -75,7 +77,8 @@ static struct dvb_usb_device_properties umt_properties;
75static int umt_probe(struct usb_interface *intf, 77static int umt_probe(struct usb_interface *intf,
76 const struct usb_device_id *id) 78 const struct usb_device_id *id)
77{ 79{
78 if (dvb_usb_device_init(intf,&umt_properties,THIS_MODULE,NULL) == 0) 80 if (0 == dvb_usb_device_init(intf, &umt_properties,
81 THIS_MODULE, NULL, adapter_nr))
79 return 0; 82 return 0;
80 return -EINVAL; 83 return -EINVAL;
81} 84}
diff --git a/drivers/media/dvb/dvb-usb/vp702x-fe.c b/drivers/media/dvb/dvb-usb/vp702x-fe.c
index c3fdc7cd094e..ccc7e4452664 100644
--- a/drivers/media/dvb/dvb-usb/vp702x-fe.c
+++ b/drivers/media/dvb/dvb-usb/vp702x-fe.c
@@ -67,7 +67,7 @@ static int vp702x_fe_read_status(struct dvb_frontend* fe, fe_status_t *status)
67{ 67{
68 struct vp702x_fe_state *st = fe->demodulator_priv; 68 struct vp702x_fe_state *st = fe->demodulator_priv;
69 vp702x_fe_refresh_state(st); 69 vp702x_fe_refresh_state(st);
70 deb_fe("%s\n",__FUNCTION__); 70 deb_fe("%s\n",__func__);
71 71
72 if (st->lock == 0) 72 if (st->lock == 0)
73 *status = FE_HAS_LOCK | FE_HAS_SYNC | FE_HAS_VITERBI | FE_HAS_SIGNAL | FE_HAS_CARRIER; 73 *status = FE_HAS_LOCK | FE_HAS_SYNC | FE_HAS_VITERBI | FE_HAS_SIGNAL | FE_HAS_CARRIER;
@@ -121,7 +121,7 @@ static int vp702x_fe_read_snr(struct dvb_frontend* fe, u16 *snr)
121 121
122static int vp702x_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune) 122static int vp702x_fe_get_tune_settings(struct dvb_frontend* fe, struct dvb_frontend_tune_settings *tune)
123{ 123{
124 deb_fe("%s\n",__FUNCTION__); 124 deb_fe("%s\n",__func__);
125 tune->min_delay_ms = 2000; 125 tune->min_delay_ms = 2000;
126 return 0; 126 return 0;
127} 127}
@@ -183,21 +183,21 @@ static int vp702x_fe_set_frontend(struct dvb_frontend* fe,
183static int vp702x_fe_init(struct dvb_frontend *fe) 183static int vp702x_fe_init(struct dvb_frontend *fe)
184{ 184{
185 struct vp702x_fe_state *st = fe->demodulator_priv; 185 struct vp702x_fe_state *st = fe->demodulator_priv;
186 deb_fe("%s\n",__FUNCTION__); 186 deb_fe("%s\n",__func__);
187 vp702x_usb_in_op(st->d, RESET_TUNER, 0, 0, NULL, 0); 187 vp702x_usb_in_op(st->d, RESET_TUNER, 0, 0, NULL, 0);
188 return 0; 188 return 0;
189} 189}
190 190
191static int vp702x_fe_sleep(struct dvb_frontend *fe) 191static int vp702x_fe_sleep(struct dvb_frontend *fe)
192{ 192{
193 deb_fe("%s\n",__FUNCTION__); 193 deb_fe("%s\n",__func__);
194 return 0; 194 return 0;
195} 195}
196 196
197static int vp702x_fe_get_frontend(struct dvb_frontend* fe, 197static int vp702x_fe_get_frontend(struct dvb_frontend* fe,
198 struct dvb_frontend_parameters *fep) 198 struct dvb_frontend_parameters *fep)
199{ 199{
200 deb_fe("%s\n",__FUNCTION__); 200 deb_fe("%s\n",__func__);
201 return 0; 201 return 0;
202} 202}
203 203
@@ -208,7 +208,7 @@ static int vp702x_fe_send_diseqc_msg (struct dvb_frontend* fe,
208 u8 cmd[8],ibuf[10]; 208 u8 cmd[8],ibuf[10];
209 memset(cmd,0,8); 209 memset(cmd,0,8);
210 210
211 deb_fe("%s\n",__FUNCTION__); 211 deb_fe("%s\n",__func__);
212 212
213 if (m->msg_len > 4) 213 if (m->msg_len > 4)
214 return -EINVAL; 214 return -EINVAL;
@@ -230,7 +230,7 @@ static int vp702x_fe_send_diseqc_msg (struct dvb_frontend* fe,
230 230
231static int vp702x_fe_send_diseqc_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t burst) 231static int vp702x_fe_send_diseqc_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t burst)
232{ 232{
233 deb_fe("%s\n",__FUNCTION__); 233 deb_fe("%s\n",__func__);
234 return 0; 234 return 0;
235} 235}
236 236
@@ -238,7 +238,7 @@ static int vp702x_fe_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
238{ 238{
239 struct vp702x_fe_state *st = fe->demodulator_priv; 239 struct vp702x_fe_state *st = fe->demodulator_priv;
240 u8 ibuf[10]; 240 u8 ibuf[10];
241 deb_fe("%s\n",__FUNCTION__); 241 deb_fe("%s\n",__func__);
242 242
243 st->tone_mode = tone; 243 st->tone_mode = tone;
244 244
@@ -263,7 +263,7 @@ static int vp702x_fe_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t
263{ 263{
264 struct vp702x_fe_state *st = fe->demodulator_priv; 264 struct vp702x_fe_state *st = fe->demodulator_priv;
265 u8 ibuf[10]; 265 u8 ibuf[10];
266 deb_fe("%s\n",__FUNCTION__); 266 deb_fe("%s\n",__func__);
267 267
268 st->voltage = voltage; 268 st->voltage = voltage;
269 269
diff --git a/drivers/media/dvb/dvb-usb/vp702x.c b/drivers/media/dvb/dvb-usb/vp702x.c
index e553c139ac44..986fff9a5ba8 100644
--- a/drivers/media/dvb/dvb-usb/vp702x.c
+++ b/drivers/media/dvb/dvb-usb/vp702x.c
@@ -21,6 +21,8 @@ int dvb_usb_vp702x_debug;
21module_param_named(debug,dvb_usb_vp702x_debug, int, 0644); 21module_param_named(debug,dvb_usb_vp702x_debug, int, 0644);
22MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DVB_USB_DEBUG_STATUS); 22MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DVB_USB_DEBUG_STATUS);
23 23
24DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
25
24struct vp702x_state { 26struct vp702x_state {
25 int pid_filter_count; 27 int pid_filter_count;
26 int pid_filter_can_bypass; 28 int pid_filter_can_bypass;
@@ -238,7 +240,8 @@ static struct dvb_usb_device_properties vp702x_properties;
238static int vp702x_usb_probe(struct usb_interface *intf, 240static int vp702x_usb_probe(struct usb_interface *intf,
239 const struct usb_device_id *id) 241 const struct usb_device_id *id)
240{ 242{
241 return dvb_usb_device_init(intf,&vp702x_properties,THIS_MODULE,NULL); 243 return dvb_usb_device_init(intf, &vp702x_properties,
244 THIS_MODULE, NULL, adapter_nr);
242} 245}
243 246
244static struct usb_device_id vp702x_usb_table [] = { 247static struct usb_device_id vp702x_usb_table [] = {
diff --git a/drivers/media/dvb/dvb-usb/vp7045.c b/drivers/media/dvb/dvb-usb/vp7045.c
index c172babf59bb..acb345504e0d 100644
--- a/drivers/media/dvb/dvb-usb/vp7045.c
+++ b/drivers/media/dvb/dvb-usb/vp7045.c
@@ -18,6 +18,9 @@
18static int dvb_usb_vp7045_debug; 18static int dvb_usb_vp7045_debug;
19module_param_named(debug,dvb_usb_vp7045_debug, int, 0644); 19module_param_named(debug,dvb_usb_vp7045_debug, int, 0644);
20MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DVB_USB_DEBUG_STATUS); 20MODULE_PARM_DESC(debug, "set debugging level (1=info,xfer=2,rc=4 (or-able))." DVB_USB_DEBUG_STATUS);
21
22DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
23
21#define deb_info(args...) dprintk(dvb_usb_vp7045_debug,0x01,args) 24#define deb_info(args...) dprintk(dvb_usb_vp7045_debug,0x01,args)
22#define deb_xfer(args...) dprintk(dvb_usb_vp7045_debug,0x02,args) 25#define deb_xfer(args...) dprintk(dvb_usb_vp7045_debug,0x02,args)
23#define deb_rc(args...) dprintk(dvb_usb_vp7045_debug,0x04,args) 26#define deb_rc(args...) dprintk(dvb_usb_vp7045_debug,0x04,args)
@@ -219,7 +222,8 @@ static struct dvb_usb_device_properties vp7045_properties;
219static int vp7045_usb_probe(struct usb_interface *intf, 222static int vp7045_usb_probe(struct usb_interface *intf,
220 const struct usb_device_id *id) 223 const struct usb_device_id *id)
221{ 224{
222 return dvb_usb_device_init(intf,&vp7045_properties,THIS_MODULE,NULL); 225 return dvb_usb_device_init(intf, &vp7045_properties,
226 THIS_MODULE, NULL, adapter_nr);
223} 227}
224 228
225static struct usb_device_id vp7045_usb_table [] = { 229static struct usb_device_id vp7045_usb_table [] = {
diff --git a/drivers/media/dvb/frontends/Kconfig b/drivers/media/dvb/frontends/Kconfig
index 9ad86ce4a4e5..68fab616f55d 100644
--- a/drivers/media/dvb/frontends/Kconfig
+++ b/drivers/media/dvb/frontends/Kconfig
@@ -188,6 +188,14 @@ config DVB_DIB7000P
188 A DVB-T tuner module. Designed for mobile usage. Say Y when you want 188 A DVB-T tuner module. Designed for mobile usage. Say Y when you want
189 to support this frontend. 189 to support this frontend.
190 190
191config DVB_TDA10048
192 tristate "Philips TDA10048HN based"
193 depends on DVB_CORE && I2C
194 default m if DVB_FE_CUSTOMISE
195 select FW_LOADER
196 help
197 A DVB-T tuner module. Say Y when you want to support this frontend.
198
191comment "DVB-C (cable) frontends" 199comment "DVB-C (cable) frontends"
192 depends on DVB_CORE 200 depends on DVB_CORE
193 201
@@ -291,6 +299,14 @@ config DVB_S5H1409
291 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want 299 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want
292 to support this frontend. 300 to support this frontend.
293 301
302config DVB_AU8522
303 tristate "Auvitek AU8522 based"
304 depends on DVB_CORE && I2C
305 default m if DVB_FE_CUSTOMISE
306 help
307 An ATSC 8VSB and QAM64/256 tuner module. Say Y when you want
308 to support this frontend.
309
294comment "Tuners/PLL support" 310comment "Tuners/PLL support"
295 depends on DVB_CORE 311 depends on DVB_CORE
296 312
@@ -369,6 +385,11 @@ config DVB_TUNER_XC5000
369 This device is only used inside a SiP called togther with a 385 This device is only used inside a SiP called togther with a
370 demodulator for now. 386 demodulator for now.
371 387
388config DVB_TUNER_ITD1000
389 tristate "Integrant ITD1000 Zero IF tuner for DVB-S/DSS"
390 depends on DVB_CORE && I2C
391 default m if DVB_FE_CUSTOMISE
392
372comment "Miscellaneous devices" 393comment "Miscellaneous devices"
373 depends on DVB_CORE 394 depends on DVB_CORE
374 395
@@ -379,6 +400,13 @@ config DVB_LNBP21
379 help 400 help
380 An SEC control chip. 401 An SEC control chip.
381 402
403config DVB_ISL6405
404 tristate "ISL6405 SEC controller"
405 depends on DVB_CORE && I2C
406 default m if DVB_FE_CUSTOMISE
407 help
408 An SEC control chip.
409
382config DVB_ISL6421 410config DVB_ISL6421
383 tristate "ISL6421 SEC controller" 411 tristate "ISL6421 SEC controller"
384 depends on DVB_CORE && I2C 412 depends on DVB_CORE && I2C
diff --git a/drivers/media/dvb/frontends/Makefile b/drivers/media/dvb/frontends/Makefile
index 16bd107ebd32..2f873fc0f649 100644
--- a/drivers/media/dvb/frontends/Makefile
+++ b/drivers/media/dvb/frontends/Makefile
@@ -38,6 +38,7 @@ obj-$(CONFIG_DVB_S5H1420) += s5h1420.o
38obj-$(CONFIG_DVB_LGDT330X) += lgdt330x.o 38obj-$(CONFIG_DVB_LGDT330X) += lgdt330x.o
39obj-$(CONFIG_DVB_CX24123) += cx24123.o 39obj-$(CONFIG_DVB_CX24123) += cx24123.o
40obj-$(CONFIG_DVB_LNBP21) += lnbp21.o 40obj-$(CONFIG_DVB_LNBP21) += lnbp21.o
41obj-$(CONFIG_DVB_ISL6405) += isl6405.o
41obj-$(CONFIG_DVB_ISL6421) += isl6421.o 42obj-$(CONFIG_DVB_ISL6421) += isl6421.o
42obj-$(CONFIG_DVB_TDA10086) += tda10086.o 43obj-$(CONFIG_DVB_TDA10086) += tda10086.o
43obj-$(CONFIG_DVB_TDA826X) += tda826x.o 44obj-$(CONFIG_DVB_TDA826X) += tda826x.o
@@ -51,3 +52,6 @@ obj-$(CONFIG_DVB_TUA6100) += tua6100.o
51obj-$(CONFIG_DVB_TUNER_MT2131) += mt2131.o 52obj-$(CONFIG_DVB_TUNER_MT2131) += mt2131.o
52obj-$(CONFIG_DVB_S5H1409) += s5h1409.o 53obj-$(CONFIG_DVB_S5H1409) += s5h1409.o
53obj-$(CONFIG_DVB_TUNER_XC5000) += xc5000.o 54obj-$(CONFIG_DVB_TUNER_XC5000) += xc5000.o
55obj-$(CONFIG_DVB_TUNER_ITD1000) += itd1000.o
56obj-$(CONFIG_DVB_AU8522) += au8522.o
57obj-$(CONFIG_DVB_TDA10048) += tda10048.o
diff --git a/drivers/media/dvb/frontends/au8522.c b/drivers/media/dvb/frontends/au8522.c
new file mode 100644
index 000000000000..084a280c2d7f
--- /dev/null
+++ b/drivers/media/dvb/frontends/au8522.c
@@ -0,0 +1,692 @@
1/*
2 Auvitek AU8522 QAM/8VSB demodulator driver
3
4 Copyright (C) 2008 Steven Toth <stoth@hauppauge.com>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20*/
21
22#include <linux/kernel.h>
23#include <linux/init.h>
24#include <linux/module.h>
25#include <linux/string.h>
26#include <linux/slab.h>
27#include <linux/delay.h>
28#include "dvb_frontend.h"
29#include "dvb-pll.h"
30#include "au8522.h"
31
32struct au8522_state {
33
34 struct i2c_adapter *i2c;
35
36 /* configuration settings */
37 const struct au8522_config *config;
38
39 struct dvb_frontend frontend;
40
41 u32 current_frequency;
42 fe_modulation_t current_modulation;
43
44};
45
46static int debug;
47
48#define dprintk(arg...) do { \
49 if (debug) \
50 printk(arg); \
51 } while (0)
52
53/* 16 bit registers, 8 bit values */
54static int au8522_writereg(struct au8522_state *state, u16 reg, u8 data)
55{
56 int ret;
57 u8 buf [] = { reg >> 8, reg & 0xff, data };
58
59 struct i2c_msg msg = { .addr = state->config->demod_address,
60 .flags = 0, .buf = buf, .len = 3 };
61
62 ret = i2c_transfer(state->i2c, &msg, 1);
63
64 if (ret != 1)
65 printk("%s: writereg error (reg == 0x%02x, val == 0x%04x, "
66 "ret == %i)\n", __func__, reg, data, ret);
67
68 return (ret != 1) ? -1 : 0;
69}
70
71static u8 au8522_readreg(struct au8522_state *state, u16 reg)
72{
73 int ret;
74 u8 b0 [] = { reg >> 8, reg & 0xff };
75 u8 b1 [] = { 0 };
76
77 struct i2c_msg msg [] = {
78 { .addr = state->config->demod_address, .flags = 0,
79 .buf = b0, .len = 2 },
80 { .addr = state->config->demod_address, .flags = I2C_M_RD,
81 .buf = b1, .len = 1 } };
82
83 ret = i2c_transfer(state->i2c, msg, 2);
84
85 if (ret != 2)
86 printk(KERN_ERR "%s: readreg error (ret == %i)\n",
87 __func__, ret);
88 return b1[0];
89}
90
91static int au8522_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
92{
93 struct au8522_state *state = fe->demodulator_priv;
94
95 dprintk("%s(%d)\n", __func__, enable);
96
97 if (enable)
98 return au8522_writereg(state, 0x106, 1);
99 else
100 return au8522_writereg(state, 0x106, 0);
101}
102
103struct mse2snr_tab {
104 u16 val;
105 u16 data;
106};
107
108/* VSB SNR lookup table */
109static struct mse2snr_tab vsb_mse2snr_tab[] = {
110 { 0, 270 },
111 { 2, 250 },
112 { 3, 240 },
113 { 5, 230 },
114 { 7, 220 },
115 { 9, 210 },
116 { 12, 200 },
117 { 13, 195 },
118 { 15, 190 },
119 { 17, 185 },
120 { 19, 180 },
121 { 21, 175 },
122 { 24, 170 },
123 { 27, 165 },
124 { 31, 160 },
125 { 32, 158 },
126 { 33, 156 },
127 { 36, 152 },
128 { 37, 150 },
129 { 39, 148 },
130 { 40, 146 },
131 { 41, 144 },
132 { 43, 142 },
133 { 44, 140 },
134 { 48, 135 },
135 { 50, 130 },
136 { 43, 142 },
137 { 53, 125 },
138 { 56, 120 },
139 { 256, 115 },
140};
141
142/* QAM64 SNR lookup table */
143static struct mse2snr_tab qam64_mse2snr_tab[] = {
144 { 15, 0 },
145 { 16, 290 },
146 { 17, 288 },
147 { 18, 286 },
148 { 19, 284 },
149 { 20, 282 },
150 { 21, 281 },
151 { 22, 279 },
152 { 23, 277 },
153 { 24, 275 },
154 { 25, 273 },
155 { 26, 271 },
156 { 27, 269 },
157 { 28, 268 },
158 { 29, 266 },
159 { 30, 264 },
160 { 31, 262 },
161 { 32, 260 },
162 { 33, 259 },
163 { 34, 258 },
164 { 35, 256 },
165 { 36, 255 },
166 { 37, 254 },
167 { 38, 252 },
168 { 39, 251 },
169 { 40, 250 },
170 { 41, 249 },
171 { 42, 248 },
172 { 43, 246 },
173 { 44, 245 },
174 { 45, 244 },
175 { 46, 242 },
176 { 47, 241 },
177 { 48, 240 },
178 { 50, 239 },
179 { 51, 238 },
180 { 53, 237 },
181 { 54, 236 },
182 { 56, 235 },
183 { 57, 234 },
184 { 59, 233 },
185 { 60, 232 },
186 { 62, 231 },
187 { 63, 230 },
188 { 65, 229 },
189 { 67, 228 },
190 { 68, 227 },
191 { 70, 226 },
192 { 71, 225 },
193 { 73, 224 },
194 { 74, 223 },
195 { 76, 222 },
196 { 78, 221 },
197 { 80, 220 },
198 { 82, 219 },
199 { 85, 218 },
200 { 88, 217 },
201 { 90, 216 },
202 { 92, 215 },
203 { 93, 214 },
204 { 94, 212 },
205 { 95, 211 },
206 { 97, 210 },
207 { 99, 209 },
208 { 101, 208 },
209 { 102, 207 },
210 { 104, 206 },
211 { 107, 205 },
212 { 111, 204 },
213 { 114, 203 },
214 { 118, 202 },
215 { 122, 201 },
216 { 125, 200 },
217 { 128, 199 },
218 { 130, 198 },
219 { 132, 197 },
220 { 256, 190 },
221};
222
223/* QAM256 SNR lookup table */
224static struct mse2snr_tab qam256_mse2snr_tab[] = {
225 { 16, 0 },
226 { 17, 400 },
227 { 18, 398 },
228 { 19, 396 },
229 { 20, 394 },
230 { 21, 392 },
231 { 22, 390 },
232 { 23, 388 },
233 { 24, 386 },
234 { 25, 384 },
235 { 26, 382 },
236 { 27, 380 },
237 { 28, 379 },
238 { 29, 378 },
239 { 30, 377 },
240 { 31, 376 },
241 { 32, 375 },
242 { 33, 374 },
243 { 34, 373 },
244 { 35, 372 },
245 { 36, 371 },
246 { 37, 370 },
247 { 38, 362 },
248 { 39, 354 },
249 { 40, 346 },
250 { 41, 338 },
251 { 42, 330 },
252 { 43, 328 },
253 { 44, 326 },
254 { 45, 324 },
255 { 46, 322 },
256 { 47, 320 },
257 { 48, 319 },
258 { 49, 318 },
259 { 50, 317 },
260 { 51, 316 },
261 { 52, 315 },
262 { 53, 314 },
263 { 54, 313 },
264 { 55, 312 },
265 { 56, 311 },
266 { 57, 310 },
267 { 58, 308 },
268 { 59, 306 },
269 { 60, 304 },
270 { 61, 302 },
271 { 62, 300 },
272 { 63, 298 },
273 { 65, 295 },
274 { 68, 294 },
275 { 70, 293 },
276 { 73, 292 },
277 { 76, 291 },
278 { 78, 290 },
279 { 79, 289 },
280 { 81, 288 },
281 { 82, 287 },
282 { 83, 286 },
283 { 84, 285 },
284 { 85, 284 },
285 { 86, 283 },
286 { 88, 282 },
287 { 89, 281 },
288 { 256, 280 },
289};
290
291static int au8522_mse2snr_lookup(struct mse2snr_tab *tab, int sz, int mse,
292 u16 *snr)
293{
294 int i, ret = -EINVAL;
295 dprintk("%s()\n", __func__);
296
297 for (i = 0; i < sz; i++) {
298 if (mse < tab[i].val) {
299 *snr = tab[i].data;
300 ret = 0;
301 break;
302 }
303 }
304 dprintk("%s() snr=%d\n", __func__, *snr);
305 return ret;
306}
307
308/* VSB Modulation table */
309static struct {
310 u16 reg;
311 u16 data;
312} VSB_mod_tab[] = {
313 { 0x8090, 0x84 },
314 { 0x4092, 0x11 },
315 { 0x2005, 0x00 },
316 { 0x8091, 0x80 },
317 { 0x80a3, 0x0c },
318 { 0x80a4, 0xe8 },
319 { 0x8081, 0xc4 },
320 { 0x80a5, 0x40 },
321 { 0x80a7, 0x40 },
322 { 0x80a6, 0x67 },
323 { 0x8262, 0x20 },
324 { 0x821c, 0x30 },
325 { 0x80d8, 0x1a },
326 { 0x8227, 0xa0 },
327 { 0x8121, 0xff },
328 { 0x80a8, 0xf0 },
329 { 0x80a9, 0x05 },
330 { 0x80aa, 0x77 },
331 { 0x80ab, 0xf0 },
332 { 0x80ac, 0x05 },
333 { 0x80ad, 0x77 },
334 { 0x80ae, 0x41 },
335 { 0x80af, 0x66 },
336 { 0x821b, 0xcc },
337 { 0x821d, 0x80 },
338 { 0x80b5, 0xfb },
339 { 0x80b6, 0x8e },
340 { 0x80b7, 0x39 },
341 { 0x80a4, 0xe8 },
342 { 0x8231, 0x13 },
343};
344
345/* QAM Modulation table */
346static struct {
347 u16 reg;
348 u16 data;
349} QAM_mod_tab[] = {
350 { 0x80a3, 0x09 },
351 { 0x80a4, 0x00 },
352 { 0x8081, 0xc4 },
353 { 0x80a5, 0x40 },
354 { 0x80b5, 0xfb },
355 { 0x80b6, 0x8e },
356 { 0x80b7, 0x39 },
357 { 0x80aa, 0x77 },
358 { 0x80ad, 0x77 },
359 { 0x80a6, 0x67 },
360 { 0x8262, 0x20 },
361 { 0x821c, 0x30 },
362 { 0x80b8, 0x3e },
363 { 0x80b9, 0xf0 },
364 { 0x80ba, 0x01 },
365 { 0x80bb, 0x18 },
366 { 0x80bc, 0x50 },
367 { 0x80bd, 0x00 },
368 { 0x80be, 0xea },
369 { 0x80bf, 0xef },
370 { 0x80c0, 0xfc },
371 { 0x80c1, 0xbd },
372 { 0x80c2, 0x1f },
373 { 0x80c3, 0xfc },
374 { 0x80c4, 0xdd },
375 { 0x80c5, 0xaf },
376 { 0x80c6, 0x00 },
377 { 0x80c7, 0x38 },
378 { 0x80c8, 0x30 },
379 { 0x80c9, 0x05 },
380 { 0x80ca, 0x4a },
381 { 0x80cb, 0xd0 },
382 { 0x80cc, 0x01 },
383 { 0x80cd, 0xd9 },
384 { 0x80ce, 0x6f },
385 { 0x80cf, 0xf9 },
386 { 0x80d0, 0x70 },
387 { 0x80d1, 0xdf },
388 { 0x80d2, 0xf7 },
389 { 0x80d3, 0xc2 },
390 { 0x80d4, 0xdf },
391 { 0x80d5, 0x02 },
392 { 0x80d6, 0x9a },
393 { 0x80d7, 0xd0 },
394 { 0x8250, 0x0d },
395 { 0x8251, 0xcd },
396 { 0x8252, 0xe0 },
397 { 0x8253, 0x05 },
398 { 0x8254, 0xa7 },
399 { 0x8255, 0xff },
400 { 0x8256, 0xed },
401 { 0x8257, 0x5b },
402 { 0x8258, 0xae },
403 { 0x8259, 0xe6 },
404 { 0x825a, 0x3d },
405 { 0x825b, 0x0f },
406 { 0x825c, 0x0d },
407 { 0x825d, 0xea },
408 { 0x825e, 0xf2 },
409 { 0x825f, 0x51 },
410 { 0x8260, 0xf5 },
411 { 0x8261, 0x06 },
412 { 0x821a, 0x00 },
413 { 0x8546, 0x40 },
414 { 0x8210, 0x26 },
415 { 0x8211, 0xf6 },
416 { 0x8212, 0x84 },
417 { 0x8213, 0x02 },
418 { 0x8502, 0x01 },
419 { 0x8121, 0x04 },
420 { 0x8122, 0x04 },
421 { 0x852e, 0x10 },
422 { 0x80a4, 0xca },
423 { 0x80a7, 0x40 },
424 { 0x8526, 0x01 },
425};
426
427static int au8522_enable_modulation(struct dvb_frontend *fe,
428 fe_modulation_t m)
429{
430 struct au8522_state *state = fe->demodulator_priv;
431 int i;
432
433 dprintk("%s(0x%08x)\n", __func__, m);
434
435 switch (m) {
436 case VSB_8:
437 dprintk("%s() VSB_8\n", __func__);
438 for (i = 0; i < ARRAY_SIZE(VSB_mod_tab); i++)
439 au8522_writereg(state,
440 VSB_mod_tab[i].reg,
441 VSB_mod_tab[i].data);
442 break;
443 case QAM_64:
444 case QAM_256:
445 dprintk("%s() QAM 64/256\n", __func__);
446 for (i = 0; i < ARRAY_SIZE(QAM_mod_tab); i++)
447 au8522_writereg(state,
448 QAM_mod_tab[i].reg,
449 QAM_mod_tab[i].data);
450 break;
451 default:
452 dprintk("%s() Invalid modulation\n", __func__);
453 return -EINVAL;
454 }
455
456 state->current_modulation = m;
457
458 return 0;
459}
460
461/* Talk to the demod, set the FEC, GUARD, QAM settings etc */
462static int au8522_set_frontend(struct dvb_frontend *fe,
463 struct dvb_frontend_parameters *p)
464{
465 struct au8522_state *state = fe->demodulator_priv;
466
467 dprintk("%s(frequency=%d)\n", __func__, p->frequency);
468
469 state->current_frequency = p->frequency;
470
471 au8522_enable_modulation(fe, p->u.vsb.modulation);
472
473 /* Allow the demod to settle */
474 msleep(100);
475
476 if (fe->ops.tuner_ops.set_params) {
477 if (fe->ops.i2c_gate_ctrl)
478 fe->ops.i2c_gate_ctrl(fe, 1);
479 fe->ops.tuner_ops.set_params(fe, p);
480 if (fe->ops.i2c_gate_ctrl)
481 fe->ops.i2c_gate_ctrl(fe, 0);
482 }
483
484 return 0;
485}
486
487/* Reset the demod hardware and reset all of the configuration registers
488 to a default state. */
489static int au8522_init(struct dvb_frontend *fe)
490{
491 struct au8522_state *state = fe->demodulator_priv;
492 dprintk("%s()\n", __func__);
493
494 au8522_writereg(state, 0xa4, 1 << 5);
495
496 au8522_i2c_gate_ctrl(fe, 1);
497
498 return 0;
499}
500
501static int au8522_read_status(struct dvb_frontend *fe, fe_status_t *status)
502{
503 struct au8522_state *state = fe->demodulator_priv;
504 u8 reg;
505 u32 tuner_status = 0;
506
507 *status = 0;
508
509 if (state->current_modulation == VSB_8) {
510 dprintk("%s() Checking VSB_8\n", __func__);
511 reg = au8522_readreg(state, 0x4088);
512 if (reg & 0x01)
513 *status |= FE_HAS_VITERBI;
514 if (reg & 0x02)
515 *status |= FE_HAS_LOCK | FE_HAS_SYNC;
516 } else {
517 dprintk("%s() Checking QAM\n", __func__);
518 reg = au8522_readreg(state, 0x4541);
519 if (reg & 0x80)
520 *status |= FE_HAS_VITERBI;
521 if (reg & 0x20)
522 *status |= FE_HAS_LOCK | FE_HAS_SYNC;
523 }
524
525 switch (state->config->status_mode) {
526 case AU8522_DEMODLOCKING:
527 dprintk("%s() DEMODLOCKING\n", __func__);
528 if (*status & FE_HAS_VITERBI)
529 *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL;
530 break;
531 case AU8522_TUNERLOCKING:
532 /* Get the tuner status */
533 dprintk("%s() TUNERLOCKING\n", __func__);
534 if (fe->ops.tuner_ops.get_status) {
535 if (fe->ops.i2c_gate_ctrl)
536 fe->ops.i2c_gate_ctrl(fe, 1);
537
538 fe->ops.tuner_ops.get_status(fe, &tuner_status);
539
540 if (fe->ops.i2c_gate_ctrl)
541 fe->ops.i2c_gate_ctrl(fe, 0);
542 }
543 if (tuner_status)
544 *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL;
545 break;
546 }
547
548 dprintk("%s() status 0x%08x\n", __func__, *status);
549
550 return 0;
551}
552
553static int au8522_read_snr(struct dvb_frontend *fe, u16 *snr)
554{
555 struct au8522_state *state = fe->demodulator_priv;
556 int ret = -EINVAL;
557
558 dprintk("%s()\n", __func__);
559
560 if (state->current_modulation == QAM_256)
561 ret = au8522_mse2snr_lookup(qam256_mse2snr_tab,
562 ARRAY_SIZE(qam256_mse2snr_tab),
563 au8522_readreg(state, 0x4522),
564 snr);
565 else if (state->current_modulation == QAM_64)
566 ret = au8522_mse2snr_lookup(qam64_mse2snr_tab,
567 ARRAY_SIZE(qam64_mse2snr_tab),
568 au8522_readreg(state, 0x4522),
569 snr);
570 else /* VSB_8 */
571 ret = au8522_mse2snr_lookup(vsb_mse2snr_tab,
572 ARRAY_SIZE(vsb_mse2snr_tab),
573 au8522_readreg(state, 0x4311),
574 snr);
575
576 return ret;
577}
578
579static int au8522_read_signal_strength(struct dvb_frontend *fe,
580 u16 *signal_strength)
581{
582 return au8522_read_snr(fe, signal_strength);
583}
584
585static int au8522_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
586{
587 struct au8522_state *state = fe->demodulator_priv;
588
589 if (state->current_modulation == VSB_8)
590 *ucblocks = au8522_readreg(state, 0x4087);
591 else
592 *ucblocks = au8522_readreg(state, 0x4543);
593
594 return 0;
595}
596
597static int au8522_read_ber(struct dvb_frontend *fe, u32 *ber)
598{
599 return au8522_read_ucblocks(fe, ber);
600}
601
602static int au8522_get_frontend(struct dvb_frontend *fe,
603 struct dvb_frontend_parameters *p)
604{
605 struct au8522_state *state = fe->demodulator_priv;
606
607 p->frequency = state->current_frequency;
608 p->u.vsb.modulation = state->current_modulation;
609
610 return 0;
611}
612
613static int au8522_get_tune_settings(struct dvb_frontend *fe,
614 struct dvb_frontend_tune_settings *tune)
615{
616 tune->min_delay_ms = 1000;
617 return 0;
618}
619
620static void au8522_release(struct dvb_frontend *fe)
621{
622 struct au8522_state *state = fe->demodulator_priv;
623 kfree(state);
624}
625
626static struct dvb_frontend_ops au8522_ops;
627
628struct dvb_frontend *au8522_attach(const struct au8522_config *config,
629 struct i2c_adapter *i2c)
630{
631 struct au8522_state *state = NULL;
632
633 /* allocate memory for the internal state */
634 state = kmalloc(sizeof(struct au8522_state), GFP_KERNEL);
635 if (state == NULL)
636 goto error;
637
638 /* setup the state */
639 state->config = config;
640 state->i2c = i2c;
641 /* create dvb_frontend */
642 memcpy(&state->frontend.ops, &au8522_ops,
643 sizeof(struct dvb_frontend_ops));
644 state->frontend.demodulator_priv = state;
645
646 if (au8522_init(&state->frontend) != 0) {
647 printk(KERN_ERR "%s: Failed to initialize correctly\n",
648 __func__);
649 goto error;
650 }
651
652 /* Note: Leaving the I2C gate open here. */
653 au8522_i2c_gate_ctrl(&state->frontend, 1);
654
655 return &state->frontend;
656
657error:
658 kfree(state);
659 return NULL;
660}
661EXPORT_SYMBOL(au8522_attach);
662
663static struct dvb_frontend_ops au8522_ops = {
664
665 .info = {
666 .name = "Auvitek AU8522 QAM/8VSB Frontend",
667 .type = FE_ATSC,
668 .frequency_min = 54000000,
669 .frequency_max = 858000000,
670 .frequency_stepsize = 62500,
671 .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB
672 },
673
674 .init = au8522_init,
675 .i2c_gate_ctrl = au8522_i2c_gate_ctrl,
676 .set_frontend = au8522_set_frontend,
677 .get_frontend = au8522_get_frontend,
678 .get_tune_settings = au8522_get_tune_settings,
679 .read_status = au8522_read_status,
680 .read_ber = au8522_read_ber,
681 .read_signal_strength = au8522_read_signal_strength,
682 .read_snr = au8522_read_snr,
683 .read_ucblocks = au8522_read_ucblocks,
684 .release = au8522_release,
685};
686
687module_param(debug, int, 0644);
688MODULE_PARM_DESC(debug, "Enable verbose debug messages");
689
690MODULE_DESCRIPTION("Auvitek AU8522 QAM-B/ATSC Demodulator driver");
691MODULE_AUTHOR("Steven Toth");
692MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/au8522.h b/drivers/media/dvb/frontends/au8522.h
new file mode 100644
index 000000000000..d7affa3cdb27
--- /dev/null
+++ b/drivers/media/dvb/frontends/au8522.h
@@ -0,0 +1,56 @@
1/*
2 Auvitek AU8522 QAM/8VSB demodulator driver
3
4 Copyright (C) 2008 Steven Toth <stoth@hauppauge.com>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20*/
21
22#ifndef __AU8522_H__
23#define __AU8522_H__
24
25#include <linux/dvb/frontend.h>
26
27struct au8522_config {
28 /* the demodulator's i2c address */
29 u8 demod_address;
30
31 /* Return lock status based on tuner lock, or demod lock */
32#define AU8522_TUNERLOCKING 0
33#define AU8522_DEMODLOCKING 1
34 u8 status_mode;
35};
36
37#if defined(CONFIG_DVB_AU8522) || \
38 (defined(CONFIG_DVB_AU8522_MODULE) && defined(MODULE))
39extern struct dvb_frontend *au8522_attach(const struct au8522_config *config,
40 struct i2c_adapter *i2c);
41#else
42static inline
43struct dvb_frontend *au8522_attach(const struct au8522_config *config,
44 struct i2c_adapter *i2c)
45{
46 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
47 return NULL;
48}
49#endif /* CONFIG_DVB_AU8522 */
50
51#endif /* __AU8522_H__ */
52
53/*
54 * Local variables:
55 * c-basic-offset: 8
56 */
diff --git a/drivers/media/dvb/frontends/bcm3510.c b/drivers/media/dvb/frontends/bcm3510.c
index a913f49c062b..d268e65e777d 100644
--- a/drivers/media/dvb/frontends/bcm3510.c
+++ b/drivers/media/dvb/frontends/bcm3510.c
@@ -91,7 +91,7 @@ static int bcm3510_writebytes (struct bcm3510_state *state, u8 reg, u8 *buf, u8
91 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) { 91 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) {
92 92
93 deb_info("%s: i2c write error (addr %02x, reg %02x, err == %i)\n", 93 deb_info("%s: i2c write error (addr %02x, reg %02x, err == %i)\n",
94 __FUNCTION__, state->config->demod_address, reg, err); 94 __func__, state->config->demod_address, reg, err);
95 return -EREMOTEIO; 95 return -EREMOTEIO;
96 } 96 }
97 97
@@ -110,7 +110,7 @@ static int bcm3510_readbytes (struct bcm3510_state *state, u8 reg, u8 *buf, u8 l
110 110
111 if ((err = i2c_transfer (state->i2c, msg, 2)) != 2) { 111 if ((err = i2c_transfer (state->i2c, msg, 2)) != 2) {
112 deb_info("%s: i2c read error (addr %02x, reg %02x, err == %i)\n", 112 deb_info("%s: i2c read error (addr %02x, reg %02x, err == %i)\n",
113 __FUNCTION__, state->config->demod_address, reg, err); 113 __func__, state->config->demod_address, reg, err);
114 return -EREMOTEIO; 114 return -EREMOTEIO;
115 } 115 }
116 deb_i2c("i2c rd %02x: ",reg); 116 deb_i2c("i2c rd %02x: ",reg);
diff --git a/drivers/media/dvb/frontends/bcm3510.h b/drivers/media/dvb/frontends/bcm3510.h
index 7e4f95e1734b..f4575c0cc446 100644
--- a/drivers/media/dvb/frontends/bcm3510.h
+++ b/drivers/media/dvb/frontends/bcm3510.h
@@ -41,7 +41,7 @@ extern struct dvb_frontend* bcm3510_attach(const struct bcm3510_config* config,
41static inline struct dvb_frontend* bcm3510_attach(const struct bcm3510_config* config, 41static inline struct dvb_frontend* bcm3510_attach(const struct bcm3510_config* config,
42 struct i2c_adapter* i2c) 42 struct i2c_adapter* i2c)
43{ 43{
44 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 44 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
45 return NULL; 45 return NULL;
46} 46}
47#endif // CONFIG_DVB_BCM3510 47#endif // CONFIG_DVB_BCM3510
diff --git a/drivers/media/dvb/frontends/bsbe1.h b/drivers/media/dvb/frontends/bsbe1.h
index d8f65738e5d2..5e431ebd089b 100644
--- a/drivers/media/dvb/frontends/bsbe1.h
+++ b/drivers/media/dvb/frontends/bsbe1.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * bsbe1.h - ALPS BSBE1 tuner support (moved from av7110.c) 2 * bsbe1.h - ALPS BSBE1 tuner support
3 * 3 *
4 * This program is free software; you can redistribute it and/or 4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License 5 * modify it under the terms of the GNU General Public License
@@ -26,44 +26,24 @@
26#define BSBE1_H 26#define BSBE1_H
27 27
28static u8 alps_bsbe1_inittab[] = { 28static u8 alps_bsbe1_inittab[] = {
29 0x01, 0x15, 29 0x01, 0x15, /* XTAL = 4MHz, VCO = 352 MHz */
30 0x02, 0x30, 30 0x02, 0x30, /* MCLK = 88 MHz */
31 0x03, 0x00, 31 0x03, 0x00, /* ACR output 0 */
32 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */ 32 0x04, 0x7d, /* F22FR = 0x7d, F22 = f_VCO / 128 / 0x7d = 22 kHz */
33 0x05, 0x35, /* I2CT = 0, SCLT = 1, SDAT = 1 */ 33 0x05, 0x05, /* I2CT = 0, SCLT = 1, SDAT = 1 */
34 0x06, 0x40, /* DAC not used, set to high impendance mode */ 34 0x06, 0x00, /* DAC output 0 */
35 0x07, 0x00, /* DAC LSB */
36 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */ 35 0x08, 0x40, /* DiSEqC off, LNB power on OP2/LOCK pin on */
37 0x09, 0x00, /* FIFO */ 36 0x09, 0x00, /* FIFO */
38 0x0c, 0x51, /* OP1 ctl = Normal, OP1 val = 1 (LNB Power ON) */ 37 0x0c, 0x51, /* OP1/OP0 normal, val = 1 (LNB power on) */
39 0x0d, 0x82, /* DC offset compensation = ON, beta_agc1 = 2 */ 38 0x0d, 0x82, /* DC offset compensation = on, beta_agc1 = 2 */
40 0x0e, 0x23, /* alpha_tmg = 2, beta_tmg = 3 */ 39 0x0f, 0x92, /* AGC1R */
41 0x10, 0x3f, // AGC2 0x3d 40 0x10, 0x34, /* AGC2O */
42 0x11, 0x84, 41 0x11, 0x84, /* TLSR */
43 0x12, 0xb9, 42 0x12, 0xb9, /* CFD */
44 0x15, 0xc9, // lock detector threshold 43 0x15, 0xc9, /* lock detector threshold */
45 0x16, 0x00, 44 0x28, 0x00, /* out imp: normal, type: parallel, FEC mode: QPSK */
46 0x17, 0x00, 45 0x33, 0xfc, /* RS control */
47 0x18, 0x00, 46 0x34, 0x93, /* count viterbi bit errors per 2E18 bytes */
48 0x19, 0x00,
49 0x1a, 0x00,
50 0x1f, 0x50,
51 0x20, 0x00,
52 0x21, 0x00,
53 0x22, 0x00,
54 0x23, 0x00,
55 0x28, 0x00, // out imp: normal out type: parallel FEC mode:0
56 0x29, 0x1e, // 1/2 threshold
57 0x2a, 0x14, // 2/3 threshold
58 0x2b, 0x0f, // 3/4 threshold
59 0x2c, 0x09, // 5/6 threshold
60 0x2d, 0x05, // 7/8 threshold
61 0x2e, 0x01,
62 0x31, 0x1f, // test all FECs
63 0x32, 0x19, // viterbi and synchro search
64 0x33, 0xfc, // rs control
65 0x34, 0x93, // error control
66 0x0f, 0x92,
67 0xff, 0xff 47 0xff, 0xff
68}; 48};
69 49
@@ -100,11 +80,11 @@ static int alps_bsbe1_tuner_set_params(struct dvb_frontend* fe, struct dvb_front
100 if ((params->frequency < 950000) || (params->frequency > 2150000)) 80 if ((params->frequency < 950000) || (params->frequency > 2150000))
101 return -EINVAL; 81 return -EINVAL;
102 82
103 div = (params->frequency + (125 - 1)) / 125; // round correctly 83 div = params->frequency / 1000;
104 data[0] = (div >> 8) & 0x7f; 84 data[0] = (div >> 8) & 0x7f;
105 data[1] = div & 0xff; 85 data[1] = div & 0xff;
106 data[2] = 0x80 | ((div & 0x18000) >> 10) | 4; 86 data[2] = 0x80 | ((div & 0x18000) >> 10) | 0x1;
107 data[3] = (params->frequency > 1530000) ? 0xE0 : 0xE4; 87 data[3] = 0xe0;
108 88
109 if (fe->ops.i2c_gate_ctrl) 89 if (fe->ops.i2c_gate_ctrl)
110 fe->ops.i2c_gate_ctrl(fe, 1); 90 fe->ops.i2c_gate_ctrl(fe, 1);
diff --git a/drivers/media/dvb/frontends/bsru6.h b/drivers/media/dvb/frontends/bsru6.h
index e231cd84b3a1..45a6dfd8ebb5 100644
--- a/drivers/media/dvb/frontends/bsru6.h
+++ b/drivers/media/dvb/frontends/bsru6.h
@@ -133,7 +133,7 @@ static struct stv0299_config alps_bsru6_config = {
133 .mclk = 88000000UL, 133 .mclk = 88000000UL,
134 .invert = 1, 134 .invert = 1,
135 .skip_reinit = 0, 135 .skip_reinit = 0,
136 .lock_output = STV0229_LOCKOUTPUT_1, 136 .lock_output = STV0299_LOCKOUTPUT_1,
137 .volt13_op0_op1 = STV0299_VOLT13_OP1, 137 .volt13_op0_op1 = STV0299_VOLT13_OP1,
138 .min_delay_ms = 100, 138 .min_delay_ms = 100,
139 .set_symbol_rate = alps_bsru6_set_symbol_rate, 139 .set_symbol_rate = alps_bsru6_set_symbol_rate,
diff --git a/drivers/media/dvb/frontends/cx22700.c b/drivers/media/dvb/frontends/cx22700.c
index 11a4968f18cb..ace5cb17165d 100644
--- a/drivers/media/dvb/frontends/cx22700.c
+++ b/drivers/media/dvb/frontends/cx22700.c
@@ -73,13 +73,13 @@ static int cx22700_writereg (struct cx22700_state* state, u8 reg, u8 data)
73 u8 buf [] = { reg, data }; 73 u8 buf [] = { reg, data };
74 struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = buf, .len = 2 }; 74 struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = buf, .len = 2 };
75 75
76 dprintk ("%s\n", __FUNCTION__); 76 dprintk ("%s\n", __func__);
77 77
78 ret = i2c_transfer (state->i2c, &msg, 1); 78 ret = i2c_transfer (state->i2c, &msg, 1);
79 79
80 if (ret != 1) 80 if (ret != 1)
81 printk("%s: writereg error (reg == 0x%02x, val == 0x%02x, ret == %i)\n", 81 printk("%s: writereg error (reg == 0x%02x, val == 0x%02x, ret == %i)\n",
82 __FUNCTION__, reg, data, ret); 82 __func__, reg, data, ret);
83 83
84 return (ret != 1) ? -1 : 0; 84 return (ret != 1) ? -1 : 0;
85} 85}
@@ -92,7 +92,7 @@ static int cx22700_readreg (struct cx22700_state* state, u8 reg)
92 struct i2c_msg msg [] = { { .addr = state->config->demod_address, .flags = 0, .buf = b0, .len = 1 }, 92 struct i2c_msg msg [] = { { .addr = state->config->demod_address, .flags = 0, .buf = b0, .len = 1 },
93 { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = b1, .len = 1 } }; 93 { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = b1, .len = 1 } };
94 94
95 dprintk ("%s\n", __FUNCTION__); 95 dprintk ("%s\n", __func__);
96 96
97 ret = i2c_transfer (state->i2c, msg, 2); 97 ret = i2c_transfer (state->i2c, msg, 2);
98 98
@@ -105,7 +105,7 @@ static int cx22700_set_inversion (struct cx22700_state* state, int inversion)
105{ 105{
106 u8 val; 106 u8 val;
107 107
108 dprintk ("%s\n", __FUNCTION__); 108 dprintk ("%s\n", __func__);
109 109
110 switch (inversion) { 110 switch (inversion) {
111 case INVERSION_AUTO: 111 case INVERSION_AUTO:
@@ -127,7 +127,7 @@ static int cx22700_set_tps (struct cx22700_state *state, struct dvb_ofdm_paramet
127 static const u8 fec_tab [6] = { 0, 1, 2, 0, 3, 4 }; 127 static const u8 fec_tab [6] = { 0, 1, 2, 0, 3, 4 };
128 u8 val; 128 u8 val;
129 129
130 dprintk ("%s\n", __FUNCTION__); 130 dprintk ("%s\n", __func__);
131 131
132 if (p->code_rate_HP < FEC_1_2 || p->code_rate_HP > FEC_7_8) 132 if (p->code_rate_HP < FEC_1_2 || p->code_rate_HP > FEC_7_8)
133 return -EINVAL; 133 return -EINVAL;
@@ -191,7 +191,7 @@ static int cx22700_get_tps (struct cx22700_state* state, struct dvb_ofdm_paramet
191 FEC_5_6, FEC_7_8 }; 191 FEC_5_6, FEC_7_8 };
192 u8 val; 192 u8 val;
193 193
194 dprintk ("%s\n", __FUNCTION__); 194 dprintk ("%s\n", __func__);
195 195
196 if (!(cx22700_readreg(state, 0x07) & 0x20)) /* tps valid? */ 196 if (!(cx22700_readreg(state, 0x07) & 0x20)) /* tps valid? */
197 return -EAGAIN; 197 return -EAGAIN;
diff --git a/drivers/media/dvb/frontends/cx22700.h b/drivers/media/dvb/frontends/cx22700.h
index 7ac33690cdcc..4757a930ca05 100644
--- a/drivers/media/dvb/frontends/cx22700.h
+++ b/drivers/media/dvb/frontends/cx22700.h
@@ -38,7 +38,7 @@ extern struct dvb_frontend* cx22700_attach(const struct cx22700_config* config,
38static inline struct dvb_frontend* cx22700_attach(const struct cx22700_config* config, 38static inline struct dvb_frontend* cx22700_attach(const struct cx22700_config* config,
39 struct i2c_adapter* i2c) 39 struct i2c_adapter* i2c)
40{ 40{
41 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 41 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
42 return NULL; 42 return NULL;
43} 43}
44#endif // CONFIG_DVB_CX22700 44#endif // CONFIG_DVB_CX22700
diff --git a/drivers/media/dvb/frontends/cx22702.c b/drivers/media/dvb/frontends/cx22702.c
index 1dc164d5488c..cc1db4e371c3 100644
--- a/drivers/media/dvb/frontends/cx22702.c
+++ b/drivers/media/dvb/frontends/cx22702.c
@@ -48,7 +48,7 @@ struct cx22702_state {
48 u8 prevUCBlocks; 48 u8 prevUCBlocks;
49}; 49};
50 50
51static int debug = 0; 51static int debug;
52#define dprintk if (debug) printk 52#define dprintk if (debug) printk
53 53
54/* Register values to initialise the demod */ 54/* Register values to initialise the demod */
@@ -90,7 +90,7 @@ static int cx22702_writereg (struct cx22702_state* state, u8 reg, u8 data)
90 90
91 if (ret != 1) 91 if (ret != 1)
92 printk("%s: writereg error (reg == 0x%02x, val == 0x%02x, ret == %i)\n", 92 printk("%s: writereg error (reg == 0x%02x, val == 0x%02x, ret == %i)\n",
93 __FUNCTION__, reg, data, ret); 93 __func__, reg, data, ret);
94 94
95 return (ret != 1) ? -1 : 0; 95 return (ret != 1) ? -1 : 0;
96} 96}
@@ -108,7 +108,7 @@ static u8 cx22702_readreg (struct cx22702_state* state, u8 reg)
108 ret = i2c_transfer(state->i2c, msg, 2); 108 ret = i2c_transfer(state->i2c, msg, 2);
109 109
110 if (ret != 2) 110 if (ret != 2)
111 printk("%s: readreg error (ret == %i)\n", __FUNCTION__, ret); 111 printk("%s: readreg error (ret == %i)\n", __func__, ret);
112 112
113 return b1[0]; 113 return b1[0];
114} 114}
@@ -195,7 +195,7 @@ static int cx22702_get_tps (struct cx22702_state *state, struct dvb_ofdm_paramet
195static int cx22702_i2c_gate_ctrl(struct dvb_frontend* fe, int enable) 195static int cx22702_i2c_gate_ctrl(struct dvb_frontend* fe, int enable)
196{ 196{
197 struct cx22702_state* state = fe->demodulator_priv; 197 struct cx22702_state* state = fe->demodulator_priv;
198 dprintk ("%s(%d)\n", __FUNCTION__, enable); 198 dprintk ("%s(%d)\n", __func__, enable);
199 if (enable) 199 if (enable)
200 return cx22702_writereg (state, 0x0D, cx22702_readreg(state, 0x0D) & 0xfe); 200 return cx22702_writereg (state, 0x0D, cx22702_readreg(state, 0x0D) & 0xfe);
201 else 201 else
@@ -228,7 +228,7 @@ static int cx22702_set_tps (struct dvb_frontend* fe, struct dvb_frontend_paramet
228 cx22702_writereg(state, 0x0C, cx22702_readreg(state, 0x0C) &0xcf ); 228 cx22702_writereg(state, 0x0C, cx22702_readreg(state, 0x0C) &0xcf );
229 break; 229 break;
230 default: 230 default:
231 dprintk ("%s: invalid bandwidth\n",__FUNCTION__); 231 dprintk ("%s: invalid bandwidth\n",__func__);
232 return -EINVAL; 232 return -EINVAL;
233 } 233 }
234 234
@@ -250,7 +250,7 @@ static int cx22702_set_tps (struct dvb_frontend* fe, struct dvb_frontend_paramet
250 cx22702_writereg(state, 0x0B, cx22702_readreg(state, 0x0B) & 0xfc ); 250 cx22702_writereg(state, 0x0B, cx22702_readreg(state, 0x0B) & 0xfc );
251 cx22702_writereg(state, 0x0C, (cx22702_readreg(state, 0x0C) & 0xBF) | 0x40 ); 251 cx22702_writereg(state, 0x0C, (cx22702_readreg(state, 0x0C) & 0xBF) | 0x40 );
252 cx22702_writereg(state, 0x00, 0x01); /* Begin aquisition */ 252 cx22702_writereg(state, 0x00, 0x01); /* Begin aquisition */
253 dprintk("%s: Autodetecting\n",__FUNCTION__); 253 dprintk("%s: Autodetecting\n",__func__);
254 return 0; 254 return 0;
255 } 255 }
256 256
@@ -261,7 +261,7 @@ static int cx22702_set_tps (struct dvb_frontend* fe, struct dvb_frontend_paramet
261 case QAM_16: val = (val&0xe7)|0x08; break; 261 case QAM_16: val = (val&0xe7)|0x08; break;
262 case QAM_64: val = (val&0xe7)|0x10; break; 262 case QAM_64: val = (val&0xe7)|0x10; break;
263 default: 263 default:
264 dprintk ("%s: invalid constellation\n",__FUNCTION__); 264 dprintk ("%s: invalid constellation\n",__func__);
265 return -EINVAL; 265 return -EINVAL;
266 } 266 }
267 switch(p->u.ofdm.hierarchy_information) { 267 switch(p->u.ofdm.hierarchy_information) {
@@ -270,7 +270,7 @@ static int cx22702_set_tps (struct dvb_frontend* fe, struct dvb_frontend_paramet
270 case HIERARCHY_2: val = (val&0xf8)|2; break; 270 case HIERARCHY_2: val = (val&0xf8)|2; break;
271 case HIERARCHY_4: val = (val&0xf8)|3; break; 271 case HIERARCHY_4: val = (val&0xf8)|3; break;
272 default: 272 default:
273 dprintk ("%s: invalid hierarchy\n",__FUNCTION__); 273 dprintk ("%s: invalid hierarchy\n",__func__);
274 return -EINVAL; 274 return -EINVAL;
275 } 275 }
276 cx22702_writereg (state, 0x06, val); 276 cx22702_writereg (state, 0x06, val);
@@ -284,7 +284,7 @@ static int cx22702_set_tps (struct dvb_frontend* fe, struct dvb_frontend_paramet
284 case FEC_5_6: val = (val&0xc7)|0x18; break; 284 case FEC_5_6: val = (val&0xc7)|0x18; break;
285 case FEC_7_8: val = (val&0xc7)|0x20; break; 285 case FEC_7_8: val = (val&0xc7)|0x20; break;
286 default: 286 default:
287 dprintk ("%s: invalid code_rate_HP\n",__FUNCTION__); 287 dprintk ("%s: invalid code_rate_HP\n",__func__);
288 return -EINVAL; 288 return -EINVAL;
289 } 289 }
290 switch(p->u.ofdm.code_rate_LP) { 290 switch(p->u.ofdm.code_rate_LP) {
@@ -295,7 +295,7 @@ static int cx22702_set_tps (struct dvb_frontend* fe, struct dvb_frontend_paramet
295 case FEC_5_6: val = (val&0xf8)|3; break; 295 case FEC_5_6: val = (val&0xf8)|3; break;
296 case FEC_7_8: val = (val&0xf8)|4; break; 296 case FEC_7_8: val = (val&0xf8)|4; break;
297 default: 297 default:
298 dprintk ("%s: invalid code_rate_LP\n",__FUNCTION__); 298 dprintk ("%s: invalid code_rate_LP\n",__func__);
299 return -EINVAL; 299 return -EINVAL;
300 } 300 }
301 cx22702_writereg (state, 0x07, val); 301 cx22702_writereg (state, 0x07, val);
@@ -307,14 +307,14 @@ static int cx22702_set_tps (struct dvb_frontend* fe, struct dvb_frontend_paramet
307 case GUARD_INTERVAL_1_8: val = (val&0xf3)|0x08; break; 307 case GUARD_INTERVAL_1_8: val = (val&0xf3)|0x08; break;
308 case GUARD_INTERVAL_1_4: val = (val&0xf3)|0x0c; break; 308 case GUARD_INTERVAL_1_4: val = (val&0xf3)|0x0c; break;
309 default: 309 default:
310 dprintk ("%s: invalid guard_interval\n",__FUNCTION__); 310 dprintk ("%s: invalid guard_interval\n",__func__);
311 return -EINVAL; 311 return -EINVAL;
312 } 312 }
313 switch(p->u.ofdm.transmission_mode) { 313 switch(p->u.ofdm.transmission_mode) {
314 case TRANSMISSION_MODE_2K: val = (val&0xfc); break; 314 case TRANSMISSION_MODE_2K: val = (val&0xfc); break;
315 case TRANSMISSION_MODE_8K: val = (val&0xfc)|1; break; 315 case TRANSMISSION_MODE_8K: val = (val&0xfc)|1; break;
316 default: 316 default:
317 dprintk ("%s: invalid transmission_mode\n",__FUNCTION__); 317 dprintk ("%s: invalid transmission_mode\n",__func__);
318 return -EINVAL; 318 return -EINVAL;
319 } 319 }
320 cx22702_writereg(state, 0x08, val); 320 cx22702_writereg(state, 0x08, val);
@@ -360,7 +360,7 @@ static int cx22702_read_status(struct dvb_frontend* fe, fe_status_t* status)
360 reg23 = cx22702_readreg (state, 0x23); 360 reg23 = cx22702_readreg (state, 0x23);
361 361
362 dprintk ("%s: status demod=0x%02x agc=0x%02x\n" 362 dprintk ("%s: status demod=0x%02x agc=0x%02x\n"
363 ,__FUNCTION__,reg0A,reg23); 363 ,__func__,reg0A,reg23);
364 364
365 if(reg0A & 0x10) { 365 if(reg0A & 0x10) {
366 *status |= FE_HAS_LOCK; 366 *status |= FE_HAS_LOCK;
diff --git a/drivers/media/dvb/frontends/cx22702.h b/drivers/media/dvb/frontends/cx22702.h
index 9cd64da6ee40..8af766a31552 100644
--- a/drivers/media/dvb/frontends/cx22702.h
+++ b/drivers/media/dvb/frontends/cx22702.h
@@ -48,7 +48,7 @@ extern struct dvb_frontend* cx22702_attach(const struct cx22702_config* config,
48static inline struct dvb_frontend* cx22702_attach(const struct cx22702_config* config, 48static inline struct dvb_frontend* cx22702_attach(const struct cx22702_config* config,
49 struct i2c_adapter* i2c) 49 struct i2c_adapter* i2c)
50{ 50{
51 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 51 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
52 return NULL; 52 return NULL;
53} 53}
54#endif // CONFIG_DVB_CX22702 54#endif // CONFIG_DVB_CX22702
diff --git a/drivers/media/dvb/frontends/cx24110.c b/drivers/media/dvb/frontends/cx24110.c
index b03d8283c37d..87ae29db024f 100644
--- a/drivers/media/dvb/frontends/cx24110.c
+++ b/drivers/media/dvb/frontends/cx24110.c
@@ -121,7 +121,7 @@ static int cx24110_writereg (struct cx24110_state* state, int reg, int data)
121 121
122 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) { 122 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) {
123 dprintk ("%s: writereg error (err == %i, reg == 0x%02x," 123 dprintk ("%s: writereg error (err == %i, reg == 0x%02x,"
124 " data == 0x%02x)\n", __FUNCTION__, err, reg, data); 124 " data == 0x%02x)\n", __func__, err, reg, data);
125 return -EREMOTEIO; 125 return -EREMOTEIO;
126 } 126 }
127 127
@@ -247,7 +247,7 @@ static int cx24110_set_symbolrate (struct cx24110_state* state, u32 srate)
247 static const u32 bands[]={5000000UL,15000000UL,90999000UL/2}; 247 static const u32 bands[]={5000000UL,15000000UL,90999000UL/2};
248 int i; 248 int i;
249 249
250 dprintk("cx24110 debug: entering %s(%d)\n",__FUNCTION__,srate); 250 dprintk("cx24110 debug: entering %s(%d)\n",__func__,srate);
251 if (srate>90999000UL/2) 251 if (srate>90999000UL/2)
252 srate=90999000UL/2; 252 srate=90999000UL/2;
253 if (srate<500000) 253 if (srate<500000)
@@ -358,7 +358,7 @@ static int cx24110_initfe(struct dvb_frontend* fe)
358/* fixme (low): error handling */ 358/* fixme (low): error handling */
359 int i; 359 int i;
360 360
361 dprintk("%s: init chip\n", __FUNCTION__); 361 dprintk("%s: init chip\n", __func__);
362 362
363 for(i = 0; i < ARRAY_SIZE(cx24110_regdata); i++) { 363 for(i = 0; i < ARRAY_SIZE(cx24110_regdata); i++) {
364 cx24110_writereg(state, cx24110_regdata[i].reg, cx24110_regdata[i].data); 364 cx24110_writereg(state, cx24110_regdata[i].reg, cx24110_regdata[i].data);
diff --git a/drivers/media/dvb/frontends/cx24110.h b/drivers/media/dvb/frontends/cx24110.h
index 0ca3af4db513..1792adb23c4d 100644
--- a/drivers/media/dvb/frontends/cx24110.h
+++ b/drivers/media/dvb/frontends/cx24110.h
@@ -48,7 +48,7 @@ extern struct dvb_frontend* cx24110_attach(const struct cx24110_config* config,
48static inline struct dvb_frontend* cx24110_attach(const struct cx24110_config* config, 48static inline struct dvb_frontend* cx24110_attach(const struct cx24110_config* config,
49 struct i2c_adapter* i2c) 49 struct i2c_adapter* i2c)
50{ 50{
51 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 51 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
52 return NULL; 52 return NULL;
53} 53}
54#endif // CONFIG_DVB_CX24110 54#endif // CONFIG_DVB_CX24110
diff --git a/drivers/media/dvb/frontends/cx24113.h b/drivers/media/dvb/frontends/cx24113.h
new file mode 100644
index 000000000000..5ab3dd11076b
--- /dev/null
+++ b/drivers/media/dvb/frontends/cx24113.h
@@ -0,0 +1,48 @@
1/*
2 * Driver for Conexant CX24113/CX24128 Tuner (Satelite)
3 *
4 * Copyright (C) 2007-8 Patrick Boettcher <pb@linuxtv.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=
20 */
21
22#ifndef CX24113_H
23#define CX24113_H
24
25struct dvb_frontend;
26
27struct cx24113_config {
28 u8 i2c_addr; /* 0x14 or 0x54 */
29
30 u32 xtal_khz;
31};
32
33/* TODO: #if defined(CONFIG_DVB_TUNER_CX24113) || \
34 * (defined(CONFIG_DVB_TUNER_CX24113_MODULE) && defined(MODULE)) */
35
36static inline struct dvb_frontend *cx24113_attach(struct dvb_frontend *fe,
37 const struct cx24113_config *config, struct i2c_adapter *i2c)
38{
39 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
40 return NULL;
41}
42
43static inline void cx24113_agc_callback(struct dvb_frontend *fe)
44{
45 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
46}
47
48#endif /* CX24113_H */
diff --git a/drivers/media/dvb/frontends/cx24123.c b/drivers/media/dvb/frontends/cx24123.c
index d74fdbd63361..7f68d78c6558 100644
--- a/drivers/media/dvb/frontends/cx24123.c
+++ b/drivers/media/dvb/frontends/cx24123.c
@@ -1,24 +1,26 @@
1/* 1/*
2 Conexant cx24123/cx24109 - DVB QPSK Satellite demod/tuner driver 2 * Conexant cx24123/cx24109 - DVB QPSK Satellite demod/tuner driver
3 3 *
4 Copyright (C) 2005 Steven Toth <stoth@hauppauge.com> 4 * Copyright (C) 2005 Steven Toth <stoth@hauppauge.com>
5 5 *
6 Support for KWorld DVB-S 100 by Vadim Catana <skystar@moldova.cc> 6 * Support for KWorld DVB-S 100 by Vadim Catana <skystar@moldova.cc>
7 7 *
8 This program is free software; you can redistribute it and/or modify 8 * Support for CX24123/CX24113-NIM by Patrick Boettcher <pb@linuxtv.org>
9 it under the terms of the GNU General Public License as published by 9 *
10 the Free Software Foundation; either version 2 of the License, or 10 * This program is free software; you can redistribute it and/or
11 (at your option) any later version. 11 * modify it under the terms of the GNU General Public License as
12 12 * published by the Free Software Foundation; either version 2 of
13 This program is distributed in the hope that it will be useful, 13 * the License, or (at your option) any later version.
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 *
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * This program is distributed in the hope that it will be useful,
16 GNU General Public License for more details. 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 You should have received a copy of the GNU General Public License 18 * General Public License for more details.
19 along with this program; if not, write to the Free Software 19 *
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * You should have received a copy of the GNU General Public License
21*/ 21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
22 24
23#include <linux/slab.h> 25#include <linux/slab.h>
24#include <linux/kernel.h> 26#include <linux/kernel.h>
@@ -32,9 +34,16 @@
32 34
33static int force_band; 35static int force_band;
34static int debug; 36static int debug;
37
38#define info(args...) do { printk(KERN_INFO "CX24123: " args); } while (0)
39#define err(args...) do { printk(KERN_ERR "CX24123: " args); } while (0)
40
35#define dprintk(args...) \ 41#define dprintk(args...) \
36 do { \ 42 do { \
37 if (debug) printk (KERN_DEBUG "cx24123: " args); \ 43 if (debug) { \
44 printk(KERN_DEBUG "CX24123: %s: ", __func__); \
45 printk(args); \
46 } \
38 } while (0) 47 } while (0)
39 48
40struct cx24123_state 49struct cx24123_state
@@ -51,6 +60,10 @@ struct cx24123_state
51 u32 pllarg; 60 u32 pllarg;
52 u32 FILTune; 61 u32 FILTune;
53 62
63 struct i2c_adapter tuner_i2c_adapter;
64
65 u8 demod_rev;
66
54 /* The Demod/Tuner can't easily provide these, we cache them */ 67 /* The Demod/Tuner can't easily provide these, we cache them */
55 u32 currentfreq; 68 u32 currentfreq;
56 u32 currentsymbolrate; 69 u32 currentsymbolrate;
@@ -225,48 +238,52 @@ static struct {
225 {0x67, 0x83}, /* Non-DCII symbol clock */ 238 {0x67, 0x83}, /* Non-DCII symbol clock */
226}; 239};
227 240
228static int cx24123_writereg(struct cx24123_state* state, int reg, int data) 241static int cx24123_i2c_writereg(struct cx24123_state *state,
242 u8 i2c_addr, int reg, int data)
229{ 243{
230 u8 buf[] = { reg, data }; 244 u8 buf[] = { reg, data };
231 struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = buf, .len = 2 }; 245 struct i2c_msg msg = {
246 .addr = i2c_addr, .flags = 0, .buf = buf, .len = 2
247 };
232 int err; 248 int err;
233 249
234 if (debug>1) 250 /* printk(KERN_DEBUG "wr(%02x): %02x %02x\n", i2c_addr, reg, data); */
235 printk("cx24123: %s: write reg 0x%02x, value 0x%02x\n",
236 __FUNCTION__,reg, data);
237 251
238 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) { 252 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) {
239 printk("%s: writereg error(err == %i, reg == 0x%02x," 253 printk("%s: writereg error(err == %i, reg == 0x%02x,"
240 " data == 0x%02x)\n", __FUNCTION__, err, reg, data); 254 " data == 0x%02x)\n", __func__, err, reg, data);
241 return -EREMOTEIO; 255 return err;
242 } 256 }
243 257
244 return 0; 258 return 0;
245} 259}
246 260
247static int cx24123_readreg(struct cx24123_state* state, u8 reg) 261static int cx24123_i2c_readreg(struct cx24123_state *state, u8 i2c_addr, u8 reg)
248{ 262{
249 int ret; 263 int ret;
250 u8 b0[] = { reg }; 264 u8 b = 0;
251 u8 b1[] = { 0 };
252 struct i2c_msg msg[] = { 265 struct i2c_msg msg[] = {
253 { .addr = state->config->demod_address, .flags = 0, .buf = b0, .len = 1 }, 266 { .addr = i2c_addr, .flags = 0, .buf = &reg, .len = 1 },
254 { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = b1, .len = 1 } 267 { .addr = i2c_addr, .flags = I2C_M_RD, .buf = &b, .len = 1 }
255 }; 268 };
256 269
257 ret = i2c_transfer(state->i2c, msg, 2); 270 ret = i2c_transfer(state->i2c, msg, 2);
258 271
259 if (ret != 2) { 272 if (ret != 2) {
260 printk("%s: reg=0x%x (error=%d)\n", __FUNCTION__, reg, ret); 273 err("%s: reg=0x%x (error=%d)\n", __func__, reg, ret);
261 return ret; 274 return ret;
262 } 275 }
263 276
264 if (debug>1) 277 /* printk(KERN_DEBUG "rd(%02x): %02x %02x\n", i2c_addr, reg, b); */
265 printk("cx24123: read reg 0x%02x, value 0x%02x\n",reg, ret);
266 278
267 return b1[0]; 279 return b;
268} 280}
269 281
282#define cx24123_readreg(state, reg) \
283 cx24123_i2c_readreg(state, state->config->demod_address, reg)
284#define cx24123_writereg(state, reg, val) \
285 cx24123_i2c_writereg(state, state->config->demod_address, reg, val)
286
270static int cx24123_set_inversion(struct cx24123_state* state, fe_spectral_inversion_t inversion) 287static int cx24123_set_inversion(struct cx24123_state* state, fe_spectral_inversion_t inversion)
271{ 288{
272 u8 nom_reg = cx24123_readreg(state, 0x0e); 289 u8 nom_reg = cx24123_readreg(state, 0x0e);
@@ -274,17 +291,17 @@ static int cx24123_set_inversion(struct cx24123_state* state, fe_spectral_invers
274 291
275 switch (inversion) { 292 switch (inversion) {
276 case INVERSION_OFF: 293 case INVERSION_OFF:
277 dprintk("%s: inversion off\n",__FUNCTION__); 294 dprintk("inversion off\n");
278 cx24123_writereg(state, 0x0e, nom_reg & ~0x80); 295 cx24123_writereg(state, 0x0e, nom_reg & ~0x80);
279 cx24123_writereg(state, 0x10, auto_reg | 0x80); 296 cx24123_writereg(state, 0x10, auto_reg | 0x80);
280 break; 297 break;
281 case INVERSION_ON: 298 case INVERSION_ON:
282 dprintk("%s: inversion on\n",__FUNCTION__); 299 dprintk("inversion on\n");
283 cx24123_writereg(state, 0x0e, nom_reg | 0x80); 300 cx24123_writereg(state, 0x0e, nom_reg | 0x80);
284 cx24123_writereg(state, 0x10, auto_reg | 0x80); 301 cx24123_writereg(state, 0x10, auto_reg | 0x80);
285 break; 302 break;
286 case INVERSION_AUTO: 303 case INVERSION_AUTO:
287 dprintk("%s: inversion auto\n",__FUNCTION__); 304 dprintk("inversion auto\n");
288 cx24123_writereg(state, 0x10, auto_reg & ~0x80); 305 cx24123_writereg(state, 0x10, auto_reg & ~0x80);
289 break; 306 break;
290 default: 307 default:
@@ -301,10 +318,10 @@ static int cx24123_get_inversion(struct cx24123_state* state, fe_spectral_invers
301 val = cx24123_readreg(state, 0x1b) >> 7; 318 val = cx24123_readreg(state, 0x1b) >> 7;
302 319
303 if (val == 0) { 320 if (val == 0) {
304 dprintk("%s: read inversion off\n",__FUNCTION__); 321 dprintk("read inversion off\n");
305 *inversion = INVERSION_OFF; 322 *inversion = INVERSION_OFF;
306 } else { 323 } else {
307 dprintk("%s: read inversion on\n",__FUNCTION__); 324 dprintk("read inversion on\n");
308 *inversion = INVERSION_ON; 325 *inversion = INVERSION_ON;
309 } 326 }
310 327
@@ -326,42 +343,42 @@ static int cx24123_set_fec(struct cx24123_state* state, fe_code_rate_t fec)
326 343
327 switch (fec) { 344 switch (fec) {
328 case FEC_1_2: 345 case FEC_1_2:
329 dprintk("%s: set FEC to 1/2\n",__FUNCTION__); 346 dprintk("set FEC to 1/2\n");
330 cx24123_writereg(state, 0x0e, nom_reg | 0x01); 347 cx24123_writereg(state, 0x0e, nom_reg | 0x01);
331 cx24123_writereg(state, 0x0f, 0x02); 348 cx24123_writereg(state, 0x0f, 0x02);
332 break; 349 break;
333 case FEC_2_3: 350 case FEC_2_3:
334 dprintk("%s: set FEC to 2/3\n",__FUNCTION__); 351 dprintk("set FEC to 2/3\n");
335 cx24123_writereg(state, 0x0e, nom_reg | 0x02); 352 cx24123_writereg(state, 0x0e, nom_reg | 0x02);
336 cx24123_writereg(state, 0x0f, 0x04); 353 cx24123_writereg(state, 0x0f, 0x04);
337 break; 354 break;
338 case FEC_3_4: 355 case FEC_3_4:
339 dprintk("%s: set FEC to 3/4\n",__FUNCTION__); 356 dprintk("set FEC to 3/4\n");
340 cx24123_writereg(state, 0x0e, nom_reg | 0x03); 357 cx24123_writereg(state, 0x0e, nom_reg | 0x03);
341 cx24123_writereg(state, 0x0f, 0x08); 358 cx24123_writereg(state, 0x0f, 0x08);
342 break; 359 break;
343 case FEC_4_5: 360 case FEC_4_5:
344 dprintk("%s: set FEC to 4/5\n",__FUNCTION__); 361 dprintk("set FEC to 4/5\n");
345 cx24123_writereg(state, 0x0e, nom_reg | 0x04); 362 cx24123_writereg(state, 0x0e, nom_reg | 0x04);
346 cx24123_writereg(state, 0x0f, 0x10); 363 cx24123_writereg(state, 0x0f, 0x10);
347 break; 364 break;
348 case FEC_5_6: 365 case FEC_5_6:
349 dprintk("%s: set FEC to 5/6\n",__FUNCTION__); 366 dprintk("set FEC to 5/6\n");
350 cx24123_writereg(state, 0x0e, nom_reg | 0x05); 367 cx24123_writereg(state, 0x0e, nom_reg | 0x05);
351 cx24123_writereg(state, 0x0f, 0x20); 368 cx24123_writereg(state, 0x0f, 0x20);
352 break; 369 break;
353 case FEC_6_7: 370 case FEC_6_7:
354 dprintk("%s: set FEC to 6/7\n",__FUNCTION__); 371 dprintk("set FEC to 6/7\n");
355 cx24123_writereg(state, 0x0e, nom_reg | 0x06); 372 cx24123_writereg(state, 0x0e, nom_reg | 0x06);
356 cx24123_writereg(state, 0x0f, 0x40); 373 cx24123_writereg(state, 0x0f, 0x40);
357 break; 374 break;
358 case FEC_7_8: 375 case FEC_7_8:
359 dprintk("%s: set FEC to 7/8\n",__FUNCTION__); 376 dprintk("set FEC to 7/8\n");
360 cx24123_writereg(state, 0x0e, nom_reg | 0x07); 377 cx24123_writereg(state, 0x0e, nom_reg | 0x07);
361 cx24123_writereg(state, 0x0f, 0x80); 378 cx24123_writereg(state, 0x0f, 0x80);
362 break; 379 break;
363 case FEC_AUTO: 380 case FEC_AUTO:
364 dprintk("%s: set FEC to auto\n",__FUNCTION__); 381 dprintk("set FEC to auto\n");
365 cx24123_writereg(state, 0x0f, 0xfe); 382 cx24123_writereg(state, 0x0f, 0xfe);
366 break; 383 break;
367 default: 384 default:
@@ -490,7 +507,8 @@ static int cx24123_set_symbolrate(struct cx24123_state* state, u32 srate)
490 tmp = cx24123_readreg(state, 0x0c) & ~0xe0; 507 tmp = cx24123_readreg(state, 0x0c) & ~0xe0;
491 cx24123_writereg(state, 0x0c, tmp | sample_gain << 5); 508 cx24123_writereg(state, 0x0c, tmp | sample_gain << 5);
492 509
493 dprintk("%s: srate=%d, ratio=0x%08x, sample_rate=%i sample_gain=%d\n", __FUNCTION__, srate, ratio, sample_rate, sample_gain); 510 dprintk("srate=%d, ratio=0x%08x, sample_rate=%i sample_gain=%d\n",
511 srate, ratio, sample_rate, sample_gain);
494 512
495 return 0; 513 return 0;
496} 514}
@@ -570,7 +588,7 @@ static int cx24123_pll_writereg(struct dvb_frontend* fe, struct dvb_frontend_par
570 struct cx24123_state *state = fe->demodulator_priv; 588 struct cx24123_state *state = fe->demodulator_priv;
571 unsigned long timeout; 589 unsigned long timeout;
572 590
573 dprintk("%s: pll writereg called, data=0x%08x\n",__FUNCTION__,data); 591 dprintk("pll writereg called, data=0x%08x\n", data);
574 592
575 /* align the 21 bytes into to bit23 boundary */ 593 /* align the 21 bytes into to bit23 boundary */
576 data = data << 3; 594 data = data << 3;
@@ -583,7 +601,8 @@ static int cx24123_pll_writereg(struct dvb_frontend* fe, struct dvb_frontend_par
583 cx24123_writereg(state, 0x22, (data >> 16) & 0xff); 601 cx24123_writereg(state, 0x22, (data >> 16) & 0xff);
584 while ((cx24123_readreg(state, 0x20) & 0x40) == 0) { 602 while ((cx24123_readreg(state, 0x20) & 0x40) == 0) {
585 if (time_after(jiffies, timeout)) { 603 if (time_after(jiffies, timeout)) {
586 printk("%s: demodulator is not responding, possibly hung, aborting.\n", __FUNCTION__); 604 err("%s: demodulator is not responding, "\
605 "possibly hung, aborting.\n", __func__);
587 return -EREMOTEIO; 606 return -EREMOTEIO;
588 } 607 }
589 msleep(10); 608 msleep(10);
@@ -594,7 +613,8 @@ static int cx24123_pll_writereg(struct dvb_frontend* fe, struct dvb_frontend_par
594 cx24123_writereg(state, 0x22, (data>>8) & 0xff ); 613 cx24123_writereg(state, 0x22, (data>>8) & 0xff );
595 while ((cx24123_readreg(state, 0x20) & 0x40) == 0) { 614 while ((cx24123_readreg(state, 0x20) & 0x40) == 0) {
596 if (time_after(jiffies, timeout)) { 615 if (time_after(jiffies, timeout)) {
597 printk("%s: demodulator is not responding, possibly hung, aborting.\n", __FUNCTION__); 616 err("%s: demodulator is not responding, "\
617 "possibly hung, aborting.\n", __func__);
598 return -EREMOTEIO; 618 return -EREMOTEIO;
599 } 619 }
600 msleep(10); 620 msleep(10);
@@ -605,7 +625,8 @@ static int cx24123_pll_writereg(struct dvb_frontend* fe, struct dvb_frontend_par
605 cx24123_writereg(state, 0x22, (data) & 0xff ); 625 cx24123_writereg(state, 0x22, (data) & 0xff );
606 while ((cx24123_readreg(state, 0x20) & 0x80)) { 626 while ((cx24123_readreg(state, 0x20) & 0x80)) {
607 if (time_after(jiffies, timeout)) { 627 if (time_after(jiffies, timeout)) {
608 printk("%s: demodulator is not responding, possibly hung, aborting.\n", __FUNCTION__); 628 err("%s: demodulator is not responding," \
629 "possibly hung, aborting.\n", __func__);
609 return -EREMOTEIO; 630 return -EREMOTEIO;
610 } 631 }
611 msleep(10); 632 msleep(10);
@@ -626,7 +647,7 @@ static int cx24123_pll_tune(struct dvb_frontend* fe, struct dvb_frontend_paramet
626 dprintk("frequency=%i\n", p->frequency); 647 dprintk("frequency=%i\n", p->frequency);
627 648
628 if (cx24123_pll_calculate(fe, p) != 0) { 649 if (cx24123_pll_calculate(fe, p) != 0) {
629 printk("%s: cx24123_pll_calcutate failed\n",__FUNCTION__); 650 err("%s: cx24123_pll_calcutate failed\n", __func__);
630 return -EINVAL; 651 return -EINVAL;
631 } 652 }
632 653
@@ -643,18 +664,38 @@ static int cx24123_pll_tune(struct dvb_frontend* fe, struct dvb_frontend_paramet
643 cx24123_writereg(state, 0x27, state->FILTune >> 2); 664 cx24123_writereg(state, 0x27, state->FILTune >> 2);
644 cx24123_writereg(state, 0x28, val | (state->FILTune & 0x3)); 665 cx24123_writereg(state, 0x28, val | (state->FILTune & 0x3));
645 666
646 dprintk("%s: pll tune VCA=%d, band=%d, pll=%d\n",__FUNCTION__,state->VCAarg, 667 dprintk("pll tune VCA=%d, band=%d, pll=%d\n", state->VCAarg,
647 state->bandselectarg,state->pllarg); 668 state->bandselectarg, state->pllarg);
648 669
649 return 0; 670 return 0;
650} 671}
651 672
673
674/*
675 * 0x23:
676 * [7:7] = BTI enabled
677 * [6:6] = I2C repeater enabled
678 * [5:5] = I2C repeater start
679 * [0:0] = BTI start
680 */
681
682/* mode == 1 -> i2c-repeater, 0 -> bti */
683static int cx24123_repeater_mode(struct cx24123_state *state, u8 mode, u8 start)
684{
685 u8 r = cx24123_readreg(state, 0x23) & 0x1e;
686 if (mode)
687 r |= (1 << 6) | (start << 5);
688 else
689 r |= (1 << 7) | (start);
690 return cx24123_writereg(state, 0x23, r);
691}
692
652static int cx24123_initfe(struct dvb_frontend* fe) 693static int cx24123_initfe(struct dvb_frontend* fe)
653{ 694{
654 struct cx24123_state *state = fe->demodulator_priv; 695 struct cx24123_state *state = fe->demodulator_priv;
655 int i; 696 int i;
656 697
657 dprintk("%s: init frontend\n",__FUNCTION__); 698 dprintk("init frontend\n");
658 699
659 /* Configure the demod to a good set of defaults */ 700 /* Configure the demod to a good set of defaults */
660 for (i = 0; i < ARRAY_SIZE(cx24123_regdata); i++) 701 for (i = 0; i < ARRAY_SIZE(cx24123_regdata); i++)
@@ -664,6 +705,9 @@ static int cx24123_initfe(struct dvb_frontend* fe)
664 if(state->config->lnb_polarity) 705 if(state->config->lnb_polarity)
665 cx24123_writereg(state, 0x32, cx24123_readreg(state, 0x32) | 0x02); 706 cx24123_writereg(state, 0x32, cx24123_readreg(state, 0x32) | 0x02);
666 707
708 if (state->config->dont_use_pll)
709 cx24123_repeater_mode(state, 1, 0);
710
667 return 0; 711 return 0;
668} 712}
669 713
@@ -676,10 +720,10 @@ static int cx24123_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage
676 720
677 switch (voltage) { 721 switch (voltage) {
678 case SEC_VOLTAGE_13: 722 case SEC_VOLTAGE_13:
679 dprintk("%s: setting voltage 13V\n", __FUNCTION__); 723 dprintk("setting voltage 13V\n");
680 return cx24123_writereg(state, 0x29, val & 0x7f); 724 return cx24123_writereg(state, 0x29, val & 0x7f);
681 case SEC_VOLTAGE_18: 725 case SEC_VOLTAGE_18:
682 dprintk("%s: setting voltage 18V\n", __FUNCTION__); 726 dprintk("setting voltage 18V\n");
683 return cx24123_writereg(state, 0x29, val | 0x80); 727 return cx24123_writereg(state, 0x29, val | 0x80);
684 case SEC_VOLTAGE_OFF: 728 case SEC_VOLTAGE_OFF:
685 /* already handled in cx88-dvb */ 729 /* already handled in cx88-dvb */
@@ -697,7 +741,8 @@ static void cx24123_wait_for_diseqc(struct cx24123_state *state)
697 unsigned long timeout = jiffies + msecs_to_jiffies(200); 741 unsigned long timeout = jiffies + msecs_to_jiffies(200);
698 while (!(cx24123_readreg(state, 0x29) & 0x40)) { 742 while (!(cx24123_readreg(state, 0x29) & 0x40)) {
699 if(time_after(jiffies, timeout)) { 743 if(time_after(jiffies, timeout)) {
700 printk("%s: diseqc queue not ready, command may be lost.\n", __FUNCTION__); 744 err("%s: diseqc queue not ready, " \
745 "command may be lost.\n", __func__);
701 break; 746 break;
702 } 747 }
703 msleep(10); 748 msleep(10);
@@ -709,7 +754,7 @@ static int cx24123_send_diseqc_msg(struct dvb_frontend* fe, struct dvb_diseqc_ma
709 struct cx24123_state *state = fe->demodulator_priv; 754 struct cx24123_state *state = fe->demodulator_priv;
710 int i, val, tone; 755 int i, val, tone;
711 756
712 dprintk("%s:\n",__FUNCTION__); 757 dprintk("\n");
713 758
714 /* stop continuous tone if enabled */ 759 /* stop continuous tone if enabled */
715 tone = cx24123_readreg(state, 0x29); 760 tone = cx24123_readreg(state, 0x29);
@@ -744,7 +789,7 @@ static int cx24123_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t
744 struct cx24123_state *state = fe->demodulator_priv; 789 struct cx24123_state *state = fe->demodulator_priv;
745 int val, tone; 790 int val, tone;
746 791
747 dprintk("%s:\n", __FUNCTION__); 792 dprintk("\n");
748 793
749 /* stop continuous tone if enabled */ 794 /* stop continuous tone if enabled */
750 tone = cx24123_readreg(state, 0x29); 795 tone = cx24123_readreg(state, 0x29);
@@ -778,13 +823,21 @@ static int cx24123_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t
778static int cx24123_read_status(struct dvb_frontend* fe, fe_status_t* status) 823static int cx24123_read_status(struct dvb_frontend* fe, fe_status_t* status)
779{ 824{
780 struct cx24123_state *state = fe->demodulator_priv; 825 struct cx24123_state *state = fe->demodulator_priv;
781
782 int sync = cx24123_readreg(state, 0x14); 826 int sync = cx24123_readreg(state, 0x14);
783 int lock = cx24123_readreg(state, 0x20);
784 827
785 *status = 0; 828 *status = 0;
786 if (lock & 0x01) 829 if (state->config->dont_use_pll) {
787 *status |= FE_HAS_SIGNAL; 830 u32 tun_status = 0;
831 if (fe->ops.tuner_ops.get_status)
832 fe->ops.tuner_ops.get_status(fe, &tun_status);
833 if (tun_status & TUNER_STATUS_LOCKED)
834 *status |= FE_HAS_SIGNAL;
835 } else {
836 int lock = cx24123_readreg(state, 0x20);
837 if (lock & 0x01)
838 *status |= FE_HAS_SIGNAL;
839 }
840
788 if (sync & 0x02) 841 if (sync & 0x02)
789 *status |= FE_HAS_CARRIER; /* Phase locked */ 842 *status |= FE_HAS_CARRIER; /* Phase locked */
790 if (sync & 0x04) 843 if (sync & 0x04)
@@ -803,7 +856,7 @@ static int cx24123_read_status(struct dvb_frontend* fe, fe_status_t* status)
803 * Configured to return the measurement of errors in blocks, because no UCBLOCKS value 856 * Configured to return the measurement of errors in blocks, because no UCBLOCKS value
804 * is available, so this value doubles up to satisfy both measurements 857 * is available, so this value doubles up to satisfy both measurements
805 */ 858 */
806static int cx24123_read_ber(struct dvb_frontend* fe, u32* ber) 859static int cx24123_read_ber(struct dvb_frontend *fe, u32 *ber)
807{ 860{
808 struct cx24123_state *state = fe->demodulator_priv; 861 struct cx24123_state *state = fe->demodulator_priv;
809 862
@@ -813,23 +866,24 @@ static int cx24123_read_ber(struct dvb_frontend* fe, u32* ber)
813 (cx24123_readreg(state, 0x1d) << 8 | 866 (cx24123_readreg(state, 0x1d) << 8 |
814 cx24123_readreg(state, 0x1e)); 867 cx24123_readreg(state, 0x1e));
815 868
816 dprintk("%s: BER = %d\n",__FUNCTION__,*ber); 869 dprintk("BER = %d\n", *ber);
817 870
818 return 0; 871 return 0;
819} 872}
820 873
821static int cx24123_read_signal_strength(struct dvb_frontend* fe, u16* signal_strength) 874static int cx24123_read_signal_strength(struct dvb_frontend *fe,
875 u16 *signal_strength)
822{ 876{
823 struct cx24123_state *state = fe->demodulator_priv; 877 struct cx24123_state *state = fe->demodulator_priv;
824 878
825 *signal_strength = cx24123_readreg(state, 0x3b) << 8; /* larger = better */ 879 *signal_strength = cx24123_readreg(state, 0x3b) << 8; /* larger = better */
826 880
827 dprintk("%s: Signal strength = %d\n",__FUNCTION__,*signal_strength); 881 dprintk("Signal strength = %d\n", *signal_strength);
828 882
829 return 0; 883 return 0;
830} 884}
831 885
832static int cx24123_read_snr(struct dvb_frontend* fe, u16* snr) 886static int cx24123_read_snr(struct dvb_frontend *fe, u16 *snr)
833{ 887{
834 struct cx24123_state *state = fe->demodulator_priv; 888 struct cx24123_state *state = fe->demodulator_priv;
835 889
@@ -838,16 +892,17 @@ static int cx24123_read_snr(struct dvb_frontend* fe, u16* snr)
838 *snr = 65535 - (((u16)cx24123_readreg(state, 0x18) << 8) | 892 *snr = 65535 - (((u16)cx24123_readreg(state, 0x18) << 8) |
839 (u16)cx24123_readreg(state, 0x19)); 893 (u16)cx24123_readreg(state, 0x19));
840 894
841 dprintk("%s: read S/N index = %d\n",__FUNCTION__,*snr); 895 dprintk("read S/N index = %d\n", *snr);
842 896
843 return 0; 897 return 0;
844} 898}
845 899
846static int cx24123_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 900static int cx24123_set_frontend(struct dvb_frontend *fe,
901 struct dvb_frontend_parameters *p)
847{ 902{
848 struct cx24123_state *state = fe->demodulator_priv; 903 struct cx24123_state *state = fe->demodulator_priv;
849 904
850 dprintk("%s: set_frontend\n",__FUNCTION__); 905 dprintk("\n");
851 906
852 if (state->config->set_ts_params) 907 if (state->config->set_ts_params)
853 state->config->set_ts_params(fe, 0); 908 state->config->set_ts_params(fe, 0);
@@ -858,13 +913,22 @@ static int cx24123_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
858 cx24123_set_inversion(state, p->inversion); 913 cx24123_set_inversion(state, p->inversion);
859 cx24123_set_fec(state, p->u.qpsk.fec_inner); 914 cx24123_set_fec(state, p->u.qpsk.fec_inner);
860 cx24123_set_symbolrate(state, p->u.qpsk.symbol_rate); 915 cx24123_set_symbolrate(state, p->u.qpsk.symbol_rate);
861 cx24123_pll_tune(fe, p); 916
917 if (!state->config->dont_use_pll)
918 cx24123_pll_tune(fe, p);
919 else if (fe->ops.tuner_ops.set_params)
920 fe->ops.tuner_ops.set_params(fe, p);
921 else
922 err("it seems I don't have a tuner...");
862 923
863 /* Enable automatic aquisition and reset cycle */ 924 /* Enable automatic aquisition and reset cycle */
864 cx24123_writereg(state, 0x03, (cx24123_readreg(state, 0x03) | 0x07)); 925 cx24123_writereg(state, 0x03, (cx24123_readreg(state, 0x03) | 0x07));
865 cx24123_writereg(state, 0x00, 0x10); 926 cx24123_writereg(state, 0x00, 0x10);
866 cx24123_writereg(state, 0x00, 0); 927 cx24123_writereg(state, 0x00, 0);
867 928
929 if (state->config->agc_callback)
930 state->config->agc_callback(fe);
931
868 return 0; 932 return 0;
869} 933}
870 934
@@ -872,14 +936,14 @@ static int cx24123_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
872{ 936{
873 struct cx24123_state *state = fe->demodulator_priv; 937 struct cx24123_state *state = fe->demodulator_priv;
874 938
875 dprintk("%s: get_frontend\n",__FUNCTION__); 939 dprintk("\n");
876 940
877 if (cx24123_get_inversion(state, &p->inversion) != 0) { 941 if (cx24123_get_inversion(state, &p->inversion) != 0) {
878 printk("%s: Failed to get inversion status\n",__FUNCTION__); 942 err("%s: Failed to get inversion status\n", __func__);
879 return -EREMOTEIO; 943 return -EREMOTEIO;
880 } 944 }
881 if (cx24123_get_fec(state, &p->u.qpsk.fec_inner) != 0) { 945 if (cx24123_get_fec(state, &p->u.qpsk.fec_inner) != 0) {
882 printk("%s: Failed to get fec status\n",__FUNCTION__); 946 err("%s: Failed to get fec status\n", __func__);
883 return -EREMOTEIO; 947 return -EREMOTEIO;
884 } 948 }
885 p->frequency = state->currentfreq; 949 p->frequency = state->currentfreq;
@@ -900,13 +964,13 @@ static int cx24123_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
900 964
901 switch (tone) { 965 switch (tone) {
902 case SEC_TONE_ON: 966 case SEC_TONE_ON:
903 dprintk("%s: setting tone on\n", __FUNCTION__); 967 dprintk("setting tone on\n");
904 return cx24123_writereg(state, 0x29, val | 0x10); 968 return cx24123_writereg(state, 0x29, val | 0x10);
905 case SEC_TONE_OFF: 969 case SEC_TONE_OFF:
906 dprintk("%s: setting tone off\n",__FUNCTION__); 970 dprintk("setting tone off\n");
907 return cx24123_writereg(state, 0x29, val & 0xef); 971 return cx24123_writereg(state, 0x29, val & 0xef);
908 default: 972 default:
909 printk("%s: CASE reached default with tone=%d\n", __FUNCTION__, tone); 973 err("CASE reached default with tone=%d\n", tone);
910 return -EINVAL; 974 return -EINVAL;
911 } 975 }
912 976
@@ -939,47 +1003,86 @@ static int cx24123_get_algo(struct dvb_frontend *fe)
939static void cx24123_release(struct dvb_frontend* fe) 1003static void cx24123_release(struct dvb_frontend* fe)
940{ 1004{
941 struct cx24123_state* state = fe->demodulator_priv; 1005 struct cx24123_state* state = fe->demodulator_priv;
942 dprintk("%s\n",__FUNCTION__); 1006 dprintk("\n");
1007 i2c_del_adapter(&state->tuner_i2c_adapter);
943 kfree(state); 1008 kfree(state);
944} 1009}
945 1010
1011static int cx24123_tuner_i2c_tuner_xfer(struct i2c_adapter *i2c_adap,
1012 struct i2c_msg msg[], int num)
1013{
1014 struct cx24123_state *state = i2c_get_adapdata(i2c_adap);
1015 /* this repeater closes after the first stop */
1016 cx24123_repeater_mode(state, 1, 1);
1017 return i2c_transfer(state->i2c, msg, num);
1018}
1019
1020static u32 cx24123_tuner_i2c_func(struct i2c_adapter *adapter)
1021{
1022 return I2C_FUNC_I2C;
1023}
1024
1025static struct i2c_algorithm cx24123_tuner_i2c_algo = {
1026 .master_xfer = cx24123_tuner_i2c_tuner_xfer,
1027 .functionality = cx24123_tuner_i2c_func,
1028};
1029
1030struct i2c_adapter *
1031 cx24123_get_tuner_i2c_adapter(struct dvb_frontend *fe)
1032{
1033 struct cx24123_state *state = fe->demodulator_priv;
1034 return &state->tuner_i2c_adapter;
1035}
1036EXPORT_SYMBOL(cx24123_get_tuner_i2c_adapter);
1037
946static struct dvb_frontend_ops cx24123_ops; 1038static struct dvb_frontend_ops cx24123_ops;
947 1039
948struct dvb_frontend* cx24123_attach(const struct cx24123_config* config, 1040struct dvb_frontend* cx24123_attach(const struct cx24123_config* config,
949 struct i2c_adapter* i2c) 1041 struct i2c_adapter* i2c)
950{ 1042{
951 struct cx24123_state* state = NULL; 1043 struct cx24123_state *state =
952 int ret; 1044 kzalloc(sizeof(struct cx24123_state), GFP_KERNEL);
953
954 dprintk("%s\n",__FUNCTION__);
955 1045
1046 dprintk("\n");
956 /* allocate memory for the internal state */ 1047 /* allocate memory for the internal state */
957 state = kmalloc(sizeof(struct cx24123_state), GFP_KERNEL);
958 if (state == NULL) { 1048 if (state == NULL) {
959 printk("Unable to kmalloc\n"); 1049 err("Unable to kmalloc\n");
960 goto error; 1050 goto error;
961 } 1051 }
962 1052
963 /* setup the state */ 1053 /* setup the state */
964 state->config = config; 1054 state->config = config;
965 state->i2c = i2c; 1055 state->i2c = i2c;
966 state->VCAarg = 0;
967 state->VGAarg = 0;
968 state->bandselectarg = 0;
969 state->pllarg = 0;
970 state->currentfreq = 0;
971 state->currentsymbolrate = 0;
972 1056
973 /* check if the demod is there */ 1057 /* check if the demod is there */
974 ret = cx24123_readreg(state, 0x00); 1058 state->demod_rev = cx24123_readreg(state, 0x00);
975 if ((ret != 0xd1) && (ret != 0xe1)) { 1059 switch (state->demod_rev) {
976 printk("Version != d1 or e1\n"); 1060 case 0xe1: info("detected CX24123C\n"); break;
1061 case 0xd1: info("detected CX24123\n"); break;
1062 default:
1063 err("wrong demod revision: %x\n", state->demod_rev);
977 goto error; 1064 goto error;
978 } 1065 }
979 1066
980 /* create dvb_frontend */ 1067 /* create dvb_frontend */
981 memcpy(&state->frontend.ops, &cx24123_ops, sizeof(struct dvb_frontend_ops)); 1068 memcpy(&state->frontend.ops, &cx24123_ops, sizeof(struct dvb_frontend_ops));
982 state->frontend.demodulator_priv = state; 1069 state->frontend.demodulator_priv = state;
1070
1071 /* create tuner i2c adapter */
1072 if (config->dont_use_pll)
1073 cx24123_repeater_mode(state, 1, 0);
1074
1075 strncpy(state->tuner_i2c_adapter.name,
1076 "CX24123 tuner I2C bus", I2C_NAME_SIZE);
1077 state->tuner_i2c_adapter.class = I2C_CLASS_TV_DIGITAL,
1078 state->tuner_i2c_adapter.algo = &cx24123_tuner_i2c_algo;
1079 state->tuner_i2c_adapter.algo_data = NULL;
1080 i2c_set_adapdata(&state->tuner_i2c_adapter, state);
1081 if (i2c_add_adapter(&state->tuner_i2c_adapter) < 0) {
1082 err("tuner i2c bus could not be initialized\n");
1083 goto error;
1084 }
1085
983 return &state->frontend; 1086 return &state->frontend;
984 1087
985error: 1088error:
@@ -1029,7 +1132,8 @@ MODULE_PARM_DESC(debug, "Activates frontend debugging (default:0)");
1029module_param(force_band, int, 0644); 1132module_param(force_band, int, 0644);
1030MODULE_PARM_DESC(force_band, "Force a specific band select (1-9, default:off)."); 1133MODULE_PARM_DESC(force_band, "Force a specific band select (1-9, default:off).");
1031 1134
1032MODULE_DESCRIPTION("DVB Frontend module for Conexant cx24123/cx24109 hardware"); 1135MODULE_DESCRIPTION("DVB Frontend module for Conexant " \
1136 "CX24123/CX24109/CX24113 hardware");
1033MODULE_AUTHOR("Steven Toth"); 1137MODULE_AUTHOR("Steven Toth");
1034MODULE_LICENSE("GPL"); 1138MODULE_LICENSE("GPL");
1035 1139
diff --git a/drivers/media/dvb/frontends/cx24123.h b/drivers/media/dvb/frontends/cx24123.h
index 84f9e4f5c15e..81ebc3d2f19f 100644
--- a/drivers/media/dvb/frontends/cx24123.h
+++ b/drivers/media/dvb/frontends/cx24123.h
@@ -33,16 +33,27 @@ struct cx24123_config
33 33
34 /* 0 = LNB voltage normal, 1 = LNB voltage inverted */ 34 /* 0 = LNB voltage normal, 1 = LNB voltage inverted */
35 int lnb_polarity; 35 int lnb_polarity;
36
37 /* this device has another tuner */
38 u8 dont_use_pll;
39 void (*agc_callback) (struct dvb_frontend *);
36}; 40};
37 41
38#if defined(CONFIG_DVB_CX24123) || (defined(CONFIG_DVB_CX24123_MODULE) && defined(MODULE)) 42#if defined(CONFIG_DVB_CX24123) || (defined(CONFIG_DVB_CX24123_MODULE) && defined(MODULE))
39extern struct dvb_frontend* cx24123_attach(const struct cx24123_config* config, 43extern struct dvb_frontend *cx24123_attach(const struct cx24123_config *config,
40 struct i2c_adapter* i2c); 44 struct i2c_adapter *i2c);
45extern struct i2c_adapter *cx24123_get_tuner_i2c_adapter(struct dvb_frontend *);
41#else 46#else
42static inline struct dvb_frontend* cx24123_attach(const struct cx24123_config* config, 47static inline struct dvb_frontend *cx24123_attach(
43 struct i2c_adapter* i2c) 48 const struct cx24123_config *config, struct i2c_adapter *i2c)
49{
50 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
51 return NULL;
52}
53static struct i2c_adapter *
54 cx24123_get_tuner_i2c_adapter(struct dvb_frontend *fe)
44{ 55{
45 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 56 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
46 return NULL; 57 return NULL;
47} 58}
48#endif // CONFIG_DVB_CX24123 59#endif // CONFIG_DVB_CX24123
diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
index a6d3854a67bc..ba917359fa65 100644
--- a/drivers/media/dvb/frontends/dib3000.h
+++ b/drivers/media/dvb/frontends/dib3000.h
@@ -48,7 +48,7 @@ extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config
48static inline struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config, 48static inline struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
49 struct i2c_adapter* i2c, struct dib_fe_xfer_ops *xfer_ops) 49 struct i2c_adapter* i2c, struct dib_fe_xfer_ops *xfer_ops)
50{ 50{
51 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 51 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
52 return NULL; 52 return NULL;
53} 53}
54#endif // CONFIG_DVB_DIB3000MB 54#endif // CONFIG_DVB_DIB3000MB
diff --git a/drivers/media/dvb/frontends/dib3000mc.h b/drivers/media/dvb/frontends/dib3000mc.h
index 72d4757601d8..4142ed7a47d0 100644
--- a/drivers/media/dvb/frontends/dib3000mc.h
+++ b/drivers/media/dvb/frontends/dib3000mc.h
@@ -44,7 +44,7 @@ extern struct dvb_frontend * dib3000mc_attach(struct i2c_adapter *i2c_adap, u8 i
44#else 44#else
45static inline struct dvb_frontend * dib3000mc_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib3000mc_config *cfg) 45static inline struct dvb_frontend * dib3000mc_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib3000mc_config *cfg)
46{ 46{
47 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 47 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
48 return NULL; 48 return NULL;
49} 49}
50#endif // CONFIG_DVB_DIB3000MC 50#endif // CONFIG_DVB_DIB3000MC
diff --git a/drivers/media/dvb/frontends/dib7000p.c b/drivers/media/dvb/frontends/dib7000p.c
index 47c23e29753e..1a0142e0d741 100644
--- a/drivers/media/dvb/frontends/dib7000p.c
+++ b/drivers/media/dvb/frontends/dib7000p.c
@@ -1168,7 +1168,7 @@ static int dib7000p_set_frontend(struct dvb_frontend* fe,
1168 ret = dib7000p_tune(fe, fep); 1168 ret = dib7000p_tune(fe, fep);
1169 1169
1170 /* make this a config parameter */ 1170 /* make this a config parameter */
1171 dib7000p_set_output_mode(state, OUTMODE_MPEG2_FIFO); 1171 dib7000p_set_output_mode(state, state->cfg.output_mode);
1172 return ret; 1172 return ret;
1173} 1173}
1174 1174
@@ -1330,6 +1330,12 @@ struct dvb_frontend * dib7000p_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr,
1330 st->gpio_val = cfg->gpio_val; 1330 st->gpio_val = cfg->gpio_val;
1331 st->gpio_dir = cfg->gpio_dir; 1331 st->gpio_dir = cfg->gpio_dir;
1332 1332
1333 /* Ensure the output mode remains at the previous default if it's
1334 * not specifically set by the caller.
1335 */
1336 if (st->cfg.output_mode != OUTMODE_MPEG2_SERIAL)
1337 st->cfg.output_mode = OUTMODE_MPEG2_FIFO;
1338
1333 demod = &st->demod; 1339 demod = &st->demod;
1334 demod->demodulator_priv = st; 1340 demod->demodulator_priv = st;
1335 memcpy(&st->demod.ops, &dib7000p_ops, sizeof(struct dvb_frontend_ops)); 1341 memcpy(&st->demod.ops, &dib7000p_ops, sizeof(struct dvb_frontend_ops));
diff --git a/drivers/media/dvb/frontends/dib7000p.h b/drivers/media/dvb/frontends/dib7000p.h
index eefcac8b5244..081bd81f3da2 100644
--- a/drivers/media/dvb/frontends/dib7000p.h
+++ b/drivers/media/dvb/frontends/dib7000p.h
@@ -31,6 +31,8 @@ struct dib7000p_config {
31 u8 spur_protect; 31 u8 spur_protect;
32 32
33 int (*agc_control) (struct dvb_frontend *, u8 before); 33 int (*agc_control) (struct dvb_frontend *, u8 before);
34
35 u8 output_mode;
34}; 36};
35 37
36#define DEFAULT_DIB7000P_I2C_ADDRESS 18 38#define DEFAULT_DIB7000P_I2C_ADDRESS 18
diff --git a/drivers/media/dvb/frontends/dvb-pll.c b/drivers/media/dvb/frontends/dvb-pll.c
index 8c8d7342d0b3..a054894ff481 100644
--- a/drivers/media/dvb/frontends/dvb-pll.c
+++ b/drivers/media/dvb/frontends/dvb-pll.c
@@ -44,14 +44,10 @@ struct dvb_pll_priv {
44 44
45static unsigned int dvb_pll_devcount; 45static unsigned int dvb_pll_devcount;
46 46
47static int debug = 0; 47static int debug;
48module_param(debug, int, 0644); 48module_param(debug, int, 0644);
49MODULE_PARM_DESC(debug, "enable verbose debug messages"); 49MODULE_PARM_DESC(debug, "enable verbose debug messages");
50 50
51static unsigned int input[DVB_PLL_MAX] = { [ 0 ... (DVB_PLL_MAX-1) ] = 0 };
52module_param_array(input, int, NULL, 0644);
53MODULE_PARM_DESC(input,"specify rf input choice, 0 for autoselect (default)");
54
55static unsigned int id[DVB_PLL_MAX] = 51static unsigned int id[DVB_PLL_MAX] =
56 { [ 0 ... (DVB_PLL_MAX-1) ] = DVB_PLL_UNDEFINED }; 52 { [ 0 ... (DVB_PLL_MAX-1) ] = DVB_PLL_UNDEFINED };
57module_param_array(id, int, NULL, 0644); 53module_param_array(id, int, NULL, 0644);
@@ -80,23 +76,6 @@ struct dvb_pll_desc {
80/* ----------------------------------------------------------- */ 76/* ----------------------------------------------------------- */
81/* descriptions */ 77/* descriptions */
82 78
83/* Set AGC TOP value to 103 dBuV:
84 0x80 = Control Byte
85 0x40 = 250 uA charge pump (irrelevant)
86 0x18 = Aux Byte to follow
87 0x06 = 64.5 kHz divider (irrelevant)
88 0x01 = Disable Vt (aka sleep)
89
90 0x00 = AGC Time constant 2s Iagc = 300 nA (vs 0x80 = 9 nA)
91 0x50 = AGC Take over point = 103 dBuV */
92static u8 tua603x_agc103[] = { 2, 0x80|0x40|0x18|0x06|0x01, 0x00|0x50 };
93
94/* 0x04 = 166.67 kHz divider
95
96 0x80 = AGC Time constant 50ms Iagc = 9 uA
97 0x20 = AGC Take over point = 112 dBuV */
98static u8 tua603x_agc112[] = { 2, 0x80|0x40|0x18|0x04|0x01, 0x80|0x20 };
99
100static struct dvb_pll_desc dvb_pll_thomson_dtt7579 = { 79static struct dvb_pll_desc dvb_pll_thomson_dtt7579 = {
101 .name = "Thomson dtt7579", 80 .name = "Thomson dtt7579",
102 .min = 177000000, 81 .min = 177000000,
@@ -112,19 +91,6 @@ static struct dvb_pll_desc dvb_pll_thomson_dtt7579 = {
112 }, 91 },
113}; 92};
114 93
115static struct dvb_pll_desc dvb_pll_thomson_dtt7610 = {
116 .name = "Thomson dtt7610",
117 .min = 44000000,
118 .max = 958000000,
119 .iffreq= 44000000,
120 .count = 3,
121 .entries = {
122 { 157250000, 62500, 0x8e, 0x39 },
123 { 454000000, 62500, 0x8e, 0x3a },
124 { 999999999, 62500, 0x8e, 0x3c },
125 },
126};
127
128static void thomson_dtt759x_bw(struct dvb_frontend *fe, u8 *buf, 94static void thomson_dtt759x_bw(struct dvb_frontend *fe, u8 *buf,
129 const struct dvb_frontend_parameters *params) 95 const struct dvb_frontend_parameters *params)
130{ 96{
@@ -165,34 +131,6 @@ static struct dvb_pll_desc dvb_pll_lg_z201 = {
165 }, 131 },
166}; 132};
167 133
168static struct dvb_pll_desc dvb_pll_microtune_4042 = {
169 .name = "Microtune 4042 FI5",
170 .min = 57000000,
171 .max = 858000000,
172 .iffreq= 44000000,
173 .count = 3,
174 .entries = {
175 { 162000000, 62500, 0x8e, 0xa1 },
176 { 457000000, 62500, 0x8e, 0x91 },
177 { 999999999, 62500, 0x8e, 0x31 },
178 },
179};
180
181static struct dvb_pll_desc dvb_pll_thomson_dtt761x = {
182 /* DTT 7611 7611A 7612 7613 7613A 7614 7615 7615A */
183 .name = "Thomson dtt761x",
184 .min = 57000000,
185 .max = 863000000,
186 .iffreq= 44000000,
187 .count = 3,
188 .initdata = tua603x_agc103,
189 .entries = {
190 { 147000000, 62500, 0x8e, 0x39 },
191 { 417000000, 62500, 0x8e, 0x3a },
192 { 999999999, 62500, 0x8e, 0x3c },
193 },
194};
195
196static struct dvb_pll_desc dvb_pll_unknown_1 = { 134static struct dvb_pll_desc dvb_pll_unknown_1 = {
197 .name = "unknown 1", /* used by dntv live dvb-t */ 135 .name = "unknown 1", /* used by dntv live dvb-t */
198 .min = 174000000, 136 .min = 174000000,
@@ -301,54 +239,6 @@ static struct dvb_pll_desc dvb_pll_tua6034 = {
301 }, 239 },
302}; 240};
303 241
304/* Infineon TUA6034
305 * used in LG TDVS-H061F, LG TDVS-H062F and LG TDVS-H064F
306 */
307static struct dvb_pll_desc dvb_pll_lg_tdvs_h06xf = {
308 .name = "LG TDVS-H06xF",
309 .min = 54000000,
310 .max = 863000000,
311 .iffreq= 44000000,
312 .initdata = tua603x_agc103,
313 .count = 3,
314 .entries = {
315 { 165000000, 62500, 0xce, 0x01 },
316 { 450000000, 62500, 0xce, 0x02 },
317 { 999999999, 62500, 0xce, 0x04 },
318 },
319};
320
321/* Philips FMD1216ME
322 * used in Medion Hybrid PCMCIA card and USB Box
323 */
324static void fmd1216me_bw(struct dvb_frontend *fe, u8 *buf,
325 const struct dvb_frontend_parameters *params)
326{
327 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ &&
328 params->frequency >= 158870000)
329 buf[3] |= 0x08;
330}
331
332static struct dvb_pll_desc dvb_pll_fmd1216me = {
333 .name = "Philips FMD1216ME",
334 .min = 50870000,
335 .max = 858000000,
336 .iffreq= 36125000,
337 .set = fmd1216me_bw,
338 .initdata = tua603x_agc112,
339 .sleepdata = (u8[]){ 4, 0x9c, 0x60, 0x85, 0x54 },
340 .count = 7,
341 .entries = {
342 { 143870000, 166667, 0xbc, 0x41 },
343 { 158870000, 166667, 0xf4, 0x41 },
344 { 329870000, 166667, 0xbc, 0x42 },
345 { 441870000, 166667, 0xf4, 0x42 },
346 { 625870000, 166667, 0xbc, 0x44 },
347 { 803870000, 166667, 0xf4, 0x44 },
348 { 999999999, 166667, 0xfc, 0x44 },
349 }
350};
351
352/* ALPS TDED4 242/* ALPS TDED4
353 * used in Nebula-Cards and USB boxes 243 * used in Nebula-Cards and USB boxes
354 */ 244 */
@@ -391,55 +281,6 @@ static struct dvb_pll_desc dvb_pll_tdhu2 = {
391 } 281 }
392}; 282};
393 283
394/* Philips TUV1236D
395 * used in ATI HDTV Wonder
396 */
397static void tuv1236d_rf(struct dvb_frontend *fe, u8 *buf,
398 const struct dvb_frontend_parameters *params)
399{
400 struct dvb_pll_priv *priv = fe->tuner_priv;
401 unsigned int new_rf = input[priv->nr];
402
403 if ((new_rf == 0) || (new_rf > 2)) {
404 switch (params->u.vsb.modulation) {
405 case QAM_64:
406 case QAM_256:
407 new_rf = 1;
408 break;
409 case VSB_8:
410 default:
411 new_rf = 2;
412 }
413 }
414
415 switch (new_rf) {
416 case 1:
417 buf[3] |= 0x08;
418 break;
419 case 2:
420 buf[3] &= ~0x08;
421 break;
422 default:
423 printk(KERN_WARNING
424 "%s: unhandled rf input selection: %d",
425 __FUNCTION__, new_rf);
426 }
427}
428
429static struct dvb_pll_desc dvb_pll_tuv1236d = {
430 .name = "Philips TUV1236D",
431 .min = 54000000,
432 .max = 864000000,
433 .iffreq= 44000000,
434 .set = tuv1236d_rf,
435 .count = 3,
436 .entries = {
437 { 157250000, 62500, 0xc6, 0x41 },
438 { 454000000, 62500, 0xc6, 0x42 },
439 { 999999999, 62500, 0xc6, 0x44 },
440 },
441};
442
443/* Samsung TBMV30111IN / TBMV30712IN1 284/* Samsung TBMV30111IN / TBMV30712IN1
444 * used in Air2PC ATSC - 2nd generation (nxt2002) 285 * used in Air2PC ATSC - 2nd generation (nxt2002)
445 */ 286 */
@@ -476,64 +317,6 @@ static struct dvb_pll_desc dvb_pll_philips_sd1878_tda8261 = {
476 }, 317 },
477}; 318};
478 319
479/*
480 * Philips TD1316 Tuner.
481 */
482static void td1316_bw(struct dvb_frontend *fe, u8 *buf,
483 const struct dvb_frontend_parameters *params)
484{
485 u8 band;
486
487 /* determine band */
488 if (params->frequency < 161000000)
489 band = 1;
490 else if (params->frequency < 444000000)
491 band = 2;
492 else
493 band = 4;
494
495 buf[3] |= band;
496
497 /* setup PLL filter */
498 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ)
499 buf[3] |= 1 << 3;
500}
501
502static struct dvb_pll_desc dvb_pll_philips_td1316 = {
503 .name = "Philips TD1316",
504 .min = 87000000,
505 .max = 895000000,
506 .iffreq= 36166667,
507 .set = td1316_bw,
508 .count = 9,
509 .entries = {
510 { 93834000, 166667, 0xca, 0x60},
511 { 123834000, 166667, 0xca, 0xa0},
512 { 163834000, 166667, 0xca, 0xc0},
513 { 253834000, 166667, 0xca, 0x60},
514 { 383834000, 166667, 0xca, 0xa0},
515 { 443834000, 166667, 0xca, 0xc0},
516 { 583834000, 166667, 0xca, 0x60},
517 { 793834000, 166667, 0xca, 0xa0},
518 { 858834000, 166667, 0xca, 0xe0},
519 },
520};
521
522/* FE6600 used on DViCO Hybrid */
523static struct dvb_pll_desc dvb_pll_thomson_fe6600 = {
524 .name = "Thomson FE6600",
525 .min = 44250000,
526 .max = 858000000,
527 .iffreq= 36125000,
528 .count = 4,
529 .entries = {
530 { 250000000, 166667, 0xb4, 0x12 },
531 { 455000000, 166667, 0xfe, 0x11 },
532 { 775500000, 166667, 0xbc, 0x18 },
533 { 999999999, 166667, 0xf4, 0x18 },
534 }
535};
536
537static void opera1_bw(struct dvb_frontend *fe, u8 *buf, 320static void opera1_bw(struct dvb_frontend *fe, u8 *buf,
538 const struct dvb_frontend_parameters *params) 321 const struct dvb_frontend_parameters *params)
539{ 322{
@@ -560,50 +343,23 @@ static struct dvb_pll_desc dvb_pll_opera1 = {
560 } 343 }
561}; 344};
562 345
563/* Philips FCV1236D
564 */
565static struct dvb_pll_desc dvb_pll_fcv1236d = {
566/* Bit_0: RF Input select
567 * Bit_1: 0=digital, 1=analog
568 */
569 .name = "Philips FCV1236D",
570 .min = 53000000,
571 .max = 803000000,
572 .iffreq= 44000000,
573 .count = 3,
574 .entries = {
575 { 159000000, 62500, 0x8e, 0xa0 },
576 { 453000000, 62500, 0x8e, 0x90 },
577 { 999999999, 62500, 0x8e, 0x30 },
578 },
579};
580
581/* ----------------------------------------------------------- */ 346/* ----------------------------------------------------------- */
582 347
583static struct dvb_pll_desc *pll_list[] = { 348static struct dvb_pll_desc *pll_list[] = {
584 [DVB_PLL_UNDEFINED] = NULL, 349 [DVB_PLL_UNDEFINED] = NULL,
585 [DVB_PLL_THOMSON_DTT7579] = &dvb_pll_thomson_dtt7579, 350 [DVB_PLL_THOMSON_DTT7579] = &dvb_pll_thomson_dtt7579,
586 [DVB_PLL_THOMSON_DTT759X] = &dvb_pll_thomson_dtt759x, 351 [DVB_PLL_THOMSON_DTT759X] = &dvb_pll_thomson_dtt759x,
587 [DVB_PLL_THOMSON_DTT7610] = &dvb_pll_thomson_dtt7610,
588 [DVB_PLL_LG_Z201] = &dvb_pll_lg_z201, 352 [DVB_PLL_LG_Z201] = &dvb_pll_lg_z201,
589 [DVB_PLL_MICROTUNE_4042] = &dvb_pll_microtune_4042,
590 [DVB_PLL_THOMSON_DTT761X] = &dvb_pll_thomson_dtt761x,
591 [DVB_PLL_UNKNOWN_1] = &dvb_pll_unknown_1, 353 [DVB_PLL_UNKNOWN_1] = &dvb_pll_unknown_1,
592 [DVB_PLL_TUA6010XS] = &dvb_pll_tua6010xs, 354 [DVB_PLL_TUA6010XS] = &dvb_pll_tua6010xs,
593 [DVB_PLL_ENV57H1XD5] = &dvb_pll_env57h1xd5, 355 [DVB_PLL_ENV57H1XD5] = &dvb_pll_env57h1xd5,
594 [DVB_PLL_TUA6034] = &dvb_pll_tua6034, 356 [DVB_PLL_TUA6034] = &dvb_pll_tua6034,
595 [DVB_PLL_LG_TDVS_H06XF] = &dvb_pll_lg_tdvs_h06xf,
596 [DVB_PLL_TDA665X] = &dvb_pll_tda665x, 357 [DVB_PLL_TDA665X] = &dvb_pll_tda665x,
597 [DVB_PLL_FMD1216ME] = &dvb_pll_fmd1216me,
598 [DVB_PLL_TDED4] = &dvb_pll_tded4, 358 [DVB_PLL_TDED4] = &dvb_pll_tded4,
599 [DVB_PLL_TUV1236D] = &dvb_pll_tuv1236d,
600 [DVB_PLL_TDHU2] = &dvb_pll_tdhu2, 359 [DVB_PLL_TDHU2] = &dvb_pll_tdhu2,
601 [DVB_PLL_SAMSUNG_TBMV] = &dvb_pll_samsung_tbmv, 360 [DVB_PLL_SAMSUNG_TBMV] = &dvb_pll_samsung_tbmv,
602 [DVB_PLL_PHILIPS_SD1878_TDA8261] = &dvb_pll_philips_sd1878_tda8261, 361 [DVB_PLL_PHILIPS_SD1878_TDA8261] = &dvb_pll_philips_sd1878_tda8261,
603 [DVB_PLL_PHILIPS_TD1316] = &dvb_pll_philips_td1316,
604 [DVB_PLL_THOMSON_FE6600] = &dvb_pll_thomson_fe6600,
605 [DVB_PLL_OPERA1] = &dvb_pll_opera1, 362 [DVB_PLL_OPERA1] = &dvb_pll_opera1,
606 [DVB_PLL_FCV1236D] = &dvb_pll_fcv1236d,
607}; 363};
608 364
609/* ----------------------------------------------------------- */ 365/* ----------------------------------------------------------- */
@@ -849,20 +605,6 @@ struct dvb_frontend *dvb_pll_attach(struct dvb_frontend *fe, int pll_addr,
849 id[priv->nr] == pll_desc_id ? 605 id[priv->nr] == pll_desc_id ?
850 "insmod option" : "autodetected"); 606 "insmod option" : "autodetected");
851 } 607 }
852 if ((debug) || (input[priv->nr] > 0)) {
853 printk("dvb-pll[%d]", priv->nr);
854 if (i2c != NULL)
855 printk(" %d-%04x", i2c_adapter_id(i2c), pll_addr);
856 printk(": tuner rf input will be ");
857 switch (input[priv->nr]) {
858 case 0:
859 printk("autoselected\n");
860 break;
861 default:
862 printk("set to input %d (insmod option)\n",
863 input[priv->nr]);
864 }
865 }
866 608
867 return fe; 609 return fe;
868} 610}
diff --git a/drivers/media/dvb/frontends/dvb-pll.h b/drivers/media/dvb/frontends/dvb-pll.h
index e93a8104052b..872ca29e7cf3 100644
--- a/drivers/media/dvb/frontends/dvb-pll.h
+++ b/drivers/media/dvb/frontends/dvb-pll.h
@@ -11,26 +11,17 @@
11#define DVB_PLL_UNDEFINED 0 11#define DVB_PLL_UNDEFINED 0
12#define DVB_PLL_THOMSON_DTT7579 1 12#define DVB_PLL_THOMSON_DTT7579 1
13#define DVB_PLL_THOMSON_DTT759X 2 13#define DVB_PLL_THOMSON_DTT759X 2
14#define DVB_PLL_THOMSON_DTT7610 3 14#define DVB_PLL_LG_Z201 3
15#define DVB_PLL_LG_Z201 4 15#define DVB_PLL_UNKNOWN_1 4
16#define DVB_PLL_MICROTUNE_4042 5 16#define DVB_PLL_TUA6010XS 5
17#define DVB_PLL_THOMSON_DTT761X 6 17#define DVB_PLL_ENV57H1XD5 6
18#define DVB_PLL_UNKNOWN_1 7 18#define DVB_PLL_TUA6034 7
19#define DVB_PLL_TUA6010XS 8 19#define DVB_PLL_TDA665X 8
20#define DVB_PLL_ENV57H1XD5 9 20#define DVB_PLL_TDED4 9
21#define DVB_PLL_TUA6034 10 21#define DVB_PLL_TDHU2 10
22#define DVB_PLL_LG_TDVS_H06XF 11 22#define DVB_PLL_SAMSUNG_TBMV 11
23#define DVB_PLL_TDA665X 12 23#define DVB_PLL_PHILIPS_SD1878_TDA8261 12
24#define DVB_PLL_FMD1216ME 13 24#define DVB_PLL_OPERA1 13
25#define DVB_PLL_TDED4 14
26#define DVB_PLL_TUV1236D 15
27#define DVB_PLL_TDHU2 16
28#define DVB_PLL_SAMSUNG_TBMV 17
29#define DVB_PLL_PHILIPS_SD1878_TDA8261 18
30#define DVB_PLL_PHILIPS_TD1316 19
31#define DVB_PLL_THOMSON_FE6600 20
32#define DVB_PLL_OPERA1 21
33#define DVB_PLL_FCV1236D 22
34 25
35/** 26/**
36 * Attach a dvb-pll to the supplied frontend structure. 27 * Attach a dvb-pll to the supplied frontend structure.
@@ -52,7 +43,7 @@ static inline struct dvb_frontend *dvb_pll_attach(struct dvb_frontend *fe,
52 struct i2c_adapter *i2c, 43 struct i2c_adapter *i2c,
53 unsigned int pll_desc_id) 44 unsigned int pll_desc_id)
54{ 45{
55 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 46 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
56 return NULL; 47 return NULL;
57} 48}
58#endif 49#endif
diff --git a/drivers/media/dvb/frontends/isl6405.c b/drivers/media/dvb/frontends/isl6405.c
new file mode 100644
index 000000000000..33d33f4d8867
--- /dev/null
+++ b/drivers/media/dvb/frontends/isl6405.c
@@ -0,0 +1,164 @@
1/*
2 * isl6405.c - driver for dual lnb supply and control ic ISL6405
3 *
4 * Copyright (C) 2008 Hartmut Hackmann
5 * Copyright (C) 2006 Oliver Endriss
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
23 *
24 *
25 * the project's page is at http://www.linuxtv.org
26 */
27#include <linux/delay.h>
28#include <linux/errno.h>
29#include <linux/init.h>
30#include <linux/kernel.h>
31#include <linux/module.h>
32#include <linux/string.h>
33#include <linux/slab.h>
34
35#include "dvb_frontend.h"
36#include "isl6405.h"
37
38struct isl6405 {
39 u8 config;
40 u8 override_or;
41 u8 override_and;
42 struct i2c_adapter *i2c;
43 u8 i2c_addr;
44};
45
46static int isl6405_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
47{
48 struct isl6405 *isl6405 = (struct isl6405 *) fe->sec_priv;
49 struct i2c_msg msg = { .addr = isl6405->i2c_addr, .flags = 0,
50 .buf = &isl6405->config,
51 .len = sizeof(isl6405->config) };
52
53 if (isl6405->override_or & 0x80) {
54 isl6405->config &= ~(ISL6405_VSEL2 | ISL6405_EN2);
55 switch (voltage) {
56 case SEC_VOLTAGE_OFF:
57 break;
58 case SEC_VOLTAGE_13:
59 isl6405->config |= ISL6405_EN2;
60 break;
61 case SEC_VOLTAGE_18:
62 isl6405->config |= (ISL6405_EN2 | ISL6405_VSEL2);
63 break;
64 default:
65 return -EINVAL;
66 }
67 } else {
68 isl6405->config &= ~(ISL6405_VSEL1 | ISL6405_EN1);
69 switch (voltage) {
70 case SEC_VOLTAGE_OFF:
71 break;
72 case SEC_VOLTAGE_13:
73 isl6405->config |= ISL6405_EN1;
74 break;
75 case SEC_VOLTAGE_18:
76 isl6405->config |= (ISL6405_EN1 | ISL6405_VSEL1);
77 break;
78 default:
79 return -EINVAL;
80 };
81 }
82 isl6405->config |= isl6405->override_or;
83 isl6405->config &= isl6405->override_and;
84
85 return (i2c_transfer(isl6405->i2c, &msg, 1) == 1) ? 0 : -EIO;
86}
87
88static int isl6405_enable_high_lnb_voltage(struct dvb_frontend *fe, long arg)
89{
90 struct isl6405 *isl6405 = (struct isl6405 *) fe->sec_priv;
91 struct i2c_msg msg = { .addr = isl6405->i2c_addr, .flags = 0,
92 .buf = &isl6405->config,
93 .len = sizeof(isl6405->config) };
94
95 if (isl6405->override_or & 0x80) {
96 if (arg)
97 isl6405->config |= ISL6405_LLC2;
98 else
99 isl6405->config &= ~ISL6405_LLC2;
100 } else {
101 if (arg)
102 isl6405->config |= ISL6405_LLC1;
103 else
104 isl6405->config &= ~ISL6405_LLC1;
105 }
106 isl6405->config |= isl6405->override_or;
107 isl6405->config &= isl6405->override_and;
108
109 return (i2c_transfer(isl6405->i2c, &msg, 1) == 1) ? 0 : -EIO;
110}
111
112static void isl6405_release(struct dvb_frontend *fe)
113{
114 /* power off */
115 isl6405_set_voltage(fe, SEC_VOLTAGE_OFF);
116
117 /* free */
118 kfree(fe->sec_priv);
119 fe->sec_priv = NULL;
120}
121
122struct dvb_frontend *isl6405_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c,
123 u8 i2c_addr, u8 override_set, u8 override_clear)
124{
125 struct isl6405 *isl6405 = kmalloc(sizeof(struct isl6405), GFP_KERNEL);
126 if (!isl6405)
127 return NULL;
128
129 /* default configuration */
130 if (override_set & 0x80)
131 isl6405->config = ISL6405_ISEL2;
132 else
133 isl6405->config = ISL6405_ISEL1;
134 isl6405->i2c = i2c;
135 isl6405->i2c_addr = i2c_addr;
136 fe->sec_priv = isl6405;
137
138 /* bits which should be forced to '1' */
139 isl6405->override_or = override_set;
140
141 /* bits which should be forced to '0' */
142 isl6405->override_and = ~override_clear;
143
144 /* detect if it is present or not */
145 if (isl6405_set_voltage(fe, SEC_VOLTAGE_OFF)) {
146 kfree(isl6405);
147 fe->sec_priv = NULL;
148 return NULL;
149 }
150
151 /* install release callback */
152 fe->ops.release_sec = isl6405_release;
153
154 /* override frontend ops */
155 fe->ops.set_voltage = isl6405_set_voltage;
156 fe->ops.enable_high_lnb_voltage = isl6405_enable_high_lnb_voltage;
157
158 return fe;
159}
160EXPORT_SYMBOL(isl6405_attach);
161
162MODULE_DESCRIPTION("Driver for lnb supply and control ic isl6405");
163MODULE_AUTHOR("Hartmut Hackmann & Oliver Endriss");
164MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/isl6405.h b/drivers/media/dvb/frontends/isl6405.h
new file mode 100644
index 000000000000..1c793d37576b
--- /dev/null
+++ b/drivers/media/dvb/frontends/isl6405.h
@@ -0,0 +1,74 @@
1/*
2 * isl6405.h - driver for dual lnb supply and control ic ISL6405
3 *
4 * Copyright (C) 2008 Hartmut Hackmann
5 * Copyright (C) 2006 Oliver Endriss
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
23 *
24 *
25 * the project's page is at http://www.linuxtv.org
26 */
27
28#ifndef _ISL6405_H
29#define _ISL6405_H
30
31#include <linux/dvb/frontend.h>
32
33/* system register bits */
34
35/* this bit selects register (control) 1 or 2
36 note that the bit maps are different */
37
38#define ISL6405_SR 0x80
39
40/* SR = 0 */
41#define ISL6405_OLF1 0x01
42#define ISL6405_EN1 0x02
43#define ISL6405_VSEL1 0x04
44#define ISL6405_LLC1 0x08
45#define ISL6405_ENT1 0x10
46#define ISL6405_ISEL1 0x20
47#define ISL6405_DCL 0x40
48
49/* SR = 1 */
50#define ISL6405_OLF2 0x01
51#define ISL6405_OTF 0x02
52#define ISL6405_EN2 0x04
53#define ISL6405_VSEL2 0x08
54#define ISL6405_LLC2 0x10
55#define ISL6405_ENT2 0x20
56#define ISL6405_ISEL2 0x40
57
58#if defined(CONFIG_DVB_ISL6405) || (defined(CONFIG_DVB_ISL6405_MODULE) && defined(MODULE))
59/* override_set and override_clear control which system register bits (above)
60 * to always set & clear
61 */
62extern struct dvb_frontend *isl6405_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c,
63 u8 i2c_addr, u8 override_set, u8 override_clear);
64#else
65static inline struct dvb_frontend *isl6405_attach(struct dvb_frontend *fe,
66 struct i2c_adapter *i2c, u8 i2c_addr,
67 u8 override_set, u8 override_clear)
68{
69 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
70 return NULL;
71}
72#endif /* CONFIG_DVB_ISL6405 */
73
74#endif
diff --git a/drivers/media/dvb/frontends/isl6421.h b/drivers/media/dvb/frontends/isl6421.h
index ea7f78a7d3cd..47e4518a042d 100644
--- a/drivers/media/dvb/frontends/isl6421.h
+++ b/drivers/media/dvb/frontends/isl6421.h
@@ -47,7 +47,7 @@ extern struct dvb_frontend *isl6421_attach(struct dvb_frontend *fe, struct i2c_a
47static inline struct dvb_frontend *isl6421_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 i2c_addr, 47static inline struct dvb_frontend *isl6421_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 i2c_addr,
48 u8 override_set, u8 override_clear) 48 u8 override_set, u8 override_clear)
49{ 49{
50 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 50 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
51 return NULL; 51 return NULL;
52} 52}
53#endif // CONFIG_DVB_ISL6421 53#endif // CONFIG_DVB_ISL6421
diff --git a/drivers/media/dvb/frontends/itd1000.c b/drivers/media/dvb/frontends/itd1000.c
new file mode 100644
index 000000000000..04c562ccf990
--- /dev/null
+++ b/drivers/media/dvb/frontends/itd1000.c
@@ -0,0 +1,400 @@
1/*
2 * Driver for the Integrant ITD1000 "Zero-IF Tuner IC for Direct Broadcast Satellite"
3 *
4 * Copyright (c) 2007-8 Patrick Boettcher <pb@linuxtv.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=
20 */
21
22#include <linux/module.h>
23#include <linux/moduleparam.h>
24#include <linux/delay.h>
25#include <linux/dvb/frontend.h>
26#include <linux/i2c.h>
27
28#include "dvb_frontend.h"
29
30#include "itd1000.h"
31#include "itd1000_priv.h"
32
33static int debug;
34module_param(debug, int, 0644);
35MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
36
37#define deb(args...) do { \
38 if (debug) { \
39 printk(KERN_DEBUG "ITD1000: " args);\
40 printk("\n"); \
41 } \
42} while (0)
43
44#define warn(args...) do { \
45 printk(KERN_WARNING "ITD1000: " args); \
46 printk("\n"); \
47} while (0)
48
49#define info(args...) do { \
50 printk(KERN_INFO "ITD1000: " args); \
51 printk("\n"); \
52} while (0)
53
54/* don't write more than one byte with flexcop behind */
55static int itd1000_write_regs(struct itd1000_state *state, u8 reg, u8 v[], u8 len)
56{
57 u8 buf[1+len];
58 struct i2c_msg msg = {
59 .addr = state->cfg->i2c_address, .flags = 0, .buf = buf, .len = len+1
60 };
61 buf[0] = reg;
62 memcpy(&buf[1], v, len);
63
64 /* deb("wr %02x: %02x", reg, v[0]); */
65
66 if (i2c_transfer(state->i2c, &msg, 1) != 1) {
67 printk(KERN_WARNING "itd1000 I2C write failed\n");
68 return -EREMOTEIO;
69 }
70 return 0;
71}
72
73static int itd1000_read_reg(struct itd1000_state *state, u8 reg)
74{
75 u8 val;
76 struct i2c_msg msg[2] = {
77 { .addr = state->cfg->i2c_address, .flags = 0, .buf = &reg, .len = 1 },
78 { .addr = state->cfg->i2c_address, .flags = I2C_M_RD, .buf = &val, .len = 1 },
79 };
80
81 /* ugly flexcop workaround */
82 itd1000_write_regs(state, (reg - 1) & 0xff, &state->shadow[(reg - 1) & 0xff], 1);
83
84 if (i2c_transfer(state->i2c, msg, 2) != 2) {
85 warn("itd1000 I2C read failed");
86 return -EREMOTEIO;
87 }
88 return val;
89}
90
91static inline int itd1000_write_reg(struct itd1000_state *state, u8 r, u8 v)
92{
93 int ret = itd1000_write_regs(state, r, &v, 1);
94 state->shadow[r] = v;
95 return ret;
96}
97
98
99static struct {
100 u32 symbol_rate;
101 u8 pgaext : 4; /* PLLFH */
102 u8 bbgvmin : 4; /* BBGVMIN */
103} itd1000_lpf_pga[] = {
104 { 0, 0x8, 0x3 },
105 { 5200000, 0x8, 0x3 },
106 { 12200000, 0x4, 0x3 },
107 { 15400000, 0x2, 0x3 },
108 { 19800000, 0x2, 0x3 },
109 { 21500000, 0x2, 0x3 },
110 { 24500000, 0x2, 0x3 },
111 { 28400000, 0x2, 0x3 },
112 { 33400000, 0x2, 0x3 },
113 { 34400000, 0x1, 0x4 },
114 { 34400000, 0x1, 0x4 },
115 { 38400000, 0x1, 0x4 },
116 { 38400000, 0x1, 0x4 },
117 { 40400000, 0x1, 0x4 },
118 { 45400000, 0x1, 0x4 },
119};
120
121static void itd1000_set_lpf_bw(struct itd1000_state *state, u32 symbol_rate)
122{
123 u8 i;
124 u8 con1 = itd1000_read_reg(state, CON1) & 0xfd;
125 u8 pllfh = itd1000_read_reg(state, PLLFH) & 0x0f;
126 u8 bbgvmin = itd1000_read_reg(state, BBGVMIN) & 0xf0;
127 u8 bw = itd1000_read_reg(state, BW) & 0xf0;
128
129 deb("symbol_rate = %d", symbol_rate);
130
131 /* not sure what is that ? - starting to download the table */
132 itd1000_write_reg(state, CON1, con1 | (1 << 1));
133
134 for (i = 0; i < ARRAY_SIZE(itd1000_lpf_pga); i++)
135 if (symbol_rate < itd1000_lpf_pga[i].symbol_rate) {
136 deb("symrate: index: %d pgaext: %x, bbgvmin: %x", i, itd1000_lpf_pga[i].pgaext, itd1000_lpf_pga[i].bbgvmin);
137 itd1000_write_reg(state, PLLFH, pllfh | (itd1000_lpf_pga[i].pgaext << 4));
138 itd1000_write_reg(state, BBGVMIN, bbgvmin | (itd1000_lpf_pga[i].bbgvmin));
139 itd1000_write_reg(state, BW, bw | (i & 0x0f));
140 break;
141 }
142
143 itd1000_write_reg(state, CON1, con1 | (0 << 1));
144}
145
146static struct {
147 u8 vcorg;
148 u32 fmax_rg;
149} itd1000_vcorg[] = {
150 { 1, 920000 },
151 { 2, 971000 },
152 { 3, 1031000 },
153 { 4, 1091000 },
154 { 5, 1171000 },
155 { 6, 1281000 },
156 { 7, 1381000 },
157 { 8, 500000 }, /* this is intentional. */
158 { 9, 1451000 },
159 { 10, 1531000 },
160 { 11, 1631000 },
161 { 12, 1741000 },
162 { 13, 1891000 },
163 { 14, 2071000 },
164 { 15, 2250000 },
165};
166
167static void itd1000_set_vco(struct itd1000_state *state, u32 freq_khz)
168{
169 u8 i;
170 u8 gvbb_i2c = itd1000_read_reg(state, GVBB_I2C) & 0xbf;
171 u8 vco_chp1_i2c = itd1000_read_reg(state, VCO_CHP1_I2C) & 0x0f;
172 u8 adcout;
173
174 /* reserved bit again (reset ?) */
175 itd1000_write_reg(state, GVBB_I2C, gvbb_i2c | (1 << 6));
176
177 for (i = 0; i < ARRAY_SIZE(itd1000_vcorg); i++) {
178 if (freq_khz < itd1000_vcorg[i].fmax_rg) {
179 itd1000_write_reg(state, VCO_CHP1_I2C, vco_chp1_i2c | (itd1000_vcorg[i].vcorg << 4));
180 msleep(1);
181
182 adcout = itd1000_read_reg(state, PLLLOCK) & 0x0f;
183
184 deb("VCO: %dkHz: %d -> ADCOUT: %d %02x", freq_khz, itd1000_vcorg[i].vcorg, adcout, vco_chp1_i2c);
185
186 if (adcout > 13) {
187 if (!(itd1000_vcorg[i].vcorg == 7 || itd1000_vcorg[i].vcorg == 15))
188 itd1000_write_reg(state, VCO_CHP1_I2C, vco_chp1_i2c | ((itd1000_vcorg[i].vcorg + 1) << 4));
189 } else if (adcout < 2) {
190 if (!(itd1000_vcorg[i].vcorg == 1 || itd1000_vcorg[i].vcorg == 9))
191 itd1000_write_reg(state, VCO_CHP1_I2C, vco_chp1_i2c | ((itd1000_vcorg[i].vcorg - 1) << 4));
192 }
193 break;
194 }
195 }
196}
197
198struct {
199 u32 freq;
200 u8 values[10]; /* RFTR, RFST1 - RFST9 */
201} itd1000_fre_values[] = {
202 { 1075000, { 0x59, 0x1d, 0x1c, 0x17, 0x16, 0x0f, 0x0e, 0x0c, 0x0b, 0x0a } },
203 { 1250000, { 0x89, 0x1e, 0x1d, 0x17, 0x15, 0x0f, 0x0e, 0x0c, 0x0b, 0x0a } },
204 { 1450000, { 0x89, 0x1e, 0x1d, 0x17, 0x15, 0x0f, 0x0e, 0x0c, 0x0b, 0x0a } },
205 { 1650000, { 0x69, 0x1e, 0x1d, 0x17, 0x15, 0x0f, 0x0e, 0x0c, 0x0b, 0x0a } },
206 { 1750000, { 0x69, 0x1e, 0x17, 0x15, 0x14, 0x0f, 0x0e, 0x0c, 0x0b, 0x0a } },
207 { 1850000, { 0x69, 0x1d, 0x17, 0x16, 0x14, 0x0f, 0x0e, 0x0d, 0x0b, 0x0a } },
208 { 1900000, { 0x69, 0x1d, 0x17, 0x15, 0x14, 0x0f, 0x0e, 0x0d, 0x0b, 0x0a } },
209 { 1950000, { 0x69, 0x1d, 0x17, 0x16, 0x14, 0x13, 0x0e, 0x0d, 0x0b, 0x0a } },
210 { 2050000, { 0x69, 0x1e, 0x1d, 0x17, 0x16, 0x14, 0x13, 0x0e, 0x0b, 0x0a } },
211 { 2150000, { 0x69, 0x1d, 0x1c, 0x17, 0x15, 0x14, 0x13, 0x0f, 0x0e, 0x0b } }
212};
213
214
215#define FREF 16
216
217static void itd1000_set_lo(struct itd1000_state *state, u32 freq_khz)
218{
219 int i, j;
220 u32 plln, pllf;
221 u64 tmp;
222
223 plln = (freq_khz * 1000) / 2 / FREF;
224
225 /* Compute the factional part times 1000 */
226 tmp = plln % 1000000;
227 plln /= 1000000;
228
229 tmp *= 1048576;
230 do_div(tmp, 1000000);
231 pllf = (u32) tmp;
232
233 state->frequency = ((plln * 1000) + (pllf * 1000)/1048576) * 2*FREF;
234 deb("frequency: %dkHz (wanted) %dkHz (set), PLLF = %d, PLLN = %d", freq_khz, state->frequency, pllf, plln);
235
236 itd1000_write_reg(state, PLLNH, 0x80); /* PLLNH */;
237 itd1000_write_reg(state, PLLNL, plln & 0xff);
238 itd1000_write_reg(state, PLLFH, (itd1000_read_reg(state, PLLFH) & 0xf0) | ((pllf >> 16) & 0x0f));
239 itd1000_write_reg(state, PLLFM, (pllf >> 8) & 0xff);
240 itd1000_write_reg(state, PLLFL, (pllf >> 0) & 0xff);
241
242 for (i = 0; i < ARRAY_SIZE(itd1000_fre_values); i++) {
243 if (freq_khz <= itd1000_fre_values[i].freq) {
244 deb("fre_values: %d", i);
245 itd1000_write_reg(state, RFTR, itd1000_fre_values[i].values[0]);
246 for (j = 0; j < 9; j++)
247 itd1000_write_reg(state, RFST1+j, itd1000_fre_values[i].values[j+1]);
248 break;
249 }
250 }
251
252 itd1000_set_vco(state, freq_khz);
253}
254
255static int itd1000_set_parameters(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
256{
257 struct itd1000_state *state = fe->tuner_priv;
258 u8 pllcon1;
259
260 itd1000_set_lo(state, p->frequency);
261 itd1000_set_lpf_bw(state, p->u.qpsk.symbol_rate);
262
263 pllcon1 = itd1000_read_reg(state, PLLCON1) & 0x7f;
264 itd1000_write_reg(state, PLLCON1, pllcon1 | (1 << 7));
265 itd1000_write_reg(state, PLLCON1, pllcon1);
266
267 return 0;
268}
269
270static int itd1000_get_frequency(struct dvb_frontend *fe, u32 *frequency)
271{
272 struct itd1000_state *state = fe->tuner_priv;
273 *frequency = state->frequency;
274 return 0;
275}
276
277static int itd1000_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
278{
279 return 0;
280}
281
282static u8 itd1000_init_tab[][2] = {
283 { PLLCON1, 0x65 }, /* Register does not change */
284 { PLLNH, 0x80 }, /* Bits [7:6] do not change */
285 { RESERVED_0X6D, 0x3b },
286 { VCO_CHP2_I2C, 0x12 },
287 { 0x72, 0xf9 }, /* No such regsister defined */
288 { RESERVED_0X73, 0xff },
289 { RESERVED_0X74, 0xb2 },
290 { RESERVED_0X75, 0xc7 },
291 { EXTGVBBRF, 0xf0 },
292 { DIVAGCCK, 0x80 },
293 { BBTR, 0xa0 },
294 { RESERVED_0X7E, 0x4f },
295 { 0x82, 0x88 }, /* No such regsister defined */
296 { 0x83, 0x80 }, /* No such regsister defined */
297 { 0x84, 0x80 }, /* No such regsister defined */
298 { RESERVED_0X85, 0x74 },
299 { RESERVED_0X86, 0xff },
300 { RESERVED_0X88, 0x02 },
301 { RESERVED_0X89, 0x16 },
302 { RFST0, 0x1f },
303 { RESERVED_0X94, 0x66 },
304 { RESERVED_0X95, 0x66 },
305 { RESERVED_0X96, 0x77 },
306 { RESERVED_0X97, 0x99 },
307 { RESERVED_0X98, 0xff },
308 { RESERVED_0X99, 0xfc },
309 { RESERVED_0X9A, 0xba },
310 { RESERVED_0X9B, 0xaa },
311};
312
313static u8 itd1000_reinit_tab[][2] = {
314 { VCO_CHP1_I2C, 0x8a },
315 { BW, 0x87 },
316 { GVBB_I2C, 0x03 },
317 { BBGVMIN, 0x03 },
318 { CON1, 0x2e },
319};
320
321
322static int itd1000_init(struct dvb_frontend *fe)
323{
324 struct itd1000_state *state = fe->tuner_priv;
325 int i;
326
327 for (i = 0; i < ARRAY_SIZE(itd1000_init_tab); i++)
328 itd1000_write_reg(state, itd1000_init_tab[i][0], itd1000_init_tab[i][1]);
329
330 for (i = 0; i < ARRAY_SIZE(itd1000_reinit_tab); i++)
331 itd1000_write_reg(state, itd1000_reinit_tab[i][0], itd1000_reinit_tab[i][1]);
332
333 return 0;
334}
335
336static int itd1000_sleep(struct dvb_frontend *fe)
337{
338 return 0;
339}
340
341static int itd1000_release(struct dvb_frontend *fe)
342{
343 kfree(fe->tuner_priv);
344 fe->tuner_priv = NULL;
345 return 0;
346}
347
348static const struct dvb_tuner_ops itd1000_tuner_ops = {
349 .info = {
350 .name = "Integrant ITD1000",
351 .frequency_min = 950000,
352 .frequency_max = 2150000,
353 .frequency_step = 125, /* kHz for QPSK frontends */
354 },
355
356 .release = itd1000_release,
357
358 .init = itd1000_init,
359 .sleep = itd1000_sleep,
360
361 .set_params = itd1000_set_parameters,
362 .get_frequency = itd1000_get_frequency,
363 .get_bandwidth = itd1000_get_bandwidth
364};
365
366
367struct dvb_frontend *itd1000_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct itd1000_config *cfg)
368{
369 struct itd1000_state *state = NULL;
370 u8 i = 0;
371
372 state = kzalloc(sizeof(struct itd1000_state), GFP_KERNEL);
373 if (state == NULL)
374 return NULL;
375
376 state->cfg = cfg;
377 state->i2c = i2c;
378
379 i = itd1000_read_reg(state, 0);
380 if (i != 0) {
381 kfree(state);
382 return NULL;
383 }
384 info("successfully identified (ID: %d)", i);
385
386 memset(state->shadow, 0xff, sizeof(state->shadow));
387 for (i = 0x65; i < 0x9c; i++)
388 state->shadow[i] = itd1000_read_reg(state, i);
389
390 memcpy(&fe->ops.tuner_ops, &itd1000_tuner_ops, sizeof(struct dvb_tuner_ops));
391
392 fe->tuner_priv = state;
393
394 return fe;
395}
396EXPORT_SYMBOL(itd1000_attach);
397
398MODULE_AUTHOR("Patrick Boettcher <pb@linuxtv.org>");
399MODULE_DESCRIPTION("Integrant ITD1000 driver");
400MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/itd1000.h b/drivers/media/dvb/frontends/itd1000.h
new file mode 100644
index 000000000000..5e18df071b88
--- /dev/null
+++ b/drivers/media/dvb/frontends/itd1000.h
@@ -0,0 +1,42 @@
1/*
2 * Driver for the Integrant ITD1000 "Zero-IF Tuner IC for Direct Broadcast Satellite"
3 *
4 * Copyright (c) 2007 Patrick Boettcher <pb@linuxtv.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=
20 */
21
22#ifndef ITD1000_H
23#define ITD1000_H
24
25struct dvb_frontend;
26struct i2c_adapter;
27
28struct itd1000_config {
29 u8 i2c_address;
30};
31
32#if defined(CONFIG_DVB_TUNER_ITD1000) || (defined(CONFIG_DVB_TUNER_ITD1000_MODULE) && defined(MODULE))
33extern struct dvb_frontend *itd1000_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct itd1000_config *cfg);
34#else
35static inline struct dvb_frontend *itd1000_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct itd1000_config *cfg)
36{
37 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
38 return NULL;
39}
40#endif
41
42#endif
diff --git a/drivers/media/dvb/frontends/itd1000_priv.h b/drivers/media/dvb/frontends/itd1000_priv.h
new file mode 100644
index 000000000000..8cdc54e57903
--- /dev/null
+++ b/drivers/media/dvb/frontends/itd1000_priv.h
@@ -0,0 +1,88 @@
1/*
2 * Driver for the Integrant ITD1000 "Zero-IF Tuner IC for Direct Broadcast Satellite"
3 *
4 * Copyright (c) 2007 Patrick Boettcher <pb@linuxtv.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.=
20 */
21
22#ifndef ITD1000_PRIV_H
23#define ITD1000_PRIV_H
24
25struct itd1000_state {
26 struct itd1000_config *cfg;
27 struct i2c_adapter *i2c;
28
29 u32 frequency; /* contains the value resulting from the LO-setting */
30
31 /* ugly workaround for flexcop's incapable i2c-controller
32 * FIXME, if possible
33 */
34 u8 shadow[255];
35};
36
37enum itd1000_register {
38 VCO_CHP1 = 0x65,
39 VCO_CHP2,
40 PLLCON1,
41 PLLNH,
42 PLLNL,
43 PLLFH,
44 PLLFM,
45 PLLFL,
46 RESERVED_0X6D,
47 PLLLOCK,
48 VCO_CHP2_I2C,
49 VCO_CHP1_I2C,
50 BW,
51 RESERVED_0X73 = 0x73,
52 RESERVED_0X74,
53 RESERVED_0X75,
54 GVBB,
55 GVRF,
56 GVBB_I2C,
57 EXTGVBBRF,
58 DIVAGCCK,
59 BBTR,
60 RFTR,
61 BBGVMIN,
62 RESERVED_0X7E,
63 RESERVED_0X85 = 0x85,
64 RESERVED_0X86,
65 CON1,
66 RESERVED_0X88,
67 RESERVED_0X89,
68 RFST0,
69 RFST1,
70 RFST2,
71 RFST3,
72 RFST4,
73 RFST5,
74 RFST6,
75 RFST7,
76 RFST8,
77 RFST9,
78 RESERVED_0X94,
79 RESERVED_0X95,
80 RESERVED_0X96,
81 RESERVED_0X97,
82 RESERVED_0X98,
83 RESERVED_0X99,
84 RESERVED_0X9A,
85 RESERVED_0X9B,
86};
87
88#endif
diff --git a/drivers/media/dvb/frontends/l64781.c b/drivers/media/dvb/frontends/l64781.c
index 443d9045d4c9..e1e70e9e0cb9 100644
--- a/drivers/media/dvb/frontends/l64781.c
+++ b/drivers/media/dvb/frontends/l64781.c
@@ -57,7 +57,7 @@ static int l64781_writereg (struct l64781_state* state, u8 reg, u8 data)
57 57
58 if ((ret = i2c_transfer(state->i2c, &msg, 1)) != 1) 58 if ((ret = i2c_transfer(state->i2c, &msg, 1)) != 1)
59 dprintk ("%s: write_reg error (reg == %02x) = %02x!\n", 59 dprintk ("%s: write_reg error (reg == %02x) = %02x!\n",
60 __FUNCTION__, reg, ret); 60 __func__, reg, ret);
61 61
62 return (ret != 1) ? -1 : 0; 62 return (ret != 1) ? -1 : 0;
63} 63}
diff --git a/drivers/media/dvb/frontends/l64781.h b/drivers/media/dvb/frontends/l64781.h
index cd15f76ff28d..1305a9e7fb0b 100644
--- a/drivers/media/dvb/frontends/l64781.h
+++ b/drivers/media/dvb/frontends/l64781.h
@@ -38,7 +38,7 @@ extern struct dvb_frontend* l64781_attach(const struct l64781_config* config,
38static inline struct dvb_frontend* l64781_attach(const struct l64781_config* config, 38static inline struct dvb_frontend* l64781_attach(const struct l64781_config* config,
39 struct i2c_adapter* i2c) 39 struct i2c_adapter* i2c)
40{ 40{
41 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 41 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
42 return NULL; 42 return NULL;
43} 43}
44#endif // CONFIG_DVB_L64781 44#endif // CONFIG_DVB_L64781
diff --git a/drivers/media/dvb/frontends/lgdt330x.c b/drivers/media/dvb/frontends/lgdt330x.c
index bdc9fa88b86a..f0195c8272f4 100644
--- a/drivers/media/dvb/frontends/lgdt330x.c
+++ b/drivers/media/dvb/frontends/lgdt330x.c
@@ -49,7 +49,7 @@
49/* Use Equalizer Mean Squared Error instead of Phaser Tracker MSE */ 49/* Use Equalizer Mean Squared Error instead of Phaser Tracker MSE */
50/* #define USE_EQMSE */ 50/* #define USE_EQMSE */
51 51
52static int debug = 0; 52static int debug;
53module_param(debug, int, 0644); 53module_param(debug, int, 0644);
54MODULE_PARM_DESC(debug,"Turn on/off lgdt330x frontend debugging (default:off)."); 54MODULE_PARM_DESC(debug,"Turn on/off lgdt330x frontend debugging (default:off).");
55#define dprintk(args...) \ 55#define dprintk(args...) \
@@ -88,7 +88,7 @@ static int i2c_write_demod_bytes (struct lgdt330x_state* state,
88 88
89 for (i=0; i<len-1; i+=2){ 89 for (i=0; i<len-1; i+=2){
90 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) { 90 if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) {
91 printk(KERN_WARNING "lgdt330x: %s error (addr %02x <- %02x, err = %i)\n", __FUNCTION__, msg.buf[0], msg.buf[1], err); 91 printk(KERN_WARNING "lgdt330x: %s error (addr %02x <- %02x, err = %i)\n", __func__, msg.buf[0], msg.buf[1], err);
92 if (err < 0) 92 if (err < 0)
93 return err; 93 return err;
94 else 94 else
@@ -117,7 +117,7 @@ static u8 i2c_read_demod_bytes (struct lgdt330x_state* state,
117 int ret; 117 int ret;
118 ret = i2c_transfer(state->i2c, msg, 2); 118 ret = i2c_transfer(state->i2c, msg, 2);
119 if (ret != 2) { 119 if (ret != 2) {
120 printk(KERN_WARNING "lgdt330x: %s: addr 0x%02x select 0x%02x error (ret == %i)\n", __FUNCTION__, state->config->demod_address, reg, ret); 120 printk(KERN_WARNING "lgdt330x: %s: addr 0x%02x select 0x%02x error (ret == %i)\n", __func__, state->config->demod_address, reg, ret);
121 } else { 121 } else {
122 ret = 0; 122 ret = 0;
123 } 123 }
@@ -256,7 +256,7 @@ static int lgdt330x_init(struct dvb_frontend* fe)
256 printk (KERN_WARNING "Only LGDT3302 and LGDT3303 are supported chips.\n"); 256 printk (KERN_WARNING "Only LGDT3302 and LGDT3303 are supported chips.\n");
257 err = -ENODEV; 257 err = -ENODEV;
258 } 258 }
259 dprintk("%s entered as %s\n", __FUNCTION__, chip_name); 259 dprintk("%s entered as %s\n", __func__, chip_name);
260 if (err < 0) 260 if (err < 0)
261 return err; 261 return err;
262 return lgdt330x_SwReset(state); 262 return lgdt330x_SwReset(state);
@@ -334,7 +334,7 @@ static int lgdt330x_set_parameters(struct dvb_frontend* fe,
334 if (state->current_modulation != param->u.vsb.modulation) { 334 if (state->current_modulation != param->u.vsb.modulation) {
335 switch(param->u.vsb.modulation) { 335 switch(param->u.vsb.modulation) {
336 case VSB_8: 336 case VSB_8:
337 dprintk("%s: VSB_8 MODE\n", __FUNCTION__); 337 dprintk("%s: VSB_8 MODE\n", __func__);
338 338
339 /* Select VSB mode */ 339 /* Select VSB mode */
340 top_ctrl_cfg[1] = 0x03; 340 top_ctrl_cfg[1] = 0x03;
@@ -350,7 +350,7 @@ static int lgdt330x_set_parameters(struct dvb_frontend* fe,
350 break; 350 break;
351 351
352 case QAM_64: 352 case QAM_64:
353 dprintk("%s: QAM_64 MODE\n", __FUNCTION__); 353 dprintk("%s: QAM_64 MODE\n", __func__);
354 354
355 /* Select QAM_64 mode */ 355 /* Select QAM_64 mode */
356 top_ctrl_cfg[1] = 0x00; 356 top_ctrl_cfg[1] = 0x00;
@@ -366,7 +366,7 @@ static int lgdt330x_set_parameters(struct dvb_frontend* fe,
366 break; 366 break;
367 367
368 case QAM_256: 368 case QAM_256:
369 dprintk("%s: QAM_256 MODE\n", __FUNCTION__); 369 dprintk("%s: QAM_256 MODE\n", __func__);
370 370
371 /* Select QAM_256 mode */ 371 /* Select QAM_256 mode */
372 top_ctrl_cfg[1] = 0x01; 372 top_ctrl_cfg[1] = 0x01;
@@ -381,7 +381,7 @@ static int lgdt330x_set_parameters(struct dvb_frontend* fe,
381 } 381 }
382 break; 382 break;
383 default: 383 default:
384 printk(KERN_WARNING "lgdt330x: %s: Modulation type(%d) UNSUPPORTED\n", __FUNCTION__, param->u.vsb.modulation); 384 printk(KERN_WARNING "lgdt330x: %s: Modulation type(%d) UNSUPPORTED\n", __func__, param->u.vsb.modulation);
385 return -1; 385 return -1;
386 } 386 }
387 /* 387 /*
@@ -431,7 +431,7 @@ static int lgdt3302_read_status(struct dvb_frontend* fe, fe_status_t* status)
431 431
432 /* AGC status register */ 432 /* AGC status register */
433 i2c_read_demod_bytes(state, AGC_STATUS, buf, 1); 433 i2c_read_demod_bytes(state, AGC_STATUS, buf, 1);
434 dprintk("%s: AGC_STATUS = 0x%02x\n", __FUNCTION__, buf[0]); 434 dprintk("%s: AGC_STATUS = 0x%02x\n", __func__, buf[0]);
435 if ((buf[0] & 0x0c) == 0x8){ 435 if ((buf[0] & 0x0c) == 0x8){
436 /* Test signal does not exist flag */ 436 /* Test signal does not exist flag */
437 /* as well as the AGC lock flag. */ 437 /* as well as the AGC lock flag. */
@@ -445,7 +445,7 @@ static int lgdt3302_read_status(struct dvb_frontend* fe, fe_status_t* status)
445 */ 445 */
446 /* signal status */ 446 /* signal status */
447 i2c_read_demod_bytes(state, TOP_CONTROL, buf, sizeof(buf)); 447 i2c_read_demod_bytes(state, TOP_CONTROL, buf, sizeof(buf));
448 dprintk("%s: TOP_CONTROL = 0x%02x, IRO_MASK = 0x%02x, IRQ_STATUS = 0x%02x\n", __FUNCTION__, buf[0], buf[1], buf[2]); 448 dprintk("%s: TOP_CONTROL = 0x%02x, IRO_MASK = 0x%02x, IRQ_STATUS = 0x%02x\n", __func__, buf[0], buf[1], buf[2]);
449 449
450 450
451 /* sync status */ 451 /* sync status */
@@ -461,7 +461,7 @@ static int lgdt3302_read_status(struct dvb_frontend* fe, fe_status_t* status)
461 461
462 /* Carrier Recovery Lock Status Register */ 462 /* Carrier Recovery Lock Status Register */
463 i2c_read_demod_bytes(state, CARRIER_LOCK, buf, 1); 463 i2c_read_demod_bytes(state, CARRIER_LOCK, buf, 1);
464 dprintk("%s: CARRIER_LOCK = 0x%02x\n", __FUNCTION__, buf[0]); 464 dprintk("%s: CARRIER_LOCK = 0x%02x\n", __func__, buf[0]);
465 switch (state->current_modulation) { 465 switch (state->current_modulation) {
466 case QAM_256: 466 case QAM_256:
467 case QAM_64: 467 case QAM_64:
@@ -474,7 +474,7 @@ static int lgdt3302_read_status(struct dvb_frontend* fe, fe_status_t* status)
474 *status |= FE_HAS_CARRIER; 474 *status |= FE_HAS_CARRIER;
475 break; 475 break;
476 default: 476 default:
477 printk(KERN_WARNING "lgdt330x: %s: Modulation set to unsupported value\n", __FUNCTION__); 477 printk(KERN_WARNING "lgdt330x: %s: Modulation set to unsupported value\n", __func__);
478 } 478 }
479 479
480 return 0; 480 return 0;
@@ -493,7 +493,7 @@ static int lgdt3303_read_status(struct dvb_frontend* fe, fe_status_t* status)
493 if (err < 0) 493 if (err < 0)
494 return err; 494 return err;
495 495
496 dprintk("%s: AGC_STATUS = 0x%02x\n", __FUNCTION__, buf[0]); 496 dprintk("%s: AGC_STATUS = 0x%02x\n", __func__, buf[0]);
497 if ((buf[0] & 0x21) == 0x01){ 497 if ((buf[0] & 0x21) == 0x01){
498 /* Test input signal does not exist flag */ 498 /* Test input signal does not exist flag */
499 /* as well as the AGC lock flag. */ 499 /* as well as the AGC lock flag. */
@@ -502,7 +502,7 @@ static int lgdt3303_read_status(struct dvb_frontend* fe, fe_status_t* status)
502 502
503 /* Carrier Recovery Lock Status Register */ 503 /* Carrier Recovery Lock Status Register */
504 i2c_read_demod_bytes(state, CARRIER_LOCK, buf, 1); 504 i2c_read_demod_bytes(state, CARRIER_LOCK, buf, 1);
505 dprintk("%s: CARRIER_LOCK = 0x%02x\n", __FUNCTION__, buf[0]); 505 dprintk("%s: CARRIER_LOCK = 0x%02x\n", __func__, buf[0]);
506 switch (state->current_modulation) { 506 switch (state->current_modulation) {
507 case QAM_256: 507 case QAM_256:
508 case QAM_64: 508 case QAM_64:
@@ -533,7 +533,7 @@ static int lgdt3303_read_status(struct dvb_frontend* fe, fe_status_t* status)
533 } 533 }
534 break; 534 break;
535 default: 535 default:
536 printk(KERN_WARNING "lgdt330x: %s: Modulation set to unsupported value\n", __FUNCTION__); 536 printk(KERN_WARNING "lgdt330x: %s: Modulation set to unsupported value\n", __func__);
537 } 537 }
538 return 0; 538 return 0;
539} 539}
@@ -607,14 +607,14 @@ static int lgdt3302_read_snr(struct dvb_frontend* fe, u16* snr)
607 break; 607 break;
608 default: 608 default:
609 printk(KERN_ERR "lgdt330x: %s: Modulation set to unsupported value\n", 609 printk(KERN_ERR "lgdt330x: %s: Modulation set to unsupported value\n",
610 __FUNCTION__); 610 __func__);
611 return -EREMOTEIO; /* return -EDRIVER_IS_GIBBERED; */ 611 return -EREMOTEIO; /* return -EDRIVER_IS_GIBBERED; */
612 } 612 }
613 613
614 state->snr = calculate_snr(noise, c); 614 state->snr = calculate_snr(noise, c);
615 *snr = (state->snr) >> 16; /* Convert from 8.24 fixed-point to 8.8 */ 615 *snr = (state->snr) >> 16; /* Convert from 8.24 fixed-point to 8.8 */
616 616
617 dprintk("%s: noise = 0x%08x, snr = %d.%02d dB\n", __FUNCTION__, noise, 617 dprintk("%s: noise = 0x%08x, snr = %d.%02d dB\n", __func__, noise,
618 state->snr >> 24, (((state->snr>>8) & 0xffff) * 100) >> 16); 618 state->snr >> 24, (((state->snr>>8) & 0xffff) * 100) >> 16);
619 619
620 return 0; 620 return 0;
@@ -651,14 +651,14 @@ static int lgdt3303_read_snr(struct dvb_frontend* fe, u16* snr)
651 break; 651 break;
652 default: 652 default:
653 printk(KERN_ERR "lgdt330x: %s: Modulation set to unsupported value\n", 653 printk(KERN_ERR "lgdt330x: %s: Modulation set to unsupported value\n",
654 __FUNCTION__); 654 __func__);
655 return -EREMOTEIO; /* return -EDRIVER_IS_GIBBERED; */ 655 return -EREMOTEIO; /* return -EDRIVER_IS_GIBBERED; */
656 } 656 }
657 657
658 state->snr = calculate_snr(noise, c); 658 state->snr = calculate_snr(noise, c);
659 *snr = (state->snr) >> 16; /* Convert from 8.24 fixed-point to 8.8 */ 659 *snr = (state->snr) >> 16; /* Convert from 8.24 fixed-point to 8.8 */
660 660
661 dprintk("%s: noise = 0x%08x, snr = %d.%02d dB\n", __FUNCTION__, noise, 661 dprintk("%s: noise = 0x%08x, snr = %d.%02d dB\n", __func__, noise,
662 state->snr >> 24, (((state->snr >> 8) & 0xffff) * 100) >> 16); 662 state->snr >> 24, (((state->snr >> 8) & 0xffff) * 100) >> 16);
663 663
664 return 0; 664 return 0;
@@ -743,7 +743,7 @@ struct dvb_frontend* lgdt330x_attach(const struct lgdt330x_config* config,
743 743
744error: 744error:
745 kfree(state); 745 kfree(state);
746 dprintk("%s: ERROR\n",__FUNCTION__); 746 dprintk("%s: ERROR\n",__func__);
747 return NULL; 747 return NULL;
748} 748}
749 749
diff --git a/drivers/media/dvb/frontends/lgdt330x.h b/drivers/media/dvb/frontends/lgdt330x.h
index 995059004b10..9012504f0f2d 100644
--- a/drivers/media/dvb/frontends/lgdt330x.h
+++ b/drivers/media/dvb/frontends/lgdt330x.h
@@ -59,7 +59,7 @@ extern struct dvb_frontend* lgdt330x_attach(const struct lgdt330x_config* config
59static inline struct dvb_frontend* lgdt330x_attach(const struct lgdt330x_config* config, 59static inline struct dvb_frontend* lgdt330x_attach(const struct lgdt330x_config* config,
60 struct i2c_adapter* i2c) 60 struct i2c_adapter* i2c)
61{ 61{
62 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 62 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
63 return NULL; 63 return NULL;
64} 64}
65#endif // CONFIG_DVB_LGDT330X 65#endif // CONFIG_DVB_LGDT330X
diff --git a/drivers/media/dvb/frontends/lnbp21.h b/drivers/media/dvb/frontends/lnbp21.h
index 68906acf7d63..8fe094bd9689 100644
--- a/drivers/media/dvb/frontends/lnbp21.h
+++ b/drivers/media/dvb/frontends/lnbp21.h
@@ -45,7 +45,7 @@ extern struct dvb_frontend *lnbp21_attach(struct dvb_frontend *fe, struct i2c_ad
45#else 45#else
46static inline struct dvb_frontend *lnbp21_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 override_set, u8 override_clear) 46static inline struct dvb_frontend *lnbp21_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, u8 override_set, u8 override_clear)
47{ 47{
48 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 48 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
49 return NULL; 49 return NULL;
50} 50}
51#endif // CONFIG_DVB_LNBP21 51#endif // CONFIG_DVB_LNBP21
diff --git a/drivers/media/dvb/frontends/mt2060.h b/drivers/media/dvb/frontends/mt2060.h
index 0a86eab3a954..acba0058f519 100644
--- a/drivers/media/dvb/frontends/mt2060.h
+++ b/drivers/media/dvb/frontends/mt2060.h
@@ -35,7 +35,7 @@ extern struct dvb_frontend * mt2060_attach(struct dvb_frontend *fe, struct i2c_a
35#else 35#else
36static inline struct dvb_frontend * mt2060_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct mt2060_config *cfg, u16 if1) 36static inline struct dvb_frontend * mt2060_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct mt2060_config *cfg, u16 if1)
37{ 37{
38 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 38 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
39 return NULL; 39 return NULL;
40} 40}
41#endif // CONFIG_DVB_TUNER_MT2060 41#endif // CONFIG_DVB_TUNER_MT2060
diff --git a/drivers/media/dvb/frontends/mt2131.c b/drivers/media/dvb/frontends/mt2131.c
index 13cf16668171..e254bcfc2efb 100644
--- a/drivers/media/dvb/frontends/mt2131.c
+++ b/drivers/media/dvb/frontends/mt2131.c
@@ -110,7 +110,7 @@ static int mt2131_set_params(struct dvb_frontend *fe,
110 priv->bandwidth = 0; 110 priv->bandwidth = 0;
111 111
112 freq = params->frequency / 1000; // Hz -> kHz 112 freq = params->frequency / 1000; // Hz -> kHz
113 dprintk(1, "%s() freq=%d\n", __FUNCTION__, freq); 113 dprintk(1, "%s() freq=%d\n", __func__, freq);
114 114
115 f_lo1 = freq + MT2131_IF1 * 1000; 115 f_lo1 = freq + MT2131_IF1 * 1000;
116 f_lo1 = (f_lo1 / 250) * 250; 116 f_lo1 = (f_lo1 / 250) * 250;
@@ -187,7 +187,7 @@ static int mt2131_set_params(struct dvb_frontend *fe,
187static int mt2131_get_frequency(struct dvb_frontend *fe, u32 *frequency) 187static int mt2131_get_frequency(struct dvb_frontend *fe, u32 *frequency)
188{ 188{
189 struct mt2131_priv *priv = fe->tuner_priv; 189 struct mt2131_priv *priv = fe->tuner_priv;
190 dprintk(1, "%s()\n", __FUNCTION__); 190 dprintk(1, "%s()\n", __func__);
191 *frequency = priv->frequency; 191 *frequency = priv->frequency;
192 return 0; 192 return 0;
193} 193}
@@ -195,7 +195,7 @@ static int mt2131_get_frequency(struct dvb_frontend *fe, u32 *frequency)
195static int mt2131_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth) 195static int mt2131_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
196{ 196{
197 struct mt2131_priv *priv = fe->tuner_priv; 197 struct mt2131_priv *priv = fe->tuner_priv;
198 dprintk(1, "%s()\n", __FUNCTION__); 198 dprintk(1, "%s()\n", __func__);
199 *bandwidth = priv->bandwidth; 199 *bandwidth = priv->bandwidth;
200 return 0; 200 return 0;
201} 201}
@@ -214,7 +214,7 @@ static int mt2131_get_status(struct dvb_frontend *fe, u32 *status)
214 214
215 mt2131_readreg(priv, 0x09, &afc_status); 215 mt2131_readreg(priv, 0x09, &afc_status);
216 dprintk(1, "%s() - LO Status = 0x%x, AFC Status = 0x%x\n", 216 dprintk(1, "%s() - LO Status = 0x%x, AFC Status = 0x%x\n",
217 __FUNCTION__, lock_status, afc_status); 217 __func__, lock_status, afc_status);
218 218
219 return 0; 219 return 0;
220} 220}
@@ -223,7 +223,7 @@ static int mt2131_init(struct dvb_frontend *fe)
223{ 223{
224 struct mt2131_priv *priv = fe->tuner_priv; 224 struct mt2131_priv *priv = fe->tuner_priv;
225 int ret; 225 int ret;
226 dprintk(1, "%s()\n", __FUNCTION__); 226 dprintk(1, "%s()\n", __func__);
227 227
228 if ((ret = mt2131_writeregs(priv, mt2131_config1, 228 if ((ret = mt2131_writeregs(priv, mt2131_config1,
229 sizeof(mt2131_config1))) < 0) 229 sizeof(mt2131_config1))) < 0)
@@ -243,7 +243,7 @@ static int mt2131_init(struct dvb_frontend *fe)
243 243
244static int mt2131_release(struct dvb_frontend *fe) 244static int mt2131_release(struct dvb_frontend *fe)
245{ 245{
246 dprintk(1, "%s()\n", __FUNCTION__); 246 dprintk(1, "%s()\n", __func__);
247 kfree(fe->tuner_priv); 247 kfree(fe->tuner_priv);
248 fe->tuner_priv = NULL; 248 fe->tuner_priv = NULL;
249 return 0; 249 return 0;
@@ -273,7 +273,7 @@ struct dvb_frontend * mt2131_attach(struct dvb_frontend *fe,
273 struct mt2131_priv *priv = NULL; 273 struct mt2131_priv *priv = NULL;
274 u8 id = 0; 274 u8 id = 0;
275 275
276 dprintk(1, "%s()\n", __FUNCTION__); 276 dprintk(1, "%s()\n", __func__);
277 277
278 priv = kzalloc(sizeof(struct mt2131_priv), GFP_KERNEL); 278 priv = kzalloc(sizeof(struct mt2131_priv), GFP_KERNEL);
279 if (priv == NULL) 279 if (priv == NULL)
diff --git a/drivers/media/dvb/frontends/mt2131.h b/drivers/media/dvb/frontends/mt2131.h
index 1e4ffe7dc8c8..606d8576bc98 100644
--- a/drivers/media/dvb/frontends/mt2131.h
+++ b/drivers/media/dvb/frontends/mt2131.h
@@ -41,7 +41,7 @@ static inline struct dvb_frontend* mt2131_attach(struct dvb_frontend *fe,
41 struct mt2131_config *cfg, 41 struct mt2131_config *cfg,
42 u16 if1) 42 u16 if1)
43{ 43{
44 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 44 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
45 return NULL; 45 return NULL;
46} 46}
47#endif /* CONFIG_DVB_TUNER_MT2131 */ 47#endif /* CONFIG_DVB_TUNER_MT2131 */
diff --git a/drivers/media/dvb/frontends/mt2266.h b/drivers/media/dvb/frontends/mt2266.h
index f31dd613ad37..c5113efe333c 100644
--- a/drivers/media/dvb/frontends/mt2266.h
+++ b/drivers/media/dvb/frontends/mt2266.h
@@ -29,7 +29,7 @@ extern struct dvb_frontend * mt2266_attach(struct dvb_frontend *fe, struct i2c_a
29#else 29#else
30static inline struct dvb_frontend * mt2266_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct mt2266_config *cfg) 30static inline struct dvb_frontend * mt2266_attach(struct dvb_frontend *fe, struct i2c_adapter *i2c, struct mt2266_config *cfg)
31{ 31{
32 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 32 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
33 return NULL; 33 return NULL;
34} 34}
35#endif // CONFIG_DVB_TUNER_MT2266 35#endif // CONFIG_DVB_TUNER_MT2266
diff --git a/drivers/media/dvb/frontends/mt312.c b/drivers/media/dvb/frontends/mt312.c
index 1638301fbd6e..081ca3398c76 100644
--- a/drivers/media/dvb/frontends/mt312.c
+++ b/drivers/media/dvb/frontends/mt312.c
@@ -1,7 +1,8 @@
1/* 1/*
2 Driver for Zarlink VP310/MT312 Satellite Channel Decoder 2 Driver for Zarlink VP310/MT312/ZL10313 Satellite Channel Decoder
3 3
4 Copyright (C) 2003 Andreas Oberritter <obi@linuxtv.org> 4 Copyright (C) 2003 Andreas Oberritter <obi@linuxtv.org>
5 Copyright (C) 2008 Matthias Schwarzott <zzam@gentoo.org>
5 6
6 This program is free software; you can redistribute it and/or modify 7 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by 8 it under the terms of the GNU General Public License as published by
@@ -43,7 +44,8 @@ struct mt312_state {
43 struct dvb_frontend frontend; 44 struct dvb_frontend frontend;
44 45
45 u8 id; 46 u8 id;
46 u8 frequency; 47 unsigned long xtal;
48 u8 freq_mult;
47}; 49};
48 50
49static int debug; 51static int debug;
@@ -53,12 +55,11 @@ static int debug;
53 printk(KERN_DEBUG "mt312: " args); \ 55 printk(KERN_DEBUG "mt312: " args); \
54 } while (0) 56 } while (0)
55 57
56#define MT312_SYS_CLK 90000000UL /* 90 MHz */
57#define MT312_LPOWER_SYS_CLK 60000000UL /* 60 MHz */
58#define MT312_PLL_CLK 10000000UL /* 10 MHz */ 58#define MT312_PLL_CLK 10000000UL /* 10 MHz */
59#define MT312_PLL_CLK_10_111 10111000UL /* 10.111 MHz */
59 60
60static int mt312_read(struct mt312_state *state, const enum mt312_reg_addr reg, 61static int mt312_read(struct mt312_state *state, const enum mt312_reg_addr reg,
61 void *buf, const size_t count) 62 u8 *buf, const size_t count)
62{ 63{
63 int ret; 64 int ret;
64 struct i2c_msg msg[2]; 65 struct i2c_msg msg[2];
@@ -76,7 +77,7 @@ static int mt312_read(struct mt312_state *state, const enum mt312_reg_addr reg,
76 ret = i2c_transfer(state->i2c, msg, 2); 77 ret = i2c_transfer(state->i2c, msg, 2);
77 78
78 if (ret != 2) { 79 if (ret != 2) {
79 printk(KERN_ERR "%s: ret == %d\n", __FUNCTION__, ret); 80 printk(KERN_ERR "%s: ret == %d\n", __func__, ret);
80 return -EREMOTEIO; 81 return -EREMOTEIO;
81 } 82 }
82 83
@@ -84,7 +85,7 @@ static int mt312_read(struct mt312_state *state, const enum mt312_reg_addr reg,
84 int i; 85 int i;
85 dprintk("R(%d):", reg & 0x7f); 86 dprintk("R(%d):", reg & 0x7f);
86 for (i = 0; i < count; i++) 87 for (i = 0; i < count; i++)
87 printk(" %02x", ((const u8 *) buf)[i]); 88 printk(" %02x", buf[i]);
88 printk("\n"); 89 printk("\n");
89 } 90 }
90 91
@@ -92,7 +93,7 @@ static int mt312_read(struct mt312_state *state, const enum mt312_reg_addr reg,
92} 93}
93 94
94static int mt312_write(struct mt312_state *state, const enum mt312_reg_addr reg, 95static int mt312_write(struct mt312_state *state, const enum mt312_reg_addr reg,
95 const void *src, const size_t count) 96 const u8 *src, const size_t count)
96{ 97{
97 int ret; 98 int ret;
98 u8 buf[count + 1]; 99 u8 buf[count + 1];
@@ -102,7 +103,7 @@ static int mt312_write(struct mt312_state *state, const enum mt312_reg_addr reg,
102 int i; 103 int i;
103 dprintk("W(%d):", reg & 0x7f); 104 dprintk("W(%d):", reg & 0x7f);
104 for (i = 0; i < count; i++) 105 for (i = 0; i < count; i++)
105 printk(" %02x", ((const u8 *) src)[i]); 106 printk(" %02x", src[i]);
106 printk("\n"); 107 printk("\n");
107 } 108 }
108 109
@@ -117,7 +118,7 @@ static int mt312_write(struct mt312_state *state, const enum mt312_reg_addr reg,
117 ret = i2c_transfer(state->i2c, &msg, 1); 118 ret = i2c_transfer(state->i2c, &msg, 1);
118 119
119 if (ret != 1) { 120 if (ret != 1) {
120 dprintk("%s: ret == %d\n", __FUNCTION__, ret); 121 dprintk("%s: ret == %d\n", __func__, ret);
121 return -EREMOTEIO; 122 return -EREMOTEIO;
122 } 123 }
123 124
@@ -209,7 +210,7 @@ static int mt312_get_symbol_rate(struct mt312_state *state, u32 *sr)
209 dprintk("sym_rat_op=%d dec_ratio=%d\n", 210 dprintk("sym_rat_op=%d dec_ratio=%d\n",
210 sym_rat_op, dec_ratio); 211 sym_rat_op, dec_ratio);
211 dprintk("*sr(manual) = %lu\n", 212 dprintk("*sr(manual) = %lu\n",
212 (((MT312_PLL_CLK * 8192) / (sym_rat_op + 8192)) * 213 (((state->xtal * 8192) / (sym_rat_op + 8192)) *
213 2) - dec_ratio); 214 2) - dec_ratio);
214 } 215 }
215 216
@@ -242,7 +243,7 @@ static int mt312_initfe(struct dvb_frontend *fe)
242 243
243 /* wake up */ 244 /* wake up */
244 ret = mt312_writereg(state, CONFIG, 245 ret = mt312_writereg(state, CONFIG,
245 (state->frequency == 60 ? 0x88 : 0x8c)); 246 (state->freq_mult == 6 ? 0x88 : 0x8c));
246 if (ret < 0) 247 if (ret < 0)
247 return ret; 248 return ret;
248 249
@@ -265,12 +266,37 @@ static int mt312_initfe(struct dvb_frontend *fe)
265 return ret; 266 return ret;
266 } 267 }
267 268
269 switch (state->id) {
270 case ID_ZL10313:
271 /* enable ADC */
272 ret = mt312_writereg(state, GPP_CTRL, 0x80);
273 if (ret < 0)
274 return ret;
275
276 /* configure ZL10313 for optimal ADC performance */
277 buf[0] = 0x80;
278 buf[1] = 0xB0;
279 ret = mt312_write(state, HW_CTRL, buf, 2);
280 if (ret < 0)
281 return ret;
282
283 /* enable MPEG output and ADCs */
284 ret = mt312_writereg(state, HW_CTRL, 0x00);
285 if (ret < 0)
286 return ret;
287
288 ret = mt312_writereg(state, MPEG_CTRL, 0x00);
289 if (ret < 0)
290 return ret;
291
292 break;
293 }
294
268 /* SYS_CLK */ 295 /* SYS_CLK */
269 buf[0] = mt312_div((state->frequency == 60 ? MT312_LPOWER_SYS_CLK : 296 buf[0] = mt312_div(state->xtal * state->freq_mult * 2, 1000000);
270 MT312_SYS_CLK) * 2, 1000000);
271 297
272 /* DISEQC_RATIO */ 298 /* DISEQC_RATIO */
273 buf[1] = mt312_div(MT312_PLL_CLK, 15000 * 4); 299 buf[1] = mt312_div(state->xtal, 22000 * 4);
274 300
275 ret = mt312_write(state, SYS_CLK, buf, sizeof(buf)); 301 ret = mt312_write(state, SYS_CLK, buf, sizeof(buf));
276 if (ret < 0) 302 if (ret < 0)
@@ -280,7 +306,17 @@ static int mt312_initfe(struct dvb_frontend *fe)
280 if (ret < 0) 306 if (ret < 0)
281 return ret; 307 return ret;
282 308
283 ret = mt312_writereg(state, OP_CTRL, 0x53); 309 /* different MOCLK polarity */
310 switch (state->id) {
311 case ID_ZL10313:
312 buf[0] = 0x33;
313 break;
314 default:
315 buf[0] = 0x53;
316 break;
317 }
318
319 ret = mt312_writereg(state, OP_CTRL, buf[0]);
284 if (ret < 0) 320 if (ret < 0)
285 return ret; 321 return ret;
286 322
@@ -323,6 +359,9 @@ static int mt312_send_master_cmd(struct dvb_frontend *fe,
323 if (ret < 0) 359 if (ret < 0)
324 return ret; 360 return ret;
325 361
362 /* is there a better way to wait for message to be transmitted */
363 msleep(100);
364
326 /* set DISEQC_MODE[2:0] to zero if a return message is expected */ 365 /* set DISEQC_MODE[2:0] to zero if a return message is expected */
327 if (c->msg[0] & 0x02) { 366 if (c->msg[0] & 0x02) {
328 ret = mt312_writereg(state, DISEQC_MODE, (diseqc_mode & 0x40)); 367 ret = mt312_writereg(state, DISEQC_MODE, (diseqc_mode & 0x40));
@@ -383,11 +422,16 @@ static int mt312_set_voltage(struct dvb_frontend *fe, const fe_sec_voltage_t v)
383{ 422{
384 struct mt312_state *state = fe->demodulator_priv; 423 struct mt312_state *state = fe->demodulator_priv;
385 const u8 volt_tab[3] = { 0x00, 0x40, 0x00 }; 424 const u8 volt_tab[3] = { 0x00, 0x40, 0x00 };
425 u8 val;
386 426
387 if (v > SEC_VOLTAGE_OFF) 427 if (v > SEC_VOLTAGE_OFF)
388 return -EINVAL; 428 return -EINVAL;
389 429
390 return mt312_writereg(state, DISEQC_MODE, volt_tab[v]); 430 val = volt_tab[v];
431 if (state->config->voltage_inverted)
432 val ^= 0x40;
433
434 return mt312_writereg(state, DISEQC_MODE, val);
391} 435}
392 436
393static int mt312_read_status(struct dvb_frontend *fe, fe_status_t *s) 437static int mt312_read_status(struct dvb_frontend *fe, fe_status_t *s)
@@ -463,7 +507,7 @@ static int mt312_read_snr(struct dvb_frontend *fe, u16 *snr)
463 int ret; 507 int ret;
464 u8 buf[2]; 508 u8 buf[2];
465 509
466 ret = mt312_read(state, M_SNR_H, &buf, sizeof(buf)); 510 ret = mt312_read(state, M_SNR_H, buf, sizeof(buf));
467 if (ret < 0) 511 if (ret < 0)
468 return ret; 512 return ret;
469 513
@@ -478,7 +522,7 @@ static int mt312_read_ucblocks(struct dvb_frontend *fe, u32 *ubc)
478 int ret; 522 int ret;
479 u8 buf[2]; 523 u8 buf[2];
480 524
481 ret = mt312_read(state, RS_UBC_H, &buf, sizeof(buf)); 525 ret = mt312_read(state, RS_UBC_H, buf, sizeof(buf));
482 if (ret < 0) 526 if (ret < 0)
483 return ret; 527 return ret;
484 528
@@ -499,7 +543,7 @@ static int mt312_set_frontend(struct dvb_frontend *fe,
499 { 0x00, 0x01, 0x02, 0x04, 0x3f, 0x08, 0x10, 0x20, 0x3f, 0x3f }; 543 { 0x00, 0x01, 0x02, 0x04, 0x3f, 0x08, 0x10, 0x20, 0x3f, 0x3f };
500 const u8 inv_tab[3] = { 0x00, 0x40, 0x80 }; 544 const u8 inv_tab[3] = { 0x00, 0x40, 0x80 };
501 545
502 dprintk("%s: Freq %d\n", __FUNCTION__, p->frequency); 546 dprintk("%s: Freq %d\n", __func__, p->frequency);
503 547
504 if ((p->frequency < fe->ops.info.frequency_min) 548 if ((p->frequency < fe->ops.info.frequency_min)
505 || (p->frequency > fe->ops.info.frequency_max)) 549 || (p->frequency > fe->ops.info.frequency_max))
@@ -532,17 +576,17 @@ static int mt312_set_frontend(struct dvb_frontend *fe,
532 return ret; 576 return ret;
533 if (p->u.qpsk.symbol_rate >= 30000000) { 577 if (p->u.qpsk.symbol_rate >= 30000000) {
534 /* Note that 30MS/s should use 90MHz */ 578 /* Note that 30MS/s should use 90MHz */
535 if ((config_val & 0x0c) == 0x08) { 579 if (state->freq_mult == 6) {
536 /* We are running 60MHz */ 580 /* We are running 60MHz */
537 state->frequency = 90; 581 state->freq_mult = 9;
538 ret = mt312_initfe(fe); 582 ret = mt312_initfe(fe);
539 if (ret < 0) 583 if (ret < 0)
540 return ret; 584 return ret;
541 } 585 }
542 } else { 586 } else {
543 if ((config_val & 0x0c) == 0x0C) { 587 if (state->freq_mult == 9) {
544 /* We are running 90MHz */ 588 /* We are running 90MHz */
545 state->frequency = 60; 589 state->freq_mult = 6;
546 ret = mt312_initfe(fe); 590 ret = mt312_initfe(fe);
547 if (ret < 0) 591 if (ret < 0)
548 return ret; 592 return ret;
@@ -551,6 +595,7 @@ static int mt312_set_frontend(struct dvb_frontend *fe,
551 break; 595 break;
552 596
553 case ID_MT312: 597 case ID_MT312:
598 case ID_ZL10313:
554 break; 599 break;
555 600
556 default: 601 default:
@@ -616,11 +661,29 @@ static int mt312_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
616{ 661{
617 struct mt312_state *state = fe->demodulator_priv; 662 struct mt312_state *state = fe->demodulator_priv;
618 663
619 if (enable) { 664 u8 val = 0x00;
620 return mt312_writereg(state, GPP_CTRL, 0x40); 665 int ret;
621 } else { 666
622 return mt312_writereg(state, GPP_CTRL, 0x00); 667 switch (state->id) {
668 case ID_ZL10313:
669 ret = mt312_readreg(state, GPP_CTRL, &val);
670 if (ret < 0)
671 goto error;
672
673 /* preserve this bit to not accidently shutdown ADC */
674 val &= 0x80;
675 break;
623 } 676 }
677
678 if (enable)
679 val |= 0x40;
680 else
681 val &= ~0x40;
682
683 ret = mt312_writereg(state, GPP_CTRL, val);
684
685error:
686 return ret;
624} 687}
625 688
626static int mt312_sleep(struct dvb_frontend *fe) 689static int mt312_sleep(struct dvb_frontend *fe)
@@ -634,6 +697,18 @@ static int mt312_sleep(struct dvb_frontend *fe)
634 if (ret < 0) 697 if (ret < 0)
635 return ret; 698 return ret;
636 699
700 if (state->id == ID_ZL10313) {
701 /* reset ADC */
702 ret = mt312_writereg(state, GPP_CTRL, 0x00);
703 if (ret < 0)
704 return ret;
705
706 /* full shutdown of ADCs, mpeg bus tristated */
707 ret = mt312_writereg(state, HW_CTRL, 0x0d);
708 if (ret < 0)
709 return ret;
710 }
711
637 ret = mt312_readreg(state, CONFIG, &config); 712 ret = mt312_readreg(state, CONFIG, &config);
638 if (ret < 0) 713 if (ret < 0)
639 return ret; 714 return ret;
@@ -661,6 +736,7 @@ static void mt312_release(struct dvb_frontend *fe)
661 kfree(state); 736 kfree(state);
662} 737}
663 738
739#define MT312_SYS_CLK 90000000UL /* 90 MHz */
664static struct dvb_frontend_ops vp310_mt312_ops = { 740static struct dvb_frontend_ops vp310_mt312_ops = {
665 741
666 .info = { 742 .info = {
@@ -668,8 +744,8 @@ static struct dvb_frontend_ops vp310_mt312_ops = {
668 .type = FE_QPSK, 744 .type = FE_QPSK,
669 .frequency_min = 950000, 745 .frequency_min = 950000,
670 .frequency_max = 2150000, 746 .frequency_max = 2150000,
671 .frequency_stepsize = (MT312_PLL_CLK / 1000) / 128, 747 .frequency_stepsize = (MT312_PLL_CLK / 1000) / 128, /* FIXME: adjust freq to real used xtal */
672 .symbol_rate_min = MT312_SYS_CLK / 128, 748 .symbol_rate_min = MT312_SYS_CLK / 128, /* FIXME as above */
673 .symbol_rate_max = MT312_SYS_CLK / 2, 749 .symbol_rate_max = MT312_SYS_CLK / 2,
674 .caps = 750 .caps =
675 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | 751 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 |
@@ -726,14 +802,21 @@ struct dvb_frontend *vp310_mt312_attach(const struct mt312_config *config,
726 switch (state->id) { 802 switch (state->id) {
727 case ID_VP310: 803 case ID_VP310:
728 strcpy(state->frontend.ops.info.name, "Zarlink VP310 DVB-S"); 804 strcpy(state->frontend.ops.info.name, "Zarlink VP310 DVB-S");
729 state->frequency = 90; 805 state->xtal = MT312_PLL_CLK;
806 state->freq_mult = 9;
730 break; 807 break;
731 case ID_MT312: 808 case ID_MT312:
732 strcpy(state->frontend.ops.info.name, "Zarlink MT312 DVB-S"); 809 strcpy(state->frontend.ops.info.name, "Zarlink MT312 DVB-S");
733 state->frequency = 60; 810 state->xtal = MT312_PLL_CLK;
811 state->freq_mult = 6;
812 break;
813 case ID_ZL10313:
814 strcpy(state->frontend.ops.info.name, "Zarlink ZL10313 DVB-S");
815 state->xtal = MT312_PLL_CLK_10_111;
816 state->freq_mult = 9;
734 break; 817 break;
735 default: 818 default:
736 printk(KERN_WARNING "Only Zarlink VP310/MT312" 819 printk(KERN_WARNING "Only Zarlink VP310/MT312/ZL10313"
737 " are supported chips.\n"); 820 " are supported chips.\n");
738 goto error; 821 goto error;
739 } 822 }
@@ -749,7 +832,7 @@ EXPORT_SYMBOL(vp310_mt312_attach);
749module_param(debug, int, 0644); 832module_param(debug, int, 0644);
750MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off)."); 833MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
751 834
752MODULE_DESCRIPTION("Zarlink VP310/MT312 DVB-S Demodulator driver"); 835MODULE_DESCRIPTION("Zarlink VP310/MT312/ZL10313 DVB-S Demodulator driver");
753MODULE_AUTHOR("Andreas Oberritter <obi@linuxtv.org>"); 836MODULE_AUTHOR("Andreas Oberritter <obi@linuxtv.org>");
754MODULE_LICENSE("GPL"); 837MODULE_LICENSE("GPL");
755 838
diff --git a/drivers/media/dvb/frontends/mt312.h b/drivers/media/dvb/frontends/mt312.h
index f17cb93ba9ba..96338f0c4dd4 100644
--- a/drivers/media/dvb/frontends/mt312.h
+++ b/drivers/media/dvb/frontends/mt312.h
@@ -31,6 +31,9 @@
31struct mt312_config { 31struct mt312_config {
32 /* the demodulator's i2c address */ 32 /* the demodulator's i2c address */
33 u8 demod_address; 33 u8 demod_address;
34
35 /* inverted voltage setting */
36 int voltage_inverted:1;
34}; 37};
35 38
36#if defined(CONFIG_DVB_MT312) || (defined(CONFIG_DVB_MT312_MODULE) && defined(MODULE)) 39#if defined(CONFIG_DVB_MT312) || (defined(CONFIG_DVB_MT312_MODULE) && defined(MODULE))
@@ -40,7 +43,7 @@ struct dvb_frontend *vp310_mt312_attach(const struct mt312_config *config,
40static inline struct dvb_frontend *vp310_mt312_attach( 43static inline struct dvb_frontend *vp310_mt312_attach(
41 const struct mt312_config *config, struct i2c_adapter *i2c) 44 const struct mt312_config *config, struct i2c_adapter *i2c)
42{ 45{
43 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 46 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
44 return NULL; 47 return NULL;
45} 48}
46#endif /* CONFIG_DVB_MT312 */ 49#endif /* CONFIG_DVB_MT312 */
diff --git a/drivers/media/dvb/frontends/mt312_priv.h b/drivers/media/dvb/frontends/mt312_priv.h
index 5e0b95b5337b..a3959f94d639 100644
--- a/drivers/media/dvb/frontends/mt312_priv.h
+++ b/drivers/media/dvb/frontends/mt312_priv.h
@@ -110,6 +110,8 @@ enum mt312_reg_addr {
110 VIT_ERRPER_H = 83, 110 VIT_ERRPER_H = 83,
111 VIT_ERRPER_M = 84, 111 VIT_ERRPER_M = 84,
112 VIT_ERRPER_L = 85, 112 VIT_ERRPER_L = 85,
113 HW_CTRL = 84, /* ZL10313 only */
114 MPEG_CTRL = 85, /* ZL10313 only */
113 VIT_SETUP = 86, 115 VIT_SETUP = 86,
114 VIT_REF0 = 87, 116 VIT_REF0 = 87,
115 VIT_REF1 = 88, 117 VIT_REF1 = 88,
@@ -156,7 +158,8 @@ enum mt312_reg_addr {
156 158
157enum mt312_model_id { 159enum mt312_model_id {
158 ID_VP310 = 1, 160 ID_VP310 = 1,
159 ID_MT312 = 3 161 ID_MT312 = 3,
162 ID_ZL10313 = 5,
160}; 163};
161 164
162#endif /* DVB_FRONTENDS_MT312_PRIV */ 165#endif /* DVB_FRONTENDS_MT312_PRIV */
diff --git a/drivers/media/dvb/frontends/mt352.c b/drivers/media/dvb/frontends/mt352.c
index 7cd190b6f015..beba5aa0db50 100644
--- a/drivers/media/dvb/frontends/mt352.c
+++ b/drivers/media/dvb/frontends/mt352.c
@@ -95,7 +95,7 @@ static int mt352_read_register(struct mt352_state* state, u8 reg)
95 95
96 if (ret != 2) { 96 if (ret != 2) {
97 printk("%s: readreg error (reg=%d, ret==%i)\n", 97 printk("%s: readreg error (reg=%d, ret==%i)\n",
98 __FUNCTION__, reg, ret); 98 __func__, reg, ret);
99 return ret; 99 return ret;
100 } 100 }
101 101
@@ -135,7 +135,7 @@ static void mt352_calc_nominal_rate(struct mt352_state* state,
135 value = 64 * bw * (1<<16) / (7 * 8); 135 value = 64 * bw * (1<<16) / (7 * 8);
136 value = value * 1000 / adc_clock; 136 value = value * 1000 / adc_clock;
137 dprintk("%s: bw %d, adc_clock %d => 0x%x\n", 137 dprintk("%s: bw %d, adc_clock %d => 0x%x\n",
138 __FUNCTION__, bw, adc_clock, value); 138 __func__, bw, adc_clock, value);
139 buf[0] = msb(value); 139 buf[0] = msb(value);
140 buf[1] = lsb(value); 140 buf[1] = lsb(value);
141} 141}
@@ -161,7 +161,7 @@ static void mt352_calc_input_freq(struct mt352_state* state,
161 } 161 }
162 value = -16374 * ife / adc_clock; 162 value = -16374 * ife / adc_clock;
163 dprintk("%s: if2 %d, ife %d, adc_clock %d => %d / 0x%x\n", 163 dprintk("%s: if2 %d, ife %d, adc_clock %d => %d / 0x%x\n",
164 __FUNCTION__, if2, ife, adc_clock, value, value & 0x3fff); 164 __func__, if2, ife, adc_clock, value, value & 0x3fff);
165 buf[0] = msb(value); 165 buf[0] = msb(value);
166 buf[1] = lsb(value); 166 buf[1] = lsb(value);
167} 167}
@@ -521,7 +521,7 @@ static int mt352_init(struct dvb_frontend* fe)
521 521
522 static u8 mt352_reset_attach [] = { RESET, 0xC0 }; 522 static u8 mt352_reset_attach [] = { RESET, 0xC0 };
523 523
524 dprintk("%s: hello\n",__FUNCTION__); 524 dprintk("%s: hello\n",__func__);
525 525
526 if ((mt352_read_register(state, CLOCK_CTL) & 0x10) == 0 || 526 if ((mt352_read_register(state, CLOCK_CTL) & 0x10) == 0 ||
527 (mt352_read_register(state, CONFIG) & 0x20) == 0) { 527 (mt352_read_register(state, CONFIG) & 0x20) == 0) {
diff --git a/drivers/media/dvb/frontends/mt352.h b/drivers/media/dvb/frontends/mt352.h
index e9964081fd84..595092f9f0c4 100644
--- a/drivers/media/dvb/frontends/mt352.h
+++ b/drivers/media/dvb/frontends/mt352.h
@@ -58,7 +58,7 @@ extern struct dvb_frontend* mt352_attach(const struct mt352_config* config,
58static inline struct dvb_frontend* mt352_attach(const struct mt352_config* config, 58static inline struct dvb_frontend* mt352_attach(const struct mt352_config* config,
59 struct i2c_adapter* i2c) 59 struct i2c_adapter* i2c)
60{ 60{
61 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 61 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
62 return NULL; 62 return NULL;
63} 63}
64#endif // CONFIG_DVB_MT352 64#endif // CONFIG_DVB_MT352
diff --git a/drivers/media/dvb/frontends/nxt200x.c b/drivers/media/dvb/frontends/nxt200x.c
index fcf964fe1d6b..23d022852543 100644
--- a/drivers/media/dvb/frontends/nxt200x.c
+++ b/drivers/media/dvb/frontends/nxt200x.c
@@ -74,7 +74,7 @@ static int i2c_writebytes (struct nxt200x_state* state, u8 addr, u8 *buf, u8 len
74 74
75 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) { 75 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) {
76 printk (KERN_WARNING "nxt200x: %s: i2c write error (addr 0x%02x, err == %i)\n", 76 printk (KERN_WARNING "nxt200x: %s: i2c write error (addr 0x%02x, err == %i)\n",
77 __FUNCTION__, addr, err); 77 __func__, addr, err);
78 return -EREMOTEIO; 78 return -EREMOTEIO;
79 } 79 }
80 return 0; 80 return 0;
@@ -87,7 +87,7 @@ static u8 i2c_readbytes (struct nxt200x_state* state, u8 addr, u8* buf, u8 len)
87 87
88 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) { 88 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) {
89 printk (KERN_WARNING "nxt200x: %s: i2c read error (addr 0x%02x, err == %i)\n", 89 printk (KERN_WARNING "nxt200x: %s: i2c read error (addr 0x%02x, err == %i)\n",
90 __FUNCTION__, addr, err); 90 __func__, addr, err);
91 return -EREMOTEIO; 91 return -EREMOTEIO;
92 } 92 }
93 return 0; 93 return 0;
@@ -104,7 +104,7 @@ static int nxt200x_writebytes (struct nxt200x_state* state, u8 reg, u8 *buf, u8
104 104
105 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) { 105 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) {
106 printk (KERN_WARNING "nxt200x: %s: i2c write error (addr 0x%02x, err == %i)\n", 106 printk (KERN_WARNING "nxt200x: %s: i2c write error (addr 0x%02x, err == %i)\n",
107 __FUNCTION__, state->config->demod_address, err); 107 __func__, state->config->demod_address, err);
108 return -EREMOTEIO; 108 return -EREMOTEIO;
109 } 109 }
110 return 0; 110 return 0;
@@ -121,7 +121,7 @@ static u8 nxt200x_readbytes (struct nxt200x_state* state, u8 reg, u8* buf, u8 le
121 121
122 if ((err = i2c_transfer (state->i2c, msg, 2)) != 2) { 122 if ((err = i2c_transfer (state->i2c, msg, 2)) != 2) {
123 printk (KERN_WARNING "nxt200x: %s: i2c read error (addr 0x%02x, err == %i)\n", 123 printk (KERN_WARNING "nxt200x: %s: i2c read error (addr 0x%02x, err == %i)\n",
124 __FUNCTION__, state->config->demod_address, err); 124 __func__, state->config->demod_address, err);
125 return -EREMOTEIO; 125 return -EREMOTEIO;
126 } 126 }
127 return 0; 127 return 0;
@@ -146,7 +146,7 @@ static u16 nxt200x_crc(u16 crc, u8 c)
146static int nxt200x_writereg_multibyte (struct nxt200x_state* state, u8 reg, u8* data, u8 len) 146static int nxt200x_writereg_multibyte (struct nxt200x_state* state, u8 reg, u8* data, u8 len)
147{ 147{
148 u8 attr, len2, buf; 148 u8 attr, len2, buf;
149 dprintk("%s\n", __FUNCTION__); 149 dprintk("%s\n", __func__);
150 150
151 /* set mutli register register */ 151 /* set mutli register register */
152 nxt200x_writebytes(state, 0x35, &reg, 1); 152 nxt200x_writebytes(state, 0x35, &reg, 1);
@@ -207,7 +207,7 @@ static int nxt200x_readreg_multibyte (struct nxt200x_state* state, u8 reg, u8* d
207{ 207{
208 int i; 208 int i;
209 u8 buf, len2, attr; 209 u8 buf, len2, attr;
210 dprintk("%s\n", __FUNCTION__); 210 dprintk("%s\n", __func__);
211 211
212 /* set mutli register register */ 212 /* set mutli register register */
213 nxt200x_writebytes(state, 0x35, &reg, 1); 213 nxt200x_writebytes(state, 0x35, &reg, 1);
@@ -254,7 +254,7 @@ static int nxt200x_readreg_multibyte (struct nxt200x_state* state, u8 reg, u8* d
254static void nxt200x_microcontroller_stop (struct nxt200x_state* state) 254static void nxt200x_microcontroller_stop (struct nxt200x_state* state)
255{ 255{
256 u8 buf, stopval, counter = 0; 256 u8 buf, stopval, counter = 0;
257 dprintk("%s\n", __FUNCTION__); 257 dprintk("%s\n", __func__);
258 258
259 /* set correct stop value */ 259 /* set correct stop value */
260 switch (state->demod_chip) { 260 switch (state->demod_chip) {
@@ -287,7 +287,7 @@ static void nxt200x_microcontroller_stop (struct nxt200x_state* state)
287static void nxt200x_microcontroller_start (struct nxt200x_state* state) 287static void nxt200x_microcontroller_start (struct nxt200x_state* state)
288{ 288{
289 u8 buf; 289 u8 buf;
290 dprintk("%s\n", __FUNCTION__); 290 dprintk("%s\n", __func__);
291 291
292 buf = 0x00; 292 buf = 0x00;
293 nxt200x_writebytes(state, 0x22, &buf, 1); 293 nxt200x_writebytes(state, 0x22, &buf, 1);
@@ -297,7 +297,7 @@ static void nxt2004_microcontroller_init (struct nxt200x_state* state)
297{ 297{
298 u8 buf[9]; 298 u8 buf[9];
299 u8 counter = 0; 299 u8 counter = 0;
300 dprintk("%s\n", __FUNCTION__); 300 dprintk("%s\n", __func__);
301 301
302 buf[0] = 0x00; 302 buf[0] = 0x00;
303 nxt200x_writebytes(state, 0x2b, buf, 1); 303 nxt200x_writebytes(state, 0x2b, buf, 1);
@@ -328,7 +328,7 @@ static int nxt200x_writetuner (struct nxt200x_state* state, u8* data)
328{ 328{
329 u8 buf, count = 0; 329 u8 buf, count = 0;
330 330
331 dprintk("%s\n", __FUNCTION__); 331 dprintk("%s\n", __func__);
332 332
333 dprintk("Tuner Bytes: %02X %02X %02X %02X\n", data[1], data[2], data[3], data[4]); 333 dprintk("Tuner Bytes: %02X %02X %02X %02X\n", data[1], data[2], data[3], data[4]);
334 334
@@ -387,7 +387,7 @@ static int nxt200x_writetuner (struct nxt200x_state* state, u8* data)
387static void nxt200x_agc_reset(struct nxt200x_state* state) 387static void nxt200x_agc_reset(struct nxt200x_state* state)
388{ 388{
389 u8 buf; 389 u8 buf;
390 dprintk("%s\n", __FUNCTION__); 390 dprintk("%s\n", __func__);
391 391
392 switch (state->demod_chip) { 392 switch (state->demod_chip) {
393 case NXT2002: 393 case NXT2002:
@@ -416,7 +416,7 @@ static int nxt2002_load_firmware (struct dvb_frontend* fe, const struct firmware
416 u8 buf[3], written = 0, chunkpos = 0; 416 u8 buf[3], written = 0, chunkpos = 0;
417 u16 rambase, position, crc = 0; 417 u16 rambase, position, crc = 0;
418 418
419 dprintk("%s\n", __FUNCTION__); 419 dprintk("%s\n", __func__);
420 dprintk("Firmware is %zu bytes\n", fw->size); 420 dprintk("Firmware is %zu bytes\n", fw->size);
421 421
422 /* Get the RAM base for this nxt2002 */ 422 /* Get the RAM base for this nxt2002 */
@@ -483,7 +483,7 @@ static int nxt2004_load_firmware (struct dvb_frontend* fe, const struct firmware
483 u8 buf[3]; 483 u8 buf[3];
484 u16 rambase, position, crc=0; 484 u16 rambase, position, crc=0;
485 485
486 dprintk("%s\n", __FUNCTION__); 486 dprintk("%s\n", __func__);
487 dprintk("Firmware is %zu bytes\n", fw->size); 487 dprintk("Firmware is %zu bytes\n", fw->size);
488 488
489 /* set rambase */ 489 /* set rambase */
diff --git a/drivers/media/dvb/frontends/nxt200x.h b/drivers/media/dvb/frontends/nxt200x.h
index bb0ef58d7972..f3c84583770f 100644
--- a/drivers/media/dvb/frontends/nxt200x.h
+++ b/drivers/media/dvb/frontends/nxt200x.h
@@ -49,7 +49,7 @@ extern struct dvb_frontend* nxt200x_attach(const struct nxt200x_config* config,
49static inline struct dvb_frontend* nxt200x_attach(const struct nxt200x_config* config, 49static inline struct dvb_frontend* nxt200x_attach(const struct nxt200x_config* config,
50 struct i2c_adapter* i2c) 50 struct i2c_adapter* i2c)
51{ 51{
52 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 52 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
53 return NULL; 53 return NULL;
54} 54}
55#endif // CONFIG_DVB_NXT200X 55#endif // CONFIG_DVB_NXT200X
diff --git a/drivers/media/dvb/frontends/nxt6000.c b/drivers/media/dvb/frontends/nxt6000.c
index d313d7dcf386..0eef22dbf8a0 100644
--- a/drivers/media/dvb/frontends/nxt6000.c
+++ b/drivers/media/dvb/frontends/nxt6000.c
@@ -38,7 +38,7 @@ struct nxt6000_state {
38 struct dvb_frontend frontend; 38 struct dvb_frontend frontend;
39}; 39};
40 40
41static int debug = 0; 41static int debug;
42#define dprintk if (debug) printk 42#define dprintk if (debug) printk
43 43
44static int nxt6000_writereg(struct nxt6000_state* state, u8 reg, u8 data) 44static int nxt6000_writereg(struct nxt6000_state* state, u8 reg, u8 data)
diff --git a/drivers/media/dvb/frontends/nxt6000.h b/drivers/media/dvb/frontends/nxt6000.h
index 13d22518356e..878eb38a075e 100644
--- a/drivers/media/dvb/frontends/nxt6000.h
+++ b/drivers/media/dvb/frontends/nxt6000.h
@@ -40,7 +40,7 @@ extern struct dvb_frontend* nxt6000_attach(const struct nxt6000_config* config,
40static inline struct dvb_frontend* nxt6000_attach(const struct nxt6000_config* config, 40static inline struct dvb_frontend* nxt6000_attach(const struct nxt6000_config* config,
41 struct i2c_adapter* i2c) 41 struct i2c_adapter* i2c)
42{ 42{
43 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 43 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
44 return NULL; 44 return NULL;
45} 45}
46#endif // CONFIG_DVB_NXT6000 46#endif // CONFIG_DVB_NXT6000
diff --git a/drivers/media/dvb/frontends/or51132.c b/drivers/media/dvb/frontends/or51132.c
index 8ffb8daca031..c7b5785f81f2 100644
--- a/drivers/media/dvb/frontends/or51132.c
+++ b/drivers/media/dvb/frontends/or51132.c
@@ -419,7 +419,7 @@ static int or51132_read_status(struct dvb_frontend* fe, fe_status_t* status)
419 *status = 0; 419 *status = 0;
420 return -EREMOTEIO; 420 return -EREMOTEIO;
421 } 421 }
422 dprintk("%s: read_status %04x\n", __FUNCTION__, reg); 422 dprintk("%s: read_status %04x\n", __func__, reg);
423 423
424 if (reg & 0x0100) /* Receiver Lock */ 424 if (reg & 0x0100) /* Receiver Lock */
425 *status = FE_HAS_SIGNAL|FE_HAS_CARRIER|FE_HAS_VITERBI| 425 *status = FE_HAS_SIGNAL|FE_HAS_CARRIER|FE_HAS_VITERBI|
@@ -504,14 +504,14 @@ start:
504 if (retry--) goto start; 504 if (retry--) goto start;
505 return -EREMOTEIO; 505 return -EREMOTEIO;
506 } 506 }
507 dprintk("%s: modulation %02x, NTSC rej O%s\n", __FUNCTION__, 507 dprintk("%s: modulation %02x, NTSC rej O%s\n", __func__,
508 reg&0xff, reg&0x1000?"n":"ff"); 508 reg&0xff, reg&0x1000?"n":"ff");
509 509
510 /* Calculate SNR using noise, c, and NTSC rejection correction */ 510 /* Calculate SNR using noise, c, and NTSC rejection correction */
511 state->snr = calculate_snr(noise, c) - usK; 511 state->snr = calculate_snr(noise, c) - usK;
512 *snr = (state->snr) >> 16; 512 *snr = (state->snr) >> 16;
513 513
514 dprintk("%s: noise = 0x%08x, snr = %d.%02d dB\n", __FUNCTION__, noise, 514 dprintk("%s: noise = 0x%08x, snr = %d.%02d dB\n", __func__, noise,
515 state->snr >> 24, (((state->snr>>8) & 0xffff) * 100) >> 16); 515 state->snr >> 24, (((state->snr>>8) & 0xffff) * 100) >> 16);
516 516
517 return 0; 517 return 0;
diff --git a/drivers/media/dvb/frontends/or51132.h b/drivers/media/dvb/frontends/or51132.h
index add24f0a743b..1b8e04d973c8 100644
--- a/drivers/media/dvb/frontends/or51132.h
+++ b/drivers/media/dvb/frontends/or51132.h
@@ -41,7 +41,7 @@ extern struct dvb_frontend* or51132_attach(const struct or51132_config* config,
41static inline struct dvb_frontend* or51132_attach(const struct or51132_config* config, 41static inline struct dvb_frontend* or51132_attach(const struct or51132_config* config,
42 struct i2c_adapter* i2c) 42 struct i2c_adapter* i2c)
43{ 43{
44 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 44 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
45 return NULL; 45 return NULL;
46} 46}
47#endif // CONFIG_DVB_OR51132 47#endif // CONFIG_DVB_OR51132
diff --git a/drivers/media/dvb/frontends/or51211.c b/drivers/media/dvb/frontends/or51211.c
index 6a6b0d727c6f..7eaa4765593f 100644
--- a/drivers/media/dvb/frontends/or51211.c
+++ b/drivers/media/dvb/frontends/or51211.c
@@ -307,19 +307,19 @@ static int or51211_read_snr(struct dvb_frontend* fe, u16* snr)
307 307
308 if (i2c_writebytes(state,state->config->demod_address,snd_buf,3)) { 308 if (i2c_writebytes(state,state->config->demod_address,snd_buf,3)) {
309 printk(KERN_WARNING "%s: error writing snr reg\n", 309 printk(KERN_WARNING "%s: error writing snr reg\n",
310 __FUNCTION__); 310 __func__);
311 return -1; 311 return -1;
312 } 312 }
313 if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) { 313 if (i2c_readbytes(state,state->config->demod_address,rec_buf,2)) {
314 printk(KERN_WARNING "%s: read_status read error\n", 314 printk(KERN_WARNING "%s: read_status read error\n",
315 __FUNCTION__); 315 __func__);
316 return -1; 316 return -1;
317 } 317 }
318 318
319 state->snr = calculate_snr(rec_buf[0], 89599047); 319 state->snr = calculate_snr(rec_buf[0], 89599047);
320 *snr = (state->snr) >> 16; 320 *snr = (state->snr) >> 16;
321 321
322 dprintk("%s: noise = 0x%02x, snr = %d.%02d dB\n", __FUNCTION__, rec_buf[0], 322 dprintk("%s: noise = 0x%02x, snr = %d.%02d dB\n", __func__, rec_buf[0],
323 state->snr >> 24, (((state->snr>>8) & 0xffff) * 100) >> 16); 323 state->snr >> 24, (((state->snr>>8) & 0xffff) * 100) >> 16);
324 324
325 return 0; 325 return 0;
diff --git a/drivers/media/dvb/frontends/or51211.h b/drivers/media/dvb/frontends/or51211.h
index 8aad8402d615..3ce0508b898e 100644
--- a/drivers/media/dvb/frontends/or51211.h
+++ b/drivers/media/dvb/frontends/or51211.h
@@ -44,7 +44,7 @@ extern struct dvb_frontend* or51211_attach(const struct or51211_config* config,
44static inline struct dvb_frontend* or51211_attach(const struct or51211_config* config, 44static inline struct dvb_frontend* or51211_attach(const struct or51211_config* config,
45 struct i2c_adapter* i2c) 45 struct i2c_adapter* i2c)
46{ 46{
47 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 47 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
48 return NULL; 48 return NULL;
49} 49}
50#endif // CONFIG_DVB_OR51211 50#endif // CONFIG_DVB_OR51211
diff --git a/drivers/media/dvb/frontends/qt1010.h b/drivers/media/dvb/frontends/qt1010.h
index 3ab4aa045c36..cff6a7ca5380 100644
--- a/drivers/media/dvb/frontends/qt1010.h
+++ b/drivers/media/dvb/frontends/qt1010.h
@@ -45,7 +45,7 @@ static inline struct dvb_frontend *qt1010_attach(struct dvb_frontend *fe,
45 struct i2c_adapter *i2c, 45 struct i2c_adapter *i2c,
46 struct qt1010_config *cfg) 46 struct qt1010_config *cfg)
47{ 47{
48 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 48 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
49 return NULL; 49 return NULL;
50} 50}
51#endif // CONFIG_DVB_TUNER_QT1010 51#endif // CONFIG_DVB_TUNER_QT1010
diff --git a/drivers/media/dvb/frontends/s5h1409.c b/drivers/media/dvb/frontends/s5h1409.c
index 1a4d8319773c..b999ec424ff7 100644
--- a/drivers/media/dvb/frontends/s5h1409.c
+++ b/drivers/media/dvb/frontends/s5h1409.c
@@ -48,7 +48,7 @@ struct s5h1409_state {
48 u32 qam_state; 48 u32 qam_state;
49}; 49};
50 50
51static int debug = 0; 51static int debug;
52#define dprintk if (debug) printk 52#define dprintk if (debug) printk
53 53
54/* Register values to initialise the demod, this will set VSB by default */ 54/* Register values to initialise the demod, this will set VSB by default */
@@ -312,7 +312,7 @@ static int s5h1409_writereg(struct s5h1409_state* state, u8 reg, u16 data)
312 312
313 if (ret != 1) 313 if (ret != 1)
314 printk("%s: writereg error (reg == 0x%02x, val == 0x%04x, " 314 printk("%s: writereg error (reg == 0x%02x, val == 0x%04x, "
315 "ret == %i)\n", __FUNCTION__, reg, data, ret); 315 "ret == %i)\n", __func__, reg, data, ret);
316 316
317 return (ret != 1) ? -1 : 0; 317 return (ret != 1) ? -1 : 0;
318} 318}
@@ -332,7 +332,7 @@ static u16 s5h1409_readreg(struct s5h1409_state* state, u8 reg)
332 ret = i2c_transfer(state->i2c, msg, 2); 332 ret = i2c_transfer(state->i2c, msg, 2);
333 333
334 if (ret != 2) 334 if (ret != 2)
335 printk("%s: readreg error (ret == %i)\n", __FUNCTION__, ret); 335 printk("%s: readreg error (ret == %i)\n", __func__, ret);
336 return (b1[0] << 8) | b1[1]; 336 return (b1[0] << 8) | b1[1];
337} 337}
338 338
@@ -340,7 +340,7 @@ static int s5h1409_softreset(struct dvb_frontend* fe)
340{ 340{
341 struct s5h1409_state* state = fe->demodulator_priv; 341 struct s5h1409_state* state = fe->demodulator_priv;
342 342
343 dprintk("%s()\n", __FUNCTION__); 343 dprintk("%s()\n", __func__);
344 344
345 s5h1409_writereg(state, 0xf5, 0); 345 s5h1409_writereg(state, 0xf5, 0);
346 s5h1409_writereg(state, 0xf5, 1); 346 s5h1409_writereg(state, 0xf5, 1);
@@ -356,7 +356,7 @@ static int s5h1409_set_if_freq(struct dvb_frontend* fe, int KHz)
356{ 356{
357 struct s5h1409_state* state = fe->demodulator_priv; 357 struct s5h1409_state* state = fe->demodulator_priv;
358 358
359 dprintk("%s(%d KHz)\n", __FUNCTION__, KHz); 359 dprintk("%s(%d KHz)\n", __func__, KHz);
360 360
361 switch (KHz) { 361 switch (KHz) {
362 case 4000: 362 case 4000:
@@ -381,7 +381,7 @@ static int s5h1409_set_spectralinversion(struct dvb_frontend* fe, int inverted)
381{ 381{
382 struct s5h1409_state* state = fe->demodulator_priv; 382 struct s5h1409_state* state = fe->demodulator_priv;
383 383
384 dprintk("%s(%d)\n", __FUNCTION__, inverted); 384 dprintk("%s(%d)\n", __func__, inverted);
385 385
386 if(inverted == 1) 386 if(inverted == 1)
387 return s5h1409_writereg(state, 0x1b, 0x1101); /* Inverted */ 387 return s5h1409_writereg(state, 0x1b, 0x1101); /* Inverted */
@@ -394,25 +394,25 @@ static int s5h1409_enable_modulation(struct dvb_frontend* fe,
394{ 394{
395 struct s5h1409_state* state = fe->demodulator_priv; 395 struct s5h1409_state* state = fe->demodulator_priv;
396 396
397 dprintk("%s(0x%08x)\n", __FUNCTION__, m); 397 dprintk("%s(0x%08x)\n", __func__, m);
398 398
399 switch(m) { 399 switch(m) {
400 case VSB_8: 400 case VSB_8:
401 dprintk("%s() VSB_8\n", __FUNCTION__); 401 dprintk("%s() VSB_8\n", __func__);
402 if (state->if_freq != S5H1409_VSB_IF_FREQ) 402 if (state->if_freq != S5H1409_VSB_IF_FREQ)
403 s5h1409_set_if_freq(fe, S5H1409_VSB_IF_FREQ); 403 s5h1409_set_if_freq(fe, S5H1409_VSB_IF_FREQ);
404 s5h1409_writereg(state, 0xf4, 0); 404 s5h1409_writereg(state, 0xf4, 0);
405 break; 405 break;
406 case QAM_64: 406 case QAM_64:
407 case QAM_256: 407 case QAM_256:
408 dprintk("%s() QAM_AUTO (64/256)\n", __FUNCTION__); 408 dprintk("%s() QAM_AUTO (64/256)\n", __func__);
409 if (state->if_freq != S5H1409_QAM_IF_FREQ) 409 if (state->if_freq != S5H1409_QAM_IF_FREQ)
410 s5h1409_set_if_freq(fe, S5H1409_QAM_IF_FREQ); 410 s5h1409_set_if_freq(fe, S5H1409_QAM_IF_FREQ);
411 s5h1409_writereg(state, 0xf4, 1); 411 s5h1409_writereg(state, 0xf4, 1);
412 s5h1409_writereg(state, 0x85, 0x110); 412 s5h1409_writereg(state, 0x85, 0x110);
413 break; 413 break;
414 default: 414 default:
415 dprintk("%s() Invalid modulation\n", __FUNCTION__); 415 dprintk("%s() Invalid modulation\n", __func__);
416 return -EINVAL; 416 return -EINVAL;
417 } 417 }
418 418
@@ -426,7 +426,7 @@ static int s5h1409_i2c_gate_ctrl(struct dvb_frontend* fe, int enable)
426{ 426{
427 struct s5h1409_state* state = fe->demodulator_priv; 427 struct s5h1409_state* state = fe->demodulator_priv;
428 428
429 dprintk("%s(%d)\n", __FUNCTION__, enable); 429 dprintk("%s(%d)\n", __func__, enable);
430 430
431 if (enable) 431 if (enable)
432 return s5h1409_writereg(state, 0xf3, 1); 432 return s5h1409_writereg(state, 0xf3, 1);
@@ -438,7 +438,7 @@ static int s5h1409_set_gpio(struct dvb_frontend* fe, int enable)
438{ 438{
439 struct s5h1409_state* state = fe->demodulator_priv; 439 struct s5h1409_state* state = fe->demodulator_priv;
440 440
441 dprintk("%s(%d)\n", __FUNCTION__, enable); 441 dprintk("%s(%d)\n", __func__, enable);
442 442
443 if (enable) 443 if (enable)
444 return s5h1409_writereg(state, 0xe3, 444 return s5h1409_writereg(state, 0xe3,
@@ -452,7 +452,7 @@ static int s5h1409_sleep(struct dvb_frontend* fe, int enable)
452{ 452{
453 struct s5h1409_state* state = fe->demodulator_priv; 453 struct s5h1409_state* state = fe->demodulator_priv;
454 454
455 dprintk("%s(%d)\n", __FUNCTION__, enable); 455 dprintk("%s(%d)\n", __func__, enable);
456 456
457 return s5h1409_writereg(state, 0xf2, enable); 457 return s5h1409_writereg(state, 0xf2, enable);
458} 458}
@@ -461,7 +461,7 @@ static int s5h1409_register_reset(struct dvb_frontend* fe)
461{ 461{
462 struct s5h1409_state* state = fe->demodulator_priv; 462 struct s5h1409_state* state = fe->demodulator_priv;
463 463
464 dprintk("%s()\n", __FUNCTION__); 464 dprintk("%s()\n", __func__);
465 465
466 return s5h1409_writereg(state, 0xfa, 0); 466 return s5h1409_writereg(state, 0xfa, 0);
467} 467}
@@ -534,7 +534,7 @@ static int s5h1409_set_frontend (struct dvb_frontend* fe,
534{ 534{
535 struct s5h1409_state* state = fe->demodulator_priv; 535 struct s5h1409_state* state = fe->demodulator_priv;
536 536
537 dprintk("%s(frequency=%d)\n", __FUNCTION__, p->frequency); 537 dprintk("%s(frequency=%d)\n", __func__, p->frequency);
538 538
539 s5h1409_softreset(fe); 539 s5h1409_softreset(fe);
540 540
@@ -565,7 +565,7 @@ static int s5h1409_set_mpeg_timing(struct dvb_frontend *fe, int mode)
565 struct s5h1409_state *state = fe->demodulator_priv; 565 struct s5h1409_state *state = fe->demodulator_priv;
566 u16 val; 566 u16 val;
567 567
568 dprintk("%s(%d)\n", __FUNCTION__, mode); 568 dprintk("%s(%d)\n", __func__, mode);
569 569
570 val = s5h1409_readreg(state, 0xac) & 0xcfff; 570 val = s5h1409_readreg(state, 0xac) & 0xcfff;
571 switch (mode) { 571 switch (mode) {
@@ -573,7 +573,7 @@ static int s5h1409_set_mpeg_timing(struct dvb_frontend *fe, int mode)
573 val |= 0x0000; 573 val |= 0x0000;
574 break; 574 break;
575 case S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK: 575 case S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK:
576 dprintk("%s(%d) Mode1 or Defaulting\n", __FUNCTION__, mode); 576 dprintk("%s(%d) Mode1 or Defaulting\n", __func__, mode);
577 val |= 0x1000; 577 val |= 0x1000;
578 break; 578 break;
579 case S5H1409_MPEGTIMING_NONCONTINOUS_INVERTING_CLOCK: 579 case S5H1409_MPEGTIMING_NONCONTINOUS_INVERTING_CLOCK:
@@ -597,7 +597,7 @@ static int s5h1409_init (struct dvb_frontend* fe)
597 int i; 597 int i;
598 598
599 struct s5h1409_state* state = fe->demodulator_priv; 599 struct s5h1409_state* state = fe->demodulator_priv;
600 dprintk("%s()\n", __FUNCTION__); 600 dprintk("%s()\n", __func__);
601 601
602 s5h1409_sleep(fe, 0); 602 s5h1409_sleep(fe, 0);
603 s5h1409_register_reset(fe); 603 s5h1409_register_reset(fe);
@@ -663,7 +663,7 @@ static int s5h1409_read_status(struct dvb_frontend* fe, fe_status_t* status)
663 break; 663 break;
664 } 664 }
665 665
666 dprintk("%s() status 0x%08x\n", __FUNCTION__, *status); 666 dprintk("%s() status 0x%08x\n", __func__, *status);
667 667
668 return 0; 668 return 0;
669} 669}
@@ -671,7 +671,7 @@ static int s5h1409_read_status(struct dvb_frontend* fe, fe_status_t* status)
671static int s5h1409_qam256_lookup_snr(struct dvb_frontend* fe, u16* snr, u16 v) 671static int s5h1409_qam256_lookup_snr(struct dvb_frontend* fe, u16* snr, u16 v)
672{ 672{
673 int i, ret = -EINVAL; 673 int i, ret = -EINVAL;
674 dprintk("%s()\n", __FUNCTION__); 674 dprintk("%s()\n", __func__);
675 675
676 for (i=0; i < ARRAY_SIZE(qam256_snr_tab); i++) { 676 for (i=0; i < ARRAY_SIZE(qam256_snr_tab); i++) {
677 if (v < qam256_snr_tab[i].val) { 677 if (v < qam256_snr_tab[i].val) {
@@ -686,7 +686,7 @@ static int s5h1409_qam256_lookup_snr(struct dvb_frontend* fe, u16* snr, u16 v)
686static int s5h1409_qam64_lookup_snr(struct dvb_frontend* fe, u16* snr, u16 v) 686static int s5h1409_qam64_lookup_snr(struct dvb_frontend* fe, u16* snr, u16 v)
687{ 687{
688 int i, ret = -EINVAL; 688 int i, ret = -EINVAL;
689 dprintk("%s()\n", __FUNCTION__); 689 dprintk("%s()\n", __func__);
690 690
691 for (i=0; i < ARRAY_SIZE(qam64_snr_tab); i++) { 691 for (i=0; i < ARRAY_SIZE(qam64_snr_tab); i++) {
692 if (v < qam64_snr_tab[i].val) { 692 if (v < qam64_snr_tab[i].val) {
@@ -701,7 +701,7 @@ static int s5h1409_qam64_lookup_snr(struct dvb_frontend* fe, u16* snr, u16 v)
701static int s5h1409_vsb_lookup_snr(struct dvb_frontend* fe, u16* snr, u16 v) 701static int s5h1409_vsb_lookup_snr(struct dvb_frontend* fe, u16* snr, u16 v)
702{ 702{
703 int i, ret = -EINVAL; 703 int i, ret = -EINVAL;
704 dprintk("%s()\n", __FUNCTION__); 704 dprintk("%s()\n", __func__);
705 705
706 for (i=0; i < ARRAY_SIZE(vsb_snr_tab); i++) { 706 for (i=0; i < ARRAY_SIZE(vsb_snr_tab); i++) {
707 if (v > vsb_snr_tab[i].val) { 707 if (v > vsb_snr_tab[i].val) {
@@ -710,7 +710,7 @@ static int s5h1409_vsb_lookup_snr(struct dvb_frontend* fe, u16* snr, u16 v)
710 break; 710 break;
711 } 711 }
712 } 712 }
713 dprintk("%s() snr=%d\n", __FUNCTION__, *snr); 713 dprintk("%s() snr=%d\n", __func__, *snr);
714 return ret; 714 return ret;
715} 715}
716 716
@@ -718,7 +718,7 @@ static int s5h1409_read_snr(struct dvb_frontend* fe, u16* snr)
718{ 718{
719 struct s5h1409_state* state = fe->demodulator_priv; 719 struct s5h1409_state* state = fe->demodulator_priv;
720 u16 reg; 720 u16 reg;
721 dprintk("%s()\n", __FUNCTION__); 721 dprintk("%s()\n", __func__);
722 722
723 switch(state->current_modulation) { 723 switch(state->current_modulation) {
724 case QAM_64: 724 case QAM_64:
@@ -812,7 +812,7 @@ struct dvb_frontend* s5h1409_attach(const struct s5h1409_config* config,
812 812
813 if (s5h1409_init(&state->frontend) != 0) { 813 if (s5h1409_init(&state->frontend) != 0) {
814 printk(KERN_ERR "%s: Failed to initialize correctly\n", 814 printk(KERN_ERR "%s: Failed to initialize correctly\n",
815 __FUNCTION__); 815 __func__);
816 goto error; 816 goto error;
817 } 817 }
818 818
diff --git a/drivers/media/dvb/frontends/s5h1409.h b/drivers/media/dvb/frontends/s5h1409.h
index f0bb13fe808b..59f4335964c6 100644
--- a/drivers/media/dvb/frontends/s5h1409.h
+++ b/drivers/media/dvb/frontends/s5h1409.h
@@ -67,7 +67,7 @@ extern struct dvb_frontend* s5h1409_attach(const struct s5h1409_config* config,
67static inline struct dvb_frontend* s5h1409_attach(const struct s5h1409_config* config, 67static inline struct dvb_frontend* s5h1409_attach(const struct s5h1409_config* config,
68 struct i2c_adapter* i2c) 68 struct i2c_adapter* i2c)
69{ 69{
70 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 70 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
71 return NULL; 71 return NULL;
72} 72}
73#endif /* CONFIG_DVB_S5H1409 */ 73#endif /* CONFIG_DVB_S5H1409 */
diff --git a/drivers/media/dvb/frontends/s5h1420.c b/drivers/media/dvb/frontends/s5h1420.c
index 2c2c344c4c64..281e1cb2edc6 100644
--- a/drivers/media/dvb/frontends/s5h1420.c
+++ b/drivers/media/dvb/frontends/s5h1420.c
@@ -1,24 +1,26 @@
1/* 1/*
2Driver for Samsung S5H1420 QPSK Demodulator 2 * Driver for
3 3 * Samsung S5H1420 and
4Copyright (C) 2005 Andrew de Quincey <adq_dvb@lidskialf.net> 4 * PnpNetwork PN1010 QPSK Demodulator
5 5 *
6This program is free software; you can redistribute it and/or modify 6 * Copyright (C) 2005 Andrew de Quincey <adq_dvb@lidskialf.net>
7it under the terms of the GNU General Public License as published by 7 * Copyright (C) 2005-8 Patrick Boettcher <pb@linuxtv.org>
8the Free Software Foundation; either version 2 of the License, or 8 *
9(at your option) any later version. 9 * This program is free software; you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
11This program is distributed in the hope that it will be useful, 11 * the Free Software Foundation; either version 2 of the License, or
12but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * (at your option) any later version.
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 *
14 14 * This program is distributed in the hope that it will be useful,
15GNU General Public License for more details. 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17You should have received a copy of the GNU General Public License 17 *
18along with this program; if not, write to the Free Software 18 * GNU General Public License for more details.
19Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 *
20 20 * You should have received a copy of the GNU General Public License
21*/ 21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
22 24
23#include <linux/kernel.h> 25#include <linux/kernel.h>
24#include <linux/module.h> 26#include <linux/module.h>
@@ -29,23 +31,35 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29#include <linux/jiffies.h> 31#include <linux/jiffies.h>
30#include <asm/div64.h> 32#include <asm/div64.h>
31 33
32#include "dvb_frontend.h" 34#include <linux/i2c.h>
33#include "s5h1420.h"
34 35
35 36
37#include "dvb_frontend.h"
38#include "s5h1420.h"
39#include "s5h1420_priv.h"
36 40
37#define TONE_FREQ 22000 41#define TONE_FREQ 22000
38 42
39struct s5h1420_state { 43struct s5h1420_state {
40 struct i2c_adapter* i2c; 44 struct i2c_adapter* i2c;
41 const struct s5h1420_config* config; 45 const struct s5h1420_config* config;
46
42 struct dvb_frontend frontend; 47 struct dvb_frontend frontend;
48 struct i2c_adapter tuner_i2c_adapter;
49
50 u8 CON_1_val;
43 51
44 u8 postlocked:1; 52 u8 postlocked:1;
45 u32 fclk; 53 u32 fclk;
46 u32 tunedfreq; 54 u32 tunedfreq;
47 fe_code_rate_t fec_inner; 55 fe_code_rate_t fec_inner;
48 u32 symbol_rate; 56 u32 symbol_rate;
57
58 /* FIXME: ugly workaround for flexcop's incapable i2c-controller
59 * it does not support repeated-start, workaround: write addr-1
60 * and then read
61 */
62 u8 shadow[255];
49}; 63};
50 64
51static u32 s5h1420_getsymbolrate(struct s5h1420_state* state); 65static u32 s5h1420_getsymbolrate(struct s5h1420_state* state);
@@ -53,44 +67,66 @@ static int s5h1420_get_tune_settings(struct dvb_frontend* fe,
53 struct dvb_frontend_tune_settings* fesettings); 67 struct dvb_frontend_tune_settings* fesettings);
54 68
55 69
56static int debug = 0; 70static int debug;
57#define dprintk if (debug) printk 71module_param(debug, int, 0644);
72MODULE_PARM_DESC(debug, "enable debugging");
73
74#define dprintk(x...) do { \
75 if (debug) \
76 printk(KERN_DEBUG "S5H1420: " x); \
77} while (0)
78
79static u8 s5h1420_readreg(struct s5h1420_state *state, u8 reg)
80{
81 int ret;
82 u8 b[2];
83 struct i2c_msg msg[] = {
84 { .addr = state->config->demod_address, .flags = 0, .buf = b, .len = 2 },
85 { .addr = state->config->demod_address, .flags = 0, .buf = &reg, .len = 1 },
86 { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = b, .len = 1 },
87 };
88
89 b[0] = (reg - 1) & 0xff;
90 b[1] = state->shadow[(reg - 1) & 0xff];
91
92 if (state->config->repeated_start_workaround) {
93 ret = i2c_transfer(state->i2c, msg, 3);
94 if (ret != 3)
95 return ret;
96 } else {
97 ret = i2c_transfer(state->i2c, &msg[1], 2);
98 if (ret != 2)
99 return ret;
100 }
101
102 /* dprintk("rd(%02x): %02x %02x\n", state->config->demod_address, reg, b[0]); */
103
104 return b[0];
105}
58 106
59static int s5h1420_writereg (struct s5h1420_state* state, u8 reg, u8 data) 107static int s5h1420_writereg (struct s5h1420_state* state, u8 reg, u8 data)
60{ 108{
61 u8 buf [] = { reg, data }; 109 u8 buf[] = { reg, data };
62 struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = buf, .len = 2 }; 110 struct i2c_msg msg = { .addr = state->config->demod_address, .flags = 0, .buf = buf, .len = 2 };
63 int err; 111 int err;
64 112
65 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) { 113 /* dprintk("wr(%02x): %02x %02x\n", state->config->demod_address, reg, data); */
66 dprintk ("%s: writereg error (err == %i, reg == 0x%02x, data == 0x%02x)\n", __FUNCTION__, err, reg, data); 114 err = i2c_transfer(state->i2c, &msg, 1);
115 if (err != 1) {
116 dprintk("%s: writereg error (err == %i, reg == 0x%02x, data == 0x%02x)\n", __func__, err, reg, data);
67 return -EREMOTEIO; 117 return -EREMOTEIO;
68 } 118 }
119 state->shadow[reg] = data;
69 120
70 return 0; 121 return 0;
71} 122}
72 123
73static u8 s5h1420_readreg (struct s5h1420_state* state, u8 reg)
74{
75 int ret;
76 u8 b0 [] = { reg };
77 u8 b1 [] = { 0 };
78 struct i2c_msg msg1 = { .addr = state->config->demod_address, .flags = 0, .buf = b0, .len = 1 };
79 struct i2c_msg msg2 = { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = b1, .len = 1 };
80
81 if ((ret = i2c_transfer (state->i2c, &msg1, 1)) != 1)
82 return ret;
83
84 if ((ret = i2c_transfer (state->i2c, &msg2, 1)) != 1)
85 return ret;
86
87 return b1[0];
88}
89
90static int s5h1420_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltage) 124static int s5h1420_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltage)
91{ 125{
92 struct s5h1420_state* state = fe->demodulator_priv; 126 struct s5h1420_state* state = fe->demodulator_priv;
93 127
128 dprintk("enter %s\n", __func__);
129
94 switch(voltage) { 130 switch(voltage) {
95 case SEC_VOLTAGE_13: 131 case SEC_VOLTAGE_13:
96 s5h1420_writereg(state, 0x3c, 132 s5h1420_writereg(state, 0x3c,
@@ -106,6 +142,7 @@ static int s5h1420_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltag
106 break; 142 break;
107 } 143 }
108 144
145 dprintk("leave %s\n", __func__);
109 return 0; 146 return 0;
110} 147}
111 148
@@ -113,6 +150,7 @@ static int s5h1420_set_tone (struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
113{ 150{
114 struct s5h1420_state* state = fe->demodulator_priv; 151 struct s5h1420_state* state = fe->demodulator_priv;
115 152
153 dprintk("enter %s\n", __func__);
116 switch(tone) { 154 switch(tone) {
117 case SEC_TONE_ON: 155 case SEC_TONE_ON:
118 s5h1420_writereg(state, 0x3b, 156 s5h1420_writereg(state, 0x3b,
@@ -124,6 +162,7 @@ static int s5h1420_set_tone (struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
124 (s5h1420_readreg(state, 0x3b) & 0x74) | 0x01); 162 (s5h1420_readreg(state, 0x3b) & 0x74) | 0x01);
125 break; 163 break;
126 } 164 }
165 dprintk("leave %s\n", __func__);
127 166
128 return 0; 167 return 0;
129} 168}
@@ -137,6 +176,7 @@ static int s5h1420_send_master_cmd (struct dvb_frontend* fe,
137 unsigned long timeout; 176 unsigned long timeout;
138 int result = 0; 177 int result = 0;
139 178
179 dprintk("enter %s\n", __func__);
140 if (cmd->msg_len > 8) 180 if (cmd->msg_len > 8)
141 return -EINVAL; 181 return -EINVAL;
142 182
@@ -168,6 +208,7 @@ static int s5h1420_send_master_cmd (struct dvb_frontend* fe,
168 /* restore original settings */ 208 /* restore original settings */
169 s5h1420_writereg(state, 0x3b, val); 209 s5h1420_writereg(state, 0x3b, val);
170 msleep(15); 210 msleep(15);
211 dprintk("leave %s\n", __func__);
171 return result; 212 return result;
172} 213}
173 214
@@ -289,6 +330,8 @@ static int s5h1420_read_status(struct dvb_frontend* fe, fe_status_t* status)
289 struct s5h1420_state* state = fe->demodulator_priv; 330 struct s5h1420_state* state = fe->demodulator_priv;
290 u8 val; 331 u8 val;
291 332
333 dprintk("enter %s\n", __func__);
334
292 if (status == NULL) 335 if (status == NULL)
293 return -EINVAL; 336 return -EINVAL;
294 337
@@ -297,13 +340,13 @@ static int s5h1420_read_status(struct dvb_frontend* fe, fe_status_t* status)
297 340
298 /* fix for FEC 5/6 inversion issue - if it doesn't quite lock, invert 341 /* fix for FEC 5/6 inversion issue - if it doesn't quite lock, invert
299 the inversion, wait a bit and check again */ 342 the inversion, wait a bit and check again */
300 if (*status == (FE_HAS_SIGNAL|FE_HAS_CARRIER|FE_HAS_VITERBI)) { 343 if (*status == (FE_HAS_SIGNAL | FE_HAS_CARRIER | FE_HAS_VITERBI)) {
301 val = s5h1420_readreg(state, 0x32); 344 val = s5h1420_readreg(state, Vit10);
302 if ((val & 0x07) == 0x03) { 345 if ((val & 0x07) == 0x03) {
303 if (val & 0x08) 346 if (val & 0x08)
304 s5h1420_writereg(state, 0x31, 0x13); 347 s5h1420_writereg(state, Vit09, 0x13);
305 else 348 else
306 s5h1420_writereg(state, 0x31, 0x1b); 349 s5h1420_writereg(state, Vit09, 0x1b);
307 350
308 /* wait a bit then update lock status */ 351 /* wait a bit then update lock status */
309 mdelay(200); 352 mdelay(200);
@@ -312,68 +355,73 @@ static int s5h1420_read_status(struct dvb_frontend* fe, fe_status_t* status)
312 } 355 }
313 356
314 /* perform post lock setup */ 357 /* perform post lock setup */
315 if ((*status & FE_HAS_LOCK) && (!state->postlocked)) { 358 if ((*status & FE_HAS_LOCK) && !state->postlocked) {
316 359
317 /* calculate the data rate */ 360 /* calculate the data rate */
318 u32 tmp = s5h1420_getsymbolrate(state); 361 u32 tmp = s5h1420_getsymbolrate(state);
319 switch(s5h1420_readreg(state, 0x32) & 0x07) { 362 switch (s5h1420_readreg(state, Vit10) & 0x07) {
320 case 0: 363 case 0: tmp = (tmp * 2 * 1) / 2; break;
321 tmp = (tmp * 2 * 1) / 2; 364 case 1: tmp = (tmp * 2 * 2) / 3; break;
322 break; 365 case 2: tmp = (tmp * 2 * 3) / 4; break;
323 366 case 3: tmp = (tmp * 2 * 5) / 6; break;
324 case 1: 367 case 4: tmp = (tmp * 2 * 6) / 7; break;
325 tmp = (tmp * 2 * 2) / 3; 368 case 5: tmp = (tmp * 2 * 7) / 8; break;
326 break;
327
328 case 2:
329 tmp = (tmp * 2 * 3) / 4;
330 break;
331
332 case 3:
333 tmp = (tmp * 2 * 5) / 6;
334 break;
335
336 case 4:
337 tmp = (tmp * 2 * 6) / 7;
338 break;
339
340 case 5:
341 tmp = (tmp * 2 * 7) / 8;
342 break;
343 } 369 }
370
344 if (tmp == 0) { 371 if (tmp == 0) {
345 printk("s5h1420: avoided division by 0\n"); 372 printk(KERN_ERR "s5h1420: avoided division by 0\n");
346 tmp = 1; 373 tmp = 1;
347 } 374 }
348 tmp = state->fclk / tmp; 375 tmp = state->fclk / tmp;
349 376
377
350 /* set the MPEG_CLK_INTL for the calculated data rate */ 378 /* set the MPEG_CLK_INTL for the calculated data rate */
351 if (tmp < 4) 379 if (tmp < 2)
352 val = 0x00; 380 val = 0x00;
353 else if (tmp < 8) 381 else if (tmp < 5)
354 val = 0x01; 382 val = 0x01;
355 else if (tmp < 12) 383 else if (tmp < 9)
356 val = 0x02; 384 val = 0x02;
357 else if (tmp < 16) 385 else if (tmp < 13)
358 val = 0x03; 386 val = 0x03;
359 else if (tmp < 24) 387 else if (tmp < 17)
360 val = 0x04; 388 val = 0x04;
361 else if (tmp < 32) 389 else if (tmp < 25)
362 val = 0x05; 390 val = 0x05;
363 else 391 else if (tmp < 33)
364 val = 0x06; 392 val = 0x06;
365 s5h1420_writereg(state, 0x22, val); 393 else
394 val = 0x07;
395 dprintk("for MPEG_CLK_INTL %d %x\n", tmp, val);
396
397 s5h1420_writereg(state, FEC01, 0x18);
398 s5h1420_writereg(state, FEC01, 0x10);
399 s5h1420_writereg(state, FEC01, val);
400
401 /* Enable "MPEG_Out" */
402 val = s5h1420_readreg(state, Mpeg02);
403 s5h1420_writereg(state, Mpeg02, val | (1 << 6));
366 404
367 /* DC freeze */ 405 /* kicker disable */
368 s5h1420_writereg(state, 0x1f, s5h1420_readreg(state, 0x1f) | 0x01); 406 val = s5h1420_readreg(state, QPSK01) & 0x7f;
407 s5h1420_writereg(state, QPSK01, val);
369 408
370 /* kicker disable + remove DC offset */ 409 /* DC freeze TODO it was never activated by default or it can stay activated */
371 s5h1420_writereg(state, 0x05, s5h1420_readreg(state, 0x05) & 0x6f); 410
411 if (s5h1420_getsymbolrate(state) >= 20000000) {
412 s5h1420_writereg(state, Loop04, 0x8a);
413 s5h1420_writereg(state, Loop05, 0x6a);
414 } else {
415 s5h1420_writereg(state, Loop04, 0x58);
416 s5h1420_writereg(state, Loop05, 0x27);
417 }
372 418
373 /* post-lock processing has been done! */ 419 /* post-lock processing has been done! */
374 state->postlocked = 1; 420 state->postlocked = 1;
375 } 421 }
376 422
423 dprintk("leave %s\n", __func__);
424
377 return 0; 425 return 0;
378} 426}
379 427
@@ -414,6 +462,7 @@ static int s5h1420_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
414 462
415static void s5h1420_reset(struct s5h1420_state* state) 463static void s5h1420_reset(struct s5h1420_state* state)
416{ 464{
465 dprintk("%s\n", __func__);
417 s5h1420_writereg (state, 0x01, 0x08); 466 s5h1420_writereg (state, 0x01, 0x08);
418 s5h1420_writereg (state, 0x01, 0x00); 467 s5h1420_writereg (state, 0x01, 0x00);
419 udelay(10); 468 udelay(10);
@@ -422,54 +471,52 @@ static void s5h1420_reset(struct s5h1420_state* state)
422static void s5h1420_setsymbolrate(struct s5h1420_state* state, 471static void s5h1420_setsymbolrate(struct s5h1420_state* state,
423 struct dvb_frontend_parameters *p) 472 struct dvb_frontend_parameters *p)
424{ 473{
474 u8 v;
425 u64 val; 475 u64 val;
426 476
477 dprintk("enter %s\n", __func__);
478
427 val = ((u64) p->u.qpsk.symbol_rate / 1000ULL) * (1ULL<<24); 479 val = ((u64) p->u.qpsk.symbol_rate / 1000ULL) * (1ULL<<24);
428 if (p->u.qpsk.symbol_rate <= 21000000) { 480 if (p->u.qpsk.symbol_rate < 29000000)
429 val *= 2; 481 val *= 2;
430 }
431 do_div(val, (state->fclk / 1000)); 482 do_div(val, (state->fclk / 1000));
432 483
433 s5h1420_writereg(state, 0x09, s5h1420_readreg(state, 0x09) & 0x7f); 484 dprintk("symbol rate register: %06llx\n", val);
434 s5h1420_writereg(state, 0x11, val >> 16); 485
435 s5h1420_writereg(state, 0x12, val >> 8); 486 v = s5h1420_readreg(state, Loop01);
436 s5h1420_writereg(state, 0x13, val & 0xff); 487 s5h1420_writereg(state, Loop01, v & 0x7f);
437 s5h1420_writereg(state, 0x09, s5h1420_readreg(state, 0x09) | 0x80); 488 s5h1420_writereg(state, Tnco01, val >> 16);
489 s5h1420_writereg(state, Tnco02, val >> 8);
490 s5h1420_writereg(state, Tnco03, val & 0xff);
491 s5h1420_writereg(state, Loop01, v | 0x80);
492 dprintk("leave %s\n", __func__);
438} 493}
439 494
440static u32 s5h1420_getsymbolrate(struct s5h1420_state* state) 495static u32 s5h1420_getsymbolrate(struct s5h1420_state* state)
441{ 496{
442 u64 val = 0; 497 return state->symbol_rate;
443 int sampling = 2;
444
445 if (s5h1420_readreg(state, 0x05) & 0x2)
446 sampling = 1;
447
448 s5h1420_writereg(state, 0x06, s5h1420_readreg(state, 0x06) | 0x08);
449 val = s5h1420_readreg(state, 0x11) << 16;
450 val |= s5h1420_readreg(state, 0x12) << 8;
451 val |= s5h1420_readreg(state, 0x13);
452 s5h1420_writereg(state, 0x06, s5h1420_readreg(state, 0x06) & 0xf7);
453
454 val *= (state->fclk / 1000ULL);
455 do_div(val, ((1<<24) * sampling));
456
457 return (u32) (val * 1000ULL);
458} 498}
459 499
460static void s5h1420_setfreqoffset(struct s5h1420_state* state, int freqoffset) 500static void s5h1420_setfreqoffset(struct s5h1420_state* state, int freqoffset)
461{ 501{
462 int val; 502 int val;
503 u8 v;
504
505 dprintk("enter %s\n", __func__);
463 506
464 /* remember freqoffset is in kHz, but the chip wants the offset in Hz, so 507 /* remember freqoffset is in kHz, but the chip wants the offset in Hz, so
465 * divide fclk by 1000000 to get the correct value. */ 508 * divide fclk by 1000000 to get the correct value. */
466 val = -(int) ((freqoffset * (1<<24)) / (state->fclk / 1000000)); 509 val = -(int) ((freqoffset * (1<<24)) / (state->fclk / 1000000));
467 510
468 s5h1420_writereg(state, 0x09, s5h1420_readreg(state, 0x09) & 0xbf); 511 dprintk("phase rotator/freqoffset: %d %06x\n", freqoffset, val);
469 s5h1420_writereg(state, 0x0e, val >> 16); 512
470 s5h1420_writereg(state, 0x0f, val >> 8); 513 v = s5h1420_readreg(state, Loop01);
471 s5h1420_writereg(state, 0x10, val & 0xff); 514 s5h1420_writereg(state, Loop01, v & 0xbf);
472 s5h1420_writereg(state, 0x09, s5h1420_readreg(state, 0x09) | 0x40); 515 s5h1420_writereg(state, Pnco01, val >> 16);
516 s5h1420_writereg(state, Pnco02, val >> 8);
517 s5h1420_writereg(state, Pnco03, val & 0xff);
518 s5h1420_writereg(state, Loop01, v | 0x40);
519 dprintk("leave %s\n", __func__);
473} 520}
474 521
475static int s5h1420_getfreqoffset(struct s5h1420_state* state) 522static int s5h1420_getfreqoffset(struct s5h1420_state* state)
@@ -496,52 +543,53 @@ static void s5h1420_setfec_inversion(struct s5h1420_state* state,
496 struct dvb_frontend_parameters *p) 543 struct dvb_frontend_parameters *p)
497{ 544{
498 u8 inversion = 0; 545 u8 inversion = 0;
546 u8 vit08, vit09;
547
548 dprintk("enter %s\n", __func__);
499 549
500 if (p->inversion == INVERSION_OFF) { 550 if (p->inversion == INVERSION_OFF)
501 inversion = state->config->invert ? 0x08 : 0; 551 inversion = state->config->invert ? 0x08 : 0;
502 } else if (p->inversion == INVERSION_ON) { 552 else if (p->inversion == INVERSION_ON)
503 inversion = state->config->invert ? 0 : 0x08; 553 inversion = state->config->invert ? 0 : 0x08;
504 }
505 554
506 if ((p->u.qpsk.fec_inner == FEC_AUTO) || (p->inversion == INVERSION_AUTO)) { 555 if ((p->u.qpsk.fec_inner == FEC_AUTO) || (p->inversion == INVERSION_AUTO)) {
507 s5h1420_writereg(state, 0x30, 0x3f); 556 vit08 = 0x3f;
508 s5h1420_writereg(state, 0x31, 0x00 | inversion); 557 vit09 = 0;
509 } else { 558 } else {
510 switch(p->u.qpsk.fec_inner) { 559 switch(p->u.qpsk.fec_inner) {
511 case FEC_1_2: 560 case FEC_1_2:
512 s5h1420_writereg(state, 0x30, 0x01); 561 vit08 = 0x01; vit09 = 0x10;
513 s5h1420_writereg(state, 0x31, 0x10 | inversion);
514 break; 562 break;
515 563
516 case FEC_2_3: 564 case FEC_2_3:
517 s5h1420_writereg(state, 0x30, 0x02); 565 vit08 = 0x02; vit09 = 0x11;
518 s5h1420_writereg(state, 0x31, 0x11 | inversion);
519 break; 566 break;
520 567
521 case FEC_3_4: 568 case FEC_3_4:
522 s5h1420_writereg(state, 0x30, 0x04); 569 vit08 = 0x04; vit09 = 0x12;
523 s5h1420_writereg(state, 0x31, 0x12 | inversion);
524 break; 570 break;
525 571
526 case FEC_5_6: 572 case FEC_5_6:
527 s5h1420_writereg(state, 0x30, 0x08); 573 vit08 = 0x08; vit09 = 0x13;
528 s5h1420_writereg(state, 0x31, 0x13 | inversion);
529 break; 574 break;
530 575
531 case FEC_6_7: 576 case FEC_6_7:
532 s5h1420_writereg(state, 0x30, 0x10); 577 vit08 = 0x10; vit09 = 0x14;
533 s5h1420_writereg(state, 0x31, 0x14 | inversion);
534 break; 578 break;
535 579
536 case FEC_7_8: 580 case FEC_7_8:
537 s5h1420_writereg(state, 0x30, 0x20); 581 vit08 = 0x20; vit09 = 0x15;
538 s5h1420_writereg(state, 0x31, 0x15 | inversion);
539 break; 582 break;
540 583
541 default: 584 default:
542 return; 585 return;
543 } 586 }
544 } 587 }
588 vit09 |= inversion;
589 dprintk("fec: %02x %02x\n", vit08, vit09);
590 s5h1420_writereg(state, Vit08, vit08);
591 s5h1420_writereg(state, Vit09, vit09);
592 dprintk("leave %s\n", __func__);
545} 593}
546 594
547static fe_code_rate_t s5h1420_getfec(struct s5h1420_state* state) 595static fe_code_rate_t s5h1420_getfec(struct s5h1420_state* state)
@@ -583,16 +631,19 @@ static int s5h1420_set_frontend(struct dvb_frontend* fe,
583 struct s5h1420_state* state = fe->demodulator_priv; 631 struct s5h1420_state* state = fe->demodulator_priv;
584 int frequency_delta; 632 int frequency_delta;
585 struct dvb_frontend_tune_settings fesettings; 633 struct dvb_frontend_tune_settings fesettings;
634 uint8_t clock_settting;
635
636 dprintk("enter %s\n", __func__);
586 637
587 /* check if we should do a fast-tune */ 638 /* check if we should do a fast-tune */
588 memcpy(&fesettings.parameters, p, sizeof(struct dvb_frontend_parameters)); 639 memcpy(&fesettings.parameters, p, sizeof(struct dvb_frontend_parameters));
589 s5h1420_get_tune_settings(fe, &fesettings); 640 s5h1420_get_tune_settings(fe, &fesettings);
590 frequency_delta = p->frequency - state->tunedfreq; 641 frequency_delta = p->frequency - state->tunedfreq;
591 if ((frequency_delta > -fesettings.max_drift) && 642 if ((frequency_delta > -fesettings.max_drift) &&
592 (frequency_delta < fesettings.max_drift) && 643 (frequency_delta < fesettings.max_drift) &&
593 (frequency_delta != 0) && 644 (frequency_delta != 0) &&
594 (state->fec_inner == p->u.qpsk.fec_inner) && 645 (state->fec_inner == p->u.qpsk.fec_inner) &&
595 (state->symbol_rate == p->u.qpsk.symbol_rate)) { 646 (state->symbol_rate == p->u.qpsk.symbol_rate)) {
596 647
597 if (fe->ops.tuner_ops.set_params) { 648 if (fe->ops.tuner_ops.set_params) {
598 fe->ops.tuner_ops.set_params(fe, p); 649 fe->ops.tuner_ops.set_params(fe, p);
@@ -606,54 +657,93 @@ static int s5h1420_set_frontend(struct dvb_frontend* fe,
606 } else { 657 } else {
607 s5h1420_setfreqoffset(state, 0); 658 s5h1420_setfreqoffset(state, 0);
608 } 659 }
660 dprintk("simple tune\n");
609 return 0; 661 return 0;
610 } 662 }
663 dprintk("tuning demod\n");
611 664
612 /* first of all, software reset */ 665 /* first of all, software reset */
613 s5h1420_reset(state); 666 s5h1420_reset(state);
614 667
615 /* set s5h1420 fclk PLL according to desired symbol rate */ 668 /* set s5h1420 fclk PLL according to desired symbol rate */
616 if (p->u.qpsk.symbol_rate > 28000000) { 669 if (p->u.qpsk.symbol_rate > 33000000)
617 state->fclk = 88000000; 670 state->fclk = 80000000;
618 s5h1420_writereg(state, 0x03, 0x50); 671 else if (p->u.qpsk.symbol_rate > 28500000)
619 s5h1420_writereg(state, 0x04, 0x40);
620 s5h1420_writereg(state, 0x05, 0xae);
621 } else if (p->u.qpsk.symbol_rate > 21000000) {
622 state->fclk = 59000000; 672 state->fclk = 59000000;
623 s5h1420_writereg(state, 0x03, 0x33); 673 else if (p->u.qpsk.symbol_rate > 25000000)
624 s5h1420_writereg(state, 0x04, 0x40); 674 state->fclk = 86000000;
625 s5h1420_writereg(state, 0x05, 0xae); 675 else if (p->u.qpsk.symbol_rate > 1900000)
626 } else {
627 state->fclk = 88000000; 676 state->fclk = 88000000;
628 s5h1420_writereg(state, 0x03, 0x50); 677 else
629 s5h1420_writereg(state, 0x04, 0x40); 678 state->fclk = 44000000;
630 s5h1420_writereg(state, 0x05, 0xac); 679
680 /* Clock */
681 switch (state->fclk) {
682 default:
683 case 88000000:
684 clock_settting = 80;
685 break;
686 case 86000000:
687 clock_settting = 78;
688 break;
689 case 80000000:
690 clock_settting = 72;
691 break;
692 case 59000000:
693 clock_settting = 51;
694 break;
695 case 44000000:
696 clock_settting = 36;
697 break;
631 } 698 }
699 dprintk("pll01: %d, ToneFreq: %d\n", state->fclk/1000000 - 8, (state->fclk + (TONE_FREQ * 32) - 1) / (TONE_FREQ * 32));
700 s5h1420_writereg(state, PLL01, state->fclk/1000000 - 8);
701 s5h1420_writereg(state, PLL02, 0x40);
702 s5h1420_writereg(state, DiS01, (state->fclk + (TONE_FREQ * 32) - 1) / (TONE_FREQ * 32));
632 703
633 /* set misc registers */ 704 /* TODO DC offset removal, config parameter ? */
634 s5h1420_writereg(state, 0x02, 0x00); 705 if (p->u.qpsk.symbol_rate > 29000000)
635 s5h1420_writereg(state, 0x06, 0x00); 706 s5h1420_writereg(state, QPSK01, 0xae | 0x10);
636 s5h1420_writereg(state, 0x07, 0xb0); 707 else
637 s5h1420_writereg(state, 0x0a, 0xe7); 708 s5h1420_writereg(state, QPSK01, 0xac | 0x10);
638 s5h1420_writereg(state, 0x0b, 0x78);
639 s5h1420_writereg(state, 0x0c, 0x48);
640 s5h1420_writereg(state, 0x0d, 0x6b);
641 s5h1420_writereg(state, 0x2e, 0x8e);
642 s5h1420_writereg(state, 0x35, 0x33);
643 s5h1420_writereg(state, 0x38, 0x01);
644 s5h1420_writereg(state, 0x39, 0x7d);
645 s5h1420_writereg(state, 0x3a, (state->fclk + (TONE_FREQ * 32) - 1) / (TONE_FREQ * 32));
646 s5h1420_writereg(state, 0x3c, 0x00);
647 s5h1420_writereg(state, 0x45, 0x61);
648 s5h1420_writereg(state, 0x46, 0x1d);
649 709
650 /* start QPSK */ 710 /* set misc registers */
651 s5h1420_writereg(state, 0x05, s5h1420_readreg(state, 0x05) | 1); 711 s5h1420_writereg(state, CON_1, 0x00);
712 s5h1420_writereg(state, QPSK02, 0x00);
713 s5h1420_writereg(state, Pre01, 0xb0);
714
715 s5h1420_writereg(state, Loop01, 0xF0);
716 s5h1420_writereg(state, Loop02, 0x2a); /* e7 for s5h1420 */
717 s5h1420_writereg(state, Loop03, 0x79); /* 78 for s5h1420 */
718 if (p->u.qpsk.symbol_rate > 20000000)
719 s5h1420_writereg(state, Loop04, 0x79);
720 else
721 s5h1420_writereg(state, Loop04, 0x58);
722 s5h1420_writereg(state, Loop05, 0x6b);
723
724 if (p->u.qpsk.symbol_rate >= 8000000)
725 s5h1420_writereg(state, Post01, (0 << 6) | 0x10);
726 else if (p->u.qpsk.symbol_rate >= 4000000)
727 s5h1420_writereg(state, Post01, (1 << 6) | 0x10);
728 else
729 s5h1420_writereg(state, Post01, (3 << 6) | 0x10);
730
731 s5h1420_writereg(state, Monitor12, 0x00); /* unfreeze DC compensation */
732
733 s5h1420_writereg(state, Sync01, 0x33);
734 s5h1420_writereg(state, Mpeg01, state->config->cdclk_polarity);
735 s5h1420_writereg(state, Mpeg02, 0x3d); /* Parallel output more, disabled -> enabled later */
736 s5h1420_writereg(state, Err01, 0x03); /* 0x1d for s5h1420 */
737
738 s5h1420_writereg(state, Vit06, 0x6e); /* 0x8e for s5h1420 */
739 s5h1420_writereg(state, DiS03, 0x00);
740 s5h1420_writereg(state, Rf01, 0x61); /* Tuner i2c address - for the gate controller */
652 741
653 /* set tuner PLL */ 742 /* set tuner PLL */
654 if (fe->ops.tuner_ops.set_params) { 743 if (fe->ops.tuner_ops.set_params) {
655 fe->ops.tuner_ops.set_params(fe, p); 744 fe->ops.tuner_ops.set_params(fe, p);
656 if (fe->ops.i2c_gate_ctrl) fe->ops.i2c_gate_ctrl(fe, 0); 745 if (fe->ops.i2c_gate_ctrl)
746 fe->ops.i2c_gate_ctrl(fe, 0);
657 s5h1420_setfreqoffset(state, 0); 747 s5h1420_setfreqoffset(state, 0);
658 } 748 }
659 749
@@ -661,10 +751,15 @@ static int s5h1420_set_frontend(struct dvb_frontend* fe,
661 s5h1420_setsymbolrate(state, p); 751 s5h1420_setsymbolrate(state, p);
662 s5h1420_setfec_inversion(state, p); 752 s5h1420_setfec_inversion(state, p);
663 753
754 /* start QPSK */
755 s5h1420_writereg(state, QPSK01, s5h1420_readreg(state, QPSK01) | 1);
756
664 state->fec_inner = p->u.qpsk.fec_inner; 757 state->fec_inner = p->u.qpsk.fec_inner;
665 state->symbol_rate = p->u.qpsk.symbol_rate; 758 state->symbol_rate = p->u.qpsk.symbol_rate;
666 state->postlocked = 0; 759 state->postlocked = 0;
667 state->tunedfreq = p->frequency; 760 state->tunedfreq = p->frequency;
761
762 dprintk("leave %s\n", __func__);
668 return 0; 763 return 0;
669} 764}
670 765
@@ -717,11 +812,10 @@ static int s5h1420_i2c_gate_ctrl(struct dvb_frontend* fe, int enable)
717{ 812{
718 struct s5h1420_state* state = fe->demodulator_priv; 813 struct s5h1420_state* state = fe->demodulator_priv;
719 814
720 if (enable) { 815 if (enable)
721 return s5h1420_writereg (state, 0x02, s5h1420_readreg(state,0x02) | 1); 816 return s5h1420_writereg(state, 0x02, state->CON_1_val | 1);
722 } else { 817 else
723 return s5h1420_writereg (state, 0x02, s5h1420_readreg(state,0x02) & 0xfe); 818 return s5h1420_writereg(state, 0x02, state->CON_1_val & 0xfe);
724 }
725} 819}
726 820
727static int s5h1420_init (struct dvb_frontend* fe) 821static int s5h1420_init (struct dvb_frontend* fe)
@@ -729,7 +823,8 @@ static int s5h1420_init (struct dvb_frontend* fe)
729 struct s5h1420_state* state = fe->demodulator_priv; 823 struct s5h1420_state* state = fe->demodulator_priv;
730 824
731 /* disable power down and do reset */ 825 /* disable power down and do reset */
732 s5h1420_writereg(state, 0x02, 0x10); 826 state->CON_1_val = 0x10;
827 s5h1420_writereg(state, 0x02, state->CON_1_val);
733 msleep(10); 828 msleep(10);
734 s5h1420_reset(state); 829 s5h1420_reset(state);
735 830
@@ -739,26 +834,60 @@ static int s5h1420_init (struct dvb_frontend* fe)
739static int s5h1420_sleep(struct dvb_frontend* fe) 834static int s5h1420_sleep(struct dvb_frontend* fe)
740{ 835{
741 struct s5h1420_state* state = fe->demodulator_priv; 836 struct s5h1420_state* state = fe->demodulator_priv;
742 837 state->CON_1_val = 0x12;
743 return s5h1420_writereg(state, 0x02, 0x12); 838 return s5h1420_writereg(state, 0x02, state->CON_1_val);
744} 839}
745 840
746static void s5h1420_release(struct dvb_frontend* fe) 841static void s5h1420_release(struct dvb_frontend* fe)
747{ 842{
748 struct s5h1420_state* state = fe->demodulator_priv; 843 struct s5h1420_state* state = fe->demodulator_priv;
844 i2c_del_adapter(&state->tuner_i2c_adapter);
749 kfree(state); 845 kfree(state);
750} 846}
751 847
752static struct dvb_frontend_ops s5h1420_ops; 848static u32 s5h1420_tuner_i2c_func(struct i2c_adapter *adapter)
849{
850 return I2C_FUNC_I2C;
851}
852
853static int s5h1420_tuner_i2c_tuner_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg msg[], int num)
854{
855 struct s5h1420_state *state = i2c_get_adapdata(i2c_adap);
856 struct i2c_msg m[1 + num];
857 u8 tx_open[2] = { CON_1, state->CON_1_val | 1 }; /* repeater stops once there was a stop condition */
858
859 memset(m, 0, sizeof(struct i2c_msg) * (1 + num));
860
861 m[0].addr = state->config->demod_address;
862 m[0].buf = tx_open;
863 m[0].len = 2;
753 864
754struct dvb_frontend* s5h1420_attach(const struct s5h1420_config* config, 865 memcpy(&m[1], msg, sizeof(struct i2c_msg) * num);
755 struct i2c_adapter* i2c) 866
867 return i2c_transfer(state->i2c, m, 1+num) == 1 + num ? num : -EIO;
868}
869
870static struct i2c_algorithm s5h1420_tuner_i2c_algo = {
871 .master_xfer = s5h1420_tuner_i2c_tuner_xfer,
872 .functionality = s5h1420_tuner_i2c_func,
873};
874
875struct i2c_adapter *s5h1420_get_tuner_i2c_adapter(struct dvb_frontend *fe)
756{ 876{
757 struct s5h1420_state* state = NULL; 877 struct s5h1420_state *state = fe->demodulator_priv;
758 u8 identity; 878 return &state->tuner_i2c_adapter;
879}
880EXPORT_SYMBOL(s5h1420_get_tuner_i2c_adapter);
881
882static struct dvb_frontend_ops s5h1420_ops;
759 883
884struct dvb_frontend *s5h1420_attach(const struct s5h1420_config *config,
885 struct i2c_adapter *i2c)
886{
760 /* allocate memory for the internal state */ 887 /* allocate memory for the internal state */
761 state = kmalloc(sizeof(struct s5h1420_state), GFP_KERNEL); 888 struct s5h1420_state *state = kzalloc(sizeof(struct s5h1420_state), GFP_KERNEL);
889 u8 i;
890
762 if (state == NULL) 891 if (state == NULL)
763 goto error; 892 goto error;
764 893
@@ -772,24 +901,42 @@ struct dvb_frontend* s5h1420_attach(const struct s5h1420_config* config,
772 state->symbol_rate = 0; 901 state->symbol_rate = 0;
773 902
774 /* check if the demod is there + identify it */ 903 /* check if the demod is there + identify it */
775 identity = s5h1420_readreg(state, 0x00); 904 i = s5h1420_readreg(state, ID01);
776 if (identity != 0x03) 905 if (i != 0x03)
777 goto error; 906 goto error;
778 907
908 memset(state->shadow, 0xff, sizeof(state->shadow));
909
910 for (i = 0; i < 0x50; i++)
911 state->shadow[i] = s5h1420_readreg(state, i);
912
779 /* create dvb_frontend */ 913 /* create dvb_frontend */
780 memcpy(&state->frontend.ops, &s5h1420_ops, sizeof(struct dvb_frontend_ops)); 914 memcpy(&state->frontend.ops, &s5h1420_ops, sizeof(struct dvb_frontend_ops));
781 state->frontend.demodulator_priv = state; 915 state->frontend.demodulator_priv = state;
916
917 /* create tuner i2c adapter */
918 strncpy(state->tuner_i2c_adapter.name, "S5H1420-PN1010 tuner I2C bus", I2C_NAME_SIZE);
919 state->tuner_i2c_adapter.class = I2C_CLASS_TV_DIGITAL,
920 state->tuner_i2c_adapter.algo = &s5h1420_tuner_i2c_algo;
921 state->tuner_i2c_adapter.algo_data = NULL;
922 i2c_set_adapdata(&state->tuner_i2c_adapter, state);
923 if (i2c_add_adapter(&state->tuner_i2c_adapter) < 0) {
924 printk(KERN_ERR "S5H1420/PN1010: tuner i2c bus could not be initialized\n");
925 goto error;
926 }
927
782 return &state->frontend; 928 return &state->frontend;
783 929
784error: 930error:
785 kfree(state); 931 kfree(state);
786 return NULL; 932 return NULL;
787} 933}
934EXPORT_SYMBOL(s5h1420_attach);
788 935
789static struct dvb_frontend_ops s5h1420_ops = { 936static struct dvb_frontend_ops s5h1420_ops = {
790 937
791 .info = { 938 .info = {
792 .name = "Samsung S5H1420 DVB-S", 939 .name = "Samsung S5H1420/PnpNetwork PN1010 DVB-S",
793 .type = FE_QPSK, 940 .type = FE_QPSK,
794 .frequency_min = 950000, 941 .frequency_min = 950000,
795 .frequency_max = 2150000, 942 .frequency_max = 2150000,
@@ -826,10 +973,6 @@ static struct dvb_frontend_ops s5h1420_ops = {
826 .set_voltage = s5h1420_set_voltage, 973 .set_voltage = s5h1420_set_voltage,
827}; 974};
828 975
829module_param(debug, int, 0644); 976MODULE_DESCRIPTION("Samsung S5H1420/PnpNetwork PN1010 DVB-S Demodulator driver");
830 977MODULE_AUTHOR("Andrew de Quincey, Patrick Boettcher");
831MODULE_DESCRIPTION("Samsung S5H1420 DVB-S Demodulator driver");
832MODULE_AUTHOR("Andrew de Quincey");
833MODULE_LICENSE("GPL"); 978MODULE_LICENSE("GPL");
834
835EXPORT_SYMBOL(s5h1420_attach);
diff --git a/drivers/media/dvb/frontends/s5h1420.h b/drivers/media/dvb/frontends/s5h1420.h
index 1555870f7226..4c913f142bc4 100644
--- a/drivers/media/dvb/frontends/s5h1420.h
+++ b/drivers/media/dvb/frontends/s5h1420.h
@@ -1,25 +1,26 @@
1/* 1/*
2 Driver for S5H1420 QPSK Demodulators 2 * Driver for
3 3 * Samsung S5H1420 and
4 Copyright (C) 2005 Andrew de Quincey <adq_dvb@lidskialf.net> 4 * PnpNetwork PN1010 QPSK Demodulator
5 5 *
6 This program is free software; you can redistribute it and/or modify 6 * Copyright (C) 2005 Andrew de Quincey <adq_dvb@lidskialf.net>
7 it under the terms of the GNU General Public License as published by 7 * Copyright (C) 2005-8 Patrick Boettcher <pb@linuxtv.org>
8 the Free Software Foundation; either version 2 of the License, or 8 *
9 (at your option) any later version. 9 * This program is free software; you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
11 This program is distributed in the hope that it will be useful, 11 * the Free Software Foundation; either version 2 of the License, or
12 but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * (at your option) any later version.
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 *
14 14 * This program is distributed in the hope that it will be useful,
15 GNU General Public License for more details. 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 You should have received a copy of the GNU General Public License 17 *
18 along with this program; if not, write to the Free Software 18 * GNU General Public License for more details.
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 *
20 20 * You should have received a copy of the GNU General Public License
21*/ 21 * along with this program; if not, write to the Free Software
22 22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 */
23#ifndef S5H1420_H 24#ifndef S5H1420_H
24#define S5H1420_H 25#define S5H1420_H
25 26
@@ -31,17 +32,26 @@ struct s5h1420_config
31 u8 demod_address; 32 u8 demod_address;
32 33
33 /* does the inversion require inversion? */ 34 /* does the inversion require inversion? */
34 u8 invert:1; 35 u8 invert : 1;
36
37 u8 repeated_start_workaround : 1;
38 u8 cdclk_polarity : 1; /* 1 == falling edge, 0 == raising edge */
35}; 39};
36 40
37#if defined(CONFIG_DVB_S5H1420) || (defined(CONFIG_DVB_S5H1420_MODULE) && defined(MODULE)) 41#if defined(CONFIG_DVB_S5H1420) || (defined(CONFIG_DVB_S5H1420_MODULE) && defined(MODULE))
38extern struct dvb_frontend* s5h1420_attach(const struct s5h1420_config* config, 42extern struct dvb_frontend *s5h1420_attach(const struct s5h1420_config *config,
39 struct i2c_adapter* i2c); 43 struct i2c_adapter *i2c);
44extern struct i2c_adapter *s5h1420_get_tuner_i2c_adapter(struct dvb_frontend *fe);
40#else 45#else
41static inline struct dvb_frontend* s5h1420_attach(const struct s5h1420_config* config, 46static inline struct dvb_frontend *s5h1420_attach(const struct s5h1420_config *config,
42 struct i2c_adapter* i2c) 47 struct i2c_adapter *i2c)
48{
49 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
50 return NULL;
51}
52
53static inline struct i2c_adapter *s5h1420_get_tuner_i2c_adapter(struct dvb_frontend *fe)
43{ 54{
44 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
45 return NULL; 55 return NULL;
46} 56}
47#endif // CONFIG_DVB_S5H1420 57#endif // CONFIG_DVB_S5H1420
diff --git a/drivers/media/dvb/frontends/s5h1420_priv.h b/drivers/media/dvb/frontends/s5h1420_priv.h
new file mode 100644
index 000000000000..d9c58d281816
--- /dev/null
+++ b/drivers/media/dvb/frontends/s5h1420_priv.h
@@ -0,0 +1,102 @@
1/*
2 * Driver for
3 * Samsung S5H1420 and
4 * PnpNetwork PN1010 QPSK Demodulator
5 *
6 * Copyright (C) 2005 Andrew de Quincey <adq_dvb@lidskialf.net>
7 * Copyright (C) 2005 Patrick Boettcher <pb@linuxtv.org>
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the Free
11 * Software Foundation; either version 2 of the License, or (at your option)
12 * any later version.
13 *
14 * This program is distributed in the hope that it will be useful, but WITHOUT
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 * FITNESS FOR A PARTICULAR PURPOSE. See the
17 *
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License along with
21 * this program; if not, write to the Free Software Foundation, Inc., 675 Mass
22 * Ave, Cambridge, MA 02139, USA.
23 */
24#ifndef S5H1420_PRIV
25#define S5H1420_PRIV
26
27#include <asm/types.h>
28
29enum s5h1420_register {
30 ID01 = 0x00,
31 CON_0 = 0x01,
32 CON_1 = 0x02,
33 PLL01 = 0x03,
34 PLL02 = 0x04,
35 QPSK01 = 0x05,
36 QPSK02 = 0x06,
37 Pre01 = 0x07,
38 Post01 = 0x08,
39 Loop01 = 0x09,
40 Loop02 = 0x0a,
41 Loop03 = 0x0b,
42 Loop04 = 0x0c,
43 Loop05 = 0x0d,
44 Pnco01 = 0x0e,
45 Pnco02 = 0x0f,
46 Pnco03 = 0x10,
47 Tnco01 = 0x11,
48 Tnco02 = 0x12,
49 Tnco03 = 0x13,
50 Monitor01 = 0x14,
51 Monitor02 = 0x15,
52 Monitor03 = 0x16,
53 Monitor04 = 0x17,
54 Monitor05 = 0x18,
55 Monitor06 = 0x19,
56 Monitor07 = 0x1a,
57 Monitor12 = 0x1f,
58
59 FEC01 = 0x22,
60 Soft01 = 0x23,
61 Soft02 = 0x24,
62 Soft03 = 0x25,
63 Soft04 = 0x26,
64 Soft05 = 0x27,
65 Soft06 = 0x28,
66 Vit01 = 0x29,
67 Vit02 = 0x2a,
68 Vit03 = 0x2b,
69 Vit04 = 0x2c,
70 Vit05 = 0x2d,
71 Vit06 = 0x2e,
72 Vit07 = 0x2f,
73 Vit08 = 0x30,
74 Vit09 = 0x31,
75 Vit10 = 0x32,
76 Vit11 = 0x33,
77 Vit12 = 0x34,
78 Sync01 = 0x35,
79 Sync02 = 0x36,
80 Rs01 = 0x37,
81 Mpeg01 = 0x38,
82 Mpeg02 = 0x39,
83 DiS01 = 0x3a,
84 DiS02 = 0x3b,
85 DiS03 = 0x3c,
86 DiS04 = 0x3d,
87 DiS05 = 0x3e,
88 DiS06 = 0x3f,
89 DiS07 = 0x40,
90 DiS08 = 0x41,
91 DiS09 = 0x42,
92 DiS10 = 0x43,
93 DiS11 = 0x44,
94 Rf01 = 0x45,
95 Err01 = 0x46,
96 Err02 = 0x47,
97 Err03 = 0x48,
98 Err04 = 0x49,
99};
100
101
102#endif
diff --git a/drivers/media/dvb/frontends/sp8870.c b/drivers/media/dvb/frontends/sp8870.c
index da876f7bfe32..aa78aa14aad9 100644
--- a/drivers/media/dvb/frontends/sp8870.c
+++ b/drivers/media/dvb/frontends/sp8870.c
@@ -70,7 +70,7 @@ static int sp8870_writereg (struct sp8870_state* state, u16 reg, u16 data)
70 int err; 70 int err;
71 71
72 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) { 72 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) {
73 dprintk ("%s: writereg error (err == %i, reg == 0x%02x, data == 0x%02x)\n", __FUNCTION__, err, reg, data); 73 dprintk ("%s: writereg error (err == %i, reg == 0x%02x, data == 0x%02x)\n", __func__, err, reg, data);
74 return -EREMOTEIO; 74 return -EREMOTEIO;
75 } 75 }
76 76
@@ -88,7 +88,7 @@ static int sp8870_readreg (struct sp8870_state* state, u16 reg)
88 ret = i2c_transfer (state->i2c, msg, 2); 88 ret = i2c_transfer (state->i2c, msg, 2);
89 89
90 if (ret != 2) { 90 if (ret != 2) {
91 dprintk("%s: readreg error (ret == %i)\n", __FUNCTION__, ret); 91 dprintk("%s: readreg error (ret == %i)\n", __func__, ret);
92 return -1; 92 return -1;
93 } 93 }
94 94
@@ -104,7 +104,7 @@ static int sp8870_firmware_upload (struct sp8870_state* state, const struct firm
104 int tx_len; 104 int tx_len;
105 int err = 0; 105 int err = 0;
106 106
107 dprintk ("%s: ...\n", __FUNCTION__); 107 dprintk ("%s: ...\n", __func__);
108 108
109 if (fw->size < SP8870_FIRMWARE_SIZE + SP8870_FIRMWARE_OFFSET) 109 if (fw->size < SP8870_FIRMWARE_SIZE + SP8870_FIRMWARE_OFFSET)
110 return -EINVAL; 110 return -EINVAL;
@@ -131,14 +131,14 @@ static int sp8870_firmware_upload (struct sp8870_state* state, const struct firm
131 msg.buf = tx_buf; 131 msg.buf = tx_buf;
132 msg.len = tx_len + 2; 132 msg.len = tx_len + 2;
133 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) { 133 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) {
134 printk("%s: firmware upload failed!\n", __FUNCTION__); 134 printk("%s: firmware upload failed!\n", __func__);
135 printk ("%s: i2c error (err == %i)\n", __FUNCTION__, err); 135 printk ("%s: i2c error (err == %i)\n", __func__, err);
136 return err; 136 return err;
137 } 137 }
138 fw_pos += tx_len; 138 fw_pos += tx_len;
139 } 139 }
140 140
141 dprintk ("%s: done!\n", __FUNCTION__); 141 dprintk ("%s: done!\n", __func__);
142 return 0; 142 return 0;
143}; 143};
144 144
@@ -310,7 +310,7 @@ static int sp8870_init (struct dvb_frontend* fe)
310 if (state->initialised) return 0; 310 if (state->initialised) return 0;
311 state->initialised = 1; 311 state->initialised = 1;
312 312
313 dprintk ("%s\n", __FUNCTION__); 313 dprintk ("%s\n", __func__);
314 314
315 315
316 /* request the firmware, this will block until someone uploads it */ 316 /* request the firmware, this will block until someone uploads it */
@@ -449,15 +449,15 @@ static int sp8870_read_uncorrected_blocks (struct dvb_frontend* fe, u32* ublocks
449 return 0; 449 return 0;
450} 450}
451 451
452// number of trials to recover from lockup 452/* number of trials to recover from lockup */
453#define MAXTRIALS 5 453#define MAXTRIALS 5
454// maximum checks for data valid signal 454/* maximum checks for data valid signal */
455#define MAXCHECKS 100 455#define MAXCHECKS 100
456 456
457// only for debugging: counter for detected lockups 457/* only for debugging: counter for detected lockups */
458static int lockups = 0; 458static int lockups;
459// only for debugging: counter for channel switches 459/* only for debugging: counter for channel switches */
460static int switches = 0; 460static int switches;
461 461
462static int sp8870_set_frontend (struct dvb_frontend* fe, struct dvb_frontend_parameters *p) 462static int sp8870_set_frontend (struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
463{ 463{
@@ -475,7 +475,7 @@ static int sp8870_set_frontend (struct dvb_frontend* fe, struct dvb_frontend_par
475 int trials = 0; 475 int trials = 0;
476 int check_count = 0; 476 int check_count = 0;
477 477
478 dprintk("%s: frequency = %i\n", __FUNCTION__, p->frequency); 478 dprintk("%s: frequency = %i\n", __func__, p->frequency);
479 479
480 for (trials = 1; trials <= MAXTRIALS; trials++) { 480 for (trials = 1; trials <= MAXTRIALS; trials++) {
481 481
@@ -487,7 +487,7 @@ static int sp8870_set_frontend (struct dvb_frontend* fe, struct dvb_frontend_par
487 valid = sp8870_read_data_valid_signal(state); 487 valid = sp8870_read_data_valid_signal(state);
488 if (valid) { 488 if (valid) {
489 dprintk("%s: delay = %i usec\n", 489 dprintk("%s: delay = %i usec\n",
490 __FUNCTION__, check_count * 10); 490 __func__, check_count * 10);
491 break; 491 break;
492 } 492 }
493 udelay(10); 493 udelay(10);
@@ -497,20 +497,20 @@ static int sp8870_set_frontend (struct dvb_frontend* fe, struct dvb_frontend_par
497 } 497 }
498 498
499 if (!valid) { 499 if (!valid) {
500 printk("%s: firmware crash!!!!!!\n", __FUNCTION__); 500 printk("%s: firmware crash!!!!!!\n", __func__);
501 return -EIO; 501 return -EIO;
502 } 502 }
503 503
504 if (debug) { 504 if (debug) {
505 if (valid) { 505 if (valid) {
506 if (trials > 1) { 506 if (trials > 1) {
507 printk("%s: firmware lockup!!!\n", __FUNCTION__); 507 printk("%s: firmware lockup!!!\n", __func__);
508 printk("%s: recovered after %i trial(s))\n", __FUNCTION__, trials - 1); 508 printk("%s: recovered after %i trial(s))\n", __func__, trials - 1);
509 lockups++; 509 lockups++;
510 } 510 }
511 } 511 }
512 switches++; 512 switches++;
513 printk("%s: switches = %i lockups = %i\n", __FUNCTION__, switches, lockups); 513 printk("%s: switches = %i lockups = %i\n", __func__, switches, lockups);
514 } 514 }
515 515
516 return 0; 516 return 0;
diff --git a/drivers/media/dvb/frontends/sp8870.h b/drivers/media/dvb/frontends/sp8870.h
index 909cefe7139e..a764a793c7d8 100644
--- a/drivers/media/dvb/frontends/sp8870.h
+++ b/drivers/media/dvb/frontends/sp8870.h
@@ -42,7 +42,7 @@ extern struct dvb_frontend* sp8870_attach(const struct sp8870_config* config,
42static inline struct dvb_frontend* sp8870_attach(const struct sp8870_config* config, 42static inline struct dvb_frontend* sp8870_attach(const struct sp8870_config* config,
43 struct i2c_adapter* i2c) 43 struct i2c_adapter* i2c)
44{ 44{
45 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 45 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
46 return NULL; 46 return NULL;
47} 47}
48#endif // CONFIG_DVB_SP8870 48#endif // CONFIG_DVB_SP8870
diff --git a/drivers/media/dvb/frontends/sp887x.c b/drivers/media/dvb/frontends/sp887x.c
index 1aa2539f5099..49f55877f513 100644
--- a/drivers/media/dvb/frontends/sp887x.c
+++ b/drivers/media/dvb/frontends/sp887x.c
@@ -43,7 +43,7 @@ static int i2c_writebytes (struct sp887x_state* state, u8 *buf, u8 len)
43 43
44 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) { 44 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) {
45 printk ("%s: i2c write error (addr %02x, err == %i)\n", 45 printk ("%s: i2c write error (addr %02x, err == %i)\n",
46 __FUNCTION__, state->config->demod_address, err); 46 __func__, state->config->demod_address, err);
47 return -EREMOTEIO; 47 return -EREMOTEIO;
48 } 48 }
49 49
@@ -65,7 +65,7 @@ static int sp887x_writereg (struct sp887x_state* state, u16 reg, u16 data)
65 { 65 {
66 printk("%s: writereg error " 66 printk("%s: writereg error "
67 "(reg %03x, data %03x, ret == %i)\n", 67 "(reg %03x, data %03x, ret == %i)\n",
68 __FUNCTION__, reg & 0xffff, data & 0xffff, ret); 68 __func__, reg & 0xffff, data & 0xffff, ret);
69 return ret; 69 return ret;
70 } 70 }
71 } 71 }
@@ -82,7 +82,7 @@ static int sp887x_readreg (struct sp887x_state* state, u16 reg)
82 { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = b1, .len = 2 }}; 82 { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = b1, .len = 2 }};
83 83
84 if ((ret = i2c_transfer(state->i2c, msg, 2)) != 2) { 84 if ((ret = i2c_transfer(state->i2c, msg, 2)) != 2) {
85 printk("%s: readreg error (ret == %i)\n", __FUNCTION__, ret); 85 printk("%s: readreg error (ret == %i)\n", __func__, ret);
86 return -1; 86 return -1;
87 } 87 }
88 88
@@ -91,7 +91,7 @@ static int sp887x_readreg (struct sp887x_state* state, u16 reg)
91 91
92static void sp887x_microcontroller_stop (struct sp887x_state* state) 92static void sp887x_microcontroller_stop (struct sp887x_state* state)
93{ 93{
94 dprintk("%s\n", __FUNCTION__); 94 dprintk("%s\n", __func__);
95 sp887x_writereg(state, 0xf08, 0x000); 95 sp887x_writereg(state, 0xf08, 0x000);
96 sp887x_writereg(state, 0xf09, 0x000); 96 sp887x_writereg(state, 0xf09, 0x000);
97 97
@@ -101,7 +101,7 @@ static void sp887x_microcontroller_stop (struct sp887x_state* state)
101 101
102static void sp887x_microcontroller_start (struct sp887x_state* state) 102static void sp887x_microcontroller_start (struct sp887x_state* state)
103{ 103{
104 dprintk("%s\n", __FUNCTION__); 104 dprintk("%s\n", __func__);
105 sp887x_writereg(state, 0xf08, 0x000); 105 sp887x_writereg(state, 0xf08, 0x000);
106 sp887x_writereg(state, 0xf09, 0x000); 106 sp887x_writereg(state, 0xf09, 0x000);
107 107
@@ -112,7 +112,7 @@ static void sp887x_microcontroller_start (struct sp887x_state* state)
112static void sp887x_setup_agc (struct sp887x_state* state) 112static void sp887x_setup_agc (struct sp887x_state* state)
113{ 113{
114 /* setup AGC parameters */ 114 /* setup AGC parameters */
115 dprintk("%s\n", __FUNCTION__); 115 dprintk("%s\n", __func__);
116 sp887x_writereg(state, 0x33c, 0x054); 116 sp887x_writereg(state, 0x33c, 0x054);
117 sp887x_writereg(state, 0x33b, 0x04c); 117 sp887x_writereg(state, 0x33b, 0x04c);
118 sp887x_writereg(state, 0x328, 0x000); 118 sp887x_writereg(state, 0x328, 0x000);
@@ -142,7 +142,7 @@ static int sp887x_initial_setup (struct dvb_frontend* fe, const struct firmware
142 int fw_size = fw->size; 142 int fw_size = fw->size;
143 unsigned char *mem = fw->data; 143 unsigned char *mem = fw->data;
144 144
145 dprintk("%s\n", __FUNCTION__); 145 dprintk("%s\n", __func__);
146 146
147 /* ignore the first 10 bytes, then we expect 0x4000 bytes of firmware */ 147 /* ignore the first 10 bytes, then we expect 0x4000 bytes of firmware */
148 if (fw_size < FW_SIZE+10) 148 if (fw_size < FW_SIZE+10)
@@ -155,7 +155,7 @@ static int sp887x_initial_setup (struct dvb_frontend* fe, const struct firmware
155 155
156 sp887x_microcontroller_stop (state); 156 sp887x_microcontroller_stop (state);
157 157
158 printk ("%s: firmware upload... ", __FUNCTION__); 158 printk ("%s: firmware upload... ", __func__);
159 159
160 /* setup write pointer to -1 (end of memory) */ 160 /* setup write pointer to -1 (end of memory) */
161 /* bit 0x8000 in address is set to enable 13bit mode */ 161 /* bit 0x8000 in address is set to enable 13bit mode */
@@ -181,7 +181,7 @@ static int sp887x_initial_setup (struct dvb_frontend* fe, const struct firmware
181 181
182 if ((err = i2c_writebytes (state, buf, c+2)) < 0) { 182 if ((err = i2c_writebytes (state, buf, c+2)) < 0) {
183 printk ("failed.\n"); 183 printk ("failed.\n");
184 printk ("%s: i2c error (err == %i)\n", __FUNCTION__, err); 184 printk ("%s: i2c error (err == %i)\n", __func__, err);
185 return err; 185 return err;
186 } 186 }
187 } 187 }
diff --git a/drivers/media/dvb/frontends/sp887x.h b/drivers/media/dvb/frontends/sp887x.h
index 7ee78d7d916d..04eff6e0eef3 100644
--- a/drivers/media/dvb/frontends/sp887x.h
+++ b/drivers/media/dvb/frontends/sp887x.h
@@ -24,7 +24,7 @@ extern struct dvb_frontend* sp887x_attach(const struct sp887x_config* config,
24static inline struct dvb_frontend* sp887x_attach(const struct sp887x_config* config, 24static inline struct dvb_frontend* sp887x_attach(const struct sp887x_config* config,
25 struct i2c_adapter* i2c) 25 struct i2c_adapter* i2c)
26{ 26{
27 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 27 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
28 return NULL; 28 return NULL;
29} 29}
30#endif // CONFIG_DVB_SP887X 30#endif // CONFIG_DVB_SP887X
diff --git a/drivers/media/dvb/frontends/stv0297.c b/drivers/media/dvb/frontends/stv0297.c
index 7c23775f77db..62caf802ed99 100644
--- a/drivers/media/dvb/frontends/stv0297.c
+++ b/drivers/media/dvb/frontends/stv0297.c
@@ -58,7 +58,7 @@ static int stv0297_writereg(struct stv0297_state *state, u8 reg, u8 data)
58 58
59 if (ret != 1) 59 if (ret != 1)
60 dprintk("%s: writereg error (reg == 0x%02x, val == 0x%02x, " 60 dprintk("%s: writereg error (reg == 0x%02x, val == 0x%02x, "
61 "ret == %i)\n", __FUNCTION__, reg, data, ret); 61 "ret == %i)\n", __func__, reg, data, ret);
62 62
63 return (ret != 1) ? -1 : 0; 63 return (ret != 1) ? -1 : 0;
64} 64}
@@ -75,16 +75,16 @@ static int stv0297_readreg(struct stv0297_state *state, u8 reg)
75 // this device needs a STOP between the register and data 75 // this device needs a STOP between the register and data
76 if (state->config->stop_during_read) { 76 if (state->config->stop_during_read) {
77 if ((ret = i2c_transfer(state->i2c, &msg[0], 1)) != 1) { 77 if ((ret = i2c_transfer(state->i2c, &msg[0], 1)) != 1) {
78 dprintk("%s: readreg error (reg == 0x%02x, ret == %i)\n", __FUNCTION__, reg, ret); 78 dprintk("%s: readreg error (reg == 0x%02x, ret == %i)\n", __func__, reg, ret);
79 return -1; 79 return -1;
80 } 80 }
81 if ((ret = i2c_transfer(state->i2c, &msg[1], 1)) != 1) { 81 if ((ret = i2c_transfer(state->i2c, &msg[1], 1)) != 1) {
82 dprintk("%s: readreg error (reg == 0x%02x, ret == %i)\n", __FUNCTION__, reg, ret); 82 dprintk("%s: readreg error (reg == 0x%02x, ret == %i)\n", __func__, reg, ret);
83 return -1; 83 return -1;
84 } 84 }
85 } else { 85 } else {
86 if ((ret = i2c_transfer(state->i2c, msg, 2)) != 2) { 86 if ((ret = i2c_transfer(state->i2c, msg, 2)) != 2) {
87 dprintk("%s: readreg error (reg == 0x%02x, ret == %i)\n", __FUNCTION__, reg, ret); 87 dprintk("%s: readreg error (reg == 0x%02x, ret == %i)\n", __func__, reg, ret);
88 return -1; 88 return -1;
89 } 89 }
90 } 90 }
@@ -115,16 +115,16 @@ static int stv0297_readregs(struct stv0297_state *state, u8 reg1, u8 * b, u8 len
115 // this device needs a STOP between the register and data 115 // this device needs a STOP between the register and data
116 if (state->config->stop_during_read) { 116 if (state->config->stop_during_read) {
117 if ((ret = i2c_transfer(state->i2c, &msg[0], 1)) != 1) { 117 if ((ret = i2c_transfer(state->i2c, &msg[0], 1)) != 1) {
118 dprintk("%s: readreg error (reg == 0x%02x, ret == %i)\n", __FUNCTION__, reg1, ret); 118 dprintk("%s: readreg error (reg == 0x%02x, ret == %i)\n", __func__, reg1, ret);
119 return -1; 119 return -1;
120 } 120 }
121 if ((ret = i2c_transfer(state->i2c, &msg[1], 1)) != 1) { 121 if ((ret = i2c_transfer(state->i2c, &msg[1], 1)) != 1) {
122 dprintk("%s: readreg error (reg == 0x%02x, ret == %i)\n", __FUNCTION__, reg1, ret); 122 dprintk("%s: readreg error (reg == 0x%02x, ret == %i)\n", __func__, reg1, ret);
123 return -1; 123 return -1;
124 } 124 }
125 } else { 125 } else {
126 if ((ret = i2c_transfer(state->i2c, msg, 2)) != 2) { 126 if ((ret = i2c_transfer(state->i2c, msg, 2)) != 2) {
127 dprintk("%s: readreg error (reg == 0x%02x, ret == %i)\n", __FUNCTION__, reg1, ret); 127 dprintk("%s: readreg error (reg == 0x%02x, ret == %i)\n", __func__, reg1, ret);
128 return -1; 128 return -1;
129 } 129 }
130 } 130 }
diff --git a/drivers/media/dvb/frontends/stv0297.h b/drivers/media/dvb/frontends/stv0297.h
index 69f4515df2b9..3f8f9468f387 100644
--- a/drivers/media/dvb/frontends/stv0297.h
+++ b/drivers/media/dvb/frontends/stv0297.h
@@ -49,7 +49,7 @@ extern struct dvb_frontend* stv0297_attach(const struct stv0297_config* config,
49static inline struct dvb_frontend* stv0297_attach(const struct stv0297_config* config, 49static inline struct dvb_frontend* stv0297_attach(const struct stv0297_config* config,
50 struct i2c_adapter* i2c) 50 struct i2c_adapter* i2c)
51{ 51{
52 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 52 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
53 return NULL; 53 return NULL;
54} 54}
55#endif // CONFIG_DVB_STV0297 55#endif // CONFIG_DVB_STV0297
diff --git a/drivers/media/dvb/frontends/stv0299.c b/drivers/media/dvb/frontends/stv0299.c
index 035dd7ba6519..17556183e871 100644
--- a/drivers/media/dvb/frontends/stv0299.c
+++ b/drivers/media/dvb/frontends/stv0299.c
@@ -86,7 +86,7 @@ static int stv0299_writeregI (struct stv0299_state* state, u8 reg, u8 data)
86 86
87 if (ret != 1) 87 if (ret != 1)
88 dprintk("%s: writereg error (reg == 0x%02x, val == 0x%02x, " 88 dprintk("%s: writereg error (reg == 0x%02x, val == 0x%02x, "
89 "ret == %i)\n", __FUNCTION__, reg, data, ret); 89 "ret == %i)\n", __func__, reg, data, ret);
90 90
91 return (ret != 1) ? -EREMOTEIO : 0; 91 return (ret != 1) ? -EREMOTEIO : 0;
92} 92}
@@ -113,7 +113,7 @@ static u8 stv0299_readreg (struct stv0299_state* state, u8 reg)
113 113
114 if (ret != 2) 114 if (ret != 2)
115 dprintk("%s: readreg error (reg == 0x%02x, ret == %i)\n", 115 dprintk("%s: readreg error (reg == 0x%02x, ret == %i)\n",
116 __FUNCTION__, reg, ret); 116 __func__, reg, ret);
117 117
118 return b1[0]; 118 return b1[0];
119} 119}
@@ -127,14 +127,14 @@ static int stv0299_readregs (struct stv0299_state* state, u8 reg1, u8 *b, u8 len
127 ret = i2c_transfer (state->i2c, msg, 2); 127 ret = i2c_transfer (state->i2c, msg, 2);
128 128
129 if (ret != 2) 129 if (ret != 2)
130 dprintk("%s: readreg error (ret == %i)\n", __FUNCTION__, ret); 130 dprintk("%s: readreg error (ret == %i)\n", __func__, ret);
131 131
132 return ret == 2 ? 0 : ret; 132 return ret == 2 ? 0 : ret;
133} 133}
134 134
135static int stv0299_set_FEC (struct stv0299_state* state, fe_code_rate_t fec) 135static int stv0299_set_FEC (struct stv0299_state* state, fe_code_rate_t fec)
136{ 136{
137 dprintk ("%s\n", __FUNCTION__); 137 dprintk ("%s\n", __func__);
138 138
139 switch (fec) { 139 switch (fec) {
140 case FEC_AUTO: 140 case FEC_AUTO:
@@ -174,7 +174,7 @@ static fe_code_rate_t stv0299_get_fec (struct stv0299_state* state)
174 FEC_7_8, FEC_1_2 }; 174 FEC_7_8, FEC_1_2 };
175 u8 index; 175 u8 index;
176 176
177 dprintk ("%s\n", __FUNCTION__); 177 dprintk ("%s\n", __func__);
178 178
179 index = stv0299_readreg (state, 0x1b); 179 index = stv0299_readreg (state, 0x1b);
180 index &= 0x7; 180 index &= 0x7;
@@ -189,11 +189,11 @@ static int stv0299_wait_diseqc_fifo (struct stv0299_state* state, int timeout)
189{ 189{
190 unsigned long start = jiffies; 190 unsigned long start = jiffies;
191 191
192 dprintk ("%s\n", __FUNCTION__); 192 dprintk ("%s\n", __func__);
193 193
194 while (stv0299_readreg(state, 0x0a) & 1) { 194 while (stv0299_readreg(state, 0x0a) & 1) {
195 if (jiffies - start > timeout) { 195 if (jiffies - start > timeout) {
196 dprintk ("%s: timeout!!\n", __FUNCTION__); 196 dprintk ("%s: timeout!!\n", __func__);
197 return -ETIMEDOUT; 197 return -ETIMEDOUT;
198 } 198 }
199 msleep(10); 199 msleep(10);
@@ -206,11 +206,11 @@ static int stv0299_wait_diseqc_idle (struct stv0299_state* state, int timeout)
206{ 206{
207 unsigned long start = jiffies; 207 unsigned long start = jiffies;
208 208
209 dprintk ("%s\n", __FUNCTION__); 209 dprintk ("%s\n", __func__);
210 210
211 while ((stv0299_readreg(state, 0x0a) & 3) != 2 ) { 211 while ((stv0299_readreg(state, 0x0a) & 3) != 2 ) {
212 if (jiffies - start > timeout) { 212 if (jiffies - start > timeout) {
213 dprintk ("%s: timeout!!\n", __FUNCTION__); 213 dprintk ("%s: timeout!!\n", __func__);
214 return -ETIMEDOUT; 214 return -ETIMEDOUT;
215 } 215 }
216 msleep(10); 216 msleep(10);
@@ -245,7 +245,7 @@ static int stv0299_get_symbolrate (struct stv0299_state* state)
245 u8 sfr[3]; 245 u8 sfr[3];
246 s8 rtf; 246 s8 rtf;
247 247
248 dprintk ("%s\n", __FUNCTION__); 248 dprintk ("%s\n", __func__);
249 249
250 stv0299_readregs (state, 0x1f, sfr, 3); 250 stv0299_readregs (state, 0x1f, sfr, 3);
251 stv0299_readregs (state, 0x1a, (u8 *)&rtf, 1); 251 stv0299_readregs (state, 0x1a, (u8 *)&rtf, 1);
@@ -257,8 +257,8 @@ static int stv0299_get_symbolrate (struct stv0299_state* state)
257 offset = (s32) rtf * (srate / 4096L); 257 offset = (s32) rtf * (srate / 4096L);
258 offset /= 128; 258 offset /= 128;
259 259
260 dprintk ("%s : srate = %i\n", __FUNCTION__, srate); 260 dprintk ("%s : srate = %i\n", __func__, srate);
261 dprintk ("%s : ofset = %i\n", __FUNCTION__, offset); 261 dprintk ("%s : ofset = %i\n", __func__, offset);
262 262
263 srate += offset; 263 srate += offset;
264 264
@@ -276,7 +276,7 @@ static int stv0299_send_diseqc_msg (struct dvb_frontend* fe,
276 u8 val; 276 u8 val;
277 int i; 277 int i;
278 278
279 dprintk ("%s\n", __FUNCTION__); 279 dprintk ("%s\n", __func__);
280 280
281 if (stv0299_wait_diseqc_idle (state, 100) < 0) 281 if (stv0299_wait_diseqc_idle (state, 100) < 0)
282 return -ETIMEDOUT; 282 return -ETIMEDOUT;
@@ -305,7 +305,7 @@ static int stv0299_send_diseqc_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t
305 struct stv0299_state* state = fe->demodulator_priv; 305 struct stv0299_state* state = fe->demodulator_priv;
306 u8 val; 306 u8 val;
307 307
308 dprintk ("%s\n", __FUNCTION__); 308 dprintk ("%s\n", __func__);
309 309
310 if (stv0299_wait_diseqc_idle (state, 100) < 0) 310 if (stv0299_wait_diseqc_idle (state, 100) < 0)
311 return -ETIMEDOUT; 311 return -ETIMEDOUT;
@@ -355,7 +355,7 @@ static int stv0299_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltag
355 u8 reg0x08; 355 u8 reg0x08;
356 u8 reg0x0c; 356 u8 reg0x0c;
357 357
358 dprintk("%s: %s\n", __FUNCTION__, 358 dprintk("%s: %s\n", __func__,
359 voltage == SEC_VOLTAGE_13 ? "SEC_VOLTAGE_13" : 359 voltage == SEC_VOLTAGE_13 ? "SEC_VOLTAGE_13" :
360 voltage == SEC_VOLTAGE_18 ? "SEC_VOLTAGE_18" : "??"); 360 voltage == SEC_VOLTAGE_18 ? "SEC_VOLTAGE_18" : "??");
361 361
@@ -366,26 +366,32 @@ static int stv0299_set_voltage (struct dvb_frontend* fe, fe_sec_voltage_t voltag
366 * H/V switching over OP0, OP1 and OP2 are LNB power enable bits 366 * H/V switching over OP0, OP1 and OP2 are LNB power enable bits
367 */ 367 */
368 reg0x0c &= 0x0f; 368 reg0x0c &= 0x0f;
369 369 reg0x08 = (reg0x08 & 0x3f) | (state->config->lock_output << 6);
370 if (voltage == SEC_VOLTAGE_OFF) {
371 stv0299_writeregI (state, 0x0c, 0x00); /* LNB power off! */
372 return stv0299_writeregI (state, 0x08, 0x00); /* LNB power off! */
373 }
374
375 stv0299_writeregI (state, 0x08, (reg0x08 & 0x3f) | (state->config->lock_output << 6));
376 370
377 switch (voltage) { 371 switch (voltage) {
378 case SEC_VOLTAGE_13: 372 case SEC_VOLTAGE_13:
379 if (state->config->volt13_op0_op1 == STV0299_VOLT13_OP0) reg0x0c |= 0x10; 373 if (state->config->volt13_op0_op1 == STV0299_VOLT13_OP0)
380 else reg0x0c |= 0x40; 374 reg0x0c |= 0x10; /* OP1 off, OP0 on */
381 375 else
382 return stv0299_writeregI(state, 0x0c, reg0x0c); 376 reg0x0c |= 0x40; /* OP1 on, OP0 off */
383 377 break;
384 case SEC_VOLTAGE_18: 378 case SEC_VOLTAGE_18:
385 return stv0299_writeregI(state, 0x0c, reg0x0c | 0x50); 379 reg0x0c |= 0x50; /* OP1 on, OP0 on */
380 break;
381 case SEC_VOLTAGE_OFF:
382 /* LNB power off! */
383 reg0x08 = 0x00;
384 reg0x0c = 0x00;
385 break;
386 default: 386 default:
387 return -EINVAL; 387 return -EINVAL;
388 }; 388 };
389
390 if (state->config->op0_off)
391 reg0x0c &= ~0x10;
392
393 stv0299_writeregI(state, 0x08, reg0x08);
394 return stv0299_writeregI(state, 0x0c, reg0x0c);
389} 395}
390 396
391static int stv0299_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long cmd) 397static int stv0299_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long cmd)
@@ -408,7 +414,7 @@ static int stv0299_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long
408 414
409 cmd = cmd << 1; 415 cmd = cmd << 1;
410 if (debug_legacy_dish_switch) 416 if (debug_legacy_dish_switch)
411 printk ("%s switch command: 0x%04lx\n",__FUNCTION__, cmd); 417 printk ("%s switch command: 0x%04lx\n",__func__, cmd);
412 418
413 do_gettimeofday (&nexttime); 419 do_gettimeofday (&nexttime);
414 if (debug_legacy_dish_switch) 420 if (debug_legacy_dish_switch)
@@ -433,7 +439,7 @@ static int stv0299_send_legacy_dish_cmd (struct dvb_frontend* fe, unsigned long
433 } 439 }
434 if (debug_legacy_dish_switch) { 440 if (debug_legacy_dish_switch) {
435 printk ("%s(%d): switch delay (should be 32k followed by all 8k\n", 441 printk ("%s(%d): switch delay (should be 32k followed by all 8k\n",
436 __FUNCTION__, fe->dvb->num); 442 __func__, fe->dvb->num);
437 for (i = 1; i < 10; i++) 443 for (i = 1; i < 10; i++)
438 printk ("%d: %d\n", i, timeval_usec_diff(tv[i-1] , tv[i])); 444 printk ("%d: %d\n", i, timeval_usec_diff(tv[i-1] , tv[i]));
439 } 445 }
@@ -445,11 +451,20 @@ static int stv0299_init (struct dvb_frontend* fe)
445{ 451{
446 struct stv0299_state* state = fe->demodulator_priv; 452 struct stv0299_state* state = fe->demodulator_priv;
447 int i; 453 int i;
454 u8 reg;
455 u8 val;
448 456
449 dprintk("stv0299: init chip\n"); 457 dprintk("stv0299: init chip\n");
450 458
451 for (i=0; !(state->config->inittab[i] == 0xff && state->config->inittab[i+1] == 0xff); i+=2) 459 for (i = 0; ; i += 2) {
452 stv0299_writeregI(state, state->config->inittab[i], state->config->inittab[i+1]); 460 reg = state->config->inittab[i];
461 val = state->config->inittab[i+1];
462 if (reg == 0xff && val == 0xff)
463 break;
464 if (reg == 0x0c && state->config->op0_off)
465 val &= ~0x10;
466 stv0299_writeregI(state, reg, val);
467 }
453 468
454 return 0; 469 return 0;
455} 470}
@@ -461,7 +476,7 @@ static int stv0299_read_status(struct dvb_frontend* fe, fe_status_t* status)
461 u8 signal = 0xff - stv0299_readreg (state, 0x18); 476 u8 signal = 0xff - stv0299_readreg (state, 0x18);
462 u8 sync = stv0299_readreg (state, 0x1b); 477 u8 sync = stv0299_readreg (state, 0x1b);
463 478
464 dprintk ("%s : FE_READ_STATUS : VSTATUS: 0x%02x\n", __FUNCTION__, sync); 479 dprintk ("%s : FE_READ_STATUS : VSTATUS: 0x%02x\n", __func__, sync);
465 *status = 0; 480 *status = 0;
466 481
467 if (signal > 10) 482 if (signal > 10)
@@ -499,7 +514,7 @@ static int stv0299_read_signal_strength(struct dvb_frontend* fe, u16* strength)
499 s32 signal = 0xffff - ((stv0299_readreg (state, 0x18) << 8) 514 s32 signal = 0xffff - ((stv0299_readreg (state, 0x18) << 8)
500 | stv0299_readreg (state, 0x19)); 515 | stv0299_readreg (state, 0x19));
501 516
502 dprintk ("%s : FE_READ_SIGNAL_STRENGTH : AGC2I: 0x%02x%02x, signal=0x%04x\n", __FUNCTION__, 517 dprintk ("%s : FE_READ_SIGNAL_STRENGTH : AGC2I: 0x%02x%02x, signal=0x%04x\n", __func__,
503 stv0299_readreg (state, 0x18), 518 stv0299_readreg (state, 0x18),
504 stv0299_readreg (state, 0x19), (int) signal); 519 stv0299_readreg (state, 0x19), (int) signal);
505 520
@@ -536,7 +551,7 @@ static int stv0299_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
536 struct stv0299_state* state = fe->demodulator_priv; 551 struct stv0299_state* state = fe->demodulator_priv;
537 int invval = 0; 552 int invval = 0;
538 553
539 dprintk ("%s : FE_SET_FRONTEND\n", __FUNCTION__); 554 dprintk ("%s : FE_SET_FRONTEND\n", __func__);
540 555
541 // set the inversion 556 // set the inversion
542 if (p->inversion == INVERSION_OFF) invval = 0; 557 if (p->inversion == INVERSION_OFF) invval = 0;
diff --git a/drivers/media/dvb/frontends/stv0299.h b/drivers/media/dvb/frontends/stv0299.h
index 33df9495908f..3282f43022f5 100644
--- a/drivers/media/dvb/frontends/stv0299.h
+++ b/drivers/media/dvb/frontends/stv0299.h
@@ -48,10 +48,10 @@
48#include <linux/dvb/frontend.h> 48#include <linux/dvb/frontend.h>
49#include "dvb_frontend.h" 49#include "dvb_frontend.h"
50 50
51#define STV0229_LOCKOUTPUT_0 0 51#define STV0299_LOCKOUTPUT_0 0
52#define STV0229_LOCKOUTPUT_1 1 52#define STV0299_LOCKOUTPUT_1 1
53#define STV0229_LOCKOUTPUT_CF 2 53#define STV0299_LOCKOUTPUT_CF 2
54#define STV0229_LOCKOUTPUT_LK 3 54#define STV0299_LOCKOUTPUT_LK 3
55 55
56#define STV0299_VOLT13_OP0 0 56#define STV0299_VOLT13_OP0 0
57#define STV0299_VOLT13_OP1 1 57#define STV0299_VOLT13_OP1 1
@@ -82,6 +82,9 @@ struct stv0299_config
82 /* Is 13v controlled by OP0 or OP1? */ 82 /* Is 13v controlled by OP0 or OP1? */
83 u8 volt13_op0_op1:1; 83 u8 volt13_op0_op1:1;
84 84
85 /* Turn-off OP0? */
86 u8 op0_off:1;
87
85 /* minimum delay before retuning */ 88 /* minimum delay before retuning */
86 int min_delay_ms; 89 int min_delay_ms;
87 90
@@ -96,7 +99,7 @@ extern struct dvb_frontend* stv0299_attach(const struct stv0299_config* config,
96static inline struct dvb_frontend* stv0299_attach(const struct stv0299_config* config, 99static inline struct dvb_frontend* stv0299_attach(const struct stv0299_config* config,
97 struct i2c_adapter* i2c) 100 struct i2c_adapter* i2c)
98{ 101{
99 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 102 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
100 return NULL; 103 return NULL;
101} 104}
102#endif // CONFIG_DVB_STV0299 105#endif // CONFIG_DVB_STV0299
diff --git a/drivers/media/dvb/frontends/tda10021.c b/drivers/media/dvb/frontends/tda10021.c
index 45137d2ebfb9..f648fdb64bb7 100644
--- a/drivers/media/dvb/frontends/tda10021.c
+++ b/drivers/media/dvb/frontends/tda10021.c
@@ -79,7 +79,7 @@ static int _tda10021_writereg (struct tda10021_state* state, u8 reg, u8 data)
79 if (ret != 1) 79 if (ret != 1)
80 printk("DVB: TDA10021(%d): %s, writereg error " 80 printk("DVB: TDA10021(%d): %s, writereg error "
81 "(reg == 0x%02x, val == 0x%02x, ret == %i)\n", 81 "(reg == 0x%02x, val == 0x%02x, ret == %i)\n",
82 state->frontend.dvb->num, __FUNCTION__, reg, data, ret); 82 state->frontend.dvb->num, __func__, reg, data, ret);
83 83
84 msleep(10); 84 msleep(10);
85 return (ret != 1) ? -EREMOTEIO : 0; 85 return (ret != 1) ? -EREMOTEIO : 0;
@@ -97,7 +97,7 @@ static u8 tda10021_readreg (struct tda10021_state* state, u8 reg)
97 // Don't print an error message if the id is read. 97 // Don't print an error message if the id is read.
98 if (ret != 2 && reg != 0x1a) 98 if (ret != 2 && reg != 0x1a)
99 printk("DVB: TDA10021: %s: readreg error (ret == %i)\n", 99 printk("DVB: TDA10021: %s: readreg error (ret == %i)\n",
100 __FUNCTION__, ret); 100 __func__, ret);
101 return b1[0]; 101 return b1[0];
102} 102}
103 103
diff --git a/drivers/media/dvb/frontends/tda10023.c b/drivers/media/dvb/frontends/tda10023.c
index 364bc01971a0..0727b80bc4d2 100644
--- a/drivers/media/dvb/frontends/tda10023.c
+++ b/drivers/media/dvb/frontends/tda10023.c
@@ -118,7 +118,7 @@ static u8 tda10023_readreg (struct tda10023_state* state, u8 reg)
118 ret = i2c_transfer (state->i2c, msg, 2); 118 ret = i2c_transfer (state->i2c, msg, 2);
119 if (ret != 2) 119 if (ret != 2)
120 printk("DVB: TDA10023: %s: readreg error (ret == %i)\n", 120 printk("DVB: TDA10023: %s: readreg error (ret == %i)\n",
121 __FUNCTION__, ret); 121 __func__, ret);
122 return b1[0]; 122 return b1[0];
123} 123}
124 124
@@ -132,7 +132,7 @@ static int tda10023_writereg (struct tda10023_state* state, u8 reg, u8 data)
132 if (ret != 1) 132 if (ret != 1)
133 printk("DVB: TDA10023(%d): %s, writereg error " 133 printk("DVB: TDA10023(%d): %s, writereg error "
134 "(reg == 0x%02x, val == 0x%02x, ret == %i)\n", 134 "(reg == 0x%02x, val == 0x%02x, ret == %i)\n",
135 state->frontend.dvb->num, __FUNCTION__, reg, data, ret); 135 state->frontend.dvb->num, __func__, reg, data, ret);
136 136
137 return (ret != 1) ? -EREMOTEIO : 0; 137 return (ret != 1) ? -EREMOTEIO : 0;
138} 138}
diff --git a/drivers/media/dvb/frontends/tda1002x.h b/drivers/media/dvb/frontends/tda1002x.h
index e9094d8123f6..1bcc0d44b90b 100644
--- a/drivers/media/dvb/frontends/tda1002x.h
+++ b/drivers/media/dvb/frontends/tda1002x.h
@@ -40,7 +40,7 @@ extern struct dvb_frontend* tda10021_attach(const struct tda1002x_config* config
40static inline struct dvb_frontend* tda10021_attach(const struct tda1002x_config* config, 40static inline struct dvb_frontend* tda10021_attach(const struct tda1002x_config* config,
41 struct i2c_adapter* i2c, u8 pwm) 41 struct i2c_adapter* i2c, u8 pwm)
42{ 42{
43 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 43 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
44 return NULL; 44 return NULL;
45} 45}
46#endif // CONFIG_DVB_TDA10021 46#endif // CONFIG_DVB_TDA10021
@@ -52,7 +52,7 @@ extern struct dvb_frontend* tda10023_attach(const struct tda1002x_config* config
52static inline struct dvb_frontend* tda10023_attach(const struct tda1002x_config* config, 52static inline struct dvb_frontend* tda10023_attach(const struct tda1002x_config* config,
53 struct i2c_adapter* i2c, u8 pwm) 53 struct i2c_adapter* i2c, u8 pwm)
54{ 54{
55 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 55 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
56 return NULL; 56 return NULL;
57} 57}
58#endif // CONFIG_DVB_TDA10023 58#endif // CONFIG_DVB_TDA10023
diff --git a/drivers/media/dvb/frontends/tda10048.c b/drivers/media/dvb/frontends/tda10048.c
new file mode 100644
index 000000000000..090fb7dd93c6
--- /dev/null
+++ b/drivers/media/dvb/frontends/tda10048.c
@@ -0,0 +1,841 @@
1/*
2 NXP TDA10048HN DVB OFDM demodulator driver
3
4 Copyright (C) 2008 Steven Toth <stoth@hauppauge.com>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20*/
21
22#include <linux/kernel.h>
23#include <linux/init.h>
24#include <linux/module.h>
25#include <linux/string.h>
26#include <linux/slab.h>
27#include <linux/delay.h>
28#include "dvb_frontend.h"
29#include "dvb_math.h"
30#include "tda10048.h"
31
32#define TDA10048_DEFAULT_FIRMWARE "dvb-fe-tda10048-1.0.fw"
33#define TDA10048_DEFAULT_FIRMWARE_SIZE 24878
34
35/* Register name definitions */
36#define TDA10048_IDENTITY 0x00
37#define TDA10048_VERSION 0x01
38#define TDA10048_DSP_CODE_CPT 0x0C
39#define TDA10048_DSP_CODE_IN 0x0E
40#define TDA10048_IN_CONF1 0x10
41#define TDA10048_IN_CONF2 0x11
42#define TDA10048_IN_CONF3 0x12
43#define TDA10048_OUT_CONF1 0x14
44#define TDA10048_OUT_CONF2 0x15
45#define TDA10048_OUT_CONF3 0x16
46#define TDA10048_AUTO 0x18
47#define TDA10048_SYNC_STATUS 0x1A
48#define TDA10048_CONF_C4_1 0x1E
49#define TDA10048_CONF_C4_2 0x1F
50#define TDA10048_CODE_IN_RAM 0x20
51#define TDA10048_CHANNEL_INFO_1_R 0x22
52#define TDA10048_CHANNEL_INFO_2_R 0x23
53#define TDA10048_CHANNEL_INFO1 0x24
54#define TDA10048_CHANNEL_INFO2 0x25
55#define TDA10048_TIME_ERROR_R 0x26
56#define TDA10048_TIME_ERROR 0x27
57#define TDA10048_FREQ_ERROR_LSB_R 0x28
58#define TDA10048_FREQ_ERROR_MSB_R 0x29
59#define TDA10048_FREQ_ERROR_LSB 0x2A
60#define TDA10048_FREQ_ERROR_MSB 0x2B
61#define TDA10048_IT_SEL 0x30
62#define TDA10048_IT_STAT 0x32
63#define TDA10048_DSP_AD_LSB 0x3C
64#define TDA10048_DSP_AD_MSB 0x3D
65#define TDA10048_DSP_REF_LSB 0x3E
66#define TDA10048_DSP_REF_MSB 0x3F
67#define TDA10048_CONF_TRISTATE1 0x44
68#define TDA10048_CONF_TRISTATE2 0x45
69#define TDA10048_CONF_POLARITY 0x46
70#define TDA10048_GPIO_SP_DS0 0x48
71#define TDA10048_GPIO_SP_DS1 0x49
72#define TDA10048_GPIO_SP_DS2 0x4A
73#define TDA10048_GPIO_SP_DS3 0x4B
74#define TDA10048_GPIO_OUT_SEL 0x4C
75#define TDA10048_GPIO_SELECT 0x4D
76#define TDA10048_IC_MODE 0x4E
77#define TDA10048_CONF_XO 0x50
78#define TDA10048_CONF_PLL1 0x51
79#define TDA10048_CONF_PLL2 0x52
80#define TDA10048_CONF_PLL3 0x53
81#define TDA10048_CONF_ADC 0x54
82#define TDA10048_CONF_ADC_2 0x55
83#define TDA10048_CONF_C1_1 0x60
84#define TDA10048_CONF_C1_3 0x62
85#define TDA10048_AGC_CONF 0x70
86#define TDA10048_AGC_THRESHOLD_LSB 0x72
87#define TDA10048_AGC_THRESHOLD_MSB 0x73
88#define TDA10048_AGC_RENORM 0x74
89#define TDA10048_AGC_GAINS 0x76
90#define TDA10048_AGC_TUN_MIN 0x78
91#define TDA10048_AGC_TUN_MAX 0x79
92#define TDA10048_AGC_IF_MIN 0x7A
93#define TDA10048_AGC_IF_MAX 0x7B
94#define TDA10048_AGC_TUN_LEVEL 0x7E
95#define TDA10048_AGC_IF_LEVEL 0x7F
96#define TDA10048_DIG_AGC_LEVEL 0x81
97#define TDA10048_FREQ_PHY2_LSB 0x86
98#define TDA10048_FREQ_PHY2_MSB 0x87
99#define TDA10048_TIME_INVWREF_LSB 0x88
100#define TDA10048_TIME_INVWREF_MSB 0x89
101#define TDA10048_TIME_WREF_LSB 0x8A
102#define TDA10048_TIME_WREF_MID1 0x8B
103#define TDA10048_TIME_WREF_MID2 0x8C
104#define TDA10048_TIME_WREF_MSB 0x8D
105#define TDA10048_NP_OUT 0xA2
106#define TDA10048_CELL_ID_LSB 0xA4
107#define TDA10048_CELL_ID_MSB 0xA5
108#define TDA10048_EXTTPS_ODD 0xAA
109#define TDA10048_EXTTPS_EVEN 0xAB
110#define TDA10048_TPS_LENGTH 0xAC
111#define TDA10048_FREE_REG_1 0xB2
112#define TDA10048_FREE_REG_2 0xB3
113#define TDA10048_CONF_C3_1 0xC0
114#define TDA10048_CYBER_CTRL 0xC2
115#define TDA10048_CBER_NMAX_LSB 0xC4
116#define TDA10048_CBER_NMAX_MSB 0xC5
117#define TDA10048_CBER_LSB 0xC6
118#define TDA10048_CBER_MSB 0xC7
119#define TDA10048_VBER_LSB 0xC8
120#define TDA10048_VBER_MID 0xC9
121#define TDA10048_VBER_MSB 0xCA
122#define TDA10048_CYBER_LUT 0xCC
123#define TDA10048_UNCOR_CTRL 0xCD
124#define TDA10048_UNCOR_CPT_LSB 0xCE
125#define TDA10048_UNCOR_CPT_MSB 0xCF
126#define TDA10048_SOFT_IT_C3 0xD6
127#define TDA10048_CONF_TS2 0xE0
128#define TDA10048_CONF_TS1 0xE1
129
130static unsigned int debug;
131
132#define dprintk(level, fmt, arg...)\
133 do { if (debug >= level)\
134 printk(KERN_DEBUG "tda10048: " fmt, ## arg);\
135 } while (0)
136
137struct tda10048_state {
138
139 struct i2c_adapter *i2c;
140
141 /* configuration settings */
142 const struct tda10048_config *config;
143 struct dvb_frontend frontend;
144
145 int fwloaded;
146};
147
148static struct init_tab {
149 u8 reg;
150 u16 data;
151} init_tab[] = {
152 { TDA10048_CONF_PLL1, 0x08 },
153 { TDA10048_CONF_ADC_2, 0x00 },
154 { TDA10048_CONF_C4_1, 0x00 },
155 { TDA10048_CONF_PLL1, 0x0f },
156 { TDA10048_CONF_PLL2, 0x0a },
157 { TDA10048_CONF_PLL3, 0x43 },
158 { TDA10048_FREQ_PHY2_LSB, 0x02 },
159 { TDA10048_FREQ_PHY2_MSB, 0x0a },
160 { TDA10048_TIME_WREF_LSB, 0xbd },
161 { TDA10048_TIME_WREF_MID1, 0xe4 },
162 { TDA10048_TIME_WREF_MID2, 0xa8 },
163 { TDA10048_TIME_WREF_MSB, 0x02 },
164 { TDA10048_TIME_INVWREF_LSB, 0x04 },
165 { TDA10048_TIME_INVWREF_MSB, 0x06 },
166 { TDA10048_CONF_C4_1, 0x00 },
167 { TDA10048_CONF_C1_1, 0xa8 },
168 { TDA10048_AGC_CONF, 0x16 },
169 { TDA10048_CONF_C1_3, 0x0b },
170 { TDA10048_AGC_TUN_MIN, 0x00 },
171 { TDA10048_AGC_TUN_MAX, 0xff },
172 { TDA10048_AGC_IF_MIN, 0x00 },
173 { TDA10048_AGC_IF_MAX, 0xff },
174 { TDA10048_AGC_THRESHOLD_MSB, 0x00 },
175 { TDA10048_AGC_THRESHOLD_LSB, 0x70 },
176 { TDA10048_CYBER_CTRL, 0x38 },
177 { TDA10048_AGC_GAINS, 0x12 },
178 { TDA10048_CONF_XO, 0x00 },
179 { TDA10048_CONF_TS1, 0x07 },
180 { TDA10048_IC_MODE, 0x00 },
181 { TDA10048_CONF_TS2, 0xc0 },
182 { TDA10048_CONF_TRISTATE1, 0x21 },
183 { TDA10048_CONF_TRISTATE2, 0x00 },
184 { TDA10048_CONF_POLARITY, 0x00 },
185 { TDA10048_CONF_C4_2, 0x04 },
186 { TDA10048_CONF_ADC, 0x60 },
187 { TDA10048_CONF_ADC_2, 0x10 },
188 { TDA10048_CONF_ADC, 0x60 },
189 { TDA10048_CONF_ADC_2, 0x00 },
190 { TDA10048_CONF_C1_1, 0xa8 },
191 { TDA10048_UNCOR_CTRL, 0x00 },
192 { TDA10048_CONF_C4_2, 0x04 },
193};
194
195static int tda10048_writereg(struct tda10048_state *state, u8 reg, u8 data)
196{
197 int ret;
198 u8 buf [] = { reg, data };
199 struct i2c_msg msg = {
200 .addr = state->config->demod_address,
201 .flags = 0, .buf = buf, .len = 2 };
202
203 dprintk(2, "%s(reg = 0x%02x, data = 0x%02x)\n", __func__, reg, data);
204
205 ret = i2c_transfer(state->i2c, &msg, 1);
206
207 if (ret != 1)
208 printk("%s: writereg error (ret == %i)\n", __func__, ret);
209
210 return (ret != 1) ? -1 : 0;
211}
212
213static u8 tda10048_readreg(struct tda10048_state *state, u8 reg)
214{
215 int ret;
216 u8 b0 [] = { reg };
217 u8 b1 [] = { 0 };
218 struct i2c_msg msg [] = {
219 { .addr = state->config->demod_address,
220 .flags = 0, .buf = b0, .len = 1 },
221 { .addr = state->config->demod_address,
222 .flags = I2C_M_RD, .buf = b1, .len = 1 } };
223
224 dprintk(2, "%s(reg = 0x%02x)\n", __func__, reg);
225
226 ret = i2c_transfer(state->i2c, msg, 2);
227
228 if (ret != 2)
229 printk(KERN_ERR "%s: readreg error (ret == %i)\n",
230 __func__, ret);
231
232 return b1[0];
233}
234
235static int tda10048_writeregbulk(struct tda10048_state *state, u8 reg,
236 u8 *data, u16 len)
237{
238 int ret = -EREMOTEIO;
239 struct i2c_msg msg;
240 u8 *buf;
241
242 dprintk(2, "%s(%d, ?, len = %d)\n", __func__, reg, len);
243
244 buf = kmalloc(len + 1, GFP_KERNEL);
245 if (buf == NULL) {
246 ret = -ENOMEM;
247 goto error;
248 }
249
250 *buf = reg;
251 memcpy(buf + 1, data, len);
252
253 msg.addr = state->config->demod_address;
254 msg.flags = 0;
255 msg.buf = buf;
256 msg.len = len + 1;
257
258 dprintk(2, "%s(): write len = %d\n",
259 __func__, msg.len);
260
261 ret = i2c_transfer(state->i2c, &msg, 1);
262 if (ret != 1) {
263 printk(KERN_ERR "%s(): writereg error err %i\n",
264 __func__, ret);
265 ret = -EREMOTEIO;
266 }
267
268error:
269 kfree(buf);
270
271 return ret;
272}
273
274static int tda10048_firmware_upload(struct dvb_frontend *fe)
275{
276 struct tda10048_state *state = fe->demodulator_priv;
277 const struct firmware *fw;
278 int ret;
279 int pos = 0;
280 int cnt;
281 u8 wlen = state->config->fwbulkwritelen;
282
283 if ((wlen != TDA10048_BULKWRITE_200) && (wlen != TDA10048_BULKWRITE_50))
284 wlen = TDA10048_BULKWRITE_200;
285
286 /* request the firmware, this will block and timeout */
287 printk(KERN_INFO "%s: waiting for firmware upload (%s)...\n",
288 __func__,
289 TDA10048_DEFAULT_FIRMWARE);
290
291 ret = request_firmware(&fw, TDA10048_DEFAULT_FIRMWARE,
292 &state->i2c->dev);
293 if (ret) {
294 printk(KERN_ERR "%s: Upload failed. (file not found?)\n",
295 __func__);
296 return -EIO;
297 } else {
298 printk(KERN_INFO "%s: firmware read %Zu bytes.\n",
299 __func__,
300 fw->size);
301 ret = 0;
302 }
303
304 if (fw->size != TDA10048_DEFAULT_FIRMWARE_SIZE) {
305 printk(KERN_ERR "%s: firmware incorrect size\n", __func__);
306 return -EIO;
307 } else {
308 printk(KERN_INFO "%s: firmware uploading\n", __func__);
309
310 /* Soft reset */
311 tda10048_writereg(state, TDA10048_CONF_TRISTATE1,
312 tda10048_readreg(state, TDA10048_CONF_TRISTATE1)
313 & 0xfe);
314 tda10048_writereg(state, TDA10048_CONF_TRISTATE1,
315 tda10048_readreg(state, TDA10048_CONF_TRISTATE1)
316 | 0x01);
317
318 /* Put the demod into host download mode */
319 tda10048_writereg(state, TDA10048_CONF_C4_1,
320 tda10048_readreg(state, TDA10048_CONF_C4_1) & 0xf9);
321
322 /* Boot the DSP */
323 tda10048_writereg(state, TDA10048_CONF_C4_1,
324 tda10048_readreg(state, TDA10048_CONF_C4_1) | 0x08);
325
326 /* Prepare for download */
327 tda10048_writereg(state, TDA10048_DSP_CODE_CPT, 0);
328
329 /* Download the firmware payload */
330 while (pos < fw->size) {
331
332 if ((fw->size - pos) > wlen)
333 cnt = wlen;
334 else
335 cnt = fw->size - pos;
336
337 tda10048_writeregbulk(state, TDA10048_DSP_CODE_IN,
338 &fw->data[pos], cnt);
339
340 pos += cnt;
341 }
342
343 ret = -EIO;
344 /* Wait up to 250ms for the DSP to boot */
345 for (cnt = 0; cnt < 250 ; cnt += 10) {
346
347 msleep(10);
348
349 if (tda10048_readreg(state, TDA10048_SYNC_STATUS)
350 & 0x40) {
351 ret = 0;
352 break;
353 }
354 }
355 }
356
357 release_firmware(fw);
358
359 if (ret == 0) {
360 printk(KERN_INFO "%s: firmware uploaded\n", __func__);
361 state->fwloaded = 1;
362 } else
363 printk(KERN_ERR "%s: firmware upload failed\n", __func__);
364
365 return ret;
366}
367
368static int tda10048_set_inversion(struct dvb_frontend *fe, int inversion)
369{
370 struct tda10048_state *state = fe->demodulator_priv;
371
372 dprintk(1, "%s(%d)\n", __func__, inversion);
373
374 if (inversion == TDA10048_INVERSION_ON)
375 tda10048_writereg(state, TDA10048_CONF_C1_1,
376 tda10048_readreg(state, TDA10048_CONF_C1_1) | 0x20);
377 else
378 tda10048_writereg(state, TDA10048_CONF_C1_1,
379 tda10048_readreg(state, TDA10048_CONF_C1_1) & 0xdf);
380
381 return 0;
382}
383
384/* Retrieve the demod settings */
385static int tda10048_get_tps(struct tda10048_state *state,
386 struct dvb_ofdm_parameters *p)
387{
388 u8 val;
389
390 /* Make sure the TPS regs are valid */
391 if (!(tda10048_readreg(state, TDA10048_AUTO) & 0x01))
392 return -EAGAIN;
393
394 val = tda10048_readreg(state, TDA10048_OUT_CONF2);
395 switch ((val & 0x60) >> 5) {
396 case 0: p->constellation = QPSK; break;
397 case 1: p->constellation = QAM_16; break;
398 case 2: p->constellation = QAM_64; break;
399 }
400 switch ((val & 0x18) >> 3) {
401 case 0: p->hierarchy_information = HIERARCHY_NONE; break;
402 case 1: p->hierarchy_information = HIERARCHY_1; break;
403 case 2: p->hierarchy_information = HIERARCHY_2; break;
404 case 3: p->hierarchy_information = HIERARCHY_4; break;
405 }
406 switch (val & 0x07) {
407 case 0: p->code_rate_HP = FEC_1_2; break;
408 case 1: p->code_rate_HP = FEC_2_3; break;
409 case 2: p->code_rate_HP = FEC_3_4; break;
410 case 3: p->code_rate_HP = FEC_5_6; break;
411 case 4: p->code_rate_HP = FEC_7_8; break;
412 }
413
414 val = tda10048_readreg(state, TDA10048_OUT_CONF3);
415 switch (val & 0x07) {
416 case 0: p->code_rate_LP = FEC_1_2; break;
417 case 1: p->code_rate_LP = FEC_2_3; break;
418 case 2: p->code_rate_LP = FEC_3_4; break;
419 case 3: p->code_rate_LP = FEC_5_6; break;
420 case 4: p->code_rate_LP = FEC_7_8; break;
421 }
422
423 val = tda10048_readreg(state, TDA10048_OUT_CONF1);
424 switch ((val & 0x0c) >> 2) {
425 case 0: p->guard_interval = GUARD_INTERVAL_1_32; break;
426 case 1: p->guard_interval = GUARD_INTERVAL_1_16; break;
427 case 2: p->guard_interval = GUARD_INTERVAL_1_8; break;
428 case 3: p->guard_interval = GUARD_INTERVAL_1_4; break;
429 }
430 switch (val & 0x02) {
431 case 0: p->transmission_mode = TRANSMISSION_MODE_2K; break;
432 case 1: p->transmission_mode = TRANSMISSION_MODE_8K; break;
433 }
434
435 return 0;
436}
437
438static int tda10048_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
439{
440 struct tda10048_state *state = fe->demodulator_priv;
441 dprintk(1, "%s(%d)\n", __func__, enable);
442
443 if (enable)
444 return tda10048_writereg(state, TDA10048_CONF_C4_1,
445 tda10048_readreg(state, TDA10048_CONF_C4_1) | 0x02);
446 else
447 return tda10048_writereg(state, TDA10048_CONF_C4_1,
448 tda10048_readreg(state, TDA10048_CONF_C4_1) & 0xfd);
449}
450
451static int tda10048_output_mode(struct dvb_frontend *fe, int serial)
452{
453 struct tda10048_state *state = fe->demodulator_priv;
454 dprintk(1, "%s(%d)\n", __func__, serial);
455
456 /* Ensure pins are out of tri-state */
457 tda10048_writereg(state, TDA10048_CONF_TRISTATE1, 0x21);
458 tda10048_writereg(state, TDA10048_CONF_TRISTATE2, 0x00);
459
460 if (serial) {
461 tda10048_writereg(state, TDA10048_IC_MODE, 0x80 | 0x20);
462 tda10048_writereg(state, TDA10048_CONF_TS2, 0xc0);
463 } else {
464 tda10048_writereg(state, TDA10048_IC_MODE, 0x00);
465 tda10048_writereg(state, TDA10048_CONF_TS2, 0x01);
466 }
467
468 return 0;
469}
470
471/* Talk to the demod, set the FEC, GUARD, QAM settings etc */
472/* TODO: Support manual tuning with specific params */
473static int tda10048_set_frontend(struct dvb_frontend *fe,
474 struct dvb_frontend_parameters *p)
475{
476 struct tda10048_state *state = fe->demodulator_priv;
477
478 dprintk(1, "%s(frequency=%d)\n", __func__, p->frequency);
479
480 if (fe->ops.tuner_ops.set_params) {
481
482 if (fe->ops.i2c_gate_ctrl)
483 fe->ops.i2c_gate_ctrl(fe, 1);
484
485 fe->ops.tuner_ops.set_params(fe, p);
486
487 if (fe->ops.i2c_gate_ctrl)
488 fe->ops.i2c_gate_ctrl(fe, 0);
489 }
490
491 /* Enable demod TPS auto detection and begin acquisition */
492 tda10048_writereg(state, TDA10048_AUTO, 0x57);
493
494 return 0;
495}
496
497/* Establish sane defaults and load firmware. */
498static int tda10048_init(struct dvb_frontend *fe)
499{
500 struct tda10048_state *state = fe->demodulator_priv;
501 int ret = 0, i;
502
503 dprintk(1, "%s()\n", __func__);
504
505 /* Apply register defaults */
506 for (i = 0; i < ARRAY_SIZE(init_tab); i++)
507 tda10048_writereg(state, init_tab[i].reg, init_tab[i].data);
508
509 if (state->fwloaded == 0)
510 ret = tda10048_firmware_upload(fe);
511
512 /* Set either serial or parallel */
513 tda10048_output_mode(fe, state->config->output_mode);
514
515 /* set inversion */
516 tda10048_set_inversion(fe, state->config->inversion);
517
518 /* Ensure we leave the gate closed */
519 tda10048_i2c_gate_ctrl(fe, 0);
520
521 return ret;
522}
523
524static int tda10048_read_status(struct dvb_frontend *fe, fe_status_t *status)
525{
526 struct tda10048_state *state = fe->demodulator_priv;
527 u8 reg;
528
529 *status = 0;
530
531 reg = tda10048_readreg(state, TDA10048_SYNC_STATUS);
532
533 dprintk(1, "%s() status =0x%02x\n", __func__, reg);
534
535 if (reg & 0x02)
536 *status |= FE_HAS_CARRIER;
537
538 if (reg & 0x04)
539 *status |= FE_HAS_SIGNAL;
540
541 if (reg & 0x08) {
542 *status |= FE_HAS_LOCK;
543 *status |= FE_HAS_VITERBI;
544 *status |= FE_HAS_SYNC;
545 }
546
547 return 0;
548}
549
550static int tda10048_read_ber(struct dvb_frontend *fe, u32 *ber)
551{
552 struct tda10048_state *state = fe->demodulator_priv;
553
554 dprintk(1, "%s()\n", __func__);
555
556 /* TODO: A reset may be required here */
557 *ber = tda10048_readreg(state, TDA10048_CBER_MSB) << 8 |
558 tda10048_readreg(state, TDA10048_CBER_LSB);
559
560 return 0;
561}
562
563static int tda10048_read_signal_strength(struct dvb_frontend *fe,
564 u16 *signal_strength)
565{
566 struct tda10048_state *state = fe->demodulator_priv;
567 u8 v;
568
569 dprintk(1, "%s()\n", __func__);
570
571 *signal_strength = 65535;
572
573 v = tda10048_readreg(state, TDA10048_NP_OUT);
574 if (v > 0)
575 *signal_strength -= (v << 8) | v;
576
577 return 0;
578}
579
580/* SNR lookup table */
581static struct snr_tab {
582 u8 val;
583 u8 data;
584} snr_tab[] = {
585 { 0, 0 },
586 { 1, 246 },
587 { 2, 215 },
588 { 3, 198 },
589 { 4, 185 },
590 { 5, 176 },
591 { 6, 168 },
592 { 7, 161 },
593 { 8, 155 },
594 { 9, 150 },
595 { 10, 146 },
596 { 11, 141 },
597 { 12, 138 },
598 { 13, 134 },
599 { 14, 131 },
600 { 15, 128 },
601 { 16, 125 },
602 { 17, 122 },
603 { 18, 120 },
604 { 19, 118 },
605 { 20, 115 },
606 { 21, 113 },
607 { 22, 111 },
608 { 23, 109 },
609 { 24, 107 },
610 { 25, 106 },
611 { 26, 104 },
612 { 27, 102 },
613 { 28, 101 },
614 { 29, 99 },
615 { 30, 98 },
616 { 31, 96 },
617 { 32, 95 },
618 { 33, 94 },
619 { 34, 92 },
620 { 35, 91 },
621 { 36, 90 },
622 { 37, 89 },
623 { 38, 88 },
624 { 39, 86 },
625 { 40, 85 },
626 { 41, 84 },
627 { 42, 83 },
628 { 43, 82 },
629 { 44, 81 },
630 { 45, 80 },
631 { 46, 79 },
632 { 47, 78 },
633 { 48, 77 },
634 { 49, 76 },
635 { 50, 76 },
636 { 51, 75 },
637 { 52, 74 },
638 { 53, 73 },
639 { 54, 72 },
640 { 56, 71 },
641 { 57, 70 },
642 { 58, 69 },
643 { 60, 68 },
644 { 61, 67 },
645 { 63, 66 },
646 { 64, 65 },
647 { 66, 64 },
648 { 67, 63 },
649 { 68, 62 },
650 { 69, 62 },
651 { 70, 61 },
652 { 72, 60 },
653 { 74, 59 },
654 { 75, 58 },
655 { 77, 57 },
656 { 79, 56 },
657 { 81, 55 },
658 { 83, 54 },
659 { 85, 53 },
660 { 87, 52 },
661 { 89, 51 },
662 { 91, 50 },
663 { 93, 49 },
664 { 95, 48 },
665 { 97, 47 },
666 { 100, 46 },
667 { 102, 45 },
668 { 104, 44 },
669 { 107, 43 },
670 { 109, 42 },
671 { 112, 41 },
672 { 114, 40 },
673 { 117, 39 },
674 { 120, 38 },
675 { 123, 37 },
676 { 125, 36 },
677 { 128, 35 },
678 { 131, 34 },
679 { 134, 33 },
680 { 138, 32 },
681 { 141, 31 },
682 { 144, 30 },
683 { 147, 29 },
684 { 151, 28 },
685 { 154, 27 },
686 { 158, 26 },
687 { 162, 25 },
688 { 165, 24 },
689 { 169, 23 },
690 { 173, 22 },
691 { 177, 21 },
692 { 181, 20 },
693 { 186, 19 },
694 { 190, 18 },
695 { 194, 17 },
696 { 199, 16 },
697 { 204, 15 },
698 { 208, 14 },
699 { 213, 13 },
700 { 218, 12 },
701 { 223, 11 },
702 { 229, 10 },
703 { 234, 9 },
704 { 239, 8 },
705 { 245, 7 },
706 { 251, 6 },
707 { 255, 5 },
708};
709
710static int tda10048_read_snr(struct dvb_frontend *fe, u16 *snr)
711{
712 struct tda10048_state *state = fe->demodulator_priv;
713 u8 v;
714 int i, ret = -EINVAL;
715
716 dprintk(1, "%s()\n", __func__);
717
718 v = tda10048_readreg(state, TDA10048_NP_OUT);
719 for (i = 0; i < ARRAY_SIZE(snr_tab); i++) {
720 if (v <= snr_tab[i].val) {
721 *snr = snr_tab[i].data;
722 ret = 0;
723 break;
724 }
725 }
726
727 return ret;
728}
729
730static int tda10048_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
731{
732 struct tda10048_state *state = fe->demodulator_priv;
733
734 dprintk(1, "%s()\n", __func__);
735
736 *ucblocks = tda10048_readreg(state, TDA10048_UNCOR_CPT_MSB) << 8 |
737 tda10048_readreg(state, TDA10048_UNCOR_CPT_LSB);
738
739 return 0;
740}
741
742static int tda10048_get_frontend(struct dvb_frontend *fe,
743 struct dvb_frontend_parameters *p)
744{
745 struct tda10048_state *state = fe->demodulator_priv;
746
747 dprintk(1, "%s()\n", __func__);
748
749 p->inversion = tda10048_readreg(state, TDA10048_CONF_C1_1)
750 & 0x20 ? INVERSION_ON : INVERSION_OFF;
751
752 return tda10048_get_tps(state, &p->u.ofdm);
753}
754
755static int tda10048_get_tune_settings(struct dvb_frontend *fe,
756 struct dvb_frontend_tune_settings *tune)
757{
758 tune->min_delay_ms = 1000;
759 return 0;
760}
761
762static void tda10048_release(struct dvb_frontend *fe)
763{
764 struct tda10048_state *state = fe->demodulator_priv;
765 dprintk(1, "%s()\n", __func__);
766 kfree(state);
767}
768
769static struct dvb_frontend_ops tda10048_ops;
770
771struct dvb_frontend *tda10048_attach(const struct tda10048_config *config,
772 struct i2c_adapter *i2c)
773{
774 struct tda10048_state *state = NULL;
775
776 dprintk(1, "%s()\n", __func__);
777
778 /* allocate memory for the internal state */
779 state = kmalloc(sizeof(struct tda10048_state), GFP_KERNEL);
780 if (state == NULL)
781 goto error;
782
783 /* setup the state */
784 state->config = config;
785 state->i2c = i2c;
786 state->fwloaded = 0;
787
788 /* check if the demod is present */
789 if (tda10048_readreg(state, TDA10048_IDENTITY) != 0x048)
790 goto error;
791
792 /* create dvb_frontend */
793 memcpy(&state->frontend.ops, &tda10048_ops,
794 sizeof(struct dvb_frontend_ops));
795 state->frontend.demodulator_priv = state;
796
797 /* Leave the gate closed */
798 tda10048_i2c_gate_ctrl(&state->frontend, 0);
799
800 return &state->frontend;
801
802error:
803 kfree(state);
804 return NULL;
805}
806EXPORT_SYMBOL(tda10048_attach);
807
808static struct dvb_frontend_ops tda10048_ops = {
809
810 .info = {
811 .name = "NXP TDA10048HN DVB-T",
812 .type = FE_OFDM,
813 .frequency_min = 177000000,
814 .frequency_max = 858000000,
815 .frequency_stepsize = 166666,
816 .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
817 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
818 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
819 FE_CAN_HIERARCHY_AUTO | FE_CAN_GUARD_INTERVAL_AUTO |
820 FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_RECOVER
821 },
822
823 .release = tda10048_release,
824 .init = tda10048_init,
825 .i2c_gate_ctrl = tda10048_i2c_gate_ctrl,
826 .set_frontend = tda10048_set_frontend,
827 .get_frontend = tda10048_get_frontend,
828 .get_tune_settings = tda10048_get_tune_settings,
829 .read_status = tda10048_read_status,
830 .read_ber = tda10048_read_ber,
831 .read_signal_strength = tda10048_read_signal_strength,
832 .read_snr = tda10048_read_snr,
833 .read_ucblocks = tda10048_read_ucblocks,
834};
835
836module_param(debug, int, 0644);
837MODULE_PARM_DESC(debug, "Enable verbose debug messages");
838
839MODULE_DESCRIPTION("NXP TDA10048HN DVB-T Demodulator driver");
840MODULE_AUTHOR("Steven Toth");
841MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/tda10048.h b/drivers/media/dvb/frontends/tda10048.h
new file mode 100644
index 000000000000..2b5c78e62c86
--- /dev/null
+++ b/drivers/media/dvb/frontends/tda10048.h
@@ -0,0 +1,63 @@
1/*
2 NXP TDA10048HN DVB OFDM demodulator driver
3
4 Copyright (C) 2008 Steven Toth <stoth@hauppauge.com>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19
20*/
21
22#ifndef TDA10048_H
23#define TDA10048_H
24
25#include <linux/dvb/frontend.h>
26#include <linux/firmware.h>
27
28struct tda10048_config {
29
30 /* the demodulator's i2c address */
31 u8 demod_address;
32
33 /* serial/parallel output */
34#define TDA10048_PARALLEL_OUTPUT 0
35#define TDA10048_SERIAL_OUTPUT 1
36 u8 output_mode;
37
38#define TDA10048_BULKWRITE_200 200
39#define TDA10048_BULKWRITE_50 50
40 u8 fwbulkwritelen;
41
42 /* Spectral Inversion */
43#define TDA10048_INVERSION_OFF 0
44#define TDA10048_INVERSION_ON 1
45 u8 inversion;
46};
47
48#if defined(CONFIG_DVB_TDA10048) || \
49 (defined(CONFIG_DVB_TDA10048_MODULE) && defined(MODULE))
50extern struct dvb_frontend *tda10048_attach(
51 const struct tda10048_config *config,
52 struct i2c_adapter *i2c);
53#else
54static inline struct dvb_frontend *tda10048_attach(
55 const struct tda10048_config *config,
56 struct i2c_adapter *i2c)
57{
58 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
59 return NULL;
60}
61#endif /* CONFIG_DVB_TDA10048 */
62
63#endif /* TDA10048_H */
diff --git a/drivers/media/dvb/frontends/tda1004x.c b/drivers/media/dvb/frontends/tda1004x.c
index 8415a8a5247a..49973846373e 100644
--- a/drivers/media/dvb/frontends/tda1004x.c
+++ b/drivers/media/dvb/frontends/tda1004x.c
@@ -131,16 +131,16 @@ static int tda1004x_write_byteI(struct tda1004x_state *state, int reg, int data)
131 u8 buf[] = { reg, data }; 131 u8 buf[] = { reg, data };
132 struct i2c_msg msg = { .flags = 0, .buf = buf, .len = 2 }; 132 struct i2c_msg msg = { .flags = 0, .buf = buf, .len = 2 };
133 133
134 dprintk("%s: reg=0x%x, data=0x%x\n", __FUNCTION__, reg, data); 134 dprintk("%s: reg=0x%x, data=0x%x\n", __func__, reg, data);
135 135
136 msg.addr = state->config->demod_address; 136 msg.addr = state->config->demod_address;
137 ret = i2c_transfer(state->i2c, &msg, 1); 137 ret = i2c_transfer(state->i2c, &msg, 1);
138 138
139 if (ret != 1) 139 if (ret != 1)
140 dprintk("%s: error reg=0x%x, data=0x%x, ret=%i\n", 140 dprintk("%s: error reg=0x%x, data=0x%x, ret=%i\n",
141 __FUNCTION__, reg, data, ret); 141 __func__, reg, data, ret);
142 142
143 dprintk("%s: success reg=0x%x, data=0x%x, ret=%i\n", __FUNCTION__, 143 dprintk("%s: success reg=0x%x, data=0x%x, ret=%i\n", __func__,
144 reg, data, ret); 144 reg, data, ret);
145 return (ret != 1) ? -1 : 0; 145 return (ret != 1) ? -1 : 0;
146} 146}
@@ -153,19 +153,19 @@ static int tda1004x_read_byte(struct tda1004x_state *state, int reg)
153 struct i2c_msg msg[] = {{ .flags = 0, .buf = b0, .len = 1 }, 153 struct i2c_msg msg[] = {{ .flags = 0, .buf = b0, .len = 1 },
154 { .flags = I2C_M_RD, .buf = b1, .len = 1 }}; 154 { .flags = I2C_M_RD, .buf = b1, .len = 1 }};
155 155
156 dprintk("%s: reg=0x%x\n", __FUNCTION__, reg); 156 dprintk("%s: reg=0x%x\n", __func__, reg);
157 157
158 msg[0].addr = state->config->demod_address; 158 msg[0].addr = state->config->demod_address;
159 msg[1].addr = state->config->demod_address; 159 msg[1].addr = state->config->demod_address;
160 ret = i2c_transfer(state->i2c, msg, 2); 160 ret = i2c_transfer(state->i2c, msg, 2);
161 161
162 if (ret != 2) { 162 if (ret != 2) {
163 dprintk("%s: error reg=0x%x, ret=%i\n", __FUNCTION__, reg, 163 dprintk("%s: error reg=0x%x, ret=%i\n", __func__, reg,
164 ret); 164 ret);
165 return -1; 165 return -1;
166 } 166 }
167 167
168 dprintk("%s: success reg=0x%x, data=0x%x, ret=%i\n", __FUNCTION__, 168 dprintk("%s: success reg=0x%x, data=0x%x, ret=%i\n", __func__,
169 reg, b1[0], ret); 169 reg, b1[0], ret);
170 return b1[0]; 170 return b1[0];
171} 171}
@@ -173,7 +173,7 @@ static int tda1004x_read_byte(struct tda1004x_state *state, int reg)
173static int tda1004x_write_mask(struct tda1004x_state *state, int reg, int mask, int data) 173static int tda1004x_write_mask(struct tda1004x_state *state, int reg, int mask, int data)
174{ 174{
175 int val; 175 int val;
176 dprintk("%s: reg=0x%x, mask=0x%x, data=0x%x\n", __FUNCTION__, reg, 176 dprintk("%s: reg=0x%x, mask=0x%x, data=0x%x\n", __func__, reg,
177 mask, data); 177 mask, data);
178 178
179 // read a byte and check 179 // read a byte and check
@@ -194,7 +194,7 @@ static int tda1004x_write_buf(struct tda1004x_state *state, int reg, unsigned ch
194 int i; 194 int i;
195 int result; 195 int result;
196 196
197 dprintk("%s: reg=0x%x, len=0x%x\n", __FUNCTION__, reg, len); 197 dprintk("%s: reg=0x%x, len=0x%x\n", __func__, reg, len);
198 198
199 result = 0; 199 result = 0;
200 for (i = 0; i < len; i++) { 200 for (i = 0; i < len; i++) {
@@ -209,7 +209,7 @@ static int tda1004x_write_buf(struct tda1004x_state *state, int reg, unsigned ch
209static int tda1004x_enable_tuner_i2c(struct tda1004x_state *state) 209static int tda1004x_enable_tuner_i2c(struct tda1004x_state *state)
210{ 210{
211 int result; 211 int result;
212 dprintk("%s\n", __FUNCTION__); 212 dprintk("%s\n", __func__);
213 213
214 result = tda1004x_write_mask(state, TDA1004X_CONFC4, 2, 2); 214 result = tda1004x_write_mask(state, TDA1004X_CONFC4, 2, 2);
215 msleep(20); 215 msleep(20);
@@ -218,7 +218,7 @@ static int tda1004x_enable_tuner_i2c(struct tda1004x_state *state)
218 218
219static int tda1004x_disable_tuner_i2c(struct tda1004x_state *state) 219static int tda1004x_disable_tuner_i2c(struct tda1004x_state *state)
220{ 220{
221 dprintk("%s\n", __FUNCTION__); 221 dprintk("%s\n", __func__);
222 222
223 return tda1004x_write_mask(state, TDA1004X_CONFC4, 2, 0); 223 return tda1004x_write_mask(state, TDA1004X_CONFC4, 2, 0);
224} 224}
@@ -345,7 +345,7 @@ static int tda1004x_do_upload(struct tda1004x_state *state,
345 } 345 }
346 pos += tx_size; 346 pos += tx_size;
347 347
348 dprintk("%s: fw_pos=0x%x\n", __FUNCTION__, pos); 348 dprintk("%s: fw_pos=0x%x\n", __func__, pos);
349 } 349 }
350 // give the DSP a chance to settle 03/10/05 Hac 350 // give the DSP a chance to settle 03/10/05 Hac
351 msleep(100); 351 msleep(100);
@@ -444,10 +444,10 @@ static void tda10046_init_plls(struct dvb_frontend* fe)
444 tda1004x_write_byteI(state, TDA10046H_CONFPLL2, 0x03); // PLL M = 3 444 tda1004x_write_byteI(state, TDA10046H_CONFPLL2, 0x03); // PLL M = 3
445 } 445 }
446 if (state->config->xtal_freq == TDA10046_XTAL_4M ) { 446 if (state->config->xtal_freq == TDA10046_XTAL_4M ) {
447 dprintk("%s: setting up PLLs for a 4 MHz Xtal\n", __FUNCTION__); 447 dprintk("%s: setting up PLLs for a 4 MHz Xtal\n", __func__);
448 tda1004x_write_byteI(state, TDA10046H_CONFPLL3, 0); // PLL P = N = 0 448 tda1004x_write_byteI(state, TDA10046H_CONFPLL3, 0); // PLL P = N = 0
449 } else { 449 } else {
450 dprintk("%s: setting up PLLs for a 16 MHz Xtal\n", __FUNCTION__); 450 dprintk("%s: setting up PLLs for a 16 MHz Xtal\n", __func__);
451 tda1004x_write_byteI(state, TDA10046H_CONFPLL3, 3); // PLL P = 0, N = 3 451 tda1004x_write_byteI(state, TDA10046H_CONFPLL3, 3); // PLL P = 0, N = 3
452 } 452 }
453 if(tda10046_clk53m) 453 if(tda10046_clk53m)
@@ -488,7 +488,7 @@ static int tda10046_fwupload(struct dvb_frontend* fe)
488 if (state->config->xtal_freq == TDA10046_XTAL_4M) { 488 if (state->config->xtal_freq == TDA10046_XTAL_4M) {
489 tda1004x_write_byteI(state, TDA1004X_CONFC4, 0); 489 tda1004x_write_byteI(state, TDA1004X_CONFC4, 0);
490 } else { 490 } else {
491 dprintk("%s: 16MHz Xtal, reducing I2C speed\n", __FUNCTION__); 491 dprintk("%s: 16MHz Xtal, reducing I2C speed\n", __func__);
492 tda1004x_write_byteI(state, TDA1004X_CONFC4, 0x80); 492 tda1004x_write_byteI(state, TDA1004X_CONFC4, 0x80);
493 } 493 }
494 tda1004x_write_mask(state, TDA10046H_CONF_TRISTATE1, 1, 0); 494 tda1004x_write_mask(state, TDA10046H_CONF_TRISTATE1, 1, 0);
@@ -594,7 +594,7 @@ static int tda10045_init(struct dvb_frontend* fe)
594{ 594{
595 struct tda1004x_state* state = fe->demodulator_priv; 595 struct tda1004x_state* state = fe->demodulator_priv;
596 596
597 dprintk("%s\n", __FUNCTION__); 597 dprintk("%s\n", __func__);
598 598
599 if (tda10045_fwupload(fe)) { 599 if (tda10045_fwupload(fe)) {
600 printk("tda1004x: firmware upload failed\n"); 600 printk("tda1004x: firmware upload failed\n");
@@ -624,7 +624,7 @@ static int tda10045_init(struct dvb_frontend* fe)
624static int tda10046_init(struct dvb_frontend* fe) 624static int tda10046_init(struct dvb_frontend* fe)
625{ 625{
626 struct tda1004x_state* state = fe->demodulator_priv; 626 struct tda1004x_state* state = fe->demodulator_priv;
627 dprintk("%s\n", __FUNCTION__); 627 dprintk("%s\n", __func__);
628 628
629 if (tda10046_fwupload(fe)) { 629 if (tda10046_fwupload(fe)) {
630 printk("tda1004x: firmware upload failed\n"); 630 printk("tda1004x: firmware upload failed\n");
@@ -686,7 +686,7 @@ static int tda1004x_set_fe(struct dvb_frontend* fe,
686 int tmp; 686 int tmp;
687 int inversion; 687 int inversion;
688 688
689 dprintk("%s\n", __FUNCTION__); 689 dprintk("%s\n", __func__);
690 690
691 if (state->demod_type == TDA1004X_DEMOD_TDA10046) { 691 if (state->demod_type == TDA1004X_DEMOD_TDA10046) {
692 // setup auto offset 692 // setup auto offset
@@ -881,7 +881,7 @@ static int tda1004x_get_fe(struct dvb_frontend* fe, struct dvb_frontend_paramete
881{ 881{
882 struct tda1004x_state* state = fe->demodulator_priv; 882 struct tda1004x_state* state = fe->demodulator_priv;
883 883
884 dprintk("%s\n", __FUNCTION__); 884 dprintk("%s\n", __func__);
885 885
886 // inversion status 886 // inversion status
887 fe_params->inversion = INVERSION_OFF; 887 fe_params->inversion = INVERSION_OFF;
@@ -989,7 +989,7 @@ static int tda1004x_read_status(struct dvb_frontend* fe, fe_status_t * fe_status
989 int cber; 989 int cber;
990 int vber; 990 int vber;
991 991
992 dprintk("%s\n", __FUNCTION__); 992 dprintk("%s\n", __func__);
993 993
994 // read status 994 // read status
995 status = tda1004x_read_byte(state, TDA1004X_STATUS_CD); 995 status = tda1004x_read_byte(state, TDA1004X_STATUS_CD);
@@ -1048,7 +1048,7 @@ static int tda1004x_read_status(struct dvb_frontend* fe, fe_status_t * fe_status
1048 } 1048 }
1049 1049
1050 // success 1050 // success
1051 dprintk("%s: fe_status=0x%x\n", __FUNCTION__, *fe_status); 1051 dprintk("%s: fe_status=0x%x\n", __func__, *fe_status);
1052 return 0; 1052 return 0;
1053} 1053}
1054 1054
@@ -1058,7 +1058,7 @@ static int tda1004x_read_signal_strength(struct dvb_frontend* fe, u16 * signal)
1058 int tmp; 1058 int tmp;
1059 int reg = 0; 1059 int reg = 0;
1060 1060
1061 dprintk("%s\n", __FUNCTION__); 1061 dprintk("%s\n", __func__);
1062 1062
1063 // determine the register to use 1063 // determine the register to use
1064 switch (state->demod_type) { 1064 switch (state->demod_type) {
@@ -1077,7 +1077,7 @@ static int tda1004x_read_signal_strength(struct dvb_frontend* fe, u16 * signal)
1077 return -EIO; 1077 return -EIO;
1078 1078
1079 *signal = (tmp << 8) | tmp; 1079 *signal = (tmp << 8) | tmp;
1080 dprintk("%s: signal=0x%x\n", __FUNCTION__, *signal); 1080 dprintk("%s: signal=0x%x\n", __func__, *signal);
1081 return 0; 1081 return 0;
1082} 1082}
1083 1083
@@ -1086,7 +1086,7 @@ static int tda1004x_read_snr(struct dvb_frontend* fe, u16 * snr)
1086 struct tda1004x_state* state = fe->demodulator_priv; 1086 struct tda1004x_state* state = fe->demodulator_priv;
1087 int tmp; 1087 int tmp;
1088 1088
1089 dprintk("%s\n", __FUNCTION__); 1089 dprintk("%s\n", __func__);
1090 1090
1091 // read it 1091 // read it
1092 tmp = tda1004x_read_byte(state, TDA1004X_SNR); 1092 tmp = tda1004x_read_byte(state, TDA1004X_SNR);
@@ -1095,7 +1095,7 @@ static int tda1004x_read_snr(struct dvb_frontend* fe, u16 * snr)
1095 tmp = 255 - tmp; 1095 tmp = 255 - tmp;
1096 1096
1097 *snr = ((tmp << 8) | tmp); 1097 *snr = ((tmp << 8) | tmp);
1098 dprintk("%s: snr=0x%x\n", __FUNCTION__, *snr); 1098 dprintk("%s: snr=0x%x\n", __func__, *snr);
1099 return 0; 1099 return 0;
1100} 1100}
1101 1101
@@ -1106,7 +1106,7 @@ static int tda1004x_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
1106 int tmp2; 1106 int tmp2;
1107 int counter; 1107 int counter;
1108 1108
1109 dprintk("%s\n", __FUNCTION__); 1109 dprintk("%s\n", __func__);
1110 1110
1111 // read the UCBLOCKS and reset 1111 // read the UCBLOCKS and reset
1112 counter = 0; 1112 counter = 0;
@@ -1132,7 +1132,7 @@ static int tda1004x_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
1132 else 1132 else
1133 *ucblocks = 0xffffffff; 1133 *ucblocks = 0xffffffff;
1134 1134
1135 dprintk("%s: ucblocks=0x%x\n", __FUNCTION__, *ucblocks); 1135 dprintk("%s: ucblocks=0x%x\n", __func__, *ucblocks);
1136 return 0; 1136 return 0;
1137} 1137}
1138 1138
@@ -1141,7 +1141,7 @@ static int tda1004x_read_ber(struct dvb_frontend* fe, u32* ber)
1141 struct tda1004x_state* state = fe->demodulator_priv; 1141 struct tda1004x_state* state = fe->demodulator_priv;
1142 int tmp; 1142 int tmp;
1143 1143
1144 dprintk("%s\n", __FUNCTION__); 1144 dprintk("%s\n", __func__);
1145 1145
1146 // read it in 1146 // read it in
1147 tmp = tda1004x_read_byte(state, TDA1004X_CBER_LSB); 1147 tmp = tda1004x_read_byte(state, TDA1004X_CBER_LSB);
@@ -1155,7 +1155,7 @@ static int tda1004x_read_ber(struct dvb_frontend* fe, u32* ber)
1155 // The address 0x20 should be read to cope with a TDA10046 bug 1155 // The address 0x20 should be read to cope with a TDA10046 bug
1156 tda1004x_read_byte(state, TDA1004X_CBER_RESET); 1156 tda1004x_read_byte(state, TDA1004X_CBER_RESET);
1157 1157
1158 dprintk("%s: ber=0x%x\n", __FUNCTION__, *ber); 1158 dprintk("%s: ber=0x%x\n", __func__, *ber);
1159 return 0; 1159 return 0;
1160} 1160}
1161 1161
diff --git a/drivers/media/dvb/frontends/tda1004x.h b/drivers/media/dvb/frontends/tda1004x.h
index abae84350142..4e27ffb0f14e 100644
--- a/drivers/media/dvb/frontends/tda1004x.h
+++ b/drivers/media/dvb/frontends/tda1004x.h
@@ -94,7 +94,6 @@ struct tda1004x_config
94 94
95 /* slave address and configuration of the tuner */ 95 /* slave address and configuration of the tuner */
96 u8 tuner_address; 96 u8 tuner_address;
97 u8 tuner_config;
98 u8 antenna_switch; 97 u8 antenna_switch;
99 98
100 /* if the board uses another I2c Bridge (tda8290), its address */ 99 /* if the board uses another I2c Bridge (tda8290), its address */
@@ -128,13 +127,13 @@ extern struct dvb_frontend* tda10046_attach(const struct tda1004x_config* config
128static inline struct dvb_frontend* tda10045_attach(const struct tda1004x_config* config, 127static inline struct dvb_frontend* tda10045_attach(const struct tda1004x_config* config,
129 struct i2c_adapter* i2c) 128 struct i2c_adapter* i2c)
130{ 129{
131 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 130 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
132 return NULL; 131 return NULL;
133} 132}
134static inline struct dvb_frontend* tda10046_attach(const struct tda1004x_config* config, 133static inline struct dvb_frontend* tda10046_attach(const struct tda1004x_config* config,
135 struct i2c_adapter* i2c) 134 struct i2c_adapter* i2c)
136{ 135{
137 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 136 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
138 return NULL; 137 return NULL;
139} 138}
140#endif // CONFIG_DVB_TDA1004X 139#endif // CONFIG_DVB_TDA1004X
diff --git a/drivers/media/dvb/frontends/tda10086.c b/drivers/media/dvb/frontends/tda10086.c
index 0d2b69a99ad4..a17ce3c4ad86 100644
--- a/drivers/media/dvb/frontends/tda10086.c
+++ b/drivers/media/dvb/frontends/tda10086.c
@@ -43,7 +43,7 @@ struct tda10086_state {
43 bool has_lock; 43 bool has_lock;
44}; 44};
45 45
46static int debug = 0; 46static int debug;
47#define dprintk(args...) \ 47#define dprintk(args...) \
48 do { \ 48 do { \
49 if (debug) printk(KERN_DEBUG "tda10086: " args); \ 49 if (debug) printk(KERN_DEBUG "tda10086: " args); \
@@ -60,7 +60,7 @@ static int tda10086_write_byte(struct tda10086_state *state, int reg, int data)
60 60
61 if (ret != 1) 61 if (ret != 1)
62 dprintk("%s: error reg=0x%x, data=0x%x, ret=%i\n", 62 dprintk("%s: error reg=0x%x, data=0x%x, ret=%i\n",
63 __FUNCTION__, reg, data, ret); 63 __func__, reg, data, ret);
64 64
65 return (ret != 1) ? ret : 0; 65 return (ret != 1) ? ret : 0;
66} 66}
@@ -78,7 +78,7 @@ static int tda10086_read_byte(struct tda10086_state *state, int reg)
78 ret = i2c_transfer(state->i2c, msg, 2); 78 ret = i2c_transfer(state->i2c, msg, 2);
79 79
80 if (ret != 2) { 80 if (ret != 2) {
81 dprintk("%s: error reg=0x%x, ret=%i\n", __FUNCTION__, reg, 81 dprintk("%s: error reg=0x%x, ret=%i\n", __func__, reg,
82 ret); 82 ret);
83 return ret; 83 return ret;
84 } 84 }
@@ -90,16 +90,16 @@ static int tda10086_write_mask(struct tda10086_state *state, int reg, int mask,
90{ 90{
91 int val; 91 int val;
92 92
93 // read a byte and check 93 /* read a byte and check */
94 val = tda10086_read_byte(state, reg); 94 val = tda10086_read_byte(state, reg);
95 if (val < 0) 95 if (val < 0)
96 return val; 96 return val;
97 97
98 // mask if off 98 /* mask if off */
99 val = val & ~mask; 99 val = val & ~mask;
100 val |= data & 0xff; 100 val |= data & 0xff;
101 101
102 // write it out again 102 /* write it out again */
103 return tda10086_write_byte(state, reg, val); 103 return tda10086_write_byte(state, reg, val);
104} 104}
105 105
@@ -108,62 +108,67 @@ static int tda10086_init(struct dvb_frontend* fe)
108 struct tda10086_state* state = fe->demodulator_priv; 108 struct tda10086_state* state = fe->demodulator_priv;
109 u8 t22k_off = 0x80; 109 u8 t22k_off = 0x80;
110 110
111 dprintk ("%s\n", __FUNCTION__); 111 dprintk ("%s\n", __func__);
112 112
113 if (state->config->diseqc_tone) 113 if (state->config->diseqc_tone)
114 t22k_off = 0; 114 t22k_off = 0;
115 // reset 115 /* reset */
116 tda10086_write_byte(state, 0x00, 0x00); 116 tda10086_write_byte(state, 0x00, 0x00);
117 msleep(10); 117 msleep(10);
118 118
119 // misc setup 119 /* misc setup */
120 tda10086_write_byte(state, 0x01, 0x94); 120 tda10086_write_byte(state, 0x01, 0x94);
121 tda10086_write_byte(state, 0x02, 0x35); // NOTE: TT drivers appear to disable CSWP 121 tda10086_write_byte(state, 0x02, 0x35); /* NOTE: TT drivers appear to disable CSWP */
122 tda10086_write_byte(state, 0x03, 0xe4); 122 tda10086_write_byte(state, 0x03, 0xe4);
123 tda10086_write_byte(state, 0x04, 0x43); 123 tda10086_write_byte(state, 0x04, 0x43);
124 tda10086_write_byte(state, 0x0c, 0x0c); 124 tda10086_write_byte(state, 0x0c, 0x0c);
125 tda10086_write_byte(state, 0x1b, 0xb0); // noise threshold 125 tda10086_write_byte(state, 0x1b, 0xb0); /* noise threshold */
126 tda10086_write_byte(state, 0x20, 0x89); // misc 126 tda10086_write_byte(state, 0x20, 0x89); /* misc */
127 tda10086_write_byte(state, 0x30, 0x04); // acquisition period length 127 tda10086_write_byte(state, 0x30, 0x04); /* acquisition period length */
128 tda10086_write_byte(state, 0x32, 0x00); // irq off 128 tda10086_write_byte(state, 0x32, 0x00); /* irq off */
129 tda10086_write_byte(state, 0x31, 0x56); // setup AFC 129 tda10086_write_byte(state, 0x31, 0x56); /* setup AFC */
130 130
131 // setup PLL (assumes 16Mhz XIN) 131 /* setup PLL (this assumes SACLK = 96MHz) */
132 tda10086_write_byte(state, 0x55, 0x2c); // misc PLL setup 132 tda10086_write_byte(state, 0x55, 0x2c); /* misc PLL setup */
133 tda10086_write_byte(state, 0x3a, 0x0b); // M=12 133 if (state->config->xtal_freq == TDA10086_XTAL_16M) {
134 tda10086_write_byte(state, 0x3b, 0x01); // P=2 134 tda10086_write_byte(state, 0x3a, 0x0b); /* M=12 */
135 tda10086_write_mask(state, 0x55, 0x20, 0x00); // powerup PLL 135 tda10086_write_byte(state, 0x3b, 0x01); /* P=2 */
136 136 } else {
137 // setup TS interface 137 tda10086_write_byte(state, 0x3a, 0x17); /* M=24 */
138 tda10086_write_byte(state, 0x3b, 0x00); /* P=1 */
139 }
140 tda10086_write_mask(state, 0x55, 0x20, 0x00); /* powerup PLL */
141
142 /* setup TS interface */
138 tda10086_write_byte(state, 0x11, 0x81); 143 tda10086_write_byte(state, 0x11, 0x81);
139 tda10086_write_byte(state, 0x12, 0x81); 144 tda10086_write_byte(state, 0x12, 0x81);
140 tda10086_write_byte(state, 0x19, 0x40); // parallel mode A + MSBFIRST 145 tda10086_write_byte(state, 0x19, 0x40); /* parallel mode A + MSBFIRST */
141 tda10086_write_byte(state, 0x56, 0x80); // powerdown WPLL - unused in the mode we use 146 tda10086_write_byte(state, 0x56, 0x80); /* powerdown WPLL - unused in the mode we use */
142 tda10086_write_byte(state, 0x57, 0x08); // bypass WPLL - unused in the mode we use 147 tda10086_write_byte(state, 0x57, 0x08); /* bypass WPLL - unused in the mode we use */
143 tda10086_write_byte(state, 0x10, 0x2a); 148 tda10086_write_byte(state, 0x10, 0x2a);
144 149
145 // setup ADC 150 /* setup ADC */
146 tda10086_write_byte(state, 0x58, 0x61); // ADC setup 151 tda10086_write_byte(state, 0x58, 0x61); /* ADC setup */
147 tda10086_write_mask(state, 0x58, 0x01, 0x00); // powerup ADC 152 tda10086_write_mask(state, 0x58, 0x01, 0x00); /* powerup ADC */
148 153
149 // setup AGC 154 /* setup AGC */
150 tda10086_write_byte(state, 0x05, 0x0B); 155 tda10086_write_byte(state, 0x05, 0x0B);
151 tda10086_write_byte(state, 0x37, 0x63); 156 tda10086_write_byte(state, 0x37, 0x63);
152 tda10086_write_byte(state, 0x3f, 0x0a); // NOTE: flydvb varies it 157 tda10086_write_byte(state, 0x3f, 0x0a); /* NOTE: flydvb varies it */
153 tda10086_write_byte(state, 0x40, 0x64); 158 tda10086_write_byte(state, 0x40, 0x64);
154 tda10086_write_byte(state, 0x41, 0x4f); 159 tda10086_write_byte(state, 0x41, 0x4f);
155 tda10086_write_byte(state, 0x42, 0x43); 160 tda10086_write_byte(state, 0x42, 0x43);
156 161
157 // setup viterbi 162 /* setup viterbi */
158 tda10086_write_byte(state, 0x1a, 0x11); // VBER 10^6, DVB, QPSK 163 tda10086_write_byte(state, 0x1a, 0x11); /* VBER 10^6, DVB, QPSK */
159 164
160 // setup carrier recovery 165 /* setup carrier recovery */
161 tda10086_write_byte(state, 0x3d, 0x80); 166 tda10086_write_byte(state, 0x3d, 0x80);
162 167
163 // setup SEC 168 /* setup SEC */
164 tda10086_write_byte(state, 0x36, t22k_off); // all SEC off, 22k tone 169 tda10086_write_byte(state, 0x36, t22k_off); /* all SEC off, 22k tone */
165 tda10086_write_byte(state, 0x34, (((1<<19) * (22000/1000)) / (SACLK/1000))); // } tone frequency 170 tda10086_write_byte(state, 0x34, (((1<<19) * (22000/1000)) / (SACLK/1000)));
166 tda10086_write_byte(state, 0x35, (((1<<19) * (22000/1000)) / (SACLK/1000)) >> 8); // } 171 tda10086_write_byte(state, 0x35, (((1<<19) * (22000/1000)) / (SACLK/1000)) >> 8);
167 172
168 return 0; 173 return 0;
169} 174}
@@ -173,7 +178,7 @@ static void tda10086_diseqc_wait(struct tda10086_state *state)
173 unsigned long timeout = jiffies + msecs_to_jiffies(200); 178 unsigned long timeout = jiffies + msecs_to_jiffies(200);
174 while (!(tda10086_read_byte(state, 0x50) & 0x01)) { 179 while (!(tda10086_read_byte(state, 0x50) & 0x01)) {
175 if(time_after(jiffies, timeout)) { 180 if(time_after(jiffies, timeout)) {
176 printk("%s: diseqc queue not ready, command may be lost.\n", __FUNCTION__); 181 printk("%s: diseqc queue not ready, command may be lost.\n", __func__);
177 break; 182 break;
178 } 183 }
179 msleep(10); 184 msleep(10);
@@ -185,7 +190,7 @@ static int tda10086_set_tone (struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
185 struct tda10086_state* state = fe->demodulator_priv; 190 struct tda10086_state* state = fe->demodulator_priv;
186 u8 t22k_off = 0x80; 191 u8 t22k_off = 0x80;
187 192
188 dprintk ("%s\n", __FUNCTION__); 193 dprintk ("%s\n", __func__);
189 194
190 if (state->config->diseqc_tone) 195 if (state->config->diseqc_tone)
191 t22k_off = 0; 196 t22k_off = 0;
@@ -211,7 +216,7 @@ static int tda10086_send_master_cmd (struct dvb_frontend* fe,
211 u8 oldval; 216 u8 oldval;
212 u8 t22k_off = 0x80; 217 u8 t22k_off = 0x80;
213 218
214 dprintk ("%s\n", __FUNCTION__); 219 dprintk ("%s\n", __func__);
215 220
216 if (state->config->diseqc_tone) 221 if (state->config->diseqc_tone)
217 t22k_off = 0; 222 t22k_off = 0;
@@ -239,7 +244,7 @@ static int tda10086_send_burst (struct dvb_frontend* fe, fe_sec_mini_cmd_t minic
239 u8 oldval = tda10086_read_byte(state, 0x36); 244 u8 oldval = tda10086_read_byte(state, 0x36);
240 u8 t22k_off = 0x80; 245 u8 t22k_off = 0x80;
241 246
242 dprintk ("%s\n", __FUNCTION__); 247 dprintk ("%s\n", __func__);
243 248
244 if (state->config->diseqc_tone) 249 if (state->config->diseqc_tone)
245 t22k_off = 0; 250 t22k_off = 0;
@@ -266,7 +271,7 @@ static int tda10086_set_inversion(struct tda10086_state *state,
266{ 271{
267 u8 invval = 0x80; 272 u8 invval = 0x80;
268 273
269 dprintk ("%s %i %i\n", __FUNCTION__, fe_params->inversion, state->config->invert); 274 dprintk ("%s %i %i\n", __func__, fe_params->inversion, state->config->invert);
270 275
271 switch(fe_params->inversion) { 276 switch(fe_params->inversion) {
272 case INVERSION_OFF: 277 case INVERSION_OFF:
@@ -300,9 +305,9 @@ static int tda10086_set_symbol_rate(struct tda10086_state *state,
300 u32 bdri; 305 u32 bdri;
301 u32 symbol_rate = fe_params->u.qpsk.symbol_rate; 306 u32 symbol_rate = fe_params->u.qpsk.symbol_rate;
302 307
303 dprintk ("%s %i\n", __FUNCTION__, symbol_rate); 308 dprintk ("%s %i\n", __func__, symbol_rate);
304 309
305 // setup the decimation and anti-aliasing filters.. 310 /* setup the decimation and anti-aliasing filters.. */
306 if (symbol_rate < (u32) (SACLK * 0.0137)) { 311 if (symbol_rate < (u32) (SACLK * 0.0137)) {
307 dfn=4; 312 dfn=4;
308 afs=1; 313 afs=1;
@@ -339,13 +344,13 @@ static int tda10086_set_symbol_rate(struct tda10086_state *state,
339 byp=1; 344 byp=1;
340 } 345 }
341 346
342 // calculate BDR 347 /* calculate BDR */
343 big = (1ULL<<21) * ((u64) symbol_rate/1000ULL) * (1ULL<<dfn); 348 big = (1ULL<<21) * ((u64) symbol_rate/1000ULL) * (1ULL<<dfn);
344 big += ((SACLK/1000ULL)-1ULL); 349 big += ((SACLK/1000ULL)-1ULL);
345 do_div(big, (SACLK/1000ULL)); 350 do_div(big, (SACLK/1000ULL));
346 bdr = big & 0xfffff; 351 bdr = big & 0xfffff;
347 352
348 // calculate BDRI 353 /* calculate BDRI */
349 tmp = (1<<dfn)*(symbol_rate/1000); 354 tmp = (1<<dfn)*(symbol_rate/1000);
350 bdri = ((32 * (SACLK/1000)) + (tmp-1)) / tmp; 355 bdri = ((32 * (SACLK/1000)) + (tmp-1)) / tmp;
351 356
@@ -366,7 +371,7 @@ static int tda10086_set_fec(struct tda10086_state *state,
366{ 371{
367 u8 fecval; 372 u8 fecval;
368 373
369 dprintk ("%s %i\n", __FUNCTION__, fe_params->u.qpsk.fec_inner); 374 dprintk ("%s %i\n", __func__, fe_params->u.qpsk.fec_inner);
370 375
371 switch(fe_params->u.qpsk.fec_inner) { 376 switch(fe_params->u.qpsk.fec_inner) {
372 case FEC_1_2: 377 case FEC_1_2:
@@ -412,13 +417,13 @@ static int tda10086_set_frontend(struct dvb_frontend* fe,
412 u32 freq = 0; 417 u32 freq = 0;
413 int freqoff; 418 int freqoff;
414 419
415 dprintk ("%s\n", __FUNCTION__); 420 dprintk ("%s\n", __func__);
416 421
417 // modify parameters for tuning 422 /* modify parameters for tuning */
418 tda10086_write_byte(state, 0x02, 0x35); 423 tda10086_write_byte(state, 0x02, 0x35);
419 state->has_lock = false; 424 state->has_lock = false;
420 425
421 // set params 426 /* set params */
422 if (fe->ops.tuner_ops.set_params) { 427 if (fe->ops.tuner_ops.set_params) {
423 fe->ops.tuner_ops.set_params(fe, fe_params); 428 fe->ops.tuner_ops.set_params(fe, fe_params);
424 if (fe->ops.i2c_gate_ctrl) 429 if (fe->ops.i2c_gate_ctrl)
@@ -430,7 +435,7 @@ static int tda10086_set_frontend(struct dvb_frontend* fe,
430 fe->ops.i2c_gate_ctrl(fe, 0); 435 fe->ops.i2c_gate_ctrl(fe, 0);
431 } 436 }
432 437
433 // calcluate the frequency offset (in *Hz* not kHz) 438 /* calcluate the frequency offset (in *Hz* not kHz) */
434 freqoff = fe_params->frequency - freq; 439 freqoff = fe_params->frequency - freq;
435 freqoff = ((1<<16) * freqoff) / (SACLK/1000); 440 freqoff = ((1<<16) * freqoff) / (SACLK/1000);
436 tda10086_write_byte(state, 0x3d, 0x80 | ((freqoff >> 8) & 0x7f)); 441 tda10086_write_byte(state, 0x3d, 0x80 | ((freqoff >> 8) & 0x7f));
@@ -443,7 +448,7 @@ static int tda10086_set_frontend(struct dvb_frontend* fe,
443 if ((ret = tda10086_set_fec(state, fe_params)) < 0) 448 if ((ret = tda10086_set_fec(state, fe_params)) < 0)
444 return ret; 449 return ret;
445 450
446 // soft reset + disable TS output until lock 451 /* soft reset + disable TS output until lock */
447 tda10086_write_mask(state, 0x10, 0x40, 0x40); 452 tda10086_write_mask(state, 0x10, 0x40, 0x40);
448 tda10086_write_mask(state, 0x00, 0x01, 0x00); 453 tda10086_write_mask(state, 0x00, 0x01, 0x00);
449 454
@@ -459,13 +464,13 @@ static int tda10086_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_pa
459 int tmp; 464 int tmp;
460 u64 tmp64; 465 u64 tmp64;
461 466
462 dprintk ("%s\n", __FUNCTION__); 467 dprintk ("%s\n", __func__);
463 468
464 // check for invalid symbol rate 469 /* check for invalid symbol rate */
465 if (fe_params->u.qpsk.symbol_rate < 500000) 470 if (fe_params->u.qpsk.symbol_rate < 500000)
466 return -EINVAL; 471 return -EINVAL;
467 472
468 // calculate the updated frequency (note: we convert from Hz->kHz) 473 /* calculate the updated frequency (note: we convert from Hz->kHz) */
469 tmp64 = tda10086_read_byte(state, 0x52); 474 tmp64 = tda10086_read_byte(state, 0x52);
470 tmp64 |= (tda10086_read_byte(state, 0x51) << 8); 475 tmp64 |= (tda10086_read_byte(state, 0x51) << 8);
471 if (tmp64 & 0x8000) 476 if (tmp64 & 0x8000)
@@ -474,7 +479,7 @@ static int tda10086_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_pa
474 do_div(tmp64, (1ULL<<15) * (1ULL<<1)); 479 do_div(tmp64, (1ULL<<15) * (1ULL<<1));
475 fe_params->frequency = (int) state->frequency + (int) tmp64; 480 fe_params->frequency = (int) state->frequency + (int) tmp64;
476 481
477 // the inversion 482 /* the inversion */
478 val = tda10086_read_byte(state, 0x0c); 483 val = tda10086_read_byte(state, 0x0c);
479 if (val & 0x80) { 484 if (val & 0x80) {
480 switch(val & 0x40) { 485 switch(val & 0x40) {
@@ -505,7 +510,7 @@ static int tda10086_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_pa
505 } 510 }
506 } 511 }
507 512
508 // calculate the updated symbol rate 513 /* calculate the updated symbol rate */
509 tmp = tda10086_read_byte(state, 0x1d); 514 tmp = tda10086_read_byte(state, 0x1d);
510 if (tmp & 0x80) 515 if (tmp & 0x80)
511 tmp |= 0xffffff00; 516 tmp |= 0xffffff00;
@@ -513,7 +518,7 @@ static int tda10086_get_frontend(struct dvb_frontend* fe, struct dvb_frontend_pa
513 tmp = ((state->symbol_rate/1000) * tmp) / (1000000/1000); 518 tmp = ((state->symbol_rate/1000) * tmp) / (1000000/1000);
514 fe_params->u.qpsk.symbol_rate = state->symbol_rate + tmp; 519 fe_params->u.qpsk.symbol_rate = state->symbol_rate + tmp;
515 520
516 // the FEC 521 /* the FEC */
517 val = (tda10086_read_byte(state, 0x0d) & 0x70) >> 4; 522 val = (tda10086_read_byte(state, 0x0d) & 0x70) >> 4;
518 switch(val) { 523 switch(val) {
519 case 0x00: 524 case 0x00:
@@ -550,7 +555,7 @@ static int tda10086_read_status(struct dvb_frontend* fe, fe_status_t *fe_status)
550 struct tda10086_state* state = fe->demodulator_priv; 555 struct tda10086_state* state = fe->demodulator_priv;
551 u8 val; 556 u8 val;
552 557
553 dprintk ("%s\n", __FUNCTION__); 558 dprintk ("%s\n", __func__);
554 559
555 val = tda10086_read_byte(state, 0x0e); 560 val = tda10086_read_byte(state, 0x0e);
556 *fe_status = 0; 561 *fe_status = 0;
@@ -566,7 +571,7 @@ static int tda10086_read_status(struct dvb_frontend* fe, fe_status_t *fe_status)
566 *fe_status |= FE_HAS_LOCK; 571 *fe_status |= FE_HAS_LOCK;
567 if (!state->has_lock) { 572 if (!state->has_lock) {
568 state->has_lock = true; 573 state->has_lock = true;
569 // modify parameters for stable reception 574 /* modify parameters for stable reception */
570 tda10086_write_byte(state, 0x02, 0x00); 575 tda10086_write_byte(state, 0x02, 0x00);
571 } 576 }
572 } 577 }
@@ -579,7 +584,7 @@ static int tda10086_read_signal_strength(struct dvb_frontend* fe, u16 * signal)
579 struct tda10086_state* state = fe->demodulator_priv; 584 struct tda10086_state* state = fe->demodulator_priv;
580 u8 _str; 585 u8 _str;
581 586
582 dprintk ("%s\n", __FUNCTION__); 587 dprintk ("%s\n", __func__);
583 588
584 _str = 0xff - tda10086_read_byte(state, 0x43); 589 _str = 0xff - tda10086_read_byte(state, 0x43);
585 *signal = (_str << 8) | _str; 590 *signal = (_str << 8) | _str;
@@ -592,7 +597,7 @@ static int tda10086_read_snr(struct dvb_frontend* fe, u16 * snr)
592 struct tda10086_state* state = fe->demodulator_priv; 597 struct tda10086_state* state = fe->demodulator_priv;
593 u8 _snr; 598 u8 _snr;
594 599
595 dprintk ("%s\n", __FUNCTION__); 600 dprintk ("%s\n", __func__);
596 601
597 _snr = 0xff - tda10086_read_byte(state, 0x1c); 602 _snr = 0xff - tda10086_read_byte(state, 0x1c);
598 *snr = (_snr << 8) | _snr; 603 *snr = (_snr << 8) | _snr;
@@ -604,12 +609,12 @@ static int tda10086_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
604{ 609{
605 struct tda10086_state* state = fe->demodulator_priv; 610 struct tda10086_state* state = fe->demodulator_priv;
606 611
607 dprintk ("%s\n", __FUNCTION__); 612 dprintk ("%s\n", __func__);
608 613
609 // read it 614 /* read it */
610 *ucblocks = tda10086_read_byte(state, 0x18) & 0x7f; 615 *ucblocks = tda10086_read_byte(state, 0x18) & 0x7f;
611 616
612 // reset counter 617 /* reset counter */
613 tda10086_write_byte(state, 0x18, 0x00); 618 tda10086_write_byte(state, 0x18, 0x00);
614 tda10086_write_byte(state, 0x18, 0x80); 619 tda10086_write_byte(state, 0x18, 0x80);
615 620
@@ -620,9 +625,9 @@ static int tda10086_read_ber(struct dvb_frontend* fe, u32* ber)
620{ 625{
621 struct tda10086_state* state = fe->demodulator_priv; 626 struct tda10086_state* state = fe->demodulator_priv;
622 627
623 dprintk ("%s\n", __FUNCTION__); 628 dprintk ("%s\n", __func__);
624 629
625 // read it 630 /* read it */
626 *ber = 0; 631 *ber = 0;
627 *ber |= tda10086_read_byte(state, 0x15); 632 *ber |= tda10086_read_byte(state, 0x15);
628 *ber |= tda10086_read_byte(state, 0x16) << 8; 633 *ber |= tda10086_read_byte(state, 0x16) << 8;
@@ -635,7 +640,7 @@ static int tda10086_sleep(struct dvb_frontend* fe)
635{ 640{
636 struct tda10086_state* state = fe->demodulator_priv; 641 struct tda10086_state* state = fe->demodulator_priv;
637 642
638 dprintk ("%s\n", __FUNCTION__); 643 dprintk ("%s\n", __func__);
639 644
640 tda10086_write_mask(state, 0x00, 0x08, 0x08); 645 tda10086_write_mask(state, 0x00, 0x08, 0x08);
641 646
@@ -646,7 +651,7 @@ static int tda10086_i2c_gate_ctrl(struct dvb_frontend* fe, int enable)
646{ 651{
647 struct tda10086_state* state = fe->demodulator_priv; 652 struct tda10086_state* state = fe->demodulator_priv;
648 653
649 dprintk ("%s\n", __FUNCTION__); 654 dprintk ("%s\n", __func__);
650 655
651 if (enable) { 656 if (enable) {
652 tda10086_write_mask(state, 0x00, 0x10, 0x10); 657 tda10086_write_mask(state, 0x00, 0x10, 0x10);
@@ -737,7 +742,7 @@ struct dvb_frontend* tda10086_attach(const struct tda10086_config* config,
737{ 742{
738 struct tda10086_state *state; 743 struct tda10086_state *state;
739 744
740 dprintk ("%s\n", __FUNCTION__); 745 dprintk ("%s\n", __func__);
741 746
742 /* allocate memory for the internal state */ 747 /* allocate memory for the internal state */
743 state = kmalloc(sizeof(struct tda10086_state), GFP_KERNEL); 748 state = kmalloc(sizeof(struct tda10086_state), GFP_KERNEL);
diff --git a/drivers/media/dvb/frontends/tda10086.h b/drivers/media/dvb/frontends/tda10086.h
index eeceaeee78ff..61148c558d8d 100644
--- a/drivers/media/dvb/frontends/tda10086.h
+++ b/drivers/media/dvb/frontends/tda10086.h
@@ -26,6 +26,11 @@
26#include <linux/dvb/frontend.h> 26#include <linux/dvb/frontend.h>
27#include <linux/firmware.h> 27#include <linux/firmware.h>
28 28
29enum tda10086_xtal {
30 TDA10086_XTAL_16M,
31 TDA10086_XTAL_4M
32};
33
29struct tda10086_config 34struct tda10086_config
30{ 35{
31 /* the demodulator's i2c address */ 36 /* the demodulator's i2c address */
@@ -36,6 +41,9 @@ struct tda10086_config
36 41
37 /* do we need the diseqc signal with carrier? */ 42 /* do we need the diseqc signal with carrier? */
38 u8 diseqc_tone; 43 u8 diseqc_tone;
44
45 /* frequency of the reference xtal */
46 enum tda10086_xtal xtal_freq;
39}; 47};
40 48
41#if defined(CONFIG_DVB_TDA10086) || (defined(CONFIG_DVB_TDA10086_MODULE) && defined(MODULE)) 49#if defined(CONFIG_DVB_TDA10086) || (defined(CONFIG_DVB_TDA10086_MODULE) && defined(MODULE))
@@ -45,9 +53,9 @@ extern struct dvb_frontend* tda10086_attach(const struct tda10086_config* config
45static inline struct dvb_frontend* tda10086_attach(const struct tda10086_config* config, 53static inline struct dvb_frontend* tda10086_attach(const struct tda10086_config* config,
46 struct i2c_adapter* i2c) 54 struct i2c_adapter* i2c)
47{ 55{
48 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 56 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
49 return NULL; 57 return NULL;
50} 58}
51#endif // CONFIG_DVB_TDA10086 59#endif /* CONFIG_DVB_TDA10086 */
52 60
53#endif // TDA10086_H 61#endif /* TDA10086_H */
diff --git a/drivers/media/dvb/frontends/tda18271-common.c b/drivers/media/dvb/frontends/tda18271-common.c
index bca570990613..e27a7620a32f 100644
--- a/drivers/media/dvb/frontends/tda18271-common.c
+++ b/drivers/media/dvb/frontends/tda18271-common.c
@@ -125,16 +125,16 @@ int tda18271_read_regs(struct dvb_frontend *fe)
125 unsigned char buf = 0x00; 125 unsigned char buf = 0x00;
126 int ret; 126 int ret;
127 struct i2c_msg msg[] = { 127 struct i2c_msg msg[] = {
128 { .addr = priv->i2c_addr, .flags = 0, 128 { .addr = priv->i2c_props.addr, .flags = 0,
129 .buf = &buf, .len = 1 }, 129 .buf = &buf, .len = 1 },
130 { .addr = priv->i2c_addr, .flags = I2C_M_RD, 130 { .addr = priv->i2c_props.addr, .flags = I2C_M_RD,
131 .buf = regs, .len = 16 } 131 .buf = regs, .len = 16 }
132 }; 132 };
133 133
134 tda18271_i2c_gate_ctrl(fe, 1); 134 tda18271_i2c_gate_ctrl(fe, 1);
135 135
136 /* read all registers */ 136 /* read all registers */
137 ret = i2c_transfer(priv->i2c_adap, msg, 2); 137 ret = i2c_transfer(priv->i2c_props.adap, msg, 2);
138 138
139 tda18271_i2c_gate_ctrl(fe, 0); 139 tda18271_i2c_gate_ctrl(fe, 0);
140 140
@@ -155,16 +155,16 @@ int tda18271_read_extended(struct dvb_frontend *fe)
155 unsigned char buf = 0x00; 155 unsigned char buf = 0x00;
156 int ret, i; 156 int ret, i;
157 struct i2c_msg msg[] = { 157 struct i2c_msg msg[] = {
158 { .addr = priv->i2c_addr, .flags = 0, 158 { .addr = priv->i2c_props.addr, .flags = 0,
159 .buf = &buf, .len = 1 }, 159 .buf = &buf, .len = 1 },
160 { .addr = priv->i2c_addr, .flags = I2C_M_RD, 160 { .addr = priv->i2c_props.addr, .flags = I2C_M_RD,
161 .buf = regdump, .len = TDA18271_NUM_REGS } 161 .buf = regdump, .len = TDA18271_NUM_REGS }
162 }; 162 };
163 163
164 tda18271_i2c_gate_ctrl(fe, 1); 164 tda18271_i2c_gate_ctrl(fe, 1);
165 165
166 /* read all registers */ 166 /* read all registers */
167 ret = i2c_transfer(priv->i2c_adap, msg, 2); 167 ret = i2c_transfer(priv->i2c_props.adap, msg, 2);
168 168
169 tda18271_i2c_gate_ctrl(fe, 0); 169 tda18271_i2c_gate_ctrl(fe, 0);
170 170
@@ -192,7 +192,7 @@ int tda18271_write_regs(struct dvb_frontend *fe, int idx, int len)
192 struct tda18271_priv *priv = fe->tuner_priv; 192 struct tda18271_priv *priv = fe->tuner_priv;
193 unsigned char *regs = priv->tda18271_regs; 193 unsigned char *regs = priv->tda18271_regs;
194 unsigned char buf[TDA18271_NUM_REGS + 1]; 194 unsigned char buf[TDA18271_NUM_REGS + 1];
195 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0, 195 struct i2c_msg msg = { .addr = priv->i2c_props.addr, .flags = 0,
196 .buf = buf, .len = len + 1 }; 196 .buf = buf, .len = len + 1 };
197 int i, ret; 197 int i, ret;
198 198
@@ -205,7 +205,7 @@ int tda18271_write_regs(struct dvb_frontend *fe, int idx, int len)
205 tda18271_i2c_gate_ctrl(fe, 1); 205 tda18271_i2c_gate_ctrl(fe, 1);
206 206
207 /* write registers */ 207 /* write registers */
208 ret = i2c_transfer(priv->i2c_adap, &msg, 1); 208 ret = i2c_transfer(priv->i2c_props.adap, &msg, 1);
209 209
210 tda18271_i2c_gate_ctrl(fe, 0); 210 tda18271_i2c_gate_ctrl(fe, 0);
211 211
@@ -217,13 +217,29 @@ int tda18271_write_regs(struct dvb_frontend *fe, int idx, int len)
217 217
218/*---------------------------------------------------------------------*/ 218/*---------------------------------------------------------------------*/
219 219
220int tda18271_charge_pump_source(struct dvb_frontend *fe,
221 enum tda18271_pll pll, int force)
222{
223 struct tda18271_priv *priv = fe->tuner_priv;
224 unsigned char *regs = priv->tda18271_regs;
225
226 int r_cp = (pll == TDA18271_CAL_PLL) ? R_EB7 : R_EB4;
227
228 regs[r_cp] &= ~0x20;
229 regs[r_cp] |= ((force & 1) << 5);
230 tda18271_write_regs(fe, r_cp, 1);
231
232 return 0;
233}
234
220int tda18271_init_regs(struct dvb_frontend *fe) 235int tda18271_init_regs(struct dvb_frontend *fe)
221{ 236{
222 struct tda18271_priv *priv = fe->tuner_priv; 237 struct tda18271_priv *priv = fe->tuner_priv;
223 unsigned char *regs = priv->tda18271_regs; 238 unsigned char *regs = priv->tda18271_regs;
224 239
225 tda_dbg("initializing registers for device @ %d-%04x\n", 240 tda_dbg("initializing registers for device @ %d-%04x\n",
226 i2c_adapter_id(priv->i2c_adap), priv->i2c_addr); 241 i2c_adapter_id(priv->i2c_props.adap),
242 priv->i2c_props.addr);
227 243
228 /* initialize registers */ 244 /* initialize registers */
229 switch (priv->id) { 245 switch (priv->id) {
@@ -310,7 +326,12 @@ int tda18271_init_regs(struct dvb_frontend *fe)
310 regs[R_EB22] = 0x48; 326 regs[R_EB22] = 0x48;
311 regs[R_EB23] = 0xb0; 327 regs[R_EB23] = 0xb0;
312 328
313 tda18271_write_regs(fe, 0x00, TDA18271_NUM_REGS); 329 if (priv->small_i2c) {
330 tda18271_write_regs(fe, 0x00, 0x10);
331 tda18271_write_regs(fe, 0x10, 0x10);
332 tda18271_write_regs(fe, 0x20, 0x07);
333 } else
334 tda18271_write_regs(fe, 0x00, TDA18271_NUM_REGS);
314 335
315 /* setup agc1 gain */ 336 /* setup agc1 gain */
316 regs[R_EB17] = 0x00; 337 regs[R_EB17] = 0x00;
@@ -349,24 +370,15 @@ int tda18271_init_regs(struct dvb_frontend *fe)
349 regs[R_MD2] = 0x08; 370 regs[R_MD2] = 0x08;
350 regs[R_MD3] = 0x00; 371 regs[R_MD3] = 0x00;
351 372
352 switch (priv->id) { 373 tda18271_write_regs(fe, R_EP3, 11);
353 case TDA18271HDC1:
354 tda18271_write_regs(fe, R_EP3, 11);
355 break;
356 case TDA18271HDC2:
357 tda18271_write_regs(fe, R_EP3, 12);
358 break;
359 };
360 374
361 if ((priv->id) == TDA18271HDC2) { 375 if ((priv->id) == TDA18271HDC2) {
362 /* main pll cp source on */ 376 /* main pll cp source on */
363 regs[R_EB4] = 0x61; 377 tda18271_charge_pump_source(fe, TDA18271_MAIN_PLL, 1);
364 tda18271_write_regs(fe, R_EB4, 1);
365 msleep(1); 378 msleep(1);
366 379
367 /* main pll cp source off */ 380 /* main pll cp source off */
368 regs[R_EB4] = 0x41; 381 tda18271_charge_pump_source(fe, TDA18271_MAIN_PLL, 0);
369 tda18271_write_regs(fe, R_EB4, 1);
370 } 382 }
371 383
372 msleep(5); /* pll locking */ 384 msleep(5); /* pll locking */
@@ -398,6 +410,7 @@ int tda18271_init_regs(struct dvb_frontend *fe)
398 tda18271_write_regs(fe, R_EP3, 11); 410 tda18271_write_regs(fe, R_EP3, 11);
399 msleep(5); /* pll locking */ 411 msleep(5); /* pll locking */
400 412
413 /* launch detector */
401 tda18271_write_regs(fe, R_EP1, 1); 414 tda18271_write_regs(fe, R_EP1, 1);
402 msleep(5); /* wanted mid measurement */ 415 msleep(5); /* wanted mid measurement */
403 416
diff --git a/drivers/media/dvb/frontends/tda18271-fe.c b/drivers/media/dvb/frontends/tda18271-fe.c
index dfe72aaec380..b262100ae897 100644
--- a/drivers/media/dvb/frontends/tda18271-fe.c
+++ b/drivers/media/dvb/frontends/tda18271-fe.c
@@ -31,30 +31,23 @@ static int tda18271_cal_on_startup;
31module_param_named(cal, tda18271_cal_on_startup, int, 0644); 31module_param_named(cal, tda18271_cal_on_startup, int, 0644);
32MODULE_PARM_DESC(cal, "perform RF tracking filter calibration on startup"); 32MODULE_PARM_DESC(cal, "perform RF tracking filter calibration on startup");
33 33
34static LIST_HEAD(tda18271_list);
35static DEFINE_MUTEX(tda18271_list_mutex); 34static DEFINE_MUTEX(tda18271_list_mutex);
35static LIST_HEAD(hybrid_tuner_instance_list);
36 36
37/*---------------------------------------------------------------------*/ 37/*---------------------------------------------------------------------*/
38 38
39static int tda18271_ir_cal_init(struct dvb_frontend *fe) 39static inline int charge_pump_source(struct dvb_frontend *fe, int force)
40{ 40{
41 struct tda18271_priv *priv = fe->tuner_priv; 41 struct tda18271_priv *priv = fe->tuner_priv;
42 unsigned char *regs = priv->tda18271_regs; 42 return tda18271_charge_pump_source(fe,
43 43 (priv->role == TDA18271_SLAVE) ?
44 tda18271_read_regs(fe); 44 TDA18271_CAL_PLL :
45 45 TDA18271_MAIN_PLL, force);
46 /* test IR_CAL_OK to see if we need init */
47 if ((regs[R_EP1] & 0x08) == 0)
48 tda18271_init_regs(fe);
49
50 return 0;
51} 46}
52 47
53/* ------------------------------------------------------------------ */
54
55static int tda18271_channel_configuration(struct dvb_frontend *fe, 48static int tda18271_channel_configuration(struct dvb_frontend *fe,
56 u32 ifc, u32 freq, u32 bw, u8 std, 49 struct tda18271_std_map_item *map,
57 int radio) 50 u32 freq, u32 bw)
58{ 51{
59 struct tda18271_priv *priv = fe->tuner_priv; 52 struct tda18271_priv *priv = fe->tuner_priv;
60 unsigned char *regs = priv->tda18271_regs; 53 unsigned char *regs = priv->tda18271_regs;
@@ -64,38 +57,34 @@ static int tda18271_channel_configuration(struct dvb_frontend *fe,
64 57
65 /* set standard */ 58 /* set standard */
66 regs[R_EP3] &= ~0x1f; /* clear std bits */ 59 regs[R_EP3] &= ~0x1f; /* clear std bits */
67 regs[R_EP3] |= std; 60 regs[R_EP3] |= (map->agc_mode << 3) | map->std;
61
62 /* set rfagc to high speed mode */
63 regs[R_EP3] &= ~0x04;
68 64
69 /* set cal mode to normal */ 65 /* set cal mode to normal */
70 regs[R_EP4] &= ~0x03; 66 regs[R_EP4] &= ~0x03;
71 67
72 /* update IF output level & IF notch frequency */ 68 /* update IF output level & IF notch frequency */
73 regs[R_EP4] &= ~0x1c; /* clear if level bits */ 69 regs[R_EP4] &= ~0x1c; /* clear if level bits */
70 regs[R_EP4] |= (map->if_lvl << 2);
74 71
75 switch (priv->mode) { 72 switch (priv->mode) {
76 case TDA18271_ANALOG: 73 case TDA18271_ANALOG:
77 regs[R_MPD] &= ~0x80; /* IF notch = 0 */ 74 regs[R_MPD] &= ~0x80; /* IF notch = 0 */
78 break; 75 break;
79 case TDA18271_DIGITAL: 76 case TDA18271_DIGITAL:
80 regs[R_EP4] |= 0x04; /* IF level = 1 */
81 regs[R_MPD] |= 0x80; /* IF notch = 1 */ 77 regs[R_MPD] |= 0x80; /* IF notch = 1 */
82 break; 78 break;
83 } 79 }
84 80
85 if (radio) 81 /* update FM_RFn */
86 regs[R_EP4] |= 0x80; 82 regs[R_EP4] &= ~0x80;
87 else 83 regs[R_EP4] |= map->fm_rfn << 7;
88 regs[R_EP4] &= ~0x80;
89 84
90 /* update RF_TOP / IF_TOP */ 85 /* update rf top / if top */
91 switch (priv->mode) { 86 regs[R_EB22] = 0x00;
92 case TDA18271_ANALOG: 87 regs[R_EB22] |= map->rfagc_top;
93 regs[R_EB22] = 0x2c;
94 break;
95 case TDA18271_DIGITAL:
96 regs[R_EB22] = 0x37;
97 break;
98 }
99 tda18271_write_regs(fe, R_EB22, 1); 88 tda18271_write_regs(fe, R_EB22, 1);
100 89
101 /* --------------------------------------------------------------- */ 90 /* --------------------------------------------------------------- */
@@ -117,8 +106,14 @@ static int tda18271_channel_configuration(struct dvb_frontend *fe,
117 106
118 /* dual tuner and agc1 extra configuration */ 107 /* dual tuner and agc1 extra configuration */
119 108
120 /* main vco when Master, cal vco when slave */ 109 switch (priv->role) {
121 regs[R_EB1] |= 0x04; /* FIXME: assumes master */ 110 case TDA18271_MASTER:
111 regs[R_EB1] |= 0x04; /* main vco */
112 break;
113 case TDA18271_SLAVE:
114 regs[R_EB1] &= ~0x04; /* cal vco */
115 break;
116 }
122 117
123 /* agc1 always active */ 118 /* agc1 always active */
124 regs[R_EB1] &= ~0x02; 119 regs[R_EB1] &= ~0x02;
@@ -130,25 +125,40 @@ static int tda18271_channel_configuration(struct dvb_frontend *fe,
130 125
131 /* --------------------------------------------------------------- */ 126 /* --------------------------------------------------------------- */
132 127
133 N = freq + ifc; 128 N = map->if_freq * 1000 + freq;
134 129
135 /* FIXME: assumes master */ 130 switch (priv->role) {
136 tda18271_calc_main_pll(fe, N); 131 case TDA18271_MASTER:
137 tda18271_write_regs(fe, R_MPD, 4); 132 tda18271_calc_main_pll(fe, N);
133 tda18271_write_regs(fe, R_MPD, 4);
134 break;
135 case TDA18271_SLAVE:
136 tda18271_calc_cal_pll(fe, N);
137 tda18271_write_regs(fe, R_CPD, 4);
138
139 regs[R_MPD] = regs[R_CPD] & 0x7f;
140 tda18271_write_regs(fe, R_MPD, 1);
141 break;
142 }
138 143
139 tda18271_write_regs(fe, R_TM, 7); 144 tda18271_write_regs(fe, R_TM, 7);
140 145
141 /* main pll charge pump source */ 146 /* force charge pump source */
142 regs[R_EB4] |= 0x20; 147 charge_pump_source(fe, 1);
143 tda18271_write_regs(fe, R_EB4, 1);
144 148
145 msleep(1); 149 msleep(1);
146 150
147 /* normal operation for the main pll */ 151 /* return pll to normal operation */
148 regs[R_EB4] &= ~0x20; 152 charge_pump_source(fe, 0);
149 tda18271_write_regs(fe, R_EB4, 1);
150 153
151 msleep(5); 154 msleep(20);
155
156 /* set rfagc to normal speed mode */
157 if (map->fm_rfn)
158 regs[R_EP3] &= ~0x04;
159 else
160 regs[R_EP3] |= 0x04;
161 tda18271_write_regs(fe, R_EP3, 1);
152 162
153 return 0; 163 return 0;
154} 164}
@@ -195,8 +205,10 @@ static int tda18271_read_thermometer(struct dvb_frontend *fe)
195 return tm; 205 return tm;
196} 206}
197 207
198static int tda18271_rf_tracking_filters_correction(struct dvb_frontend *fe, 208/* ------------------------------------------------------------------ */
199 u32 freq) 209
210static int tda18271c2_rf_tracking_filters_correction(struct dvb_frontend *fe,
211 u32 freq)
200{ 212{
201 struct tda18271_priv *priv = fe->tuner_priv; 213 struct tda18271_priv *priv = fe->tuner_priv;
202 struct tda18271_rf_tracking_filter_cal *map = priv->rf_cal_state; 214 struct tda18271_rf_tracking_filter_cal *map = priv->rf_cal_state;
@@ -296,12 +308,10 @@ static int tda18271_calibrate_rf(struct dvb_frontend *fe, u32 freq)
296 tda18271_write_regs(fe, R_EB13, 1); 308 tda18271_write_regs(fe, R_EB13, 1);
297 309
298 /* main pll charge pump source */ 310 /* main pll charge pump source */
299 regs[R_EB4] |= 0x20; 311 tda18271_charge_pump_source(fe, TDA18271_MAIN_PLL, 1);
300 tda18271_write_regs(fe, R_EB4, 1);
301 312
302 /* cal pll charge pump source */ 313 /* cal pll charge pump source */
303 regs[R_EB7] |= 0x20; 314 tda18271_charge_pump_source(fe, TDA18271_CAL_PLL, 1);
304 tda18271_write_regs(fe, R_EB7, 1);
305 315
306 /* force dcdc converter to 0 V */ 316 /* force dcdc converter to 0 V */
307 regs[R_EB14] = 0x00; 317 regs[R_EB14] = 0x00;
@@ -320,8 +330,8 @@ static int tda18271_calibrate_rf(struct dvb_frontend *fe, u32 freq)
320 /* set the internal calibration signal */ 330 /* set the internal calibration signal */
321 N = freq; 331 N = freq;
322 332
323 tda18271_calc_main_pll(fe, N); 333 tda18271_calc_cal_pll(fe, N);
324 tda18271_write_regs(fe, R_MPD, 4); 334 tda18271_write_regs(fe, R_CPD, 4);
325 335
326 /* downconvert internal calibration */ 336 /* downconvert internal calibration */
327 N += 1000000; 337 N += 1000000;
@@ -339,14 +349,12 @@ static int tda18271_calibrate_rf(struct dvb_frontend *fe, u32 freq)
339 /* --------------------------------------------------------------- */ 349 /* --------------------------------------------------------------- */
340 350
341 /* normal operation for the main pll */ 351 /* normal operation for the main pll */
342 regs[R_EB4] &= ~0x20; 352 tda18271_charge_pump_source(fe, TDA18271_MAIN_PLL, 0);
343 tda18271_write_regs(fe, R_EB4, 1);
344 353
345 /* normal operation for the cal pll */ 354 /* normal operation for the cal pll */
346 regs[R_EB7] &= ~0x20; 355 tda18271_charge_pump_source(fe, TDA18271_CAL_PLL, 0);
347 tda18271_write_regs(fe, R_EB7, 1);
348 356
349 msleep(5); /* plls locking */ 357 msleep(10); /* plls locking */
350 358
351 /* launch the rf tracking filters calibration */ 359 /* launch the rf tracking filters calibration */
352 regs[R_EB20] |= 0x20; 360 regs[R_EB20] |= 0x20;
@@ -443,7 +451,7 @@ static int tda18271_powerscan(struct dvb_frontend *fe,
443 451
444 count += 200; 452 count += 200;
445 453
446 if (count < count_limit) 454 if (count <= count_limit)
447 continue; 455 continue;
448 456
449 if (sgn <= 0) 457 if (sgn <= 0)
@@ -587,7 +595,7 @@ static int tda18271_calc_rf_filter_curve(struct dvb_frontend *fe)
587 595
588/* ------------------------------------------------------------------ */ 596/* ------------------------------------------------------------------ */
589 597
590static int tda18271_rf_cal_init(struct dvb_frontend *fe) 598static int tda18271c2_rf_cal_init(struct dvb_frontend *fe)
591{ 599{
592 struct tda18271_priv *priv = fe->tuner_priv; 600 struct tda18271_priv *priv = fe->tuner_priv;
593 unsigned char *regs = priv->tda18271_regs; 601 unsigned char *regs = priv->tda18271_regs;
@@ -610,63 +618,13 @@ static int tda18271_rf_cal_init(struct dvb_frontend *fe)
610 return 0; 618 return 0;
611} 619}
612 620
613static int tda18271_init(struct dvb_frontend *fe) 621static int tda18271c1_rf_tracking_filter_calibration(struct dvb_frontend *fe,
614{ 622 u32 freq, u32 bw)
615 struct tda18271_priv *priv = fe->tuner_priv;
616
617 mutex_lock(&priv->lock);
618
619 /* power up */
620 tda18271_set_standby_mode(fe, 0, 0, 0);
621
622 /* initialization */
623 tda18271_ir_cal_init(fe);
624
625 if (priv->id == TDA18271HDC2)
626 tda18271_rf_cal_init(fe);
627
628 mutex_unlock(&priv->lock);
629
630 return 0;
631}
632
633static int tda18271c2_tune(struct dvb_frontend *fe,
634 u32 ifc, u32 freq, u32 bw, u8 std, int radio)
635{
636 struct tda18271_priv *priv = fe->tuner_priv;
637
638 tda_dbg("freq = %d, ifc = %d\n", freq, ifc);
639
640 tda18271_init(fe);
641
642 mutex_lock(&priv->lock);
643
644 tda18271_rf_tracking_filters_correction(fe, freq);
645
646 tda18271_channel_configuration(fe, ifc, freq, bw, std, radio);
647
648 mutex_unlock(&priv->lock);
649
650 return 0;
651}
652
653/* ------------------------------------------------------------------ */
654
655static int tda18271c1_tune(struct dvb_frontend *fe,
656 u32 ifc, u32 freq, u32 bw, u8 std, int radio)
657{ 623{
658 struct tda18271_priv *priv = fe->tuner_priv; 624 struct tda18271_priv *priv = fe->tuner_priv;
659 unsigned char *regs = priv->tda18271_regs; 625 unsigned char *regs = priv->tda18271_regs;
660 u32 N = 0; 626 u32 N = 0;
661 627
662 tda18271_init(fe);
663
664 mutex_lock(&priv->lock);
665
666 tda_dbg("freq = %d, ifc = %d\n", freq, ifc);
667
668 /* RF tracking filter calibration */
669
670 /* calculate bp filter */ 628 /* calculate bp filter */
671 tda18271_calc_bp_filter(fe, &freq); 629 tda18271_calc_bp_filter(fe, &freq);
672 tda18271_write_regs(fe, R_EP1, 1); 630 tda18271_write_regs(fe, R_EP1, 1);
@@ -737,7 +695,7 @@ static int tda18271c1_tune(struct dvb_frontend *fe,
737 695
738 regs[R_EB7] = 0x40; 696 regs[R_EB7] = 0x40;
739 tda18271_write_regs(fe, R_EB7, 1); 697 tda18271_write_regs(fe, R_EB7, 1);
740 msleep(10); 698 msleep(10); /* pll locking */
741 699
742 regs[R_EB20] = 0xec; 700 regs[R_EB20] = 0xec;
743 tda18271_write_regs(fe, R_EB20, 1); 701 tda18271_write_regs(fe, R_EB20, 1);
@@ -752,74 +710,70 @@ static int tda18271c1_tune(struct dvb_frontend *fe,
752 if (0 == tda18271_calc_rf_cal(fe, &freq)) 710 if (0 == tda18271_calc_rf_cal(fe, &freq))
753 tda18271_write_regs(fe, R_EB14, 1); 711 tda18271_write_regs(fe, R_EB14, 1);
754 712
755 /* Channel Configuration */ 713 return 0;
714}
756 715
757 switch (priv->mode) { 716/* ------------------------------------------------------------------ */
758 case TDA18271_ANALOG:
759 regs[R_EB22] = 0x2c;
760 break;
761 case TDA18271_DIGITAL:
762 regs[R_EB22] = 0x37;
763 break;
764 }
765 tda18271_write_regs(fe, R_EB22, 1);
766 717
767 regs[R_EP1] |= 0x40; /* set dis power level on */ 718static int tda18271_ir_cal_init(struct dvb_frontend *fe)
719{
720 struct tda18271_priv *priv = fe->tuner_priv;
721 unsigned char *regs = priv->tda18271_regs;
768 722
769 /* set standard */ 723 tda18271_read_regs(fe);
770 regs[R_EP3] &= ~0x1f; /* clear std bits */
771 724
772 /* see table 22 */ 725 /* test IR_CAL_OK to see if we need init */
773 regs[R_EP3] |= std; 726 if ((regs[R_EP1] & 0x08) == 0)
727 tda18271_init_regs(fe);
774 728
775 regs[R_EP4] &= ~0x03; /* set cal mode to normal */ 729 return 0;
730}
776 731
777 regs[R_EP4] &= ~0x1c; /* clear if level bits */ 732static int tda18271_init(struct dvb_frontend *fe)
778 switch (priv->mode) { 733{
779 case TDA18271_ANALOG: 734 struct tda18271_priv *priv = fe->tuner_priv;
780 regs[R_MPD] &= ~0x80; /* IF notch = 0 */
781 break;
782 case TDA18271_DIGITAL:
783 regs[R_EP4] |= 0x04;
784 regs[R_MPD] |= 0x80;
785 break;
786 }
787 735
788 if (radio) 736 mutex_lock(&priv->lock);
789 regs[R_EP4] |= 0x80;
790 else
791 regs[R_EP4] &= ~0x80;
792 737
793 /* image rejection validity */ 738 /* power up */
794 tda18271_calc_ir_measure(fe, &freq); 739 tda18271_set_standby_mode(fe, 0, 0, 0);
795 740
796 /* calculate MAIN PLL */ 741 /* initialization */
797 N = freq + ifc; 742 tda18271_ir_cal_init(fe);
798 743
799 tda18271_calc_main_pll(fe, N); 744 if (priv->id == TDA18271HDC2)
745 tda18271c2_rf_cal_init(fe);
800 746
801 tda18271_write_regs(fe, R_TM, 15);
802 msleep(5);
803 mutex_unlock(&priv->lock); 747 mutex_unlock(&priv->lock);
804 748
805 return 0; 749 return 0;
806} 750}
807 751
808static inline int tda18271_tune(struct dvb_frontend *fe, 752static int tda18271_tune(struct dvb_frontend *fe,
809 u32 ifc, u32 freq, u32 bw, u8 std, int radio) 753 struct tda18271_std_map_item *map, u32 freq, u32 bw)
810{ 754{
811 struct tda18271_priv *priv = fe->tuner_priv; 755 struct tda18271_priv *priv = fe->tuner_priv;
812 int ret = -EINVAL; 756
757 tda_dbg("freq = %d, ifc = %d, bw = %d, agc_mode = %d, std = %d\n",
758 freq, map->if_freq, bw, map->agc_mode, map->std);
759
760 tda18271_init(fe);
761
762 mutex_lock(&priv->lock);
813 763
814 switch (priv->id) { 764 switch (priv->id) {
815 case TDA18271HDC1: 765 case TDA18271HDC1:
816 ret = tda18271c1_tune(fe, ifc, freq, bw, std, radio); 766 tda18271c1_rf_tracking_filter_calibration(fe, freq, bw);
817 break; 767 break;
818 case TDA18271HDC2: 768 case TDA18271HDC2:
819 ret = tda18271c2_tune(fe, ifc, freq, bw, std, radio); 769 tda18271c2_rf_tracking_filters_correction(fe, freq);
820 break; 770 break;
821 } 771 }
822 return ret; 772 tda18271_channel_configuration(fe, map, freq, bw);
773
774 mutex_unlock(&priv->lock);
775
776 return 0;
823} 777}
824 778
825/* ------------------------------------------------------------------ */ 779/* ------------------------------------------------------------------ */
@@ -829,9 +783,8 @@ static int tda18271_set_params(struct dvb_frontend *fe,
829{ 783{
830 struct tda18271_priv *priv = fe->tuner_priv; 784 struct tda18271_priv *priv = fe->tuner_priv;
831 struct tda18271_std_map *std_map = &priv->std; 785 struct tda18271_std_map *std_map = &priv->std;
786 struct tda18271_std_map_item *map;
832 int ret; 787 int ret;
833 u8 std;
834 u16 sgIF;
835 u32 bw, freq = params->frequency; 788 u32 bw, freq = params->frequency;
836 789
837 priv->mode = TDA18271_DIGITAL; 790 priv->mode = TDA18271_DIGITAL;
@@ -840,13 +793,11 @@ static int tda18271_set_params(struct dvb_frontend *fe,
840 switch (params->u.vsb.modulation) { 793 switch (params->u.vsb.modulation) {
841 case VSB_8: 794 case VSB_8:
842 case VSB_16: 795 case VSB_16:
843 std = std_map->atsc_6.std_bits; 796 map = &std_map->atsc_6;
844 sgIF = std_map->atsc_6.if_freq;
845 break; 797 break;
846 case QAM_64: 798 case QAM_64:
847 case QAM_256: 799 case QAM_256:
848 std = std_map->qam_6.std_bits; 800 map = &std_map->qam_6;
849 sgIF = std_map->qam_6.if_freq;
850 break; 801 break;
851 default: 802 default:
852 tda_warn("modulation not set!\n"); 803 tda_warn("modulation not set!\n");
@@ -861,18 +812,15 @@ static int tda18271_set_params(struct dvb_frontend *fe,
861 switch (params->u.ofdm.bandwidth) { 812 switch (params->u.ofdm.bandwidth) {
862 case BANDWIDTH_6_MHZ: 813 case BANDWIDTH_6_MHZ:
863 bw = 6000000; 814 bw = 6000000;
864 std = std_map->dvbt_6.std_bits; 815 map = &std_map->dvbt_6;
865 sgIF = std_map->dvbt_6.if_freq;
866 break; 816 break;
867 case BANDWIDTH_7_MHZ: 817 case BANDWIDTH_7_MHZ:
868 bw = 7000000; 818 bw = 7000000;
869 std = std_map->dvbt_7.std_bits; 819 map = &std_map->dvbt_7;
870 sgIF = std_map->dvbt_7.if_freq;
871 break; 820 break;
872 case BANDWIDTH_8_MHZ: 821 case BANDWIDTH_8_MHZ:
873 bw = 8000000; 822 bw = 8000000;
874 std = std_map->dvbt_8.std_bits; 823 map = &std_map->dvbt_8;
875 sgIF = std_map->dvbt_8.if_freq;
876 break; 824 break;
877 default: 825 default:
878 tda_warn("bandwidth not set!\n"); 826 tda_warn("bandwidth not set!\n");
@@ -887,7 +835,7 @@ static int tda18271_set_params(struct dvb_frontend *fe,
887 if (fe->ops.analog_ops.standby) 835 if (fe->ops.analog_ops.standby)
888 fe->ops.analog_ops.standby(fe); 836 fe->ops.analog_ops.standby(fe);
889 837
890 ret = tda18271_tune(fe, sgIF * 1000, freq, bw, std, 0); 838 ret = tda18271_tune(fe, map, freq, bw);
891 839
892 if (ret < 0) 840 if (ret < 0)
893 goto fail; 841 goto fail;
@@ -904,57 +852,46 @@ static int tda18271_set_analog_params(struct dvb_frontend *fe,
904{ 852{
905 struct tda18271_priv *priv = fe->tuner_priv; 853 struct tda18271_priv *priv = fe->tuner_priv;
906 struct tda18271_std_map *std_map = &priv->std; 854 struct tda18271_std_map *std_map = &priv->std;
855 struct tda18271_std_map_item *map;
907 char *mode; 856 char *mode;
908 int ret, radio = 0; 857 int ret;
909 u8 std;
910 u16 sgIF;
911 u32 freq = params->frequency * 62500; 858 u32 freq = params->frequency * 62500;
912 859
913 priv->mode = TDA18271_ANALOG; 860 priv->mode = TDA18271_ANALOG;
914 861
915 if (params->mode == V4L2_TUNER_RADIO) { 862 if (params->mode == V4L2_TUNER_RADIO) {
916 radio = 1;
917 freq = freq / 1000; 863 freq = freq / 1000;
918 std = std_map->fm_radio.std_bits; 864 map = &std_map->fm_radio;
919 sgIF = std_map->fm_radio.if_freq;
920 mode = "fm"; 865 mode = "fm";
921 } else if (params->std & V4L2_STD_MN) { 866 } else if (params->std & V4L2_STD_MN) {
922 std = std_map->atv_mn.std_bits; 867 map = &std_map->atv_mn;
923 sgIF = std_map->atv_mn.if_freq;
924 mode = "MN"; 868 mode = "MN";
925 } else if (params->std & V4L2_STD_B) { 869 } else if (params->std & V4L2_STD_B) {
926 std = std_map->atv_b.std_bits; 870 map = &std_map->atv_b;
927 sgIF = std_map->atv_b.if_freq;
928 mode = "B"; 871 mode = "B";
929 } else if (params->std & V4L2_STD_GH) { 872 } else if (params->std & V4L2_STD_GH) {
930 std = std_map->atv_gh.std_bits; 873 map = &std_map->atv_gh;
931 sgIF = std_map->atv_gh.if_freq;
932 mode = "GH"; 874 mode = "GH";
933 } else if (params->std & V4L2_STD_PAL_I) { 875 } else if (params->std & V4L2_STD_PAL_I) {
934 std = std_map->atv_i.std_bits; 876 map = &std_map->atv_i;
935 sgIF = std_map->atv_i.if_freq;
936 mode = "I"; 877 mode = "I";
937 } else if (params->std & V4L2_STD_DK) { 878 } else if (params->std & V4L2_STD_DK) {
938 std = std_map->atv_dk.std_bits; 879 map = &std_map->atv_dk;
939 sgIF = std_map->atv_dk.if_freq;
940 mode = "DK"; 880 mode = "DK";
941 } else if (params->std & V4L2_STD_SECAM_L) { 881 } else if (params->std & V4L2_STD_SECAM_L) {
942 std = std_map->atv_l.std_bits; 882 map = &std_map->atv_l;
943 sgIF = std_map->atv_l.if_freq;
944 mode = "L"; 883 mode = "L";
945 } else if (params->std & V4L2_STD_SECAM_LC) { 884 } else if (params->std & V4L2_STD_SECAM_LC) {
946 std = std_map->atv_lc.std_bits; 885 map = &std_map->atv_lc;
947 sgIF = std_map->atv_lc.if_freq;
948 mode = "L'"; 886 mode = "L'";
949 } else { 887 } else {
950 std = std_map->atv_i.std_bits; 888 map = &std_map->atv_i;
951 sgIF = std_map->atv_i.if_freq;
952 mode = "xx"; 889 mode = "xx";
953 } 890 }
954 891
955 tda_dbg("setting tda18271 to system %s\n", mode); 892 tda_dbg("setting tda18271 to system %s\n", mode);
956 893
957 ret = tda18271_tune(fe, sgIF * 1000, freq, 0, std, radio); 894 ret = tda18271_tune(fe, map, freq, 0);
958 895
959 if (ret < 0) 896 if (ret < 0)
960 goto fail; 897 goto fail;
@@ -986,16 +923,9 @@ static int tda18271_release(struct dvb_frontend *fe)
986 923
987 mutex_lock(&tda18271_list_mutex); 924 mutex_lock(&tda18271_list_mutex);
988 925
989 priv->count--; 926 if (priv)
927 hybrid_tuner_release_state(priv);
990 928
991 if (!priv->count) {
992 tda_dbg("destroying instance @ %d-%04x\n",
993 i2c_adapter_id(priv->i2c_adap),
994 priv->i2c_addr);
995 list_del(&priv->tda18271_list);
996
997 kfree(priv);
998 }
999 mutex_unlock(&tda18271_list_mutex); 929 mutex_unlock(&tda18271_list_mutex);
1000 930
1001 fe->tuner_priv = NULL; 931 fe->tuner_priv = NULL;
@@ -1020,15 +950,20 @@ static int tda18271_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
1020/* ------------------------------------------------------------------ */ 950/* ------------------------------------------------------------------ */
1021 951
1022#define tda18271_update_std(std_cfg, name) do { \ 952#define tda18271_update_std(std_cfg, name) do { \
1023 if (map->std_cfg.if_freq + map->std_cfg.std_bits > 0) { \ 953 if (map->std_cfg.if_freq + \
954 map->std_cfg.agc_mode + map->std_cfg.std + \
955 map->std_cfg.if_lvl + map->std_cfg.rfagc_top > 0) { \
1024 tda_dbg("Using custom std config for %s\n", name); \ 956 tda_dbg("Using custom std config for %s\n", name); \
1025 memcpy(&std->std_cfg, &map->std_cfg, \ 957 memcpy(&std->std_cfg, &map->std_cfg, \
1026 sizeof(struct tda18271_std_map_item)); \ 958 sizeof(struct tda18271_std_map_item)); \
1027 } } while (0) 959 } } while (0)
1028 960
1029#define tda18271_dump_std_item(std_cfg, name) do { \ 961#define tda18271_dump_std_item(std_cfg, name) do { \
1030 tda_dbg("(%s) if freq = %d, std bits = 0x%02x\n", \ 962 tda_dbg("(%s) if_freq = %d, agc_mode = %d, std = %d, " \
1031 name, std->std_cfg.if_freq, std->std_cfg.std_bits); \ 963 "if_lvl = %d, rfagc_top = 0x%02x\n", \
964 name, std->std_cfg.if_freq, \
965 std->std_cfg.agc_mode, std->std_cfg.std, \
966 std->std_cfg.if_lvl, std->std_cfg.rfagc_top); \
1032 } while (0) 967 } while (0)
1033 968
1034static int tda18271_dump_std_map(struct dvb_frontend *fe) 969static int tda18271_dump_std_map(struct dvb_frontend *fe)
@@ -1037,20 +972,20 @@ static int tda18271_dump_std_map(struct dvb_frontend *fe)
1037 struct tda18271_std_map *std = &priv->std; 972 struct tda18271_std_map *std = &priv->std;
1038 973
1039 tda_dbg("========== STANDARD MAP SETTINGS ==========\n"); 974 tda_dbg("========== STANDARD MAP SETTINGS ==========\n");
1040 tda18271_dump_std_item(fm_radio, "fm"); 975 tda18271_dump_std_item(fm_radio, " fm ");
1041 tda18271_dump_std_item(atv_b, "pal b"); 976 tda18271_dump_std_item(atv_b, "atv b ");
1042 tda18271_dump_std_item(atv_dk, "pal dk"); 977 tda18271_dump_std_item(atv_dk, "atv dk");
1043 tda18271_dump_std_item(atv_gh, "pal gh"); 978 tda18271_dump_std_item(atv_gh, "atv gh");
1044 tda18271_dump_std_item(atv_i, "pal i"); 979 tda18271_dump_std_item(atv_i, "atv i ");
1045 tda18271_dump_std_item(atv_l, "pal l"); 980 tda18271_dump_std_item(atv_l, "atv l ");
1046 tda18271_dump_std_item(atv_lc, "pal l'"); 981 tda18271_dump_std_item(atv_lc, "atv l'");
1047 tda18271_dump_std_item(atv_mn, "atv mn"); 982 tda18271_dump_std_item(atv_mn, "atv mn");
1048 tda18271_dump_std_item(atsc_6, "atsc 6"); 983 tda18271_dump_std_item(atsc_6, "atsc 6");
1049 tda18271_dump_std_item(dvbt_6, "dvbt 6"); 984 tda18271_dump_std_item(dvbt_6, "dvbt 6");
1050 tda18271_dump_std_item(dvbt_7, "dvbt 7"); 985 tda18271_dump_std_item(dvbt_7, "dvbt 7");
1051 tda18271_dump_std_item(dvbt_8, "dvbt 8"); 986 tda18271_dump_std_item(dvbt_8, "dvbt 8");
1052 tda18271_dump_std_item(qam_6, "qam 6"); 987 tda18271_dump_std_item(qam_6, "qam 6 ");
1053 tda18271_dump_std_item(qam_8, "qam 8"); 988 tda18271_dump_std_item(qam_8, "qam 8 ");
1054 989
1055 return 0; 990 return 0;
1056} 991}
@@ -1109,7 +1044,8 @@ static int tda18271_get_id(struct dvb_frontend *fe)
1109 } 1044 }
1110 1045
1111 tda_info("%s detected @ %d-%04x%s\n", name, 1046 tda_info("%s detected @ %d-%04x%s\n", name,
1112 i2c_adapter_id(priv->i2c_adap), priv->i2c_addr, 1047 i2c_adapter_id(priv->i2c_props.adap),
1048 priv->i2c_props.addr,
1113 (0 == ret) ? "" : ", device not supported."); 1049 (0 == ret) ? "" : ", device not supported.");
1114 1050
1115 return ret; 1051 return ret;
@@ -1136,45 +1072,28 @@ struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr,
1136 struct tda18271_config *cfg) 1072 struct tda18271_config *cfg)
1137{ 1073{
1138 struct tda18271_priv *priv = NULL; 1074 struct tda18271_priv *priv = NULL;
1139 int state_found = 0; 1075 int instance;
1140 1076
1141 mutex_lock(&tda18271_list_mutex); 1077 mutex_lock(&tda18271_list_mutex);
1142 1078
1143 list_for_each_entry(priv, &tda18271_list, tda18271_list) { 1079 instance = hybrid_tuner_request_state(struct tda18271_priv, priv,
1144 if ((i2c_adapter_id(priv->i2c_adap) == i2c_adapter_id(i2c)) && 1080 hybrid_tuner_instance_list,
1145 (priv->i2c_addr == addr)) { 1081 i2c, addr, "tda18271");
1146 tda_dbg("attaching existing tuner @ %d-%04x\n", 1082 switch (instance) {
1147 i2c_adapter_id(priv->i2c_adap), 1083 case 0:
1148 priv->i2c_addr); 1084 goto fail;
1149 priv->count++; 1085 break;
1150 fe->tuner_priv = priv; 1086 case 1:
1151 state_found = 1; 1087 /* new tuner instance */
1152 /* allow dvb driver to override i2c gate setting */
1153 if ((cfg) && (cfg->gate != TDA18271_GATE_ANALOG))
1154 priv->gate = cfg->gate;
1155 break;
1156 }
1157 }
1158 if (state_found == 0) {
1159 tda_dbg("creating new tuner instance @ %d-%04x\n",
1160 i2c_adapter_id(i2c), addr);
1161
1162 priv = kzalloc(sizeof(struct tda18271_priv), GFP_KERNEL);
1163 if (priv == NULL) {
1164 mutex_unlock(&tda18271_list_mutex);
1165 return NULL;
1166 }
1167
1168 priv->i2c_addr = addr;
1169 priv->i2c_adap = i2c;
1170 priv->gate = (cfg) ? cfg->gate : TDA18271_GATE_AUTO; 1088 priv->gate = (cfg) ? cfg->gate : TDA18271_GATE_AUTO;
1089 priv->role = (cfg) ? cfg->role : TDA18271_MASTER;
1171 priv->cal_initialized = false; 1090 priv->cal_initialized = false;
1172 mutex_init(&priv->lock); 1091 mutex_init(&priv->lock);
1173 priv->count++;
1174 1092
1175 fe->tuner_priv = priv; 1093 fe->tuner_priv = priv;
1176 1094
1177 list_add_tail(&priv->tda18271_list, &tda18271_list); 1095 if (cfg)
1096 priv->small_i2c = cfg->small_i2c;
1178 1097
1179 if (tda18271_get_id(fe) < 0) 1098 if (tda18271_get_id(fe) < 0)
1180 goto fail; 1099 goto fail;
@@ -1186,9 +1105,18 @@ struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr,
1186 tda18271_init_regs(fe); 1105 tda18271_init_regs(fe);
1187 1106
1188 if ((tda18271_cal_on_startup) && (priv->id == TDA18271HDC2)) 1107 if ((tda18271_cal_on_startup) && (priv->id == TDA18271HDC2))
1189 tda18271_rf_cal_init(fe); 1108 tda18271c2_rf_cal_init(fe);
1190 1109
1191 mutex_unlock(&priv->lock); 1110 mutex_unlock(&priv->lock);
1111 break;
1112 default:
1113 /* existing tuner instance */
1114 fe->tuner_priv = priv;
1115
1116 /* allow dvb driver to override i2c gate setting */
1117 if ((cfg) && (cfg->gate != TDA18271_GATE_ANALOG))
1118 priv->gate = cfg->gate;
1119 break;
1192 } 1120 }
1193 1121
1194 /* override default std map with values in config struct */ 1122 /* override default std map with values in config struct */
@@ -1200,7 +1128,7 @@ struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr,
1200 memcpy(&fe->ops.tuner_ops, &tda18271_tuner_ops, 1128 memcpy(&fe->ops.tuner_ops, &tda18271_tuner_ops,
1201 sizeof(struct dvb_tuner_ops)); 1129 sizeof(struct dvb_tuner_ops));
1202 1130
1203 if (tda18271_debug & DBG_MAP) 1131 if (tda18271_debug & (DBG_MAP | DBG_ADV))
1204 tda18271_dump_std_map(fe); 1132 tda18271_dump_std_map(fe);
1205 1133
1206 return fe; 1134 return fe;
@@ -1214,7 +1142,7 @@ EXPORT_SYMBOL_GPL(tda18271_attach);
1214MODULE_DESCRIPTION("NXP TDA18271HD analog / digital tuner driver"); 1142MODULE_DESCRIPTION("NXP TDA18271HD analog / digital tuner driver");
1215MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>"); 1143MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
1216MODULE_LICENSE("GPL"); 1144MODULE_LICENSE("GPL");
1217MODULE_VERSION("0.2"); 1145MODULE_VERSION("0.3");
1218 1146
1219/* 1147/*
1220 * Overrides for Emacs so that we follow Linus's tabbing style. 1148 * Overrides for Emacs so that we follow Linus's tabbing style.
diff --git a/drivers/media/dvb/frontends/tda18271-priv.h b/drivers/media/dvb/frontends/tda18271-priv.h
index 7b939a5325fb..2bc5eb368ea2 100644
--- a/drivers/media/dvb/frontends/tda18271-priv.h
+++ b/drivers/media/dvb/frontends/tda18271-priv.h
@@ -24,6 +24,7 @@
24#include <linux/kernel.h> 24#include <linux/kernel.h>
25#include <linux/types.h> 25#include <linux/types.h>
26#include <linux/mutex.h> 26#include <linux/mutex.h>
27#include "tuner-i2c.h"
27#include "tda18271.h" 28#include "tda18271.h"
28 29
29#define R_ID 0x00 /* ID byte */ 30#define R_ID 0x00 /* ID byte */
@@ -85,6 +86,11 @@ struct tda18271_rf_tracking_filter_cal {
85 int rf_b2; 86 int rf_b2;
86}; 87};
87 88
89enum tda18271_pll {
90 TDA18271_MAIN_PLL,
91 TDA18271_CAL_PLL,
92};
93
88enum tda18271_mode { 94enum tda18271_mode {
89 TDA18271_ANALOG, 95 TDA18271_ANALOG,
90 TDA18271_DIGITAL, 96 TDA18271_DIGITAL,
@@ -98,19 +104,19 @@ enum tda18271_ver {
98}; 104};
99 105
100struct tda18271_priv { 106struct tda18271_priv {
101 u8 i2c_addr;
102 struct i2c_adapter *i2c_adap;
103 unsigned char tda18271_regs[TDA18271_NUM_REGS]; 107 unsigned char tda18271_regs[TDA18271_NUM_REGS];
104 108
105 struct list_head tda18271_list; 109 struct list_head hybrid_tuner_instance_list;
110 struct tuner_i2c_props i2c_props;
106 111
107 enum tda18271_mode mode; 112 enum tda18271_mode mode;
113 enum tda18271_role role;
108 enum tda18271_i2c_gate gate; 114 enum tda18271_i2c_gate gate;
109 enum tda18271_ver id; 115 enum tda18271_ver id;
110 116
111 unsigned int count;
112 unsigned int tm_rfcal; 117 unsigned int tm_rfcal;
113 unsigned int cal_initialized:1; 118 unsigned int cal_initialized:1;
119 unsigned int small_i2c:1;
114 120
115 struct tda18271_map_layout *maps; 121 struct tda18271_map_layout *maps;
116 struct tda18271_std_map std; 122 struct tda18271_std_map std;
@@ -133,7 +139,7 @@ extern int tda18271_debug;
133#define DBG_CAL 16 139#define DBG_CAL 16
134 140
135#define tda_printk(kern, fmt, arg...) \ 141#define tda_printk(kern, fmt, arg...) \
136 printk(kern "%s: " fmt, __FUNCTION__, ##arg) 142 printk(kern "%s: " fmt, __func__, ##arg)
137 143
138#define dprintk(kern, lvl, fmt, arg...) do {\ 144#define dprintk(kern, lvl, fmt, arg...) do {\
139 if (tda18271_debug & lvl) \ 145 if (tda18271_debug & lvl) \
@@ -188,6 +194,8 @@ extern int tda18271_read_extended(struct dvb_frontend *fe);
188extern int tda18271_write_regs(struct dvb_frontend *fe, int idx, int len); 194extern int tda18271_write_regs(struct dvb_frontend *fe, int idx, int len);
189extern int tda18271_init_regs(struct dvb_frontend *fe); 195extern int tda18271_init_regs(struct dvb_frontend *fe);
190 196
197extern int tda18271_charge_pump_source(struct dvb_frontend *fe,
198 enum tda18271_pll pll, int force);
191extern int tda18271_set_standby_mode(struct dvb_frontend *fe, 199extern int tda18271_set_standby_mode(struct dvb_frontend *fe,
192 int sm, int sm_lt, int sm_xt); 200 int sm, int sm_lt, int sm_xt);
193 201
diff --git a/drivers/media/dvb/frontends/tda18271-tables.c b/drivers/media/dvb/frontends/tda18271-tables.c
index e94afcfdc5bc..83e7561960c1 100644
--- a/drivers/media/dvb/frontends/tda18271-tables.c
+++ b/drivers/media/dvb/frontends/tda18271-tables.c
@@ -1187,37 +1187,65 @@ fail:
1187/*---------------------------------------------------------------------*/ 1187/*---------------------------------------------------------------------*/
1188 1188
1189static struct tda18271_std_map tda18271c1_std_map = { 1189static struct tda18271_std_map tda18271c1_std_map = {
1190 .fm_radio = { .if_freq = 1250, .std_bits = 0x18 }, 1190 .fm_radio = { .if_freq = 1250, .fm_rfn = 1, .agc_mode = 3, .std = 0,
1191 .atv_b = { .if_freq = 6750, .std_bits = 0x0e }, 1191 .if_lvl = 0, .rfagc_top = 0x2c, }, /* EP3[4:0] 0x18 */
1192 .atv_dk = { .if_freq = 7750, .std_bits = 0x0f }, 1192 .atv_b = { .if_freq = 6750, .fm_rfn = 0, .agc_mode = 1, .std = 6,
1193 .atv_gh = { .if_freq = 7750, .std_bits = 0x0f }, 1193 .if_lvl = 0, .rfagc_top = 0x2c, }, /* EP3[4:0] 0x0e */
1194 .atv_i = { .if_freq = 7750, .std_bits = 0x0f }, 1194 .atv_dk = { .if_freq = 7750, .fm_rfn = 0, .agc_mode = 1, .std = 7,
1195 .atv_l = { .if_freq = 7750, .std_bits = 0x0f }, 1195 .if_lvl = 0, .rfagc_top = 0x2c, }, /* EP3[4:0] 0x0f */
1196 .atv_lc = { .if_freq = 1250, .std_bits = 0x0f }, 1196 .atv_gh = { .if_freq = 7750, .fm_rfn = 0, .agc_mode = 1, .std = 7,
1197 .atv_mn = { .if_freq = 5750, .std_bits = 0x0d }, 1197 .if_lvl = 0, .rfagc_top = 0x2c, }, /* EP3[4:0] 0x0f */
1198 .atsc_6 = { .if_freq = 3250, .std_bits = 0x1c }, 1198 .atv_i = { .if_freq = 7750, .fm_rfn = 0, .agc_mode = 1, .std = 7,
1199 .dvbt_6 = { .if_freq = 3300, .std_bits = 0x1c }, 1199 .if_lvl = 0, .rfagc_top = 0x2c, }, /* EP3[4:0] 0x0f */
1200 .dvbt_7 = { .if_freq = 3800, .std_bits = 0x1d }, 1200 .atv_l = { .if_freq = 7750, .fm_rfn = 0, .agc_mode = 1, .std = 7,
1201 .dvbt_8 = { .if_freq = 4300, .std_bits = 0x1e }, 1201 .if_lvl = 0, .rfagc_top = 0x2c, }, /* EP3[4:0] 0x0f */
1202 .qam_6 = { .if_freq = 4000, .std_bits = 0x1d }, 1202 .atv_lc = { .if_freq = 1250, .fm_rfn = 0, .agc_mode = 1, .std = 7,
1203 .qam_8 = { .if_freq = 5000, .std_bits = 0x1f }, 1203 .if_lvl = 0, .rfagc_top = 0x2c, }, /* EP3[4:0] 0x0f */
1204 .atv_mn = { .if_freq = 5750, .fm_rfn = 0, .agc_mode = 1, .std = 5,
1205 .if_lvl = 0, .rfagc_top = 0x2c, }, /* EP3[4:0] 0x0d */
1206 .atsc_6 = { .if_freq = 3250, .fm_rfn = 0, .agc_mode = 3, .std = 4,
1207 .if_lvl = 1, .rfagc_top = 0x37, }, /* EP3[4:0] 0x1c */
1208 .dvbt_6 = { .if_freq = 3300, .fm_rfn = 0, .agc_mode = 3, .std = 4,
1209 .if_lvl = 1, .rfagc_top = 0x37, }, /* EP3[4:0] 0x1c */
1210 .dvbt_7 = { .if_freq = 3800, .fm_rfn = 0, .agc_mode = 3, .std = 5,
1211 .if_lvl = 1, .rfagc_top = 0x37, }, /* EP3[4:0] 0x1d */
1212 .dvbt_8 = { .if_freq = 4300, .fm_rfn = 0, .agc_mode = 3, .std = 6,
1213 .if_lvl = 1, .rfagc_top = 0x37, }, /* EP3[4:0] 0x1e */
1214 .qam_6 = { .if_freq = 4000, .fm_rfn = 0, .agc_mode = 3, .std = 5,
1215 .if_lvl = 1, .rfagc_top = 0x37, }, /* EP3[4:0] 0x1d */
1216 .qam_8 = { .if_freq = 5000, .fm_rfn = 0, .agc_mode = 3, .std = 7,
1217 .if_lvl = 1, .rfagc_top = 0x37, }, /* EP3[4:0] 0x1f */
1204}; 1218};
1205 1219
1206static struct tda18271_std_map tda18271c2_std_map = { 1220static struct tda18271_std_map tda18271c2_std_map = {
1207 .fm_radio = { .if_freq = 1250, .std_bits = 0x18 }, 1221 .fm_radio = { .if_freq = 1250, .fm_rfn = 1, .agc_mode = 3, .std = 0,
1208 .atv_b = { .if_freq = 6000, .std_bits = 0x0d }, 1222 .if_lvl = 0, .rfagc_top = 0x2c, }, /* EP3[4:0] 0x18 */
1209 .atv_dk = { .if_freq = 6900, .std_bits = 0x0e }, 1223 .atv_b = { .if_freq = 6000, .fm_rfn = 0, .agc_mode = 1, .std = 5,
1210 .atv_gh = { .if_freq = 7100, .std_bits = 0x0e }, 1224 .if_lvl = 0, .rfagc_top = 0x2c, }, /* EP3[4:0] 0x0d */
1211 .atv_i = { .if_freq = 7250, .std_bits = 0x0e }, 1225 .atv_dk = { .if_freq = 6900, .fm_rfn = 0, .agc_mode = 1, .std = 6,
1212 .atv_l = { .if_freq = 6900, .std_bits = 0x0e }, 1226 .if_lvl = 0, .rfagc_top = 0x2c, }, /* EP3[4:0] 0x0e */
1213 .atv_lc = { .if_freq = 1250, .std_bits = 0x0e }, 1227 .atv_gh = { .if_freq = 7100, .fm_rfn = 0, .agc_mode = 1, .std = 6,
1214 .atv_mn = { .if_freq = 5400, .std_bits = 0x0c }, 1228 .if_lvl = 0, .rfagc_top = 0x2c, }, /* EP3[4:0] 0x0e */
1215 .atsc_6 = { .if_freq = 3250, .std_bits = 0x1c }, 1229 .atv_i = { .if_freq = 7250, .fm_rfn = 0, .agc_mode = 1, .std = 6,
1216 .dvbt_6 = { .if_freq = 3300, .std_bits = 0x1c }, 1230 .if_lvl = 0, .rfagc_top = 0x2c, }, /* EP3[4:0] 0x0e */
1217 .dvbt_7 = { .if_freq = 3500, .std_bits = 0x1c }, 1231 .atv_l = { .if_freq = 6900, .fm_rfn = 0, .agc_mode = 1, .std = 6,
1218 .dvbt_8 = { .if_freq = 4000, .std_bits = 0x1d }, 1232 .if_lvl = 0, .rfagc_top = 0x2c, }, /* EP3[4:0] 0x0e */
1219 .qam_6 = { .if_freq = 4000, .std_bits = 0x1d }, 1233 .atv_lc = { .if_freq = 1250, .fm_rfn = 0, .agc_mode = 1, .std = 6,
1220 .qam_8 = { .if_freq = 5000, .std_bits = 0x1f }, 1234 .if_lvl = 0, .rfagc_top = 0x2c, }, /* EP3[4:0] 0x0e */
1235 .atv_mn = { .if_freq = 5400, .fm_rfn = 0, .agc_mode = 1, .std = 4,
1236 .if_lvl = 0, .rfagc_top = 0x2c, }, /* EP3[4:0] 0x0c */
1237 .atsc_6 = { .if_freq = 3250, .fm_rfn = 0, .agc_mode = 3, .std = 4,
1238 .if_lvl = 1, .rfagc_top = 0x37, }, /* EP3[4:0] 0x1c */
1239 .dvbt_6 = { .if_freq = 3300, .fm_rfn = 0, .agc_mode = 3, .std = 4,
1240 .if_lvl = 1, .rfagc_top = 0x37, }, /* EP3[4:0] 0x1c */
1241 .dvbt_7 = { .if_freq = 3500, .fm_rfn = 0, .agc_mode = 3, .std = 4,
1242 .if_lvl = 1, .rfagc_top = 0x37, }, /* EP3[4:0] 0x1c */
1243 .dvbt_8 = { .if_freq = 4000, .fm_rfn = 0, .agc_mode = 3, .std = 5,
1244 .if_lvl = 1, .rfagc_top = 0x37, }, /* EP3[4:0] 0x1d */
1245 .qam_6 = { .if_freq = 4000, .fm_rfn = 0, .agc_mode = 3, .std = 5,
1246 .if_lvl = 1, .rfagc_top = 0x37, }, /* EP3[4:0] 0x1d */
1247 .qam_8 = { .if_freq = 5000, .fm_rfn = 0, .agc_mode = 3, .std = 7,
1248 .if_lvl = 1, .rfagc_top = 0x37, }, /* EP3[4:0] 0x1f */
1221}; 1249};
1222 1250
1223/*---------------------------------------------------------------------*/ 1251/*---------------------------------------------------------------------*/
diff --git a/drivers/media/dvb/frontends/tda18271.h b/drivers/media/dvb/frontends/tda18271.h
index 24b0e35a2ab3..0e7af8d05a38 100644
--- a/drivers/media/dvb/frontends/tda18271.h
+++ b/drivers/media/dvb/frontends/tda18271.h
@@ -26,7 +26,17 @@
26 26
27struct tda18271_std_map_item { 27struct tda18271_std_map_item {
28 u16 if_freq; 28 u16 if_freq;
29 u8 std_bits; 29
30 /* EP3[4:3] */
31 unsigned int agc_mode:2;
32 /* EP3[2:0] */
33 unsigned int std:3;
34 /* EP4[7] */
35 unsigned int fm_rfn:1;
36 /* EP4[4:2] */
37 unsigned int if_lvl:3;
38 /* EB22[6:0] */
39 unsigned int rfagc_top:7;
30}; 40};
31 41
32struct tda18271_std_map { 42struct tda18271_std_map {
@@ -46,6 +56,11 @@ struct tda18271_std_map {
46 struct tda18271_std_map_item qam_8; 56 struct tda18271_std_map_item qam_8;
47}; 57};
48 58
59enum tda18271_role {
60 TDA18271_MASTER = 0,
61 TDA18271_SLAVE,
62};
63
49enum tda18271_i2c_gate { 64enum tda18271_i2c_gate {
50 TDA18271_GATE_AUTO = 0, 65 TDA18271_GATE_AUTO = 0,
51 TDA18271_GATE_ANALOG, 66 TDA18271_GATE_ANALOG,
@@ -56,8 +71,14 @@ struct tda18271_config {
56 /* override default if freq / std settings (optional) */ 71 /* override default if freq / std settings (optional) */
57 struct tda18271_std_map *std_map; 72 struct tda18271_std_map *std_map;
58 73
74 /* master / slave tuner: master uses main pll, slave uses cal pll */
75 enum tda18271_role role;
76
59 /* use i2c gate provided by analog or digital demod */ 77 /* use i2c gate provided by analog or digital demod */
60 enum tda18271_i2c_gate gate; 78 enum tda18271_i2c_gate gate;
79
80 /* some i2c providers cant write all 39 registers at once */
81 unsigned int small_i2c:1;
61}; 82};
62 83
63#if defined(CONFIG_DVB_TDA18271) || (defined(CONFIG_DVB_TDA18271_MODULE) && defined(MODULE)) 84#if defined(CONFIG_DVB_TDA18271) || (defined(CONFIG_DVB_TDA18271_MODULE) && defined(MODULE))
@@ -70,7 +91,7 @@ static inline struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe,
70 struct i2c_adapter *i2c, 91 struct i2c_adapter *i2c,
71 struct tda18271_config *cfg) 92 struct tda18271_config *cfg)
72{ 93{
73 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 94 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
74 return NULL; 95 return NULL;
75} 96}
76#endif 97#endif
diff --git a/drivers/media/dvb/frontends/tda8083.c b/drivers/media/dvb/frontends/tda8083.c
index 011b74f798a0..5b843b2e67e8 100644
--- a/drivers/media/dvb/frontends/tda8083.c
+++ b/drivers/media/dvb/frontends/tda8083.c
@@ -68,7 +68,7 @@ static int tda8083_writereg (struct tda8083_state* state, u8 reg, u8 data)
68 68
69 if (ret != 1) 69 if (ret != 1)
70 dprintk ("%s: writereg error (reg %02x, ret == %i)\n", 70 dprintk ("%s: writereg error (reg %02x, ret == %i)\n",
71 __FUNCTION__, reg, ret); 71 __func__, reg, ret);
72 72
73 return (ret != 1) ? -1 : 0; 73 return (ret != 1) ? -1 : 0;
74} 74}
@@ -83,7 +83,7 @@ static int tda8083_readregs (struct tda8083_state* state, u8 reg1, u8 *b, u8 len
83 83
84 if (ret != 2) 84 if (ret != 2)
85 dprintk ("%s: readreg error (reg %02x, ret == %i)\n", 85 dprintk ("%s: readreg error (reg %02x, ret == %i)\n",
86 __FUNCTION__, reg1, ret); 86 __func__, reg1, ret);
87 87
88 return ret == 2 ? 0 : -1; 88 return ret == 2 ? 0 : -1;
89} 89}
diff --git a/drivers/media/dvb/frontends/tda8083.h b/drivers/media/dvb/frontends/tda8083.h
index 2d3307999f21..5a03c14a10e8 100644
--- a/drivers/media/dvb/frontends/tda8083.h
+++ b/drivers/media/dvb/frontends/tda8083.h
@@ -42,7 +42,7 @@ extern struct dvb_frontend* tda8083_attach(const struct tda8083_config* config,
42static inline struct dvb_frontend* tda8083_attach(const struct tda8083_config* config, 42static inline struct dvb_frontend* tda8083_attach(const struct tda8083_config* config,
43 struct i2c_adapter* i2c) 43 struct i2c_adapter* i2c)
44{ 44{
45 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 45 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
46 return NULL; 46 return NULL;
47} 47}
48#endif // CONFIG_DVB_TDA8083 48#endif // CONFIG_DVB_TDA8083
diff --git a/drivers/media/dvb/frontends/tda826x.c b/drivers/media/dvb/frontends/tda826x.c
index bd3ebc284835..a051554b5e25 100644
--- a/drivers/media/dvb/frontends/tda826x.c
+++ b/drivers/media/dvb/frontends/tda826x.c
@@ -26,7 +26,7 @@
26 26
27#include "tda826x.h" 27#include "tda826x.h"
28 28
29static int debug = 0; 29static int debug;
30#define dprintk(args...) \ 30#define dprintk(args...) \
31 do { \ 31 do { \
32 if (debug) printk(KERN_DEBUG "tda826x: " args); \ 32 if (debug) printk(KERN_DEBUG "tda826x: " args); \
@@ -54,7 +54,7 @@ static int tda826x_sleep(struct dvb_frontend *fe)
54 u8 buf [] = { 0x00, 0x8d }; 54 u8 buf [] = { 0x00, 0x8d };
55 struct i2c_msg msg = { .addr = priv->i2c_address, .flags = 0, .buf = buf, .len = 2 }; 55 struct i2c_msg msg = { .addr = priv->i2c_address, .flags = 0, .buf = buf, .len = 2 };
56 56
57 dprintk("%s:\n", __FUNCTION__); 57 dprintk("%s:\n", __func__);
58 58
59 if (!priv->has_loopthrough) 59 if (!priv->has_loopthrough)
60 buf[1] = 0xad; 60 buf[1] = 0xad;
@@ -62,7 +62,7 @@ static int tda826x_sleep(struct dvb_frontend *fe)
62 if (fe->ops.i2c_gate_ctrl) 62 if (fe->ops.i2c_gate_ctrl)
63 fe->ops.i2c_gate_ctrl(fe, 1); 63 fe->ops.i2c_gate_ctrl(fe, 1);
64 if ((ret = i2c_transfer (priv->i2c, &msg, 1)) != 1) { 64 if ((ret = i2c_transfer (priv->i2c, &msg, 1)) != 1) {
65 dprintk("%s: i2c error\n", __FUNCTION__); 65 dprintk("%s: i2c error\n", __func__);
66 } 66 }
67 if (fe->ops.i2c_gate_ctrl) 67 if (fe->ops.i2c_gate_ctrl)
68 fe->ops.i2c_gate_ctrl(fe, 0); 68 fe->ops.i2c_gate_ctrl(fe, 0);
@@ -75,13 +75,24 @@ static int tda826x_set_params(struct dvb_frontend *fe, struct dvb_frontend_param
75 struct tda826x_priv *priv = fe->tuner_priv; 75 struct tda826x_priv *priv = fe->tuner_priv;
76 int ret; 76 int ret;
77 u32 div; 77 u32 div;
78 u32 ksyms;
79 u32 bandwidth;
78 u8 buf [11]; 80 u8 buf [11];
79 struct i2c_msg msg = { .addr = priv->i2c_address, .flags = 0, .buf = buf, .len = 11 }; 81 struct i2c_msg msg = { .addr = priv->i2c_address, .flags = 0, .buf = buf, .len = 11 };
80 82
81 dprintk("%s:\n", __FUNCTION__); 83 dprintk("%s:\n", __func__);
82 84
83 div = (params->frequency + (1000-1)) / 1000; 85 div = (params->frequency + (1000-1)) / 1000;
84 86
87 /* BW = ((1 + RO) * SR/2 + 5) * 1.3 [SR in MSPS, BW in MHz] */
88 /* with R0 = 0.35 and some transformations: */
89 ksyms = params->u.qpsk.symbol_rate / 1000;
90 bandwidth = (878 * ksyms + 6500000) / 1000000 + 1;
91 if (bandwidth < 5)
92 bandwidth = 5;
93 else if (bandwidth > 36)
94 bandwidth = 36;
95
85 buf[0] = 0x00; // subaddress 96 buf[0] = 0x00; // subaddress
86 buf[1] = 0x09; // powerdown RSSI + the magic value 1 97 buf[1] = 0x09; // powerdown RSSI + the magic value 1
87 if (!priv->has_loopthrough) 98 if (!priv->has_loopthrough)
@@ -89,7 +100,7 @@ static int tda826x_set_params(struct dvb_frontend *fe, struct dvb_frontend_param
89 buf[2] = (1<<5) | 0x0b; // 1Mhz + 0.45 VCO 100 buf[2] = (1<<5) | 0x0b; // 1Mhz + 0.45 VCO
90 buf[3] = div >> 7; 101 buf[3] = div >> 7;
91 buf[4] = div << 1; 102 buf[4] = div << 1;
92 buf[5] = 0x77; // baseband cut-off 19 MHz 103 buf[5] = ((bandwidth - 5) << 3) | 7; /* baseband cut-off */
93 buf[6] = 0xfe; // baseband gain 9 db + no RF attenuation 104 buf[6] = 0xfe; // baseband gain 9 db + no RF attenuation
94 buf[7] = 0x83; // charge pumps at high, tests off 105 buf[7] = 0x83; // charge pumps at high, tests off
95 buf[8] = 0x80; // recommended value 4 for AMPVCO + disable ports. 106 buf[8] = 0x80; // recommended value 4 for AMPVCO + disable ports.
@@ -99,7 +110,7 @@ static int tda826x_set_params(struct dvb_frontend *fe, struct dvb_frontend_param
99 if (fe->ops.i2c_gate_ctrl) 110 if (fe->ops.i2c_gate_ctrl)
100 fe->ops.i2c_gate_ctrl(fe, 1); 111 fe->ops.i2c_gate_ctrl(fe, 1);
101 if ((ret = i2c_transfer (priv->i2c, &msg, 1)) != 1) { 112 if ((ret = i2c_transfer (priv->i2c, &msg, 1)) != 1) {
102 dprintk("%s: i2c error\n", __FUNCTION__); 113 dprintk("%s: i2c error\n", __func__);
103 } 114 }
104 if (fe->ops.i2c_gate_ctrl) 115 if (fe->ops.i2c_gate_ctrl)
105 fe->ops.i2c_gate_ctrl(fe, 0); 116 fe->ops.i2c_gate_ctrl(fe, 0);
@@ -138,7 +149,7 @@ struct dvb_frontend *tda826x_attach(struct dvb_frontend *fe, int addr, struct i2
138 }; 149 };
139 int ret; 150 int ret;
140 151
141 dprintk("%s:\n", __FUNCTION__); 152 dprintk("%s:\n", __func__);
142 153
143 if (fe->ops.i2c_gate_ctrl) 154 if (fe->ops.i2c_gate_ctrl)
144 fe->ops.i2c_gate_ctrl(fe, 1); 155 fe->ops.i2c_gate_ctrl(fe, 1);
diff --git a/drivers/media/dvb/frontends/tda826x.h b/drivers/media/dvb/frontends/tda826x.h
index ad9981195961..89e97926ab23 100644
--- a/drivers/media/dvb/frontends/tda826x.h
+++ b/drivers/media/dvb/frontends/tda826x.h
@@ -45,7 +45,7 @@ static inline struct dvb_frontend* tda826x_attach(struct dvb_frontend *fe,
45 struct i2c_adapter *i2c, 45 struct i2c_adapter *i2c,
46 int has_loopthrough) 46 int has_loopthrough)
47{ 47{
48 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 48 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
49 return NULL; 49 return NULL;
50} 50}
51#endif // CONFIG_DVB_TDA826X 51#endif // CONFIG_DVB_TDA826X
diff --git a/drivers/media/dvb/frontends/tda827x.c b/drivers/media/dvb/frontends/tda827x.c
index 229b11987a58..d30d2c9094d9 100644
--- a/drivers/media/dvb/frontends/tda827x.c
+++ b/drivers/media/dvb/frontends/tda827x.c
@@ -25,7 +25,7 @@
25 25
26#include "tda827x.h" 26#include "tda827x.h"
27 27
28static int debug = 0; 28static int debug;
29module_param(debug, int, 0644); 29module_param(debug, int, 0644);
30MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off)."); 30MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
31 31
@@ -142,7 +142,7 @@ static int tda827xo_set_params(struct dvb_frontend *fe,
142 int i, tuner_freq, if_freq; 142 int i, tuner_freq, if_freq;
143 u32 N; 143 u32 N;
144 144
145 dprintk("%s:\n", __FUNCTION__); 145 dprintk("%s:\n", __func__);
146 switch (params->u.ofdm.bandwidth) { 146 switch (params->u.ofdm.bandwidth) {
147 case BANDWIDTH_6_MHZ: 147 case BANDWIDTH_6_MHZ:
148 if_freq = 4000000; 148 if_freq = 4000000;
@@ -186,7 +186,7 @@ static int tda827xo_set_params(struct dvb_frontend *fe,
186 fe->ops.i2c_gate_ctrl(fe, 1); 186 fe->ops.i2c_gate_ctrl(fe, 1);
187 if (i2c_transfer(priv->i2c_adap, &msg, 1) != 1) { 187 if (i2c_transfer(priv->i2c_adap, &msg, 1) != 1) {
188 printk("%s: could not write to tuner at addr: 0x%02x\n", 188 printk("%s: could not write to tuner at addr: 0x%02x\n",
189 __FUNCTION__, priv->i2c_addr << 1); 189 __func__, priv->i2c_addr << 1);
190 return -EIO; 190 return -EIO;
191 } 191 }
192 msleep(500); 192 msleep(500);
@@ -212,7 +212,7 @@ static int tda827xo_sleep(struct dvb_frontend *fe)
212 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0, 212 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
213 .buf = buf, .len = sizeof(buf) }; 213 .buf = buf, .len = sizeof(buf) };
214 214
215 dprintk("%s:\n", __FUNCTION__); 215 dprintk("%s:\n", __func__);
216 if (fe->ops.i2c_gate_ctrl) 216 if (fe->ops.i2c_gate_ctrl)
217 fe->ops.i2c_gate_ctrl(fe, 1); 217 fe->ops.i2c_gate_ctrl(fe, 1);
218 i2c_transfer(priv->i2c_adap, &msg, 1); 218 i2c_transfer(priv->i2c_adap, &msg, 1);
@@ -389,6 +389,79 @@ static struct tda827xa_data tda827xa_analog[] = {
389 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0} 389 { .lomax = 0, .svco = 0, .spd = 0, .scr = 0, .sbs = 0, .gc3 = 0}
390}; 390};
391 391
392static int tda827xa_sleep(struct dvb_frontend *fe)
393{
394 struct tda827x_priv *priv = fe->tuner_priv;
395 static u8 buf[] = { 0x30, 0x90 };
396 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
397 .buf = buf, .len = sizeof(buf) };
398
399 dprintk("%s:\n", __func__);
400 if (fe->ops.i2c_gate_ctrl)
401 fe->ops.i2c_gate_ctrl(fe, 1);
402
403 i2c_transfer(priv->i2c_adap, &msg, 1);
404
405 if (fe->ops.i2c_gate_ctrl)
406 fe->ops.i2c_gate_ctrl(fe, 0);
407
408 if (priv->cfg && priv->cfg->sleep)
409 priv->cfg->sleep(fe);
410
411 return 0;
412}
413
414static void tda827xa_lna_gain(struct dvb_frontend *fe, int high,
415 struct analog_parameters *params)
416{
417 struct tda827x_priv *priv = fe->tuner_priv;
418 unsigned char buf[] = {0x22, 0x01};
419 int arg;
420 int gp_func;
421 struct i2c_msg msg = { .addr = priv->cfg->switch_addr, .flags = 0,
422 .buf = buf, .len = sizeof(buf) };
423
424 if (NULL == priv->cfg) {
425 dprintk("tda827x_config not defined, cannot set LNA gain!\n");
426 return;
427 }
428 if (priv->cfg->config) {
429 if (high)
430 dprintk("setting LNA to high gain\n");
431 else
432 dprintk("setting LNA to low gain\n");
433 }
434 switch (priv->cfg->config) {
435 case 0: /* no LNA */
436 break;
437 case 1: /* switch is GPIO 0 of tda8290 */
438 case 2:
439 if (params == NULL) {
440 gp_func = 0;
441 arg = 0;
442 } else {
443 /* turn Vsync on */
444 gp_func = 1;
445 if (params->std & V4L2_STD_MN)
446 arg = 1;
447 else
448 arg = 0;
449 }
450 if (priv->cfg->tuner_callback)
451 priv->cfg->tuner_callback(priv->i2c_adap->algo_data,
452 gp_func, arg);
453 buf[1] = high ? 0 : 1;
454 if (priv->cfg->config == 2)
455 buf[1] = high ? 1 : 0;
456 i2c_transfer(priv->i2c_adap, &msg, 1);
457 break;
458 case 3: /* switch with GPIO of saa713x */
459 if (priv->cfg->tuner_callback)
460 priv->cfg->tuner_callback(priv->i2c_adap->algo_data, 0, high);
461 break;
462 }
463}
464
392static int tda827xa_set_params(struct dvb_frontend *fe, 465static int tda827xa_set_params(struct dvb_frontend *fe,
393 struct dvb_frontend_parameters *params) 466 struct dvb_frontend_parameters *params)
394{ 467{
@@ -401,9 +474,9 @@ static int tda827xa_set_params(struct dvb_frontend *fe,
401 int i, tuner_freq, if_freq; 474 int i, tuner_freq, if_freq;
402 u32 N; 475 u32 N;
403 476
404 dprintk("%s:\n", __FUNCTION__); 477 dprintk("%s:\n", __func__);
405 if (priv->cfg && priv->cfg->lna_gain) 478
406 priv->cfg->lna_gain(fe, 1); 479 tda827xa_lna_gain(fe, 1, NULL);
407 msleep(20); 480 msleep(20);
408 481
409 switch (params->u.ofdm.bandwidth) { 482 switch (params->u.ofdm.bandwidth) {
@@ -444,7 +517,7 @@ static int tda827xa_set_params(struct dvb_frontend *fe,
444 fe->ops.i2c_gate_ctrl(fe, 1); 517 fe->ops.i2c_gate_ctrl(fe, 1);
445 if (i2c_transfer(priv->i2c_adap, &msg, 1) != 1) { 518 if (i2c_transfer(priv->i2c_adap, &msg, 1) != 1) {
446 printk("%s: could not write to tuner at addr: 0x%02x\n", 519 printk("%s: could not write to tuner at addr: 0x%02x\n",
447 __FUNCTION__, priv->i2c_addr << 1); 520 __func__, priv->i2c_addr << 1);
448 return -EIO; 521 return -EIO;
449 } 522 }
450 buf[0] = 0x90; 523 buf[0] = 0x90;
@@ -474,8 +547,7 @@ static int tda827xa_set_params(struct dvb_frontend *fe,
474 buf[1] >>= 4; 547 buf[1] >>= 4;
475 dprintk("tda8275a AGC2 gain is: %d\n", buf[1]); 548 dprintk("tda8275a AGC2 gain is: %d\n", buf[1]);
476 if ((buf[1]) < 2) { 549 if ((buf[1]) < 2) {
477 if (priv->cfg && priv->cfg->lna_gain) 550 tda827xa_lna_gain(fe, 0, NULL);
478 priv->cfg->lna_gain(fe, 0);
479 buf[0] = 0x60; 551 buf[0] = 0x60;
480 buf[1] = 0x0c; 552 buf[1] = 0x0c;
481 if (fe->ops.i2c_gate_ctrl) 553 if (fe->ops.i2c_gate_ctrl)
@@ -523,75 +595,6 @@ static int tda827xa_set_params(struct dvb_frontend *fe,
523 return 0; 595 return 0;
524} 596}
525 597
526static int tda827xa_sleep(struct dvb_frontend *fe)
527{
528 struct tda827x_priv *priv = fe->tuner_priv;
529 static u8 buf[] = { 0x30, 0x90 };
530 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
531 .buf = buf, .len = sizeof(buf) };
532
533 dprintk("%s:\n", __FUNCTION__);
534 if (fe->ops.i2c_gate_ctrl)
535 fe->ops.i2c_gate_ctrl(fe, 1);
536
537 i2c_transfer(priv->i2c_adap, &msg, 1);
538
539 if (fe->ops.i2c_gate_ctrl)
540 fe->ops.i2c_gate_ctrl(fe, 0);
541
542 if (priv->cfg && priv->cfg->sleep)
543 priv->cfg->sleep(fe);
544
545 return 0;
546}
547
548/* ------------------------------------------------------------------ */
549
550static void tda827xa_lna_gain(struct dvb_frontend *fe, int high,
551 struct analog_parameters *params)
552{
553 struct tda827x_priv *priv = fe->tuner_priv;
554 unsigned char buf[] = {0x22, 0x01};
555 int arg;
556 struct i2c_msg msg = { .addr = priv->i2c_addr, .flags = 0,
557 .buf = buf, .len = sizeof(buf) };
558
559 if (NULL == priv->cfg) {
560 dprintk("tda827x_config not defined, cannot set LNA gain!\n");
561 return;
562 }
563
564 if (priv->cfg->config) {
565 if (high)
566 dprintk("setting LNA to high gain\n");
567 else
568 dprintk("setting LNA to low gain\n");
569 }
570 switch (*priv->cfg->config) {
571 case 0: /* no LNA */
572 break;
573 case 1: /* switch is GPIO 0 of tda8290 */
574 case 2:
575 /* turn Vsync on */
576 if (params->std & V4L2_STD_MN)
577 arg = 1;
578 else
579 arg = 0;
580 if (priv->cfg->tuner_callback)
581 priv->cfg->tuner_callback(priv->i2c_adap->algo_data,
582 1, arg);
583 buf[1] = high ? 0 : 1;
584 if (*priv->cfg->config == 2)
585 buf[1] = high ? 1 : 0;
586 i2c_transfer(priv->i2c_adap, &msg, 1);
587 break;
588 case 3: /* switch with GPIO of saa713x */
589 if (priv->cfg->tuner_callback)
590 priv->cfg->tuner_callback(priv->i2c_adap->algo_data,
591 0, high);
592 break;
593 }
594}
595 598
596static int tda827xa_set_analog_params(struct dvb_frontend *fe, 599static int tda827xa_set_analog_params(struct dvb_frontend *fe,
597 struct analog_parameters *params) 600 struct analog_parameters *params)
@@ -726,7 +729,7 @@ static int tda827x_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
726static int tda827x_init(struct dvb_frontend *fe) 729static int tda827x_init(struct dvb_frontend *fe)
727{ 730{
728 struct tda827x_priv *priv = fe->tuner_priv; 731 struct tda827x_priv *priv = fe->tuner_priv;
729 dprintk("%s:\n", __FUNCTION__); 732 dprintk("%s:\n", __func__);
730 if (priv->cfg && priv->cfg->init) 733 if (priv->cfg && priv->cfg->init)
731 priv->cfg->init(fe); 734 priv->cfg->init(fe);
732 735
@@ -794,7 +797,7 @@ static int tda827x_probe_version(struct dvb_frontend *fe)
794 fe->ops.i2c_gate_ctrl(fe, 1); 797 fe->ops.i2c_gate_ctrl(fe, 1);
795 if (i2c_transfer(priv->i2c_adap, &msg, 1) != 1) { 798 if (i2c_transfer(priv->i2c_adap, &msg, 1) != 1) {
796 printk("%s: could not read from tuner at addr: 0x%02x\n", 799 printk("%s: could not read from tuner at addr: 0x%02x\n",
797 __FUNCTION__, msg.addr << 1); 800 __func__, msg.addr << 1);
798 return -EIO; 801 return -EIO;
799 } 802 }
800 if ((data & 0x3c) == 0) { 803 if ((data & 0x3c) == 0) {
@@ -818,7 +821,7 @@ struct dvb_frontend *tda827x_attach(struct dvb_frontend *fe, int addr,
818{ 821{
819 struct tda827x_priv *priv = NULL; 822 struct tda827x_priv *priv = NULL;
820 823
821 dprintk("%s:\n", __FUNCTION__); 824 dprintk("%s:\n", __func__);
822 priv = kzalloc(sizeof(struct tda827x_priv), GFP_KERNEL); 825 priv = kzalloc(sizeof(struct tda827x_priv), GFP_KERNEL);
823 if (priv == NULL) 826 if (priv == NULL)
824 return NULL; 827 return NULL;
diff --git a/drivers/media/dvb/frontends/tda827x.h b/drivers/media/dvb/frontends/tda827x.h
index 92eb65b4012b..b73c23570dab 100644
--- a/drivers/media/dvb/frontends/tda827x.h
+++ b/drivers/media/dvb/frontends/tda827x.h
@@ -30,12 +30,12 @@
30struct tda827x_config 30struct tda827x_config
31{ 31{
32 /* saa7134 - provided callbacks */ 32 /* saa7134 - provided callbacks */
33 void (*lna_gain) (struct dvb_frontend *fe, int high);
34 int (*init) (struct dvb_frontend *fe); 33 int (*init) (struct dvb_frontend *fe);
35 int (*sleep) (struct dvb_frontend *fe); 34 int (*sleep) (struct dvb_frontend *fe);
36 35
37 /* interface to tda829x driver */ 36 /* interface to tda829x driver */
38 unsigned int *config; 37 unsigned int config;
38 int switch_addr;
39 int (*tuner_callback) (void *dev, int command, int arg); 39 int (*tuner_callback) (void *dev, int command, int arg);
40 40
41 void (*agcf)(struct dvb_frontend *fe); 41 void (*agcf)(struct dvb_frontend *fe);
@@ -61,7 +61,7 @@ static inline struct dvb_frontend* tda827x_attach(struct dvb_frontend *fe,
61 struct i2c_adapter *i2c, 61 struct i2c_adapter *i2c,
62 struct tda827x_config *cfg) 62 struct tda827x_config *cfg)
63{ 63{
64 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 64 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
65 return NULL; 65 return NULL;
66} 66}
67#endif // CONFIG_DVB_TDA827X 67#endif // CONFIG_DVB_TDA827X
diff --git a/drivers/media/dvb/frontends/tua6100.c b/drivers/media/dvb/frontends/tua6100.c
index 6ba0029dcf2e..1790baee014c 100644
--- a/drivers/media/dvb/frontends/tua6100.c
+++ b/drivers/media/dvb/frontends/tua6100.c
@@ -58,7 +58,7 @@ static int tua6100_sleep(struct dvb_frontend *fe)
58 if (fe->ops.i2c_gate_ctrl) 58 if (fe->ops.i2c_gate_ctrl)
59 fe->ops.i2c_gate_ctrl(fe, 1); 59 fe->ops.i2c_gate_ctrl(fe, 1);
60 if ((ret = i2c_transfer (priv->i2c, &msg, 1)) != 1) { 60 if ((ret = i2c_transfer (priv->i2c, &msg, 1)) != 1) {
61 printk("%s: i2c error\n", __FUNCTION__); 61 printk("%s: i2c error\n", __func__);
62 } 62 }
63 if (fe->ops.i2c_gate_ctrl) 63 if (fe->ops.i2c_gate_ctrl)
64 fe->ops.i2c_gate_ctrl(fe, 0); 64 fe->ops.i2c_gate_ctrl(fe, 0);
diff --git a/drivers/media/dvb/frontends/tua6100.h b/drivers/media/dvb/frontends/tua6100.h
index 03a665e7df6d..f83dbd5e42ae 100644
--- a/drivers/media/dvb/frontends/tua6100.h
+++ b/drivers/media/dvb/frontends/tua6100.h
@@ -39,7 +39,7 @@ extern struct dvb_frontend *tua6100_attach(struct dvb_frontend *fe, int addr, st
39#else 39#else
40static inline struct dvb_frontend* tua6100_attach(struct dvb_frontend *fe, int addr, struct i2c_adapter *i2c) 40static inline struct dvb_frontend* tua6100_attach(struct dvb_frontend *fe, int addr, struct i2c_adapter *i2c)
41{ 41{
42 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 42 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
43 return NULL; 43 return NULL;
44} 44}
45#endif // CONFIG_DVB_TUA6100 45#endif // CONFIG_DVB_TUA6100
diff --git a/drivers/media/dvb/frontends/ves1820.c b/drivers/media/dvb/frontends/ves1820.c
index 8791701c8f25..a184597f1d9b 100644
--- a/drivers/media/dvb/frontends/ves1820.c
+++ b/drivers/media/dvb/frontends/ves1820.c
@@ -66,7 +66,7 @@ static int ves1820_writereg(struct ves1820_state *state, u8 reg, u8 data)
66 66
67 if (ret != 1) 67 if (ret != 1)
68 printk("ves1820: %s(): writereg error (reg == 0x%02x, " 68 printk("ves1820: %s(): writereg error (reg == 0x%02x, "
69 "val == 0x%02x, ret == %i)\n", __FUNCTION__, reg, data, ret); 69 "val == 0x%02x, ret == %i)\n", __func__, reg, data, ret);
70 70
71 return (ret != 1) ? -EREMOTEIO : 0; 71 return (ret != 1) ? -EREMOTEIO : 0;
72} 72}
@@ -85,7 +85,7 @@ static u8 ves1820_readreg(struct ves1820_state *state, u8 reg)
85 85
86 if (ret != 2) 86 if (ret != 2)
87 printk("ves1820: %s(): readreg error (reg == 0x%02x, " 87 printk("ves1820: %s(): readreg error (reg == 0x%02x, "
88 "ret == %i)\n", __FUNCTION__, reg, ret); 88 "ret == %i)\n", __func__, reg, ret);
89 89
90 return b1[0]; 90 return b1[0];
91} 91}
diff --git a/drivers/media/dvb/frontends/ves1820.h b/drivers/media/dvb/frontends/ves1820.h
index e4a2a324046a..e902ed634ec3 100644
--- a/drivers/media/dvb/frontends/ves1820.h
+++ b/drivers/media/dvb/frontends/ves1820.h
@@ -48,7 +48,7 @@ extern struct dvb_frontend* ves1820_attach(const struct ves1820_config* config,
48static inline struct dvb_frontend* ves1820_attach(const struct ves1820_config* config, 48static inline struct dvb_frontend* ves1820_attach(const struct ves1820_config* config,
49 struct i2c_adapter* i2c, u8 pwm) 49 struct i2c_adapter* i2c, u8 pwm)
50{ 50{
51 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 51 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
52 return NULL; 52 return NULL;
53} 53}
54#endif // CONFIG_DVB_VES1820 54#endif // CONFIG_DVB_VES1820
diff --git a/drivers/media/dvb/frontends/ves1x93.c b/drivers/media/dvb/frontends/ves1x93.c
index 23fd0303c91b..bd558960bd87 100644
--- a/drivers/media/dvb/frontends/ves1x93.c
+++ b/drivers/media/dvb/frontends/ves1x93.c
@@ -48,7 +48,7 @@ struct ves1x93_state {
48 u8 demod_type; 48 u8 demod_type;
49}; 49};
50 50
51static int debug = 0; 51static int debug;
52#define dprintk if (debug) printk 52#define dprintk if (debug) printk
53 53
54#define DEMOD_VES1893 0 54#define DEMOD_VES1893 0
@@ -98,7 +98,7 @@ static int ves1x93_writereg (struct ves1x93_state* state, u8 reg, u8 data)
98 int err; 98 int err;
99 99
100 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) { 100 if ((err = i2c_transfer (state->i2c, &msg, 1)) != 1) {
101 dprintk ("%s: writereg error (err == %i, reg == 0x%02x, data == 0x%02x)\n", __FUNCTION__, err, reg, data); 101 dprintk ("%s: writereg error (err == %i, reg == 0x%02x, data == 0x%02x)\n", __func__, err, reg, data);
102 return -EREMOTEIO; 102 return -EREMOTEIO;
103 } 103 }
104 104
@@ -179,7 +179,7 @@ static int ves1x93_set_symbolrate (struct ves1x93_state* state, u32 srate)
179 u32 tmp; 179 u32 tmp;
180 u32 FIN; 180 u32 FIN;
181 181
182 dprintk("%s: srate == %d\n", __FUNCTION__, (unsigned int) srate); 182 dprintk("%s: srate == %d\n", __func__, (unsigned int) srate);
183 183
184 if (srate > state->config->xin/2) 184 if (srate > state->config->xin/2)
185 srate = state->config->xin/2; 185 srate = state->config->xin/2;
@@ -266,7 +266,7 @@ static int ves1x93_init (struct dvb_frontend* fe)
266 int i; 266 int i;
267 int val; 267 int val;
268 268
269 dprintk("%s: init chip\n", __FUNCTION__); 269 dprintk("%s: init chip\n", __func__);
270 270
271 for (i = 0; i < state->tab_size; i++) { 271 for (i = 0; i < state->tab_size; i++) {
272 if (state->init_1x93_wtab[i]) { 272 if (state->init_1x93_wtab[i]) {
diff --git a/drivers/media/dvb/frontends/ves1x93.h b/drivers/media/dvb/frontends/ves1x93.h
index d507f8966f81..8a5a49e808f6 100644
--- a/drivers/media/dvb/frontends/ves1x93.h
+++ b/drivers/media/dvb/frontends/ves1x93.h
@@ -47,7 +47,7 @@ extern struct dvb_frontend* ves1x93_attach(const struct ves1x93_config* config,
47static inline struct dvb_frontend* ves1x93_attach(const struct ves1x93_config* config, 47static inline struct dvb_frontend* ves1x93_attach(const struct ves1x93_config* config,
48 struct i2c_adapter* i2c) 48 struct i2c_adapter* i2c)
49{ 49{
50 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 50 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
51 return NULL; 51 return NULL;
52} 52}
53#endif // CONFIG_DVB_VES1X93 53#endif // CONFIG_DVB_VES1X93
diff --git a/drivers/media/dvb/frontends/xc5000.c b/drivers/media/dvb/frontends/xc5000.c
index f642ca200b59..43d35bdb221f 100644
--- a/drivers/media/dvb/frontends/xc5000.c
+++ b/drivers/media/dvb/frontends/xc5000.c
@@ -151,7 +151,7 @@ typedef struct {
151#define FM_Radio_INPUT2 21 151#define FM_Radio_INPUT2 21
152#define FM_Radio_INPUT1 22 152#define FM_Radio_INPUT1 22
153 153
154XC_TV_STANDARD XC5000_Standard[MAX_TV_STANDARD] = { 154static XC_TV_STANDARD XC5000_Standard[MAX_TV_STANDARD] = {
155 {"M/N-NTSC/PAL-BTSC", 0x0400, 0x8020}, 155 {"M/N-NTSC/PAL-BTSC", 0x0400, 0x8020},
156 {"M/N-NTSC/PAL-A2", 0x0600, 0x8020}, 156 {"M/N-NTSC/PAL-A2", 0x0600, 0x8020},
157 {"M/N-NTSC/PAL-EIAJ", 0x0440, 0x8020}, 157 {"M/N-NTSC/PAL-EIAJ", 0x0440, 0x8020},
@@ -209,7 +209,7 @@ static void xc5000_TunerReset(struct dvb_frontend *fe)
209 struct xc5000_priv *priv = fe->tuner_priv; 209 struct xc5000_priv *priv = fe->tuner_priv;
210 int ret; 210 int ret;
211 211
212 dprintk(1, "%s()\n", __FUNCTION__); 212 dprintk(1, "%s()\n", __func__);
213 213
214 if (priv->cfg->tuner_callback) { 214 if (priv->cfg->tuner_callback) {
215 ret = priv->cfg->tuner_callback(priv->cfg->priv, 215 ret = priv->cfg->tuner_callback(priv->cfg->priv,
@@ -330,7 +330,7 @@ static int xc_load_i2c_sequence(struct dvb_frontend *fe, u8 i2c_sequence[])
330 330
331static int xc_initialize(struct xc5000_priv *priv) 331static int xc_initialize(struct xc5000_priv *priv)
332{ 332{
333 dprintk(1, "%s()\n", __FUNCTION__); 333 dprintk(1, "%s()\n", __func__);
334 return xc_write_reg(priv, XREG_INIT, 0); 334 return xc_write_reg(priv, XREG_INIT, 0);
335} 335}
336 336
@@ -338,9 +338,9 @@ static int xc_SetTVStandard(struct xc5000_priv *priv,
338 u16 VideoMode, u16 AudioMode) 338 u16 VideoMode, u16 AudioMode)
339{ 339{
340 int ret; 340 int ret;
341 dprintk(1, "%s(0x%04x,0x%04x)\n", __FUNCTION__, VideoMode, AudioMode); 341 dprintk(1, "%s(0x%04x,0x%04x)\n", __func__, VideoMode, AudioMode);
342 dprintk(1, "%s() Standard = %s\n", 342 dprintk(1, "%s() Standard = %s\n",
343 __FUNCTION__, 343 __func__,
344 XC5000_Standard[priv->video_standard].Name); 344 XC5000_Standard[priv->video_standard].Name);
345 345
346 ret = xc_write_reg(priv, XREG_VIDEO_MODE, VideoMode); 346 ret = xc_write_reg(priv, XREG_VIDEO_MODE, VideoMode);
@@ -361,7 +361,7 @@ static int xc_shutdown(struct xc5000_priv *priv)
361 361
362static int xc_SetSignalSource(struct xc5000_priv *priv, u16 rf_mode) 362static int xc_SetSignalSource(struct xc5000_priv *priv, u16 rf_mode)
363{ 363{
364 dprintk(1, "%s(%d) Source = %s\n", __FUNCTION__, rf_mode, 364 dprintk(1, "%s(%d) Source = %s\n", __func__, rf_mode,
365 rf_mode == XC_RF_MODE_AIR ? "ANTENNA" : "CABLE"); 365 rf_mode == XC_RF_MODE_AIR ? "ANTENNA" : "CABLE");
366 366
367 if ((rf_mode != XC_RF_MODE_AIR) && (rf_mode != XC_RF_MODE_CABLE)) 367 if ((rf_mode != XC_RF_MODE_AIR) && (rf_mode != XC_RF_MODE_CABLE))
@@ -369,7 +369,7 @@ static int xc_SetSignalSource(struct xc5000_priv *priv, u16 rf_mode)
369 rf_mode = XC_RF_MODE_CABLE; 369 rf_mode = XC_RF_MODE_CABLE;
370 printk(KERN_ERR 370 printk(KERN_ERR
371 "%s(), Invalid mode, defaulting to CABLE", 371 "%s(), Invalid mode, defaulting to CABLE",
372 __FUNCTION__); 372 __func__);
373 } 373 }
374 return xc_write_reg(priv, XREG_SIGNALSOURCE, rf_mode); 374 return xc_write_reg(priv, XREG_SIGNALSOURCE, rf_mode);
375} 375}
@@ -380,7 +380,7 @@ static int xc_set_RF_frequency(struct xc5000_priv *priv, u32 freq_hz)
380{ 380{
381 u16 freq_code; 381 u16 freq_code;
382 382
383 dprintk(1, "%s(%u)\n", __FUNCTION__, freq_hz); 383 dprintk(1, "%s(%u)\n", __func__, freq_hz);
384 384
385 if ((freq_hz > xc5000_tuner_ops.info.frequency_max) || 385 if ((freq_hz > xc5000_tuner_ops.info.frequency_max) ||
386 (freq_hz < xc5000_tuner_ops.info.frequency_min)) 386 (freq_hz < xc5000_tuner_ops.info.frequency_min))
@@ -396,7 +396,7 @@ static int xc_set_IF_frequency(struct xc5000_priv *priv, u32 freq_khz)
396{ 396{
397 u32 freq_code = (freq_khz * 1024)/1000; 397 u32 freq_code = (freq_khz * 1024)/1000;
398 dprintk(1, "%s(freq_khz = %d) freq_code = 0x%x\n", 398 dprintk(1, "%s(freq_khz = %d) freq_code = 0x%x\n",
399 __FUNCTION__, freq_khz, freq_code); 399 __func__, freq_khz, freq_code);
400 400
401 return xc_write_reg(priv, XREG_IF_OUT, freq_code); 401 return xc_write_reg(priv, XREG_IF_OUT, freq_code);
402} 402}
@@ -488,7 +488,7 @@ static int xc_tune_channel(struct xc5000_priv *priv, u32 freq_hz)
488{ 488{
489 int found = 0; 489 int found = 0;
490 490
491 dprintk(1, "%s(%u)\n", __FUNCTION__, freq_hz); 491 dprintk(1, "%s(%u)\n", __func__, freq_hz);
492 492
493 if (xc_set_RF_frequency(priv, freq_hz) != XC_RESULT_SUCCESS) 493 if (xc_set_RF_frequency(priv, freq_hz) != XC_RESULT_SUCCESS)
494 return 0; 494 return 0;
@@ -627,12 +627,12 @@ static int xc5000_set_params(struct dvb_frontend *fe,
627 struct xc5000_priv *priv = fe->tuner_priv; 627 struct xc5000_priv *priv = fe->tuner_priv;
628 int ret; 628 int ret;
629 629
630 dprintk(1, "%s() frequency=%d (Hz)\n", __FUNCTION__, params->frequency); 630 dprintk(1, "%s() frequency=%d (Hz)\n", __func__, params->frequency);
631 631
632 switch(params->u.vsb.modulation) { 632 switch(params->u.vsb.modulation) {
633 case VSB_8: 633 case VSB_8:
634 case VSB_16: 634 case VSB_16:
635 dprintk(1, "%s() VSB modulation\n", __FUNCTION__); 635 dprintk(1, "%s() VSB modulation\n", __func__);
636 priv->rf_mode = XC_RF_MODE_AIR; 636 priv->rf_mode = XC_RF_MODE_AIR;
637 priv->freq_hz = params->frequency - 1750000; 637 priv->freq_hz = params->frequency - 1750000;
638 priv->bandwidth = BANDWIDTH_6_MHZ; 638 priv->bandwidth = BANDWIDTH_6_MHZ;
@@ -641,7 +641,7 @@ static int xc5000_set_params(struct dvb_frontend *fe,
641 case QAM_64: 641 case QAM_64:
642 case QAM_256: 642 case QAM_256:
643 case QAM_AUTO: 643 case QAM_AUTO:
644 dprintk(1, "%s() QAM modulation\n", __FUNCTION__); 644 dprintk(1, "%s() QAM modulation\n", __func__);
645 priv->rf_mode = XC_RF_MODE_CABLE; 645 priv->rf_mode = XC_RF_MODE_CABLE;
646 priv->freq_hz = params->frequency - 1750000; 646 priv->freq_hz = params->frequency - 1750000;
647 priv->bandwidth = BANDWIDTH_6_MHZ; 647 priv->bandwidth = BANDWIDTH_6_MHZ;
@@ -652,7 +652,7 @@ static int xc5000_set_params(struct dvb_frontend *fe,
652 } 652 }
653 653
654 dprintk(1, "%s() frequency=%d (compensated)\n", 654 dprintk(1, "%s() frequency=%d (compensated)\n",
655 __FUNCTION__, priv->freq_hz); 655 __func__, priv->freq_hz);
656 656
657 ret = xc_SetSignalSource(priv, priv->rf_mode); 657 ret = xc_SetSignalSource(priv, priv->rf_mode);
658 if (ret != XC_RESULT_SUCCESS) { 658 if (ret != XC_RESULT_SUCCESS) {
@@ -697,7 +697,7 @@ static int xc5000_set_analog_params(struct dvb_frontend *fe,
697 xc_load_fw_and_init_tuner(fe); 697 xc_load_fw_and_init_tuner(fe);
698 698
699 dprintk(1, "%s() frequency=%d (in units of 62.5khz)\n", 699 dprintk(1, "%s() frequency=%d (in units of 62.5khz)\n",
700 __FUNCTION__, params->frequency); 700 __func__, params->frequency);
701 701
702 priv->rf_mode = XC_RF_MODE_CABLE; /* Fix me: it could be air. */ 702 priv->rf_mode = XC_RF_MODE_CABLE; /* Fix me: it could be air. */
703 703
@@ -775,7 +775,7 @@ tune_channel:
775static int xc5000_get_frequency(struct dvb_frontend *fe, u32 *freq) 775static int xc5000_get_frequency(struct dvb_frontend *fe, u32 *freq)
776{ 776{
777 struct xc5000_priv *priv = fe->tuner_priv; 777 struct xc5000_priv *priv = fe->tuner_priv;
778 dprintk(1, "%s()\n", __FUNCTION__); 778 dprintk(1, "%s()\n", __func__);
779 *freq = priv->freq_hz; 779 *freq = priv->freq_hz;
780 return 0; 780 return 0;
781} 781}
@@ -783,7 +783,7 @@ static int xc5000_get_frequency(struct dvb_frontend *fe, u32 *freq)
783static int xc5000_get_bandwidth(struct dvb_frontend *fe, u32 *bw) 783static int xc5000_get_bandwidth(struct dvb_frontend *fe, u32 *bw)
784{ 784{
785 struct xc5000_priv *priv = fe->tuner_priv; 785 struct xc5000_priv *priv = fe->tuner_priv;
786 dprintk(1, "%s()\n", __FUNCTION__); 786 dprintk(1, "%s()\n", __func__);
787 787
788 *bw = priv->bandwidth; 788 *bw = priv->bandwidth;
789 return 0; 789 return 0;
@@ -796,7 +796,7 @@ static int xc5000_get_status(struct dvb_frontend *fe, u32 *status)
796 796
797 xc_get_lock_status(priv, &lock_status); 797 xc_get_lock_status(priv, &lock_status);
798 798
799 dprintk(1, "%s() lock_status = 0x%08x\n", __FUNCTION__, lock_status); 799 dprintk(1, "%s() lock_status = 0x%08x\n", __func__, lock_status);
800 800
801 *status = lock_status; 801 *status = lock_status;
802 802
@@ -836,7 +836,7 @@ static int xc5000_sleep(struct dvb_frontend *fe)
836 struct xc5000_priv *priv = fe->tuner_priv; 836 struct xc5000_priv *priv = fe->tuner_priv;
837 int ret; 837 int ret;
838 838
839 dprintk(1, "%s()\n", __FUNCTION__); 839 dprintk(1, "%s()\n", __func__);
840 840
841 /* On Pinnacle PCTV HD 800i, the tuner cannot be reinitialized 841 /* On Pinnacle PCTV HD 800i, the tuner cannot be reinitialized
842 * once shutdown without reloading the driver. Maybe I am not 842 * once shutdown without reloading the driver. Maybe I am not
@@ -848,7 +848,7 @@ static int xc5000_sleep(struct dvb_frontend *fe)
848 if(ret != XC_RESULT_SUCCESS) { 848 if(ret != XC_RESULT_SUCCESS) {
849 printk(KERN_ERR 849 printk(KERN_ERR
850 "xc5000: %s() unable to shutdown tuner\n", 850 "xc5000: %s() unable to shutdown tuner\n",
851 __FUNCTION__); 851 __func__);
852 return -EREMOTEIO; 852 return -EREMOTEIO;
853 } 853 }
854 else { 854 else {
@@ -860,7 +860,7 @@ static int xc5000_sleep(struct dvb_frontend *fe)
860static int xc5000_init(struct dvb_frontend *fe) 860static int xc5000_init(struct dvb_frontend *fe)
861{ 861{
862 struct xc5000_priv *priv = fe->tuner_priv; 862 struct xc5000_priv *priv = fe->tuner_priv;
863 dprintk(1, "%s()\n", __FUNCTION__); 863 dprintk(1, "%s()\n", __func__);
864 864
865 if (xc_load_fw_and_init_tuner(fe) != XC_RESULT_SUCCESS) { 865 if (xc_load_fw_and_init_tuner(fe) != XC_RESULT_SUCCESS) {
866 printk(KERN_ERR "xc5000: Unable to initialise tuner\n"); 866 printk(KERN_ERR "xc5000: Unable to initialise tuner\n");
@@ -875,7 +875,7 @@ static int xc5000_init(struct dvb_frontend *fe)
875 875
876static int xc5000_release(struct dvb_frontend *fe) 876static int xc5000_release(struct dvb_frontend *fe)
877{ 877{
878 dprintk(1, "%s()\n", __FUNCTION__); 878 dprintk(1, "%s()\n", __func__);
879 kfree(fe->tuner_priv); 879 kfree(fe->tuner_priv);
880 fe->tuner_priv = NULL; 880 fe->tuner_priv = NULL;
881 return 0; 881 return 0;
@@ -907,7 +907,7 @@ struct dvb_frontend * xc5000_attach(struct dvb_frontend *fe,
907 struct xc5000_priv *priv = NULL; 907 struct xc5000_priv *priv = NULL;
908 u16 id = 0; 908 u16 id = 0;
909 909
910 dprintk(1, "%s()\n", __FUNCTION__); 910 dprintk(1, "%s()\n", __func__);
911 911
912 priv = kzalloc(sizeof(struct xc5000_priv), GFP_KERNEL); 912 priv = kzalloc(sizeof(struct xc5000_priv), GFP_KERNEL);
913 if (priv == NULL) 913 if (priv == NULL)
diff --git a/drivers/media/dvb/frontends/xc5000.h b/drivers/media/dvb/frontends/xc5000.h
index 32a5f1c86a16..b890883a0cdc 100644
--- a/drivers/media/dvb/frontends/xc5000.h
+++ b/drivers/media/dvb/frontends/xc5000.h
@@ -55,7 +55,7 @@ static inline struct dvb_frontend* xc5000_attach(struct dvb_frontend *fe,
55 struct i2c_adapter *i2c, 55 struct i2c_adapter *i2c,
56 struct xc5000_config *cfg) 56 struct xc5000_config *cfg)
57{ 57{
58 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 58 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
59 return NULL; 59 return NULL;
60} 60}
61#endif // CONFIG_DVB_TUNER_XC5000 61#endif // CONFIG_DVB_TUNER_XC5000
diff --git a/drivers/media/dvb/frontends/zl10353.c b/drivers/media/dvb/frontends/zl10353.c
index 276e3b631dc2..36a5a1c101d5 100644
--- a/drivers/media/dvb/frontends/zl10353.c
+++ b/drivers/media/dvb/frontends/zl10353.c
@@ -46,7 +46,7 @@ static int debug;
46 if (debug) printk(KERN_DEBUG "zl10353: " args); \ 46 if (debug) printk(KERN_DEBUG "zl10353: " args); \
47 } while (0) 47 } while (0)
48 48
49static int debug_regs = 0; 49static int debug_regs;
50 50
51static int zl10353_single_write(struct dvb_frontend *fe, u8 reg, u8 val) 51static int zl10353_single_write(struct dvb_frontend *fe, u8 reg, u8 val)
52{ 52{
@@ -88,7 +88,7 @@ static int zl10353_read_register(struct zl10353_state *state, u8 reg)
88 88
89 if (ret != 2) { 89 if (ret != 2) {
90 printk("%s: readreg error (reg=%d, ret==%i)\n", 90 printk("%s: readreg error (reg=%d, ret==%i)\n",
91 __FUNCTION__, reg, ret); 91 __func__, reg, ret);
92 return ret; 92 return ret;
93 } 93 }
94 94
@@ -152,7 +152,7 @@ static void zl10353_calc_nominal_rate(struct dvb_frontend *fe,
152 *nominal_rate = value; 152 *nominal_rate = value;
153 153
154 dprintk("%s: bw %d, adc_clock %d => 0x%x\n", 154 dprintk("%s: bw %d, adc_clock %d => 0x%x\n",
155 __FUNCTION__, bw, adc_clock, *nominal_rate); 155 __func__, bw, adc_clock, *nominal_rate);
156} 156}
157 157
158static void zl10353_calc_input_freq(struct dvb_frontend *fe, 158static void zl10353_calc_input_freq(struct dvb_frontend *fe,
@@ -181,7 +181,7 @@ static void zl10353_calc_input_freq(struct dvb_frontend *fe,
181 *input_freq = -value; 181 *input_freq = -value;
182 182
183 dprintk("%s: if2 %d, ife %d, adc_clock %d => %d / 0x%x\n", 183 dprintk("%s: if2 %d, ife %d, adc_clock %d => %d / 0x%x\n",
184 __FUNCTION__, if2, ife, adc_clock, -(int)value, *input_freq); 184 __func__, if2, ife, adc_clock, -(int)value, *input_freq);
185} 185}
186 186
187static int zl10353_sleep(struct dvb_frontend *fe) 187static int zl10353_sleep(struct dvb_frontend *fe)
diff --git a/drivers/media/dvb/frontends/zl10353.h b/drivers/media/dvb/frontends/zl10353.h
index fc734c22b5fa..fdbb88ff75fe 100644
--- a/drivers/media/dvb/frontends/zl10353.h
+++ b/drivers/media/dvb/frontends/zl10353.h
@@ -47,7 +47,7 @@ extern struct dvb_frontend* zl10353_attach(const struct zl10353_config *config,
47static inline struct dvb_frontend* zl10353_attach(const struct zl10353_config *config, 47static inline struct dvb_frontend* zl10353_attach(const struct zl10353_config *config,
48 struct i2c_adapter *i2c) 48 struct i2c_adapter *i2c)
49{ 49{
50 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 50 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
51 return NULL; 51 return NULL;
52} 52}
53#endif /* CONFIG_DVB_ZL10353 */ 53#endif /* CONFIG_DVB_ZL10353 */
diff --git a/drivers/media/dvb/pluto2/pluto2.c b/drivers/media/dvb/pluto2/pluto2.c
index 08a2599ed74a..960ed5763ae1 100644
--- a/drivers/media/dvb/pluto2/pluto2.c
+++ b/drivers/media/dvb/pluto2/pluto2.c
@@ -39,6 +39,8 @@
39#include "dvbdev.h" 39#include "dvbdev.h"
40#include "tda1004x.h" 40#include "tda1004x.h"
41 41
42DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
43
42#define DRIVER_NAME "pluto2" 44#define DRIVER_NAME "pluto2"
43 45
44#define REG_PIDn(n) ((n) << 2) /* PID n pattern registers */ 46#define REG_PIDn(n) ((n) << 2) /* PID n pattern registers */
@@ -662,7 +664,8 @@ static int __devinit pluto2_probe(struct pci_dev *pdev,
662 goto err_pluto_hw_exit; 664 goto err_pluto_hw_exit;
663 665
664 /* dvb */ 666 /* dvb */
665 ret = dvb_register_adapter(&pluto->dvb_adapter, DRIVER_NAME, THIS_MODULE, &pdev->dev); 667 ret = dvb_register_adapter(&pluto->dvb_adapter, DRIVER_NAME,
668 THIS_MODULE, &pdev->dev, adapter_nr);
666 if (ret < 0) 669 if (ret < 0)
667 goto err_i2c_del_adapter; 670 goto err_i2c_del_adapter;
668 671
diff --git a/drivers/media/dvb/ttpci/av7110.c b/drivers/media/dvb/ttpci/av7110.c
index 0e5701bdff19..747e7f1a6267 100644
--- a/drivers/media/dvb/ttpci/av7110.c
+++ b/drivers/media/dvb/ttpci/av7110.c
@@ -112,6 +112,8 @@ MODULE_PARM_DESC(wss_cfg_16_9, "WSS 16:9 - default 0x0007 - bit 15: disable, 14:
112module_param(tv_standard, int, 0444); 112module_param(tv_standard, int, 0444);
113MODULE_PARM_DESC(tv_standard, "TV standard: 0 PAL (default), 1 NTSC"); 113MODULE_PARM_DESC(tv_standard, "TV standard: 0 PAL (default), 1 NTSC");
114 114
115DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
116
115static void restart_feeds(struct av7110 *av7110); 117static void restart_feeds(struct av7110 *av7110);
116 118
117static int av7110_num; 119static int av7110_num;
@@ -359,7 +361,7 @@ static inline void start_debi_dma(struct av7110 *av7110, int dir,
359{ 361{
360 dprintk(8, "%c %08lx %u\n", dir == DEBI_READ ? 'R' : 'W', addr, len); 362 dprintk(8, "%c %08lx %u\n", dir == DEBI_READ ? 'R' : 'W', addr, len);
361 if (saa7146_wait_for_debi_done(av7110->dev, 0)) { 363 if (saa7146_wait_for_debi_done(av7110->dev, 0)) {
362 printk(KERN_ERR "%s: saa7146_wait_for_debi_done timed out\n", __FUNCTION__); 364 printk(KERN_ERR "%s: saa7146_wait_for_debi_done timed out\n", __func__);
363 return; 365 return;
364 } 366 }
365 367
@@ -497,7 +499,7 @@ static void gpioirq(unsigned long data)
497 saa7146_read(av7110->dev, SSR)); 499 saa7146_read(av7110->dev, SSR));
498 500
499 if (saa7146_wait_for_debi_done(av7110->dev, 0)) { 501 if (saa7146_wait_for_debi_done(av7110->dev, 0)) {
500 printk(KERN_ERR "%s: saa7146_wait_for_debi_done timed out\n", __FUNCTION__); 502 printk(KERN_ERR "%s: saa7146_wait_for_debi_done timed out\n", __func__);
501 BUG(); /* maybe we should try resetting the debi? */ 503 BUG(); /* maybe we should try resetting the debi? */
502 } 504 }
503 505
@@ -827,7 +829,7 @@ static int StartHWFilter(struct dvb_demux_filter *dvbdmxfilter)
827 if (ret != 0 || handle >= 32) { 829 if (ret != 0 || handle >= 32) {
828 printk("dvb-ttpci: %s error buf %04x %04x %04x %04x " 830 printk("dvb-ttpci: %s error buf %04x %04x %04x %04x "
829 "ret %d handle %04x\n", 831 "ret %d handle %04x\n",
830 __FUNCTION__, buf[0], buf[1], buf[2], buf[3], 832 __func__, buf[0], buf[1], buf[2], buf[3],
831 ret, handle); 833 ret, handle);
832 dvbdmxfilter->hw_handle = 0xffff; 834 dvbdmxfilter->hw_handle = 0xffff;
833 if (!ret) 835 if (!ret)
@@ -854,7 +856,7 @@ static int StopHWFilter(struct dvb_demux_filter *dvbdmxfilter)
854 handle = dvbdmxfilter->hw_handle; 856 handle = dvbdmxfilter->hw_handle;
855 if (handle >= 32) { 857 if (handle >= 32) {
856 printk("%s tried to stop invalid filter %04x, filter type = %x\n", 858 printk("%s tried to stop invalid filter %04x, filter type = %x\n",
857 __FUNCTION__, handle, dvbdmxfilter->type); 859 __func__, handle, dvbdmxfilter->type);
858 return -EINVAL; 860 return -EINVAL;
859 } 861 }
860 862
@@ -867,7 +869,7 @@ static int StopHWFilter(struct dvb_demux_filter *dvbdmxfilter)
867 if (ret != 0 || answ[1] != handle) { 869 if (ret != 0 || answ[1] != handle) {
868 printk("dvb-ttpci: %s error cmd %04x %04x %04x ret %x " 870 printk("dvb-ttpci: %s error cmd %04x %04x %04x ret %x "
869 "resp %04x %04x pid %d\n", 871 "resp %04x %04x pid %d\n",
870 __FUNCTION__, buf[0], buf[1], buf[2], ret, 872 __func__, buf[0], buf[1], buf[2], ret,
871 answ[0], answ[1], dvbdmxfilter->feed->pid); 873 answ[0], answ[1], dvbdmxfilter->feed->pid);
872 if (!ret) 874 if (!ret)
873 ret = -1; 875 ret = -1;
@@ -1122,7 +1124,7 @@ static int dvb_get_stc(struct dmx_demux *demux, unsigned int num,
1122 1124
1123 ret = av7110_fw_request(av7110, &tag, 0, fwstc, 4); 1125 ret = av7110_fw_request(av7110, &tag, 0, fwstc, 4);
1124 if (ret) { 1126 if (ret) {
1125 printk(KERN_ERR "%s: av7110_fw_request error\n", __FUNCTION__); 1127 printk(KERN_ERR "%s: av7110_fw_request error\n", __func__);
1126 return ret; 1128 return ret;
1127 } 1129 }
1128 dprintk(2, "fwstc = %04hx %04hx %04hx %04hx\n", 1130 dprintk(2, "fwstc = %04hx %04hx %04hx %04hx\n",
@@ -2461,7 +2463,7 @@ static int __devinit av7110_attach(struct saa7146_dev* dev,
2461 goto err_kfree_0; 2463 goto err_kfree_0;
2462 2464
2463 ret = dvb_register_adapter(&av7110->dvb_adapter, av7110->card_name, 2465 ret = dvb_register_adapter(&av7110->dvb_adapter, av7110->card_name,
2464 THIS_MODULE, &dev->pci->dev); 2466 THIS_MODULE, &dev->pci->dev, adapter_nr);
2465 if (ret < 0) 2467 if (ret < 0)
2466 goto err_put_firmware_1; 2468 goto err_put_firmware_1;
2467 2469
diff --git a/drivers/media/dvb/ttpci/av7110.h b/drivers/media/dvb/ttpci/av7110.h
index 39fbf7d5cffb..e494e04eeee8 100644
--- a/drivers/media/dvb/ttpci/av7110.h
+++ b/drivers/media/dvb/ttpci/av7110.h
@@ -40,7 +40,7 @@
40extern int av7110_debug; 40extern int av7110_debug;
41 41
42#define dprintk(level,args...) \ 42#define dprintk(level,args...) \
43 do { if ((av7110_debug & level)) { printk("dvb-ttpci: %s(): ", __FUNCTION__); printk(args); } } while (0) 43 do { if ((av7110_debug & level)) { printk("dvb-ttpci: %s(): ", __func__); printk(args); } } while (0)
44 44
45#define MAXFILT 32 45#define MAXFILT 32
46 46
diff --git a/drivers/media/dvb/ttpci/av7110_hw.c b/drivers/media/dvb/ttpci/av7110_hw.c
index a468aa2e4854..9d81074b31df 100644
--- a/drivers/media/dvb/ttpci/av7110_hw.c
+++ b/drivers/media/dvb/ttpci/av7110_hw.c
@@ -53,11 +53,11 @@ int av7110_debiwrite(struct av7110 *av7110, u32 config,
53 struct saa7146_dev *dev = av7110->dev; 53 struct saa7146_dev *dev = av7110->dev;
54 54
55 if (count <= 0 || count > 32764) { 55 if (count <= 0 || count > 32764) {
56 printk("%s: invalid count %d\n", __FUNCTION__, count); 56 printk("%s: invalid count %d\n", __func__, count);
57 return -1; 57 return -1;
58 } 58 }
59 if (saa7146_wait_for_debi_done(av7110->dev, 0) < 0) { 59 if (saa7146_wait_for_debi_done(av7110->dev, 0) < 0) {
60 printk("%s: wait_for_debi_done failed\n", __FUNCTION__); 60 printk("%s: wait_for_debi_done failed\n", __func__);
61 return -1; 61 return -1;
62 } 62 }
63 saa7146_write(dev, DEBI_CONFIG, config); 63 saa7146_write(dev, DEBI_CONFIG, config);
@@ -76,11 +76,11 @@ u32 av7110_debiread(struct av7110 *av7110, u32 config, int addr, int count)
76 u32 result = 0; 76 u32 result = 0;
77 77
78 if (count > 32764 || count <= 0) { 78 if (count > 32764 || count <= 0) {
79 printk("%s: invalid count %d\n", __FUNCTION__, count); 79 printk("%s: invalid count %d\n", __func__, count);
80 return 0; 80 return 0;
81 } 81 }
82 if (saa7146_wait_for_debi_done(av7110->dev, 0) < 0) { 82 if (saa7146_wait_for_debi_done(av7110->dev, 0) < 0) {
83 printk("%s: wait_for_debi_done #1 failed\n", __FUNCTION__); 83 printk("%s: wait_for_debi_done #1 failed\n", __func__);
84 return 0; 84 return 0;
85 } 85 }
86 saa7146_write(dev, DEBI_AD, av7110->debi_bus); 86 saa7146_write(dev, DEBI_AD, av7110->debi_bus);
@@ -91,7 +91,7 @@ u32 av7110_debiread(struct av7110 *av7110, u32 config, int addr, int count)
91 if (count > 4) 91 if (count > 4)
92 return count; 92 return count;
93 if (saa7146_wait_for_debi_done(av7110->dev, 0) < 0) { 93 if (saa7146_wait_for_debi_done(av7110->dev, 0) < 0) {
94 printk("%s: wait_for_debi_done #2 failed\n", __FUNCTION__); 94 printk("%s: wait_for_debi_done #2 failed\n", __func__);
95 return 0; 95 return 0;
96 } 96 }
97 97
@@ -332,7 +332,7 @@ int av7110_wait_msgstate(struct av7110 *av7110, u16 flags)
332 break; 332 break;
333 if (err) { 333 if (err) {
334 printk(KERN_ERR "%s: timeout waiting for MSGSTATE %04x\n", 334 printk(KERN_ERR "%s: timeout waiting for MSGSTATE %04x\n",
335 __FUNCTION__, stat & flags); 335 __func__, stat & flags);
336 return -ETIMEDOUT; 336 return -ETIMEDOUT;
337 } 337 }
338 msleep(1); 338 msleep(1);
@@ -362,7 +362,7 @@ static int __av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
362 if (rdebi(av7110, DEBINOSWAP, COMMAND, 0, 2) == 0) 362 if (rdebi(av7110, DEBINOSWAP, COMMAND, 0, 2) == 0)
363 break; 363 break;
364 if (err) { 364 if (err) {
365 printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for COMMAND idle\n", __FUNCTION__); 365 printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for COMMAND idle\n", __func__);
366 av7110->arm_errors++; 366 av7110->arm_errors++;
367 return -ETIMEDOUT; 367 return -ETIMEDOUT;
368 } 368 }
@@ -379,7 +379,7 @@ static int __av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
379 if (rdebi(av7110, DEBINOSWAP, HANDSHAKE_REG, 0, 2) == 0) 379 if (rdebi(av7110, DEBINOSWAP, HANDSHAKE_REG, 0, 2) == 0)
380 break; 380 break;
381 if (err) { 381 if (err) {
382 printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for HANDSHAKE_REG\n", __FUNCTION__); 382 printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for HANDSHAKE_REG\n", __func__);
383 return -ETIMEDOUT; 383 return -ETIMEDOUT;
384 } 384 }
385 msleep(1); 385 msleep(1);
@@ -419,14 +419,14 @@ static int __av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
419 stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2); 419 stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2);
420 if (stat & flags[0]) { 420 if (stat & flags[0]) {
421 printk(KERN_ERR "%s: %s QUEUE overflow\n", 421 printk(KERN_ERR "%s: %s QUEUE overflow\n",
422 __FUNCTION__, type); 422 __func__, type);
423 return -1; 423 return -1;
424 } 424 }
425 if ((stat & flags[1]) == 0) 425 if ((stat & flags[1]) == 0)
426 break; 426 break;
427 if (err) { 427 if (err) {
428 printk(KERN_ERR "%s: timeout waiting on busy %s QUEUE\n", 428 printk(KERN_ERR "%s: timeout waiting on busy %s QUEUE\n",
429 __FUNCTION__, type); 429 __func__, type);
430 return -ETIMEDOUT; 430 return -ETIMEDOUT;
431 } 431 }
432 msleep(1); 432 msleep(1);
@@ -454,7 +454,7 @@ static int __av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
454 break; 454 break;
455 if (err) { 455 if (err) {
456 printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for COMMAND %d to complete\n", 456 printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for COMMAND %d to complete\n",
457 __FUNCTION__, (buf[0] >> 8) & 0xff); 457 __func__, (buf[0] >> 8) & 0xff);
458 return -ETIMEDOUT; 458 return -ETIMEDOUT;
459 } 459 }
460 msleep(1); 460 msleep(1);
@@ -462,11 +462,11 @@ static int __av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
462 462
463 stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2); 463 stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2);
464 if (stat & GPMQOver) { 464 if (stat & GPMQOver) {
465 printk(KERN_ERR "dvb-ttpci: %s(): GPMQOver\n", __FUNCTION__); 465 printk(KERN_ERR "dvb-ttpci: %s(): GPMQOver\n", __func__);
466 return -ENOSPC; 466 return -ENOSPC;
467 } 467 }
468 else if (stat & OSDQOver) { 468 else if (stat & OSDQOver) {
469 printk(KERN_ERR "dvb-ttpci: %s(): OSDQOver\n", __FUNCTION__); 469 printk(KERN_ERR "dvb-ttpci: %s(): OSDQOver\n", __func__);
470 return -ENOSPC; 470 return -ENOSPC;
471 } 471 }
472#endif 472#endif
@@ -491,7 +491,7 @@ static int av7110_send_fw_cmd(struct av7110 *av7110, u16* buf, int length)
491 mutex_unlock(&av7110->dcomlock); 491 mutex_unlock(&av7110->dcomlock);
492 if (ret && ret!=-ERESTARTSYS) 492 if (ret && ret!=-ERESTARTSYS)
493 printk(KERN_ERR "dvb-ttpci: %s(): av7110_send_fw_cmd error %d\n", 493 printk(KERN_ERR "dvb-ttpci: %s(): av7110_send_fw_cmd error %d\n",
494 __FUNCTION__, ret); 494 __func__, ret);
495 return ret; 495 return ret;
496} 496}
497 497
@@ -575,7 +575,7 @@ int av7110_fw_request(struct av7110 *av7110, u16 *request_buf,
575 if (rdebi(av7110, DEBINOSWAP, COMMAND, 0, 2) == 0) 575 if (rdebi(av7110, DEBINOSWAP, COMMAND, 0, 2) == 0)
576 break; 576 break;
577 if (err) { 577 if (err) {
578 printk(KERN_ERR "%s: timeout waiting for COMMAND to complete\n", __FUNCTION__); 578 printk(KERN_ERR "%s: timeout waiting for COMMAND to complete\n", __func__);
579 mutex_unlock(&av7110->dcomlock); 579 mutex_unlock(&av7110->dcomlock);
580 return -ETIMEDOUT; 580 return -ETIMEDOUT;
581 } 581 }
@@ -591,7 +591,7 @@ int av7110_fw_request(struct av7110 *av7110, u16 *request_buf,
591 if (rdebi(av7110, DEBINOSWAP, HANDSHAKE_REG, 0, 2) == 0) 591 if (rdebi(av7110, DEBINOSWAP, HANDSHAKE_REG, 0, 2) == 0)
592 break; 592 break;
593 if (err) { 593 if (err) {
594 printk(KERN_ERR "%s: timeout waiting for HANDSHAKE_REG\n", __FUNCTION__); 594 printk(KERN_ERR "%s: timeout waiting for HANDSHAKE_REG\n", __func__);
595 mutex_unlock(&av7110->dcomlock); 595 mutex_unlock(&av7110->dcomlock);
596 return -ETIMEDOUT; 596 return -ETIMEDOUT;
597 } 597 }
@@ -602,12 +602,12 @@ int av7110_fw_request(struct av7110 *av7110, u16 *request_buf,
602#ifdef COM_DEBUG 602#ifdef COM_DEBUG
603 stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2); 603 stat = rdebi(av7110, DEBINOSWAP, MSGSTATE, 0, 2);
604 if (stat & GPMQOver) { 604 if (stat & GPMQOver) {
605 printk(KERN_ERR "%s: GPMQOver\n", __FUNCTION__); 605 printk(KERN_ERR "%s: GPMQOver\n", __func__);
606 mutex_unlock(&av7110->dcomlock); 606 mutex_unlock(&av7110->dcomlock);
607 return -1; 607 return -1;
608 } 608 }
609 else if (stat & OSDQOver) { 609 else if (stat & OSDQOver) {
610 printk(KERN_ERR "%s: OSDQOver\n", __FUNCTION__); 610 printk(KERN_ERR "%s: OSDQOver\n", __func__);
611 mutex_unlock(&av7110->dcomlock); 611 mutex_unlock(&av7110->dcomlock);
612 return -1; 612 return -1;
613 } 613 }
@@ -741,7 +741,7 @@ static int FlushText(struct av7110 *av7110)
741 break; 741 break;
742 if (err) { 742 if (err) {
743 printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for BUFF1_BASE == 0\n", 743 printk(KERN_ERR "dvb-ttpci: %s(): timeout waiting for BUFF1_BASE == 0\n",
744 __FUNCTION__); 744 __func__);
745 mutex_unlock(&av7110->dcomlock); 745 mutex_unlock(&av7110->dcomlock);
746 return -ETIMEDOUT; 746 return -ETIMEDOUT;
747 } 747 }
@@ -768,7 +768,7 @@ static int WriteText(struct av7110 *av7110, u8 win, u16 x, u16 y, char *buf)
768 break; 768 break;
769 if (ret) { 769 if (ret) {
770 printk(KERN_ERR "dvb-ttpci: %s: timeout waiting for BUFF1_BASE == 0\n", 770 printk(KERN_ERR "dvb-ttpci: %s: timeout waiting for BUFF1_BASE == 0\n",
771 __FUNCTION__); 771 __func__);
772 mutex_unlock(&av7110->dcomlock); 772 mutex_unlock(&av7110->dcomlock);
773 return -ETIMEDOUT; 773 return -ETIMEDOUT;
774 } 774 }
@@ -782,7 +782,7 @@ static int WriteText(struct av7110 *av7110, u8 win, u16 x, u16 y, char *buf)
782 break; 782 break;
783 if (ret) { 783 if (ret) {
784 printk(KERN_ERR "dvb-ttpci: %s: timeout waiting for HANDSHAKE_REG\n", 784 printk(KERN_ERR "dvb-ttpci: %s: timeout waiting for HANDSHAKE_REG\n",
785 __FUNCTION__); 785 __func__);
786 mutex_unlock(&av7110->dcomlock); 786 mutex_unlock(&av7110->dcomlock);
787 return -ETIMEDOUT; 787 return -ETIMEDOUT;
788 } 788 }
diff --git a/drivers/media/dvb/ttpci/av7110_ir.c b/drivers/media/dvb/ttpci/av7110_ir.c
index a283e1de83fa..23a1c6380d3f 100644
--- a/drivers/media/dvb/ttpci/av7110_ir.c
+++ b/drivers/media/dvb/ttpci/av7110_ir.c
@@ -133,7 +133,7 @@ static void av7110_emit_key(unsigned long parm)
133 break; 133 break;
134 134
135 default: 135 default:
136 printk("%s invalid protocol %x\n", __FUNCTION__, ir->protocol); 136 printk("%s invalid protocol %x\n", __func__, ir->protocol);
137 return; 137 return;
138 } 138 }
139 139
@@ -143,7 +143,7 @@ static void av7110_emit_key(unsigned long parm)
143 keycode = ir->key_map[data]; 143 keycode = ir->key_map[data];
144 144
145 dprintk(16, "%s: code %08x -> addr %i data 0x%02x -> keycode %i\n", 145 dprintk(16, "%s: code %08x -> addr %i data 0x%02x -> keycode %i\n",
146 __FUNCTION__, ircom, addr, data, keycode); 146 __func__, ircom, addr, data, keycode);
147 147
148 /* check device address */ 148 /* check device address */
149 if (!(ir->device_mask & (1 << addr))) 149 if (!(ir->device_mask & (1 << addr)))
@@ -151,7 +151,7 @@ static void av7110_emit_key(unsigned long parm)
151 151
152 if (!keycode) { 152 if (!keycode) {
153 printk ("%s: code %08x -> addr %i data 0x%02x -> unknown key!\n", 153 printk ("%s: code %08x -> addr %i data 0x%02x -> unknown key!\n",
154 __FUNCTION__, ircom, addr, data); 154 __func__, ircom, addr, data);
155 return; 155 return;
156 } 156 }
157 157
diff --git a/drivers/media/dvb/ttpci/av7110_v4l.c b/drivers/media/dvb/ttpci/av7110_v4l.c
index e2f066fb7967..b4a0cc5dc935 100644
--- a/drivers/media/dvb/ttpci/av7110_v4l.c
+++ b/drivers/media/dvb/ttpci/av7110_v4l.c
@@ -573,7 +573,7 @@ static int av7110_vbi_reset(struct inode *inode, struct file *file)
573 struct saa7146_dev *dev = fh->dev; 573 struct saa7146_dev *dev = fh->dev;
574 struct av7110 *av7110 = (struct av7110*) dev->ext_priv; 574 struct av7110 *av7110 = (struct av7110*) dev->ext_priv;
575 575
576 dprintk(2, "%s\n", __FUNCTION__); 576 dprintk(2, "%s\n", __func__);
577 av7110->wssMode = 0; 577 av7110->wssMode = 0;
578 av7110->wssData = 0; 578 av7110->wssData = 0;
579 if (FW_VERSION(av7110->arm_app) < 0x2623) 579 if (FW_VERSION(av7110->arm_app) < 0x2623)
@@ -590,7 +590,7 @@ static ssize_t av7110_vbi_write(struct file *file, const char __user *data, size
590 struct v4l2_sliced_vbi_data d; 590 struct v4l2_sliced_vbi_data d;
591 int rc; 591 int rc;
592 592
593 dprintk(2, "%s\n", __FUNCTION__); 593 dprintk(2, "%s\n", __func__);
594 if (FW_VERSION(av7110->arm_app) < 0x2623 || !av7110->wssMode || count != sizeof d) 594 if (FW_VERSION(av7110->arm_app) < 0x2623 || !av7110->wssMode || count != sizeof d)
595 return -EINVAL; 595 return -EINVAL;
596 if (copy_from_user(&d, data, count)) 596 if (copy_from_user(&d, data, count))
diff --git a/drivers/media/dvb/ttpci/budget-av.c b/drivers/media/dvb/ttpci/budget-av.c
index 2d64d557b977..b30a5288e484 100644
--- a/drivers/media/dvb/ttpci/budget-av.c
+++ b/drivers/media/dvb/ttpci/budget-av.c
@@ -178,7 +178,7 @@ static int ciintf_read_cam_control(struct dvb_ca_en50221 *ca, int slot, u8 addre
178 udelay(1); 178 udelay(1);
179 179
180 result = ttpci_budget_debiread(&budget_av->budget, DEBICICAM, address & 3, 1, 0, 0); 180 result = ttpci_budget_debiread(&budget_av->budget, DEBICICAM, address & 3, 1, 0, 0);
181 if ((result == -ETIMEDOUT) || ((result == 0xff) && ((address & 3) < 2))) { 181 if (result == -ETIMEDOUT) {
182 ciintf_slot_shutdown(ca, slot); 182 ciintf_slot_shutdown(ca, slot);
183 printk(KERN_INFO "budget-av: cam ejected 3\n"); 183 printk(KERN_INFO "budget-av: cam ejected 3\n");
184 return -ETIMEDOUT; 184 return -ETIMEDOUT;
@@ -577,7 +577,7 @@ static struct stv0299_config typhoon_config = {
577 .mclk = 88000000UL, 577 .mclk = 88000000UL,
578 .invert = 0, 578 .invert = 0,
579 .skip_reinit = 0, 579 .skip_reinit = 0,
580 .lock_output = STV0229_LOCKOUTPUT_1, 580 .lock_output = STV0299_LOCKOUTPUT_1,
581 .volt13_op0_op1 = STV0299_VOLT13_OP0, 581 .volt13_op0_op1 = STV0299_VOLT13_OP0,
582 .min_delay_ms = 100, 582 .min_delay_ms = 100,
583 .set_symbol_rate = philips_su1278_ty_ci_set_symbol_rate, 583 .set_symbol_rate = philips_su1278_ty_ci_set_symbol_rate,
@@ -590,7 +590,7 @@ static struct stv0299_config cinergy_1200s_config = {
590 .mclk = 88000000UL, 590 .mclk = 88000000UL,
591 .invert = 0, 591 .invert = 0,
592 .skip_reinit = 0, 592 .skip_reinit = 0,
593 .lock_output = STV0229_LOCKOUTPUT_0, 593 .lock_output = STV0299_LOCKOUTPUT_0,
594 .volt13_op0_op1 = STV0299_VOLT13_OP0, 594 .volt13_op0_op1 = STV0299_VOLT13_OP0,
595 .min_delay_ms = 100, 595 .min_delay_ms = 100,
596 .set_symbol_rate = philips_su1278_ty_ci_set_symbol_rate, 596 .set_symbol_rate = philips_su1278_ty_ci_set_symbol_rate,
@@ -602,7 +602,7 @@ static struct stv0299_config cinergy_1200s_1894_0010_config = {
602 .mclk = 88000000UL, 602 .mclk = 88000000UL,
603 .invert = 1, 603 .invert = 1,
604 .skip_reinit = 0, 604 .skip_reinit = 0,
605 .lock_output = STV0229_LOCKOUTPUT_1, 605 .lock_output = STV0299_LOCKOUTPUT_1,
606 .volt13_op0_op1 = STV0299_VOLT13_OP0, 606 .volt13_op0_op1 = STV0299_VOLT13_OP0,
607 .min_delay_ms = 100, 607 .min_delay_ms = 100,
608 .set_symbol_rate = philips_su1278_ty_ci_set_symbol_rate, 608 .set_symbol_rate = philips_su1278_ty_ci_set_symbol_rate,
@@ -869,7 +869,7 @@ static struct stv0299_config philips_sd1878_config = {
869 .mclk = 88000000UL, 869 .mclk = 88000000UL,
870 .invert = 0, 870 .invert = 0,
871 .skip_reinit = 0, 871 .skip_reinit = 0,
872 .lock_output = STV0229_LOCKOUTPUT_1, 872 .lock_output = STV0299_LOCKOUTPUT_1,
873 .volt13_op0_op1 = STV0299_VOLT13_OP0, 873 .volt13_op0_op1 = STV0299_VOLT13_OP0,
874 .min_delay_ms = 100, 874 .min_delay_ms = 100,
875 .set_symbol_rate = philips_sd1878_ci_set_symbol_rate, 875 .set_symbol_rate = philips_sd1878_ci_set_symbol_rate,
@@ -941,6 +941,12 @@ static void frontend_init(struct budget_av *budget_av)
941 switch (saa->pci->subsystem_device) { 941 switch (saa->pci->subsystem_device) {
942 942
943 case SUBID_DVBS_KNC1: 943 case SUBID_DVBS_KNC1:
944 /*
945 * maybe that setting is needed for other dvb-s cards as well,
946 * but so far it has been only confirmed for this type
947 */
948 budget_av->reinitialise_demod = 1;
949 /* fall through */
944 case SUBID_DVBS_KNC1_PLUS: 950 case SUBID_DVBS_KNC1_PLUS:
945 case SUBID_DVBS_EASYWATCH_1: 951 case SUBID_DVBS_EASYWATCH_1:
946 if (saa->pci->subsystem_vendor == 0x1894) { 952 if (saa->pci->subsystem_vendor == 0x1894) {
diff --git a/drivers/media/dvb/ttpci/budget-ci.c b/drivers/media/dvb/ttpci/budget-ci.c
index 509349211d4f..6530323d5406 100644
--- a/drivers/media/dvb/ttpci/budget-ci.c
+++ b/drivers/media/dvb/ttpci/budget-ci.c
@@ -86,7 +86,7 @@ static int rc5_device = -1;
86module_param(rc5_device, int, 0644); 86module_param(rc5_device, int, 0644);
87MODULE_PARM_DESC(rc5_device, "only IR commands to given RC5 device (device = 0 - 31, any device = 255, default: autodetect)"); 87MODULE_PARM_DESC(rc5_device, "only IR commands to given RC5 device (device = 0 - 31, any device = 255, default: autodetect)");
88 88
89static int ir_debug = 0; 89static int ir_debug;
90module_param(ir_debug, int, 0644); 90module_param(ir_debug, int, 0644);
91MODULE_PARM_DESC(ir_debug, "enable debugging information for IR decoding"); 91MODULE_PARM_DESC(ir_debug, "enable debugging information for IR decoding");
92 92
@@ -728,7 +728,7 @@ static struct stv0299_config philips_su1278_tt_config = {
728 .mclk = 64000000UL, 728 .mclk = 64000000UL,
729 .invert = 0, 729 .invert = 0,
730 .skip_reinit = 1, 730 .skip_reinit = 1,
731 .lock_output = STV0229_LOCKOUTPUT_1, 731 .lock_output = STV0299_LOCKOUTPUT_1,
732 .volt13_op0_op1 = STV0299_VOLT13_OP1, 732 .volt13_op0_op1 = STV0299_VOLT13_OP1,
733 .min_delay_ms = 50, 733 .min_delay_ms = 50,
734 .set_symbol_rate = philips_su1278_tt_set_symbol_rate, 734 .set_symbol_rate = philips_su1278_tt_set_symbol_rate,
@@ -1121,7 +1121,7 @@ static void frontend_init(struct budget_ci *budget_ci)
1121 1121
1122 budget_ci->budget.dvb_frontend->ops.dishnetwork_send_legacy_command = NULL; 1122 budget_ci->budget.dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
1123 if (dvb_attach(lnbp21_attach, budget_ci->budget.dvb_frontend, &budget_ci->budget.i2c_adap, LNBP21_LLC, 0) == NULL) { 1123 if (dvb_attach(lnbp21_attach, budget_ci->budget.dvb_frontend, &budget_ci->budget.i2c_adap, LNBP21_LLC, 0) == NULL) {
1124 printk("%s: No LNBP21 found!\n", __FUNCTION__); 1124 printk("%s: No LNBP21 found!\n", __func__);
1125 dvb_frontend_detach(budget_ci->budget.dvb_frontend); 1125 dvb_frontend_detach(budget_ci->budget.dvb_frontend);
1126 budget_ci->budget.dvb_frontend = NULL; 1126 budget_ci->budget.dvb_frontend = NULL;
1127 } 1127 }
diff --git a/drivers/media/dvb/ttpci/budget-core.c b/drivers/media/dvb/ttpci/budget-core.c
index 0252081f013c..18cac4b12ab2 100644
--- a/drivers/media/dvb/ttpci/budget-core.c
+++ b/drivers/media/dvb/ttpci/budget-core.c
@@ -57,6 +57,8 @@ module_param_named(bufsize, dma_buffer_size, int, 0444);
57MODULE_PARM_DESC(debug, "Turn on/off budget debugging (default:off)."); 57MODULE_PARM_DESC(debug, "Turn on/off budget debugging (default:off).");
58MODULE_PARM_DESC(bufsize, "DMA buffer size in KB, default: 188, min: 188, max: 1410 (Activy: 564)"); 58MODULE_PARM_DESC(bufsize, "DMA buffer size in KB, default: 188, min: 188, max: 1410 (Activy: 564)");
59 59
60DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
61
60/**************************************************************************** 62/****************************************************************************
61 * TT budget / WinTV Nova 63 * TT budget / WinTV Nova
62 ****************************************************************************/ 64 ****************************************************************************/
@@ -223,7 +225,7 @@ static void vpeirq(unsigned long data)
223 225
224 if (budget->buffer_warnings && time_after(jiffies, budget->buffer_warning_time)) { 226 if (budget->buffer_warnings && time_after(jiffies, budget->buffer_warning_time)) {
225 printk("%s %s: used %d times >80%% of buffer (%u bytes now)\n", 227 printk("%s %s: used %d times >80%% of buffer (%u bytes now)\n",
226 budget->dev->name, __FUNCTION__, budget->buffer_warnings, count); 228 budget->dev->name, __func__, budget->buffer_warnings, count);
227 budget->buffer_warning_time = jiffies + BUFFER_WARNING_WAIT; 229 budget->buffer_warning_time = jiffies + BUFFER_WARNING_WAIT;
228 budget->buffer_warnings = 0; 230 budget->buffer_warnings = 0;
229 } 231 }
@@ -471,9 +473,10 @@ int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
471 budget->buffer_width, budget->buffer_height); 473 budget->buffer_width, budget->buffer_height);
472 printk("%s: dma buffer size %u\n", budget->dev->name, budget->buffer_size); 474 printk("%s: dma buffer size %u\n", budget->dev->name, budget->buffer_size);
473 475
474 if ((ret = dvb_register_adapter(&budget->dvb_adapter, budget->card->name, owner, &budget->dev->pci->dev)) < 0) { 476 ret = dvb_register_adapter(&budget->dvb_adapter, budget->card->name,
477 owner, &budget->dev->pci->dev, adapter_nr);
478 if (ret < 0)
475 return ret; 479 return ret;
476 }
477 480
478 /* set dd1 stream a & b */ 481 /* set dd1 stream a & b */
479 saa7146_write(dev, DD1_STREAM_B, 0x00000000); 482 saa7146_write(dev, DD1_STREAM_B, 0x00000000);
diff --git a/drivers/media/dvb/ttpci/budget.c b/drivers/media/dvb/ttpci/budget.c
index 14b00f57b5de..2293d80c6e51 100644
--- a/drivers/media/dvb/ttpci/budget.c
+++ b/drivers/media/dvb/ttpci/budget.c
@@ -45,6 +45,7 @@
45#include "tda826x.h" 45#include "tda826x.h"
46#include "lnbp21.h" 46#include "lnbp21.h"
47#include "bsru6.h" 47#include "bsru6.h"
48#include "bsbe1.h"
48 49
49static int diseqc_method; 50static int diseqc_method;
50module_param(diseqc_method, int, 0444); 51module_param(diseqc_method, int, 0444);
@@ -257,11 +258,17 @@ static struct ves1820_config alps_tdbe2_config = {
257 258
258static int grundig_29504_401_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) 259static int grundig_29504_401_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
259{ 260{
260 struct budget* budget = (struct budget*) fe->dvb->priv; 261 struct budget *budget = fe->dvb->priv;
262 u8 *tuner_addr = fe->tuner_priv;
261 u32 div; 263 u32 div;
262 u8 cfg, cpump, band_select; 264 u8 cfg, cpump, band_select;
263 u8 data[4]; 265 u8 data[4];
264 struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) }; 266 struct i2c_msg msg = { .flags = 0, .buf = data, .len = sizeof(data) };
267
268 if (tuner_addr)
269 msg.addr = *tuner_addr;
270 else
271 msg.addr = 0x61;
265 272
266 div = (36125000 + params->frequency) / 166666; 273 div = (36125000 + params->frequency) / 166666;
267 274
@@ -292,6 +299,12 @@ static struct l64781_config grundig_29504_401_config = {
292 .demod_address = 0x55, 299 .demod_address = 0x55,
293}; 300};
294 301
302static struct l64781_config grundig_29504_401_config_activy = {
303 .demod_address = 0x54,
304};
305
306static u8 tuner_address_grundig_29504_401_activy = 0x60;
307
295static int grundig_29504_451_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params) 308static int grundig_29504_451_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend_parameters* params)
296{ 309{
297 struct budget* budget = (struct budget*) fe->dvb->priv; 310 struct budget* budget = (struct budget*) fe->dvb->priv;
@@ -346,14 +359,48 @@ static int s5h1420_tuner_set_params(struct dvb_frontend* fe, struct dvb_frontend
346static struct s5h1420_config s5h1420_config = { 359static struct s5h1420_config s5h1420_config = {
347 .demod_address = 0x53, 360 .demod_address = 0x53,
348 .invert = 1, 361 .invert = 1,
362 .cdclk_polarity = 1,
349}; 363};
350 364
351static struct tda10086_config tda10086_config = { 365static struct tda10086_config tda10086_config = {
352 .demod_address = 0x0e, 366 .demod_address = 0x0e,
353 .invert = 0, 367 .invert = 0,
354 .diseqc_tone = 1, 368 .diseqc_tone = 1,
369 .xtal_freq = TDA10086_XTAL_16M,
355}; 370};
356 371
372static struct stv0299_config alps_bsru6_config_activy = {
373 .demod_address = 0x68,
374 .inittab = alps_bsru6_inittab,
375 .mclk = 88000000UL,
376 .invert = 1,
377 .op0_off = 1,
378 .min_delay_ms = 100,
379 .set_symbol_rate = alps_bsru6_set_symbol_rate,
380};
381
382static struct stv0299_config alps_bsbe1_config_activy = {
383 .demod_address = 0x68,
384 .inittab = alps_bsbe1_inittab,
385 .mclk = 88000000UL,
386 .invert = 1,
387 .op0_off = 1,
388 .min_delay_ms = 100,
389 .set_symbol_rate = alps_bsbe1_set_symbol_rate,
390};
391
392
393static int i2c_readreg(struct i2c_adapter *i2c, u8 adr, u8 reg)
394{
395 u8 val;
396 struct i2c_msg msg[] = {
397 { .addr = adr, .flags = 0, .buf = &reg, .len = 1 },
398 { .addr = adr, .flags = I2C_M_RD, .buf = &val, .len = 1 }
399 };
400
401 return (i2c_transfer(i2c, msg, 2) != 2) ? -EIO : val;
402}
403
357static u8 read_pwm(struct budget* budget) 404static u8 read_pwm(struct budget* budget)
358{ 405{
359 u8 b = 0xff; 406 u8 b = 0xff;
@@ -369,6 +416,8 @@ static u8 read_pwm(struct budget* budget)
369 416
370static void frontend_init(struct budget *budget) 417static void frontend_init(struct budget *budget)
371{ 418{
419 (void)alps_bsbe1_config; /* avoid warning */
420
372 switch(budget->dev->pci->subsystem_device) { 421 switch(budget->dev->pci->subsystem_device) {
373 case 0x1003: // Hauppauge/TT Nova budget (stv0299/ALPS BSRU6(tsa5059) OR ves1893/ALPS BSRV2(sp5659)) 422 case 0x1003: // Hauppauge/TT Nova budget (stv0299/ALPS BSRU6(tsa5059) OR ves1893/ALPS BSRV2(sp5659))
374 case 0x1013: 423 case 0x1013:
@@ -414,15 +463,43 @@ static void frontend_init(struct budget *budget)
414 } 463 }
415 break; 464 break;
416 465
417 case 0x4f60: // Fujitsu Siemens Activy Budget-S PCI rev AL (stv0299/ALPS BSRU6(tsa5059)) 466 case 0x4f60: /* Fujitsu Siemens Activy Budget-S PCI rev AL (stv0299/tsa5059) */
418 budget->dvb_frontend = dvb_attach(stv0299_attach, &alps_bsru6_config, &budget->i2c_adap); 467 {
419 if (budget->dvb_frontend) { 468 int subtype = i2c_readreg(&budget->i2c_adap, 0x50, 0x67);
420 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params; 469
421 budget->dvb_frontend->tuner_priv = &budget->i2c_adap; 470 if (subtype < 0)
422 budget->dvb_frontend->ops.set_voltage = siemens_budget_set_voltage; 471 break;
423 budget->dvb_frontend->ops.dishnetwork_send_legacy_command = NULL; 472 /* fixme: find a better way to identify the card */
473 if (subtype < 0x36) {
474 /* assume ALPS BSRU6 */
475 budget->dvb_frontend = dvb_attach(stv0299_attach, &alps_bsru6_config_activy, &budget->i2c_adap);
476 if (budget->dvb_frontend) {
477 printk(KERN_INFO "budget: tuner ALPS BSRU6 detected\n");
478 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsru6_tuner_set_params;
479 budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
480 budget->dvb_frontend->ops.set_voltage = siemens_budget_set_voltage;
481 budget->dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
482 break;
483 }
484 } else {
485 /* assume ALPS BSBE1 */
486 /* reset tuner */
487 saa7146_setgpio(budget->dev, 3, SAA7146_GPIO_OUTLO);
488 msleep(50);
489 saa7146_setgpio(budget->dev, 3, SAA7146_GPIO_OUTHI);
490 msleep(250);
491 budget->dvb_frontend = dvb_attach(stv0299_attach, &alps_bsbe1_config_activy, &budget->i2c_adap);
492 if (budget->dvb_frontend) {
493 printk(KERN_INFO "budget: tuner ALPS BSBE1 detected\n");
494 budget->dvb_frontend->ops.tuner_ops.set_params = alps_bsbe1_tuner_set_params;
495 budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
496 budget->dvb_frontend->ops.set_voltage = siemens_budget_set_voltage;
497 budget->dvb_frontend->ops.dishnetwork_send_legacy_command = NULL;
498 break;
499 }
424 } 500 }
425 break; 501 break;
502 }
426 503
427 case 0x4f61: // Fujitsu Siemens Activy Budget-S PCI rev GR (tda8083/Grundig 29504-451(tsa5522)) 504 case 0x4f61: // Fujitsu Siemens Activy Budget-S PCI rev GR (tda8083/Grundig 29504-451(tsa5522))
428 budget->dvb_frontend = dvb_attach(tda8083_attach, &grundig_29504_451_config, &budget->i2c_adap); 505 budget->dvb_frontend = dvb_attach(tda8083_attach, &grundig_29504_451_config, &budget->i2c_adap);
@@ -433,12 +510,20 @@ static void frontend_init(struct budget *budget)
433 } 510 }
434 break; 511 break;
435 512
513 case 0x5f61: /* Fujitsu Siemens Activy Budget-T PCI rev GR (L64781/Grundig 29504-401(tsa5060)) */
514 budget->dvb_frontend = dvb_attach(l64781_attach, &grundig_29504_401_config_activy, &budget->i2c_adap);
515 if (budget->dvb_frontend) {
516 budget->dvb_frontend->tuner_priv = &tuner_address_grundig_29504_401_activy;
517 budget->dvb_frontend->ops.tuner_ops.set_params = grundig_29504_401_tuner_set_params;
518 }
519 break;
520
436 case 0x1016: // Hauppauge/TT Nova-S SE (samsung s5h1420/????(tda8260)) 521 case 0x1016: // Hauppauge/TT Nova-S SE (samsung s5h1420/????(tda8260))
437 budget->dvb_frontend = dvb_attach(s5h1420_attach, &s5h1420_config, &budget->i2c_adap); 522 budget->dvb_frontend = dvb_attach(s5h1420_attach, &s5h1420_config, &budget->i2c_adap);
438 if (budget->dvb_frontend) { 523 if (budget->dvb_frontend) {
439 budget->dvb_frontend->ops.tuner_ops.set_params = s5h1420_tuner_set_params; 524 budget->dvb_frontend->ops.tuner_ops.set_params = s5h1420_tuner_set_params;
440 if (dvb_attach(lnbp21_attach, budget->dvb_frontend, &budget->i2c_adap, 0, 0) == NULL) { 525 if (dvb_attach(lnbp21_attach, budget->dvb_frontend, &budget->i2c_adap, 0, 0) == NULL) {
441 printk("%s: No LNBP21 found!\n", __FUNCTION__); 526 printk("%s: No LNBP21 found!\n", __func__);
442 goto error_out; 527 goto error_out;
443 } 528 }
444 break; 529 break;
@@ -454,9 +539,9 @@ static void frontend_init(struct budget *budget)
454 budget->dvb_frontend = dvb_attach(tda10086_attach, &tda10086_config, &budget->i2c_adap); 539 budget->dvb_frontend = dvb_attach(tda10086_attach, &tda10086_config, &budget->i2c_adap);
455 if (budget->dvb_frontend) { 540 if (budget->dvb_frontend) {
456 if (dvb_attach(tda826x_attach, budget->dvb_frontend, 0x60, &budget->i2c_adap, 0) == NULL) 541 if (dvb_attach(tda826x_attach, budget->dvb_frontend, 0x60, &budget->i2c_adap, 0) == NULL)
457 printk("%s: No tda826x found!\n", __FUNCTION__); 542 printk("%s: No tda826x found!\n", __func__);
458 if (dvb_attach(lnbp21_attach, budget->dvb_frontend, &budget->i2c_adap, 0, 0) == NULL) { 543 if (dvb_attach(lnbp21_attach, budget->dvb_frontend, &budget->i2c_adap, 0, 0) == NULL) {
459 printk("%s: No LNBP21 found!\n", __FUNCTION__); 544 printk("%s: No LNBP21 found!\n", __func__);
460 goto error_out; 545 goto error_out;
461 } 546 }
462 break; 547 break;
@@ -537,6 +622,7 @@ MAKE_BUDGET_INFO(satel, "SATELCO Multimedia PCI", BUDGET_TT_HW_DISEQC);
537MAKE_BUDGET_INFO(ttbs1401, "TT-Budget-S-1401 PCI", BUDGET_TT); 622MAKE_BUDGET_INFO(ttbs1401, "TT-Budget-S-1401 PCI", BUDGET_TT);
538MAKE_BUDGET_INFO(fsacs0, "Fujitsu Siemens Activy Budget-S PCI (rev GR/grundig frontend)", BUDGET_FS_ACTIVY); 623MAKE_BUDGET_INFO(fsacs0, "Fujitsu Siemens Activy Budget-S PCI (rev GR/grundig frontend)", BUDGET_FS_ACTIVY);
539MAKE_BUDGET_INFO(fsacs1, "Fujitsu Siemens Activy Budget-S PCI (rev AL/alps frontend)", BUDGET_FS_ACTIVY); 624MAKE_BUDGET_INFO(fsacs1, "Fujitsu Siemens Activy Budget-S PCI (rev AL/alps frontend)", BUDGET_FS_ACTIVY);
625MAKE_BUDGET_INFO(fsact, "Fujitsu Siemens Activy Budget-T PCI (rev GR/Grundig frontend)", BUDGET_FS_ACTIVY);
540 626
541static struct pci_device_id pci_tbl[] = { 627static struct pci_device_id pci_tbl[] = {
542 MAKE_EXTENSION_PCI(ttbs, 0x13c2, 0x1003), 628 MAKE_EXTENSION_PCI(ttbs, 0x13c2, 0x1003),
@@ -547,6 +633,7 @@ static struct pci_device_id pci_tbl[] = {
547 MAKE_EXTENSION_PCI(ttbs1401, 0x13c2, 0x1018), 633 MAKE_EXTENSION_PCI(ttbs1401, 0x13c2, 0x1018),
548 MAKE_EXTENSION_PCI(fsacs1,0x1131, 0x4f60), 634 MAKE_EXTENSION_PCI(fsacs1,0x1131, 0x4f60),
549 MAKE_EXTENSION_PCI(fsacs0,0x1131, 0x4f61), 635 MAKE_EXTENSION_PCI(fsacs0,0x1131, 0x4f61),
636 MAKE_EXTENSION_PCI(fsact, 0x1131, 0x5f61),
550 { 637 {
551 .vendor = 0, 638 .vendor = 0,
552 } 639 }
diff --git a/drivers/media/dvb/ttpci/budget.h b/drivers/media/dvb/ttpci/budget.h
index d764ffa728b0..dd450b739bff 100644
--- a/drivers/media/dvb/ttpci/budget.h
+++ b/drivers/media/dvb/ttpci/budget.h
@@ -1,3 +1,4 @@
1
1#ifndef __BUDGET_DVB__ 2#ifndef __BUDGET_DVB__
2#define __BUDGET_DVB__ 3#define __BUDGET_DVB__
3 4
@@ -21,7 +22,7 @@ extern int budget_debug;
21#endif 22#endif
22 23
23#define dprintk(level,args...) \ 24#define dprintk(level,args...) \
24 do { if ((budget_debug & level)) { printk("%s: %s(): ", KBUILD_MODNAME, __FUNCTION__); printk(args); } } while (0) 25 do { if ((budget_debug & level)) { printk("%s: %s(): ", KBUILD_MODNAME, __func__); printk(args); } } while (0)
25 26
26struct budget_info { 27struct budget_info {
27 char *name; 28 char *name;
diff --git a/drivers/media/dvb/ttpci/ttpci-eeprom.c b/drivers/media/dvb/ttpci/ttpci-eeprom.c
index 1f31e91195b0..7dd54b3026a2 100644
--- a/drivers/media/dvb/ttpci/ttpci-eeprom.c
+++ b/drivers/media/dvb/ttpci/ttpci-eeprom.c
@@ -95,7 +95,7 @@ static int ttpci_eeprom_read_encodedMAC(struct i2c_adapter *adapter, u8 * encode
95 { .addr = 0x50, .flags = I2C_M_RD, .buf = encodedMAC, .len = 20 } 95 { .addr = 0x50, .flags = I2C_M_RD, .buf = encodedMAC, .len = 20 }
96 }; 96 };
97 97
98 /* dprintk("%s\n", __FUNCTION__); */ 98 /* dprintk("%s\n", __func__); */
99 99
100 ret = i2c_transfer(adapter, msg, 2); 100 ret = i2c_transfer(adapter, msg, 2);
101 101
diff --git a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
index 7902ae1d9a18..732ce4de512e 100644
--- a/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
+++ b/drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
@@ -56,10 +56,11 @@
56*/ 56*/
57 57
58static int debug; 58static int debug;
59
60module_param(debug, int, 0644); 59module_param(debug, int, 0644);
61MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off)."); 60MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
62 61
62DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
63
63#define dprintk(x...) do { if (debug) printk(KERN_DEBUG x); } while (0) 64#define dprintk(x...) do { if (debug) printk(KERN_DEBUG x); } while (0)
64 65
65#define ISO_BUF_COUNT 4 66#define ISO_BUF_COUNT 4
@@ -153,12 +154,12 @@ static int ttusb_cmd(struct ttusb *ttusb,
153 (u8 *) data, len, &actual_len, 1000); 154 (u8 *) data, len, &actual_len, 1000);
154 if (err != 0) { 155 if (err != 0) {
155 dprintk("%s: usb_bulk_msg(send) failed, err == %i!\n", 156 dprintk("%s: usb_bulk_msg(send) failed, err == %i!\n",
156 __FUNCTION__, err); 157 __func__, err);
157 mutex_unlock(&ttusb->semusb); 158 mutex_unlock(&ttusb->semusb);
158 return err; 159 return err;
159 } 160 }
160 if (actual_len != len) { 161 if (actual_len != len) {
161 dprintk("%s: only wrote %d of %d bytes\n", __FUNCTION__, 162 dprintk("%s: only wrote %d of %d bytes\n", __func__,
162 actual_len, len); 163 actual_len, len);
163 mutex_unlock(&ttusb->semusb); 164 mutex_unlock(&ttusb->semusb);
164 return -1; 165 return -1;
@@ -168,7 +169,7 @@ static int ttusb_cmd(struct ttusb *ttusb,
168 ttusb->last_result, 32, &actual_len, 1000); 169 ttusb->last_result, 32, &actual_len, 1000);
169 170
170 if (err != 0) { 171 if (err != 0) {
171 printk("%s: failed, receive error %d\n", __FUNCTION__, 172 printk("%s: failed, receive error %d\n", __func__,
172 err); 173 err);
173 mutex_unlock(&ttusb->semusb); 174 mutex_unlock(&ttusb->semusb);
174 return err; 175 return err;
@@ -229,7 +230,7 @@ static int ttusb_i2c_msg(struct ttusb *ttusb,
229 if (err || b[0] != 0x55 || b[1] != id) { 230 if (err || b[0] != 0x55 || b[1] != id) {
230 dprintk 231 dprintk
231 ("%s: usb_bulk_msg(recv) failed, err == %i, id == %02x, b == ", 232 ("%s: usb_bulk_msg(recv) failed, err == %i, id == %02x, b == ",
232 __FUNCTION__, err, id); 233 __func__, err, id);
233 return -EREMOTEIO; 234 return -EREMOTEIO;
234 } 235 }
235 236
@@ -273,7 +274,7 @@ static int master_xfer(struct i2c_adapter* adapter, struct i2c_msg *msg, int num
273 snd_buf, snd_len, rcv_buf, rcv_len); 274 snd_buf, snd_len, rcv_buf, rcv_len);
274 275
275 if (err < rcv_len) { 276 if (err < rcv_len) {
276 dprintk("%s: i == %i\n", __FUNCTION__, i); 277 dprintk("%s: i == %i\n", __func__, i);
277 break; 278 break;
278 } 279 }
279 280
@@ -327,7 +328,7 @@ static int ttusb_boot_dsp(struct ttusb *ttusb)
327 done: 328 done:
328 if (err) { 329 if (err) {
329 dprintk("%s: usb_bulk_msg() failed, return value %i!\n", 330 dprintk("%s: usb_bulk_msg() failed, return value %i!\n",
330 __FUNCTION__, err); 331 __func__, err);
331 } 332 }
332 333
333 return err; 334 return err;
@@ -427,7 +428,7 @@ static int ttusb_init_controller(struct ttusb *ttusb)
427 if ((err = ttusb_result(ttusb, get_version, sizeof(get_version)))) 428 if ((err = ttusb_result(ttusb, get_version, sizeof(get_version))))
428 return err; 429 return err;
429 430
430 dprintk("%s: stc-version: %c%c%c%c%c\n", __FUNCTION__, 431 dprintk("%s: stc-version: %c%c%c%c%c\n", __func__,
431 get_version[4], get_version[5], get_version[6], 432 get_version[4], get_version[5], get_version[6],
432 get_version[7], get_version[8]); 433 get_version[7], get_version[8]);
433 434
@@ -437,7 +438,7 @@ static int ttusb_init_controller(struct ttusb *ttusb)
437 memcmp(get_version + 4, "V 2.2", 5)) { 438 memcmp(get_version + 4, "V 2.2", 5)) {
438 printk 439 printk
439 ("%s: unknown STC version %c%c%c%c%c, please report!\n", 440 ("%s: unknown STC version %c%c%c%c%c, please report!\n",
440 __FUNCTION__, get_version[4], get_version[5], 441 __func__, get_version[4], get_version[5],
441 get_version[6], get_version[7], get_version[8]); 442 get_version[6], get_version[7], get_version[8]);
442 } 443 }
443 444
@@ -453,7 +454,7 @@ static int ttusb_init_controller(struct ttusb *ttusb)
453 ttusb_result(ttusb, get_dsp_version, sizeof(get_dsp_version)); 454 ttusb_result(ttusb, get_dsp_version, sizeof(get_dsp_version));
454 if (err) 455 if (err)
455 return err; 456 return err;
456 printk("%s: dsp-version: %c%c%c\n", __FUNCTION__, 457 printk("%s: dsp-version: %c%c%c\n", __func__,
457 get_dsp_version[4], get_dsp_version[5], get_dsp_version[6]); 458 get_dsp_version[4], get_dsp_version[5], get_dsp_version[6]);
458 return 0; 459 return 0;
459} 460}
@@ -476,7 +477,7 @@ static int ttusb_send_diseqc(struct dvb_frontend* fe,
476 /* Diseqc */ 477 /* Diseqc */
477 if ((err = ttusb_cmd(ttusb, b, 4 + b[3], 0))) { 478 if ((err = ttusb_cmd(ttusb, b, 4 + b[3], 0))) {
478 dprintk("%s: usb_bulk_msg() failed, return value %i!\n", 479 dprintk("%s: usb_bulk_msg() failed, return value %i!\n",
479 __FUNCTION__, err); 480 __func__, err);
480 } 481 }
481 482
482 return err; 483 return err;
@@ -494,7 +495,7 @@ static int ttusb_update_lnb(struct ttusb *ttusb)
494 /* SetLNB */ 495 /* SetLNB */
495 if ((err = ttusb_cmd(ttusb, b, sizeof(b), 0))) { 496 if ((err = ttusb_cmd(ttusb, b, sizeof(b), 0))) {
496 dprintk("%s: usb_bulk_msg() failed, return value %i!\n", 497 dprintk("%s: usb_bulk_msg() failed, return value %i!\n",
497 __FUNCTION__, err); 498 __func__, err);
498 } 499 }
499 500
500 return err; 501 return err;
@@ -528,7 +529,7 @@ static void ttusb_set_led_freq(struct ttusb *ttusb, u8 freq)
528 err = ttusb_cmd(ttusb, b, sizeof(b), 0); 529 err = ttusb_cmd(ttusb, b, sizeof(b), 0);
529 if (err) { 530 if (err) {
530 dprintk("%s: usb_bulk_msg() failed, return value %i!\n", 531 dprintk("%s: usb_bulk_msg() failed, return value %i!\n",
531 __FUNCTION__, err); 532 __func__, err);
532 } 533 }
533} 534}
534#endif 535#endif
@@ -542,7 +543,7 @@ static void ttusb_handle_sec_data(struct ttusb_channel *channel,
542 const u8 * data, int len); 543 const u8 * data, int len);
543#endif 544#endif
544 545
545static int numpkt = 0, numts, numstuff, numsec, numinvalid; 546static int numpkt, numts, numstuff, numsec, numinvalid;
546static unsigned long lastj; 547static unsigned long lastj;
547 548
548static void ttusb_process_muxpack(struct ttusb *ttusb, const u8 * muxpack, 549static void ttusb_process_muxpack(struct ttusb *ttusb, const u8 * muxpack,
@@ -554,7 +555,7 @@ static void ttusb_process_muxpack(struct ttusb *ttusb, const u8 * muxpack,
554 csum ^= le16_to_cpup((u16 *) (muxpack + i)); 555 csum ^= le16_to_cpup((u16 *) (muxpack + i));
555 if (csum) { 556 if (csum) {
556 printk("%s: muxpack with incorrect checksum, ignoring\n", 557 printk("%s: muxpack with incorrect checksum, ignoring\n",
557 __FUNCTION__); 558 __func__);
558 numinvalid++; 559 numinvalid++;
559 return; 560 return;
560 } 561 }
@@ -563,7 +564,7 @@ static void ttusb_process_muxpack(struct ttusb *ttusb, const u8 * muxpack,
563 cc &= 0x7FFF; 564 cc &= 0x7FFF;
564 if ((cc != ttusb->cc) && (ttusb->cc != -1)) 565 if ((cc != ttusb->cc) && (ttusb->cc != -1))
565 printk("%s: cc discontinuity (%d frames missing)\n", 566 printk("%s: cc discontinuity (%d frames missing)\n",
566 __FUNCTION__, (cc - ttusb->cc) & 0x7FFF); 567 __func__, (cc - ttusb->cc) & 0x7FFF);
567 ttusb->cc = (cc + 1) & 0x7FFF; 568 ttusb->cc = (cc + 1) & 0x7FFF;
568 if (muxpack[0] & 0x80) { 569 if (muxpack[0] & 0x80) {
569#ifdef TTUSB_HWSECTIONS 570#ifdef TTUSB_HWSECTIONS
@@ -613,7 +614,7 @@ static void ttusb_process_frame(struct ttusb *ttusb, u8 * data, int len)
613 int maxwork = 1024; 614 int maxwork = 1024;
614 while (len) { 615 while (len) {
615 if (!(maxwork--)) { 616 if (!(maxwork--)) {
616 printk("%s: too much work\n", __FUNCTION__); 617 printk("%s: too much work\n", __func__);
617 break; 618 break;
618 } 619 }
619 620
@@ -632,7 +633,7 @@ static void ttusb_process_frame(struct ttusb *ttusb, u8 * data, int len)
632#else 633#else
633 if (ttusb->insync) { 634 if (ttusb->insync) {
634 printk("%s: lost sync.\n", 635 printk("%s: lost sync.\n",
635 __FUNCTION__); 636 __func__);
636 ttusb->insync = 0; 637 ttusb->insync = 0;
637 } 638 }
638#endif 639#endif
@@ -691,7 +692,7 @@ static void ttusb_process_frame(struct ttusb *ttusb, u8 * data, int len)
691 else { 692 else {
692 dprintk 693 dprintk
693 ("%s: invalid state: first byte is %x\n", 694 ("%s: invalid state: first byte is %x\n",
694 __FUNCTION__, 695 __func__,
695 ttusb->muxpack[0]); 696 ttusb->muxpack[0]);
696 ttusb->mux_state = 0; 697 ttusb->mux_state = 0;
697 } 698 }
@@ -740,7 +741,7 @@ static void ttusb_iso_irq(struct urb *urb)
740 741
741#if 0 742#if 0
742 printk("%s: status %d, errcount == %d, length == %i\n", 743 printk("%s: status %d, errcount == %d, length == %i\n",
743 __FUNCTION__, 744 __func__,
744 urb->status, urb->error_count, urb->actual_length); 745 urb->status, urb->error_count, urb->actual_length);
745#endif 746#endif
746 747
@@ -833,7 +834,7 @@ static int ttusb_start_iso_xfer(struct ttusb *ttusb)
833 int i, j, err, buffer_offset = 0; 834 int i, j, err, buffer_offset = 0;
834 835
835 if (ttusb->iso_streaming) { 836 if (ttusb->iso_streaming) {
836 printk("%s: iso xfer already running!\n", __FUNCTION__); 837 printk("%s: iso xfer already running!\n", __func__);
837 return 0; 838 return 0;
838 } 839 }
839 840
@@ -869,7 +870,7 @@ static int ttusb_start_iso_xfer(struct ttusb *ttusb)
869 ttusb_stop_iso_xfer(ttusb); 870 ttusb_stop_iso_xfer(ttusb);
870 printk 871 printk
871 ("%s: failed urb submission (%i: err = %i)!\n", 872 ("%s: failed urb submission (%i: err = %i)!\n",
872 __FUNCTION__, i, err); 873 __func__, i, err);
873 return err; 874 return err;
874 } 875 }
875 } 876 }
@@ -1005,7 +1006,7 @@ static int stc_release(struct inode *inode, struct file *file)
1005 return 0; 1006 return 0;
1006} 1007}
1007 1008
1008static struct file_operations stc_fops = { 1009static const struct file_operations stc_fops = {
1009 .owner = THIS_MODULE, 1010 .owner = THIS_MODULE,
1010 .read = stc_read, 1011 .read = stc_read,
1011 .open = stc_open, 1012 .open = stc_open,
@@ -1313,7 +1314,7 @@ static struct stv0299_config alps_stv0299_config = {
1313 .mclk = 88000000UL, 1314 .mclk = 88000000UL,
1314 .invert = 1, 1315 .invert = 1,
1315 .skip_reinit = 0, 1316 .skip_reinit = 0,
1316 .lock_output = STV0229_LOCKOUTPUT_1, 1317 .lock_output = STV0299_LOCKOUTPUT_1,
1317 .volt13_op0_op1 = STV0299_VOLT13_OP1, 1318 .volt13_op0_op1 = STV0299_VOLT13_OP1,
1318 .min_delay_ms = 100, 1319 .min_delay_ms = 100,
1319 .set_symbol_rate = alps_stv0299_set_symbol_rate, 1320 .set_symbol_rate = alps_stv0299_set_symbol_rate,
@@ -1643,7 +1644,7 @@ static int ttusb_probe(struct usb_interface *intf, const struct usb_device_id *i
1643 struct ttusb *ttusb; 1644 struct ttusb *ttusb;
1644 int result; 1645 int result;
1645 1646
1646 dprintk("%s: TTUSB DVB connected\n", __FUNCTION__); 1647 dprintk("%s: TTUSB DVB connected\n", __func__);
1647 1648
1648 udev = interface_to_usbdev(intf); 1649 udev = interface_to_usbdev(intf);
1649 1650
@@ -1669,7 +1670,10 @@ static int ttusb_probe(struct usb_interface *intf, const struct usb_device_id *i
1669 1670
1670 mutex_unlock(&ttusb->semi2c); 1671 mutex_unlock(&ttusb->semi2c);
1671 1672
1672 if ((result = dvb_register_adapter(&ttusb->adapter, "Technotrend/Hauppauge Nova-USB", THIS_MODULE, &udev->dev)) < 0) { 1673 result = dvb_register_adapter(&ttusb->adapter,
1674 "Technotrend/Hauppauge Nova-USB",
1675 THIS_MODULE, &udev->dev, adapter_nr);
1676 if (result < 0) {
1673 ttusb_free_iso_urbs(ttusb); 1677 ttusb_free_iso_urbs(ttusb);
1674 kfree(ttusb); 1678 kfree(ttusb);
1675 return result; 1679 return result;
@@ -1773,7 +1777,7 @@ static void ttusb_disconnect(struct usb_interface *intf)
1773 1777
1774 kfree(ttusb); 1778 kfree(ttusb);
1775 1779
1776 dprintk("%s: TTUSB DVB disconnected\n", __FUNCTION__); 1780 dprintk("%s: TTUSB DVB disconnected\n", __func__);
1777} 1781}
1778 1782
1779static struct usb_device_id ttusb_table[] = { 1783static struct usb_device_id ttusb_table[] = {
diff --git a/drivers/media/dvb/ttusb-dec/ttusb_dec.c b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
index 1ec981d98b91..42eee04daa5d 100644
--- a/drivers/media/dvb/ttusb-dec/ttusb_dec.c
+++ b/drivers/media/dvb/ttusb-dec/ttusb_dec.c
@@ -52,6 +52,8 @@ MODULE_PARM_DESC(output_pva, "Output PVA from dvr device (default:off)");
52module_param(enable_rc, int, 0644); 52module_param(enable_rc, int, 0644);
53MODULE_PARM_DESC(enable_rc, "Turn on/off IR remote control(default: off)"); 53MODULE_PARM_DESC(enable_rc, "Turn on/off IR remote control(default: off)");
54 54
55DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
56
55#define dprintk if (debug) printk 57#define dprintk if (debug) printk
56 58
57#define DRIVER_NAME "TechnoTrend/Hauppauge DEC USB" 59#define DRIVER_NAME "TechnoTrend/Hauppauge DEC USB"
@@ -217,11 +219,11 @@ static void ttusb_dec_handle_irq( struct urb *urb)
217 case -ETIME: 219 case -ETIME:
218 /* this urb is dead, cleanup */ 220 /* this urb is dead, cleanup */
219 dprintk("%s:urb shutting down with status: %d\n", 221 dprintk("%s:urb shutting down with status: %d\n",
220 __FUNCTION__, urb->status); 222 __func__, urb->status);
221 return; 223 return;
222 default: 224 default:
223 dprintk("%s:nonzero status received: %d\n", 225 dprintk("%s:nonzero status received: %d\n",
224 __FUNCTION__,urb->status); 226 __func__,urb->status);
225 goto exit; 227 goto exit;
226 } 228 }
227 229
@@ -235,7 +237,7 @@ static void ttusb_dec_handle_irq( struct urb *urb)
235 * keyrepeat signal is recieved for lets say 200ms. 237 * keyrepeat signal is recieved for lets say 200ms.
236 * this should/could be added later ... 238 * this should/could be added later ...
237 * for now lets report each signal as a key down and up*/ 239 * for now lets report each signal as a key down and up*/
238 dprintk("%s:rc signal:%d\n", __FUNCTION__, buffer[4]); 240 dprintk("%s:rc signal:%d\n", __func__, buffer[4]);
239 input_report_key(dec->rc_input_dev, rc_keys[buffer[4] - 1], 1); 241 input_report_key(dec->rc_input_dev, rc_keys[buffer[4] - 1], 1);
240 input_sync(dec->rc_input_dev); 242 input_sync(dec->rc_input_dev);
241 input_report_key(dec->rc_input_dev, rc_keys[buffer[4] - 1], 0); 243 input_report_key(dec->rc_input_dev, rc_keys[buffer[4] - 1], 0);
@@ -245,7 +247,7 @@ static void ttusb_dec_handle_irq( struct urb *urb)
245exit: retval = usb_submit_urb(urb, GFP_ATOMIC); 247exit: retval = usb_submit_urb(urb, GFP_ATOMIC);
246 if(retval) 248 if(retval)
247 printk("%s - usb_commit_urb failed with result: %d\n", 249 printk("%s - usb_commit_urb failed with result: %d\n",
248 __FUNCTION__, retval); 250 __func__, retval);
249} 251}
250 252
251static u16 crc16(u16 crc, const u8 *buf, size_t len) 253static u16 crc16(u16 crc, const u8 *buf, size_t len)
@@ -268,7 +270,7 @@ static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
268 int result, actual_len, i; 270 int result, actual_len, i;
269 u8 *b; 271 u8 *b;
270 272
271 dprintk("%s\n", __FUNCTION__); 273 dprintk("%s\n", __func__);
272 274
273 b = kmalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL); 275 b = kmalloc(COMMAND_PACKET_SIZE + 4, GFP_KERNEL);
274 if (!b) 276 if (!b)
@@ -276,7 +278,7 @@ static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
276 278
277 if ((result = mutex_lock_interruptible(&dec->usb_mutex))) { 279 if ((result = mutex_lock_interruptible(&dec->usb_mutex))) {
278 kfree(b); 280 kfree(b);
279 printk("%s: Failed to lock usb mutex.\n", __FUNCTION__); 281 printk("%s: Failed to lock usb mutex.\n", __func__);
280 return result; 282 return result;
281 } 283 }
282 284
@@ -289,7 +291,7 @@ static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
289 memcpy(&b[4], params, param_length); 291 memcpy(&b[4], params, param_length);
290 292
291 if (debug) { 293 if (debug) {
292 printk("%s: command: ", __FUNCTION__); 294 printk("%s: command: ", __func__);
293 for (i = 0; i < param_length + 4; i++) 295 for (i = 0; i < param_length + 4; i++)
294 printk("0x%02X ", b[i]); 296 printk("0x%02X ", b[i]);
295 printk("\n"); 297 printk("\n");
@@ -300,7 +302,7 @@ static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
300 302
301 if (result) { 303 if (result) {
302 printk("%s: command bulk message failed: error %d\n", 304 printk("%s: command bulk message failed: error %d\n",
303 __FUNCTION__, result); 305 __func__, result);
304 mutex_unlock(&dec->usb_mutex); 306 mutex_unlock(&dec->usb_mutex);
305 kfree(b); 307 kfree(b);
306 return result; 308 return result;
@@ -311,13 +313,13 @@ static int ttusb_dec_send_command(struct ttusb_dec *dec, const u8 command,
311 313
312 if (result) { 314 if (result) {
313 printk("%s: result bulk message failed: error %d\n", 315 printk("%s: result bulk message failed: error %d\n",
314 __FUNCTION__, result); 316 __func__, result);
315 mutex_unlock(&dec->usb_mutex); 317 mutex_unlock(&dec->usb_mutex);
316 kfree(b); 318 kfree(b);
317 return result; 319 return result;
318 } else { 320 } else {
319 if (debug) { 321 if (debug) {
320 printk("%s: result: ", __FUNCTION__); 322 printk("%s: result: ", __func__);
321 for (i = 0; i < actual_len; i++) 323 for (i = 0; i < actual_len; i++)
322 printk("0x%02X ", b[i]); 324 printk("0x%02X ", b[i]);
323 printk("\n"); 325 printk("\n");
@@ -343,7 +345,7 @@ static int ttusb_dec_get_stb_state (struct ttusb_dec *dec, unsigned int *mode,
343 int result; 345 int result;
344 unsigned int tmp; 346 unsigned int tmp;
345 347
346 dprintk("%s\n", __FUNCTION__); 348 dprintk("%s\n", __func__);
347 349
348 result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c); 350 result = ttusb_dec_send_command(dec, 0x08, 0, NULL, &c_length, c);
349 if (result) 351 if (result)
@@ -400,7 +402,7 @@ static void ttusb_dec_set_pids(struct ttusb_dec *dec)
400 u16 audio = htons(dec->pid[DMX_PES_AUDIO]); 402 u16 audio = htons(dec->pid[DMX_PES_AUDIO]);
401 u16 video = htons(dec->pid[DMX_PES_VIDEO]); 403 u16 video = htons(dec->pid[DMX_PES_VIDEO]);
402 404
403 dprintk("%s\n", __FUNCTION__); 405 dprintk("%s\n", __func__);
404 406
405 memcpy(&b[0], &pcr, 2); 407 memcpy(&b[0], &pcr, 2);
406 memcpy(&b[2], &audio, 2); 408 memcpy(&b[2], &audio, 2);
@@ -419,12 +421,12 @@ static void ttusb_dec_set_pids(struct ttusb_dec *dec)
419static void ttusb_dec_process_pva(struct ttusb_dec *dec, u8 *pva, int length) 421static void ttusb_dec_process_pva(struct ttusb_dec *dec, u8 *pva, int length)
420{ 422{
421 if (length < 8) { 423 if (length < 8) {
422 printk("%s: packet too short - discarding\n", __FUNCTION__); 424 printk("%s: packet too short - discarding\n", __func__);
423 return; 425 return;
424 } 426 }
425 427
426 if (length > 8 + MAX_PVA_LENGTH) { 428 if (length > 8 + MAX_PVA_LENGTH) {
427 printk("%s: packet too long - discarding\n", __FUNCTION__); 429 printk("%s: packet too long - discarding\n", __func__);
428 return; 430 return;
429 } 431 }
430 432
@@ -507,7 +509,7 @@ static void ttusb_dec_process_pva(struct ttusb_dec *dec, u8 *pva, int length)
507 break; 509 break;
508 510
509 default: 511 default:
510 printk("%s: unknown PVA type: %02x.\n", __FUNCTION__, 512 printk("%s: unknown PVA type: %02x.\n", __func__,
511 pva[2]); 513 pva[2]);
512 break; 514 break;
513 } 515 }
@@ -546,7 +548,7 @@ static void ttusb_dec_process_packet(struct ttusb_dec *dec)
546 u16 packet_id; 548 u16 packet_id;
547 549
548 if (dec->packet_length % 2) { 550 if (dec->packet_length % 2) {
549 printk("%s: odd sized packet - discarding\n", __FUNCTION__); 551 printk("%s: odd sized packet - discarding\n", __func__);
550 return; 552 return;
551 } 553 }
552 554
@@ -554,7 +556,7 @@ static void ttusb_dec_process_packet(struct ttusb_dec *dec)
554 csum ^= ((dec->packet[i] << 8) + dec->packet[i + 1]); 556 csum ^= ((dec->packet[i] << 8) + dec->packet[i + 1]);
555 557
556 if (csum) { 558 if (csum) {
557 printk("%s: checksum failed - discarding\n", __FUNCTION__); 559 printk("%s: checksum failed - discarding\n", __func__);
558 return; 560 return;
559 } 561 }
560 562
@@ -563,7 +565,7 @@ static void ttusb_dec_process_packet(struct ttusb_dec *dec)
563 565
564 if ((packet_id != dec->next_packet_id) && dec->next_packet_id) { 566 if ((packet_id != dec->next_packet_id) && dec->next_packet_id) {
565 printk("%s: warning: lost packets between %u and %u\n", 567 printk("%s: warning: lost packets between %u and %u\n",
566 __FUNCTION__, dec->next_packet_id - 1, packet_id); 568 __func__, dec->next_packet_id - 1, packet_id);
567 } 569 }
568 570
569 if (packet_id == 0xffff) 571 if (packet_id == 0xffff)
@@ -652,7 +654,7 @@ static void ttusb_dec_process_urb_frame(struct ttusb_dec *dec, u8 *b,
652 dec->packet_state = 7; 654 dec->packet_state = 7;
653 } else { 655 } else {
654 printk("%s: unknown packet type: " 656 printk("%s: unknown packet type: "
655 "%02x%02x\n", __FUNCTION__, 657 "%02x%02x\n", __func__,
656 dec->packet[0], dec->packet[1]); 658 dec->packet[0], dec->packet[1]);
657 dec->packet_state = 0; 659 dec->packet_state = 0;
658 } 660 }
@@ -724,7 +726,7 @@ static void ttusb_dec_process_urb_frame(struct ttusb_dec *dec, u8 *b,
724 726
725 default: 727 default:
726 printk("%s: illegal packet state encountered.\n", 728 printk("%s: illegal packet state encountered.\n",
727 __FUNCTION__); 729 __func__);
728 dec->packet_state = 0; 730 dec->packet_state = 0;
729 } 731 }
730 } 732 }
@@ -792,7 +794,7 @@ static void ttusb_dec_process_urb(struct urb *urb)
792 } else { 794 } else {
793 /* -ENOENT is expected when unlinking urbs */ 795 /* -ENOENT is expected when unlinking urbs */
794 if (urb->status != -ENOENT) 796 if (urb->status != -ENOENT)
795 dprintk("%s: urb error: %d\n", __FUNCTION__, 797 dprintk("%s: urb error: %d\n", __func__,
796 urb->status); 798 urb->status);
797 } 799 }
798 800
@@ -804,7 +806,7 @@ static void ttusb_dec_setup_urbs(struct ttusb_dec *dec)
804{ 806{
805 int i, j, buffer_offset = 0; 807 int i, j, buffer_offset = 0;
806 808
807 dprintk("%s\n", __FUNCTION__); 809 dprintk("%s\n", __func__);
808 810
809 for (i = 0; i < ISO_BUF_COUNT; i++) { 811 for (i = 0; i < ISO_BUF_COUNT; i++) {
810 int frame_offset = 0; 812 int frame_offset = 0;
@@ -834,7 +836,7 @@ static void ttusb_dec_stop_iso_xfer(struct ttusb_dec *dec)
834{ 836{
835 int i; 837 int i;
836 838
837 dprintk("%s\n", __FUNCTION__); 839 dprintk("%s\n", __func__);
838 840
839 if (mutex_lock_interruptible(&dec->iso_mutex)) 841 if (mutex_lock_interruptible(&dec->iso_mutex))
840 return; 842 return;
@@ -889,7 +891,7 @@ static int ttusb_dec_start_iso_xfer(struct ttusb_dec *dec)
889{ 891{
890 int i, result; 892 int i, result;
891 893
892 dprintk("%s\n", __FUNCTION__); 894 dprintk("%s\n", __func__);
893 895
894 if (mutex_lock_interruptible(&dec->iso_mutex)) 896 if (mutex_lock_interruptible(&dec->iso_mutex))
895 return -EAGAIN; 897 return -EAGAIN;
@@ -905,7 +907,7 @@ static int ttusb_dec_start_iso_xfer(struct ttusb_dec *dec)
905 if ((result = usb_submit_urb(dec->iso_urb[i], 907 if ((result = usb_submit_urb(dec->iso_urb[i],
906 GFP_ATOMIC))) { 908 GFP_ATOMIC))) {
907 printk("%s: failed urb submission %d: " 909 printk("%s: failed urb submission %d: "
908 "error %d\n", __FUNCTION__, i, result); 910 "error %d\n", __func__, i, result);
909 911
910 while (i) { 912 while (i) {
911 usb_kill_urb(dec->iso_urb[i - 1]); 913 usb_kill_urb(dec->iso_urb[i - 1]);
@@ -932,7 +934,7 @@ static int ttusb_dec_start_ts_feed(struct dvb_demux_feed *dvbdmxfeed)
932 u8 b0[] = { 0x05 }; 934 u8 b0[] = { 0x05 };
933 int result = 0; 935 int result = 0;
934 936
935 dprintk("%s\n", __FUNCTION__); 937 dprintk("%s\n", __func__);
936 938
937 dprintk(" ts_type:"); 939 dprintk(" ts_type:");
938 940
@@ -1012,7 +1014,7 @@ static int ttusb_dec_start_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
1012 unsigned long flags; 1014 unsigned long flags;
1013 u8 x = 1; 1015 u8 x = 1;
1014 1016
1015 dprintk("%s\n", __FUNCTION__); 1017 dprintk("%s\n", __func__);
1016 1018
1017 pid = htons(dvbdmxfeed->pid); 1019 pid = htons(dvbdmxfeed->pid);
1018 memcpy(&b0[0], &pid, 2); 1020 memcpy(&b0[0], &pid, 2);
@@ -1052,7 +1054,7 @@ static int ttusb_dec_start_feed(struct dvb_demux_feed *dvbdmxfeed)
1052{ 1054{
1053 struct dvb_demux *dvbdmx = dvbdmxfeed->demux; 1055 struct dvb_demux *dvbdmx = dvbdmxfeed->demux;
1054 1056
1055 dprintk("%s\n", __FUNCTION__); 1057 dprintk("%s\n", __func__);
1056 1058
1057 if (!dvbdmx->dmx.frontend) 1059 if (!dvbdmx->dmx.frontend)
1058 return -EINVAL; 1060 return -EINVAL;
@@ -1113,7 +1115,7 @@ static int ttusb_dec_stop_sec_feed(struct dvb_demux_feed *dvbdmxfeed)
1113 1115
1114static int ttusb_dec_stop_feed(struct dvb_demux_feed *dvbdmxfeed) 1116static int ttusb_dec_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
1115{ 1117{
1116 dprintk("%s\n", __FUNCTION__); 1118 dprintk("%s\n", __func__);
1117 1119
1118 switch (dvbdmxfeed->type) { 1120 switch (dvbdmxfeed->type) {
1119 case DMX_TYPE_TS: 1121 case DMX_TYPE_TS:
@@ -1132,7 +1134,7 @@ static void ttusb_dec_free_iso_urbs(struct ttusb_dec *dec)
1132{ 1134{
1133 int i; 1135 int i;
1134 1136
1135 dprintk("%s\n", __FUNCTION__); 1137 dprintk("%s\n", __func__);
1136 1138
1137 for (i = 0; i < ISO_BUF_COUNT; i++) 1139 for (i = 0; i < ISO_BUF_COUNT; i++)
1138 usb_free_urb(dec->iso_urb[i]); 1140 usb_free_urb(dec->iso_urb[i]);
@@ -1147,7 +1149,7 @@ static int ttusb_dec_alloc_iso_urbs(struct ttusb_dec *dec)
1147{ 1149{
1148 int i; 1150 int i;
1149 1151
1150 dprintk("%s\n", __FUNCTION__); 1152 dprintk("%s\n", __func__);
1151 1153
1152 dec->iso_buffer = pci_alloc_consistent(NULL, 1154 dec->iso_buffer = pci_alloc_consistent(NULL,
1153 ISO_FRAME_SIZE * 1155 ISO_FRAME_SIZE *
@@ -1214,7 +1216,7 @@ static int ttusb_init_rc( struct ttusb_dec *dec)
1214 1216
1215 dec->rc_input_dev = input_dev; 1217 dec->rc_input_dev = input_dev;
1216 if (usb_submit_urb(dec->irq_urb, GFP_KERNEL)) 1218 if (usb_submit_urb(dec->irq_urb, GFP_KERNEL))
1217 printk("%s: usb_submit_urb failed\n",__FUNCTION__); 1219 printk("%s: usb_submit_urb failed\n",__func__);
1218 /* enable irq pipe */ 1220 /* enable irq pipe */
1219 ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL); 1221 ttusb_dec_send_command(dec,0xb0,sizeof(b),b,NULL,NULL);
1220 1222
@@ -1223,7 +1225,7 @@ static int ttusb_init_rc( struct ttusb_dec *dec)
1223 1225
1224static void ttusb_dec_init_v_pes(struct ttusb_dec *dec) 1226static void ttusb_dec_init_v_pes(struct ttusb_dec *dec)
1225{ 1227{
1226 dprintk("%s\n", __FUNCTION__); 1228 dprintk("%s\n", __func__);
1227 1229
1228 dec->v_pes[0] = 0x00; 1230 dec->v_pes[0] = 0x00;
1229 dec->v_pes[1] = 0x00; 1231 dec->v_pes[1] = 0x00;
@@ -1233,7 +1235,7 @@ static void ttusb_dec_init_v_pes(struct ttusb_dec *dec)
1233 1235
1234static int ttusb_dec_init_usb(struct ttusb_dec *dec) 1236static int ttusb_dec_init_usb(struct ttusb_dec *dec)
1235{ 1237{
1236 dprintk("%s\n", __FUNCTION__); 1238 dprintk("%s\n", __func__);
1237 1239
1238 mutex_init(&dec->usb_mutex); 1240 mutex_init(&dec->usb_mutex);
1239 mutex_init(&dec->iso_mutex); 1241 mutex_init(&dec->iso_mutex);
@@ -1281,11 +1283,11 @@ static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
1281 u32 crc32_csum, crc32_check, tmp; 1283 u32 crc32_csum, crc32_check, tmp;
1282 const struct firmware *fw_entry = NULL; 1284 const struct firmware *fw_entry = NULL;
1283 1285
1284 dprintk("%s\n", __FUNCTION__); 1286 dprintk("%s\n", __func__);
1285 1287
1286 if (request_firmware(&fw_entry, dec->firmware_name, &dec->udev->dev)) { 1288 if (request_firmware(&fw_entry, dec->firmware_name, &dec->udev->dev)) {
1287 printk(KERN_ERR "%s: Firmware (%s) unavailable.\n", 1289 printk(KERN_ERR "%s: Firmware (%s) unavailable.\n",
1288 __FUNCTION__, dec->firmware_name); 1290 __func__, dec->firmware_name);
1289 return 1; 1291 return 1;
1290 } 1292 }
1291 1293
@@ -1294,7 +1296,7 @@ static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
1294 1296
1295 if (firmware_size < 60) { 1297 if (firmware_size < 60) {
1296 printk("%s: firmware size too small for DSP code (%zu < 60).\n", 1298 printk("%s: firmware size too small for DSP code (%zu < 60).\n",
1297 __FUNCTION__, firmware_size); 1299 __func__, firmware_size);
1298 release_firmware(fw_entry); 1300 release_firmware(fw_entry);
1299 return -1; 1301 return -1;
1300 } 1302 }
@@ -1308,7 +1310,7 @@ static int ttusb_dec_boot_dsp(struct ttusb_dec *dec)
1308 if (crc32_csum != crc32_check) { 1310 if (crc32_csum != crc32_check) {
1309 printk("%s: crc32 check of DSP code failed (calculated " 1311 printk("%s: crc32 check of DSP code failed (calculated "
1310 "0x%08x != 0x%08x in file), file invalid.\n", 1312 "0x%08x != 0x%08x in file), file invalid.\n",
1311 __FUNCTION__, crc32_csum, crc32_check); 1313 __func__, crc32_csum, crc32_check);
1312 release_firmware(fw_entry); 1314 release_firmware(fw_entry);
1313 return -1; 1315 return -1;
1314 } 1316 }
@@ -1376,7 +1378,7 @@ static int ttusb_dec_init_stb(struct ttusb_dec *dec)
1376 int result; 1378 int result;
1377 unsigned int mode, model, version; 1379 unsigned int mode, model, version;
1378 1380
1379 dprintk("%s\n", __FUNCTION__); 1381 dprintk("%s\n", __func__);
1380 1382
1381 result = ttusb_dec_get_stb_state(dec, &mode, &model, &version); 1383 result = ttusb_dec_get_stb_state(dec, &mode, &model, &version);
1382 1384
@@ -1415,7 +1417,7 @@ static int ttusb_dec_init_stb(struct ttusb_dec *dec)
1415 default: 1417 default:
1416 printk(KERN_ERR "%s: unknown model returned " 1418 printk(KERN_ERR "%s: unknown model returned "
1417 "by firmware (%08x) - please report\n", 1419 "by firmware (%08x) - please report\n",
1418 __FUNCTION__, model); 1420 __func__, model);
1419 return -1; 1421 return -1;
1420 break; 1422 break;
1421 } 1423 }
@@ -1434,12 +1436,14 @@ static int ttusb_dec_init_dvb(struct ttusb_dec *dec)
1434{ 1436{
1435 int result; 1437 int result;
1436 1438
1437 dprintk("%s\n", __FUNCTION__); 1439 dprintk("%s\n", __func__);
1438 1440
1439 if ((result = dvb_register_adapter(&dec->adapter, 1441 if ((result = dvb_register_adapter(&dec->adapter,
1440 dec->model_name, THIS_MODULE, &dec->udev->dev)) < 0) { 1442 dec->model_name, THIS_MODULE,
1443 &dec->udev->dev,
1444 adapter_nr)) < 0) {
1441 printk("%s: dvb_register_adapter failed: error %d\n", 1445 printk("%s: dvb_register_adapter failed: error %d\n",
1442 __FUNCTION__, result); 1446 __func__, result);
1443 1447
1444 return result; 1448 return result;
1445 } 1449 }
@@ -1454,7 +1458,7 @@ static int ttusb_dec_init_dvb(struct ttusb_dec *dec)
1454 dec->demux.write_to_decoder = NULL; 1458 dec->demux.write_to_decoder = NULL;
1455 1459
1456 if ((result = dvb_dmx_init(&dec->demux)) < 0) { 1460 if ((result = dvb_dmx_init(&dec->demux)) < 0) {
1457 printk("%s: dvb_dmx_init failed: error %d\n", __FUNCTION__, 1461 printk("%s: dvb_dmx_init failed: error %d\n", __func__,
1458 result); 1462 result);
1459 1463
1460 dvb_unregister_adapter(&dec->adapter); 1464 dvb_unregister_adapter(&dec->adapter);
@@ -1468,7 +1472,7 @@ static int ttusb_dec_init_dvb(struct ttusb_dec *dec)
1468 1472
1469 if ((result = dvb_dmxdev_init(&dec->dmxdev, &dec->adapter)) < 0) { 1473 if ((result = dvb_dmxdev_init(&dec->dmxdev, &dec->adapter)) < 0) {
1470 printk("%s: dvb_dmxdev_init failed: error %d\n", 1474 printk("%s: dvb_dmxdev_init failed: error %d\n",
1471 __FUNCTION__, result); 1475 __func__, result);
1472 1476
1473 dvb_dmx_release(&dec->demux); 1477 dvb_dmx_release(&dec->demux);
1474 dvb_unregister_adapter(&dec->adapter); 1478 dvb_unregister_adapter(&dec->adapter);
@@ -1480,7 +1484,7 @@ static int ttusb_dec_init_dvb(struct ttusb_dec *dec)
1480 1484
1481 if ((result = dec->demux.dmx.add_frontend(&dec->demux.dmx, 1485 if ((result = dec->demux.dmx.add_frontend(&dec->demux.dmx,
1482 &dec->frontend)) < 0) { 1486 &dec->frontend)) < 0) {
1483 printk("%s: dvb_dmx_init failed: error %d\n", __FUNCTION__, 1487 printk("%s: dvb_dmx_init failed: error %d\n", __func__,
1484 result); 1488 result);
1485 1489
1486 dvb_dmxdev_release(&dec->dmxdev); 1490 dvb_dmxdev_release(&dec->dmxdev);
@@ -1492,7 +1496,7 @@ static int ttusb_dec_init_dvb(struct ttusb_dec *dec)
1492 1496
1493 if ((result = dec->demux.dmx.connect_frontend(&dec->demux.dmx, 1497 if ((result = dec->demux.dmx.connect_frontend(&dec->demux.dmx,
1494 &dec->frontend)) < 0) { 1498 &dec->frontend)) < 0) {
1495 printk("%s: dvb_dmx_init failed: error %d\n", __FUNCTION__, 1499 printk("%s: dvb_dmx_init failed: error %d\n", __func__,
1496 result); 1500 result);
1497 1501
1498 dec->demux.dmx.remove_frontend(&dec->demux.dmx, &dec->frontend); 1502 dec->demux.dmx.remove_frontend(&dec->demux.dmx, &dec->frontend);
@@ -1510,7 +1514,7 @@ static int ttusb_dec_init_dvb(struct ttusb_dec *dec)
1510 1514
1511static void ttusb_dec_exit_dvb(struct ttusb_dec *dec) 1515static void ttusb_dec_exit_dvb(struct ttusb_dec *dec)
1512{ 1516{
1513 dprintk("%s\n", __FUNCTION__); 1517 dprintk("%s\n", __func__);
1514 1518
1515 dvb_net_release(&dec->dvb_net); 1519 dvb_net_release(&dec->dvb_net);
1516 dec->demux.dmx.close(&dec->demux.dmx); 1520 dec->demux.dmx.close(&dec->demux.dmx);
@@ -1528,7 +1532,7 @@ static void ttusb_dec_exit_dvb(struct ttusb_dec *dec)
1528static void ttusb_dec_exit_rc(struct ttusb_dec *dec) 1532static void ttusb_dec_exit_rc(struct ttusb_dec *dec)
1529{ 1533{
1530 1534
1531 dprintk("%s\n", __FUNCTION__); 1535 dprintk("%s\n", __func__);
1532 /* we have to check whether the irq URB is already submitted. 1536 /* we have to check whether the irq URB is already submitted.
1533 * As the irq is submitted after the interface is changed, 1537 * As the irq is submitted after the interface is changed,
1534 * this is the best method i figured out. 1538 * this is the best method i figured out.
@@ -1552,7 +1556,7 @@ static void ttusb_dec_exit_usb(struct ttusb_dec *dec)
1552{ 1556{
1553 int i; 1557 int i;
1554 1558
1555 dprintk("%s\n", __FUNCTION__); 1559 dprintk("%s\n", __func__);
1556 1560
1557 dec->iso_stream_count = 0; 1561 dec->iso_stream_count = 0;
1558 1562
@@ -1612,12 +1616,12 @@ static int ttusb_dec_probe(struct usb_interface *intf,
1612 struct usb_device *udev; 1616 struct usb_device *udev;
1613 struct ttusb_dec *dec; 1617 struct ttusb_dec *dec;
1614 1618
1615 dprintk("%s\n", __FUNCTION__); 1619 dprintk("%s\n", __func__);
1616 1620
1617 udev = interface_to_usbdev(intf); 1621 udev = interface_to_usbdev(intf);
1618 1622
1619 if (!(dec = kzalloc(sizeof(struct ttusb_dec), GFP_KERNEL))) { 1623 if (!(dec = kzalloc(sizeof(struct ttusb_dec), GFP_KERNEL))) {
1620 printk("%s: couldn't allocate memory.\n", __FUNCTION__); 1624 printk("%s: couldn't allocate memory.\n", __func__);
1621 return -ENOMEM; 1625 return -ENOMEM;
1622 } 1626 }
1623 1627
@@ -1692,7 +1696,7 @@ static void ttusb_dec_disconnect(struct usb_interface *intf)
1692 1696
1693 usb_set_intfdata(intf, NULL); 1697 usb_set_intfdata(intf, NULL);
1694 1698
1695 dprintk("%s\n", __FUNCTION__); 1699 dprintk("%s\n", __func__);
1696 1700
1697 if (dec->active) { 1701 if (dec->active) {
1698 ttusb_dec_exit_tasklet(dec); 1702 ttusb_dec_exit_tasklet(dec);
@@ -1749,7 +1753,7 @@ static int __init ttusb_dec_init(void)
1749 int result; 1753 int result;
1750 1754
1751 if ((result = usb_register(&ttusb_dec_driver)) < 0) { 1755 if ((result = usb_register(&ttusb_dec_driver)) < 0) {
1752 printk("%s: initialisation failed: error %d.\n", __FUNCTION__, 1756 printk("%s: initialisation failed: error %d.\n", __func__,
1753 result); 1757 result);
1754 return result; 1758 return result;
1755 } 1759 }
diff --git a/drivers/media/dvb/ttusb-dec/ttusbdecfe.c b/drivers/media/dvb/ttusb-dec/ttusbdecfe.c
index a6fb1d6a7b5d..eb5eaeccd7c4 100644
--- a/drivers/media/dvb/ttusb-dec/ttusbdecfe.c
+++ b/drivers/media/dvb/ttusb-dec/ttusbdecfe.c
@@ -53,7 +53,7 @@ static int ttusbdecfe_read_status(struct dvb_frontend* fe, fe_status_t* status)
53 return ret; 53 return ret;
54 54
55 if(len != 4) { 55 if(len != 4) {
56 printk(KERN_ERR "%s: unexpected reply\n", __FUNCTION__); 56 printk(KERN_ERR "%s: unexpected reply\n", __func__);
57 return -EIO; 57 return -EIO;
58 } 58 }
59 59
@@ -70,7 +70,7 @@ static int ttusbdecfe_read_status(struct dvb_frontend* fe, fe_status_t* status)
70 break; 70 break;
71 default: 71 default:
72 pr_info("%s: returned unknown value: %d\n", 72 pr_info("%s: returned unknown value: %d\n",
73 __FUNCTION__, result[3]); 73 __func__, result[3]);
74 return -EIO; 74 return -EIO;
75 } 75 }
76 76
diff --git a/drivers/media/radio/dsbr100.c b/drivers/media/radio/dsbr100.c
index 36c0e3651502..4e3f83e4e48f 100644
--- a/drivers/media/radio/dsbr100.c
+++ b/drivers/media/radio/dsbr100.c
@@ -438,7 +438,9 @@ static const struct file_operations usb_dsbr100_fops = {
438 .open = usb_dsbr100_open, 438 .open = usb_dsbr100_open,
439 .release = usb_dsbr100_close, 439 .release = usb_dsbr100_close,
440 .ioctl = video_ioctl2, 440 .ioctl = video_ioctl2,
441#ifdef CONFIG_COMPAT
441 .compat_ioctl = v4l_compat_ioctl32, 442 .compat_ioctl = v4l_compat_ioctl32,
443#endif
442 .llseek = no_llseek, 444 .llseek = no_llseek,
443}; 445};
444 446
diff --git a/drivers/media/radio/miropcm20-radio.c b/drivers/media/radio/miropcm20-radio.c
index 3ae56fef8c92..09fe6f1cdf14 100644
--- a/drivers/media/radio/miropcm20-radio.c
+++ b/drivers/media/radio/miropcm20-radio.c
@@ -221,7 +221,9 @@ static const struct file_operations pcm20_fops = {
221 .open = video_exclusive_open, 221 .open = video_exclusive_open,
222 .release = video_exclusive_release, 222 .release = video_exclusive_release,
223 .ioctl = pcm20_ioctl, 223 .ioctl = pcm20_ioctl,
224#ifdef CONFIG_COMPAT
224 .compat_ioctl = v4l_compat_ioctl32, 225 .compat_ioctl = v4l_compat_ioctl32,
226#endif
225 .llseek = no_llseek, 227 .llseek = no_llseek,
226}; 228};
227 229
diff --git a/drivers/media/radio/miropcm20-rds.c b/drivers/media/radio/miropcm20-rds.c
index aed11477378b..06dfed9ef4c7 100644
--- a/drivers/media/radio/miropcm20-rds.c
+++ b/drivers/media/radio/miropcm20-rds.c
@@ -19,7 +19,7 @@
19#include "miropcm20-rds-core.h" 19#include "miropcm20-rds-core.h"
20 20
21static char * text_buffer; 21static char * text_buffer;
22static int rds_users = 0; 22static int rds_users;
23 23
24 24
25static int rds_f_open(struct inode *in, struct file *fi) 25static int rds_f_open(struct inode *in, struct file *fi)
diff --git a/drivers/media/radio/radio-aimslab.c b/drivers/media/radio/radio-aimslab.c
index c69bde39a233..1ec18ed1a733 100644
--- a/drivers/media/radio/radio-aimslab.c
+++ b/drivers/media/radio/radio-aimslab.c
@@ -382,7 +382,9 @@ static const struct file_operations rtrack_fops = {
382 .open = video_exclusive_open, 382 .open = video_exclusive_open,
383 .release = video_exclusive_release, 383 .release = video_exclusive_release,
384 .ioctl = video_ioctl2, 384 .ioctl = video_ioctl2,
385#ifdef CONFIG_COMPAT
385 .compat_ioctl = v4l_compat_ioctl32, 386 .compat_ioctl = v4l_compat_ioctl32,
387#endif
386 .llseek = no_llseek, 388 .llseek = no_llseek,
387}; 389};
388 390
diff --git a/drivers/media/radio/radio-aztech.c b/drivers/media/radio/radio-aztech.c
index 9b1f7a99dac0..46cdb549eac7 100644
--- a/drivers/media/radio/radio-aztech.c
+++ b/drivers/media/radio/radio-aztech.c
@@ -346,7 +346,9 @@ static const struct file_operations aztech_fops = {
346 .open = video_exclusive_open, 346 .open = video_exclusive_open,
347 .release = video_exclusive_release, 347 .release = video_exclusive_release,
348 .ioctl = video_ioctl2, 348 .ioctl = video_ioctl2,
349#ifdef CONFIG_COMPAT
349 .compat_ioctl = v4l_compat_ioctl32, 350 .compat_ioctl = v4l_compat_ioctl32,
351#endif
350 .llseek = no_llseek, 352 .llseek = no_llseek,
351}; 353};
352 354
diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
index 57b9e3adc8f0..b14db53ea456 100644
--- a/drivers/media/radio/radio-cadet.c
+++ b/drivers/media/radio/radio-cadet.c
@@ -69,13 +69,13 @@ static struct v4l2_queryctrl radio_qctrl[] = {
69 69
70static int io=-1; /* default to isapnp activation */ 70static int io=-1; /* default to isapnp activation */
71static int radio_nr = -1; 71static int radio_nr = -1;
72static int users=0; 72static int users;
73static int curtuner=0; 73static int curtuner;
74static int tunestat=0; 74static int tunestat;
75static int sigstrength=0; 75static int sigstrength;
76static wait_queue_head_t read_queue; 76static wait_queue_head_t read_queue;
77static struct timer_list readtimer; 77static struct timer_list readtimer;
78static __u8 rdsin=0,rdsout=0,rdsstat=0; 78static __u8 rdsin, rdsout, rdsstat;
79static unsigned char rdsbuf[RDS_BUFFER]; 79static unsigned char rdsbuf[RDS_BUFFER];
80static spinlock_t cadet_io_lock; 80static spinlock_t cadet_io_lock;
81 81
@@ -563,7 +563,9 @@ static const struct file_operations cadet_fops = {
563 .read = cadet_read, 563 .read = cadet_read,
564 .ioctl = video_ioctl2, 564 .ioctl = video_ioctl2,
565 .poll = cadet_poll, 565 .poll = cadet_poll,
566#ifdef CONFIG_COMPAT
566 .compat_ioctl = v4l_compat_ioctl32, 567 .compat_ioctl = v4l_compat_ioctl32,
568#endif
567 .llseek = no_llseek, 569 .llseek = no_llseek,
568}; 570};
569 571
diff --git a/drivers/media/radio/radio-gemtek-pci.c b/drivers/media/radio/radio-gemtek-pci.c
index 99a323131333..de49be971480 100644
--- a/drivers/media/radio/radio-gemtek-pci.c
+++ b/drivers/media/radio/radio-gemtek-pci.c
@@ -368,7 +368,9 @@ static const struct file_operations gemtek_pci_fops = {
368 .open = video_exclusive_open, 368 .open = video_exclusive_open,
369 .release = video_exclusive_release, 369 .release = video_exclusive_release,
370 .ioctl = video_ioctl2, 370 .ioctl = video_ioctl2,
371#ifdef CONFIG_COMPAT
371 .compat_ioctl = v4l_compat_ioctl32, 372 .compat_ioctl = v4l_compat_ioctl32,
373#endif
372 .llseek = no_llseek, 374 .llseek = no_llseek,
373}; 375};
374 376
diff --git a/drivers/media/radio/radio-gemtek.c b/drivers/media/radio/radio-gemtek.c
index 246422b49267..81f6aeb1cd11 100644
--- a/drivers/media/radio/radio-gemtek.c
+++ b/drivers/media/radio/radio-gemtek.c
@@ -397,7 +397,9 @@ static const struct file_operations gemtek_fops = {
397 .open = video_exclusive_open, 397 .open = video_exclusive_open,
398 .release = video_exclusive_release, 398 .release = video_exclusive_release,
399 .ioctl = video_ioctl2, 399 .ioctl = video_ioctl2,
400#ifdef CONFIG_COMPAT
400 .compat_ioctl = v4l_compat_ioctl32, 401 .compat_ioctl = v4l_compat_ioctl32,
402#endif
401 .llseek = no_llseek 403 .llseek = no_llseek
402}; 404};
403 405
diff --git a/drivers/media/radio/radio-maestro.c b/drivers/media/radio/radio-maestro.c
index bc51f4d23a5a..bddd3c409aa9 100644
--- a/drivers/media/radio/radio-maestro.c
+++ b/drivers/media/radio/radio-maestro.c
@@ -100,7 +100,9 @@ static const struct file_operations maestro_fops = {
100 .open = video_exclusive_open, 100 .open = video_exclusive_open,
101 .release = video_exclusive_release, 101 .release = video_exclusive_release,
102 .ioctl = video_ioctl2, 102 .ioctl = video_ioctl2,
103#ifdef CONFIG_COMPAT
103 .compat_ioctl = v4l_compat_ioctl32, 104 .compat_ioctl = v4l_compat_ioctl32,
105#endif
104 .llseek = no_llseek, 106 .llseek = no_llseek,
105}; 107};
106 108
diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
index 8e184cfc1c94..0133ecf3e040 100644
--- a/drivers/media/radio/radio-maxiradio.c
+++ b/drivers/media/radio/radio-maxiradio.c
@@ -103,7 +103,9 @@ static const struct file_operations maxiradio_fops = {
103 .open = video_exclusive_open, 103 .open = video_exclusive_open,
104 .release = video_exclusive_release, 104 .release = video_exclusive_release,
105 .ioctl = video_ioctl2, 105 .ioctl = video_ioctl2,
106#ifdef CONFIG_COMPAT
106 .compat_ioctl = v4l_compat_ioctl32, 107 .compat_ioctl = v4l_compat_ioctl32,
108#endif
107 .llseek = no_llseek, 109 .llseek = no_llseek,
108}; 110};
109 111
diff --git a/drivers/media/radio/radio-rtrack2.c b/drivers/media/radio/radio-rtrack2.c
index 82aedfc95d4f..070802103dc3 100644
--- a/drivers/media/radio/radio-rtrack2.c
+++ b/drivers/media/radio/radio-rtrack2.c
@@ -288,7 +288,9 @@ static const struct file_operations rtrack2_fops = {
288 .open = video_exclusive_open, 288 .open = video_exclusive_open,
289 .release = video_exclusive_release, 289 .release = video_exclusive_release,
290 .ioctl = video_ioctl2, 290 .ioctl = video_ioctl2,
291#ifdef CONFIG_COMPAT
291 .compat_ioctl = v4l_compat_ioctl32, 292 .compat_ioctl = v4l_compat_ioctl32,
293#endif
292 .llseek = no_llseek, 294 .llseek = no_llseek,
293}; 295};
294 296
diff --git a/drivers/media/radio/radio-sf16fmi.c b/drivers/media/radio/radio-sf16fmi.c
index 53e114857377..66e052fd3909 100644
--- a/drivers/media/radio/radio-sf16fmi.c
+++ b/drivers/media/radio/radio-sf16fmi.c
@@ -288,7 +288,9 @@ static const struct file_operations fmi_fops = {
288 .open = video_exclusive_open, 288 .open = video_exclusive_open,
289 .release = video_exclusive_release, 289 .release = video_exclusive_release,
290 .ioctl = video_ioctl2, 290 .ioctl = video_ioctl2,
291#ifdef CONFIG_COMPAT
291 .compat_ioctl = v4l_compat_ioctl32, 292 .compat_ioctl = v4l_compat_ioctl32,
293#endif
292 .llseek = no_llseek, 294 .llseek = no_llseek,
293}; 295};
294 296
diff --git a/drivers/media/radio/radio-sf16fmr2.c b/drivers/media/radio/radio-sf16fmr2.c
index ebc5fbbc38bb..b0ccf7cb5952 100644
--- a/drivers/media/radio/radio-sf16fmr2.c
+++ b/drivers/media/radio/radio-sf16fmr2.c
@@ -29,6 +29,8 @@ static struct mutex lock;
29#include <linux/version.h> /* for KERNEL_VERSION MACRO */ 29#include <linux/version.h> /* for KERNEL_VERSION MACRO */
30#define RADIO_VERSION KERNEL_VERSION(0,0,2) 30#define RADIO_VERSION KERNEL_VERSION(0,0,2)
31 31
32#define AUD_VOL_INDEX 1
33
32static struct v4l2_queryctrl radio_qctrl[] = { 34static struct v4l2_queryctrl radio_qctrl[] = {
33 { 35 {
34 .id = V4L2_CID_AUDIO_MUTE, 36 .id = V4L2_CID_AUDIO_MUTE,
@@ -37,13 +39,14 @@ static struct v4l2_queryctrl radio_qctrl[] = {
37 .maximum = 1, 39 .maximum = 1,
38 .default_value = 1, 40 .default_value = 1,
39 .type = V4L2_CTRL_TYPE_BOOLEAN, 41 .type = V4L2_CTRL_TYPE_BOOLEAN,
40 },{ 42 },
43 [AUD_VOL_INDEX] = {
41 .id = V4L2_CID_AUDIO_VOLUME, 44 .id = V4L2_CID_AUDIO_VOLUME,
42 .name = "Volume", 45 .name = "Volume",
43 .minimum = 0, 46 .minimum = 0,
44 .maximum = 65535, 47 .maximum = 15,
45 .step = 1<<12, 48 .step = 1,
46 .default_value = 0xff, 49 .default_value = 0,
47 .type = V4L2_CTRL_TYPE_INTEGER, 50 .type = V4L2_CTRL_TYPE_INTEGER,
48 } 51 }
49}; 52};
@@ -61,7 +64,7 @@ static struct v4l2_queryctrl radio_qctrl[] = {
61struct fmr2_device 64struct fmr2_device
62{ 65{
63 int port; 66 int port;
64 int curvol; /* 0-65535, if not volume 0 or 65535 */ 67 int curvol; /* 0-15 */
65 int mute; 68 int mute;
66 int stereo; /* card is producing stereo audio */ 69 int stereo; /* card is producing stereo audio */
67 unsigned long curfreq; /* freq in kHz */ 70 unsigned long curfreq; /* freq in kHz */
@@ -176,51 +179,35 @@ static int fmr2_setfreq(struct fmr2_device *dev)
176/* !!! not tested, in my card this does't work !!! */ 179/* !!! not tested, in my card this does't work !!! */
177static int fmr2_setvolume(struct fmr2_device *dev) 180static int fmr2_setvolume(struct fmr2_device *dev)
178{ 181{
179 int i,a,n, port = dev->port; 182 int vol[16] = { 0x021, 0x084, 0x090, 0x104,
183 0x110, 0x204, 0x210, 0x402,
184 0x404, 0x408, 0x410, 0x801,
185 0x802, 0x804, 0x808, 0x810 };
186 int i, a, port = dev->port;
187 int n = vol[dev->curvol & 0x0f];
180 188
181 if (dev->card_type != 11) return 1; 189 if (dev->card_type != 11)
190 return 1;
182 191
183 switch( (dev->curvol+(1<<11)) >> 12 ) 192 for (i = 12; --i >= 0; ) {
184 {
185 case 0: case 1: n = 0x21; break;
186 case 2: n = 0x84; break;
187 case 3: n = 0x90; break;
188 case 4: n = 0x104; break;
189 case 5: n = 0x110; break;
190 case 6: n = 0x204; break;
191 case 7: n = 0x210; break;
192 case 8: n = 0x402; break;
193 case 9: n = 0x404; break;
194 default:
195 case 10: n = 0x408; break;
196 case 11: n = 0x410; break;
197 case 12: n = 0x801; break;
198 case 13: n = 0x802; break;
199 case 14: n = 0x804; break;
200 case 15: n = 0x808; break;
201 case 16: n = 0x810; break;
202 }
203 for(i=12;--i>=0;)
204 {
205 a = ((n >> i) & 1) << 6; /* if (a=0) a= 0; else a= 0x40; */ 193 a = ((n >> i) & 1) << 6; /* if (a=0) a= 0; else a= 0x40; */
206 outb(a|4, port); 194 outb(a | 4, port);
207 wait(4,port); 195 wait(4, port);
208 outb(a|0x24, port); 196 outb(a | 0x24, port);
209 wait(4,port); 197 wait(4, port);
210 outb(a|4, port); 198 outb(a | 4, port);
211 wait(4,port); 199 wait(4, port);
212 } 200 }
213 for(i=6;--i>=0;) 201 for (i = 6; --i >= 0; ) {
214 {
215 a = ((0x18 >> i) & 1) << 6; 202 a = ((0x18 >> i) & 1) << 6;
216 outb(a|4, port); 203 outb(a | 4, port);
217 wait(4,port); 204 wait(4,port);
218 outb(a|0x24, port); 205 outb(a | 0x24, port);
219 wait(4,port); 206 wait(4,port);
220 outb(a|4, port); 207 outb(a|4, port);
221 wait(4,port); 208 wait(4,port);
222 } 209 }
223 wait(4,port); 210 wait(4, port);
224 outb(0x14, port); 211 outb(0x14, port);
225 212
226 return 0; 213 return 0;
@@ -312,16 +299,10 @@ static int vidioc_queryctrl(struct file *file, void *priv,
312 struct v4l2_queryctrl *qc) 299 struct v4l2_queryctrl *qc)
313{ 300{
314 int i; 301 int i;
315 struct video_device *dev = video_devdata(file);
316 struct fmr2_device *fmr2 = dev->priv;
317 302
318 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) { 303 for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
319 if ((fmr2->card_type != 11)
320 && V4L2_CID_AUDIO_VOLUME)
321 radio_qctrl[i].step = 65535;
322 if (qc->id && qc->id == radio_qctrl[i].id) { 304 if (qc->id && qc->id == radio_qctrl[i].id) {
323 memcpy(qc, &(radio_qctrl[i]), 305 memcpy(qc, &radio_qctrl[i], sizeof(*qc));
324 sizeof(*qc));
325 return 0; 306 return 0;
326 } 307 }
327 } 308 }
@@ -354,24 +335,13 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
354 switch (ctrl->id) { 335 switch (ctrl->id) {
355 case V4L2_CID_AUDIO_MUTE: 336 case V4L2_CID_AUDIO_MUTE:
356 fmr2->mute = ctrl->value; 337 fmr2->mute = ctrl->value;
357 if (fmr2->card_type != 11) {
358 if (!fmr2->mute)
359 fmr2->curvol = 65535;
360 else
361 fmr2->curvol = 0;
362 }
363 break; 338 break;
364 case V4L2_CID_AUDIO_VOLUME: 339 case V4L2_CID_AUDIO_VOLUME:
365 fmr2->curvol = ctrl->value; 340 if (ctrl->value > radio_qctrl[AUD_VOL_INDEX].maximum)
366 if (fmr2->card_type != 11) { 341 fmr2->curvol = radio_qctrl[AUD_VOL_INDEX].maximum;
367 if (fmr2->curvol) { 342 else
368 fmr2->curvol = 65535; 343 fmr2->curvol = ctrl->value;
369 fmr2->mute = 0; 344
370 } else {
371 fmr2->curvol = 0;
372 fmr2->mute = 1;
373 }
374 }
375 break; 345 break;
376 default: 346 default:
377 return -EINVAL; 347 return -EINVAL;
@@ -387,6 +357,7 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
387 mutex_lock(&lock); 357 mutex_lock(&lock);
388 if (fmr2->curvol && !fmr2->mute) { 358 if (fmr2->curvol && !fmr2->mute) {
389 fmr2_setvolume(fmr2); 359 fmr2_setvolume(fmr2);
360 /* Set frequency and unmute card */
390 fmr2_setfreq(fmr2); 361 fmr2_setfreq(fmr2);
391 } else 362 } else
392 fmr2_mute(fmr2->port); 363 fmr2_mute(fmr2->port);
@@ -433,7 +404,9 @@ static const struct file_operations fmr2_fops = {
433 .open = video_exclusive_open, 404 .open = video_exclusive_open,
434 .release = video_exclusive_release, 405 .release = video_exclusive_release,
435 .ioctl = video_ioctl2, 406 .ioctl = video_ioctl2,
407#ifdef CONFIG_COMPAT
436 .compat_ioctl = v4l_compat_ioctl32, 408 .compat_ioctl = v4l_compat_ioctl32,
409#endif
437 .llseek = no_llseek, 410 .llseek = no_llseek,
438}; 411};
439 412
@@ -487,6 +460,11 @@ static int __init fmr2_init(void)
487 fmr2_product_info(&fmr2_unit); 460 fmr2_product_info(&fmr2_unit);
488 mutex_unlock(&lock); 461 mutex_unlock(&lock);
489 debug_print((KERN_DEBUG "card_type %d\n", fmr2_unit.card_type)); 462 debug_print((KERN_DEBUG "card_type %d\n", fmr2_unit.card_type));
463
464 /* Only card_type == 11 implements volume */
465 if (fmr2_unit.card_type != 11)
466 radio_qctrl[AUD_VOL_INDEX].maximum = 1;
467
490 return 0; 468 return 0;
491} 469}
492 470
diff --git a/drivers/media/radio/radio-si470x.c b/drivers/media/radio/radio-si470x.c
index 649f14d2c013..77354ca6e8e9 100644
--- a/drivers/media/radio/radio-si470x.c
+++ b/drivers/media/radio/radio-si470x.c
@@ -85,6 +85,7 @@
85 * Oliver Neukum <oliver@neukum.org> 85 * Oliver Neukum <oliver@neukum.org>
86 * Version 1.0.7 86 * Version 1.0.7
87 * - usb autosuspend support 87 * - usb autosuspend support
88 * - unplugging fixed
88 * 89 *
89 * ToDo: 90 * ToDo:
90 * - add seeking support 91 * - add seeking support
@@ -97,10 +98,10 @@
97/* driver definitions */ 98/* driver definitions */
98#define DRIVER_AUTHOR "Tobias Lorenz <tobias.lorenz@gmx.net>" 99#define DRIVER_AUTHOR "Tobias Lorenz <tobias.lorenz@gmx.net>"
99#define DRIVER_NAME "radio-si470x" 100#define DRIVER_NAME "radio-si470x"
100#define DRIVER_KERNEL_VERSION KERNEL_VERSION(1, 0, 6) 101#define DRIVER_KERNEL_VERSION KERNEL_VERSION(1, 0, 7)
101#define DRIVER_CARD "Silicon Labs Si470x FM Radio Receiver" 102#define DRIVER_CARD "Silicon Labs Si470x FM Radio Receiver"
102#define DRIVER_DESC "USB radio driver for Si470x FM Radio Receivers" 103#define DRIVER_DESC "USB radio driver for Si470x FM Radio Receivers"
103#define DRIVER_VERSION "1.0.6" 104#define DRIVER_VERSION "1.0.7"
104 105
105 106
106/* kernel includes */ 107/* kernel includes */
@@ -424,6 +425,7 @@ struct si470x_device {
424 425
425 /* driver management */ 426 /* driver management */
426 unsigned int users; 427 unsigned int users;
428 unsigned char disconnected;
427 429
428 /* Silabs internal registers (0..15) */ 430 /* Silabs internal registers (0..15) */
429 unsigned short registers[RADIO_REGISTER_NUM]; 431 unsigned short registers[RADIO_REGISTER_NUM];
@@ -440,6 +442,12 @@ struct si470x_device {
440 442
441 443
442/* 444/*
445 * Lock to prevent kfree of data before all users have releases the device.
446 */
447static DEFINE_MUTEX(open_close_lock);
448
449
450/*
443 * The frequency is set in units of 62.5 Hz when using V4L2_TUNER_CAP_LOW, 451 * The frequency is set in units of 62.5 Hz when using V4L2_TUNER_CAP_LOW,
444 * 62.5 kHz otherwise. 452 * 62.5 kHz otherwise.
445 * The tuner is able to have a channel spacing of 50, 100 or 200 kHz. 453 * The tuner is able to have a channel spacing of 50, 100 or 200 kHz.
@@ -577,7 +585,7 @@ static int si470x_get_rds_registers(struct si470x_device *radio)
577 usb_rcvintpipe(radio->usbdev, 1), 585 usb_rcvintpipe(radio->usbdev, 1),
578 (void *) &buf, sizeof(buf), &size, usb_timeout); 586 (void *) &buf, sizeof(buf), &size, usb_timeout);
579 if (size != sizeof(buf)) 587 if (size != sizeof(buf))
580 printk(KERN_WARNING DRIVER_NAME ": si470x_get_rds_register: " 588 printk(KERN_WARNING DRIVER_NAME ": si470x_get_rds_registers: "
581 "return size differs: %d != %zu\n", size, sizeof(buf)); 589 "return size differs: %d != %zu\n", size, sizeof(buf));
582 if (retval < 0) 590 if (retval < 0)
583 printk(KERN_WARNING DRIVER_NAME ": si470x_get_rds_registers: " 591 printk(KERN_WARNING DRIVER_NAME ": si470x_get_rds_registers: "
@@ -875,6 +883,8 @@ static void si470x_work(struct work_struct *work)
875 struct si470x_device *radio = container_of(work, struct si470x_device, 883 struct si470x_device *radio = container_of(work, struct si470x_device,
876 work.work); 884 work.work);
877 885
886 if (radio->disconnected)
887 return;
878 if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0) 888 if ((radio->registers[SYSCONFIG1] & SYSCONFIG1_RDS) == 0)
879 return; 889 return;
880 890
@@ -1001,13 +1011,21 @@ static int si470x_fops_open(struct inode *inode, struct file *file)
1001static int si470x_fops_release(struct inode *inode, struct file *file) 1011static int si470x_fops_release(struct inode *inode, struct file *file)
1002{ 1012{
1003 struct si470x_device *radio = video_get_drvdata(video_devdata(file)); 1013 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
1004 int retval; 1014 int retval = 0;
1005 1015
1006 if (!radio) 1016 if (!radio)
1007 return -ENODEV; 1017 return -ENODEV;
1008 1018
1019 mutex_lock(&open_close_lock);
1009 radio->users--; 1020 radio->users--;
1010 if (radio->users == 0) { 1021 if (radio->users == 0) {
1022 if (radio->disconnected) {
1023 video_unregister_device(radio->videodev);
1024 kfree(radio->buffer);
1025 kfree(radio);
1026 goto done;
1027 }
1028
1011 /* stop rds reception */ 1029 /* stop rds reception */
1012 cancel_delayed_work_sync(&radio->work); 1030 cancel_delayed_work_sync(&radio->work);
1013 1031
@@ -1016,10 +1034,11 @@ static int si470x_fops_release(struct inode *inode, struct file *file)
1016 1034
1017 retval = si470x_stop(radio); 1035 retval = si470x_stop(radio);
1018 usb_autopm_put_interface(radio->intf); 1036 usb_autopm_put_interface(radio->intf);
1019 return retval;
1020 } 1037 }
1021 1038
1022 return 0; 1039done:
1040 mutex_unlock(&open_close_lock);
1041 return retval;
1023} 1042}
1024 1043
1025 1044
@@ -1032,7 +1051,9 @@ static const struct file_operations si470x_fops = {
1032 .read = si470x_fops_read, 1051 .read = si470x_fops_read,
1033 .poll = si470x_fops_poll, 1052 .poll = si470x_fops_poll,
1034 .ioctl = video_ioctl2, 1053 .ioctl = video_ioctl2,
1054#ifdef CONFIG_COMPAT
1035 .compat_ioctl = v4l_compat_ioctl32, 1055 .compat_ioctl = v4l_compat_ioctl32,
1056#endif
1036 .open = si470x_fops_open, 1057 .open = si470x_fops_open,
1037 .release = si470x_fops_release, 1058 .release = si470x_fops_release,
1038}; 1059};
@@ -1157,6 +1178,9 @@ static int si470x_vidioc_g_ctrl(struct file *file, void *priv,
1157{ 1178{
1158 struct si470x_device *radio = video_get_drvdata(video_devdata(file)); 1179 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
1159 1180
1181 if (radio->disconnected)
1182 return -EIO;
1183
1160 switch (ctrl->id) { 1184 switch (ctrl->id) {
1161 case V4L2_CID_AUDIO_VOLUME: 1185 case V4L2_CID_AUDIO_VOLUME:
1162 ctrl->value = radio->registers[SYSCONFIG2] & 1186 ctrl->value = radio->registers[SYSCONFIG2] &
@@ -1181,6 +1205,9 @@ static int si470x_vidioc_s_ctrl(struct file *file, void *priv,
1181 struct si470x_device *radio = video_get_drvdata(video_devdata(file)); 1205 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
1182 int retval; 1206 int retval;
1183 1207
1208 if (radio->disconnected)
1209 return -EIO;
1210
1184 switch (ctrl->id) { 1211 switch (ctrl->id) {
1185 case V4L2_CID_AUDIO_VOLUME: 1212 case V4L2_CID_AUDIO_VOLUME:
1186 radio->registers[SYSCONFIG2] &= ~SYSCONFIG2_VOLUME; 1213 radio->registers[SYSCONFIG2] &= ~SYSCONFIG2_VOLUME;
@@ -1243,6 +1270,8 @@ static int si470x_vidioc_g_tuner(struct file *file, void *priv,
1243 struct si470x_device *radio = video_get_drvdata(video_devdata(file)); 1270 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
1244 int retval; 1271 int retval;
1245 1272
1273 if (radio->disconnected)
1274 return -EIO;
1246 if (tuner->index > 0) 1275 if (tuner->index > 0)
1247 return -EINVAL; 1276 return -EINVAL;
1248 1277
@@ -1299,6 +1328,8 @@ static int si470x_vidioc_s_tuner(struct file *file, void *priv,
1299 struct si470x_device *radio = video_get_drvdata(video_devdata(file)); 1328 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
1300 int retval; 1329 int retval;
1301 1330
1331 if (radio->disconnected)
1332 return -EIO;
1302 if (tuner->index > 0) 1333 if (tuner->index > 0)
1303 return -EINVAL; 1334 return -EINVAL;
1304 1335
@@ -1324,6 +1355,9 @@ static int si470x_vidioc_g_frequency(struct file *file, void *priv,
1324{ 1355{
1325 struct si470x_device *radio = video_get_drvdata(video_devdata(file)); 1356 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
1326 1357
1358 if (radio->disconnected)
1359 return -EIO;
1360
1327 freq->type = V4L2_TUNER_RADIO; 1361 freq->type = V4L2_TUNER_RADIO;
1328 freq->frequency = si470x_get_freq(radio); 1362 freq->frequency = si470x_get_freq(radio);
1329 1363
@@ -1340,6 +1374,8 @@ static int si470x_vidioc_s_frequency(struct file *file, void *priv,
1340 struct si470x_device *radio = video_get_drvdata(video_devdata(file)); 1374 struct si470x_device *radio = video_get_drvdata(video_devdata(file));
1341 int retval; 1375 int retval;
1342 1376
1377 if (radio->disconnected)
1378 return -EIO;
1343 if (freq->type != V4L2_TUNER_RADIO) 1379 if (freq->type != V4L2_TUNER_RADIO)
1344 return -EINVAL; 1380 return -EINVAL;
1345 1381
@@ -1510,11 +1546,16 @@ static void si470x_usb_driver_disconnect(struct usb_interface *intf)
1510{ 1546{
1511 struct si470x_device *radio = usb_get_intfdata(intf); 1547 struct si470x_device *radio = usb_get_intfdata(intf);
1512 1548
1549 mutex_lock(&open_close_lock);
1550 radio->disconnected = 1;
1513 cancel_delayed_work_sync(&radio->work); 1551 cancel_delayed_work_sync(&radio->work);
1514 usb_set_intfdata(intf, NULL); 1552 usb_set_intfdata(intf, NULL);
1515 video_unregister_device(radio->videodev); 1553 if (radio->users == 0) {
1516 kfree(radio->buffer); 1554 video_unregister_device(radio->videodev);
1517 kfree(radio); 1555 kfree(radio->buffer);
1556 kfree(radio);
1557 }
1558 mutex_unlock(&open_close_lock);
1518} 1559}
1519 1560
1520 1561
diff --git a/drivers/media/radio/radio-terratec.c b/drivers/media/radio/radio-terratec.c
index 535ffe8c8102..acc32080e9bd 100644
--- a/drivers/media/radio/radio-terratec.c
+++ b/drivers/media/radio/radio-terratec.c
@@ -360,7 +360,9 @@ static const struct file_operations terratec_fops = {
360 .open = video_exclusive_open, 360 .open = video_exclusive_open,
361 .release = video_exclusive_release, 361 .release = video_exclusive_release,
362 .ioctl = video_ioctl2, 362 .ioctl = video_ioctl2,
363#ifdef CONFIG_COMPAT
363 .compat_ioctl = v4l_compat_ioctl32, 364 .compat_ioctl = v4l_compat_ioctl32,
365#endif
364 .llseek = no_llseek, 366 .llseek = no_llseek,
365}; 367};
366 368
diff --git a/drivers/media/radio/radio-trust.c b/drivers/media/radio/radio-trust.c
index c11981fed827..4ebdfbadeb9c 100644
--- a/drivers/media/radio/radio-trust.c
+++ b/drivers/media/radio/radio-trust.c
@@ -340,7 +340,9 @@ static const struct file_operations trust_fops = {
340 .open = video_exclusive_open, 340 .open = video_exclusive_open,
341 .release = video_exclusive_release, 341 .release = video_exclusive_release,
342 .ioctl = video_ioctl2, 342 .ioctl = video_ioctl2,
343#ifdef CONFIG_COMPAT
343 .compat_ioctl = v4l_compat_ioctl32, 344 .compat_ioctl = v4l_compat_ioctl32,
345#endif
344 .llseek = no_llseek, 346 .llseek = no_llseek,
345}; 347};
346 348
diff --git a/drivers/media/radio/radio-typhoon.c b/drivers/media/radio/radio-typhoon.c
index 1366326474e5..18f2abd7e255 100644
--- a/drivers/media/radio/radio-typhoon.c
+++ b/drivers/media/radio/radio-typhoon.c
@@ -35,6 +35,7 @@
35#include <linux/init.h> /* Initdata */ 35#include <linux/init.h> /* Initdata */
36#include <linux/ioport.h> /* request_region */ 36#include <linux/ioport.h> /* request_region */
37#include <linux/proc_fs.h> /* radio card status report */ 37#include <linux/proc_fs.h> /* radio card status report */
38#include <linux/seq_file.h>
38#include <asm/io.h> /* outb, outb_p */ 39#include <asm/io.h> /* outb, outb_p */
39#include <asm/uaccess.h> /* copy to/from user */ 40#include <asm/uaccess.h> /* copy to/from user */
40#include <linux/videodev2.h> /* kernel radio structs */ 41#include <linux/videodev2.h> /* kernel radio structs */
@@ -93,9 +94,6 @@ static int typhoon_setfreq(struct typhoon_device *dev, unsigned long frequency);
93static void typhoon_mute(struct typhoon_device *dev); 94static void typhoon_mute(struct typhoon_device *dev);
94static void typhoon_unmute(struct typhoon_device *dev); 95static void typhoon_unmute(struct typhoon_device *dev);
95static int typhoon_setvol(struct typhoon_device *dev, int vol); 96static int typhoon_setvol(struct typhoon_device *dev, int vol);
96#ifdef CONFIG_RADIO_TYPHOON_PROC_FS
97static int typhoon_get_info(char *buf, char **start, off_t offset, int len);
98#endif
99 97
100static void typhoon_setvol_generic(struct typhoon_device *dev, int vol) 98static void typhoon_setvol_generic(struct typhoon_device *dev, int vol)
101{ 99{
@@ -340,7 +338,9 @@ static const struct file_operations typhoon_fops = {
340 .open = video_exclusive_open, 338 .open = video_exclusive_open,
341 .release = video_exclusive_release, 339 .release = video_exclusive_release,
342 .ioctl = video_ioctl2, 340 .ioctl = video_ioctl2,
341#ifdef CONFIG_COMPAT
343 .compat_ioctl = v4l_compat_ioctl32, 342 .compat_ioctl = v4l_compat_ioctl32,
343#endif
344 .llseek = no_llseek, 344 .llseek = no_llseek,
345}; 345};
346 346
@@ -366,30 +366,39 @@ static struct video_device typhoon_radio =
366 366
367#ifdef CONFIG_RADIO_TYPHOON_PROC_FS 367#ifdef CONFIG_RADIO_TYPHOON_PROC_FS
368 368
369static int typhoon_get_info(char *buf, char **start, off_t offset, int len) 369static int typhoon_proc_show(struct seq_file *m, void *v)
370{ 370{
371 char *out = buf;
372
373 #ifdef MODULE 371 #ifdef MODULE
374 #define MODULEPROCSTRING "Driver loaded as a module" 372 #define MODULEPROCSTRING "Driver loaded as a module"
375 #else 373 #else
376 #define MODULEPROCSTRING "Driver compiled into kernel" 374 #define MODULEPROCSTRING "Driver compiled into kernel"
377 #endif 375 #endif
378 376
379 /* output must be kept under PAGE_SIZE */ 377 seq_puts(m, BANNER);
380 out += sprintf(out, BANNER); 378 seq_puts(m, "Load type: " MODULEPROCSTRING "\n\n");
381 out += sprintf(out, "Load type: " MODULEPROCSTRING "\n\n"); 379 seq_printf(m, "frequency = %lu kHz\n",
382 out += sprintf(out, "frequency = %lu kHz\n",
383 typhoon_unit.curfreq >> 4); 380 typhoon_unit.curfreq >> 4);
384 out += sprintf(out, "volume = %d\n", typhoon_unit.curvol); 381 seq_printf(m, "volume = %d\n", typhoon_unit.curvol);
385 out += sprintf(out, "mute = %s\n", typhoon_unit.muted ? 382 seq_printf(m, "mute = %s\n", typhoon_unit.muted ?
386 "on" : "off"); 383 "on" : "off");
387 out += sprintf(out, "iobase = 0x%x\n", typhoon_unit.iobase); 384 seq_printf(m, "iobase = 0x%x\n", typhoon_unit.iobase);
388 out += sprintf(out, "mute frequency = %lu kHz\n", 385 seq_printf(m, "mute frequency = %lu kHz\n",
389 typhoon_unit.mutefreq >> 4); 386 typhoon_unit.mutefreq >> 4);
390 return out - buf; 387 return 0;
391} 388}
392 389
390static int typhoon_proc_open(struct inode *inode, struct file *file)
391{
392 return single_open(file, typhoon_proc_show, NULL);
393}
394
395static const struct file_operations typhoon_proc_fops = {
396 .owner = THIS_MODULE,
397 .open = typhoon_proc_open,
398 .read = seq_read,
399 .llseek = seq_lseek,
400 .release = single_release,
401};
393#endif /* CONFIG_RADIO_TYPHOON_PROC_FS */ 402#endif /* CONFIG_RADIO_TYPHOON_PROC_FS */
394 403
395MODULE_AUTHOR("Dr. Henrik Seidel"); 404MODULE_AUTHOR("Dr. Henrik Seidel");
@@ -404,7 +413,7 @@ MODULE_PARM_DESC(io, "I/O address of the Typhoon card (0x316 or 0x336)");
404module_param(radio_nr, int, 0); 413module_param(radio_nr, int, 0);
405 414
406#ifdef MODULE 415#ifdef MODULE
407static unsigned long mutefreq = 0; 416static unsigned long mutefreq;
408module_param(mutefreq, ulong, 0); 417module_param(mutefreq, ulong, 0);
409MODULE_PARM_DESC(mutefreq, "Frequency used when muting the card (in kHz)"); 418MODULE_PARM_DESC(mutefreq, "Frequency used when muting the card (in kHz)");
410#endif 419#endif
@@ -450,8 +459,7 @@ static int __init typhoon_init(void)
450 typhoon_mute(&typhoon_unit); 459 typhoon_mute(&typhoon_unit);
451 460
452#ifdef CONFIG_RADIO_TYPHOON_PROC_FS 461#ifdef CONFIG_RADIO_TYPHOON_PROC_FS
453 if (!create_proc_info_entry("driver/radio-typhoon", 0, NULL, 462 if (!proc_create("driver/radio-typhoon", 0, NULL, &typhoon_proc_fops))
454 typhoon_get_info))
455 printk(KERN_ERR "radio-typhoon: registering /proc/driver/radio-typhoon failed\n"); 463 printk(KERN_ERR "radio-typhoon: registering /proc/driver/radio-typhoon failed\n");
456#endif 464#endif
457 465
diff --git a/drivers/media/radio/radio-zoltrix.c b/drivers/media/radio/radio-zoltrix.c
index 203f4373eeb8..43773c56c62f 100644
--- a/drivers/media/radio/radio-zoltrix.c
+++ b/drivers/media/radio/radio-zoltrix.c
@@ -401,7 +401,9 @@ static const struct file_operations zoltrix_fops =
401 .open = video_exclusive_open, 401 .open = video_exclusive_open,
402 .release = video_exclusive_release, 402 .release = video_exclusive_release,
403 .ioctl = video_ioctl2, 403 .ioctl = video_ioctl2,
404#ifdef CONFIG_COMPAT
404 .compat_ioctl = v4l_compat_ioctl32, 405 .compat_ioctl = v4l_compat_ioctl32,
406#endif
405 .llseek = no_llseek, 407 .llseek = no_llseek,
406}; 408};
407 409
diff --git a/drivers/media/video/Kconfig b/drivers/media/video/Kconfig
index 1832966f53f3..fe9a4cc14141 100644
--- a/drivers/media/video/Kconfig
+++ b/drivers/media/video/Kconfig
@@ -270,6 +270,15 @@ config VIDEO_SAA711X
270 To compile this driver as a module, choose M here: the 270 To compile this driver as a module, choose M here: the
271 module will be called saa7115. 271 module will be called saa7115.
272 272
273config VIDEO_SAA717X
274 tristate "Philips SAA7171/3/4 audio/video decoders"
275 depends on VIDEO_V4L2 && I2C
276 ---help---
277 Support for the Philips SAA7171/3/4 audio/video decoders.
278
279 To compile this driver as a module, choose M here: the
280 module will be called saa717x.
281
273config VIDEO_SAA7191 282config VIDEO_SAA7191
274 tristate "Philips SAA7191 video decoder" 283 tristate "Philips SAA7191 video decoder"
275 depends on VIDEO_V4L1 && I2C 284 depends on VIDEO_V4L1 && I2C
@@ -689,6 +698,8 @@ source "drivers/media/video/cx88/Kconfig"
689 698
690source "drivers/media/video/cx23885/Kconfig" 699source "drivers/media/video/cx23885/Kconfig"
691 700
701source "drivers/media/video/au0828/Kconfig"
702
692source "drivers/media/video/ivtv/Kconfig" 703source "drivers/media/video/ivtv/Kconfig"
693 704
694config VIDEO_M32R_AR 705config VIDEO_M32R_AR
@@ -836,4 +847,49 @@ config USB_STKWEBCAM
836 847
837endif # V4L_USB_DRIVERS 848endif # V4L_USB_DRIVERS
838 849
850config SOC_CAMERA
851 tristate "SoC camera support"
852 depends on VIDEO_V4L2
853 select VIDEOBUF_DMA_SG
854 help
855 SoC Camera is a common API to several cameras, not connecting
856 over a bus like PCI or USB. For example some i2c camera connected
857 directly to the data bus of an SoC.
858
859config SOC_CAMERA_MT9M001
860 tristate "mt9m001 support"
861 depends on SOC_CAMERA
862 select GPIO_PCA953X if MT9M001_PCA9536_SWITCH
863 help
864 This driver supports MT9M001 cameras from Micron, monochrome
865 and colour models.
866
867config MT9M001_PCA9536_SWITCH
868 bool "pca9536 datawidth switch for mt9m001"
869 depends on SOC_CAMERA_MT9M001 && GENERIC_GPIO
870 help
871 Select this if your MT9M001 camera uses a PCA9536 I2C GPIO
872 extender to switch between 8 and 10 bit datawidth modes
873
874config SOC_CAMERA_MT9V022
875 tristate "mt9v022 support"
876 depends on SOC_CAMERA
877 select GPIO_PCA953X if MT9V022_PCA9536_SWITCH
878 help
879 This driver supports MT9V022 cameras from Micron
880
881config MT9V022_PCA9536_SWITCH
882 bool "pca9536 datawidth switch for mt9v022"
883 depends on SOC_CAMERA_MT9V022 && GENERIC_GPIO
884 help
885 Select this if your MT9V022 camera uses a PCA9536 I2C GPIO
886 extender to switch between 8 and 10 bit datawidth modes
887
888config VIDEO_PXA27x
889 tristate "PXA27x Quick Capture Interface driver"
890 depends on VIDEO_DEV && PXA27x
891 select SOC_CAMERA
892 ---help---
893 This is a v4l2 driver for the PXA27x Quick Capture Interface
894
839endif # VIDEO_CAPTURE_DRIVERS 895endif # VIDEO_CAPTURE_DRIVERS
diff --git a/drivers/media/video/Makefile b/drivers/media/video/Makefile
index 3f209b32eeac..be14227f3726 100644
--- a/drivers/media/video/Makefile
+++ b/drivers/media/video/Makefile
@@ -4,7 +4,7 @@
4 4
5zr36067-objs := zoran_procfs.o zoran_device.o \ 5zr36067-objs := zoran_procfs.o zoran_device.o \
6 zoran_driver.o zoran_card.o 6 zoran_driver.o zoran_card.o
7tuner-objs := tuner-core.o tuner-types.o 7tuner-objs := tuner-core.o
8 8
9msp3400-objs := msp3400-driver.o msp3400-kthreads.o 9msp3400-objs := msp3400-driver.o msp3400-kthreads.o
10 10
@@ -38,6 +38,7 @@ obj-$(CONFIG_VIDEO_SAA7110) += saa7110.o
38obj-$(CONFIG_VIDEO_SAA7111) += saa7111.o 38obj-$(CONFIG_VIDEO_SAA7111) += saa7111.o
39obj-$(CONFIG_VIDEO_SAA7114) += saa7114.o 39obj-$(CONFIG_VIDEO_SAA7114) += saa7114.o
40obj-$(CONFIG_VIDEO_SAA711X) += saa7115.o 40obj-$(CONFIG_VIDEO_SAA711X) += saa7115.o
41obj-$(CONFIG_VIDEO_SAA717X) += saa717x.o
41obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o 42obj-$(CONFIG_VIDEO_SAA7127) += saa7127.o
42obj-$(CONFIG_VIDEO_SAA7185) += saa7185.o 43obj-$(CONFIG_VIDEO_SAA7185) += saa7185.o
43obj-$(CONFIG_VIDEO_SAA7191) += saa7191.o 44obj-$(CONFIG_VIDEO_SAA7191) += saa7191.o
@@ -87,6 +88,8 @@ obj-$(CONFIG_VIDEO_TUNER) += tuner.o
87 88
88obj-$(CONFIG_TUNER_XC2028) += tuner-xc2028.o 89obj-$(CONFIG_TUNER_XC2028) += tuner-xc2028.o
89obj-$(CONFIG_TUNER_SIMPLE) += tuner-simple.o 90obj-$(CONFIG_TUNER_SIMPLE) += tuner-simple.o
91# tuner-types will be merged into tuner-simple, in the future
92obj-$(CONFIG_TUNER_SIMPLE) += tuner-types.o
90obj-$(CONFIG_TUNER_MT20XX) += mt20xx.o 93obj-$(CONFIG_TUNER_MT20XX) += mt20xx.o
91obj-$(CONFIG_TUNER_TDA8290) += tda8290.o 94obj-$(CONFIG_TUNER_TDA8290) += tda8290.o
92obj-$(CONFIG_TUNER_TEA5767) += tea5767.o 95obj-$(CONFIG_TUNER_TEA5767) += tea5767.o
@@ -135,5 +138,12 @@ obj-$(CONFIG_VIDEO_IVTV) += ivtv/
135obj-$(CONFIG_VIDEO_VIVI) += vivi.o 138obj-$(CONFIG_VIDEO_VIVI) += vivi.o
136obj-$(CONFIG_VIDEO_CX23885) += cx23885/ 139obj-$(CONFIG_VIDEO_CX23885) += cx23885/
137 140
141obj-$(CONFIG_VIDEO_PXA27x) += pxa_camera.o
142obj-$(CONFIG_SOC_CAMERA) += soc_camera.o
143obj-$(CONFIG_SOC_CAMERA_MT9M001) += mt9m001.o
144obj-$(CONFIG_SOC_CAMERA_MT9V022) += mt9v022.o
145
146obj-$(CONFIG_VIDEO_AU0828) += au0828/
147
138EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core 148EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
139EXTRA_CFLAGS += -Idrivers/media/dvb/frontends 149EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
diff --git a/drivers/media/video/adv7170.c b/drivers/media/video/adv7170.c
index fea2e723e34b..f794f2dbfb32 100644
--- a/drivers/media/video/adv7170.c
+++ b/drivers/media/video/adv7170.c
@@ -56,7 +56,7 @@ MODULE_LICENSE("GPL");
56#define I2C_NAME(x) (x)->name 56#define I2C_NAME(x) (x)->name
57 57
58 58
59static int debug = 0; 59static int debug;
60module_param(debug, int, 0); 60module_param(debug, int, 0);
61MODULE_PARM_DESC(debug, "Debug level (0-1)"); 61MODULE_PARM_DESC(debug, "Debug level (0-1)");
62 62
diff --git a/drivers/media/video/adv7175.c b/drivers/media/video/adv7175.c
index 10d4d89623f1..8ee07a68f702 100644
--- a/drivers/media/video/adv7175.c
+++ b/drivers/media/video/adv7175.c
@@ -52,7 +52,7 @@ MODULE_LICENSE("GPL");
52#define I2C_NAME(s) (s)->name 52#define I2C_NAME(s) (s)->name
53 53
54 54
55static int debug = 0; 55static int debug;
56module_param(debug, int, 0); 56module_param(debug, int, 0);
57MODULE_PARM_DESC(debug, "Debug level (0-1)"); 57MODULE_PARM_DESC(debug, "Debug level (0-1)");
58 58
diff --git a/drivers/media/video/arv.c b/drivers/media/video/arv.c
index c94a4d0f2804..8c7d1958856b 100644
--- a/drivers/media/video/arv.c
+++ b/drivers/media/video/arv.c
@@ -125,8 +125,8 @@ static unsigned char yuv[MAX_AR_FRAME_BYTES];
125/* default frequency */ 125/* default frequency */
126#define DEFAULT_FREQ 50 /* 50 or 75 (MHz) is available as BCLK */ 126#define DEFAULT_FREQ 50 /* 50 or 75 (MHz) is available as BCLK */
127static int freq = DEFAULT_FREQ; /* BCLK: available 50 or 70 (MHz) */ 127static int freq = DEFAULT_FREQ; /* BCLK: available 50 or 70 (MHz) */
128static int vga = 0; /* default mode(0:QVGA mode, other:VGA mode) */ 128static int vga; /* default mode(0:QVGA mode, other:VGA mode) */
129static int vga_interlace = 0; /* 0 is normal mode for, else interlace mode */ 129static int vga_interlace; /* 0 is normal mode for, else interlace mode */
130module_param(freq, int, 0); 130module_param(freq, int, 0);
131module_param(vga, int, 0); 131module_param(vga, int, 0);
132module_param(vga_interlace, int, 0); 132module_param(vga_interlace, int, 0);
@@ -747,7 +747,9 @@ static const struct file_operations ar_fops = {
747 .release = video_exclusive_release, 747 .release = video_exclusive_release,
748 .read = ar_read, 748 .read = ar_read,
749 .ioctl = ar_ioctl, 749 .ioctl = ar_ioctl,
750#ifdef CONFIG_COMPAT
750 .compat_ioctl = v4l_compat_ioctl32, 751 .compat_ioctl = v4l_compat_ioctl32,
752#endif
751 .llseek = no_llseek, 753 .llseek = no_llseek,
752}; 754};
753 755
diff --git a/drivers/media/video/au0828/Kconfig b/drivers/media/video/au0828/Kconfig
new file mode 100644
index 000000000000..c97c4bd24841
--- /dev/null
+++ b/drivers/media/video/au0828/Kconfig
@@ -0,0 +1,12 @@
1
2config VIDEO_AU0828
3 tristate "Auvitek AU0828 support"
4 depends on VIDEO_DEV && I2C && INPUT
5 select I2C_ALGOBIT
6 select DVB_AU8522 if !DVB_FE_CUSTOMIZE
7 select DVB_TUNER_XC5000 if !DVB_FE_CUSTOMIZE
8 ---help---
9 This is a video4linux driver for Auvitek's USB device.
10
11 To compile this driver as a module, choose M here: the
12 module will be called au0828
diff --git a/drivers/media/video/au0828/Makefile b/drivers/media/video/au0828/Makefile
new file mode 100644
index 000000000000..9f4f572c89c5
--- /dev/null
+++ b/drivers/media/video/au0828/Makefile
@@ -0,0 +1,9 @@
1au0828-objs := au0828-core.o au0828-i2c.o au0828-cards.o au0828-dvb.o
2
3obj-$(CONFIG_VIDEO_AU0828) += au0828.o
4
5EXTRA_CFLAGS += -Idrivers/media/video
6EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
7EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
8
9EXTRA_CFLAGS += $(extra-cflags-y) $(extra-cflags-m)
diff --git a/drivers/media/video/au0828/au0828-cards.c b/drivers/media/video/au0828/au0828-cards.c
new file mode 100644
index 000000000000..8ca91f814277
--- /dev/null
+++ b/drivers/media/video/au0828/au0828-cards.c
@@ -0,0 +1,182 @@
1/*
2 * Driver for the Auvitek USB bridge
3 *
4 * Copyright (c) 2008 Steven Toth <stoth@hauppauge.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include "au0828.h"
23#include "au0828-cards.h"
24
25struct au0828_board au0828_boards[] = {
26 [AU0828_BOARD_UNKNOWN] = {
27 .name = "Unknown board",
28 },
29 [AU0828_BOARD_HAUPPAUGE_HVR850] = {
30 .name = "Hauppauge HVR850",
31 },
32 [AU0828_BOARD_HAUPPAUGE_HVR950Q] = {
33 .name = "Hauppauge HVR950Q",
34 },
35 [AU0828_BOARD_DVICO_FUSIONHDTV7] = {
36 .name = "DViCO FusionHDTV USB",
37 },
38};
39const unsigned int au0828_bcount = ARRAY_SIZE(au0828_boards);
40
41/* Tuner callback function for au0828 boards. Currently only needed
42 * for HVR1500Q, which has an xc5000 tuner.
43 */
44int au0828_tuner_callback(void *priv, int command, int arg)
45{
46 struct au0828_dev *dev = priv;
47
48 dprintk(1, "%s()\n", __func__);
49
50 switch (dev->board) {
51 case AU0828_BOARD_HAUPPAUGE_HVR850:
52 case AU0828_BOARD_HAUPPAUGE_HVR950Q:
53 case AU0828_BOARD_DVICO_FUSIONHDTV7:
54 if (command == 0) {
55 /* Tuner Reset Command from xc5000 */
56 /* Drive the tuner into reset and out */
57 au0828_clear(dev, REG_001, 2);
58 mdelay(200);
59 au0828_set(dev, REG_001, 2);
60 mdelay(50);
61 return 0;
62 } else {
63 printk(KERN_ERR
64 "%s(): Unknown command.\n", __func__);
65 return -EINVAL;
66 }
67 break;
68 }
69
70 return 0; /* Should never be here */
71}
72
73static void hauppauge_eeprom(struct au0828_dev *dev, u8 *eeprom_data)
74{
75 struct tveeprom tv;
76
77 tveeprom_hauppauge_analog(&dev->i2c_client, &tv, eeprom_data);
78
79 /* Make sure we support the board model */
80 switch (tv.model) {
81 case 72001: /* WinTV-HVR950q (Retail, IR, ATSC/QAM and basic analog video */
82 case 72301: /* WinTV-HVR850 (Retail, IR, ATSC and basic analog video */
83 break;
84 default:
85 printk(KERN_WARNING "%s: warning: "
86 "unknown hauppauge model #%d\n", __func__, tv.model);
87 break;
88 }
89
90 printk(KERN_INFO "%s: hauppauge eeprom: model=%d\n",
91 __func__, tv.model);
92}
93
94void au0828_card_setup(struct au0828_dev *dev)
95{
96 static u8 eeprom[256];
97
98 dprintk(1, "%s()\n", __func__);
99
100 if (dev->i2c_rc == 0) {
101 dev->i2c_client.addr = 0xa0 >> 1;
102 tveeprom_read(&dev->i2c_client, eeprom, sizeof(eeprom));
103 }
104
105 switch (dev->board) {
106 case AU0828_BOARD_HAUPPAUGE_HVR850:
107 case AU0828_BOARD_HAUPPAUGE_HVR950Q:
108 if (dev->i2c_rc == 0)
109 hauppauge_eeprom(dev, eeprom+0xa0);
110 break;
111 }
112}
113
114/*
115 * The bridge has between 8 and 12 gpios.
116 * Regs 1 and 0 deal with output enables.
117 * Regs 3 and 2 deal with direction.
118 */
119void au0828_gpio_setup(struct au0828_dev *dev)
120{
121 dprintk(1, "%s()\n", __func__);
122
123 switch (dev->board) {
124 case AU0828_BOARD_HAUPPAUGE_HVR850:
125 case AU0828_BOARD_HAUPPAUGE_HVR950Q:
126 /* GPIO's
127 * 4 - CS5340
128 * 5 - AU8522 Demodulator
129 * 6 - eeprom W/P
130 * 9 - XC5000 Tuner
131 */
132
133 /* Into reset */
134 au0828_write(dev, REG_003, 0x02);
135 au0828_write(dev, REG_002, 0x88 | 0x20);
136 au0828_write(dev, REG_001, 0x0);
137 au0828_write(dev, REG_000, 0x0);
138 msleep(100);
139
140 /* Out of reset */
141 au0828_write(dev, REG_003, 0x02);
142 au0828_write(dev, REG_001, 0x02);
143 au0828_write(dev, REG_002, 0x88 | 0x20);
144 au0828_write(dev, REG_000, 0x88 | 0x20 | 0x40);
145 msleep(250);
146 break;
147 case AU0828_BOARD_DVICO_FUSIONHDTV7:
148 /* GPIO's
149 * 6 - ?
150 * 8 - AU8522 Demodulator
151 * 9 - XC5000 Tuner
152 */
153
154 /* Into reset */
155 au0828_write(dev, REG_003, 0x02);
156 au0828_write(dev, REG_002, 0xa0);
157 au0828_write(dev, REG_001, 0x0);
158 au0828_write(dev, REG_000, 0x0);
159 msleep(100);
160
161 /* Out of reset */
162 au0828_write(dev, REG_003, 0x02);
163 au0828_write(dev, REG_002, 0xa0);
164 au0828_write(dev, REG_001, 0x02);
165 au0828_write(dev, REG_000, 0xa0);
166 msleep(250);
167 break;
168 }
169}
170
171/* table of devices that work with this driver */
172struct usb_device_id au0828_usb_id_table [] = {
173 { USB_DEVICE(0x2040, 0x7200),
174 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR950Q },
175 { USB_DEVICE(0x2040, 0x7240),
176 .driver_info = AU0828_BOARD_HAUPPAUGE_HVR850 },
177 { USB_DEVICE(0x0fe9, 0xd620),
178 .driver_info = AU0828_BOARD_DVICO_FUSIONHDTV7 },
179 { },
180};
181
182MODULE_DEVICE_TABLE(usb, au0828_usb_id_table);
diff --git a/drivers/media/video/au0828/au0828-cards.h b/drivers/media/video/au0828/au0828-cards.h
new file mode 100644
index 000000000000..e26f54a961d0
--- /dev/null
+++ b/drivers/media/video/au0828/au0828-cards.h
@@ -0,0 +1,25 @@
1/*
2 * Driver for the Auvitek USB bridge
3 *
4 * Copyright (c) 2008 Steven Toth <stoth@hauppauge.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#define AU0828_BOARD_UNKNOWN 0
23#define AU0828_BOARD_HAUPPAUGE_HVR950Q 1
24#define AU0828_BOARD_HAUPPAUGE_HVR850 2
25#define AU0828_BOARD_DVICO_FUSIONHDTV7 3
diff --git a/drivers/media/video/au0828/au0828-core.c b/drivers/media/video/au0828/au0828-core.c
new file mode 100644
index 000000000000..e65d5642cb1d
--- /dev/null
+++ b/drivers/media/video/au0828/au0828-core.c
@@ -0,0 +1,270 @@
1/*
2 * Driver for the Auvitek USB bridge
3 *
4 * Copyright (c) 2008 Steven Toth <stoth@hauppauge.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include <linux/module.h>
23#include <linux/videodev2.h>
24#include <media/v4l2-common.h>
25#include <linux/mutex.h>
26
27#include "au0828.h"
28
29/*
30 * 1 = General debug messages
31 * 2 = USB handling
32 * 4 = I2C related
33 * 8 = Bridge related
34 */
35unsigned int debug;
36module_param(debug, int, 0644);
37MODULE_PARM_DESC(debug, "enable debug messages");
38
39unsigned int usb_debug;
40module_param(usb_debug, int, 0644);
41MODULE_PARM_DESC(usb_debug, "enable usb debug messages");
42
43unsigned int bridge_debug;
44module_param(bridge_debug, int, 0644);
45MODULE_PARM_DESC(bridge_debug, "enable bridge debug messages");
46
47#define _AU0828_BULKPIPE 0x03
48#define _BULKPIPESIZE 0xffff
49
50static int send_control_msg(struct au0828_dev *dev, u16 request, u32 value,
51 u16 index, unsigned char *cp, u16 size);
52static int recv_control_msg(struct au0828_dev *dev, u16 request, u32 value,
53 u16 index, unsigned char *cp, u16 size);
54
55/* USB Direction */
56#define CMD_REQUEST_IN 0x00
57#define CMD_REQUEST_OUT 0x01
58
59u32 au0828_readreg(struct au0828_dev *dev, u16 reg)
60{
61 recv_control_msg(dev, CMD_REQUEST_IN, 0, reg, dev->ctrlmsg, 1);
62 dprintk(8, "%s(0x%x) = 0x%x\n", __func__, reg, dev->ctrlmsg[0]);
63 return dev->ctrlmsg[0];
64}
65
66u32 au0828_writereg(struct au0828_dev *dev, u16 reg, u32 val)
67{
68 dprintk(8, "%s(0x%x, 0x%x)\n", __func__, reg, val);
69 return send_control_msg(dev, CMD_REQUEST_OUT, val, reg,
70 dev->ctrlmsg, 0);
71}
72
73static void cmd_msg_dump(struct au0828_dev *dev)
74{
75 int i;
76
77 for (i = 0; i < sizeof(dev->ctrlmsg); i += 16)
78 dprintk(2, "%s() %02x %02x %02x %02x %02x %02x %02x %02x "
79 "%02x %02x %02x %02x %02x %02x %02x %02x\n",
80 __func__,
81 dev->ctrlmsg[i+0], dev->ctrlmsg[i+1],
82 dev->ctrlmsg[i+2], dev->ctrlmsg[i+3],
83 dev->ctrlmsg[i+4], dev->ctrlmsg[i+5],
84 dev->ctrlmsg[i+6], dev->ctrlmsg[i+7],
85 dev->ctrlmsg[i+8], dev->ctrlmsg[i+9],
86 dev->ctrlmsg[i+10], dev->ctrlmsg[i+11],
87 dev->ctrlmsg[i+12], dev->ctrlmsg[i+13],
88 dev->ctrlmsg[i+14], dev->ctrlmsg[i+15]);
89}
90
91static int send_control_msg(struct au0828_dev *dev, u16 request, u32 value,
92 u16 index, unsigned char *cp, u16 size)
93{
94 int status = -ENODEV;
95 mutex_lock(&dev->mutex);
96 if (dev->usbdev) {
97
98 /* cp must be memory that has been allocated by kmalloc */
99 status = usb_control_msg(dev->usbdev,
100 usb_sndctrlpipe(dev->usbdev, 0),
101 request,
102 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
103 value, index,
104 cp, size, 1000);
105
106 status = min(status, 0);
107
108 if (status < 0) {
109 printk(KERN_ERR "%s() Failed sending control message, error %d.\n",
110 __func__, status);
111 }
112
113 }
114 mutex_unlock(&dev->mutex);
115 return status;
116}
117
118static int recv_control_msg(struct au0828_dev *dev, u16 request, u32 value,
119 u16 index, unsigned char *cp, u16 size)
120{
121 int status = -ENODEV;
122 mutex_lock(&dev->mutex);
123 if (dev->usbdev) {
124
125 memset(dev->ctrlmsg, 0, sizeof(dev->ctrlmsg));
126
127 /* cp must be memory that has been allocated by kmalloc */
128 status = usb_control_msg(dev->usbdev,
129 usb_rcvctrlpipe(dev->usbdev, 0),
130 request,
131 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
132 value, index,
133 cp, size, 1000);
134
135 status = min(status, 0);
136
137 if (status < 0) {
138 printk(KERN_ERR "%s() Failed receiving control message, error %d.\n",
139 __func__, status);
140 } else
141 cmd_msg_dump(dev);
142 }
143 mutex_unlock(&dev->mutex);
144 return status;
145}
146
147static void au0828_usb_disconnect(struct usb_interface *interface)
148{
149 struct au0828_dev *dev = usb_get_intfdata(interface);
150
151 dprintk(1, "%s()\n", __func__);
152
153 /* Digital TV */
154 au0828_dvb_unregister(dev);
155
156 /* I2C */
157 au0828_i2c_unregister(dev);
158
159 usb_set_intfdata(interface, NULL);
160
161 mutex_lock(&dev->mutex);
162 dev->usbdev = NULL;
163 mutex_unlock(&dev->mutex);
164
165 kfree(dev);
166
167}
168
169static int au0828_usb_probe(struct usb_interface *interface,
170 const struct usb_device_id *id)
171{
172 int ifnum;
173 struct au0828_dev *dev;
174 struct usb_device *usbdev = interface_to_usbdev(interface);
175
176 ifnum = interface->altsetting->desc.bInterfaceNumber;
177
178 if (ifnum != 0)
179 return -ENODEV;
180
181 dprintk(1, "%s() vendor id 0x%x device id 0x%x ifnum:%d\n", __func__,
182 le16_to_cpu(usbdev->descriptor.idVendor),
183 le16_to_cpu(usbdev->descriptor.idProduct),
184 ifnum);
185
186 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
187 if (dev == NULL) {
188 printk(KERN_ERR "%s() Unable to allocate memory\n", __func__);
189 return -ENOMEM;
190 }
191
192 mutex_init(&dev->mutex);
193 mutex_init(&dev->dvb.lock);
194 dev->usbdev = usbdev;
195 dev->board = id->driver_info;
196
197 usb_set_intfdata(interface, dev);
198
199 /* Power Up the bridge */
200 au0828_write(dev, REG_600, 1 << 4);
201
202 /* Bring up the GPIO's and supporting devices */
203 au0828_gpio_setup(dev);
204
205 /* I2C */
206 au0828_i2c_register(dev);
207
208 /* Setup */
209 au0828_card_setup(dev);
210
211 /* Digital TV */
212 au0828_dvb_register(dev);
213
214 printk(KERN_INFO "Registered device AU0828 [%s]\n",
215 au0828_boards[dev->board].name == NULL ? "Unset" :
216 au0828_boards[dev->board].name);
217
218 return 0;
219}
220
221static struct usb_driver au0828_usb_driver = {
222 .name = DRIVER_NAME,
223 .probe = au0828_usb_probe,
224 .disconnect = au0828_usb_disconnect,
225 .id_table = au0828_usb_id_table,
226};
227
228static int __init au0828_init(void)
229{
230 int ret;
231
232 if (debug)
233 printk(KERN_INFO "%s() Debugging is enabled\n", __func__);
234
235 if (usb_debug) {
236 printk(KERN_INFO "%s() USB Debugging is enabled\n", __func__);
237 debug |= 2;
238 }
239
240 if (i2c_debug) {
241 printk(KERN_INFO "%s() I2C Debugging is enabled\n", __func__);
242 debug |= 4;
243 }
244
245 if (bridge_debug) {
246 printk(KERN_INFO "%s() Bridge Debugging is enabled\n",
247 __func__);
248 debug |= 8;
249 }
250
251 printk(KERN_INFO "au0828 driver loaded\n");
252
253 ret = usb_register(&au0828_usb_driver);
254 if (ret)
255 printk(KERN_ERR "usb_register failed, error = %d\n", ret);
256
257 return ret;
258}
259
260static void __exit au0828_exit(void)
261{
262 usb_deregister(&au0828_usb_driver);
263}
264
265module_init(au0828_init);
266module_exit(au0828_exit);
267
268MODULE_DESCRIPTION("Driver for Auvitek AU0828 based products");
269MODULE_AUTHOR("Steven Toth <stoth@hauppauge.com>");
270MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/au0828/au0828-dvb.c b/drivers/media/video/au0828/au0828-dvb.c
new file mode 100644
index 000000000000..85d0ae9a322f
--- /dev/null
+++ b/drivers/media/video/au0828/au0828-dvb.c
@@ -0,0 +1,373 @@
1/*
2 * Driver for the Auvitek USB bridge
3 *
4 * Copyright (c) 2008 Steven Toth <stoth@hauppauge.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include <linux/module.h>
23#include <linux/init.h>
24#include <linux/device.h>
25#include <linux/suspend.h>
26#include <media/v4l2-common.h>
27
28#include "au0828.h"
29#include "au8522.h"
30#include "xc5000.h"
31
32DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
33
34#define _AU0828_BULKPIPE 0x83
35#define _BULKPIPESIZE 0xe522
36
37static struct au8522_config hauppauge_hvr950q_config = {
38 .demod_address = 0x8e >> 1,
39 .status_mode = AU8522_DEMODLOCKING,
40};
41
42static struct xc5000_config hauppauge_hvr950q_tunerconfig = {
43 .i2c_address = 0x61,
44 .if_khz = 6000,
45 .tuner_callback = au0828_tuner_callback
46};
47
48/*-------------------------------------------------------------------*/
49static void urb_completion(struct urb *purb)
50{
51 u8 *ptr;
52 struct au0828_dev *dev = purb->context;
53 int ptype = usb_pipetype(purb->pipe);
54
55 dprintk(2, "%s()\n", __func__);
56
57 if (!dev)
58 return;
59
60 if (dev->urb_streaming == 0)
61 return;
62
63 if (ptype != PIPE_BULK) {
64 printk(KERN_ERR "%s() Unsupported URB type %d\n",
65 __func__, ptype);
66 return;
67 }
68
69 ptr = (u8 *)purb->transfer_buffer;
70
71 /* Feed the transport payload into the kernel demux */
72 dvb_dmx_swfilter_packets(&dev->dvb.demux,
73 purb->transfer_buffer, purb->actual_length / 188);
74
75 /* Clean the buffer before we requeue */
76 memset(purb->transfer_buffer, 0, URB_BUFSIZE);
77
78 /* Requeue URB */
79 usb_submit_urb(purb, GFP_ATOMIC);
80}
81
82static int stop_urb_transfer(struct au0828_dev *dev)
83{
84 int i;
85
86 dprintk(2, "%s()\n", __func__);
87
88 for (i = 0; i < URB_COUNT; i++) {
89 usb_kill_urb(dev->urbs[i]);
90 kfree(dev->urbs[i]->transfer_buffer);
91 usb_free_urb(dev->urbs[i]);
92 }
93
94 dev->urb_streaming = 0;
95
96 return 0;
97}
98
99static int start_urb_transfer(struct au0828_dev *dev)
100{
101 struct urb *purb;
102 int i, ret = -ENOMEM;
103
104 dprintk(2, "%s()\n", __func__);
105
106 if (dev->urb_streaming) {
107 dprintk(2, "%s: iso xfer already running!\n", __func__);
108 return 0;
109 }
110
111 for (i = 0; i < URB_COUNT; i++) {
112
113 dev->urbs[i] = usb_alloc_urb(0, GFP_KERNEL);
114 if (!dev->urbs[i])
115 goto err;
116
117 purb = dev->urbs[i];
118
119 purb->transfer_buffer = kzalloc(URB_BUFSIZE, GFP_KERNEL);
120 if (!purb->transfer_buffer) {
121 usb_free_urb(purb);
122 dev->urbs[i] = 0;
123 goto err;
124 }
125
126 purb->status = -EINPROGRESS;
127 usb_fill_bulk_urb(purb,
128 dev->usbdev,
129 usb_rcvbulkpipe(dev->usbdev, _AU0828_BULKPIPE),
130 purb->transfer_buffer,
131 URB_BUFSIZE,
132 urb_completion,
133 dev);
134
135 }
136
137 for (i = 0; i < URB_COUNT; i++) {
138 ret = usb_submit_urb(dev->urbs[i], GFP_ATOMIC);
139 if (ret != 0) {
140 stop_urb_transfer(dev);
141 printk(KERN_ERR "%s: failed urb submission, "
142 "err = %d\n", __func__, ret);
143 return ret;
144 }
145 }
146
147 dev->urb_streaming = 1;
148 ret = 0;
149
150err:
151 return ret;
152}
153
154static int au0828_dvb_start_feed(struct dvb_demux_feed *feed)
155{
156 struct dvb_demux *demux = feed->demux;
157 struct au0828_dev *dev = (struct au0828_dev *) demux->priv;
158 struct au0828_dvb *dvb = &dev->dvb;
159 int ret = 0;
160
161 dprintk(1, "%s()\n", __func__);
162
163 if (!demux->dmx.frontend)
164 return -EINVAL;
165
166 if (dvb) {
167 mutex_lock(&dvb->lock);
168 if (dvb->feeding++ == 0) {
169 /* Start transport */
170 au0828_write(dev, 0x608, 0x90);
171 au0828_write(dev, 0x609, 0x72);
172 au0828_write(dev, 0x60a, 0x71);
173 au0828_write(dev, 0x60b, 0x01);
174 ret = start_urb_transfer(dev);
175 }
176 mutex_unlock(&dvb->lock);
177 }
178
179 return ret;
180}
181
182static int au0828_dvb_stop_feed(struct dvb_demux_feed *feed)
183{
184 struct dvb_demux *demux = feed->demux;
185 struct au0828_dev *dev = (struct au0828_dev *) demux->priv;
186 struct au0828_dvb *dvb = &dev->dvb;
187 int ret = 0;
188
189 dprintk(1, "%s()\n", __func__);
190
191 if (dvb) {
192 mutex_lock(&dvb->lock);
193 if (--dvb->feeding == 0) {
194 /* Stop transport */
195 au0828_write(dev, 0x608, 0x00);
196 au0828_write(dev, 0x609, 0x00);
197 au0828_write(dev, 0x60a, 0x00);
198 au0828_write(dev, 0x60b, 0x00);
199 ret = stop_urb_transfer(dev);
200 }
201 mutex_unlock(&dvb->lock);
202 }
203
204 return ret;
205}
206
207int dvb_register(struct au0828_dev *dev)
208{
209 struct au0828_dvb *dvb = &dev->dvb;
210 int result;
211
212 dprintk(1, "%s()\n", __func__);
213
214 /* register adapter */
215 result = dvb_register_adapter(&dvb->adapter, DRIVER_NAME, THIS_MODULE,
216 &dev->usbdev->dev, adapter_nr);
217 if (result < 0) {
218 printk(KERN_ERR "%s: dvb_register_adapter failed "
219 "(errno = %d)\n", DRIVER_NAME, result);
220 goto fail_adapter;
221 }
222 dvb->adapter.priv = dev;
223
224 /* register frontend */
225 result = dvb_register_frontend(&dvb->adapter, dvb->frontend);
226 if (result < 0) {
227 printk(KERN_ERR "%s: dvb_register_frontend failed "
228 "(errno = %d)\n", DRIVER_NAME, result);
229 goto fail_frontend;
230 }
231
232 /* register demux stuff */
233 dvb->demux.dmx.capabilities =
234 DMX_TS_FILTERING | DMX_SECTION_FILTERING |
235 DMX_MEMORY_BASED_FILTERING;
236 dvb->demux.priv = dev;
237 dvb->demux.filternum = 256;
238 dvb->demux.feednum = 256;
239 dvb->demux.start_feed = au0828_dvb_start_feed;
240 dvb->demux.stop_feed = au0828_dvb_stop_feed;
241 result = dvb_dmx_init(&dvb->demux);
242 if (result < 0) {
243 printk(KERN_ERR "%s: dvb_dmx_init failed (errno = %d)\n",
244 DRIVER_NAME, result);
245 goto fail_dmx;
246 }
247
248 dvb->dmxdev.filternum = 256;
249 dvb->dmxdev.demux = &dvb->demux.dmx;
250 dvb->dmxdev.capabilities = 0;
251 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
252 if (result < 0) {
253 printk(KERN_ERR "%s: dvb_dmxdev_init failed (errno = %d)\n",
254 DRIVER_NAME, result);
255 goto fail_dmxdev;
256 }
257
258 dvb->fe_hw.source = DMX_FRONTEND_0;
259 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
260 if (result < 0) {
261 printk(KERN_ERR "%s: add_frontend failed "
262 "(DMX_FRONTEND_0, errno = %d)\n", DRIVER_NAME, result);
263 goto fail_fe_hw;
264 }
265
266 dvb->fe_mem.source = DMX_MEMORY_FE;
267 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
268 if (result < 0) {
269 printk(KERN_ERR "%s: add_frontend failed "
270 "(DMX_MEMORY_FE, errno = %d)\n", DRIVER_NAME, result);
271 goto fail_fe_mem;
272 }
273
274 result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
275 if (result < 0) {
276 printk(KERN_ERR "%s: connect_frontend failed (errno = %d)\n",
277 DRIVER_NAME, result);
278 goto fail_fe_conn;
279 }
280
281 /* register network adapter */
282 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
283 return 0;
284
285fail_fe_conn:
286 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
287fail_fe_mem:
288 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
289fail_fe_hw:
290 dvb_dmxdev_release(&dvb->dmxdev);
291fail_dmxdev:
292 dvb_dmx_release(&dvb->demux);
293fail_dmx:
294 dvb_unregister_frontend(dvb->frontend);
295fail_frontend:
296 dvb_frontend_detach(dvb->frontend);
297 dvb_unregister_adapter(&dvb->adapter);
298fail_adapter:
299 return result;
300}
301
302void au0828_dvb_unregister(struct au0828_dev *dev)
303{
304 struct au0828_dvb *dvb = &dev->dvb;
305
306 dprintk(1, "%s()\n", __func__);
307
308 if (dvb->frontend == NULL)
309 return;
310
311 dvb_net_release(&dvb->net);
312 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
313 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
314 dvb_dmxdev_release(&dvb->dmxdev);
315 dvb_dmx_release(&dvb->demux);
316 dvb_unregister_frontend(dvb->frontend);
317 dvb_frontend_detach(dvb->frontend);
318 dvb_unregister_adapter(&dvb->adapter);
319}
320
321/* All the DVB attach calls go here, this function get's modified
322 * for each new card. No other function in this file needs
323 * to change.
324 */
325int au0828_dvb_register(struct au0828_dev *dev)
326{
327 struct au0828_dvb *dvb = &dev->dvb;
328 int ret;
329
330 dprintk(1, "%s()\n", __func__);
331
332 /* init frontend */
333 switch (dev->board) {
334 case AU0828_BOARD_HAUPPAUGE_HVR850:
335 case AU0828_BOARD_HAUPPAUGE_HVR950Q:
336 case AU0828_BOARD_DVICO_FUSIONHDTV7:
337 dvb->frontend = dvb_attach(au8522_attach,
338 &hauppauge_hvr950q_config,
339 &dev->i2c_adap);
340 if (dvb->frontend != NULL) {
341 hauppauge_hvr950q_tunerconfig.priv = dev;
342 dvb_attach(xc5000_attach, dvb->frontend,
343 &dev->i2c_adap,
344 &hauppauge_hvr950q_tunerconfig);
345 }
346 break;
347 default:
348 printk(KERN_WARNING "The frontend of your DVB/ATSC card "
349 "isn't supported yet\n");
350 break;
351 }
352 if (NULL == dvb->frontend) {
353 printk(KERN_ERR "%s() Frontend initialization failed\n",
354 __func__);
355 return -1;
356 }
357
358 /* Put the analog decoder in standby to keep it quiet */
359 au0828_call_i2c_clients(dev, TUNER_SET_STANDBY, NULL);
360
361 if (dvb->frontend->ops.analog_ops.standby)
362 dvb->frontend->ops.analog_ops.standby(dvb->frontend);
363
364 /* register everything */
365 ret = dvb_register(dev);
366 if (ret < 0) {
367 if (dvb->frontend->ops.release)
368 dvb->frontend->ops.release(dvb->frontend);
369 return ret;
370 }
371
372 return 0;
373}
diff --git a/drivers/media/video/au0828/au0828-i2c.c b/drivers/media/video/au0828/au0828-i2c.c
new file mode 100644
index 000000000000..94c8b74a6651
--- /dev/null
+++ b/drivers/media/video/au0828/au0828-i2c.c
@@ -0,0 +1,385 @@
1/*
2 * Driver for the Auvitek AU0828 USB bridge
3 *
4 * Copyright (c) 2008 Steven Toth <stoth@hauppauge.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include <linux/module.h>
23#include <linux/moduleparam.h>
24#include <linux/init.h>
25#include <linux/delay.h>
26#include <linux/io.h>
27
28#include "au0828.h"
29
30#include <media/v4l2-common.h>
31
32unsigned int i2c_debug;
33module_param(i2c_debug, int, 0444);
34MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
35
36unsigned int i2c_scan;
37module_param(i2c_scan, int, 0444);
38MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time");
39
40#define I2C_WAIT_DELAY 512
41#define I2C_WAIT_RETRY 64
42
43static inline int i2c_slave_did_write_ack(struct i2c_adapter *i2c_adap)
44{
45 struct au0828_dev *dev = i2c_adap->algo_data;
46 return au0828_read(dev, REG_201) & 0x08 ? 0 : 1;
47}
48
49static inline int i2c_slave_did_read_ack(struct i2c_adapter *i2c_adap)
50{
51 struct au0828_dev *dev = i2c_adap->algo_data;
52 return au0828_read(dev, REG_201) & 0x02 ? 0 : 1;
53}
54
55static int i2c_wait_read_ack(struct i2c_adapter *i2c_adap)
56{
57 int count;
58
59 for (count = 0; count < I2C_WAIT_RETRY; count++) {
60 if (!i2c_slave_did_read_ack(i2c_adap))
61 break;
62 udelay(I2C_WAIT_DELAY);
63 }
64
65 if (I2C_WAIT_RETRY == count)
66 return 0;
67
68 return 1;
69}
70
71static inline int i2c_is_read_busy(struct i2c_adapter *i2c_adap)
72{
73 struct au0828_dev *dev = i2c_adap->algo_data;
74 return au0828_read(dev, REG_201) & 0x01 ? 0 : 1;
75}
76
77static int i2c_wait_read_done(struct i2c_adapter *i2c_adap)
78{
79 int count;
80
81 for (count = 0; count < I2C_WAIT_RETRY; count++) {
82 if (!i2c_is_read_busy(i2c_adap))
83 break;
84 udelay(I2C_WAIT_DELAY);
85 }
86
87 if (I2C_WAIT_RETRY == count)
88 return 0;
89
90 return 1;
91}
92
93static inline int i2c_is_write_done(struct i2c_adapter *i2c_adap)
94{
95 struct au0828_dev *dev = i2c_adap->algo_data;
96 return au0828_read(dev, REG_201) & 0x04 ? 1 : 0;
97}
98
99static int i2c_wait_write_done(struct i2c_adapter *i2c_adap)
100{
101 int count;
102
103 for (count = 0; count < I2C_WAIT_RETRY; count++) {
104 if (i2c_is_write_done(i2c_adap))
105 break;
106 udelay(I2C_WAIT_DELAY);
107 }
108
109 if (I2C_WAIT_RETRY == count)
110 return 0;
111
112 return 1;
113}
114
115static inline int i2c_is_busy(struct i2c_adapter *i2c_adap)
116{
117 struct au0828_dev *dev = i2c_adap->algo_data;
118 return au0828_read(dev, REG_201) & 0x10 ? 1 : 0;
119}
120
121static int i2c_wait_done(struct i2c_adapter *i2c_adap)
122{
123 int count;
124
125 for (count = 0; count < I2C_WAIT_RETRY; count++) {
126 if (!i2c_is_busy(i2c_adap))
127 break;
128 udelay(I2C_WAIT_DELAY);
129 }
130
131 if (I2C_WAIT_RETRY == count)
132 return 0;
133
134 return 1;
135}
136
137/* FIXME: Implement join handling correctly */
138static int i2c_sendbytes(struct i2c_adapter *i2c_adap,
139 const struct i2c_msg *msg, int joined_rlen)
140{
141 int i, strobe = 0;
142 struct au0828_dev *dev = i2c_adap->algo_data;
143
144 dprintk(4, "%s()\n", __func__);
145
146 au0828_write(dev, REG_2FF, 0x01);
147 au0828_write(dev, REG_202, 0x07);
148
149 /* Hardware needs 8 bit addresses */
150 au0828_write(dev, REG_203, msg->addr << 1);
151
152 dprintk(4, "SEND: %02x\n", msg->addr);
153
154 for (i = 0; i < msg->len;) {
155
156 dprintk(4, " %02x\n", msg->buf[i]);
157
158 au0828_write(dev, REG_205, msg->buf[i]);
159
160 strobe++;
161 i++;
162
163 if ((strobe >= 4) || (i >= msg->len)) {
164
165 /* Strobe the byte into the bus */
166 if (i < msg->len)
167 au0828_write(dev, REG_200, 0x41);
168 else
169 au0828_write(dev, REG_200, 0x01);
170
171 /* Reset strobe trigger */
172 strobe = 0;
173
174 if (!i2c_wait_write_done(i2c_adap))
175 return -EIO;
176
177 }
178
179 }
180 if (!i2c_wait_done(i2c_adap))
181 return -EIO;
182
183 dprintk(4, "\n");
184
185 return msg->len;
186}
187
188/* FIXME: Implement join handling correctly */
189static int i2c_readbytes(struct i2c_adapter *i2c_adap,
190 const struct i2c_msg *msg, int joined)
191{
192 struct au0828_dev *dev = i2c_adap->algo_data;
193 int i;
194
195 dprintk(4, "%s()\n", __func__);
196
197 au0828_write(dev, REG_2FF, 0x01);
198 au0828_write(dev, REG_202, 0x07);
199
200 /* Hardware needs 8 bit addresses */
201 au0828_write(dev, REG_203, msg->addr << 1);
202
203 dprintk(4, " RECV:\n");
204
205 /* Deal with i2c_scan */
206 if (msg->len == 0) {
207 au0828_write(dev, REG_200, 0x20);
208 if (i2c_wait_read_ack(i2c_adap))
209 return -EIO;
210 return 0;
211 }
212
213 for (i = 0; i < msg->len;) {
214
215 i++;
216
217 if (i < msg->len)
218 au0828_write(dev, REG_200, 0x60);
219 else
220 au0828_write(dev, REG_200, 0x20);
221
222 if (!i2c_wait_read_done(i2c_adap))
223 return -EIO;
224
225 msg->buf[i-1] = au0828_read(dev, REG_209) & 0xff;
226
227 dprintk(4, " %02x\n", msg->buf[i-1]);
228 }
229 if (!i2c_wait_done(i2c_adap))
230 return -EIO;
231
232 dprintk(4, "\n");
233
234 return msg->len;
235}
236
237static int i2c_xfer(struct i2c_adapter *i2c_adap,
238 struct i2c_msg *msgs, int num)
239{
240 int i, retval = 0;
241
242 dprintk(4, "%s(num = %d)\n", __func__, num);
243
244 for (i = 0; i < num; i++) {
245 dprintk(4, "%s(num = %d) addr = 0x%02x len = 0x%x\n",
246 __func__, num, msgs[i].addr, msgs[i].len);
247 if (msgs[i].flags & I2C_M_RD) {
248 /* read */
249 retval = i2c_readbytes(i2c_adap, &msgs[i], 0);
250 } else if (i + 1 < num && (msgs[i + 1].flags & I2C_M_RD) &&
251 msgs[i].addr == msgs[i + 1].addr) {
252 /* write then read from same address */
253 retval = i2c_sendbytes(i2c_adap, &msgs[i],
254 msgs[i + 1].len);
255 if (retval < 0)
256 goto err;
257 i++;
258 retval = i2c_readbytes(i2c_adap, &msgs[i], 1);
259 } else {
260 /* write */
261 retval = i2c_sendbytes(i2c_adap, &msgs[i], 0);
262 }
263 if (retval < 0)
264 goto err;
265 }
266 return num;
267
268err:
269 return retval;
270}
271
272static int attach_inform(struct i2c_client *client)
273{
274 dprintk(1, "%s i2c attach [addr=0x%x,client=%s]\n",
275 client->driver->driver.name, client->addr, client->name);
276
277 if (!client->driver->command)
278 return 0;
279
280 return 0;
281}
282
283static int detach_inform(struct i2c_client *client)
284{
285 dprintk(1, "i2c detach [client=%s]\n", client->name);
286
287 return 0;
288}
289
290void au0828_call_i2c_clients(struct au0828_dev *dev,
291 unsigned int cmd, void *arg)
292{
293 if (dev->i2c_rc != 0)
294 return;
295
296 i2c_clients_command(&dev->i2c_adap, cmd, arg);
297}
298
299static u32 au0828_functionality(struct i2c_adapter *adap)
300{
301 return I2C_FUNC_SMBUS_EMUL | I2C_FUNC_I2C;
302}
303
304static struct i2c_algorithm au0828_i2c_algo_template = {
305 .master_xfer = i2c_xfer,
306 .functionality = au0828_functionality,
307};
308
309/* ----------------------------------------------------------------------- */
310
311static struct i2c_adapter au0828_i2c_adap_template = {
312 .name = DRIVER_NAME,
313 .owner = THIS_MODULE,
314 .id = I2C_HW_B_AU0828,
315 .algo = &au0828_i2c_algo_template,
316 .class = I2C_CLASS_TV_ANALOG,
317 .client_register = attach_inform,
318 .client_unregister = detach_inform,
319};
320
321static struct i2c_client au0828_i2c_client_template = {
322 .name = "au0828 internal",
323};
324
325static char *i2c_devs[128] = {
326 [0x8e >> 1] = "au8522",
327 [0xa0 >> 1] = "eeprom",
328 [0xc2 >> 1] = "tuner/xc5000",
329};
330
331static void do_i2c_scan(char *name, struct i2c_client *c)
332{
333 unsigned char buf;
334 int i, rc;
335
336 for (i = 0; i < 128; i++) {
337 c->addr = i;
338 rc = i2c_master_recv(c, &buf, 0);
339 if (rc < 0)
340 continue;
341 printk(KERN_INFO "%s: i2c scan: found device @ 0x%x [%s]\n",
342 name, i << 1, i2c_devs[i] ? i2c_devs[i] : "???");
343 }
344}
345
346/* init + register i2c algo-bit adapter */
347int au0828_i2c_register(struct au0828_dev *dev)
348{
349 dprintk(1, "%s()\n", __func__);
350
351 memcpy(&dev->i2c_adap, &au0828_i2c_adap_template,
352 sizeof(dev->i2c_adap));
353 memcpy(&dev->i2c_algo, &au0828_i2c_algo_template,
354 sizeof(dev->i2c_algo));
355 memcpy(&dev->i2c_client, &au0828_i2c_client_template,
356 sizeof(dev->i2c_client));
357
358 dev->i2c_adap.dev.parent = &dev->usbdev->dev;
359
360 strlcpy(dev->i2c_adap.name, DRIVER_NAME,
361 sizeof(dev->i2c_adap.name));
362
363 dev->i2c_algo.data = dev;
364 dev->i2c_adap.algo_data = dev;
365 i2c_set_adapdata(&dev->i2c_adap, dev);
366 i2c_add_adapter(&dev->i2c_adap);
367
368 dev->i2c_client.adapter = &dev->i2c_adap;
369
370 if (0 == dev->i2c_rc) {
371 printk(KERN_INFO "%s: i2c bus registered\n", DRIVER_NAME);
372 if (i2c_scan)
373 do_i2c_scan(DRIVER_NAME, &dev->i2c_client);
374 } else
375 printk(KERN_INFO "%s: i2c bus register FAILED\n", DRIVER_NAME);
376
377 return dev->i2c_rc;
378}
379
380int au0828_i2c_unregister(struct au0828_dev *dev)
381{
382 i2c_del_adapter(&dev->i2c_adap);
383 return 0;
384}
385
diff --git a/drivers/media/video/au0828/au0828-reg.h b/drivers/media/video/au0828/au0828-reg.h
new file mode 100644
index 000000000000..39827550891c
--- /dev/null
+++ b/drivers/media/video/au0828/au0828-reg.h
@@ -0,0 +1,38 @@
1/*
2 * Driver for the Auvitek USB bridge
3 *
4 * Copyright (c) 2008 Steven Toth <stoth@hauppauge.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22/* We'll start to rename these registers once we have a better
23 * understanding of their meaning.
24 */
25#define REG_000 0x000
26#define REG_001 0x001
27#define REG_002 0x002
28#define REG_003 0x003
29
30#define REG_200 0x200
31#define REG_201 0x201
32#define REG_202 0x202
33#define REG_203 0x203
34#define REG_205 0x205
35#define REG_209 0x209
36#define REG_2FF 0x2ff
37
38#define REG_600 0x600
diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
new file mode 100644
index 000000000000..0200b9fc5dc4
--- /dev/null
+++ b/drivers/media/video/au0828/au0828.h
@@ -0,0 +1,128 @@
1/*
2 * Driver for the Auvitek AU0828 USB bridge
3 *
4 * Copyright (c) 2008 Steven Toth <stoth@hauppauge.com>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22#include <linux/usb.h>
23#include <linux/i2c.h>
24#include <linux/i2c-algo-bit.h>
25#include <media/tveeprom.h>
26
27/* DVB */
28#include "demux.h"
29#include "dmxdev.h"
30#include "dvb_demux.h"
31#include "dvb_frontend.h"
32#include "dvb_net.h"
33#include "dvbdev.h"
34
35#include "au0828-reg.h"
36#include "au0828-cards.h"
37
38#define DRIVER_NAME "au0828"
39#define URB_COUNT 16
40#define URB_BUFSIZE (0xe522)
41
42struct au0828_board {
43 char *name;
44};
45
46struct au0828_dvb {
47 struct mutex lock;
48 struct dvb_adapter adapter;
49 struct dvb_frontend *frontend;
50 struct dvb_demux demux;
51 struct dmxdev dmxdev;
52 struct dmx_frontend fe_hw;
53 struct dmx_frontend fe_mem;
54 struct dvb_net net;
55 int feeding;
56};
57
58struct au0828_dev {
59 struct mutex mutex;
60 struct usb_device *usbdev;
61 int board;
62 u8 ctrlmsg[64];
63
64 /* I2C */
65 struct i2c_adapter i2c_adap;
66 struct i2c_algo_bit_data i2c_algo;
67 struct i2c_client i2c_client;
68 u32 i2c_rc;
69
70 /* Digital */
71 struct au0828_dvb dvb;
72
73 /* USB / URB Related */
74 int urb_streaming;
75 struct urb *urbs[URB_COUNT];
76
77};
78
79struct au0828_buff {
80 struct au0828_dev *dev;
81 struct urb *purb;
82 struct list_head buff_list;
83};
84
85/* ----------------------------------------------------------- */
86#define au0828_read(dev, reg) au0828_readreg(dev, reg)
87#define au0828_write(dev, reg, value) au0828_writereg(dev, reg, value)
88#define au0828_andor(dev, reg, mask, value) \
89 au0828_writereg(dev, reg, \
90 (au0828_readreg(dev, reg) & ~(mask)) | ((value) & (mask)))
91
92#define au0828_set(dev, reg, bit) au0828_andor(dev, (reg), (bit), (bit))
93#define au0828_clear(dev, reg, bit) au0828_andor(dev, (reg), (bit), 0)
94
95/* ----------------------------------------------------------- */
96/* au0828-core.c */
97extern u32 au0828_read(struct au0828_dev *dev, u16 reg);
98extern u32 au0828_write(struct au0828_dev *dev, u16 reg, u32 val);
99extern unsigned int debug;
100extern unsigned int usb_debug;
101extern unsigned int bridge_debug;
102
103/* ----------------------------------------------------------- */
104/* au0828-cards.c */
105extern struct au0828_board au0828_boards[];
106extern struct usb_device_id au0828_usb_id_table[];
107extern const unsigned int au0828_bcount;
108extern void au0828_gpio_setup(struct au0828_dev *dev);
109extern int au0828_tuner_callback(void *priv, int command, int arg);
110extern void au0828_card_setup(struct au0828_dev *dev);
111
112/* ----------------------------------------------------------- */
113/* au0828-i2c.c */
114extern int au0828_i2c_register(struct au0828_dev *dev);
115extern int au0828_i2c_unregister(struct au0828_dev *dev);
116extern void au0828_call_i2c_clients(struct au0828_dev *dev,
117 unsigned int cmd, void *arg);
118extern unsigned int i2c_debug;
119
120/* ----------------------------------------------------------- */
121/* au0828-dvb.c */
122extern int au0828_dvb_register(struct au0828_dev *dev);
123extern void au0828_dvb_unregister(struct au0828_dev *dev);
124
125#define dprintk(level, fmt, arg...)\
126 do { if (debug & level)\
127 printk(KERN_DEBUG DRIVER_NAME "/0: " fmt, ## arg);\
128 } while (0)
diff --git a/drivers/media/video/bt819.c b/drivers/media/video/bt819.c
index e663cc045c41..8bfd5c75cb3a 100644
--- a/drivers/media/video/bt819.c
+++ b/drivers/media/video/bt819.c
@@ -57,7 +57,7 @@ MODULE_LICENSE("GPL");
57#define I2C_NAME(s) (s)->name 57#define I2C_NAME(s) (s)->name
58 58
59 59
60static int debug = 0; 60static int debug;
61module_param(debug, int, 0); 61module_param(debug, int, 0);
62MODULE_PARM_DESC(debug, "Debug level (0-1)"); 62MODULE_PARM_DESC(debug, "Debug level (0-1)");
63 63
diff --git a/drivers/media/video/bt856.c b/drivers/media/video/bt856.c
index 7dee2e3235ad..98ee2d8feb34 100644
--- a/drivers/media/video/bt856.c
+++ b/drivers/media/video/bt856.c
@@ -56,7 +56,7 @@ MODULE_LICENSE("GPL");
56#define I2C_NAME(s) (s)->name 56#define I2C_NAME(s) (s)->name
57 57
58 58
59static int debug = 0; 59static int debug;
60module_param(debug, int, 0); 60module_param(debug, int, 0);
61MODULE_PARM_DESC(debug, "Debug level (0-1)"); 61MODULE_PARM_DESC(debug, "Debug level (0-1)");
62 62
diff --git a/drivers/media/video/bt8xx/bttv-cards.c b/drivers/media/video/bt8xx/bttv-cards.c
index 7374c02dd183..f20a01cfc73e 100644
--- a/drivers/media/video/bt8xx/bttv-cards.c
+++ b/drivers/media/video/bt8xx/bttv-cards.c
@@ -71,6 +71,8 @@ static void kodicom4400r_init(struct bttv *btv);
71static void sigmaSLC_muxsel(struct bttv *btv, unsigned int input); 71static void sigmaSLC_muxsel(struct bttv *btv, unsigned int input);
72static void sigmaSQ_muxsel(struct bttv *btv, unsigned int input); 72static void sigmaSQ_muxsel(struct bttv *btv, unsigned int input);
73 73
74static void geovision_muxsel(struct bttv *btv, unsigned int input);
75
74static int terratec_active_radio_upgrade(struct bttv *btv); 76static int terratec_active_radio_upgrade(struct bttv *btv);
75static int tea5757_read(struct bttv *btv); 77static int tea5757_read(struct bttv *btv);
76static int tea5757_write(struct bttv *btv, int value); 78static int tea5757_write(struct bttv *btv, int value);
@@ -301,6 +303,7 @@ static struct CARD {
301 { 0xd50018ac, BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE, "DViCO FusionHDTV 5 Lite" }, 303 { 0xd50018ac, BTTV_BOARD_DVICO_FUSIONHDTV_5_LITE, "DViCO FusionHDTV 5 Lite" },
302 { 0x00261822, BTTV_BOARD_TWINHAN_DST, "DNTV Live! Mini "}, 304 { 0x00261822, BTTV_BOARD_TWINHAN_DST, "DNTV Live! Mini "},
303 { 0xd200dbc0, BTTV_BOARD_DVICO_FUSIONHDTV_2, "DViCO FusionHDTV 2" }, 305 { 0xd200dbc0, BTTV_BOARD_DVICO_FUSIONHDTV_2, "DViCO FusionHDTV 2" },
306 { 0x763c008a, BTTV_BOARD_GEOVISION_GV600, "GeoVision GV-600" },
304 307
305 { 0, -1, NULL } 308 { 0, -1, NULL }
306}; 309};
@@ -576,6 +579,8 @@ struct tvcard bttv_tvcards[] = {
576 .needs_tvaudio = 1, 579 .needs_tvaudio = 1,
577 .pll = PLL_28, 580 .pll = PLL_28,
578 .tuner_type = UNSET, 581 .tuner_type = UNSET,
582 .tuner_addr = ADDR_UNSET,
583 .radio_addr = ADDR_UNSET,
579 }, 584 },
580 [BTTV_BOARD_WINVIEW_601] = { 585 [BTTV_BOARD_WINVIEW_601] = {
581 .name = "Leadtek WinView 601", 586 .name = "Leadtek WinView 601",
@@ -2322,7 +2327,7 @@ struct tvcard bttv_tvcards[] = {
2322 .tuner = 0, 2327 .tuner = 0,
2323 .svhs = 2, 2328 .svhs = 2,
2324 .muxsel = { 2, 3, 1, 0 }, 2329 .muxsel = { 2, 3, 1, 0 },
2325 .tuner_type = TUNER_PHILIPS_ATSC, 2330 .tuner_type = TUNER_PHILIPS_FCV1236D,
2326 .tuner_addr = ADDR_UNSET, 2331 .tuner_addr = ADDR_UNSET,
2327 .radio_addr = ADDR_UNSET, 2332 .radio_addr = ADDR_UNSET,
2328 .has_dvb = 1, 2333 .has_dvb = 1,
@@ -2961,7 +2966,7 @@ struct tvcard bttv_tvcards[] = {
2961 [BTTV_BOARD_DVICO_FUSIONHDTV_2] = { 2966 [BTTV_BOARD_DVICO_FUSIONHDTV_2] = {
2962 .name = "DViCO FusionHDTV 2", 2967 .name = "DViCO FusionHDTV 2",
2963 .tuner = 0, 2968 .tuner = 0,
2964 .tuner_type = TUNER_PHILIPS_ATSC, /* FCV1236D */ 2969 .tuner_type = TUNER_PHILIPS_FCV1236D,
2965 .tuner_addr = ADDR_UNSET, 2970 .tuner_addr = ADDR_UNSET,
2966 .radio_addr = ADDR_UNSET, 2971 .radio_addr = ADDR_UNSET,
2967 .video_inputs = 3, 2972 .video_inputs = 3,
@@ -2992,6 +2997,45 @@ struct tvcard bttv_tvcards[] = {
2992 .tuner_addr = ADDR_UNSET, 2997 .tuner_addr = ADDR_UNSET,
2993 .radio_addr = ADDR_UNSET, 2998 .radio_addr = ADDR_UNSET,
2994 }, 2999 },
3000 [BTTV_BOARD_GEOVISION_GV600] = {
3001 /* emhn@usb.ve */
3002 .name = "Geovision GV-600",
3003 .video_inputs = 16,
3004 .audio_inputs = 0,
3005 .tuner = UNSET,
3006 .svhs = UNSET,
3007 .gpiomask = 0x0,
3008 .muxsel = { 2, 2, 2, 2, 2, 2, 2, 2,
3009 2, 2, 2, 2, 2, 2, 2, 2 },
3010 .muxsel_hook = geovision_muxsel,
3011 .gpiomux = { 0 },
3012 .no_msp34xx = 1,
3013 .pll = PLL_28,
3014 .tuner_type = UNSET,
3015 .tuner_addr = ADDR_UNSET,
3016 .radio_addr = ADDR_UNSET,
3017 },
3018 [BTTV_BOARD_KOZUMI_KTV_01C] = {
3019 /* Mauro Lacy <mauro@lacy.com.ar>
3020 * Based on MagicTV and Conceptronic CONTVFMi */
3021
3022 .name = "Kozumi KTV-01C",
3023 .video_inputs = 3,
3024 .audio_inputs = 1,
3025 .tuner = 0,
3026 .svhs = 2,
3027 .gpiomask = 0x008007,
3028 .muxsel = { 2, 3, 1, 1 },
3029 .gpiomux = { 0, 1, 2, 2 }, /* CONTVFMi */
3030 .gpiomute = 3, /* CONTVFMi */
3031 .needs_tvaudio = 0,
3032 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, /* TCL MK3 */
3033 .tuner_addr = ADDR_UNSET,
3034 .radio_addr = ADDR_UNSET,
3035 .pll = PLL_28,
3036 .has_radio = 1,
3037 .has_remote = 1,
3038 },
2995}; 3039};
2996 3040
2997static const unsigned int bttv_num_tvcards = ARRAY_SIZE(bttv_tvcards); 3041static const unsigned int bttv_num_tvcards = ARRAY_SIZE(bttv_tvcards);
@@ -3331,6 +3375,13 @@ static void sigmaSLC_muxsel(struct bttv *btv, unsigned int input)
3331 gpio_bits( 3<<9, inmux<<9 ); 3375 gpio_bits( 3<<9, inmux<<9 );
3332} 3376}
3333 3377
3378static void geovision_muxsel(struct bttv *btv, unsigned int input)
3379{
3380 unsigned int inmux = input % 16;
3381 gpio_inout(0xf, 0xf);
3382 gpio_bits(0xf, inmux);
3383}
3384
3334/* ----------------------------------------------------------------------- */ 3385/* ----------------------------------------------------------------------- */
3335 3386
3336static void bttv_reset_audio(struct bttv *btv) 3387static void bttv_reset_audio(struct bttv *btv)
diff --git a/drivers/media/video/bt8xx/bttv-driver.c b/drivers/media/video/bt8xx/bttv-driver.c
index fcf8f2d208a8..2ca3e9cfb2bb 100644
--- a/drivers/media/video/bt8xx/bttv-driver.c
+++ b/drivers/media/video/bt8xx/bttv-driver.c
@@ -2372,7 +2372,7 @@ static int setup_window(struct bttv_fh *fh, struct bttv *btv,
2372 if (check_btres(fh, RESOURCE_OVERLAY)) { 2372 if (check_btres(fh, RESOURCE_OVERLAY)) {
2373 struct bttv_buffer *new; 2373 struct bttv_buffer *new;
2374 2374
2375 new = videobuf_pci_alloc(sizeof(*new)); 2375 new = videobuf_sg_alloc(sizeof(*new));
2376 new->crop = btv->crop[!!fh->do_crop].rect; 2376 new->crop = btv->crop[!!fh->do_crop].rect;
2377 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new); 2377 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new);
2378 retval = bttv_switch_overlay(btv,fh,new); 2378 retval = bttv_switch_overlay(btv,fh,new);
@@ -2760,7 +2760,7 @@ static int bttv_overlay(struct file *file, void *f, unsigned int on)
2760 mutex_lock(&fh->cap.vb_lock); 2760 mutex_lock(&fh->cap.vb_lock);
2761 if (on) { 2761 if (on) {
2762 fh->ov.tvnorm = btv->tvnorm; 2762 fh->ov.tvnorm = btv->tvnorm;
2763 new = videobuf_pci_alloc(sizeof(*new)); 2763 new = videobuf_sg_alloc(sizeof(*new));
2764 new->crop = btv->crop[!!fh->do_crop].rect; 2764 new->crop = btv->crop[!!fh->do_crop].rect;
2765 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new); 2765 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new);
2766 } else { 2766 } else {
@@ -2834,7 +2834,7 @@ static int bttv_s_fbuf(struct file *file, void *f,
2834 if (check_btres(fh, RESOURCE_OVERLAY)) { 2834 if (check_btres(fh, RESOURCE_OVERLAY)) {
2835 struct bttv_buffer *new; 2835 struct bttv_buffer *new;
2836 2836
2837 new = videobuf_pci_alloc(sizeof(*new)); 2837 new = videobuf_sg_alloc(sizeof(*new));
2838 new->crop = btv->crop[!!fh->do_crop].rect; 2838 new->crop = btv->crop[!!fh->do_crop].rect;
2839 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new); 2839 bttv_overlay_risc(btv, &fh->ov, fh->ovfmt, new);
2840 retval = bttv_switch_overlay(btv, fh, new); 2840 retval = bttv_switch_overlay(btv, fh, new);
@@ -3117,12 +3117,18 @@ static int bttv_s_crop(struct file *file, void *f, struct v4l2_crop *crop)
3117 3117
3118static int bttv_g_audio(struct file *file, void *priv, struct v4l2_audio *a) 3118static int bttv_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
3119{ 3119{
3120 if (unlikely(a->index))
3121 return -EINVAL;
3122
3120 strcpy(a->name, "audio"); 3123 strcpy(a->name, "audio");
3121 return 0; 3124 return 0;
3122} 3125}
3123 3126
3124static int bttv_s_audio(struct file *file, void *priv, struct v4l2_audio *a) 3127static int bttv_s_audio(struct file *file, void *priv, struct v4l2_audio *a)
3125{ 3128{
3129 if (unlikely(a->index))
3130 return -EINVAL;
3131
3126 return 0; 3132 return 0;
3127} 3133}
3128 3134
@@ -3184,7 +3190,7 @@ static unsigned int bttv_poll(struct file *file, poll_table *wait)
3184 /* need to capture a new frame */ 3190 /* need to capture a new frame */
3185 if (locked_btres(fh->btv,RESOURCE_VIDEO_STREAM)) 3191 if (locked_btres(fh->btv,RESOURCE_VIDEO_STREAM))
3186 goto err; 3192 goto err;
3187 fh->cap.read_buf = videobuf_pci_alloc(fh->cap.msize); 3193 fh->cap.read_buf = videobuf_sg_alloc(fh->cap.msize);
3188 if (NULL == fh->cap.read_buf) 3194 if (NULL == fh->cap.read_buf)
3189 goto err; 3195 goto err;
3190 fh->cap.read_buf->memory = V4L2_MEMORY_USERPTR; 3196 fh->cap.read_buf->memory = V4L2_MEMORY_USERPTR;
@@ -3251,14 +3257,14 @@ static int bttv_open(struct inode *inode, struct file *file)
3251 fh->ov.setup_ok = 0; 3257 fh->ov.setup_ok = 0;
3252 v4l2_prio_open(&btv->prio,&fh->prio); 3258 v4l2_prio_open(&btv->prio,&fh->prio);
3253 3259
3254 videobuf_queue_pci_init(&fh->cap, &bttv_video_qops, 3260 videobuf_queue_sg_init(&fh->cap, &bttv_video_qops,
3255 btv->c.pci, &btv->s_lock, 3261 &btv->c.pci->dev, &btv->s_lock,
3256 V4L2_BUF_TYPE_VIDEO_CAPTURE, 3262 V4L2_BUF_TYPE_VIDEO_CAPTURE,
3257 V4L2_FIELD_INTERLACED, 3263 V4L2_FIELD_INTERLACED,
3258 sizeof(struct bttv_buffer), 3264 sizeof(struct bttv_buffer),
3259 fh); 3265 fh);
3260 videobuf_queue_pci_init(&fh->vbi, &bttv_vbi_qops, 3266 videobuf_queue_sg_init(&fh->vbi, &bttv_vbi_qops,
3261 btv->c.pci, &btv->s_lock, 3267 &btv->c.pci->dev, &btv->s_lock,
3262 V4L2_BUF_TYPE_VBI_CAPTURE, 3268 V4L2_BUF_TYPE_VBI_CAPTURE,
3263 V4L2_FIELD_SEQ_TB, 3269 V4L2_FIELD_SEQ_TB,
3264 sizeof(struct bttv_buffer), 3270 sizeof(struct bttv_buffer),
@@ -3457,6 +3463,9 @@ static int radio_release(struct inode *inode, struct file *file)
3457 struct bttv *btv = fh->btv; 3463 struct bttv *btv = fh->btv;
3458 struct rds_command cmd; 3464 struct rds_command cmd;
3459 3465
3466 file->private_data = NULL;
3467 kfree(fh);
3468
3460 btv->radio_user--; 3469 btv->radio_user--;
3461 3470
3462 bttv_call_i2c_clients(btv, RDS_CMD_CLOSE, &cmd); 3471 bttv_call_i2c_clients(btv, RDS_CMD_CLOSE, &cmd);
@@ -3510,7 +3519,7 @@ static int radio_enum_input(struct file *file, void *priv,
3510 return -EINVAL; 3519 return -EINVAL;
3511 3520
3512 strcpy(i->name, "Radio"); 3521 strcpy(i->name, "Radio");
3513 i->type = V4L2_INPUT_TYPE_TUNER; 3522 i->type = V4L2_INPUT_TYPE_TUNER;
3514 3523
3515 return 0; 3524 return 0;
3516} 3525}
@@ -3518,10 +3527,9 @@ static int radio_enum_input(struct file *file, void *priv,
3518static int radio_g_audio(struct file *file, void *priv, 3527static int radio_g_audio(struct file *file, void *priv,
3519 struct v4l2_audio *a) 3528 struct v4l2_audio *a)
3520{ 3529{
3521 if (a->index != 0) 3530 if (unlikely(a->index))
3522 return -EINVAL; 3531 return -EINVAL;
3523 3532
3524 memset(a, 0, sizeof(*a));
3525 strcpy(a->name, "Radio"); 3533 strcpy(a->name, "Radio");
3526 3534
3527 return 0; 3535 return 0;
@@ -3543,11 +3551,17 @@ static int radio_s_tuner(struct file *file, void *priv,
3543static int radio_s_audio(struct file *file, void *priv, 3551static int radio_s_audio(struct file *file, void *priv,
3544 struct v4l2_audio *a) 3552 struct v4l2_audio *a)
3545{ 3553{
3554 if (unlikely(a->index))
3555 return -EINVAL;
3556
3546 return 0; 3557 return 0;
3547} 3558}
3548 3559
3549static int radio_s_input(struct file *filp, void *priv, unsigned int i) 3560static int radio_s_input(struct file *filp, void *priv, unsigned int i)
3550{ 3561{
3562 if (unlikely(i))
3563 return -EINVAL;
3564
3551 return 0; 3565 return 0;
3552} 3566}
3553 3567
diff --git a/drivers/media/video/bt8xx/bttv-input.c b/drivers/media/video/bt8xx/bttv-input.c
index fc9ecb21eec6..a38af98f4cae 100644
--- a/drivers/media/video/bt8xx/bttv-input.c
+++ b/drivers/media/video/bt8xx/bttv-input.c
@@ -278,6 +278,12 @@ int bttv_input_init(struct bttv *btv)
278 ir->mask_keyup = 0x004000; 278 ir->mask_keyup = 0x004000;
279 ir->polling = 50; /* ms */ 279 ir->polling = 50; /* ms */
280 break; 280 break;
281 case BTTV_BOARD_KOZUMI_KTV_01C:
282 ir_codes = ir_codes_pctv_sedna;
283 ir->mask_keycode = 0x001f00;
284 ir->mask_keyup = 0x006000;
285 ir->polling = 50; /* ms */
286 break;
281 } 287 }
282 if (NULL == ir_codes) { 288 if (NULL == ir_codes) {
283 dprintk(KERN_INFO "Ooops: IR config error [card=%d]\n", btv->c.type); 289 dprintk(KERN_INFO "Ooops: IR config error [card=%d]\n", btv->c.type);
diff --git a/drivers/media/video/bt8xx/bttv-vbi.c b/drivers/media/video/bt8xx/bttv-vbi.c
index 75fa82c7c735..bfdbc469e30f 100644
--- a/drivers/media/video/bt8xx/bttv-vbi.c
+++ b/drivers/media/video/bt8xx/bttv-vbi.c
@@ -54,7 +54,7 @@
54#define VBI_DEFLINES 16 54#define VBI_DEFLINES 16
55 55
56static unsigned int vbibufs = 4; 56static unsigned int vbibufs = 4;
57static unsigned int vbi_debug = 0; 57static unsigned int vbi_debug;
58 58
59module_param(vbibufs, int, 0444); 59module_param(vbibufs, int, 0444);
60module_param(vbi_debug, int, 0644); 60module_param(vbi_debug, int, 0644);
diff --git a/drivers/media/video/bt8xx/bttv.h b/drivers/media/video/bt8xx/bttv.h
index bf4c339a520c..f2393202904b 100644
--- a/drivers/media/video/bt8xx/bttv.h
+++ b/drivers/media/video/bt8xx/bttv.h
@@ -19,6 +19,7 @@
19#include <media/ir-common.h> 19#include <media/ir-common.h>
20#include <media/ir-kbd-i2c.h> 20#include <media/ir-kbd-i2c.h>
21#include <media/i2c-addr.h> 21#include <media/i2c-addr.h>
22#include <media/tuner.h>
22 23
23/* ---------------------------------------------------------- */ 24/* ---------------------------------------------------------- */
24/* exported by bttv-cards.c */ 25/* exported by bttv-cards.c */
@@ -173,6 +174,8 @@
173#define BTTV_BOARD_VOODOOTV_200 0x93 174#define BTTV_BOARD_VOODOOTV_200 0x93
174#define BTTV_BOARD_DVICO_FUSIONHDTV_2 0x94 175#define BTTV_BOARD_DVICO_FUSIONHDTV_2 0x94
175#define BTTV_BOARD_TYPHOON_TVTUNERPCI 0x95 176#define BTTV_BOARD_TYPHOON_TVTUNERPCI 0x95
177#define BTTV_BOARD_GEOVISION_GV600 0x96
178#define BTTV_BOARD_KOZUMI_KTV_01C 0x97
176 179
177 180
178/* more card-specific defines */ 181/* more card-specific defines */
diff --git a/drivers/media/video/bt8xx/bttvp.h b/drivers/media/video/bt8xx/bttvp.h
index 1305d315cfc5..03816b73f847 100644
--- a/drivers/media/video/bt8xx/bttvp.h
+++ b/drivers/media/video/bt8xx/bttvp.h
@@ -42,7 +42,6 @@
42 42
43#include <linux/device.h> 43#include <linux/device.h>
44#include <media/videobuf-dma-sg.h> 44#include <media/videobuf-dma-sg.h>
45#include <media/tuner.h>
46#include <media/tveeprom.h> 45#include <media/tveeprom.h>
47#include <media/ir-common.h> 46#include <media/ir-common.h>
48 47
diff --git a/drivers/media/video/bw-qcam.c b/drivers/media/video/bw-qcam.c
index 032265383df2..b364adaae78d 100644
--- a/drivers/media/video/bw-qcam.c
+++ b/drivers/media/video/bw-qcam.c
@@ -523,7 +523,7 @@ static inline int qc_readbytes(struct qcam_device *q, char buffer[])
523 int ret=1; 523 int ret=1;
524 unsigned int hi, lo; 524 unsigned int hi, lo;
525 unsigned int hi2, lo2; 525 unsigned int hi2, lo2;
526 static int state = 0; 526 static int state;
527 527
528 if (buffer == NULL) 528 if (buffer == NULL)
529 { 529 {
@@ -898,7 +898,9 @@ static const struct file_operations qcam_fops = {
898 .open = video_exclusive_open, 898 .open = video_exclusive_open,
899 .release = video_exclusive_release, 899 .release = video_exclusive_release,
900 .ioctl = qcam_ioctl, 900 .ioctl = qcam_ioctl,
901#ifdef CONFIG_COMPAT
901 .compat_ioctl = v4l_compat_ioctl32, 902 .compat_ioctl = v4l_compat_ioctl32,
903#endif
902 .read = qcam_read, 904 .read = qcam_read,
903 .llseek = no_llseek, 905 .llseek = no_llseek,
904}; 906};
@@ -912,7 +914,7 @@ static struct video_device qcam_template=
912 914
913#define MAX_CAMS 4 915#define MAX_CAMS 4
914static struct qcam_device *qcams[MAX_CAMS]; 916static struct qcam_device *qcams[MAX_CAMS];
915static unsigned int num_cams = 0; 917static unsigned int num_cams;
916 918
917static int init_bwqcam(struct parport *port) 919static int init_bwqcam(struct parport *port)
918{ 920{
diff --git a/drivers/media/video/c-qcam.c b/drivers/media/video/c-qcam.c
index cf1546b5a7f1..fe1e67bb1ca8 100644
--- a/drivers/media/video/c-qcam.c
+++ b/drivers/media/video/c-qcam.c
@@ -36,6 +36,7 @@
36#include <linux/videodev.h> 36#include <linux/videodev.h>
37#include <media/v4l2-common.h> 37#include <media/v4l2-common.h>
38#include <linux/mutex.h> 38#include <linux/mutex.h>
39#include <linux/jiffies.h>
39 40
40#include <asm/uaccess.h> 41#include <asm/uaccess.h>
41 42
@@ -69,7 +70,7 @@ struct qcam_device {
69 70
70static int parport[MAX_CAMS] = { [1 ... MAX_CAMS-1] = -1 }; 71static int parport[MAX_CAMS] = { [1 ... MAX_CAMS-1] = -1 };
71static int probe = 2; 72static int probe = 2;
72static int force_rgb = 0; 73static int force_rgb;
73static int video_nr = -1; 74static int video_nr = -1;
74 75
75static inline void qcam_set_ack(struct qcam_device *qcam, unsigned int i) 76static inline void qcam_set_ack(struct qcam_device *qcam, unsigned int i)
@@ -95,7 +96,8 @@ static unsigned int qcam_await_ready1(struct qcam_device *qcam,
95 unsigned long oldjiffies = jiffies; 96 unsigned long oldjiffies = jiffies;
96 unsigned int i; 97 unsigned int i;
97 98
98 for (oldjiffies = jiffies; (jiffies - oldjiffies) < msecs_to_jiffies(40); ) 99 for (oldjiffies = jiffies;
100 time_before(jiffies, oldjiffies + msecs_to_jiffies(40)); )
99 if (qcam_ready1(qcam) == value) 101 if (qcam_ready1(qcam) == value)
100 return 0; 102 return 0;
101 103
@@ -120,7 +122,8 @@ static unsigned int qcam_await_ready2(struct qcam_device *qcam, int value)
120 unsigned long oldjiffies = jiffies; 122 unsigned long oldjiffies = jiffies;
121 unsigned int i; 123 unsigned int i;
122 124
123 for (oldjiffies = jiffies; (jiffies - oldjiffies) < msecs_to_jiffies(40); ) 125 for (oldjiffies = jiffies;
126 time_before(jiffies, oldjiffies + msecs_to_jiffies(40)); )
124 if (qcam_ready2(qcam) == value) 127 if (qcam_ready2(qcam) == value)
125 return 0; 128 return 0;
126 129
@@ -689,7 +692,9 @@ static const struct file_operations qcam_fops = {
689 .open = video_exclusive_open, 692 .open = video_exclusive_open,
690 .release = video_exclusive_release, 693 .release = video_exclusive_release,
691 .ioctl = qcam_ioctl, 694 .ioctl = qcam_ioctl,
695#ifdef CONFIG_COMPAT
692 .compat_ioctl = v4l_compat_ioctl32, 696 .compat_ioctl = v4l_compat_ioctl32,
697#endif
693 .read = qcam_read, 698 .read = qcam_read,
694 .llseek = no_llseek, 699 .llseek = no_llseek,
695}; 700};
@@ -741,7 +746,7 @@ static struct qcam_device *qcam_init(struct parport *port)
741} 746}
742 747
743static struct qcam_device *qcams[MAX_CAMS]; 748static struct qcam_device *qcams[MAX_CAMS];
744static unsigned int num_cams = 0; 749static unsigned int num_cams;
745 750
746static int init_cqcam(struct parport *port) 751static int init_cqcam(struct parport *port)
747{ 752{
diff --git a/drivers/media/video/cafe_ccic.c b/drivers/media/video/cafe_ccic.c
index 7ae499c9c54c..5195b1f3378a 100644
--- a/drivers/media/video/cafe_ccic.c
+++ b/drivers/media/video/cafe_ccic.c
@@ -65,7 +65,7 @@ MODULE_SUPPORTED_DEVICE("Video");
65 */ 65 */
66 66
67#define MAX_DMA_BUFS 3 67#define MAX_DMA_BUFS 3
68static int alloc_bufs_at_read = 0; 68static int alloc_bufs_at_read;
69module_param(alloc_bufs_at_read, bool, 0444); 69module_param(alloc_bufs_at_read, bool, 0444);
70MODULE_PARM_DESC(alloc_bufs_at_read, 70MODULE_PARM_DESC(alloc_bufs_at_read,
71 "Non-zero value causes DMA buffers to be allocated when the " 71 "Non-zero value causes DMA buffers to be allocated when the "
@@ -99,7 +99,7 @@ MODULE_PARM_DESC(max_buffers,
99 "will be allowed to allocate. These buffers are big and live " 99 "will be allowed to allocate. These buffers are big and live "
100 "in vmalloc space."); 100 "in vmalloc space.");
101 101
102static int flip = 0; 102static int flip;
103module_param(flip, bool, 0444); 103module_param(flip, bool, 0444);
104MODULE_PARM_DESC(flip, 104MODULE_PARM_DESC(flip,
105 "If set, the sensor will be instructed to flip the image " 105 "If set, the sensor will be instructed to flip the image "
diff --git a/drivers/media/video/cpia.c b/drivers/media/video/cpia.c
index 7c630f5ee725..2a81376ef503 100644
--- a/drivers/media/video/cpia.c
+++ b/drivers/media/video/cpia.c
@@ -3792,7 +3792,9 @@ static const struct file_operations cpia_fops = {
3792 .read = cpia_read, 3792 .read = cpia_read,
3793 .mmap = cpia_mmap, 3793 .mmap = cpia_mmap,
3794 .ioctl = cpia_ioctl, 3794 .ioctl = cpia_ioctl,
3795#ifdef CONFIG_COMPAT
3795 .compat_ioctl = v4l_compat_ioctl32, 3796 .compat_ioctl = v4l_compat_ioctl32,
3797#endif
3796 .llseek = no_llseek, 3798 .llseek = no_llseek,
3797}; 3799};
3798 3800
diff --git a/drivers/media/video/cpia.h b/drivers/media/video/cpia.h
index 78392fb6f94e..5096058bf579 100644
--- a/drivers/media/video/cpia.h
+++ b/drivers/media/video/cpia.h
@@ -412,11 +412,11 @@ void cpia_unregister_camera(struct cam_data *cam);
412/* ErrorCode */ 412/* ErrorCode */
413#define ERROR_FLICKER_BELOW_MIN_EXP 0x01 /*flicker exposure got below minimum exposure */ 413#define ERROR_FLICKER_BELOW_MIN_EXP 0x01 /*flicker exposure got below minimum exposure */
414#define ALOG(fmt,args...) printk(fmt, ##args) 414#define ALOG(fmt,args...) printk(fmt, ##args)
415#define LOG(fmt,args...) ALOG(KERN_INFO __FILE__ ":%s(%d):" fmt, __FUNCTION__ , __LINE__ , ##args) 415#define LOG(fmt,args...) ALOG(KERN_INFO __FILE__ ":%s(%d):" fmt, __func__ , __LINE__ , ##args)
416 416
417#ifdef _CPIA_DEBUG_ 417#ifdef _CPIA_DEBUG_
418#define ADBG(fmt,args...) printk(fmt, jiffies, ##args) 418#define ADBG(fmt,args...) printk(fmt, jiffies, ##args)
419#define DBG(fmt,args...) ADBG(KERN_DEBUG __FILE__" (%ld):%s(%d):" fmt, __FUNCTION__, __LINE__ , ##args) 419#define DBG(fmt,args...) ADBG(KERN_DEBUG __FILE__" (%ld):%s(%d):" fmt, __func__, __LINE__ , ##args)
420#else 420#else
421#define DBG(fmn,args...) do {} while(0) 421#define DBG(fmn,args...) do {} while(0)
422#endif 422#endif
diff --git a/drivers/media/video/cpia2/cpia2_core.c b/drivers/media/video/cpia2/cpia2_core.c
index a76bd786cf13..c8b9fdb700ff 100644
--- a/drivers/media/video/cpia2/cpia2_core.c
+++ b/drivers/media/video/cpia2/cpia2_core.c
@@ -34,7 +34,7 @@
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/vmalloc.h> 35#include <linux/vmalloc.h>
36 36
37//#define _CPIA2_DEBUG_ 37/* #define _CPIA2_DEBUG_ */
38 38
39#include "cpia2patch.h" 39#include "cpia2patch.h"
40 40
@@ -48,7 +48,7 @@ static const char *block_name[] = {
48}; 48};
49#endif 49#endif
50 50
51static unsigned int debugs_on = 0;//DEBUG_REG; 51static unsigned int debugs_on; /* default 0 - DEBUG_REG */
52 52
53 53
54/****************************************************************************** 54/******************************************************************************
@@ -570,7 +570,7 @@ int cpia2_send_command(struct camera_data *cam, struct cpia2_command *cmd)
570 block_name[block_index]); 570 block_name[block_index]);
571 break; 571 break;
572 default: 572 default:
573 LOG("%s: invalid request mode\n",__FUNCTION__); 573 LOG("%s: invalid request mode\n",__func__);
574 return -EINVAL; 574 return -EINVAL;
575 } 575 }
576 576
@@ -952,7 +952,7 @@ static int set_default_user_mode(struct camera_data *cam)
952 frame_rate = CPIA2_VP_FRAMERATE_30; 952 frame_rate = CPIA2_VP_FRAMERATE_30;
953 break; 953 break;
954 default: 954 default:
955 LOG("%s: Invalid sensor flag value 0x%0X\n",__FUNCTION__, 955 LOG("%s: Invalid sensor flag value 0x%0X\n",__func__,
956 cam->params.version.sensor_flags); 956 cam->params.version.sensor_flags);
957 return -EINVAL; 957 return -EINVAL;
958 } 958 }
@@ -2356,12 +2356,12 @@ long cpia2_read(struct camera_data *cam,
2356 } 2356 }
2357 2357
2358 if (!buf) { 2358 if (!buf) {
2359 ERR("%s: buffer NULL\n",__FUNCTION__); 2359 ERR("%s: buffer NULL\n",__func__);
2360 return -EINVAL; 2360 return -EINVAL;
2361 } 2361 }
2362 2362
2363 if (!cam) { 2363 if (!cam) {
2364 ERR("%s: Internal error, camera_data NULL!\n",__FUNCTION__); 2364 ERR("%s: Internal error, camera_data NULL!\n",__func__);
2365 return -EINVAL; 2365 return -EINVAL;
2366 } 2366 }
2367 2367
@@ -2370,7 +2370,7 @@ long cpia2_read(struct camera_data *cam,
2370 return -ERESTARTSYS; 2370 return -ERESTARTSYS;
2371 2371
2372 if (!cam->present) { 2372 if (!cam->present) {
2373 LOG("%s: camera removed\n",__FUNCTION__); 2373 LOG("%s: camera removed\n",__func__);
2374 mutex_unlock(&cam->busy_lock); 2374 mutex_unlock(&cam->busy_lock);
2375 return 0; /* EOF */ 2375 return 0; /* EOF */
2376 } 2376 }
@@ -2434,7 +2434,7 @@ unsigned int cpia2_poll(struct camera_data *cam, struct file *filp,
2434 unsigned int status=0; 2434 unsigned int status=0;
2435 2435
2436 if(!cam) { 2436 if(!cam) {
2437 ERR("%s: Internal error, camera_data not found!\n",__FUNCTION__); 2437 ERR("%s: Internal error, camera_data not found!\n",__func__);
2438 return POLLERR; 2438 return POLLERR;
2439 } 2439 }
2440 2440
diff --git a/drivers/media/video/cpia2/cpia2_usb.c b/drivers/media/video/cpia2/cpia2_usb.c
index d8e929863a88..a4574740350d 100644
--- a/drivers/media/video/cpia2/cpia2_usb.c
+++ b/drivers/media/video/cpia2/cpia2_usb.c
@@ -84,7 +84,7 @@ static struct usb_driver cpia2_driver = {
84 *****************************************************************************/ 84 *****************************************************************************/
85static void process_frame(struct camera_data *cam) 85static void process_frame(struct camera_data *cam)
86{ 86{
87 static int frame_count = 0; 87 static int frame_count;
88 88
89 unsigned char *inbuff = cam->workbuff->data; 89 unsigned char *inbuff = cam->workbuff->data;
90 90
diff --git a/drivers/media/video/cpia2/cpia2_v4l.c b/drivers/media/video/cpia2/cpia2_v4l.c
index e378abec806d..7ce2789fa976 100644
--- a/drivers/media/video/cpia2/cpia2_v4l.c
+++ b/drivers/media/video/cpia2/cpia2_v4l.c
@@ -1927,7 +1927,9 @@ static const struct file_operations fops_template = {
1927 .poll = cpia2_v4l_poll, 1927 .poll = cpia2_v4l_poll,
1928 .ioctl = cpia2_ioctl, 1928 .ioctl = cpia2_ioctl,
1929 .llseek = no_llseek, 1929 .llseek = no_llseek,
1930#ifdef CONFIG_COMPAT
1930 .compat_ioctl = v4l_compat_ioctl32, 1931 .compat_ioctl = v4l_compat_ioctl32,
1932#endif
1931 .mmap = cpia2_mmap, 1933 .mmap = cpia2_mmap,
1932}; 1934};
1933 1935
diff --git a/drivers/media/video/cpia_usb.c b/drivers/media/video/cpia_usb.c
index 9da4726eb9b9..ef1f89399983 100644
--- a/drivers/media/video/cpia_usb.c
+++ b/drivers/media/video/cpia_usb.c
@@ -170,7 +170,7 @@ static void cpia_usb_complete(struct urb *urb)
170 /* resubmit */ 170 /* resubmit */
171 urb->dev = ucpia->dev; 171 urb->dev = ucpia->dev;
172 if ((i = usb_submit_urb(urb, GFP_ATOMIC)) != 0) 172 if ((i = usb_submit_urb(urb, GFP_ATOMIC)) != 0)
173 printk(KERN_ERR "%s: usb_submit_urb ret %d\n", __FUNCTION__, i); 173 printk(KERN_ERR "%s: usb_submit_urb ret %d\n", __func__, i);
174} 174}
175 175
176static int cpia_usb_open(void *privdata) 176static int cpia_usb_open(void *privdata)
diff --git a/drivers/media/video/cx23885/Kconfig b/drivers/media/video/cx23885/Kconfig
index 1fd326fe4113..ca5fbce3a909 100644
--- a/drivers/media/video/cx23885/Kconfig
+++ b/drivers/media/video/cx23885/Kconfig
@@ -8,6 +8,7 @@ config VIDEO_CX23885
8 select VIDEO_TVEEPROM 8 select VIDEO_TVEEPROM
9 select VIDEO_IR 9 select VIDEO_IR
10 select VIDEOBUF_DVB 10 select VIDEOBUF_DVB
11 select VIDEO_CX25840
11 select DVB_TUNER_MT2131 if !DVB_FE_CUSTOMISE 12 select DVB_TUNER_MT2131 if !DVB_FE_CUSTOMISE
12 select DVB_S5H1409 if !DVB_FE_CUSTOMISE 13 select DVB_S5H1409 if !DVB_FE_CUSTOMISE
13 select DVB_LGDT330X if !DVB_FE_CUSTOMISE 14 select DVB_LGDT330X if !DVB_FE_CUSTOMISE
@@ -16,6 +17,7 @@ config VIDEO_CX23885
16 select TUNER_TDA8290 if !DVB_FE_CUSTOMIZE 17 select TUNER_TDA8290 if !DVB_FE_CUSTOMIZE
17 select DVB_TDA18271 if !DVB_FE_CUSTOMIZE 18 select DVB_TDA18271 if !DVB_FE_CUSTOMIZE
18 select DVB_TUNER_XC5000 if !DVB_FE_CUSTOMIZE 19 select DVB_TUNER_XC5000 if !DVB_FE_CUSTOMIZE
20 select DVB_TDA10048 if !DVB_FE_CUSTOMIZE
19 ---help--- 21 ---help---
20 This is a video4linux driver for Conexant 23885 based 22 This is a video4linux driver for Conexant 23885 based
21 TV cards. 23 TV cards.
diff --git a/drivers/media/video/cx23885/Makefile b/drivers/media/video/cx23885/Makefile
index 32c90be50602..d7b0721af062 100644
--- a/drivers/media/video/cx23885/Makefile
+++ b/drivers/media/video/cx23885/Makefile
@@ -1,4 +1,4 @@
1cx23885-objs := cx23885-cards.o cx23885-video.o cx23885-vbi.o cx23885-core.o cx23885-i2c.o cx23885-dvb.o 1cx23885-objs := cx23885-cards.o cx23885-video.o cx23885-vbi.o cx23885-core.o cx23885-i2c.o cx23885-dvb.o cx23885-417.o
2 2
3obj-$(CONFIG_VIDEO_CX23885) += cx23885.o 3obj-$(CONFIG_VIDEO_CX23885) += cx23885.o
4 4
diff --git a/drivers/media/video/cx23885/cx23885-417.c b/drivers/media/video/cx23885/cx23885-417.c
new file mode 100644
index 000000000000..acdd3b6b3e7c
--- /dev/null
+++ b/drivers/media/video/cx23885/cx23885-417.c
@@ -0,0 +1,1764 @@
1/*
2 *
3 * Support for a cx23417 mpeg encoder via cx23885 host port.
4 *
5 * (c) 2004 Jelle Foks <jelle@foks.8m.com>
6 * (c) 2004 Gerd Knorr <kraxel@bytesex.org>
7 * (c) 2008 Steven Toth <stoth@hauppauge.com>
8 * - CX23885/7/8 support
9 *
10 * Includes parts from the ivtv driver( http://ivtv.sourceforge.net/),
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */
26
27#include <linux/module.h>
28#include <linux/moduleparam.h>
29#include <linux/init.h>
30#include <linux/fs.h>
31#include <linux/delay.h>
32#include <linux/device.h>
33#include <linux/firmware.h>
34#include <media/v4l2-common.h>
35#include <media/cx2341x.h>
36
37#include "cx23885.h"
38#include "media/cx2341x.h"
39
40#define CX23885_FIRM_IMAGE_SIZE 376836
41#define CX23885_FIRM_IMAGE_NAME "v4l-cx23885-enc.fw"
42
43static unsigned int mpegbufs = 32;
44module_param(mpegbufs, int, 0644);
45MODULE_PARM_DESC(mpegbufs, "number of mpeg buffers, range 2-32");
46static unsigned int mpeglines = 32;
47module_param(mpeglines, int, 0644);
48MODULE_PARM_DESC(mpeglines, "number of lines in an MPEG buffer, range 2-32");
49static unsigned int mpeglinesize = 512;
50module_param(mpeglinesize, int, 0644);
51MODULE_PARM_DESC(mpeglinesize,
52 "number of bytes in each line of an MPEG buffer, range 512-1024");
53
54static unsigned int v4l_debug;
55module_param(v4l_debug, int, 0644);
56MODULE_PARM_DESC(v4l_debug, "enable V4L debug messages");
57
58#define dprintk(level, fmt, arg...)\
59 do { if (v4l_debug >= level) \
60 printk(KERN_DEBUG "%s: " fmt, dev->name , ## arg);\
61 } while (0)
62
63static struct cx23885_tvnorm cx23885_tvnorms[] = {
64 {
65 .name = "NTSC-M",
66 .id = V4L2_STD_NTSC_M,
67 }, {
68 .name = "NTSC-JP",
69 .id = V4L2_STD_NTSC_M_JP,
70 }, {
71 .name = "PAL-BG",
72 .id = V4L2_STD_PAL_BG,
73 }, {
74 .name = "PAL-DK",
75 .id = V4L2_STD_PAL_DK,
76 }, {
77 .name = "PAL-I",
78 .id = V4L2_STD_PAL_I,
79 }, {
80 .name = "PAL-M",
81 .id = V4L2_STD_PAL_M,
82 }, {
83 .name = "PAL-N",
84 .id = V4L2_STD_PAL_N,
85 }, {
86 .name = "PAL-Nc",
87 .id = V4L2_STD_PAL_Nc,
88 }, {
89 .name = "PAL-60",
90 .id = V4L2_STD_PAL_60,
91 }, {
92 .name = "SECAM-L",
93 .id = V4L2_STD_SECAM_L,
94 }, {
95 .name = "SECAM-DK",
96 .id = V4L2_STD_SECAM_DK,
97 }
98};
99
100/* ------------------------------------------------------------------ */
101enum cx23885_capture_type {
102 CX23885_MPEG_CAPTURE,
103 CX23885_RAW_CAPTURE,
104 CX23885_RAW_PASSTHRU_CAPTURE
105};
106enum cx23885_capture_bits {
107 CX23885_RAW_BITS_NONE = 0x00,
108 CX23885_RAW_BITS_YUV_CAPTURE = 0x01,
109 CX23885_RAW_BITS_PCM_CAPTURE = 0x02,
110 CX23885_RAW_BITS_VBI_CAPTURE = 0x04,
111 CX23885_RAW_BITS_PASSTHRU_CAPTURE = 0x08,
112 CX23885_RAW_BITS_TO_HOST_CAPTURE = 0x10
113};
114enum cx23885_capture_end {
115 CX23885_END_AT_GOP, /* stop at the end of gop, generate irq */
116 CX23885_END_NOW, /* stop immediately, no irq */
117};
118enum cx23885_framerate {
119 CX23885_FRAMERATE_NTSC_30, /* NTSC: 30fps */
120 CX23885_FRAMERATE_PAL_25 /* PAL: 25fps */
121};
122enum cx23885_stream_port {
123 CX23885_OUTPUT_PORT_MEMORY,
124 CX23885_OUTPUT_PORT_STREAMING,
125 CX23885_OUTPUT_PORT_SERIAL
126};
127enum cx23885_data_xfer_status {
128 CX23885_MORE_BUFFERS_FOLLOW,
129 CX23885_LAST_BUFFER,
130};
131enum cx23885_picture_mask {
132 CX23885_PICTURE_MASK_NONE,
133 CX23885_PICTURE_MASK_I_FRAMES,
134 CX23885_PICTURE_MASK_I_P_FRAMES = 0x3,
135 CX23885_PICTURE_MASK_ALL_FRAMES = 0x7,
136};
137enum cx23885_vbi_mode_bits {
138 CX23885_VBI_BITS_SLICED,
139 CX23885_VBI_BITS_RAW,
140};
141enum cx23885_vbi_insertion_bits {
142 CX23885_VBI_BITS_INSERT_IN_XTENSION_USR_DATA,
143 CX23885_VBI_BITS_INSERT_IN_PRIVATE_PACKETS = 0x1 << 1,
144 CX23885_VBI_BITS_SEPARATE_STREAM = 0x2 << 1,
145 CX23885_VBI_BITS_SEPARATE_STREAM_USR_DATA = 0x4 << 1,
146 CX23885_VBI_BITS_SEPARATE_STREAM_PRV_DATA = 0x5 << 1,
147};
148enum cx23885_dma_unit {
149 CX23885_DMA_BYTES,
150 CX23885_DMA_FRAMES,
151};
152enum cx23885_dma_transfer_status_bits {
153 CX23885_DMA_TRANSFER_BITS_DONE = 0x01,
154 CX23885_DMA_TRANSFER_BITS_ERROR = 0x04,
155 CX23885_DMA_TRANSFER_BITS_LL_ERROR = 0x10,
156};
157enum cx23885_pause {
158 CX23885_PAUSE_ENCODING,
159 CX23885_RESUME_ENCODING,
160};
161enum cx23885_copyright {
162 CX23885_COPYRIGHT_OFF,
163 CX23885_COPYRIGHT_ON,
164};
165enum cx23885_notification_type {
166 CX23885_NOTIFICATION_REFRESH,
167};
168enum cx23885_notification_status {
169 CX23885_NOTIFICATION_OFF,
170 CX23885_NOTIFICATION_ON,
171};
172enum cx23885_notification_mailbox {
173 CX23885_NOTIFICATION_NO_MAILBOX = -1,
174};
175enum cx23885_field1_lines {
176 CX23885_FIELD1_SAA7114 = 0x00EF, /* 239 */
177 CX23885_FIELD1_SAA7115 = 0x00F0, /* 240 */
178 CX23885_FIELD1_MICRONAS = 0x0105, /* 261 */
179};
180enum cx23885_field2_lines {
181 CX23885_FIELD2_SAA7114 = 0x00EF, /* 239 */
182 CX23885_FIELD2_SAA7115 = 0x00F0, /* 240 */
183 CX23885_FIELD2_MICRONAS = 0x0106, /* 262 */
184};
185enum cx23885_custom_data_type {
186 CX23885_CUSTOM_EXTENSION_USR_DATA,
187 CX23885_CUSTOM_PRIVATE_PACKET,
188};
189enum cx23885_mute {
190 CX23885_UNMUTE,
191 CX23885_MUTE,
192};
193enum cx23885_mute_video_mask {
194 CX23885_MUTE_VIDEO_V_MASK = 0x0000FF00,
195 CX23885_MUTE_VIDEO_U_MASK = 0x00FF0000,
196 CX23885_MUTE_VIDEO_Y_MASK = 0xFF000000,
197};
198enum cx23885_mute_video_shift {
199 CX23885_MUTE_VIDEO_V_SHIFT = 8,
200 CX23885_MUTE_VIDEO_U_SHIFT = 16,
201 CX23885_MUTE_VIDEO_Y_SHIFT = 24,
202};
203
204/* defines below are from ivtv-driver.h */
205#define IVTV_CMD_HW_BLOCKS_RST 0xFFFFFFFF
206
207/* Firmware API commands */
208#define IVTV_API_STD_TIMEOUT 500
209
210/* Registers */
211/* IVTV_REG_OFFSET */
212#define IVTV_REG_ENC_SDRAM_REFRESH (0x07F8)
213#define IVTV_REG_ENC_SDRAM_PRECHARGE (0x07FC)
214#define IVTV_REG_SPU (0x9050)
215#define IVTV_REG_HW_BLOCKS (0x9054)
216#define IVTV_REG_VPU (0x9058)
217#define IVTV_REG_APU (0xA064)
218
219/**** Bit definitions for MC417_RWD and MC417_OEN registers ***
220 bits 31-16
221+-----------+
222| Reserved |
223+-----------+
224 bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8
225+-------+-------+-------+-------+-------+-------+-------+-------+
226| MIWR# | MIRD# | MICS# |MIRDY# |MIADDR3|MIADDR2|MIADDR1|MIADDR0|
227+-------+-------+-------+-------+-------+-------+-------+-------+
228 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0
229+-------+-------+-------+-------+-------+-------+-------+-------+
230|MIDATA7|MIDATA6|MIDATA5|MIDATA4|MIDATA3|MIDATA2|MIDATA1|MIDATA0|
231+-------+-------+-------+-------+-------+-------+-------+-------+
232***/
233#define MC417_MIWR 0x8000
234#define MC417_MIRD 0x4000
235#define MC417_MICS 0x2000
236#define MC417_MIRDY 0x1000
237#define MC417_MIADDR 0x0F00
238#define MC417_MIDATA 0x00FF
239
240/* MIADDR* nibble definitions */
241#define MCI_MEMORY_DATA_BYTE0 0x000
242#define MCI_MEMORY_DATA_BYTE1 0x100
243#define MCI_MEMORY_DATA_BYTE2 0x200
244#define MCI_MEMORY_DATA_BYTE3 0x300
245#define MCI_MEMORY_ADDRESS_BYTE2 0x400
246#define MCI_MEMORY_ADDRESS_BYTE1 0x500
247#define MCI_MEMORY_ADDRESS_BYTE0 0x600
248#define MCI_REGISTER_DATA_BYTE0 0x800
249#define MCI_REGISTER_DATA_BYTE1 0x900
250#define MCI_REGISTER_DATA_BYTE2 0xA00
251#define MCI_REGISTER_DATA_BYTE3 0xB00
252#define MCI_REGISTER_ADDRESS_BYTE0 0xC00
253#define MCI_REGISTER_ADDRESS_BYTE1 0xD00
254#define MCI_REGISTER_MODE 0xE00
255
256/* Read and write modes */
257#define MCI_MODE_REGISTER_READ 0
258#define MCI_MODE_REGISTER_WRITE 1
259#define MCI_MODE_MEMORY_READ 0
260#define MCI_MODE_MEMORY_WRITE 0x40
261
262/*** Bit definitions for MC417_CTL register ****
263 bits 31-6 bits 5-4 bit 3 bits 2-1 Bit 0
264+--------+-------------+--------+--------------+------------+
265|Reserved|MC417_SPD_CTL|Reserved|MC417_GPIO_SEL|UART_GPIO_EN|
266+--------+-------------+--------+--------------+------------+
267***/
268#define MC417_SPD_CTL(x) (((x) << 4) & 0x00000030)
269#define MC417_GPIO_SEL(x) (((x) << 1) & 0x00000006)
270#define MC417_UART_GPIO_EN 0x00000001
271
272/* Values for speed control */
273#define MC417_SPD_CTL_SLOW 0x1
274#define MC417_SPD_CTL_MEDIUM 0x0
275#define MC417_SPD_CTL_FAST 0x3 /* b'1x, but we use b'11 */
276
277/* Values for GPIO select */
278#define MC417_GPIO_SEL_GPIO3 0x3
279#define MC417_GPIO_SEL_GPIO2 0x2
280#define MC417_GPIO_SEL_GPIO1 0x1
281#define MC417_GPIO_SEL_GPIO0 0x0
282
283void cx23885_mc417_init(struct cx23885_dev *dev)
284{
285 u32 regval;
286
287 dprintk(2, "%s()\n", __func__);
288
289 /* Configure MC417_CTL register to defaults. */
290 regval = MC417_SPD_CTL(MC417_SPD_CTL_FAST) |
291 MC417_GPIO_SEL(MC417_GPIO_SEL_GPIO3) |
292 MC417_UART_GPIO_EN;
293 cx_write(MC417_CTL, regval);
294
295 /* Configure MC417_OEN to defaults. */
296 regval = MC417_MIRDY;
297 cx_write(MC417_OEN, regval);
298
299 /* Configure MC417_RWD to defaults. */
300 regval = MC417_MIWR | MC417_MIRD | MC417_MICS;
301 cx_write(MC417_RWD, regval);
302}
303
304static int mc417_wait_ready(struct cx23885_dev *dev)
305{
306 u32 mi_ready;
307 unsigned long timeout = jiffies + msecs_to_jiffies(1);
308
309 for (;;) {
310 mi_ready = cx_read(MC417_RWD) & MC417_MIRDY;
311 if (mi_ready != 0)
312 return 0;
313 if (time_after(jiffies, timeout))
314 return -1;
315 udelay(1);
316 }
317}
318
319static int mc417_register_write(struct cx23885_dev *dev, u16 address, u32 value)
320{
321 u32 regval;
322
323 /* Enable MC417 GPIO outputs except for MC417_MIRDY,
324 * which is an input.
325 */
326 cx_write(MC417_OEN, MC417_MIRDY);
327
328 /* Write data byte 0 */
329 regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_DATA_BYTE0 |
330 (value & 0x000000FF);
331 cx_write(MC417_RWD, regval);
332
333 /* Transition CS/WR to effect write transaction across bus. */
334 regval |= MC417_MICS | MC417_MIWR;
335 cx_write(MC417_RWD, regval);
336
337 /* Write data byte 1 */
338 regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_DATA_BYTE1 |
339 ((value >> 8) & 0x000000FF);
340 cx_write(MC417_RWD, regval);
341 regval |= MC417_MICS | MC417_MIWR;
342 cx_write(MC417_RWD, regval);
343
344 /* Write data byte 2 */
345 regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_DATA_BYTE2 |
346 ((value >> 16) & 0x000000FF);
347 cx_write(MC417_RWD, regval);
348 regval |= MC417_MICS | MC417_MIWR;
349 cx_write(MC417_RWD, regval);
350
351 /* Write data byte 3 */
352 regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_DATA_BYTE3 |
353 ((value >> 24) & 0x000000FF);
354 cx_write(MC417_RWD, regval);
355 regval |= MC417_MICS | MC417_MIWR;
356 cx_write(MC417_RWD, regval);
357
358 /* Write address byte 0 */
359 regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_ADDRESS_BYTE0 |
360 (address & 0xFF);
361 cx_write(MC417_RWD, regval);
362 regval |= MC417_MICS | MC417_MIWR;
363 cx_write(MC417_RWD, regval);
364
365 /* Write address byte 1 */
366 regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_ADDRESS_BYTE1 |
367 ((address >> 8) & 0xFF);
368 cx_write(MC417_RWD, regval);
369 regval |= MC417_MICS | MC417_MIWR;
370 cx_write(MC417_RWD, regval);
371
372 /* Indicate that this is a write. */
373 regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_MODE |
374 MCI_MODE_REGISTER_WRITE;
375 cx_write(MC417_RWD, regval);
376 regval |= MC417_MICS | MC417_MIWR;
377 cx_write(MC417_RWD, regval);
378
379 /* Wait for the trans to complete (MC417_MIRDY asserted). */
380 return mc417_wait_ready(dev);
381}
382
383static int mc417_register_read(struct cx23885_dev *dev, u16 address, u32 *value)
384{
385 int retval;
386 u32 regval;
387 u32 tempval;
388 u32 dataval;
389
390 /* Enable MC417 GPIO outputs except for MC417_MIRDY,
391 * which is an input.
392 */
393 cx_write(MC417_OEN, MC417_MIRDY);
394
395 /* Write address byte 0 */
396 regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_ADDRESS_BYTE0 |
397 ((address & 0x00FF));
398 cx_write(MC417_RWD, regval);
399 regval |= MC417_MICS | MC417_MIWR;
400 cx_write(MC417_RWD, regval);
401
402 /* Write address byte 1 */
403 regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_ADDRESS_BYTE1 |
404 ((address >> 8) & 0xFF);
405 cx_write(MC417_RWD, regval);
406 regval |= MC417_MICS | MC417_MIWR;
407 cx_write(MC417_RWD, regval);
408
409 /* Indicate that this is a register read. */
410 regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_MODE |
411 MCI_MODE_REGISTER_READ;
412 cx_write(MC417_RWD, regval);
413 regval |= MC417_MICS | MC417_MIWR;
414 cx_write(MC417_RWD, regval);
415
416 /* Wait for the trans to complete (MC417_MIRDY asserted). */
417 retval = mc417_wait_ready(dev);
418
419 /* switch the DAT0-7 GPIO[10:3] to input mode */
420 cx_write(MC417_OEN, MC417_MIRDY | MC417_MIDATA);
421
422 /* Read data byte 0 */
423 regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_DATA_BYTE0;
424 cx_write(MC417_RWD, regval);
425
426 /* Transition RD to effect read transaction across bus.
427 * Transtion 0x5000 -> 0x9000 correct (RD/RDY -> WR/RDY)?
428 * Should it be 0x9000 -> 0xF000 (also why is RDY being set, its
429 * input only...)
430 */
431 regval = MC417_MIWR | MC417_MIRDY | MCI_REGISTER_DATA_BYTE0;
432 cx_write(MC417_RWD, regval);
433
434 /* Collect byte */
435 tempval = cx_read(MC417_RWD);
436 dataval = tempval & 0x000000FF;
437
438 /* Bring CS and RD high. */
439 regval = MC417_MIWR | MC417_MIRD | MC417_MICS | MC417_MIRDY;
440 cx_write(MC417_RWD, regval);
441
442 /* Read data byte 1 */
443 regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_DATA_BYTE1;
444 cx_write(MC417_RWD, regval);
445 regval = MC417_MIWR | MC417_MIRDY | MCI_REGISTER_DATA_BYTE1;
446 cx_write(MC417_RWD, regval);
447 tempval = cx_read(MC417_RWD);
448 dataval |= ((tempval & 0x000000FF) << 8);
449 regval = MC417_MIWR | MC417_MIRD | MC417_MICS | MC417_MIRDY;
450 cx_write(MC417_RWD, regval);
451
452 /* Read data byte 2 */
453 regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_DATA_BYTE2;
454 cx_write(MC417_RWD, regval);
455 regval = MC417_MIWR | MC417_MIRDY | MCI_REGISTER_DATA_BYTE2;
456 cx_write(MC417_RWD, regval);
457 tempval = cx_read(MC417_RWD);
458 dataval |= ((tempval & 0x000000FF) << 16);
459 regval = MC417_MIWR | MC417_MIRD | MC417_MICS | MC417_MIRDY;
460 cx_write(MC417_RWD, regval);
461
462 /* Read data byte 3 */
463 regval = MC417_MIRD | MC417_MIRDY | MCI_REGISTER_DATA_BYTE3;
464 cx_write(MC417_RWD, regval);
465 regval = MC417_MIWR | MC417_MIRDY | MCI_REGISTER_DATA_BYTE3;
466 cx_write(MC417_RWD, regval);
467 tempval = cx_read(MC417_RWD);
468 dataval |= ((tempval & 0x000000FF) << 24);
469 regval = MC417_MIWR | MC417_MIRD | MC417_MICS | MC417_MIRDY;
470 cx_write(MC417_RWD, regval);
471
472 *value = dataval;
473
474 return retval;
475}
476
477int mc417_memory_write(struct cx23885_dev *dev, u32 address, u32 value)
478{
479 u32 regval;
480
481 /* Enable MC417 GPIO outputs except for MC417_MIRDY,
482 * which is an input.
483 */
484 cx_write(MC417_OEN, MC417_MIRDY);
485
486 /* Write data byte 0 */
487 regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_DATA_BYTE0 |
488 (value & 0x000000FF);
489 cx_write(MC417_RWD, regval);
490
491 /* Transition CS/WR to effect write transaction across bus. */
492 regval |= MC417_MICS | MC417_MIWR;
493 cx_write(MC417_RWD, regval);
494
495 /* Write data byte 1 */
496 regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_DATA_BYTE1 |
497 ((value >> 8) & 0x000000FF);
498 cx_write(MC417_RWD, regval);
499 regval |= MC417_MICS | MC417_MIWR;
500 cx_write(MC417_RWD, regval);
501
502 /* Write data byte 2 */
503 regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_DATA_BYTE2 |
504 ((value >> 16) & 0x000000FF);
505 cx_write(MC417_RWD, regval);
506 regval |= MC417_MICS | MC417_MIWR;
507 cx_write(MC417_RWD, regval);
508
509 /* Write data byte 3 */
510 regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_DATA_BYTE3 |
511 ((value >> 24) & 0x000000FF);
512 cx_write(MC417_RWD, regval);
513 regval |= MC417_MICS | MC417_MIWR;
514 cx_write(MC417_RWD, regval);
515
516 /* Write address byte 2 */
517 regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_ADDRESS_BYTE2 |
518 MCI_MODE_MEMORY_WRITE | ((address >> 16) & 0x3F);
519 cx_write(MC417_RWD, regval);
520 regval |= MC417_MICS | MC417_MIWR;
521 cx_write(MC417_RWD, regval);
522
523 /* Write address byte 1 */
524 regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_ADDRESS_BYTE1 |
525 ((address >> 8) & 0xFF);
526 cx_write(MC417_RWD, regval);
527 regval |= MC417_MICS | MC417_MIWR;
528 cx_write(MC417_RWD, regval);
529
530 /* Write address byte 0 */
531 regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_ADDRESS_BYTE0 |
532 (address & 0xFF);
533 cx_write(MC417_RWD, regval);
534 regval |= MC417_MICS | MC417_MIWR;
535 cx_write(MC417_RWD, regval);
536
537 /* Wait for the trans to complete (MC417_MIRDY asserted). */
538 return mc417_wait_ready(dev);
539}
540
541int mc417_memory_read(struct cx23885_dev *dev, u32 address, u32 *value)
542{
543 int retval;
544 u32 regval;
545 u32 tempval;
546 u32 dataval;
547
548 /* Enable MC417 GPIO outputs except for MC417_MIRDY,
549 * which is an input.
550 */
551 cx_write(MC417_OEN, MC417_MIRDY);
552
553 /* Write address byte 2 */
554 regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_ADDRESS_BYTE2 |
555 MCI_MODE_MEMORY_READ | ((address >> 16) & 0x3F);
556 cx_write(MC417_RWD, regval);
557 regval |= MC417_MICS | MC417_MIWR;
558 cx_write(MC417_RWD, regval);
559
560 /* Write address byte 1 */
561 regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_ADDRESS_BYTE1 |
562 ((address >> 8) & 0xFF);
563 cx_write(MC417_RWD, regval);
564 regval |= MC417_MICS | MC417_MIWR;
565 cx_write(MC417_RWD, regval);
566
567 /* Write address byte 0 */
568 regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_ADDRESS_BYTE0 |
569 (address & 0xFF);
570 cx_write(MC417_RWD, regval);
571 regval |= MC417_MICS | MC417_MIWR;
572 cx_write(MC417_RWD, regval);
573
574 /* Wait for the trans to complete (MC417_MIRDY asserted). */
575 retval = mc417_wait_ready(dev);
576
577 /* switch the DAT0-7 GPIO[10:3] to input mode */
578 cx_write(MC417_OEN, MC417_MIRDY | MC417_MIDATA);
579
580 /* Read data byte 3 */
581 regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_DATA_BYTE3;
582 cx_write(MC417_RWD, regval);
583
584 /* Transition RD to effect read transaction across bus. */
585 regval = MC417_MIWR | MC417_MIRDY | MCI_MEMORY_DATA_BYTE3;
586 cx_write(MC417_RWD, regval);
587
588 /* Collect byte */
589 tempval = cx_read(MC417_RWD);
590 dataval = ((tempval & 0x000000FF) << 24);
591
592 /* Bring CS and RD high. */
593 regval = MC417_MIWR | MC417_MIRD | MC417_MICS | MC417_MIRDY;
594 cx_write(MC417_RWD, regval);
595
596 /* Read data byte 2 */
597 regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_DATA_BYTE2;
598 cx_write(MC417_RWD, regval);
599 regval = MC417_MIWR | MC417_MIRDY | MCI_MEMORY_DATA_BYTE2;
600 cx_write(MC417_RWD, regval);
601 tempval = cx_read(MC417_RWD);
602 dataval |= ((tempval & 0x000000FF) << 16);
603 regval = MC417_MIWR | MC417_MIRD | MC417_MICS | MC417_MIRDY;
604 cx_write(MC417_RWD, regval);
605
606 /* Read data byte 1 */
607 regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_DATA_BYTE1;
608 cx_write(MC417_RWD, regval);
609 regval = MC417_MIWR | MC417_MIRDY | MCI_MEMORY_DATA_BYTE1;
610 cx_write(MC417_RWD, regval);
611 tempval = cx_read(MC417_RWD);
612 dataval |= ((tempval & 0x000000FF) << 8);
613 regval = MC417_MIWR | MC417_MIRD | MC417_MICS | MC417_MIRDY;
614 cx_write(MC417_RWD, regval);
615
616 /* Read data byte 0 */
617 regval = MC417_MIRD | MC417_MIRDY | MCI_MEMORY_DATA_BYTE0;
618 cx_write(MC417_RWD, regval);
619 regval = MC417_MIWR | MC417_MIRDY | MCI_MEMORY_DATA_BYTE0;
620 cx_write(MC417_RWD, regval);
621 tempval = cx_read(MC417_RWD);
622 dataval |= (tempval & 0x000000FF);
623 regval = MC417_MIWR | MC417_MIRD | MC417_MICS | MC417_MIRDY;
624 cx_write(MC417_RWD, regval);
625
626 *value = dataval;
627
628 return retval;
629}
630
631/* ------------------------------------------------------------------ */
632
633/* MPEG encoder API */
634char *cmd_to_str(int cmd)
635{
636 switch (cmd) {
637 case CX2341X_ENC_PING_FW:
638 return "PING_FW";
639 case CX2341X_ENC_START_CAPTURE:
640 return "START_CAPTURE";
641 case CX2341X_ENC_STOP_CAPTURE:
642 return "STOP_CAPTURE";
643 case CX2341X_ENC_SET_AUDIO_ID:
644 return "SET_AUDIO_ID";
645 case CX2341X_ENC_SET_VIDEO_ID:
646 return "SET_VIDEO_ID";
647 case CX2341X_ENC_SET_PCR_ID:
648 return "SET_PCR_PID";
649 case CX2341X_ENC_SET_FRAME_RATE:
650 return "SET_FRAME_RATE";
651 case CX2341X_ENC_SET_FRAME_SIZE:
652 return "SET_FRAME_SIZE";
653 case CX2341X_ENC_SET_BIT_RATE:
654 return "SET_BIT_RATE";
655 case CX2341X_ENC_SET_GOP_PROPERTIES:
656 return "SET_GOP_PROPERTIES";
657 case CX2341X_ENC_SET_ASPECT_RATIO:
658 return "SET_ASPECT_RATIO";
659 case CX2341X_ENC_SET_DNR_FILTER_MODE:
660 return "SET_DNR_FILTER_PROPS";
661 case CX2341X_ENC_SET_DNR_FILTER_PROPS:
662 return "SET_DNR_FILTER_PROPS";
663 case CX2341X_ENC_SET_CORING_LEVELS:
664 return "SET_CORING_LEVELS";
665 case CX2341X_ENC_SET_SPATIAL_FILTER_TYPE:
666 return "SET_SPATIAL_FILTER_TYPE";
667 case CX2341X_ENC_SET_VBI_LINE:
668 return "SET_VBI_LINE";
669 case CX2341X_ENC_SET_STREAM_TYPE:
670 return "SET_STREAM_TYPE";
671 case CX2341X_ENC_SET_OUTPUT_PORT:
672 return "SET_OUTPUT_PORT";
673 case CX2341X_ENC_SET_AUDIO_PROPERTIES:
674 return "SET_AUDIO_PROPERTIES";
675 case CX2341X_ENC_HALT_FW:
676 return "HALT_FW";
677 case CX2341X_ENC_GET_VERSION:
678 return "GET_VERSION";
679 case CX2341X_ENC_SET_GOP_CLOSURE:
680 return "SET_GOP_CLOSURE";
681 case CX2341X_ENC_GET_SEQ_END:
682 return "GET_SEQ_END";
683 case CX2341X_ENC_SET_PGM_INDEX_INFO:
684 return "SET_PGM_INDEX_INFO";
685 case CX2341X_ENC_SET_VBI_CONFIG:
686 return "SET_VBI_CONFIG";
687 case CX2341X_ENC_SET_DMA_BLOCK_SIZE:
688 return "SET_DMA_BLOCK_SIZE";
689 case CX2341X_ENC_GET_PREV_DMA_INFO_MB_10:
690 return "GET_PREV_DMA_INFO_MB_10";
691 case CX2341X_ENC_GET_PREV_DMA_INFO_MB_9:
692 return "GET_PREV_DMA_INFO_MB_9";
693 case CX2341X_ENC_SCHED_DMA_TO_HOST:
694 return "SCHED_DMA_TO_HOST";
695 case CX2341X_ENC_INITIALIZE_INPUT:
696 return "INITIALIZE_INPUT";
697 case CX2341X_ENC_SET_FRAME_DROP_RATE:
698 return "SET_FRAME_DROP_RATE";
699 case CX2341X_ENC_PAUSE_ENCODER:
700 return "PAUSE_ENCODER";
701 case CX2341X_ENC_REFRESH_INPUT:
702 return "REFRESH_INPUT";
703 case CX2341X_ENC_SET_COPYRIGHT:
704 return "SET_COPYRIGHT";
705 case CX2341X_ENC_SET_EVENT_NOTIFICATION:
706 return "SET_EVENT_NOTIFICATION";
707 case CX2341X_ENC_SET_NUM_VSYNC_LINES:
708 return "SET_NUM_VSYNC_LINES";
709 case CX2341X_ENC_SET_PLACEHOLDER:
710 return "SET_PLACEHOLDER";
711 case CX2341X_ENC_MUTE_VIDEO:
712 return "MUTE_VIDEO";
713 case CX2341X_ENC_MUTE_AUDIO:
714 return "MUTE_AUDIO";
715 case CX2341X_ENC_MISC:
716 return "MISC";
717 default:
718 return "UNKNOWN";
719 }
720}
721
722static int cx23885_mbox_func(void *priv,
723 u32 command,
724 int in,
725 int out,
726 u32 data[CX2341X_MBOX_MAX_DATA])
727{
728 struct cx23885_dev *dev = priv;
729 unsigned long timeout;
730 u32 value, flag, retval = 0;
731 int i;
732
733 dprintk(3, "%s: command(0x%X) = %s\n", __func__, command,
734 cmd_to_str(command));
735
736 /* this may not be 100% safe if we can't read any memory location
737 without side effects */
738 mc417_memory_read(dev, dev->cx23417_mailbox - 4, &value);
739 if (value != 0x12345678) {
740 printk(KERN_ERR
741 "Firmware and/or mailbox pointer not initialized "
742 "or corrupted, signature = 0x%x, cmd = %s\n", value,
743 cmd_to_str(command));
744 return -1;
745 }
746
747 /* This read looks at 32 bits, but flag is only 8 bits.
748 * Seems we also bail if CMD or TIMEOUT bytes are set???
749 */
750 mc417_memory_read(dev, dev->cx23417_mailbox, &flag);
751 if (flag) {
752 printk(KERN_ERR "ERROR: Mailbox appears to be in use "
753 "(%x), cmd = %s\n", flag, cmd_to_str(command));
754 return -1;
755 }
756
757 flag |= 1; /* tell 'em we're working on it */
758 mc417_memory_write(dev, dev->cx23417_mailbox, flag);
759
760 /* write command + args + fill remaining with zeros */
761 /* command code */
762 mc417_memory_write(dev, dev->cx23417_mailbox + 1, command);
763 mc417_memory_write(dev, dev->cx23417_mailbox + 3,
764 IVTV_API_STD_TIMEOUT); /* timeout */
765 for (i = 0; i < in; i++) {
766 mc417_memory_write(dev, dev->cx23417_mailbox + 4 + i, data[i]);
767 dprintk(3, "API Input %d = %d\n", i, data[i]);
768 }
769 for (; i < CX2341X_MBOX_MAX_DATA; i++)
770 mc417_memory_write(dev, dev->cx23417_mailbox + 4 + i, 0);
771
772 flag |= 3; /* tell 'em we're done writing */
773 mc417_memory_write(dev, dev->cx23417_mailbox, flag);
774
775 /* wait for firmware to handle the API command */
776 timeout = jiffies + msecs_to_jiffies(10);
777 for (;;) {
778 mc417_memory_read(dev, dev->cx23417_mailbox, &flag);
779 if (0 != (flag & 4))
780 break;
781 if (time_after(jiffies, timeout)) {
782 printk(KERN_ERR "ERROR: API Mailbox timeout\n");
783 return -1;
784 }
785 udelay(10);
786 }
787
788 /* read output values */
789 for (i = 0; i < out; i++) {
790 mc417_memory_read(dev, dev->cx23417_mailbox + 4 + i, data + i);
791 dprintk(3, "API Output %d = %d\n", i, data[i]);
792 }
793
794 mc417_memory_read(dev, dev->cx23417_mailbox + 2, &retval);
795 dprintk(3, "API result = %d\n", retval);
796
797 flag = 0;
798 mc417_memory_write(dev, dev->cx23417_mailbox, flag);
799
800 return retval;
801}
802
803/* We don't need to call the API often, so using just one
804 * mailbox will probably suffice
805 */
806static int cx23885_api_cmd(struct cx23885_dev *dev,
807 u32 command,
808 u32 inputcnt,
809 u32 outputcnt,
810 ...)
811{
812 u32 data[CX2341X_MBOX_MAX_DATA];
813 va_list vargs;
814 int i, err;
815
816 dprintk(3, "%s() cmds = 0x%08x\n", __func__, command);
817
818 va_start(vargs, outputcnt);
819 for (i = 0; i < inputcnt; i++)
820 data[i] = va_arg(vargs, int);
821
822 err = cx23885_mbox_func(dev, command, inputcnt, outputcnt, data);
823 for (i = 0; i < outputcnt; i++) {
824 int *vptr = va_arg(vargs, int *);
825 *vptr = data[i];
826 }
827 va_end(vargs);
828
829 return err;
830}
831
832static int cx23885_find_mailbox(struct cx23885_dev *dev)
833{
834 u32 signature[4] = {
835 0x12345678, 0x34567812, 0x56781234, 0x78123456
836 };
837 int signaturecnt = 0;
838 u32 value;
839 int i;
840
841 dprintk(2, "%s()\n", __func__);
842
843 for (i = 0; i < CX23885_FIRM_IMAGE_SIZE; i++) {
844 mc417_memory_read(dev, i, &value);
845 if (value == signature[signaturecnt])
846 signaturecnt++;
847 else
848 signaturecnt = 0;
849 if (4 == signaturecnt) {
850 dprintk(1, "Mailbox signature found at 0x%x\n", i+1);
851 return i+1;
852 }
853 }
854 printk(KERN_ERR "Mailbox signature values not found!\n");
855 return -1;
856}
857
858static int cx23885_load_firmware(struct cx23885_dev *dev)
859{
860 static const unsigned char magic[8] = {
861 0xa7, 0x0d, 0x00, 0x00, 0x66, 0xbb, 0x55, 0xaa
862 };
863 const struct firmware *firmware;
864 int i, retval = 0;
865 u32 value = 0;
866 u32 gpio_output = 0;
867 u32 checksum = 0;
868 u32 *dataptr;
869
870 dprintk(2, "%s()\n", __func__);
871
872 /* Save GPIO settings before reset of APU */
873 retval |= mc417_memory_read(dev, 0x9020, &gpio_output);
874 retval |= mc417_memory_read(dev, 0x900C, &value);
875
876 retval = mc417_register_write(dev,
877 IVTV_REG_VPU, 0xFFFFFFED);
878 retval |= mc417_register_write(dev,
879 IVTV_REG_HW_BLOCKS, IVTV_CMD_HW_BLOCKS_RST);
880 retval |= mc417_register_write(dev,
881 IVTV_REG_ENC_SDRAM_REFRESH, 0x80000800);
882 retval |= mc417_register_write(dev,
883 IVTV_REG_ENC_SDRAM_PRECHARGE, 0x1A);
884 retval |= mc417_register_write(dev,
885 IVTV_REG_APU, 0);
886
887 if (retval != 0) {
888 printk(KERN_ERR "%s: Error with mc417_register_write\n",
889 __func__);
890 return -1;
891 }
892
893 retval = request_firmware(&firmware, CX23885_FIRM_IMAGE_NAME,
894 &dev->pci->dev);
895
896 if (retval != 0) {
897 printk(KERN_ERR
898 "ERROR: Hotplug firmware request failed (%s).\n",
899 CX2341X_FIRM_ENC_FILENAME);
900 printk(KERN_ERR "Please fix your hotplug setup, the board will "
901 "not work without firmware loaded!\n");
902 return -1;
903 }
904
905 if (firmware->size != CX23885_FIRM_IMAGE_SIZE) {
906 printk(KERN_ERR "ERROR: Firmware size mismatch "
907 "(have %zd, expected %d)\n",
908 firmware->size, CX23885_FIRM_IMAGE_SIZE);
909 release_firmware(firmware);
910 return -1;
911 }
912
913 if (0 != memcmp(firmware->data, magic, 8)) {
914 printk(KERN_ERR
915 "ERROR: Firmware magic mismatch, wrong file?\n");
916 release_firmware(firmware);
917 return -1;
918 }
919
920 /* transfer to the chip */
921 dprintk(2, "Loading firmware ...\n");
922 dataptr = (u32 *)firmware->data;
923 for (i = 0; i < (firmware->size >> 2); i++) {
924 value = *dataptr;
925 checksum += ~value;
926 if (mc417_memory_write(dev, i, value) != 0) {
927 printk(KERN_ERR "ERROR: Loading firmware failed!\n");
928 release_firmware(firmware);
929 return -1;
930 }
931 dataptr++;
932 }
933
934 /* read back to verify with the checksum */
935 dprintk(1, "Verifying firmware ...\n");
936 for (i--; i >= 0; i--) {
937 if (mc417_memory_read(dev, i, &value) != 0) {
938 printk(KERN_ERR "ERROR: Reading firmware failed!\n");
939 release_firmware(firmware);
940 return -1;
941 }
942 checksum -= ~value;
943 }
944 if (checksum) {
945 printk(KERN_ERR
946 "ERROR: Firmware load failed (checksum mismatch).\n");
947 release_firmware(firmware);
948 return -1;
949 }
950 release_firmware(firmware);
951 dprintk(1, "Firmware upload successful.\n");
952
953 retval |= mc417_register_write(dev, IVTV_REG_HW_BLOCKS,
954 IVTV_CMD_HW_BLOCKS_RST);
955
956 /* Restore GPIO settings, make sure EIO14 is enabled as an output. */
957 dprintk(2, "%s: GPIO output EIO 0-15 was = 0x%x\n",
958 __func__, gpio_output);
959 /* Power-up seems to have GPIOs AFU. This was causing digital side
960 * to fail at power-up. Seems GPIOs should be set to 0x10ff0411 at
961 * power-up.
962 * gpio_output |= (1<<14);
963 */
964 /* Note: GPIO14 is specific to the HVR1800 here */
965 gpio_output = 0x10ff0411 | (1<<14);
966 retval |= mc417_register_write(dev, 0x9020, gpio_output | (1<<14));
967 dprintk(2, "%s: GPIO output EIO 0-15 now = 0x%x\n",
968 __func__, gpio_output);
969
970 dprintk(1, "%s: GPIO value EIO 0-15 was = 0x%x\n",
971 __func__, value);
972 value |= (1<<14);
973 dprintk(1, "%s: GPIO value EIO 0-15 now = 0x%x\n",
974 __func__, value);
975 retval |= mc417_register_write(dev, 0x900C, value);
976
977 retval |= mc417_register_read(dev, IVTV_REG_VPU, &value);
978 retval |= mc417_register_write(dev, IVTV_REG_VPU, value & 0xFFFFFFE8);
979
980 if (retval < 0)
981 printk(KERN_ERR "%s: Error with mc417_register_write\n",
982 __func__);
983 return 0;
984}
985
986void cx23885_417_check_encoder(struct cx23885_dev *dev)
987{
988 u32 status, seq;
989
990 status = seq = 0;
991 cx23885_api_cmd(dev, CX2341X_ENC_GET_SEQ_END, 0, 2, &status, &seq);
992 dprintk(1, "%s() status = %d, seq = %d\n", __func__, status, seq);
993}
994
995static void cx23885_codec_settings(struct cx23885_dev *dev)
996{
997 dprintk(1, "%s()\n", __func__);
998
999 /* assign frame size */
1000 cx23885_api_cmd(dev, CX2341X_ENC_SET_FRAME_SIZE, 2, 0,
1001 dev->ts1.height, dev->ts1.width);
1002
1003 dev->mpeg_params.width = dev->ts1.width;
1004 dev->mpeg_params.height = dev->ts1.height;
1005 dev->mpeg_params.is_50hz =
1006 (dev->encodernorm.id & V4L2_STD_625_50) != 0;
1007
1008 cx2341x_update(dev, cx23885_mbox_func, NULL, &dev->mpeg_params);
1009
1010 cx23885_api_cmd(dev, CX2341X_ENC_MISC, 2, 0, 3, 1);
1011 cx23885_api_cmd(dev, CX2341X_ENC_MISC, 2, 0, 4, 1);
1012}
1013
1014static int cx23885_initialize_codec(struct cx23885_dev *dev)
1015{
1016 int version;
1017 int retval;
1018 u32 i, data[7];
1019
1020 dprintk(1, "%s()\n", __func__);
1021
1022 retval = cx23885_api_cmd(dev, CX2341X_ENC_PING_FW, 0, 0); /* ping */
1023 if (retval < 0) {
1024 dprintk(2, "%s() PING OK\n", __func__);
1025 retval = cx23885_load_firmware(dev);
1026 if (retval < 0) {
1027 printk(KERN_ERR "%s() f/w load failed\n", __func__);
1028 return retval;
1029 }
1030 dev->cx23417_mailbox = cx23885_find_mailbox(dev);
1031 if (dev->cx23417_mailbox < 0) {
1032 printk(KERN_ERR "%s() mailbox < 0, error\n",
1033 __func__);
1034 return -1;
1035 }
1036 retval = cx23885_api_cmd(dev, CX2341X_ENC_PING_FW, 0, 0);
1037 if (retval < 0) {
1038 printk(KERN_ERR
1039 "ERROR: cx23417 firmware ping failed!\n");
1040 return -1;
1041 }
1042 retval = cx23885_api_cmd(dev, CX2341X_ENC_GET_VERSION, 0, 1,
1043 &version);
1044 if (retval < 0) {
1045 printk(KERN_ERR "ERROR: cx23417 firmware get encoder :"
1046 "version failed!\n");
1047 return -1;
1048 }
1049 dprintk(1, "cx23417 firmware version is 0x%08x\n", version);
1050 msleep(200);
1051 }
1052
1053 cx23885_codec_settings(dev);
1054 msleep(60);
1055
1056 cx23885_api_cmd(dev, CX2341X_ENC_SET_NUM_VSYNC_LINES, 2, 0,
1057 CX23885_FIELD1_SAA7115, CX23885_FIELD2_SAA7115);
1058 cx23885_api_cmd(dev, CX2341X_ENC_SET_PLACEHOLDER, 12, 0,
1059 CX23885_CUSTOM_EXTENSION_USR_DATA, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1060 0, 0);
1061
1062 /* Setup to capture VBI */
1063 data[0] = 0x0001BD00;
1064 data[1] = 1; /* frames per interrupt */
1065 data[2] = 4; /* total bufs */
1066 data[3] = 0x91559155; /* start codes */
1067 data[4] = 0x206080C0; /* stop codes */
1068 data[5] = 6; /* lines */
1069 data[6] = 64; /* BPL */
1070
1071 cx23885_api_cmd(dev, CX2341X_ENC_SET_VBI_CONFIG, 7, 0, data[0], data[1],
1072 data[2], data[3], data[4], data[5], data[6]);
1073
1074 for (i = 2; i <= 24; i++) {
1075 int valid;
1076
1077 valid = ((i >= 19) && (i <= 21));
1078 cx23885_api_cmd(dev, CX2341X_ENC_SET_VBI_LINE, 5, 0, i,
1079 valid, 0 , 0, 0);
1080 cx23885_api_cmd(dev, CX2341X_ENC_SET_VBI_LINE, 5, 0,
1081 i | 0x80000000, valid, 0, 0, 0);
1082 }
1083
1084 cx23885_api_cmd(dev, CX2341X_ENC_MUTE_AUDIO, 1, 0, CX23885_UNMUTE);
1085 msleep(60);
1086
1087 /* initialize the video input */
1088 cx23885_api_cmd(dev, CX2341X_ENC_INITIALIZE_INPUT, 0, 0);
1089 msleep(60);
1090
1091 /* Enable VIP style pixel invalidation so we work with scaled mode */
1092 mc417_memory_write(dev, 2120, 0x00000080);
1093
1094 /* start capturing to the host interface */
1095 cx23885_api_cmd(dev, CX2341X_ENC_START_CAPTURE, 2, 0,
1096 CX23885_MPEG_CAPTURE, CX23885_RAW_BITS_NONE);
1097 msleep(10);
1098
1099 return 0;
1100}
1101
1102/* ------------------------------------------------------------------ */
1103
1104static int bb_buf_setup(struct videobuf_queue *q,
1105 unsigned int *count, unsigned int *size)
1106{
1107 struct cx23885_fh *fh = q->priv_data;
1108
1109 fh->dev->ts1.ts_packet_size = mpeglinesize;
1110 fh->dev->ts1.ts_packet_count = mpeglines;
1111
1112 *size = fh->dev->ts1.ts_packet_size * fh->dev->ts1.ts_packet_count;
1113 *count = mpegbufs;
1114
1115 return 0;
1116}
1117
1118static int bb_buf_prepare(struct videobuf_queue *q,
1119 struct videobuf_buffer *vb, enum v4l2_field field)
1120{
1121 struct cx23885_fh *fh = q->priv_data;
1122 return cx23885_buf_prepare(q, &fh->dev->ts1,
1123 (struct cx23885_buffer *)vb,
1124 field);
1125}
1126
1127static void bb_buf_queue(struct videobuf_queue *q,
1128 struct videobuf_buffer *vb)
1129{
1130 struct cx23885_fh *fh = q->priv_data;
1131 cx23885_buf_queue(&fh->dev->ts1, (struct cx23885_buffer *)vb);
1132}
1133
1134static void bb_buf_release(struct videobuf_queue *q,
1135 struct videobuf_buffer *vb)
1136{
1137 cx23885_free_buffer(q, (struct cx23885_buffer *)vb);
1138}
1139
1140static struct videobuf_queue_ops cx23885_qops = {
1141 .buf_setup = bb_buf_setup,
1142 .buf_prepare = bb_buf_prepare,
1143 .buf_queue = bb_buf_queue,
1144 .buf_release = bb_buf_release,
1145};
1146
1147/* ------------------------------------------------------------------ */
1148
1149static const u32 *ctrl_classes[] = {
1150 cx2341x_mpeg_ctrls,
1151 NULL
1152};
1153
1154static int cx23885_queryctrl(struct cx23885_dev *dev,
1155 struct v4l2_queryctrl *qctrl)
1156{
1157 qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
1158 if (qctrl->id == 0)
1159 return -EINVAL;
1160
1161 /* MPEG V4L2 controls */
1162 if (cx2341x_ctrl_query(&dev->mpeg_params, qctrl))
1163 qctrl->flags |= V4L2_CTRL_FLAG_DISABLED;
1164
1165 return 0;
1166}
1167
1168static int cx23885_querymenu(struct cx23885_dev *dev,
1169 struct v4l2_querymenu *qmenu)
1170{
1171 struct v4l2_queryctrl qctrl;
1172
1173 qctrl.id = qmenu->id;
1174 cx23885_queryctrl(dev, &qctrl);
1175 return v4l2_ctrl_query_menu(qmenu, &qctrl,
1176 cx2341x_ctrl_get_menu(qmenu->id));
1177}
1178
1179int cx23885_do_ioctl(struct inode *inode, struct file *file, int radio,
1180 struct cx23885_dev *dev, unsigned int cmd, void *arg,
1181 v4l2_kioctl driver_ioctl)
1182{
1183 int err;
1184
1185 switch (cmd) {
1186 /* ---------- tv norms ---------- */
1187 case VIDIOC_ENUMSTD:
1188 {
1189 struct v4l2_standard *e = arg;
1190 unsigned int i;
1191
1192 i = e->index;
1193 if (i >= ARRAY_SIZE(cx23885_tvnorms))
1194 return -EINVAL;
1195 err = v4l2_video_std_construct(e,
1196 cx23885_tvnorms[e->index].id,
1197 cx23885_tvnorms[e->index].name);
1198 e->index = i;
1199 if (err < 0)
1200 return err;
1201 return 0;
1202 }
1203 case VIDIOC_G_STD:
1204 {
1205 v4l2_std_id *id = arg;
1206
1207 *id = dev->encodernorm.id;
1208 return 0;
1209 }
1210 case VIDIOC_S_STD:
1211 {
1212 v4l2_std_id *id = arg;
1213 unsigned int i;
1214
1215 for (i = 0; i < ARRAY_SIZE(cx23885_tvnorms); i++)
1216 if (*id & cx23885_tvnorms[i].id)
1217 break;
1218 if (i == ARRAY_SIZE(cx23885_tvnorms))
1219 return -EINVAL;
1220 dev->encodernorm = cx23885_tvnorms[i];
1221
1222 return 0;
1223 }
1224
1225 /* ------ input switching ---------- */
1226 case VIDIOC_ENUMINPUT:
1227 {
1228 struct cx23885_input *input;
1229 struct v4l2_input *i = arg;
1230 unsigned int n;
1231
1232 n = i->index;
1233 if (n >= 4)
1234 return -EINVAL;
1235 input = &cx23885_boards[dev->board].input[n];
1236 if (input->type == 0)
1237 return -EINVAL;
1238 memset(i, 0, sizeof(*i));
1239 i->index = n;
1240 /* FIXME
1241 * strcpy(i->name, input->name); */
1242 strcpy(i->name, "unset");
1243 if (input->type == CX23885_VMUX_TELEVISION ||
1244 input->type == CX23885_VMUX_CABLE)
1245 i->type = V4L2_INPUT_TYPE_TUNER;
1246 else
1247 i->type = V4L2_INPUT_TYPE_CAMERA;
1248
1249 for (n = 0; n < ARRAY_SIZE(cx23885_tvnorms); n++)
1250 i->std |= cx23885_tvnorms[n].id;
1251 return 0;
1252 }
1253 case VIDIOC_G_INPUT:
1254 {
1255 unsigned int *i = arg;
1256
1257 *i = dev->input;
1258 return 0;
1259 }
1260 case VIDIOC_S_INPUT:
1261 {
1262 unsigned int *i = arg;
1263
1264 if (*i >= 4)
1265 return -EINVAL;
1266
1267 return 0;
1268 }
1269
1270 /* --- tuner ioctls ------------------------------------------ */
1271 case VIDIOC_G_TUNER:
1272 {
1273 struct v4l2_tuner *t = arg;
1274
1275 if (UNSET == dev->tuner_type)
1276 return -EINVAL;
1277 if (0 != t->index)
1278 return -EINVAL;
1279 memset(t, 0, sizeof(*t));
1280 strcpy(t->name, "Television");
1281 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_G_TUNER, t);
1282 cx23885_call_i2c_clients(&dev->i2c_bus[1], VIDIOC_G_TUNER, t);
1283
1284 dprintk(1, "VIDIOC_G_TUNER: tuner type %d\n", t->type);
1285
1286 return 0;
1287 }
1288 case VIDIOC_S_TUNER:
1289 {
1290 struct v4l2_tuner *t = arg;
1291
1292 if (UNSET == dev->tuner_type)
1293 return -EINVAL;
1294
1295 /* Update the A/V core */
1296 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_S_TUNER, t);
1297
1298 return 0;
1299 }
1300 case VIDIOC_G_FREQUENCY:
1301 {
1302 struct v4l2_frequency *f = arg;
1303
1304 memset(f, 0, sizeof(*f));
1305 if (UNSET == dev->tuner_type)
1306 return -EINVAL;
1307 f->type = V4L2_TUNER_ANALOG_TV;
1308 f->frequency = dev->freq;
1309
1310 /* Assumption that tuner is always on bus 1 */
1311 cx23885_call_i2c_clients(&dev->i2c_bus[1],
1312 VIDIOC_G_FREQUENCY, f);
1313
1314 return 0;
1315 }
1316 case VIDIOC_S_FREQUENCY:
1317 {
1318 struct v4l2_frequency *f = arg;
1319
1320 dprintk(1, "VIDIOC_S_FREQUENCY: dev type %d, f\n",
1321 dev->tuner_type);
1322 dprintk(1, "VIDIOC_S_FREQUENCY: f tuner %d, f type %d\n",
1323 f->tuner, f->type);
1324 if (UNSET == dev->tuner_type)
1325 return -EINVAL;
1326 if (f->tuner != 0)
1327 return -EINVAL;
1328 if (f->type != V4L2_TUNER_ANALOG_TV)
1329 return -EINVAL;
1330 dev->freq = f->frequency;
1331
1332 /* Assumption that tuner is always on bus 1 */
1333 cx23885_call_i2c_clients(&dev->i2c_bus[1],
1334 VIDIOC_S_FREQUENCY, f);
1335 return 0;
1336 }
1337 case VIDIOC_S_CTRL:
1338 {
1339 /* Update the A/V core */
1340 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_S_CTRL, arg);
1341 return 0;
1342 }
1343 default:
1344 /* Convert V4L ioctl to V4L2 and call mpeg_do_ioctl
1345 * (driver_ioctl) */
1346 return v4l_compat_translate_ioctl(inode, file, cmd, arg,
1347 driver_ioctl);
1348 }
1349
1350 return 0;
1351}
1352
1353static int mpeg_do_ioctl(struct inode *inode, struct file *file,
1354 unsigned int cmd, void *arg)
1355{
1356 struct cx23885_fh *fh = file->private_data;
1357 struct cx23885_dev *dev = fh->dev;
1358 struct cx23885_tsport *tsport = &dev->ts1;
1359
1360 if (v4l_debug > 1)
1361 v4l_print_ioctl(dev->name, cmd);
1362
1363 switch (cmd) {
1364
1365 /* --- capabilities ------------------------------------------ */
1366 case VIDIOC_QUERYCAP:
1367 {
1368 struct v4l2_capability *cap = arg;
1369
1370 memset(cap, 0, sizeof(*cap));
1371 strcpy(cap->driver, dev->name);
1372 strlcpy(cap->card, cx23885_boards[tsport->dev->board].name,
1373 sizeof(cap->card));
1374 sprintf(cap->bus_info, "PCI:%s", pci_name(dev->pci));
1375 cap->version = CX23885_VERSION_CODE;
1376 cap->capabilities =
1377 V4L2_CAP_VIDEO_CAPTURE |
1378 V4L2_CAP_READWRITE |
1379 V4L2_CAP_STREAMING |
1380 0;
1381 if (UNSET != dev->tuner_type)
1382 cap->capabilities |= V4L2_CAP_TUNER;
1383
1384 return 0;
1385 }
1386
1387 /* --- capture ioctls ---------------------------------------- */
1388 case VIDIOC_ENUM_FMT:
1389 {
1390 struct v4l2_fmtdesc *f = arg;
1391 int index;
1392
1393 index = f->index;
1394 if (index != 0)
1395 return -EINVAL;
1396
1397 memset(f, 0, sizeof(*f));
1398 f->index = index;
1399 strlcpy(f->description, "MPEG", sizeof(f->description));
1400 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1401 f->pixelformat = V4L2_PIX_FMT_MPEG;
1402 return 0;
1403 }
1404 case VIDIOC_G_FMT:
1405 {
1406 struct v4l2_format *f = arg;
1407
1408 memset(f, 0, sizeof(*f));
1409 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1410 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
1411 f->fmt.pix.bytesperline = 0;
1412 f->fmt.pix.sizeimage =
1413 dev->ts1.ts_packet_size * dev->ts1.ts_packet_count;
1414 f->fmt.pix.colorspace = 0;
1415 f->fmt.pix.width = dev->ts1.width;
1416 f->fmt.pix.height = dev->ts1.height;
1417 f->fmt.pix.field = fh->mpegq.field;
1418 dprintk(1, "VIDIOC_G_FMT: w: %d, h: %d, f: %d\n",
1419 dev->ts1.width, dev->ts1.height, fh->mpegq.field);
1420 return 0;
1421 }
1422 case VIDIOC_TRY_FMT:
1423 {
1424 struct v4l2_format *f = arg;
1425
1426 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1427 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
1428 f->fmt.pix.bytesperline = 0;
1429 f->fmt.pix.sizeimage =
1430 dev->ts1.ts_packet_size * dev->ts1.ts_packet_count;
1431 f->fmt.pix.sizeimage =
1432 f->fmt.pix.colorspace = 0;
1433 dprintk(1, "VIDIOC_TRY_FMT: w: %d, h: %d, f: %d\n",
1434 dev->ts1.width, dev->ts1.height, fh->mpegq.field);
1435 return 0;
1436 }
1437 case VIDIOC_S_FMT:
1438 {
1439 struct v4l2_format *f = arg;
1440
1441 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1442 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MPEG;
1443 f->fmt.pix.bytesperline = 0;
1444 f->fmt.pix.sizeimage =
1445 dev->ts1.ts_packet_size * dev->ts1.ts_packet_count;
1446 f->fmt.pix.colorspace = 0;
1447 dprintk(1, "VIDIOC_S_FMT: w: %d, h: %d, f: %d\n",
1448 f->fmt.pix.width, f->fmt.pix.height, f->fmt.pix.field);
1449 return 0;
1450 }
1451
1452 /* --- streaming capture ------------------------------------- */
1453 case VIDIOC_REQBUFS:
1454 return videobuf_reqbufs(&fh->mpegq, arg);
1455
1456 case VIDIOC_QUERYBUF:
1457 return videobuf_querybuf(&fh->mpegq, arg);
1458
1459 case VIDIOC_QBUF:
1460 return videobuf_qbuf(&fh->mpegq, arg);
1461
1462 case VIDIOC_DQBUF:
1463 return videobuf_dqbuf(&fh->mpegq, arg,
1464 file->f_flags & O_NONBLOCK);
1465
1466 case VIDIOC_STREAMON:
1467 return videobuf_streamon(&fh->mpegq);
1468
1469 case VIDIOC_STREAMOFF:
1470 return videobuf_streamoff(&fh->mpegq);
1471
1472 case VIDIOC_G_EXT_CTRLS:
1473 {
1474 struct v4l2_ext_controls *f = arg;
1475
1476 if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG)
1477 return -EINVAL;
1478 return cx2341x_ext_ctrls(&dev->mpeg_params, 0, f, cmd);
1479 }
1480 case VIDIOC_S_EXT_CTRLS:
1481 case VIDIOC_TRY_EXT_CTRLS:
1482 {
1483 struct v4l2_ext_controls *f = arg;
1484 struct cx2341x_mpeg_params p;
1485 int err;
1486
1487 if (f->ctrl_class != V4L2_CTRL_CLASS_MPEG)
1488 return -EINVAL;
1489 p = dev->mpeg_params;
1490 err = cx2341x_ext_ctrls(&p, 0, f, cmd);
1491 if (err == 0 && cmd == VIDIOC_S_EXT_CTRLS) {
1492 err = cx2341x_update(dev, cx23885_mbox_func,
1493 &dev->mpeg_params, &p);
1494 dev->mpeg_params = p;
1495 }
1496 return err;
1497 }
1498 case VIDIOC_S_FREQUENCY:
1499 {
1500 cx23885_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0,
1501 CX23885_END_NOW, CX23885_MPEG_CAPTURE,
1502 CX23885_RAW_BITS_NONE);
1503 cx23885_do_ioctl(inode, file, 0, dev, cmd, arg,
1504 mpeg_do_ioctl);
1505 cx23885_initialize_codec(dev);
1506
1507 return 0;
1508 }
1509 case VIDIOC_LOG_STATUS:
1510 {
1511 char name[32 + 2];
1512
1513 snprintf(name, sizeof(name), "%s/2", dev->name);
1514 printk(KERN_INFO
1515 "%s/2: ============ START LOG STATUS ============\n",
1516 dev->name);
1517 cx23885_call_i2c_clients(&dev->i2c_bus[0], VIDIOC_LOG_STATUS,
1518 NULL);
1519 cx23885_call_i2c_clients(&dev->i2c_bus[1], VIDIOC_LOG_STATUS,
1520 NULL);
1521 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_LOG_STATUS,
1522 NULL);
1523 cx2341x_log_status(&dev->mpeg_params, name);
1524 printk(KERN_INFO
1525 "%s/2: ============= END LOG STATUS =============\n",
1526 dev->name);
1527 return 0;
1528 }
1529 case VIDIOC_QUERYMENU:
1530 return cx23885_querymenu(dev, arg);
1531 case VIDIOC_QUERYCTRL:
1532 {
1533 struct v4l2_queryctrl *c = arg;
1534
1535 return cx23885_queryctrl(dev, c);
1536 }
1537
1538 default:
1539 return cx23885_do_ioctl(inode, file, 0, dev, cmd, arg,
1540 mpeg_do_ioctl);
1541 }
1542 return 0;
1543}
1544
1545static int mpeg_ioctl(struct inode *inode, struct file *file,
1546 unsigned int cmd, unsigned long arg)
1547{
1548 return video_usercopy(inode, file, cmd, arg, mpeg_do_ioctl);
1549}
1550
1551static int mpeg_open(struct inode *inode, struct file *file)
1552{
1553 int minor = iminor(inode);
1554 struct cx23885_dev *h, *dev = NULL;
1555 struct list_head *list;
1556 struct cx23885_fh *fh;
1557
1558 dprintk(2, "%s()\n", __func__);
1559
1560 list_for_each(list, &cx23885_devlist) {
1561 h = list_entry(list, struct cx23885_dev, devlist);
1562 if (h->v4l_device->minor == minor) {
1563 dev = h;
1564 break;
1565 }
1566 }
1567
1568 if (dev == NULL)
1569 return -ENODEV;
1570
1571 /* allocate + initialize per filehandle data */
1572 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
1573 if (NULL == fh)
1574 return -ENOMEM;
1575
1576 file->private_data = fh;
1577 fh->dev = dev;
1578
1579 videobuf_queue_sg_init(&fh->mpegq, &cx23885_qops,
1580 &dev->pci->dev, &dev->ts1.slock,
1581 V4L2_BUF_TYPE_VIDEO_CAPTURE,
1582 V4L2_FIELD_INTERLACED,
1583 sizeof(struct cx23885_buffer),
1584 fh);
1585
1586 return 0;
1587}
1588
1589static int mpeg_release(struct inode *inode, struct file *file)
1590{
1591 struct cx23885_fh *fh = file->private_data;
1592 struct cx23885_dev *dev = fh->dev;
1593
1594 dprintk(2, "%s()\n", __func__);
1595
1596 /* FIXME: Review this crap */
1597 /* Shut device down on last close */
1598 if (atomic_cmpxchg(&fh->v4l_reading, 1, 0) == 1) {
1599 if (atomic_dec_return(&dev->v4l_reader_count) == 0) {
1600 /* stop mpeg capture */
1601 cx23885_api_cmd(fh->dev, CX2341X_ENC_STOP_CAPTURE, 3, 0,
1602 CX23885_END_NOW, CX23885_MPEG_CAPTURE,
1603 CX23885_RAW_BITS_NONE);
1604
1605 msleep(500);
1606 cx23885_417_check_encoder(dev);
1607
1608 cx23885_cancel_buffers(&fh->dev->ts1);
1609 }
1610 }
1611
1612 if (fh->mpegq.streaming)
1613 videobuf_streamoff(&fh->mpegq);
1614 if (fh->mpegq.reading)
1615 videobuf_read_stop(&fh->mpegq);
1616
1617 videobuf_mmap_free(&fh->mpegq);
1618 file->private_data = NULL;
1619 kfree(fh);
1620
1621 return 0;
1622}
1623
1624static ssize_t mpeg_read(struct file *file, char __user *data,
1625 size_t count, loff_t *ppos)
1626{
1627 struct cx23885_fh *fh = file->private_data;
1628 struct cx23885_dev *dev = fh->dev;
1629
1630 dprintk(2, "%s()\n", __func__);
1631
1632 /* Deal w/ A/V decoder * and mpeg encoder sync issues. */
1633 /* Start mpeg encoder on first read. */
1634 if (atomic_cmpxchg(&fh->v4l_reading, 0, 1) == 0) {
1635 if (atomic_inc_return(&dev->v4l_reader_count) == 1) {
1636 if (cx23885_initialize_codec(dev) < 0)
1637 return -EINVAL;
1638 }
1639 }
1640
1641 return videobuf_read_stream(&fh->mpegq, data, count, ppos, 0,
1642 file->f_flags & O_NONBLOCK);
1643}
1644
1645static unsigned int mpeg_poll(struct file *file,
1646 struct poll_table_struct *wait)
1647{
1648 struct cx23885_fh *fh = file->private_data;
1649 struct cx23885_dev *dev = fh->dev;
1650
1651 dprintk(2, "%s\n", __func__);
1652
1653 return videobuf_poll_stream(file, &fh->mpegq, wait);
1654}
1655
1656static int mpeg_mmap(struct file *file, struct vm_area_struct *vma)
1657{
1658 struct cx23885_fh *fh = file->private_data;
1659 struct cx23885_dev *dev = fh->dev;
1660
1661 dprintk(2, "%s()\n", __func__);
1662
1663 return videobuf_mmap_mapper(&fh->mpegq, vma);
1664}
1665
1666static struct file_operations mpeg_fops = {
1667 .owner = THIS_MODULE,
1668 .open = mpeg_open,
1669 .release = mpeg_release,
1670 .read = mpeg_read,
1671 .poll = mpeg_poll,
1672 .mmap = mpeg_mmap,
1673 .ioctl = mpeg_ioctl,
1674 .llseek = no_llseek,
1675};
1676
1677static struct video_device cx23885_mpeg_template = {
1678 .name = "cx23885",
1679 .type = VID_TYPE_CAPTURE |
1680 VID_TYPE_TUNER |
1681 VID_TYPE_SCALES |
1682 VID_TYPE_MPEG_ENCODER,
1683 .fops = &mpeg_fops,
1684 .minor = -1,
1685};
1686
1687void cx23885_417_unregister(struct cx23885_dev *dev)
1688{
1689 dprintk(1, "%s()\n", __func__);
1690
1691 if (dev->v4l_device) {
1692 if (-1 != dev->v4l_device->minor)
1693 video_unregister_device(dev->v4l_device);
1694 else
1695 video_device_release(dev->v4l_device);
1696 dev->v4l_device = NULL;
1697 }
1698}
1699
1700static struct video_device *cx23885_video_dev_alloc(
1701 struct cx23885_tsport *tsport,
1702 struct pci_dev *pci,
1703 struct video_device *template,
1704 char *type)
1705{
1706 struct video_device *vfd;
1707 struct cx23885_dev *dev = tsport->dev;
1708
1709 dprintk(1, "%s()\n", __func__);
1710
1711 vfd = video_device_alloc();
1712 if (NULL == vfd)
1713 return NULL;
1714 *vfd = *template;
1715 vfd->minor = -1;
1716 snprintf(vfd->name, sizeof(vfd->name), "%s %s (%s)", dev->name,
1717 type, cx23885_boards[tsport->dev->board].name);
1718 vfd->dev = &pci->dev;
1719 vfd->release = video_device_release;
1720 return vfd;
1721}
1722
1723int cx23885_417_register(struct cx23885_dev *dev)
1724{
1725 /* FIXME: Port1 hardcoded here */
1726 int err = -ENODEV;
1727 struct cx23885_tsport *tsport = &dev->ts1;
1728
1729 dprintk(1, "%s()\n", __func__);
1730
1731 if (cx23885_boards[dev->board].portb != CX23885_MPEG_ENCODER)
1732 return err;
1733
1734 /* Set default TV standard */
1735 dev->encodernorm = cx23885_tvnorms[0];
1736
1737 if (dev->encodernorm.id & V4L2_STD_525_60)
1738 tsport->height = 480;
1739 else
1740 tsport->height = 576;
1741
1742 tsport->width = 720;
1743 cx2341x_fill_defaults(&dev->mpeg_params);
1744
1745 dev->mpeg_params.port = CX2341X_PORT_SERIAL;
1746
1747 /* Allocate and initialize V4L video device */
1748 dev->v4l_device = cx23885_video_dev_alloc(tsport,
1749 dev->pci, &cx23885_mpeg_template, "mpeg");
1750 err = video_register_device(dev->v4l_device,
1751 VFL_TYPE_GRABBER, -1);
1752 if (err < 0) {
1753 printk(KERN_INFO "%s: can't register mpeg device\n", dev->name);
1754 return err;
1755 }
1756
1757 /* Initialize MC417 registers */
1758 cx23885_mc417_init(dev);
1759
1760 printk(KERN_INFO "%s: registered device video%d [mpeg]\n",
1761 dev->name, dev->v4l_device->minor & 0x1f);
1762
1763 return 0;
1764}
diff --git a/drivers/media/video/cx23885/cx23885-cards.c b/drivers/media/video/cx23885/cx23885-cards.c
index dfa269838e01..6ebf58724a01 100644
--- a/drivers/media/video/cx23885/cx23885-cards.c
+++ b/drivers/media/video/cx23885/cx23885-cards.c
@@ -73,6 +73,7 @@ struct cx23885_board cx23885_boards[] = {
73 [CX23885_BOARD_HAUPPAUGE_HVR1800] = { 73 [CX23885_BOARD_HAUPPAUGE_HVR1800] = {
74 .name = "Hauppauge WinTV-HVR1800", 74 .name = "Hauppauge WinTV-HVR1800",
75 .porta = CX23885_ANALOG_VIDEO, 75 .porta = CX23885_ANALOG_VIDEO,
76 .portb = CX23885_MPEG_ENCODER,
76 .portc = CX23885_MPEG_DVB, 77 .portc = CX23885_MPEG_DVB,
77 .tuner_type = TUNER_PHILIPS_TDA8290, 78 .tuner_type = TUNER_PHILIPS_TDA8290,
78 .tuner_addr = 0x42, /* 0x84 >> 1 */ 79 .tuner_addr = 0x42, /* 0x84 >> 1 */
@@ -130,6 +131,18 @@ struct cx23885_board cx23885_boards[] = {
130 .name = "Hauppauge WinTV-HVR1500", 131 .name = "Hauppauge WinTV-HVR1500",
131 .portc = CX23885_MPEG_DVB, 132 .portc = CX23885_MPEG_DVB,
132 }, 133 },
134 [CX23885_BOARD_HAUPPAUGE_HVR1200] = {
135 .name = "Hauppauge WinTV-HVR1200",
136 .portc = CX23885_MPEG_DVB,
137 },
138 [CX23885_BOARD_HAUPPAUGE_HVR1700] = {
139 .name = "Hauppauge WinTV-HVR1700",
140 .portc = CX23885_MPEG_DVB,
141 },
142 [CX23885_BOARD_HAUPPAUGE_HVR1400] = {
143 .name = "Hauppauge WinTV-HVR1400",
144 .portc = CX23885_MPEG_DVB,
145 },
133}; 146};
134const unsigned int cx23885_bcount = ARRAY_SIZE(cx23885_boards); 147const unsigned int cx23885_bcount = ARRAY_SIZE(cx23885_boards);
135 148
@@ -181,6 +194,18 @@ struct cx23885_subid cx23885_subids[] = {
181 .subvendor = 0x0070, 194 .subvendor = 0x0070,
182 .subdevice = 0x7717, 195 .subdevice = 0x7717,
183 .card = CX23885_BOARD_HAUPPAUGE_HVR1500, 196 .card = CX23885_BOARD_HAUPPAUGE_HVR1500,
197 }, {
198 .subvendor = 0x0070,
199 .subdevice = 0x71d1,
200 .card = CX23885_BOARD_HAUPPAUGE_HVR1200,
201 }, {
202 .subvendor = 0x0070,
203 .subdevice = 0x8101,
204 .card = CX23885_BOARD_HAUPPAUGE_HVR1700,
205 }, {
206 .subvendor = 0x0070,
207 .subdevice = 0x8010,
208 .card = CX23885_BOARD_HAUPPAUGE_HVR1400,
184 }, 209 },
185}; 210};
186const unsigned int cx23885_idcount = ARRAY_SIZE(cx23885_subids); 211const unsigned int cx23885_idcount = ARRAY_SIZE(cx23885_subids);
@@ -235,6 +260,12 @@ static void hauppauge_eeprom(struct cx23885_dev *dev, u8 *eeprom_data)
235 case 79561: /* WinTV-HVR1250 (PCIe, OEM, No IR, half height, ATSC and Basic analog */ 260 case 79561: /* WinTV-HVR1250 (PCIe, OEM, No IR, half height, ATSC and Basic analog */
236 case 79571: /* WinTV-HVR1250 (PCIe, OEM, No IR, full height, ATSC and Basic analog */ 261 case 79571: /* WinTV-HVR1250 (PCIe, OEM, No IR, full height, ATSC and Basic analog */
237 case 79671: /* WinTV-HVR1250 (PCIe, OEM, No IR, half height, ATSC and Basic analog */ 262 case 79671: /* WinTV-HVR1250 (PCIe, OEM, No IR, half height, ATSC and Basic analog */
263 case 80019:
264 /* WinTV-HVR1400 (Express Card, Retail, IR,
265 * DVB-T and Basic analog */
266 case 81519:
267 /* WinTV-HVR1700 (PCIe, Retail, No IR, half height,
268 * DVB-T and MPEG2 HW Encoder */
238 break; 269 break;
239 default: 270 default:
240 printk("%s: warning: unknown hauppauge model #%d\n", dev->name, tv.model); 271 printk("%s: warning: unknown hauppauge model #%d\n", dev->name, tv.model);
@@ -264,7 +295,7 @@ int cx23885_tuner_callback(void *priv, int command, int arg)
264 } 295 }
265 else { 296 else {
266 printk(KERN_ERR 297 printk(KERN_ERR
267 "%s(): Unknow command.\n", __FUNCTION__); 298 "%s(): Unknow command.\n", __func__);
268 return -EINVAL; 299 return -EINVAL;
269 } 300 }
270 break; 301 break;
@@ -306,6 +337,10 @@ void cx23885_gpio_setup(struct cx23885_dev *dev)
306 /* GPIO-15-18 cx23417 READY, CS, RD, WR */ 337 /* GPIO-15-18 cx23417 READY, CS, RD, WR */
307 /* GPIO-19 IR_RX */ 338 /* GPIO-19 IR_RX */
308 339
340 /* CX23417 GPIO's */
341 /* EIO15 Zilog Reset */
342 /* EIO14 S5H1409/CX24227 Reset */
343
309 /* Force the TDA8295A into reset and back */ 344 /* Force the TDA8295A into reset and back */
310 cx_set(GP0_IO, 0x00040004); 345 cx_set(GP0_IO, 0x00040004);
311 mdelay(20); 346 mdelay(20);
@@ -314,6 +349,50 @@ void cx23885_gpio_setup(struct cx23885_dev *dev)
314 cx_set(GP0_IO, 0x00040004); 349 cx_set(GP0_IO, 0x00040004);
315 mdelay(20); 350 mdelay(20);
316 break; 351 break;
352 case CX23885_BOARD_HAUPPAUGE_HVR1200:
353 /* GPIO-0 tda10048 demodulator reset */
354 /* GPIO-2 tda18271 tuner reset */
355
356 /* Put the parts into reset and back */
357 cx_set(GP0_IO, 0x00050000);
358 mdelay(20);
359 cx_clear(GP0_IO, 0x00000005);
360 mdelay(20);
361 cx_set(GP0_IO, 0x00050005);
362 break;
363 case CX23885_BOARD_HAUPPAUGE_HVR1700:
364 /* GPIO-0 TDA10048 demodulator reset */
365 /* GPIO-2 TDA8295A Reset */
366 /* GPIO-3-10 cx23417 data0-7 */
367 /* GPIO-11-14 cx23417 addr0-3 */
368 /* GPIO-15-18 cx23417 READY, CS, RD, WR */
369
370 /* The following GPIO's are on the interna AVCore (cx25840) */
371 /* GPIO-19 IR_RX */
372 /* GPIO-20 IR_TX 416/DVBT Select */
373 /* GPIO-21 IIS DAT */
374 /* GPIO-22 IIS WCLK */
375 /* GPIO-23 IIS BCLK */
376
377 /* Put the parts into reset and back */
378 cx_set(GP0_IO, 0x00050000);
379 mdelay(20);
380 cx_clear(GP0_IO, 0x00000005);
381 mdelay(20);
382 cx_set(GP0_IO, 0x00050005);
383 break;
384 case CX23885_BOARD_HAUPPAUGE_HVR1400:
385 /* GPIO-0 Dibcom7000p demodulator reset */
386 /* GPIO-2 xc3028L tuner reset */
387 /* GPIO-13 LED */
388
389 /* Put the parts into reset and back */
390 cx_set(GP0_IO, 0x00050000);
391 mdelay(20);
392 cx_clear(GP0_IO, 0x00000005);
393 mdelay(20);
394 cx_set(GP0_IO, 0x00050005);
395 break;
317 } 396 }
318} 397}
319 398
@@ -324,6 +403,8 @@ int cx23885_ir_init(struct cx23885_dev *dev)
324 case CX23885_BOARD_HAUPPAUGE_HVR1500: 403 case CX23885_BOARD_HAUPPAUGE_HVR1500:
325 case CX23885_BOARD_HAUPPAUGE_HVR1500Q: 404 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
326 case CX23885_BOARD_HAUPPAUGE_HVR1800: 405 case CX23885_BOARD_HAUPPAUGE_HVR1800:
406 case CX23885_BOARD_HAUPPAUGE_HVR1200:
407 case CX23885_BOARD_HAUPPAUGE_HVR1400:
327 /* FIXME: Implement me */ 408 /* FIXME: Implement me */
328 break; 409 break;
329 } 410 }
@@ -348,11 +429,14 @@ void cx23885_card_setup(struct cx23885_dev *dev)
348 case CX23885_BOARD_HAUPPAUGE_HVR1250: 429 case CX23885_BOARD_HAUPPAUGE_HVR1250:
349 case CX23885_BOARD_HAUPPAUGE_HVR1500: 430 case CX23885_BOARD_HAUPPAUGE_HVR1500:
350 case CX23885_BOARD_HAUPPAUGE_HVR1500Q: 431 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
432 case CX23885_BOARD_HAUPPAUGE_HVR1400:
351 if (dev->i2c_bus[0].i2c_rc == 0) 433 if (dev->i2c_bus[0].i2c_rc == 0)
352 hauppauge_eeprom(dev, eeprom+0x80); 434 hauppauge_eeprom(dev, eeprom+0x80);
353 break; 435 break;
354 case CX23885_BOARD_HAUPPAUGE_HVR1800: 436 case CX23885_BOARD_HAUPPAUGE_HVR1800:
355 case CX23885_BOARD_HAUPPAUGE_HVR1800lp: 437 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
438 case CX23885_BOARD_HAUPPAUGE_HVR1200:
439 case CX23885_BOARD_HAUPPAUGE_HVR1700:
356 if (dev->i2c_bus[0].i2c_rc == 0) 440 if (dev->i2c_bus[0].i2c_rc == 0)
357 hauppauge_eeprom(dev, eeprom+0xc0); 441 hauppauge_eeprom(dev, eeprom+0xc0);
358 break; 442 break;
@@ -364,17 +448,45 @@ void cx23885_card_setup(struct cx23885_dev *dev)
364 ts1->ts_clk_en_val = 0x1; /* Enable TS_CLK */ 448 ts1->ts_clk_en_val = 0x1; /* Enable TS_CLK */
365 ts1->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO; 449 ts1->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
366 break; 450 break;
451 case CX23885_BOARD_HAUPPAUGE_HVR1800:
452 /* Defaults for VID B - Analog encoder */
453 /* DREQ_POL, SMODE, PUNC_CLK, MCLK_POL Serial bus + punc clk */
454 ts1->gen_ctrl_val = 0x10e;
455 ts1->ts_clk_en_val = 0x1; /* Enable TS_CLK */
456 ts1->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
457
458 /* APB_TSVALERR_POL (active low)*/
459 ts1->vld_misc_val = 0x2000;
460 ts1->hw_sop_ctrl_val = (0x47 << 16 | 188 << 4 | 0xc);
461
462 /* Defaults for VID C */
463 ts2->gen_ctrl_val = 0xc; /* Serial bus + punctured clock */
464 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */
465 ts2->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
466 break;
367 case CX23885_BOARD_HAUPPAUGE_HVR1250: 467 case CX23885_BOARD_HAUPPAUGE_HVR1250:
368 case CX23885_BOARD_HAUPPAUGE_HVR1500: 468 case CX23885_BOARD_HAUPPAUGE_HVR1500:
369 case CX23885_BOARD_HAUPPAUGE_HVR1500Q: 469 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
370 case CX23885_BOARD_HAUPPAUGE_HVR1800:
371 case CX23885_BOARD_HAUPPAUGE_HVR1800lp: 470 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
471 case CX23885_BOARD_HAUPPAUGE_HVR1200:
472 case CX23885_BOARD_HAUPPAUGE_HVR1700:
473 case CX23885_BOARD_HAUPPAUGE_HVR1400:
372 default: 474 default:
373 ts2->gen_ctrl_val = 0xc; /* Serial bus + punctured clock */ 475 ts2->gen_ctrl_val = 0xc; /* Serial bus + punctured clock */
374 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */ 476 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */
375 ts2->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO; 477 ts2->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
376 } 478 }
377 479
480 /* Certain boards support analog, or require the avcore to be
481 * loaded, ensure this happens.
482 */
483 switch (dev->board) {
484 case CX23885_BOARD_HAUPPAUGE_HVR1800:
485 case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
486 case CX23885_BOARD_HAUPPAUGE_HVR1700:
487 request_module("cx25840");
488 break;
489 }
378} 490}
379 491
380/* ------------------------------------------------------------------ */ 492/* ------------------------------------------------------------------ */
diff --git a/drivers/media/video/cx23885/cx23885-core.c b/drivers/media/video/cx23885/cx23885-core.c
index 7f10b273598f..f24abcd06dea 100644
--- a/drivers/media/video/cx23885/cx23885-core.c
+++ b/drivers/media/video/cx23885/cx23885-core.c
@@ -190,25 +190,25 @@ static struct sram_channel cx23887_sram_channels[] = {
190static int cx23885_risc_decode(u32 risc) 190static int cx23885_risc_decode(u32 risc)
191{ 191{
192 static char *instr[16] = { 192 static char *instr[16] = {
193 [ RISC_SYNC >> 28 ] = "sync", 193 [RISC_SYNC >> 28] = "sync",
194 [ RISC_WRITE >> 28 ] = "write", 194 [RISC_WRITE >> 28] = "write",
195 [ RISC_WRITEC >> 28 ] = "writec", 195 [RISC_WRITEC >> 28] = "writec",
196 [ RISC_READ >> 28 ] = "read", 196 [RISC_READ >> 28] = "read",
197 [ RISC_READC >> 28 ] = "readc", 197 [RISC_READC >> 28] = "readc",
198 [ RISC_JUMP >> 28 ] = "jump", 198 [RISC_JUMP >> 28] = "jump",
199 [ RISC_SKIP >> 28 ] = "skip", 199 [RISC_SKIP >> 28] = "skip",
200 [ RISC_WRITERM >> 28 ] = "writerm", 200 [RISC_WRITERM >> 28] = "writerm",
201 [ RISC_WRITECM >> 28 ] = "writecm", 201 [RISC_WRITECM >> 28] = "writecm",
202 [ RISC_WRITECR >> 28 ] = "writecr", 202 [RISC_WRITECR >> 28] = "writecr",
203 }; 203 };
204 static int incr[16] = { 204 static int incr[16] = {
205 [ RISC_WRITE >> 28 ] = 3, 205 [RISC_WRITE >> 28] = 3,
206 [ RISC_JUMP >> 28 ] = 3, 206 [RISC_JUMP >> 28] = 3,
207 [ RISC_SKIP >> 28 ] = 1, 207 [RISC_SKIP >> 28] = 1,
208 [ RISC_SYNC >> 28 ] = 1, 208 [RISC_SYNC >> 28] = 1,
209 [ RISC_WRITERM >> 28 ] = 3, 209 [RISC_WRITERM >> 28] = 3,
210 [ RISC_WRITECM >> 28 ] = 3, 210 [RISC_WRITECM >> 28] = 3,
211 [ RISC_WRITECR >> 28 ] = 4, 211 [RISC_WRITECR >> 28] = 4,
212 }; 212 };
213 static char *bits[] = { 213 static char *bits[] = {
214 "12", "13", "14", "resync", 214 "12", "13", "14", "resync",
@@ -260,7 +260,7 @@ void cx23885_wakeup(struct cx23885_tsport *port,
260 } 260 }
261 if (bc != 1) 261 if (bc != 1)
262 printk("%s: %d buffers handled (should be 1)\n", 262 printk("%s: %d buffers handled (should be 1)\n",
263 __FUNCTION__, bc); 263 __func__, bc);
264} 264}
265 265
266int cx23885_sram_channel_setup(struct cx23885_dev *dev, 266int cx23885_sram_channel_setup(struct cx23885_dev *dev,
@@ -272,7 +272,7 @@ int cx23885_sram_channel_setup(struct cx23885_dev *dev,
272 272
273 if (ch->cmds_start == 0) 273 if (ch->cmds_start == 0)
274 { 274 {
275 dprintk(1, "%s() Erasing channel [%s]\n", __FUNCTION__, 275 dprintk(1, "%s() Erasing channel [%s]\n", __func__,
276 ch->name); 276 ch->name);
277 cx_write(ch->ptr1_reg, 0); 277 cx_write(ch->ptr1_reg, 0);
278 cx_write(ch->ptr2_reg, 0); 278 cx_write(ch->ptr2_reg, 0);
@@ -280,7 +280,7 @@ int cx23885_sram_channel_setup(struct cx23885_dev *dev,
280 cx_write(ch->cnt1_reg, 0); 280 cx_write(ch->cnt1_reg, 0);
281 return 0; 281 return 0;
282 } else { 282 } else {
283 dprintk(1, "%s() Configuring channel [%s]\n", __FUNCTION__, 283 dprintk(1, "%s() Configuring channel [%s]\n", __func__,
284 ch->name); 284 ch->name);
285 } 285 }
286 286
@@ -297,7 +297,7 @@ int cx23885_sram_channel_setup(struct cx23885_dev *dev,
297 297
298 /* write CDT */ 298 /* write CDT */
299 for (i = 0; i < lines; i++) { 299 for (i = 0; i < lines; i++) {
300 dprintk(2, "%s() 0x%08x <- 0x%08x\n", __FUNCTION__, cdt + 16*i, 300 dprintk(2, "%s() 0x%08x <- 0x%08x\n", __func__, cdt + 16*i,
301 ch->fifo_start + bpl*i); 301 ch->fifo_start + bpl*i);
302 cx_write(cdt + 16*i, ch->fifo_start + bpl*i); 302 cx_write(cdt + 16*i, ch->fifo_start + bpl*i);
303 cx_write(cdt + 16*i + 4, 0); 303 cx_write(cdt + 16*i + 4, 0);
@@ -449,7 +449,7 @@ static void cx23885_shutdown(struct cx23885_dev *dev)
449 449
450static void cx23885_reset(struct cx23885_dev *dev) 450static void cx23885_reset(struct cx23885_dev *dev)
451{ 451{
452 dprintk(1, "%s()\n", __FUNCTION__); 452 dprintk(1, "%s()\n", __func__);
453 453
454 cx23885_shutdown(dev); 454 cx23885_shutdown(dev);
455 455
@@ -482,7 +482,7 @@ static void cx23885_reset(struct cx23885_dev *dev)
482 482
483static int cx23885_pci_quirks(struct cx23885_dev *dev) 483static int cx23885_pci_quirks(struct cx23885_dev *dev)
484{ 484{
485 dprintk(1, "%s()\n", __FUNCTION__); 485 dprintk(1, "%s()\n", __func__);
486 486
487 /* The cx23885 bridge has a weird bug which causes NMI to be asserted 487 /* The cx23885 bridge has a weird bug which causes NMI to be asserted
488 * when DMA begins if RDR_TLCTL0 bit4 is not cleared. It does not 488 * when DMA begins if RDR_TLCTL0 bit4 is not cleared. It does not
@@ -513,11 +513,13 @@ int cx23885_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
513 513
514static int cx23885_init_tsport(struct cx23885_dev *dev, struct cx23885_tsport *port, int portno) 514static int cx23885_init_tsport(struct cx23885_dev *dev, struct cx23885_tsport *port, int portno)
515{ 515{
516 dprintk(1, "%s(portno=%d)\n", __FUNCTION__, portno); 516 dprintk(1, "%s(portno=%d)\n", __func__, portno);
517 517
518 /* Transport bus init dma queue - Common settings */ 518 /* Transport bus init dma queue - Common settings */
519 port->dma_ctl_val = 0x11; /* Enable RISC controller and Fifo */ 519 port->dma_ctl_val = 0x11; /* Enable RISC controller and Fifo */
520 port->ts_int_msk_val = 0x1111; /* TS port bits for RISC */ 520 port->ts_int_msk_val = 0x1111; /* TS port bits for RISC */
521 port->vld_misc_val = 0x0;
522 port->hw_sop_ctrl_val = (0x47 << 16 | 188 << 4);
521 523
522 spin_lock_init(&port->slock); 524 spin_lock_init(&port->slock);
523 port->dev = dev; 525 port->dev = dev;
@@ -544,7 +546,7 @@ static int cx23885_init_tsport(struct cx23885_dev *dev, struct cx23885_tsport *p
544 port->reg_ts_clk_en = VID_B_TS_CLK_EN; 546 port->reg_ts_clk_en = VID_B_TS_CLK_EN;
545 port->reg_src_sel = VID_B_SRC_SEL; 547 port->reg_src_sel = VID_B_SRC_SEL;
546 port->reg_ts_int_msk = VID_B_INT_MSK; 548 port->reg_ts_int_msk = VID_B_INT_MSK;
547 port->reg_ts_int_stat = VID_B_INT_STAT; 549 port->reg_ts_int_stat = VID_B_INT_STAT;
548 port->sram_chno = SRAM_CH03; /* VID_B */ 550 port->sram_chno = SRAM_CH03; /* VID_B */
549 port->pci_irqmask = 0x02; /* VID_B bit1 */ 551 port->pci_irqmask = 0x02; /* VID_B bit1 */
550 break; 552 break;
@@ -604,14 +606,14 @@ static void cx23885_dev_checkrevision(struct cx23885_dev *dev)
604 break; 606 break;
605 default: 607 default:
606 printk(KERN_ERR "%s() New hardware revision found 0x%x\n", 608 printk(KERN_ERR "%s() New hardware revision found 0x%x\n",
607 __FUNCTION__, dev->hwrevision); 609 __func__, dev->hwrevision);
608 } 610 }
609 if (dev->hwrevision) 611 if (dev->hwrevision)
610 printk(KERN_INFO "%s() Hardware revision = 0x%02x\n", 612 printk(KERN_INFO "%s() Hardware revision = 0x%02x\n",
611 __FUNCTION__, dev->hwrevision); 613 __func__, dev->hwrevision);
612 else 614 else
613 printk(KERN_ERR "%s() Hardware revision unknown 0x%x\n", 615 printk(KERN_ERR "%s() Hardware revision unknown 0x%x\n",
614 __FUNCTION__, dev->hwrevision); 616 __func__, dev->hwrevision);
615} 617}
616 618
617static int cx23885_dev_setup(struct cx23885_dev *dev) 619static int cx23885_dev_setup(struct cx23885_dev *dev)
@@ -644,7 +646,7 @@ static int cx23885_dev_setup(struct cx23885_dev *dev)
644 BUG(); 646 BUG();
645 647
646 dprintk(1, "%s() Memory configured for PCIe bridge type %d\n", 648 dprintk(1, "%s() Memory configured for PCIe bridge type %d\n",
647 __FUNCTION__, dev->bridge); 649 __func__, dev->bridge);
648 650
649 /* board config */ 651 /* board config */
650 dev->board = UNSET; 652 dev->board = UNSET;
@@ -697,10 +699,12 @@ static int cx23885_dev_setup(struct cx23885_dev *dev)
697 dev->i2c_bus[2].reg_wdata = I2C3_WDATA; 699 dev->i2c_bus[2].reg_wdata = I2C3_WDATA;
698 dev->i2c_bus[2].i2c_period = (0x07 << 24); /* 1.95MHz */ 700 dev->i2c_bus[2].i2c_period = (0x07 << 24); /* 1.95MHz */
699 701
700 if(cx23885_boards[dev->board].portb == CX23885_MPEG_DVB) 702 if ((cx23885_boards[dev->board].portb == CX23885_MPEG_DVB) ||
703 (cx23885_boards[dev->board].portb == CX23885_MPEG_ENCODER))
701 cx23885_init_tsport(dev, &dev->ts1, 1); 704 cx23885_init_tsport(dev, &dev->ts1, 1);
702 705
703 if(cx23885_boards[dev->board].portc == CX23885_MPEG_DVB) 706 if ((cx23885_boards[dev->board].portc == CX23885_MPEG_DVB) ||
707 (cx23885_boards[dev->board].portc == CX23885_MPEG_ENCODER))
704 cx23885_init_tsport(dev, &dev->ts2, 2); 708 cx23885_init_tsport(dev, &dev->ts2, 2);
705 709
706 if (get_resources(dev) < 0) { 710 if (get_resources(dev) < 0) {
@@ -734,9 +738,9 @@ static int cx23885_dev_setup(struct cx23885_dev *dev)
734 dev->radio_addr = cx23885_boards[dev->board].radio_addr; 738 dev->radio_addr = cx23885_boards[dev->board].radio_addr;
735 739
736 dprintk(1, "%s() tuner_type = 0x%x tuner_addr = 0x%x\n", 740 dprintk(1, "%s() tuner_type = 0x%x tuner_addr = 0x%x\n",
737 __FUNCTION__, dev->tuner_type, dev->tuner_addr); 741 __func__, dev->tuner_type, dev->tuner_addr);
738 dprintk(1, "%s() radio_type = 0x%x radio_addr = 0x%x\n", 742 dprintk(1, "%s() radio_type = 0x%x radio_addr = 0x%x\n",
739 __FUNCTION__, dev->radio_type, dev->radio_addr); 743 __func__, dev->radio_type, dev->radio_addr);
740 744
741 /* init hardware */ 745 /* init hardware */
742 cx23885_reset(dev); 746 cx23885_reset(dev);
@@ -744,28 +748,43 @@ static int cx23885_dev_setup(struct cx23885_dev *dev)
744 cx23885_i2c_register(&dev->i2c_bus[0]); 748 cx23885_i2c_register(&dev->i2c_bus[0]);
745 cx23885_i2c_register(&dev->i2c_bus[1]); 749 cx23885_i2c_register(&dev->i2c_bus[1]);
746 cx23885_i2c_register(&dev->i2c_bus[2]); 750 cx23885_i2c_register(&dev->i2c_bus[2]);
747 cx23885_call_i2c_clients (&dev->i2c_bus[0], TUNER_SET_STANDBY, NULL);
748 cx23885_card_setup(dev); 751 cx23885_card_setup(dev);
752 cx23885_call_i2c_clients (&dev->i2c_bus[0], TUNER_SET_STANDBY, NULL);
749 cx23885_ir_init(dev); 753 cx23885_ir_init(dev);
750 754
751 if (cx23885_boards[dev->board].porta == CX23885_ANALOG_VIDEO) { 755 if (cx23885_boards[dev->board].porta == CX23885_ANALOG_VIDEO) {
752 if (cx23885_video_register(dev) < 0) { 756 if (cx23885_video_register(dev) < 0) {
753 printk(KERN_ERR "%s() Failed to register analog " 757 printk(KERN_ERR "%s() Failed to register analog "
754 "video adapters on VID_A\n", __FUNCTION__); 758 "video adapters on VID_A\n", __func__);
755 } 759 }
756 } 760 }
757 761
758 if (cx23885_boards[dev->board].portb == CX23885_MPEG_DVB) { 762 if (cx23885_boards[dev->board].portb == CX23885_MPEG_DVB) {
759 if (cx23885_dvb_register(&dev->ts1) < 0) { 763 if (cx23885_dvb_register(&dev->ts1) < 0) {
760 printk(KERN_ERR "%s() Failed to register dvb adapters on VID_B\n", 764 printk(KERN_ERR "%s() Failed to register dvb adapters on VID_B\n",
761 __FUNCTION__); 765 __func__);
766 }
767 } else
768 if (cx23885_boards[dev->board].portb == CX23885_MPEG_ENCODER) {
769 if (cx23885_417_register(dev) < 0) {
770 printk(KERN_ERR
771 "%s() Failed to register 417 on VID_B\n",
772 __func__);
762 } 773 }
763 } 774 }
764 775
765 if (cx23885_boards[dev->board].portc == CX23885_MPEG_DVB) { 776 if (cx23885_boards[dev->board].portc == CX23885_MPEG_DVB) {
766 if (cx23885_dvb_register(&dev->ts2) < 0) { 777 if (cx23885_dvb_register(&dev->ts2) < 0) {
767 printk(KERN_ERR "%s() Failed to register dvb adapters on VID_C\n", 778 printk(KERN_ERR
768 __FUNCTION__); 779 "%s() Failed to register dvb on VID_C\n",
780 __func__);
781 }
782 } else
783 if (cx23885_boards[dev->board].portc == CX23885_MPEG_ENCODER) {
784 if (cx23885_417_register(dev) < 0) {
785 printk(KERN_ERR
786 "%s() Failed to register 417 on VID_C\n",
787 __func__);
769 } 788 }
770 } 789 }
771 790
@@ -785,12 +804,18 @@ static void cx23885_dev_unregister(struct cx23885_dev *dev)
785 if (cx23885_boards[dev->board].porta == CX23885_ANALOG_VIDEO) 804 if (cx23885_boards[dev->board].porta == CX23885_ANALOG_VIDEO)
786 cx23885_video_unregister(dev); 805 cx23885_video_unregister(dev);
787 806
788 if(cx23885_boards[dev->board].portb == CX23885_MPEG_DVB) 807 if (cx23885_boards[dev->board].portb == CX23885_MPEG_DVB)
789 cx23885_dvb_unregister(&dev->ts1); 808 cx23885_dvb_unregister(&dev->ts1);
790 809
791 if(cx23885_boards[dev->board].portc == CX23885_MPEG_DVB) 810 if (cx23885_boards[dev->board].portb == CX23885_MPEG_ENCODER)
811 cx23885_417_unregister(dev);
812
813 if (cx23885_boards[dev->board].portc == CX23885_MPEG_DVB)
792 cx23885_dvb_unregister(&dev->ts2); 814 cx23885_dvb_unregister(&dev->ts2);
793 815
816 if (cx23885_boards[dev->board].portc == CX23885_MPEG_ENCODER)
817 cx23885_417_unregister(dev);
818
794 cx23885_i2c_unregister(&dev->i2c_bus[2]); 819 cx23885_i2c_unregister(&dev->i2c_bus[2]);
795 cx23885_i2c_unregister(&dev->i2c_bus[1]); 820 cx23885_i2c_unregister(&dev->i2c_bus[1]);
796 cx23885_i2c_unregister(&dev->i2c_bus[0]); 821 cx23885_i2c_unregister(&dev->i2c_bus[0]);
@@ -952,7 +977,7 @@ void cx23885_free_buffer(struct videobuf_queue *q, struct cx23885_buffer *buf)
952 videobuf_waiton(&buf->vb, 0, 0); 977 videobuf_waiton(&buf->vb, 0, 0);
953 videobuf_dma_unmap(q, dma); 978 videobuf_dma_unmap(q, dma);
954 videobuf_dma_free(dma); 979 videobuf_dma_free(dma);
955 btcx_riscmem_free((struct pci_dev *)q->dev, &buf->risc); 980 btcx_riscmem_free(to_pci_dev(q->dev), &buf->risc);
956 buf->vb.state = VIDEOBUF_NEEDS_INIT; 981 buf->vb.state = VIDEOBUF_NEEDS_INIT;
957} 982}
958 983
@@ -960,50 +985,50 @@ static void cx23885_tsport_reg_dump(struct cx23885_tsport *port)
960{ 985{
961 struct cx23885_dev *dev = port->dev; 986 struct cx23885_dev *dev = port->dev;
962 987
963 dprintk(1, "%s() Register Dump\n", __FUNCTION__); 988 dprintk(1, "%s() Register Dump\n", __func__);
964 dprintk(1, "%s() DEV_CNTRL2 0x%08X\n", __FUNCTION__, 989 dprintk(1, "%s() DEV_CNTRL2 0x%08X\n", __func__,
965 cx_read(DEV_CNTRL2)); 990 cx_read(DEV_CNTRL2));
966 dprintk(1, "%s() PCI_INT_MSK 0x%08X\n", __FUNCTION__, 991 dprintk(1, "%s() PCI_INT_MSK 0x%08X\n", __func__,
967 cx_read(PCI_INT_MSK)); 992 cx_read(PCI_INT_MSK));
968 dprintk(1, "%s() AUD_INT_INT_MSK 0x%08X\n", __FUNCTION__, 993 dprintk(1, "%s() AUD_INT_INT_MSK 0x%08X\n", __func__,
969 cx_read(AUDIO_INT_INT_MSK)); 994 cx_read(AUDIO_INT_INT_MSK));
970 dprintk(1, "%s() AUD_INT_DMA_CTL 0x%08X\n", __FUNCTION__, 995 dprintk(1, "%s() AUD_INT_DMA_CTL 0x%08X\n", __func__,
971 cx_read(AUD_INT_DMA_CTL)); 996 cx_read(AUD_INT_DMA_CTL));
972 dprintk(1, "%s() AUD_EXT_INT_MSK 0x%08X\n", __FUNCTION__, 997 dprintk(1, "%s() AUD_EXT_INT_MSK 0x%08X\n", __func__,
973 cx_read(AUDIO_EXT_INT_MSK)); 998 cx_read(AUDIO_EXT_INT_MSK));
974 dprintk(1, "%s() AUD_EXT_DMA_CTL 0x%08X\n", __FUNCTION__, 999 dprintk(1, "%s() AUD_EXT_DMA_CTL 0x%08X\n", __func__,
975 cx_read(AUD_EXT_DMA_CTL)); 1000 cx_read(AUD_EXT_DMA_CTL));
976 dprintk(1, "%s() PAD_CTRL 0x%08X\n", __FUNCTION__, 1001 dprintk(1, "%s() PAD_CTRL 0x%08X\n", __func__,
977 cx_read(PAD_CTRL)); 1002 cx_read(PAD_CTRL));
978 dprintk(1, "%s() ALT_PIN_OUT_SEL 0x%08X\n", __FUNCTION__, 1003 dprintk(1, "%s() ALT_PIN_OUT_SEL 0x%08X\n", __func__,
979 cx_read(ALT_PIN_OUT_SEL)); 1004 cx_read(ALT_PIN_OUT_SEL));
980 dprintk(1, "%s() GPIO2 0x%08X\n", __FUNCTION__, 1005 dprintk(1, "%s() GPIO2 0x%08X\n", __func__,
981 cx_read(GPIO2)); 1006 cx_read(GPIO2));
982 dprintk(1, "%s() gpcnt(0x%08X) 0x%08X\n", __FUNCTION__, 1007 dprintk(1, "%s() gpcnt(0x%08X) 0x%08X\n", __func__,
983 port->reg_gpcnt, cx_read(port->reg_gpcnt)); 1008 port->reg_gpcnt, cx_read(port->reg_gpcnt));
984 dprintk(1, "%s() gpcnt_ctl(0x%08X) 0x%08x\n", __FUNCTION__, 1009 dprintk(1, "%s() gpcnt_ctl(0x%08X) 0x%08x\n", __func__,
985 port->reg_gpcnt_ctl, cx_read(port->reg_gpcnt_ctl)); 1010 port->reg_gpcnt_ctl, cx_read(port->reg_gpcnt_ctl));
986 dprintk(1, "%s() dma_ctl(0x%08X) 0x%08x\n", __FUNCTION__, 1011 dprintk(1, "%s() dma_ctl(0x%08X) 0x%08x\n", __func__,
987 port->reg_dma_ctl, cx_read(port->reg_dma_ctl)); 1012 port->reg_dma_ctl, cx_read(port->reg_dma_ctl));
988 dprintk(1, "%s() src_sel(0x%08X) 0x%08x\n", __FUNCTION__, 1013 dprintk(1, "%s() src_sel(0x%08X) 0x%08x\n", __func__,
989 port->reg_src_sel, cx_read(port->reg_src_sel)); 1014 port->reg_src_sel, cx_read(port->reg_src_sel));
990 dprintk(1, "%s() lngth(0x%08X) 0x%08x\n", __FUNCTION__, 1015 dprintk(1, "%s() lngth(0x%08X) 0x%08x\n", __func__,
991 port->reg_lngth, cx_read(port->reg_lngth)); 1016 port->reg_lngth, cx_read(port->reg_lngth));
992 dprintk(1, "%s() hw_sop_ctrl(0x%08X) 0x%08x\n", __FUNCTION__, 1017 dprintk(1, "%s() hw_sop_ctrl(0x%08X) 0x%08x\n", __func__,
993 port->reg_hw_sop_ctrl, cx_read(port->reg_hw_sop_ctrl)); 1018 port->reg_hw_sop_ctrl, cx_read(port->reg_hw_sop_ctrl));
994 dprintk(1, "%s() gen_ctrl(0x%08X) 0x%08x\n", __FUNCTION__, 1019 dprintk(1, "%s() gen_ctrl(0x%08X) 0x%08x\n", __func__,
995 port->reg_gen_ctrl, cx_read(port->reg_gen_ctrl)); 1020 port->reg_gen_ctrl, cx_read(port->reg_gen_ctrl));
996 dprintk(1, "%s() bd_pkt_status(0x%08X) 0x%08x\n", __FUNCTION__, 1021 dprintk(1, "%s() bd_pkt_status(0x%08X) 0x%08x\n", __func__,
997 port->reg_bd_pkt_status, cx_read(port->reg_bd_pkt_status)); 1022 port->reg_bd_pkt_status, cx_read(port->reg_bd_pkt_status));
998 dprintk(1, "%s() sop_status(0x%08X) 0x%08x\n", __FUNCTION__, 1023 dprintk(1, "%s() sop_status(0x%08X) 0x%08x\n", __func__,
999 port->reg_sop_status, cx_read(port->reg_sop_status)); 1024 port->reg_sop_status, cx_read(port->reg_sop_status));
1000 dprintk(1, "%s() fifo_ovfl_stat(0x%08X) 0x%08x\n", __FUNCTION__, 1025 dprintk(1, "%s() fifo_ovfl_stat(0x%08X) 0x%08x\n", __func__,
1001 port->reg_fifo_ovfl_stat, cx_read(port->reg_fifo_ovfl_stat)); 1026 port->reg_fifo_ovfl_stat, cx_read(port->reg_fifo_ovfl_stat));
1002 dprintk(1, "%s() vld_misc(0x%08X) 0x%08x\n", __FUNCTION__, 1027 dprintk(1, "%s() vld_misc(0x%08X) 0x%08x\n", __func__,
1003 port->reg_vld_misc, cx_read(port->reg_vld_misc)); 1028 port->reg_vld_misc, cx_read(port->reg_vld_misc));
1004 dprintk(1, "%s() ts_clk_en(0x%08X) 0x%08x\n", __FUNCTION__, 1029 dprintk(1, "%s() ts_clk_en(0x%08X) 0x%08x\n", __func__,
1005 port->reg_ts_clk_en, cx_read(port->reg_ts_clk_en)); 1030 port->reg_ts_clk_en, cx_read(port->reg_ts_clk_en));
1006 dprintk(1, "%s() ts_int_msk(0x%08X) 0x%08x\n", __FUNCTION__, 1031 dprintk(1, "%s() ts_int_msk(0x%08X) 0x%08x\n", __func__,
1007 port->reg_ts_int_msk, cx_read(port->reg_ts_int_msk)); 1032 port->reg_ts_int_msk, cx_read(port->reg_ts_int_msk));
1008} 1033}
1009 1034
@@ -1012,8 +1037,9 @@ static int cx23885_start_dma(struct cx23885_tsport *port,
1012 struct cx23885_buffer *buf) 1037 struct cx23885_buffer *buf)
1013{ 1038{
1014 struct cx23885_dev *dev = port->dev; 1039 struct cx23885_dev *dev = port->dev;
1040 u32 reg;
1015 1041
1016 dprintk(1, "%s() w: %d, h: %d, f: %d\n", __FUNCTION__, 1042 dprintk(1, "%s() w: %d, h: %d, f: %d\n", __func__,
1017 buf->vb.width, buf->vb.height, buf->vb.field); 1043 buf->vb.width, buf->vb.height, buf->vb.field);
1018 1044
1019 /* setup fifo + format */ 1045 /* setup fifo + format */
@@ -1031,21 +1057,24 @@ static int cx23885_start_dma(struct cx23885_tsport *port,
1031 if ( (!(cx23885_boards[dev->board].portb & CX23885_MPEG_DVB)) && 1057 if ( (!(cx23885_boards[dev->board].portb & CX23885_MPEG_DVB)) &&
1032 (!(cx23885_boards[dev->board].portc & CX23885_MPEG_DVB)) ) { 1058 (!(cx23885_boards[dev->board].portc & CX23885_MPEG_DVB)) ) {
1033 printk( "%s() Failed. Unsupported value in .portb/c (0x%08x)/(0x%08x)\n", 1059 printk( "%s() Failed. Unsupported value in .portb/c (0x%08x)/(0x%08x)\n",
1034 __FUNCTION__, 1060 __func__,
1035 cx23885_boards[dev->board].portb, 1061 cx23885_boards[dev->board].portb,
1036 cx23885_boards[dev->board].portc ); 1062 cx23885_boards[dev->board].portc );
1037 return -EINVAL; 1063 return -EINVAL;
1038 } 1064 }
1039 1065
1066 if (cx23885_boards[dev->board].portb == CX23885_MPEG_ENCODER)
1067 cx23885_av_clk(dev, 0);
1068
1040 udelay(100); 1069 udelay(100);
1041 1070
1042 /* If the port supports SRC SELECT, configure it */ 1071 /* If the port supports SRC SELECT, configure it */
1043 if(port->reg_src_sel) 1072 if(port->reg_src_sel)
1044 cx_write(port->reg_src_sel, port->src_sel_val); 1073 cx_write(port->reg_src_sel, port->src_sel_val);
1045 1074
1046 cx_write(port->reg_hw_sop_ctrl, 0x47 << 16 | 188 << 4); 1075 cx_write(port->reg_hw_sop_ctrl, port->hw_sop_ctrl_val);
1047 cx_write(port->reg_ts_clk_en, port->ts_clk_en_val); 1076 cx_write(port->reg_ts_clk_en, port->ts_clk_en_val);
1048 cx_write(port->reg_vld_misc, 0x00); 1077 cx_write(port->reg_vld_misc, port->vld_misc_val);
1049 cx_write(port->reg_gen_ctrl, port->gen_ctrl_val); 1078 cx_write(port->reg_gen_ctrl, port->gen_ctrl_val);
1050 udelay(100); 1079 udelay(100);
1051 1080
@@ -1054,11 +1083,26 @@ static int cx23885_start_dma(struct cx23885_tsport *port,
1054 cx_write(port->reg_gpcnt_ctl, 3); 1083 cx_write(port->reg_gpcnt_ctl, 3);
1055 q->count = 1; 1084 q->count = 1;
1056 1085
1086 if (cx23885_boards[dev->board].portb & CX23885_MPEG_ENCODER) {
1087
1088 reg = cx_read(PAD_CTRL);
1089 reg = reg & ~0x1; /* Clear TS1_OE */
1090
1091 /* FIXME, bit 2 writing here is questionable */
1092 /* set TS1_SOP_OE and TS1_OE_HI */
1093 reg = reg | 0xa;
1094 cx_write(PAD_CTRL, reg);
1095
1096 /* FIXME and these two registers should be documented. */
1097 cx_write(CLK_DELAY, cx_read(CLK_DELAY) | 0x80000011);
1098 cx_write(ALT_PIN_OUT_SEL, 0x10100045);
1099 }
1100
1057 switch(dev->bridge) { 1101 switch(dev->bridge) {
1058 case CX23885_BRIDGE_885: 1102 case CX23885_BRIDGE_885:
1059 case CX23885_BRIDGE_887: 1103 case CX23885_BRIDGE_887:
1060 /* enable irqs */ 1104 /* enable irqs */
1061 dprintk(1, "%s() enabling TS int's and DMA\n", __FUNCTION__ ); 1105 dprintk(1, "%s() enabling TS int's and DMA\n", __func__ );
1062 cx_set(port->reg_ts_int_msk, port->ts_int_msk_val); 1106 cx_set(port->reg_ts_int_msk, port->ts_int_msk_val);
1063 cx_set(port->reg_dma_ctl, port->dma_ctl_val); 1107 cx_set(port->reg_dma_ctl, port->dma_ctl_val);
1064 cx_set(PCI_INT_MSK, dev->pci_irqmask | port->pci_irqmask); 1108 cx_set(PCI_INT_MSK, dev->pci_irqmask | port->pci_irqmask);
@@ -1069,6 +1113,9 @@ static int cx23885_start_dma(struct cx23885_tsport *port,
1069 1113
1070 cx_set(DEV_CNTRL2, (1<<5)); /* Enable RISC controller */ 1114 cx_set(DEV_CNTRL2, (1<<5)); /* Enable RISC controller */
1071 1115
1116 if (cx23885_boards[dev->board].portb == CX23885_MPEG_ENCODER)
1117 cx23885_av_clk(dev, 1);
1118
1072 if (debug > 4) 1119 if (debug > 4)
1073 cx23885_tsport_reg_dump(port); 1120 cx23885_tsport_reg_dump(port);
1074 1121
@@ -1078,12 +1125,32 @@ static int cx23885_start_dma(struct cx23885_tsport *port,
1078static int cx23885_stop_dma(struct cx23885_tsport *port) 1125static int cx23885_stop_dma(struct cx23885_tsport *port)
1079{ 1126{
1080 struct cx23885_dev *dev = port->dev; 1127 struct cx23885_dev *dev = port->dev;
1081 dprintk(1, "%s()\n", __FUNCTION__); 1128 u32 reg;
1129
1130 dprintk(1, "%s()\n", __func__);
1082 1131
1083 /* Stop interrupts and DMA */ 1132 /* Stop interrupts and DMA */
1084 cx_clear(port->reg_ts_int_msk, port->ts_int_msk_val); 1133 cx_clear(port->reg_ts_int_msk, port->ts_int_msk_val);
1085 cx_clear(port->reg_dma_ctl, port->dma_ctl_val); 1134 cx_clear(port->reg_dma_ctl, port->dma_ctl_val);
1086 1135
1136 if (cx23885_boards[dev->board].portb & CX23885_MPEG_ENCODER) {
1137
1138 reg = cx_read(PAD_CTRL);
1139
1140 /* Set TS1_OE */
1141 reg = reg | 0x1;
1142
1143 /* clear TS1_SOP_OE and TS1_OE_HI */
1144 reg = reg & ~0xa;
1145 cx_write(PAD_CTRL, reg);
1146 cx_write(port->reg_src_sel, 0);
1147 cx_write(port->reg_gen_ctrl, 8);
1148
1149 }
1150
1151 if (cx23885_boards[dev->board].portb == CX23885_MPEG_ENCODER)
1152 cx23885_av_clk(dev, 0);
1153
1087 return 0; 1154 return 0;
1088} 1155}
1089 1156
@@ -1093,13 +1160,13 @@ int cx23885_restart_queue(struct cx23885_tsport *port,
1093 struct cx23885_dev *dev = port->dev; 1160 struct cx23885_dev *dev = port->dev;
1094 struct cx23885_buffer *buf; 1161 struct cx23885_buffer *buf;
1095 1162
1096 dprintk(5, "%s()\n", __FUNCTION__); 1163 dprintk(5, "%s()\n", __func__);
1097 if (list_empty(&q->active)) 1164 if (list_empty(&q->active))
1098 { 1165 {
1099 struct cx23885_buffer *prev; 1166 struct cx23885_buffer *prev;
1100 prev = NULL; 1167 prev = NULL;
1101 1168
1102 dprintk(5, "%s() queue is empty\n", __FUNCTION__); 1169 dprintk(5, "%s() queue is empty\n", __func__);
1103 1170
1104 for (;;) { 1171 for (;;) {
1105 if (list_empty(&q->queued)) 1172 if (list_empty(&q->queued))
@@ -1154,7 +1221,7 @@ int cx23885_buf_prepare(struct videobuf_queue *q, struct cx23885_tsport *port,
1154 int size = port->ts_packet_size * port->ts_packet_count; 1221 int size = port->ts_packet_size * port->ts_packet_count;
1155 int rc; 1222 int rc;
1156 1223
1157 dprintk(1, "%s: %p\n", __FUNCTION__, buf); 1224 dprintk(1, "%s: %p\n", __func__, buf);
1158 if (0 != buf->vb.baddr && buf->vb.bsize < size) 1225 if (0 != buf->vb.baddr && buf->vb.bsize < size)
1159 return -EINVAL; 1226 return -EINVAL;
1160 1227
@@ -1197,7 +1264,7 @@ void cx23885_buf_queue(struct cx23885_tsport *port, struct cx23885_buffer *buf)
1197 buf->count = cx88q->count++; 1264 buf->count = cx88q->count++;
1198 mod_timer(&cx88q->timeout, jiffies + BUFFER_TIMEOUT); 1265 mod_timer(&cx88q->timeout, jiffies + BUFFER_TIMEOUT);
1199 dprintk(1, "[%p/%d] %s - first active\n", 1266 dprintk(1, "[%p/%d] %s - first active\n",
1200 buf, buf->vb.i, __FUNCTION__); 1267 buf, buf->vb.i, __func__);
1201 } else { 1268 } else {
1202 dprintk( 1, "queue is not empty - append to active\n" ); 1269 dprintk( 1, "queue is not empty - append to active\n" );
1203 prev = list_entry(cx88q->active.prev, struct cx23885_buffer, 1270 prev = list_entry(cx88q->active.prev, struct cx23885_buffer,
@@ -1208,7 +1275,7 @@ void cx23885_buf_queue(struct cx23885_tsport *port, struct cx23885_buffer *buf)
1208 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 1275 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
1209 prev->risc.jmp[2] = cpu_to_le32(0); /* 64 bit bits 63-32 */ 1276 prev->risc.jmp[2] = cpu_to_le32(0); /* 64 bit bits 63-32 */
1210 dprintk( 1, "[%p/%d] %s - append to active\n", 1277 dprintk( 1, "[%p/%d] %s - append to active\n",
1211 buf, buf->vb.i, __FUNCTION__); 1278 buf, buf->vb.i, __func__);
1212 } 1279 }
1213} 1280}
1214 1281
@@ -1239,13 +1306,23 @@ static void do_cancel_buffers(struct cx23885_tsport *port, char *reason,
1239 spin_unlock_irqrestore(&port->slock, flags); 1306 spin_unlock_irqrestore(&port->slock, flags);
1240} 1307}
1241 1308
1309void cx23885_cancel_buffers(struct cx23885_tsport *port)
1310{
1311 struct cx23885_dev *dev = port->dev;
1312 struct cx23885_dmaqueue *q = &port->mpegq;
1313
1314 dprintk(1, "%s()\n", __FUNCTION__);
1315 del_timer_sync(&q->timeout);
1316 cx23885_stop_dma(port);
1317 do_cancel_buffers(port, "cancel", 0);
1318}
1242 1319
1243static void cx23885_timeout(unsigned long data) 1320static void cx23885_timeout(unsigned long data)
1244{ 1321{
1245 struct cx23885_tsport *port = (struct cx23885_tsport *)data; 1322 struct cx23885_tsport *port = (struct cx23885_tsport *)data;
1246 struct cx23885_dev *dev = port->dev; 1323 struct cx23885_dev *dev = port->dev;
1247 1324
1248 dprintk(1, "%s()\n",__FUNCTION__); 1325 dprintk(1, "%s()\n",__func__);
1249 1326
1250 if (debug > 5) 1327 if (debug > 5)
1251 cx23885_sram_channel_dump(dev, &dev->sram_channels[ port->sram_chno ]); 1328 cx23885_sram_channel_dump(dev, &dev->sram_channels[ port->sram_chno ]);
@@ -1254,16 +1331,77 @@ static void cx23885_timeout(unsigned long data)
1254 do_cancel_buffers(port, "timeout", 1); 1331 do_cancel_buffers(port, "timeout", 1);
1255} 1332}
1256 1333
1334int cx23885_irq_417(struct cx23885_dev *dev, u32 status)
1335{
1336 /* FIXME: port1 assumption here. */
1337 struct cx23885_tsport *port = &dev->ts1;
1338 int count = 0;
1339 int handled = 0;
1340
1341 if (status == 0)
1342 return handled;
1343
1344 count = cx_read(port->reg_gpcnt);
1345 dprintk(7, "status: 0x%08x mask: 0x%08x count: 0x%x\n",
1346 status, cx_read(port->reg_ts_int_msk), count);
1347
1348 if ((status & VID_B_MSK_BAD_PKT) ||
1349 (status & VID_B_MSK_OPC_ERR) ||
1350 (status & VID_B_MSK_VBI_OPC_ERR) ||
1351 (status & VID_B_MSK_SYNC) ||
1352 (status & VID_B_MSK_VBI_SYNC) ||
1353 (status & VID_B_MSK_OF) ||
1354 (status & VID_B_MSK_VBI_OF)) {
1355 printk(KERN_ERR "%s: V4L mpeg risc op code error, status "
1356 "= 0x%x\n", dev->name, status);
1357 if (status & VID_B_MSK_BAD_PKT)
1358 dprintk(1, " VID_B_MSK_BAD_PKT\n");
1359 if (status & VID_B_MSK_OPC_ERR)
1360 dprintk(1, " VID_B_MSK_OPC_ERR\n");
1361 if (status & VID_B_MSK_VBI_OPC_ERR)
1362 dprintk(1, " VID_B_MSK_VBI_OPC_ERR\n");
1363 if (status & VID_B_MSK_SYNC)
1364 dprintk(1, " VID_B_MSK_SYNC\n");
1365 if (status & VID_B_MSK_VBI_SYNC)
1366 dprintk(1, " VID_B_MSK_VBI_SYNC\n");
1367 if (status & VID_B_MSK_OF)
1368 dprintk(1, " VID_B_MSK_OF\n");
1369 if (status & VID_B_MSK_VBI_OF)
1370 dprintk(1, " VID_B_MSK_VBI_OF\n");
1371
1372 cx_clear(port->reg_dma_ctl, port->dma_ctl_val);
1373 cx23885_sram_channel_dump(dev,
1374 &dev->sram_channels[port->sram_chno]);
1375 cx23885_417_check_encoder(dev);
1376 } else if (status & VID_B_MSK_RISCI1) {
1377 dprintk(7, " VID_B_MSK_RISCI1\n");
1378 spin_lock(&port->slock);
1379 cx23885_wakeup(port, &port->mpegq, count);
1380 spin_unlock(&port->slock);
1381 } else if (status & VID_B_MSK_RISCI2) {
1382 dprintk(7, " VID_B_MSK_RISCI2\n");
1383 spin_lock(&port->slock);
1384 cx23885_restart_queue(port, &port->mpegq);
1385 spin_unlock(&port->slock);
1386 }
1387 if (status) {
1388 cx_write(port->reg_ts_int_stat, status);
1389 handled = 1;
1390 }
1391
1392 return handled;
1393}
1394
1257static int cx23885_irq_ts(struct cx23885_tsport *port, u32 status) 1395static int cx23885_irq_ts(struct cx23885_tsport *port, u32 status)
1258{ 1396{
1259 struct cx23885_dev *dev = port->dev; 1397 struct cx23885_dev *dev = port->dev;
1260 int handled = 0; 1398 int handled = 0;
1261 u32 count; 1399 u32 count;
1262 1400
1263 if ( (status & VID_BC_MSK_OPC_ERR) || 1401 if ((status & VID_BC_MSK_OPC_ERR) ||
1264 (status & VID_BC_MSK_BAD_PKT) || 1402 (status & VID_BC_MSK_BAD_PKT) ||
1265 (status & VID_BC_MSK_SYNC) || 1403 (status & VID_BC_MSK_SYNC) ||
1266 (status & VID_BC_MSK_OF)) 1404 (status & VID_BC_MSK_OF))
1267 { 1405 {
1268 if (status & VID_BC_MSK_OPC_ERR) 1406 if (status & VID_BC_MSK_OPC_ERR)
1269 dprintk(7, " (VID_BC_MSK_OPC_ERR 0x%08x)\n", VID_BC_MSK_OPC_ERR); 1407 dprintk(7, " (VID_BC_MSK_OPC_ERR 0x%08x)\n", VID_BC_MSK_OPC_ERR);
@@ -1277,7 +1415,8 @@ static int cx23885_irq_ts(struct cx23885_tsport *port, u32 status)
1277 printk(KERN_ERR "%s: mpeg risc op code error\n", dev->name); 1415 printk(KERN_ERR "%s: mpeg risc op code error\n", dev->name);
1278 1416
1279 cx_clear(port->reg_dma_ctl, port->dma_ctl_val); 1417 cx_clear(port->reg_dma_ctl, port->dma_ctl_val);
1280 cx23885_sram_channel_dump(dev, &dev->sram_channels[ port->sram_chno ]); 1418 cx23885_sram_channel_dump(dev,
1419 &dev->sram_channels[port->sram_chno]);
1281 1420
1282 } else if (status & VID_BC_MSK_RISCI1) { 1421 } else if (status & VID_BC_MSK_RISCI1) {
1283 1422
@@ -1378,11 +1517,17 @@ static irqreturn_t cx23885_irq(int irq, void *dev_id)
1378 if (ts1_status) { 1517 if (ts1_status) {
1379 if (cx23885_boards[dev->board].portb == CX23885_MPEG_DVB) 1518 if (cx23885_boards[dev->board].portb == CX23885_MPEG_DVB)
1380 handled += cx23885_irq_ts(ts1, ts1_status); 1519 handled += cx23885_irq_ts(ts1, ts1_status);
1520 else
1521 if (cx23885_boards[dev->board].portb == CX23885_MPEG_ENCODER)
1522 handled += cx23885_irq_417(dev, ts1_status);
1381 } 1523 }
1382 1524
1383 if (ts2_status) { 1525 if (ts2_status) {
1384 if (cx23885_boards[dev->board].portc == CX23885_MPEG_DVB) 1526 if (cx23885_boards[dev->board].portc == CX23885_MPEG_DVB)
1385 handled += cx23885_irq_ts(ts2, ts2_status); 1527 handled += cx23885_irq_ts(ts2, ts2_status);
1528 else
1529 if (cx23885_boards[dev->board].portc == CX23885_MPEG_ENCODER)
1530 handled += cx23885_irq_417(dev, ts2_status);
1386 } 1531 }
1387 1532
1388 if (vida_status) 1533 if (vida_status)
@@ -1422,7 +1567,8 @@ static int __devinit cx23885_initdev(struct pci_dev *pci_dev,
1422 printk(KERN_INFO "%s/0: found at %s, rev: %d, irq: %d, " 1567 printk(KERN_INFO "%s/0: found at %s, rev: %d, irq: %d, "
1423 "latency: %d, mmio: 0x%llx\n", dev->name, 1568 "latency: %d, mmio: 0x%llx\n", dev->name,
1424 pci_name(pci_dev), dev->pci_rev, pci_dev->irq, 1569 pci_name(pci_dev), dev->pci_rev, pci_dev->irq,
1425 dev->pci_lat, (unsigned long long)pci_resource_start(pci_dev,0)); 1570 dev->pci_lat,
1571 (unsigned long long)pci_resource_start(pci_dev, 0));
1426 1572
1427 pci_set_master(pci_dev); 1573 pci_set_master(pci_dev);
1428 if (!pci_dma_supported(pci_dev, 0xffffffff)) { 1574 if (!pci_dma_supported(pci_dev, 0xffffffff)) {
diff --git a/drivers/media/video/cx23885/cx23885-dvb.c b/drivers/media/video/cx23885/cx23885-dvb.c
index ed465c007cea..870d6e197d65 100644
--- a/drivers/media/video/cx23885/cx23885-dvb.c
+++ b/drivers/media/video/cx23885/cx23885-dvb.c
@@ -36,9 +36,12 @@
36#include "tda18271.h" 36#include "tda18271.h"
37#include "lgdt330x.h" 37#include "lgdt330x.h"
38#include "xc5000.h" 38#include "xc5000.h"
39#include "tda10048.h"
39#include "dvb-pll.h" 40#include "dvb-pll.h"
40#include "tuner-xc2028.h" 41#include "tuner-xc2028.h"
41#include "tuner-xc2028-types.h" 42#include "tuner-simple.h"
43#include "dib7000p.h"
44#include "dibx000_common.h"
42 45
43static unsigned int debug; 46static unsigned int debug;
44 47
@@ -53,6 +56,8 @@ static unsigned int alt_tuner;
53module_param(alt_tuner, int, 0644); 56module_param(alt_tuner, int, 0644);
54MODULE_PARM_DESC(alt_tuner, "Enable alternate tuner configuration"); 57MODULE_PARM_DESC(alt_tuner, "Enable alternate tuner configuration");
55 58
59DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
60
56/* ------------------------------------------------------------------ */ 61/* ------------------------------------------------------------------ */
57 62
58static int dvb_buf_setup(struct videobuf_queue *q, 63static int dvb_buf_setup(struct videobuf_queue *q,
@@ -104,6 +109,13 @@ static struct s5h1409_config hauppauge_generic_config = {
104 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK, 109 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
105}; 110};
106 111
112static struct tda10048_config hauppauge_hvr1200_config = {
113 .demod_address = 0x10 >> 1,
114 .output_mode = TDA10048_SERIAL_OUTPUT,
115 .fwbulkwritelen = TDA10048_BULKWRITE_200,
116 .inversion = TDA10048_INVERSION_ON
117};
118
107static struct s5h1409_config hauppauge_ezqam_config = { 119static struct s5h1409_config hauppauge_ezqam_config = {
108 .demod_address = 0x32 >> 1, 120 .demod_address = 0x32 >> 1,
109 .output_mode = S5H1409_SERIAL_OUTPUT, 121 .output_mode = S5H1409_SERIAL_OUTPUT,
@@ -164,8 +176,10 @@ static struct tda829x_config tda829x_no_probe = {
164}; 176};
165 177
166static struct tda18271_std_map hauppauge_tda18271_std_map = { 178static struct tda18271_std_map hauppauge_tda18271_std_map = {
167 .atsc_6 = { .if_freq = 5380, .std_bits = 0x1b }, 179 .atsc_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3,
168 .qam_6 = { .if_freq = 4000, .std_bits = 0x18 }, 180 .if_lvl = 6, .rfagc_top = 0x37 },
181 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0,
182 .if_lvl = 6, .rfagc_top = 0x37 },
169}; 183};
170 184
171static struct tda18271_config hauppauge_tda18271_config = { 185static struct tda18271_config hauppauge_tda18271_config = {
@@ -173,6 +187,96 @@ static struct tda18271_config hauppauge_tda18271_config = {
173 .gate = TDA18271_GATE_ANALOG, 187 .gate = TDA18271_GATE_ANALOG,
174}; 188};
175 189
190static struct tda18271_config hauppauge_hvr1200_tuner_config = {
191 .gate = TDA18271_GATE_ANALOG,
192};
193
194struct dibx000_agc_config xc3028_agc_config = {
195 BAND_VHF | BAND_UHF, /* band_caps */
196
197 /* P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=0,
198 * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0,
199 * P_agc_inh_dc_rv_est=0, P_agc_time_est=3, P_agc_freeze=0,
200 * P_agc_nb_est=2, P_agc_write=0
201 */
202 (0 << 15) | (0 << 14) | (0 << 11) | (0 << 10) | (0 << 9) | (0 << 8) |
203 (3 << 5) | (0 << 4) | (2 << 1) | (0 << 0), /* setup */
204
205 712, /* inv_gain */
206 21, /* time_stabiliz */
207
208 0, /* alpha_level */
209 118, /* thlock */
210
211 0, /* wbd_inv */
212 2867, /* wbd_ref */
213 0, /* wbd_sel */
214 2, /* wbd_alpha */
215
216 0, /* agc1_max */
217 0, /* agc1_min */
218 39718, /* agc2_max */
219 9930, /* agc2_min */
220 0, /* agc1_pt1 */
221 0, /* agc1_pt2 */
222 0, /* agc1_pt3 */
223 0, /* agc1_slope1 */
224 0, /* agc1_slope2 */
225 0, /* agc2_pt1 */
226 128, /* agc2_pt2 */
227 29, /* agc2_slope1 */
228 29, /* agc2_slope2 */
229
230 17, /* alpha_mant */
231 27, /* alpha_exp */
232 23, /* beta_mant */
233 51, /* beta_exp */
234
235 1, /* perform_agc_softsplit */
236};
237
238/* PLL Configuration for COFDM BW_MHz = 8.000000
239 * With external clock = 30.000000 */
240struct dibx000_bandwidth_config xc3028_bw_config = {
241 60000, /* internal */
242 30000, /* sampling */
243 1, /* pll_cfg: prediv */
244 8, /* pll_cfg: ratio */
245 3, /* pll_cfg: range */
246 1, /* pll_cfg: reset */
247 0, /* pll_cfg: bypass */
248 0, /* misc: refdiv */
249 0, /* misc: bypclk_div */
250 1, /* misc: IO_CLK_en_core */
251 1, /* misc: ADClkSrc */
252 0, /* misc: modulo */
253 (3 << 14) | (1 << 12) | (524 << 0), /* sad_cfg: refsel, sel, freq_15k */
254 (1 << 25) | 5816102, /* ifreq = 5.200000 MHz */
255 20452225, /* timf */
256 30000000 /* xtal_hz */
257};
258
259static struct dib7000p_config hauppauge_hvr1400_dib7000_config = {
260 .output_mpeg2_in_188_bytes = 1,
261 .hostbus_diversity = 1,
262 .tuner_is_baseband = 0,
263 .update_lna = NULL,
264
265 .agc_config_count = 1,
266 .agc = &xc3028_agc_config,
267 .bw = &xc3028_bw_config,
268
269 .gpio_dir = DIB7000P_GPIO_DEFAULT_DIRECTIONS,
270 .gpio_val = DIB7000P_GPIO_DEFAULT_VALUES,
271 .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
272
273 .pwm_freq_div = 0,
274 .agc_control = NULL,
275 .spur_protect = 0,
276
277 .output_mode = OUTMODE_MPEG2_SERIAL,
278};
279
176static int cx23885_hvr1500_xc3028_callback(void *ptr, int command, int arg) 280static int cx23885_hvr1500_xc3028_callback(void *ptr, int command, int arg)
177{ 281{
178 struct cx23885_tsport *port = ptr; 282 struct cx23885_tsport *port = ptr;
@@ -182,7 +286,7 @@ static int cx23885_hvr1500_xc3028_callback(void *ptr, int command, int arg)
182 case XC2028_TUNER_RESET: 286 case XC2028_TUNER_RESET:
183 /* Send the tuner in then out of reset */ 287 /* Send the tuner in then out of reset */
184 /* GPIO-2 xc3028 tuner */ 288 /* GPIO-2 xc3028 tuner */
185 dprintk(1, "%s: XC2028_TUNER_RESET %d\n", __FUNCTION__, arg); 289 dprintk(1, "%s: XC2028_TUNER_RESET %d\n", __func__, arg);
186 290
187 cx_set(GP0_IO, 0x00040000); 291 cx_set(GP0_IO, 0x00040000);
188 cx_clear(GP0_IO, 0x00000004); 292 cx_clear(GP0_IO, 0x00000004);
@@ -192,10 +296,10 @@ static int cx23885_hvr1500_xc3028_callback(void *ptr, int command, int arg)
192 msleep(5); 296 msleep(5);
193 break; 297 break;
194 case XC2028_RESET_CLK: 298 case XC2028_RESET_CLK:
195 dprintk(1, "%s: XC2028_RESET_CLK %d\n", __FUNCTION__, arg); 299 dprintk(1, "%s: XC2028_RESET_CLK %d\n", __func__, arg);
196 break; 300 break;
197 default: 301 default:
198 dprintk(1, "%s: unknown command %d, arg %d\n", __FUNCTION__, 302 dprintk(1, "%s: unknown command %d, arg %d\n", __func__,
199 command, arg); 303 command, arg);
200 return -EINVAL; 304 return -EINVAL;
201 } 305 }
@@ -271,8 +375,9 @@ static int dvb_register(struct cx23885_tsport *port)
271 &fusionhdtv_5_express, 375 &fusionhdtv_5_express,
272 &i2c_bus->i2c_adap); 376 &i2c_bus->i2c_adap);
273 if (port->dvb.frontend != NULL) { 377 if (port->dvb.frontend != NULL) {
274 dvb_attach(dvb_pll_attach, port->dvb.frontend, 0x61, 378 dvb_attach(simple_tuner_attach, port->dvb.frontend,
275 &i2c_bus->i2c_adap, DVB_PLL_LG_TDVS_H06XF); 379 &i2c_bus->i2c_adap, 0x61,
380 TUNER_LG_TDVS_H06XF);
276 } 381 }
277 break; 382 break;
278 case CX23885_BOARD_HAUPPAUGE_HVR1500Q: 383 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
@@ -297,13 +402,52 @@ static int dvb_register(struct cx23885_tsport *port)
297 struct xc2028_config cfg = { 402 struct xc2028_config cfg = {
298 .i2c_adap = &i2c_bus->i2c_adap, 403 .i2c_adap = &i2c_bus->i2c_adap,
299 .i2c_addr = 0x61, 404 .i2c_addr = 0x61,
300 .video_dev = port,
301 .callback = cx23885_hvr1500_xc3028_callback, 405 .callback = cx23885_hvr1500_xc3028_callback,
302 }; 406 };
303 static struct xc2028_ctrl ctl = { 407 static struct xc2028_ctrl ctl = {
304 .fname = "xc3028-v27.fw", 408 .fname = "xc3028-v27.fw",
305 .max_len = 64, 409 .max_len = 64,
306 .scode_table = OREN538, 410 .scode_table = XC3028_FE_OREN538,
411 };
412
413 fe = dvb_attach(xc2028_attach,
414 port->dvb.frontend, &cfg);
415 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
416 fe->ops.tuner_ops.set_config(fe, &ctl);
417 }
418 break;
419 case CX23885_BOARD_HAUPPAUGE_HVR1200:
420 case CX23885_BOARD_HAUPPAUGE_HVR1700:
421 i2c_bus = &dev->i2c_bus[0];
422 port->dvb.frontend = dvb_attach(tda10048_attach,
423 &hauppauge_hvr1200_config,
424 &i2c_bus->i2c_adap);
425 if (port->dvb.frontend != NULL) {
426 dvb_attach(tda829x_attach, port->dvb.frontend,
427 &dev->i2c_bus[1].i2c_adap, 0x42,
428 &tda829x_no_probe);
429 dvb_attach(tda18271_attach, port->dvb.frontend,
430 0x60, &dev->i2c_bus[1].i2c_adap,
431 &hauppauge_hvr1200_tuner_config);
432 }
433 break;
434 case CX23885_BOARD_HAUPPAUGE_HVR1400:
435 i2c_bus = &dev->i2c_bus[0];
436 port->dvb.frontend = dvb_attach(dib7000p_attach,
437 &i2c_bus->i2c_adap,
438 0x12, &hauppauge_hvr1400_dib7000_config);
439 if (port->dvb.frontend != NULL) {
440 struct dvb_frontend *fe;
441 struct xc2028_config cfg = {
442 .i2c_adap = &dev->i2c_bus[1].i2c_adap,
443 .i2c_addr = 0x64,
444 .callback = cx23885_hvr1500_xc3028_callback,
445 };
446 static struct xc2028_ctrl ctl = {
447 .fname = "xc3028L-v36.fw",
448 .max_len = 64,
449 .demod = 5000,
450 .d2633 = 1
307 }; 451 };
308 452
309 fe = dvb_attach(xc2028_attach, 453 fe = dvb_attach(xc2028_attach,
@@ -330,7 +474,7 @@ static int dvb_register(struct cx23885_tsport *port)
330 474
331 /* register everything */ 475 /* register everything */
332 return videobuf_dvb_register(&port->dvb, THIS_MODULE, port, 476 return videobuf_dvb_register(&port->dvb, THIS_MODULE, port,
333 &dev->pci->dev); 477 &dev->pci->dev, adapter_nr);
334} 478}
335 479
336int cx23885_dvb_register(struct cx23885_tsport *port) 480int cx23885_dvb_register(struct cx23885_tsport *port)
@@ -338,7 +482,7 @@ int cx23885_dvb_register(struct cx23885_tsport *port)
338 struct cx23885_dev *dev = port->dev; 482 struct cx23885_dev *dev = port->dev;
339 int err; 483 int err;
340 484
341 dprintk(1, "%s\n", __FUNCTION__); 485 dprintk(1, "%s\n", __func__);
342 dprintk(1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n", 486 dprintk(1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
343 dev->board, 487 dev->board,
344 dev->name, 488 dev->name,
@@ -349,12 +493,12 @@ int cx23885_dvb_register(struct cx23885_tsport *port)
349 493
350 /* dvb stuff */ 494 /* dvb stuff */
351 printk("%s: cx23885 based dvb card\n", dev->name); 495 printk("%s: cx23885 based dvb card\n", dev->name);
352 videobuf_queue_pci_init(&port->dvb.dvbq, &dvb_qops, dev->pci, &port->slock, 496 videobuf_queue_sg_init(&port->dvb.dvbq, &dvb_qops, &dev->pci->dev, &port->slock,
353 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP, 497 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_TOP,
354 sizeof(struct cx23885_buffer), port); 498 sizeof(struct cx23885_buffer), port);
355 err = dvb_register(port); 499 err = dvb_register(port);
356 if (err != 0) 500 if (err != 0)
357 printk("%s() dvb_register failed err = %d\n", __FUNCTION__, err); 501 printk("%s() dvb_register failed err = %d\n", __func__, err);
358 502
359 return err; 503 return err;
360} 504}
diff --git a/drivers/media/video/cx23885/cx23885-i2c.c b/drivers/media/video/cx23885/cx23885-i2c.c
index 92fe0bd37c84..c6bb0a05bc1c 100644
--- a/drivers/media/video/cx23885/cx23885-i2c.c
+++ b/drivers/media/video/cx23885/cx23885-i2c.c
@@ -33,7 +33,7 @@ static unsigned int i2c_debug;
33module_param(i2c_debug, int, 0644); 33module_param(i2c_debug, int, 0644);
34MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]"); 34MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
35 35
36static unsigned int i2c_scan = 0; 36static unsigned int i2c_scan;
37module_param(i2c_scan, int, 0444); 37module_param(i2c_scan, int, 0444);
38MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time"); 38MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time");
39 39
@@ -87,10 +87,10 @@ static int i2c_sendbytes(struct i2c_adapter *i2c_adap,
87 int retval, cnt; 87 int retval, cnt;
88 88
89 if (joined_rlen) 89 if (joined_rlen)
90 dprintk(1, "%s(msg->wlen=%d, nextmsg->rlen=%d)\n", __FUNCTION__, 90 dprintk(1, "%s(msg->wlen=%d, nextmsg->rlen=%d)\n", __func__,
91 msg->len, joined_rlen); 91 msg->len, joined_rlen);
92 else 92 else
93 dprintk(1, "%s(msg->len=%d)\n", __FUNCTION__, msg->len); 93 dprintk(1, "%s(msg->len=%d)\n", __func__, msg->len);
94 94
95 /* Deal with i2c probe functions with zero payload */ 95 /* Deal with i2c probe functions with zero payload */
96 if (msg->len == 0) { 96 if (msg->len == 0) {
@@ -101,7 +101,7 @@ static int i2c_sendbytes(struct i2c_adapter *i2c_adap,
101 if (!i2c_slave_did_ack(i2c_adap)) 101 if (!i2c_slave_did_ack(i2c_adap))
102 return -EIO; 102 return -EIO;
103 103
104 dprintk(1, "%s() returns 0\n", __FUNCTION__); 104 dprintk(1, "%s() returns 0\n", __func__);
105 return 0; 105 return 0;
106 } 106 }
107 107
@@ -176,7 +176,7 @@ static int i2c_readbytes(struct i2c_adapter *i2c_adap,
176 176
177 177
178 if (i2c_debug && !joined) 178 if (i2c_debug && !joined)
179 dprintk(1, "%s(msg->len=%d)\n", __FUNCTION__, msg->len); 179 dprintk(1, "%s(msg->len=%d)\n", __func__, msg->len);
180 180
181 /* Deal with i2c probe functions with zero payload */ 181 /* Deal with i2c probe functions with zero payload */
182 if (msg->len == 0) { 182 if (msg->len == 0) {
@@ -188,7 +188,7 @@ static int i2c_readbytes(struct i2c_adapter *i2c_adap,
188 return -EIO; 188 return -EIO;
189 189
190 190
191 dprintk(1, "%s() returns 0\n", __FUNCTION__); 191 dprintk(1, "%s() returns 0\n", __func__);
192 return 0; 192 return 0;
193 } 193 }
194 194
@@ -238,11 +238,11 @@ static int i2c_xfer(struct i2c_adapter *i2c_adap,
238 struct cx23885_dev *dev = bus->dev; 238 struct cx23885_dev *dev = bus->dev;
239 int i, retval = 0; 239 int i, retval = 0;
240 240
241 dprintk(1, "%s(num = %d)\n", __FUNCTION__, num); 241 dprintk(1, "%s(num = %d)\n", __func__, num);
242 242
243 for (i = 0 ; i < num; i++) { 243 for (i = 0 ; i < num; i++) {
244 dprintk(1, "%s(num = %d) addr = 0x%02x len = 0x%x\n", 244 dprintk(1, "%s(num = %d) addr = 0x%02x len = 0x%x\n",
245 __FUNCTION__, num, msgs[i].addr, msgs[i].len); 245 __func__, num, msgs[i].addr, msgs[i].len);
246 if (msgs[i].flags & I2C_M_RD) { 246 if (msgs[i].flags & I2C_M_RD) {
247 /* read */ 247 /* read */
248 retval = i2c_readbytes(i2c_adap, &msgs[i], 0); 248 retval = i2c_readbytes(i2c_adap, &msgs[i], 0);
@@ -353,6 +353,8 @@ static struct i2c_client cx23885_i2c_client_template = {
353}; 353};
354 354
355static char *i2c_devs[128] = { 355static char *i2c_devs[128] = {
356 [0x10 >> 1] = "tda10048",
357 [0x12 >> 1] = "dib7000pc",
356 [ 0x1c >> 1 ] = "lgdt3303", 358 [ 0x1c >> 1 ] = "lgdt3303",
357 [ 0x86 >> 1 ] = "tda9887", 359 [ 0x86 >> 1 ] = "tda9887",
358 [ 0x32 >> 1 ] = "cx24227", 360 [ 0x32 >> 1 ] = "cx24227",
@@ -360,7 +362,8 @@ static char *i2c_devs[128] = {
360 [ 0x84 >> 1 ] = "tda8295", 362 [ 0x84 >> 1 ] = "tda8295",
361 [ 0xa0 >> 1 ] = "eeprom", 363 [ 0xa0 >> 1 ] = "eeprom",
362 [ 0xc0 >> 1 ] = "tuner/mt2131/tda8275", 364 [ 0xc0 >> 1 ] = "tuner/mt2131/tda8275",
363 [ 0xc2 >> 1 ] = "tuner/mt2131/tda8275/xc5000", 365 [0xc2 >> 1] = "tuner/mt2131/tda8275/xc5000/xc3028",
366 [0xc8 >> 1] = "tuner/xc3028L",
364}; 367};
365 368
366static void do_i2c_scan(char *name, struct i2c_client *c) 369static void do_i2c_scan(char *name, struct i2c_client *c)
@@ -383,7 +386,7 @@ int cx23885_i2c_register(struct cx23885_i2c *bus)
383{ 386{
384 struct cx23885_dev *dev = bus->dev; 387 struct cx23885_dev *dev = bus->dev;
385 388
386 dprintk(1, "%s(bus = %d)\n", __FUNCTION__, bus->nr); 389 dprintk(1, "%s(bus = %d)\n", __func__, bus->nr);
387 390
388 memcpy(&bus->i2c_adap, &cx23885_i2c_adap_template, 391 memcpy(&bus->i2c_adap, &cx23885_i2c_adap_template,
389 sizeof(bus->i2c_adap)); 392 sizeof(bus->i2c_adap));
@@ -420,6 +423,29 @@ int cx23885_i2c_unregister(struct cx23885_i2c *bus)
420 return 0; 423 return 0;
421} 424}
422 425
426void cx23885_av_clk(struct cx23885_dev *dev, int enable)
427{
428 /* write 0 to bus 2 addr 0x144 via i2x_xfer() */
429 char buffer[3];
430 struct i2c_msg msg;
431 dprintk(1, "%s(enabled = %d)\n", __func__, enable);
432
433 /* Register 0x144 */
434 buffer[0] = 0x01;
435 buffer[1] = 0x44;
436 if (enable == 1)
437 buffer[2] = 0x05;
438 else
439 buffer[2] = 0x00;
440
441 msg.addr = 0x44;
442 msg.flags = I2C_M_TEN;
443 msg.len = 3;
444 msg.buf = buffer;
445
446 i2c_xfer(&dev->i2c_bus[2].i2c_adap, &msg, 1);
447}
448
423/* ----------------------------------------------------------------------- */ 449/* ----------------------------------------------------------------------- */
424 450
425/* 451/*
diff --git a/drivers/media/video/cx23885/cx23885-video.c b/drivers/media/video/cx23885/cx23885-video.c
index d3c4d2c5cbe0..84652210a28c 100644
--- a/drivers/media/video/cx23885/cx23885-video.c
+++ b/drivers/media/video/cx23885/cx23885-video.c
@@ -141,7 +141,7 @@ static struct cx23885_fmt *format_by_fourcc(unsigned int fourcc)
141 if (formats[i].fourcc == fourcc) 141 if (formats[i].fourcc == fourcc)
142 return formats+i; 142 return formats+i;
143 143
144 printk(KERN_ERR "%s(0x%08x) NOT FOUND\n", __FUNCTION__, fourcc); 144 printk(KERN_ERR "%s(0x%08x) NOT FOUND\n", __func__, fourcc);
145 return NULL; 145 return NULL;
146} 146}
147 147
@@ -292,13 +292,13 @@ void cx23885_video_wakeup(struct cx23885_dev *dev,
292 } 292 }
293 if (bc != 1) 293 if (bc != 1)
294 printk(KERN_ERR "%s: %d buffers handled (should be 1)\n", 294 printk(KERN_ERR "%s: %d buffers handled (should be 1)\n",
295 __FUNCTION__, bc); 295 __func__, bc);
296} 296}
297 297
298int cx23885_set_tvnorm(struct cx23885_dev *dev, v4l2_std_id norm) 298int cx23885_set_tvnorm(struct cx23885_dev *dev, v4l2_std_id norm)
299{ 299{
300 dprintk(1, "%s(norm = 0x%08x) name: [%s]\n", 300 dprintk(1, "%s(norm = 0x%08x) name: [%s]\n",
301 __FUNCTION__, 301 __func__,
302 (unsigned int)norm, 302 (unsigned int)norm,
303 v4l2_norm_to_name(norm)); 303 v4l2_norm_to_name(norm));
304 304
@@ -319,7 +319,7 @@ struct video_device *cx23885_vdev_init(struct cx23885_dev *dev,
319 char *type) 319 char *type)
320{ 320{
321 struct video_device *vfd; 321 struct video_device *vfd;
322 dprintk(1, "%s()\n", __FUNCTION__); 322 dprintk(1, "%s()\n", __func__);
323 323
324 vfd = video_device_alloc(); 324 vfd = video_device_alloc();
325 if (NULL == vfd) 325 if (NULL == vfd)
@@ -358,7 +358,7 @@ EXPORT_SYMBOL(cx23885_ctrl_query);
358static int res_get(struct cx23885_dev *dev, struct cx23885_fh *fh, 358static int res_get(struct cx23885_dev *dev, struct cx23885_fh *fh,
359 unsigned int bit) 359 unsigned int bit)
360{ 360{
361 dprintk(1, "%s()\n", __FUNCTION__); 361 dprintk(1, "%s()\n", __func__);
362 if (fh->resources & bit) 362 if (fh->resources & bit)
363 /* have it already allocated */ 363 /* have it already allocated */
364 return 1; 364 return 1;
@@ -392,7 +392,7 @@ static void res_free(struct cx23885_dev *dev, struct cx23885_fh *fh,
392 unsigned int bits) 392 unsigned int bits)
393{ 393{
394 BUG_ON((fh->resources & bits) != bits); 394 BUG_ON((fh->resources & bits) != bits);
395 dprintk(1, "%s()\n", __FUNCTION__); 395 dprintk(1, "%s()\n", __func__);
396 396
397 mutex_lock(&dev->lock); 397 mutex_lock(&dev->lock);
398 fh->resources &= ~bits; 398 fh->resources &= ~bits;
@@ -407,7 +407,7 @@ int cx23885_video_mux(struct cx23885_dev *dev, unsigned int input)
407 memset(&route, 0, sizeof(route)); 407 memset(&route, 0, sizeof(route));
408 408
409 dprintk(1, "%s() video_mux: %d [vmux=%d, gpio=0x%x,0x%x,0x%x,0x%x]\n", 409 dprintk(1, "%s() video_mux: %d [vmux=%d, gpio=0x%x,0x%x,0x%x,0x%x]\n",
410 __FUNCTION__, 410 __func__,
411 input, INPUT(input)->vmux, 411 input, INPUT(input)->vmux,
412 INPUT(input)->gpio0, INPUT(input)->gpio1, 412 INPUT(input)->gpio0, INPUT(input)->gpio1,
413 INPUT(input)->gpio2, INPUT(input)->gpio3); 413 INPUT(input)->gpio2, INPUT(input)->gpio3);
@@ -427,7 +427,7 @@ EXPORT_SYMBOL(cx23885_video_mux);
427int cx23885_set_scale(struct cx23885_dev *dev, unsigned int width, 427int cx23885_set_scale(struct cx23885_dev *dev, unsigned int width,
428 unsigned int height, enum v4l2_field field) 428 unsigned int height, enum v4l2_field field)
429{ 429{
430 dprintk(1, "%s()\n", __FUNCTION__); 430 dprintk(1, "%s()\n", __func__);
431 return 0; 431 return 0;
432} 432}
433 433
@@ -435,7 +435,7 @@ static int cx23885_start_video_dma(struct cx23885_dev *dev,
435 struct cx23885_dmaqueue *q, 435 struct cx23885_dmaqueue *q,
436 struct cx23885_buffer *buf) 436 struct cx23885_buffer *buf)
437{ 437{
438 dprintk(1, "%s()\n", __FUNCTION__); 438 dprintk(1, "%s()\n", __func__);
439 439
440 /* setup fifo + format */ 440 /* setup fifo + format */
441 cx23885_sram_channel_setup(dev, &dev->sram_channels[SRAM_CH01], 441 cx23885_sram_channel_setup(dev, &dev->sram_channels[SRAM_CH01],
@@ -463,7 +463,7 @@ static int cx23885_restart_video_queue(struct cx23885_dev *dev,
463{ 463{
464 struct cx23885_buffer *buf, *prev; 464 struct cx23885_buffer *buf, *prev;
465 struct list_head *item; 465 struct list_head *item;
466 dprintk(1, "%s()\n", __FUNCTION__); 466 dprintk(1, "%s()\n", __func__);
467 467
468 if (!list_empty(&q->active)) { 468 if (!list_empty(&q->active)) {
469 buf = list_entry(q->active.next, struct cx23885_buffer, 469 buf = list_entry(q->active.next, struct cx23885_buffer,
@@ -579,13 +579,13 @@ static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
579 if (dev->tvnorm & V4L2_STD_NTSC) { 579 if (dev->tvnorm & V4L2_STD_NTSC) {
580 /* cx25840 transmits NTSC bottom field first */ 580 /* cx25840 transmits NTSC bottom field first */
581 dprintk(1, "%s() Creating NTSC risc\n", 581 dprintk(1, "%s() Creating NTSC risc\n",
582 __FUNCTION__); 582 __func__);
583 line0_offset = buf->bpl; 583 line0_offset = buf->bpl;
584 line1_offset = 0; 584 line1_offset = 0;
585 } else { 585 } else {
586 /* All other formats are top field first */ 586 /* All other formats are top field first */
587 dprintk(1, "%s() Creating PAL/SECAM risc\n", 587 dprintk(1, "%s() Creating PAL/SECAM risc\n",
588 __FUNCTION__); 588 __func__);
589 line0_offset = 0; 589 line0_offset = 0;
590 line1_offset = buf->bpl; 590 line1_offset = buf->bpl;
591 } 591 }
@@ -765,8 +765,8 @@ static int video_open(struct inode *inode, struct file *file)
765 fh->height = 240; 765 fh->height = 240;
766 fh->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24); 766 fh->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
767 767
768 videobuf_queue_pci_init(&fh->vidq, &cx23885_video_qops, 768 videobuf_queue_sg_init(&fh->vidq, &cx23885_video_qops,
769 dev->pci, &dev->slock, 769 &dev->pci->dev, &dev->slock,
770 V4L2_BUF_TYPE_VIDEO_CAPTURE, 770 V4L2_BUF_TYPE_VIDEO_CAPTURE,
771 V4L2_FIELD_INTERLACED, 771 V4L2_FIELD_INTERLACED,
772 sizeof(struct cx23885_buffer), 772 sizeof(struct cx23885_buffer),
@@ -885,7 +885,7 @@ static int video_mmap(struct file *file, struct vm_area_struct *vma)
885 885
886int cx23885_get_control(struct cx23885_dev *dev, struct v4l2_control *ctl) 886int cx23885_get_control(struct cx23885_dev *dev, struct v4l2_control *ctl)
887{ 887{
888 dprintk(1, "%s() calling cx25840(VIDIOC_G_CTRL)\n", __FUNCTION__); 888 dprintk(1, "%s() calling cx25840(VIDIOC_G_CTRL)\n", __func__);
889 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_G_CTRL, ctl); 889 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_G_CTRL, ctl);
890 return 0; 890 return 0;
891} 891}
@@ -894,7 +894,7 @@ EXPORT_SYMBOL(cx23885_get_control);
894int cx23885_set_control(struct cx23885_dev *dev, struct v4l2_control *ctl) 894int cx23885_set_control(struct cx23885_dev *dev, struct v4l2_control *ctl)
895{ 895{
896 dprintk(1, "%s() calling cx25840(VIDIOC_S_CTRL)" 896 dprintk(1, "%s() calling cx25840(VIDIOC_S_CTRL)"
897 " (disabled - no action)\n", __FUNCTION__); 897 " (disabled - no action)\n", __func__);
898 return 0; 898 return 0;
899} 899}
900EXPORT_SYMBOL(cx23885_set_control); 900EXPORT_SYMBOL(cx23885_set_control);
@@ -990,7 +990,7 @@ static int vidioc_s_fmt_cap(struct file *file, void *priv,
990 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev; 990 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
991 int err; 991 int err;
992 992
993 dprintk(2, "%s()\n", __FUNCTION__); 993 dprintk(2, "%s()\n", __func__);
994 err = vidioc_try_fmt_cap(file, priv, f); 994 err = vidioc_try_fmt_cap(file, priv, f);
995 995
996 if (0 != err) 996 if (0 != err)
@@ -999,7 +999,7 @@ static int vidioc_s_fmt_cap(struct file *file, void *priv,
999 fh->width = f->fmt.pix.width; 999 fh->width = f->fmt.pix.width;
1000 fh->height = f->fmt.pix.height; 1000 fh->height = f->fmt.pix.height;
1001 fh->vidq.field = f->fmt.pix.field; 1001 fh->vidq.field = f->fmt.pix.field;
1002 dprintk(2, "%s() width=%d height=%d field=%d\n", __FUNCTION__, 1002 dprintk(2, "%s() width=%d height=%d field=%d\n", __func__,
1003 fh->width, fh->height, fh->vidq.field); 1003 fh->width, fh->height, fh->vidq.field);
1004 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_S_FMT, f); 1004 cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_S_FMT, f);
1005 return 0; 1005 return 0;
@@ -1101,7 +1101,7 @@ static int vidioc_streamon(struct file *file, void *priv,
1101{ 1101{
1102 struct cx23885_fh *fh = priv; 1102 struct cx23885_fh *fh = priv;
1103 struct cx23885_dev *dev = fh->dev; 1103 struct cx23885_dev *dev = fh->dev;
1104 dprintk(1, "%s()\n", __FUNCTION__); 1104 dprintk(1, "%s()\n", __func__);
1105 1105
1106 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)) 1106 if (unlikely(fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE))
1107 return -EINVAL; 1107 return -EINVAL;
@@ -1118,7 +1118,7 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1118 struct cx23885_fh *fh = priv; 1118 struct cx23885_fh *fh = priv;
1119 struct cx23885_dev *dev = fh->dev; 1119 struct cx23885_dev *dev = fh->dev;
1120 int err, res; 1120 int err, res;
1121 dprintk(1, "%s()\n", __FUNCTION__); 1121 dprintk(1, "%s()\n", __func__);
1122 1122
1123 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1123 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1124 return -EINVAL; 1124 return -EINVAL;
@@ -1136,7 +1136,7 @@ static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
1136static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *tvnorms) 1136static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *tvnorms)
1137{ 1137{
1138 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev; 1138 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1139 dprintk(1, "%s()\n", __FUNCTION__); 1139 dprintk(1, "%s()\n", __func__);
1140 1140
1141 mutex_lock(&dev->lock); 1141 mutex_lock(&dev->lock);
1142 cx23885_set_tvnorm(dev, *tvnorms); 1142 cx23885_set_tvnorm(dev, *tvnorms);
@@ -1159,7 +1159,7 @@ int cx23885_enum_input(struct cx23885_dev *dev, struct v4l2_input *i)
1159 [CX23885_VMUX_DEBUG] = "for debug only", 1159 [CX23885_VMUX_DEBUG] = "for debug only",
1160 }; 1160 };
1161 unsigned int n; 1161 unsigned int n;
1162 dprintk(1, "%s()\n", __FUNCTION__); 1162 dprintk(1, "%s()\n", __func__);
1163 1163
1164 n = i->index; 1164 n = i->index;
1165 if (n >= 4) 1165 if (n >= 4)
@@ -1184,7 +1184,7 @@ static int vidioc_enum_input(struct file *file, void *priv,
1184 struct v4l2_input *i) 1184 struct v4l2_input *i)
1185{ 1185{
1186 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev; 1186 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1187 dprintk(1, "%s()\n", __FUNCTION__); 1187 dprintk(1, "%s()\n", __func__);
1188 return cx23885_enum_input(dev, i); 1188 return cx23885_enum_input(dev, i);
1189} 1189}
1190 1190
@@ -1193,7 +1193,7 @@ static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
1193 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev; 1193 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1194 1194
1195 *i = dev->input; 1195 *i = dev->input;
1196 dprintk(1, "%s() returns %d\n", __FUNCTION__, *i); 1196 dprintk(1, "%s() returns %d\n", __func__, *i);
1197 return 0; 1197 return 0;
1198} 1198}
1199 1199
@@ -1201,10 +1201,10 @@ static int vidioc_s_input(struct file *file, void *priv, unsigned int i)
1201{ 1201{
1202 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev; 1202 struct cx23885_dev *dev = ((struct cx23885_fh *)priv)->dev;
1203 1203
1204 dprintk(1, "%s(%d)\n", __FUNCTION__, i); 1204 dprintk(1, "%s(%d)\n", __func__, i);
1205 1205
1206 if (i >= 4) { 1206 if (i >= 4) {
1207 dprintk(1, "%s() -EINVAL\n", __FUNCTION__); 1207 dprintk(1, "%s() -EINVAL\n", __func__);
1208 return -EINVAL; 1208 return -EINVAL;
1209 } 1209 }
1210 1210
@@ -1389,7 +1389,7 @@ int cx23885_video_irq(struct cx23885_dev *dev, u32 status)
1389 return handled; 1389 return handled;
1390 cx_write(VID_A_INT_STAT, status); 1390 cx_write(VID_A_INT_STAT, status);
1391 1391
1392 dprintk(2, "%s() status = 0x%08x\n", __FUNCTION__, status); 1392 dprintk(2, "%s() status = 0x%08x\n", __func__, status);
1393 /* risc op code error */ 1393 /* risc op code error */
1394 if (status & (1 << 16)) { 1394 if (status & (1 << 16)) {
1395 printk(KERN_WARNING "%s/0: video risc op code error\n", 1395 printk(KERN_WARNING "%s/0: video risc op code error\n",
@@ -1487,7 +1487,7 @@ static const struct file_operations radio_fops = {
1487 1487
1488void cx23885_video_unregister(struct cx23885_dev *dev) 1488void cx23885_video_unregister(struct cx23885_dev *dev)
1489{ 1489{
1490 dprintk(1, "%s()\n", __FUNCTION__); 1490 dprintk(1, "%s()\n", __func__);
1491 cx_clear(PCI_INT_MSK, 1); 1491 cx_clear(PCI_INT_MSK, 1);
1492 1492
1493 if (dev->video_dev) { 1493 if (dev->video_dev) {
@@ -1505,7 +1505,7 @@ int cx23885_video_register(struct cx23885_dev *dev)
1505{ 1505{
1506 int err; 1506 int err;
1507 1507
1508 dprintk(1, "%s()\n", __FUNCTION__); 1508 dprintk(1, "%s()\n", __func__);
1509 spin_lock_init(&dev->slock); 1509 spin_lock_init(&dev->slock);
1510 1510
1511 /* Initialize VBI template */ 1511 /* Initialize VBI template */
diff --git a/drivers/media/video/cx23885/cx23885.h b/drivers/media/video/cx23885/cx23885.h
index 7cb2179f2622..32af87f25e7b 100644
--- a/drivers/media/video/cx23885/cx23885.h
+++ b/drivers/media/video/cx23885/cx23885.h
@@ -32,6 +32,7 @@
32 32
33#include "btcx-risc.h" 33#include "btcx-risc.h"
34#include "cx23885-reg.h" 34#include "cx23885-reg.h"
35#include "media/cx2341x.h"
35 36
36#include <linux/version.h> 37#include <linux/version.h>
37#include <linux/mutex.h> 38#include <linux/mutex.h>
@@ -59,6 +60,9 @@
59#define CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP 4 60#define CX23885_BOARD_DVICO_FUSIONHDTV_5_EXP 4
60#define CX23885_BOARD_HAUPPAUGE_HVR1500Q 5 61#define CX23885_BOARD_HAUPPAUGE_HVR1500Q 5
61#define CX23885_BOARD_HAUPPAUGE_HVR1500 6 62#define CX23885_BOARD_HAUPPAUGE_HVR1500 6
63#define CX23885_BOARD_HAUPPAUGE_HVR1200 7
64#define CX23885_BOARD_HAUPPAUGE_HVR1700 8
65#define CX23885_BOARD_HAUPPAUGE_HVR1400 9
62 66
63/* Currently unsupported by the driver: PAL/H, NTSC/Kr, SECAM B/G/H/LC */ 67/* Currently unsupported by the driver: PAL/H, NTSC/Kr, SECAM B/G/H/LC */
64#define CX23885_NORMS (\ 68#define CX23885_NORMS (\
@@ -154,6 +158,7 @@ typedef enum {
154 CX23885_MPEG_UNDEFINED = 0, 158 CX23885_MPEG_UNDEFINED = 0,
155 CX23885_MPEG_DVB, 159 CX23885_MPEG_DVB,
156 CX23885_ANALOG_VIDEO, 160 CX23885_ANALOG_VIDEO,
161 CX23885_MPEG_ENCODER,
157} port_t; 162} port_t;
158 163
159struct cx23885_board { 164struct cx23885_board {
@@ -252,6 +257,8 @@ struct cx23885_tsport {
252 u32 gen_ctrl_val; 257 u32 gen_ctrl_val;
253 u32 ts_clk_en_val; 258 u32 ts_clk_en_val;
254 u32 src_sel_val; 259 u32 src_sel_val;
260 u32 vld_misc_val;
261 u32 hw_sop_ctrl_val;
255}; 262};
256 263
257struct cx23885_dev { 264struct cx23885_dev {
@@ -312,6 +319,14 @@ struct cx23885_dev {
312 struct cx23885_dmaqueue vidq; 319 struct cx23885_dmaqueue vidq;
313 struct cx23885_dmaqueue vbiq; 320 struct cx23885_dmaqueue vbiq;
314 spinlock_t slock; 321 spinlock_t slock;
322
323 /* MPEG Encoder ONLY settings */
324 u32 cx23417_mailbox;
325 struct cx2341x_mpeg_params mpeg_params;
326 struct video_device *v4l_device;
327 atomic_t v4l_reader_count;
328 struct cx23885_tvnorm encodernorm;
329
315}; 330};
316 331
317extern struct list_head cx23885_devlist; 332extern struct list_head cx23885_devlist;
@@ -431,6 +446,18 @@ extern int cx23885_i2c_register(struct cx23885_i2c *bus);
431extern int cx23885_i2c_unregister(struct cx23885_i2c *bus); 446extern int cx23885_i2c_unregister(struct cx23885_i2c *bus);
432extern void cx23885_call_i2c_clients(struct cx23885_i2c *bus, unsigned int cmd, 447extern void cx23885_call_i2c_clients(struct cx23885_i2c *bus, unsigned int cmd,
433 void *arg); 448 void *arg);
449extern void cx23885_av_clk(struct cx23885_dev *dev, int enable);
450
451/* ----------------------------------------------------------- */
452/* cx23885-417.c */
453extern int cx23885_417_register(struct cx23885_dev *dev);
454extern void cx23885_417_unregister(struct cx23885_dev *dev);
455extern int cx23885_irq_417(struct cx23885_dev *dev, u32 status);
456extern void cx23885_417_check_encoder(struct cx23885_dev *dev);
457extern void cx23885_mc417_init(struct cx23885_dev *dev);
458extern int mc417_memory_read(struct cx23885_dev *dev, u32 address, u32 *value);
459extern int mc417_memory_write(struct cx23885_dev *dev, u32 address, u32 value);
460
434 461
435/* ----------------------------------------------------------- */ 462/* ----------------------------------------------------------- */
436/* tv norms */ 463/* tv norms */
diff --git a/drivers/media/video/cx25840/cx25840-core.c b/drivers/media/video/cx25840/cx25840-core.c
index 756a1eeb274e..7fde678b2c4a 100644
--- a/drivers/media/video/cx25840/cx25840-core.c
+++ b/drivers/media/video/cx25840/cx25840-core.c
@@ -352,7 +352,7 @@ static void cx23885_initialize(struct i2c_client *client)
352static void input_change(struct i2c_client *client) 352static void input_change(struct i2c_client *client)
353{ 353{
354 struct cx25840_state *state = i2c_get_clientdata(client); 354 struct cx25840_state *state = i2c_get_clientdata(client);
355 v4l2_std_id std = cx25840_get_v4lstd(client); 355 v4l2_std_id std = state->std;
356 356
357 /* Follow step 8c and 8d of section 3.16 in the cx25840 datasheet */ 357 /* Follow step 8c and 8d of section 3.16 in the cx25840 datasheet */
358 if (std & V4L2_STD_SECAM) { 358 if (std & V4L2_STD_SECAM) {
@@ -523,32 +523,34 @@ static int set_input(struct i2c_client *client, enum cx25840_video_input vid_inp
523 523
524/* ----------------------------------------------------------------------- */ 524/* ----------------------------------------------------------------------- */
525 525
526static int set_v4lstd(struct i2c_client *client, v4l2_std_id std) 526static int set_v4lstd(struct i2c_client *client)
527{ 527{
528 u8 fmt=0; /* zero is autodetect */ 528 struct cx25840_state *state = i2c_get_clientdata(client);
529 u8 fmt = 0; /* zero is autodetect */
530 u8 pal_m = 0;
529 531
530 /* First tests should be against specific std */ 532 /* First tests should be against specific std */
531 if (std == V4L2_STD_NTSC_M_JP) { 533 if (state->std == V4L2_STD_NTSC_M_JP) {
532 fmt=0x2; 534 fmt = 0x2;
533 } else if (std == V4L2_STD_NTSC_443) { 535 } else if (state->std == V4L2_STD_NTSC_443) {
534 fmt=0x3; 536 fmt = 0x3;
535 } else if (std == V4L2_STD_PAL_M) { 537 } else if (state->std == V4L2_STD_PAL_M) {
536 fmt=0x5; 538 pal_m = 1;
537 } else if (std == V4L2_STD_PAL_N) { 539 fmt = 0x5;
538 fmt=0x6; 540 } else if (state->std == V4L2_STD_PAL_N) {
539 } else if (std == V4L2_STD_PAL_Nc) { 541 fmt = 0x6;
540 fmt=0x7; 542 } else if (state->std == V4L2_STD_PAL_Nc) {
541 } else if (std == V4L2_STD_PAL_60) { 543 fmt = 0x7;
542 fmt=0x8; 544 } else if (state->std == V4L2_STD_PAL_60) {
545 fmt = 0x8;
543 } else { 546 } else {
544 /* Then, test against generic ones */ 547 /* Then, test against generic ones */
545 if (std & V4L2_STD_NTSC) { 548 if (state->std & V4L2_STD_NTSC)
546 fmt=0x1; 549 fmt = 0x1;
547 } else if (std & V4L2_STD_PAL) { 550 else if (state->std & V4L2_STD_PAL)
548 fmt=0x4; 551 fmt = 0x4;
549 } else if (std & V4L2_STD_SECAM) { 552 else if (state->std & V4L2_STD_SECAM)
550 fmt=0xc; 553 fmt = 0xc;
551 }
552 } 554 }
553 555
554 v4l_dbg(1, cx25840_debug, client, "changing video std to fmt %i\n",fmt); 556 v4l_dbg(1, cx25840_debug, client, "changing video std to fmt %i\n",fmt);
@@ -563,42 +565,13 @@ static int set_v4lstd(struct i2c_client *client, v4l2_std_id std)
563 cx25840_and_or(client, 0x47b, ~6, 0); 565 cx25840_and_or(client, 0x47b, ~6, 0);
564 } 566 }
565 cx25840_and_or(client, 0x400, ~0xf, fmt); 567 cx25840_and_or(client, 0x400, ~0xf, fmt);
568 cx25840_and_or(client, 0x403, ~0x3, pal_m);
566 cx25840_vbi_setup(client); 569 cx25840_vbi_setup(client);
570 if (!state->is_cx25836)
571 input_change(client);
567 return 0; 572 return 0;
568} 573}
569 574
570v4l2_std_id cx25840_get_v4lstd(struct i2c_client * client)
571{
572 struct cx25840_state *state = i2c_get_clientdata(client);
573 /* check VID_FMT_SEL first */
574 u8 fmt = cx25840_read(client, 0x400) & 0xf;
575
576 if (!fmt) {
577 /* check AFD_FMT_STAT if set to autodetect */
578 fmt = cx25840_read(client, 0x40d) & 0xf;
579 }
580
581 switch (fmt) {
582 case 0x1:
583 {
584 /* if the audio std is A2-M, then this is the South Korean
585 NTSC standard */
586 if (!state->is_cx25836 && cx25840_read(client, 0x805) == 2)
587 return V4L2_STD_NTSC_M_KR;
588 return V4L2_STD_NTSC_M;
589 }
590 case 0x2: return V4L2_STD_NTSC_M_JP;
591 case 0x3: return V4L2_STD_NTSC_443;
592 case 0x4: return V4L2_STD_PAL;
593 case 0x5: return V4L2_STD_PAL_M;
594 case 0x6: return V4L2_STD_PAL_N;
595 case 0x7: return V4L2_STD_PAL_Nc;
596 case 0x8: return V4L2_STD_PAL_60;
597 case 0xc: return V4L2_STD_SECAM;
598 default: return V4L2_STD_UNKNOWN;
599 }
600}
601
602/* ----------------------------------------------------------------------- */ 575/* ----------------------------------------------------------------------- */
603 576
604static int set_v4lctrl(struct i2c_client *client, struct v4l2_control *ctrl) 577static int set_v4lctrl(struct i2c_client *client, struct v4l2_control *ctrl)
@@ -718,9 +691,10 @@ static int get_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt)
718 691
719static int set_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt) 692static int set_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt)
720{ 693{
694 struct cx25840_state *state = i2c_get_clientdata(client);
721 struct v4l2_pix_format *pix; 695 struct v4l2_pix_format *pix;
722 int HSC, VSC, Vsrc, Hsrc, filter, Vlines; 696 int HSC, VSC, Vsrc, Hsrc, filter, Vlines;
723 int is_50Hz = !(cx25840_get_v4lstd(client) & V4L2_STD_525_60); 697 int is_50Hz = !(state->std & V4L2_STD_525_60);
724 698
725 switch (fmt->type) { 699 switch (fmt->type) {
726 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 700 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
@@ -1096,12 +1070,15 @@ static int cx25840_command(struct i2c_client *client, unsigned int cmd,
1096 } 1070 }
1097 1071
1098 case VIDIOC_G_STD: 1072 case VIDIOC_G_STD:
1099 *(v4l2_std_id *)arg = cx25840_get_v4lstd(client); 1073 *(v4l2_std_id *)arg = state->std;
1100 break; 1074 break;
1101 1075
1102 case VIDIOC_S_STD: 1076 case VIDIOC_S_STD:
1077 if (state->radio == 0 && state->std == *(v4l2_std_id *)arg)
1078 return 0;
1103 state->radio = 0; 1079 state->radio = 0;
1104 return set_v4lstd(client, *(v4l2_std_id *)arg); 1080 state->std = *(v4l2_std_id *)arg;
1081 return set_v4lstd(client);
1105 1082
1106 case AUDC_SET_RADIO: 1083 case AUDC_SET_RADIO:
1107 state->radio = 1; 1084 state->radio = 1;
@@ -1291,6 +1268,12 @@ static int cx25840_probe(struct i2c_client *client)
1291 state->id = id; 1268 state->id = id;
1292 state->rev = device_id; 1269 state->rev = device_id;
1293 1270
1271 if (state->is_cx23885) {
1272 /* Drive GPIO2 direction and values */
1273 cx25840_write(client, 0x160, 0x1d);
1274 cx25840_write(client, 0x164, 0x00);
1275 }
1276
1294 return 0; 1277 return 0;
1295} 1278}
1296 1279
diff --git a/drivers/media/video/cx25840/cx25840-core.h b/drivers/media/video/cx25840/cx25840-core.h
index 95093edc9186..8bf797f48b09 100644
--- a/drivers/media/video/cx25840/cx25840-core.h
+++ b/drivers/media/video/cx25840/cx25840-core.h
@@ -38,6 +38,7 @@ struct cx25840_state {
38 struct i2c_client *c; 38 struct i2c_client *c;
39 int pvr150_workaround; 39 int pvr150_workaround;
40 int radio; 40 int radio;
41 v4l2_std_id std;
41 enum cx25840_video_input vid_input; 42 enum cx25840_video_input vid_input;
42 enum cx25840_audio_input aud_input; 43 enum cx25840_audio_input aud_input;
43 u32 audclk_freq; 44 u32 audclk_freq;
@@ -60,7 +61,6 @@ int cx25840_write4(struct i2c_client *client, u16 addr, u32 value);
60u8 cx25840_read(struct i2c_client *client, u16 addr); 61u8 cx25840_read(struct i2c_client *client, u16 addr);
61u32 cx25840_read4(struct i2c_client *client, u16 addr); 62u32 cx25840_read4(struct i2c_client *client, u16 addr);
62int cx25840_and_or(struct i2c_client *client, u16 addr, unsigned mask, u8 value); 63int cx25840_and_or(struct i2c_client *client, u16 addr, unsigned mask, u8 value);
63v4l2_std_id cx25840_get_v4lstd(struct i2c_client *client);
64 64
65/* ----------------------------------------------------------------------- */ 65/* ----------------------------------------------------------------------- */
66/* cx25850-firmware.c */ 66/* cx25850-firmware.c */
diff --git a/drivers/media/video/cx25840/cx25840-firmware.c b/drivers/media/video/cx25840/cx25840-firmware.c
index 1ddf724a2c74..620d295947ab 100644
--- a/drivers/media/video/cx25840/cx25840-firmware.c
+++ b/drivers/media/video/cx25840/cx25840-firmware.c
@@ -79,11 +79,9 @@ static int check_fw_load(struct i2c_client *client, int size)
79 return 0; 79 return 0;
80} 80}
81 81
82static int fw_write(struct i2c_client *client, u8 * data, int size) 82static int fw_write(struct i2c_client *client, u8 *data, int size)
83{ 83{
84 int sent; 84 if (i2c_master_send(client, data, size) < size) {
85
86 if ((sent = i2c_master_send(client, data, size)) < size) {
87 v4l_err(client, "firmware load i2c failure\n"); 85 v4l_err(client, "firmware load i2c failure\n");
88 return -ENOSYS; 86 return -ENOSYS;
89 } 87 }
@@ -96,7 +94,7 @@ int cx25840_loadfw(struct i2c_client *client)
96 struct cx25840_state *state = i2c_get_clientdata(client); 94 struct cx25840_state *state = i2c_get_clientdata(client);
97 const struct firmware *fw = NULL; 95 const struct firmware *fw = NULL;
98 u8 buffer[4], *ptr; 96 u8 buffer[4], *ptr;
99 int size, send, retval; 97 int size, retval;
100 98
101 if (state->is_cx23885) 99 if (state->is_cx23885)
102 firmware = FWFILE_CX23885; 100 firmware = FWFILE_CX23885;
@@ -124,8 +122,7 @@ int cx25840_loadfw(struct i2c_client *client)
124 while (size > 0) { 122 while (size > 0) {
125 ptr[0] = 0x08; 123 ptr[0] = 0x08;
126 ptr[1] = 0x02; 124 ptr[1] = 0x02;
127 send = size > (FWSEND - 2) ? FWSEND : size + 2; 125 retval = fw_write(client, ptr, min(FWSEND, size + 2));
128 retval = fw_write(client, ptr, send);
129 126
130 if (retval < 0) { 127 if (retval < 0) {
131 release_firmware(fw); 128 release_firmware(fw);
diff --git a/drivers/media/video/cx25840/cx25840-vbi.c b/drivers/media/video/cx25840/cx25840-vbi.c
index 6828f59b9d83..c754b9d13369 100644
--- a/drivers/media/video/cx25840/cx25840-vbi.c
+++ b/drivers/media/video/cx25840/cx25840-vbi.c
@@ -85,7 +85,7 @@ static int decode_vps(u8 * dst, u8 * p)
85void cx25840_vbi_setup(struct i2c_client *client) 85void cx25840_vbi_setup(struct i2c_client *client)
86{ 86{
87 struct cx25840_state *state = i2c_get_clientdata(client); 87 struct cx25840_state *state = i2c_get_clientdata(client);
88 v4l2_std_id std = cx25840_get_v4lstd(client); 88 v4l2_std_id std = state->std;
89 int hblank,hactive,burst,vblank,vactive,sc,vblank656,src_decimation; 89 int hblank,hactive,burst,vblank,vactive,sc,vblank656,src_decimation;
90 int luma_lpf,uv_lpf, comb; 90 int luma_lpf,uv_lpf, comb;
91 u32 pll_int,pll_frac,pll_post; 91 u32 pll_int,pll_frac,pll_post;
@@ -242,7 +242,7 @@ int cx25840_vbi(struct i2c_client *client, unsigned int cmd, void *arg)
242 0, 0, V4L2_SLICED_VPS, 0, 0, /* 9 */ 242 0, 0, V4L2_SLICED_VPS, 0, 0, /* 9 */
243 0, 0, 0, 0 243 0, 0, 0, 0
244 }; 244 };
245 int is_pal = !(cx25840_get_v4lstd(client) & V4L2_STD_525_60); 245 int is_pal = !(state->std & V4L2_STD_525_60);
246 int i; 246 int i;
247 247
248 fmt = arg; 248 fmt = arg;
@@ -279,7 +279,7 @@ int cx25840_vbi(struct i2c_client *client, unsigned int cmd, void *arg)
279 279
280 case VIDIOC_S_FMT: 280 case VIDIOC_S_FMT:
281 { 281 {
282 int is_pal = !(cx25840_get_v4lstd(client) & V4L2_STD_525_60); 282 int is_pal = !(state->std & V4L2_STD_525_60);
283 int vbi_offset = is_pal ? 1 : 0; 283 int vbi_offset = is_pal ? 1 : 0;
284 int i, x; 284 int i, x;
285 u8 lcr[24]; 285 u8 lcr[24];
diff --git a/drivers/media/video/cx88/Kconfig b/drivers/media/video/cx88/Kconfig
index 49d3813a9b48..bcf6d9ba063d 100644
--- a/drivers/media/video/cx88/Kconfig
+++ b/drivers/media/video/cx88/Kconfig
@@ -57,6 +57,7 @@ config VIDEO_CX88_DVB
57 select DVB_NXT200X if !DVB_FE_CUSTOMISE 57 select DVB_NXT200X if !DVB_FE_CUSTOMISE
58 select DVB_CX24123 if !DVB_FE_CUSTOMISE 58 select DVB_CX24123 if !DVB_FE_CUSTOMISE
59 select DVB_ISL6421 if !DVB_FE_CUSTOMISE 59 select DVB_ISL6421 if !DVB_FE_CUSTOMISE
60 select TUNER_SIMPLE if !DVB_FE_CUSTOMISE
60 ---help--- 61 ---help---
61 This adds support for DVB/ATSC cards based on the 62 This adds support for DVB/ATSC cards based on the
62 Conexant 2388x chip. 63 Conexant 2388x chip.
diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
index 316b106c3511..e976fc6bef7c 100644
--- a/drivers/media/video/cx88/cx88-alsa.c
+++ b/drivers/media/video/cx88/cx88-alsa.c
@@ -283,7 +283,7 @@ static int dsp_buffer_free(snd_cx88_card_t *chip)
283 BUG_ON(!chip->dma_size); 283 BUG_ON(!chip->dma_size);
284 284
285 dprintk(2,"Freeing buffer\n"); 285 dprintk(2,"Freeing buffer\n");
286 videobuf_pci_dma_unmap(chip->pci, chip->dma_risc); 286 videobuf_sg_dma_unmap(&chip->pci->dev, chip->dma_risc);
287 videobuf_dma_free(chip->dma_risc); 287 videobuf_dma_free(chip->dma_risc);
288 btcx_riscmem_free(chip->pci,&chip->buf->risc); 288 btcx_riscmem_free(chip->pci,&chip->buf->risc);
289 kfree(chip->buf); 289 kfree(chip->buf);
@@ -385,7 +385,7 @@ static int snd_cx88_hw_params(struct snd_pcm_substream * substream,
385 BUG_ON(!chip->dma_size); 385 BUG_ON(!chip->dma_size);
386 BUG_ON(chip->num_periods & (chip->num_periods-1)); 386 BUG_ON(chip->num_periods & (chip->num_periods-1));
387 387
388 buf = videobuf_pci_alloc(sizeof(*buf)); 388 buf = videobuf_sg_alloc(sizeof(*buf));
389 if (NULL == buf) 389 if (NULL == buf)
390 return -ENOMEM; 390 return -ENOMEM;
391 391
@@ -396,14 +396,14 @@ static int snd_cx88_hw_params(struct snd_pcm_substream * substream,
396 buf->vb.height = chip->num_periods; 396 buf->vb.height = chip->num_periods;
397 buf->vb.size = chip->dma_size; 397 buf->vb.size = chip->dma_size;
398 398
399 dma=videobuf_to_dma(&buf->vb); 399 dma = videobuf_to_dma(&buf->vb);
400 videobuf_dma_init(dma); 400 videobuf_dma_init(dma);
401 ret = videobuf_dma_init_kernel(dma, PCI_DMA_FROMDEVICE, 401 ret = videobuf_dma_init_kernel(dma, PCI_DMA_FROMDEVICE,
402 (PAGE_ALIGN(buf->vb.size) >> PAGE_SHIFT)); 402 (PAGE_ALIGN(buf->vb.size) >> PAGE_SHIFT));
403 if (ret < 0) 403 if (ret < 0)
404 goto error; 404 goto error;
405 405
406 ret = videobuf_pci_dma_map(chip->pci,dma); 406 ret = videobuf_sg_dma_map(&chip->pci->dev, dma);
407 if (ret < 0) 407 if (ret < 0)
408 goto error; 408 goto error;
409 409
@@ -494,7 +494,7 @@ static snd_pcm_uframes_t snd_cx88_pointer(struct snd_pcm_substream *substream)
494 494
495 count = atomic_read(&chip->count); 495 count = atomic_read(&chip->count);
496 496
497// dprintk(2, "%s - count %d (+%u), period %d, frame %lu\n", __FUNCTION__, 497// dprintk(2, "%s - count %d (+%u), period %d, frame %lu\n", __func__,
498// count, new, count & (runtime->periods-1), 498// count, new, count & (runtime->periods-1),
499// runtime->period_size * (count & (runtime->periods-1))); 499// runtime->period_size * (count & (runtime->periods-1)));
500 return runtime->period_size * (count & (runtime->periods-1)); 500 return runtime->period_size * (count & (runtime->periods-1));
@@ -690,10 +690,8 @@ MODULE_DEVICE_TABLE(pci, cx88_audio_pci_tbl);
690static int snd_cx88_free(snd_cx88_card_t *chip) 690static int snd_cx88_free(snd_cx88_card_t *chip)
691{ 691{
692 692
693 if (chip->irq >= 0){ 693 if (chip->irq >= 0)
694 synchronize_irq(chip->irq);
695 free_irq(chip->irq, chip); 694 free_irq(chip->irq, chip);
696 }
697 695
698 cx88_core_put(chip->core,chip->pci); 696 cx88_core_put(chip->core,chip->pci);
699 697
diff --git a/drivers/media/video/cx88/cx88-blackbird.c b/drivers/media/video/cx88/cx88-blackbird.c
index a99e9d5950aa..61c4f72644b8 100644
--- a/drivers/media/video/cx88/cx88-blackbird.c
+++ b/drivers/media/video/cx88/cx88-blackbird.c
@@ -45,7 +45,7 @@ static unsigned int mpegbufs = 32;
45module_param(mpegbufs,int,0644); 45module_param(mpegbufs,int,0644);
46MODULE_PARM_DESC(mpegbufs,"number of mpeg buffers, range 2-32"); 46MODULE_PARM_DESC(mpegbufs,"number of mpeg buffers, range 2-32");
47 47
48static unsigned int debug = 0; 48static unsigned int debug;
49module_param(debug,int,0644); 49module_param(debug,int,0644);
50MODULE_PARM_DESC(debug,"enable debug messages [blackbird]"); 50MODULE_PARM_DESC(debug,"enable debug messages [blackbird]");
51 51
@@ -314,7 +314,7 @@ static int blackbird_mbox_func(void *priv, u32 command, int in, int out, u32 dat
314 u32 value, flag, retval; 314 u32 value, flag, retval;
315 int i; 315 int i;
316 316
317 dprintk(1,"%s: 0x%X\n", __FUNCTION__, command); 317 dprintk(1,"%s: 0x%X\n", __func__, command);
318 318
319 /* this may not be 100% safe if we can't read any memory location 319 /* this may not be 100% safe if we can't read any memory location
320 without side effects */ 320 without side effects */
@@ -693,7 +693,7 @@ static int blackbird_queryctrl(struct cx8802_dev *dev, struct v4l2_queryctrl *qc
693 return -EINVAL; 693 return -EINVAL;
694 694
695 /* Standard V4L2 controls */ 695 /* Standard V4L2 controls */
696 if (cx8800_ctrl_query(qctrl) == 0) 696 if (cx8800_ctrl_query(dev->core, qctrl) == 0)
697 return 0; 697 return 0;
698 698
699 /* MPEG V4L2 controls */ 699 /* MPEG V4L2 controls */
@@ -933,7 +933,7 @@ static int vidioc_queryctrl (struct file *file, void *priv,
933 qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id); 933 qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
934 if (unlikely(qctrl->id == 0)) 934 if (unlikely(qctrl->id == 0))
935 return -EINVAL; 935 return -EINVAL;
936 return cx8800_ctrl_query(qctrl); 936 return cx8800_ctrl_query(dev->core, qctrl);
937} 937}
938 938
939static int vidioc_enum_input (struct file *file, void *priv, 939static int vidioc_enum_input (struct file *file, void *priv,
@@ -1055,7 +1055,7 @@ static int mpeg_open(struct inode *inode, struct file *file)
1055 1055
1056 dev = cx8802_get_device(inode); 1056 dev = cx8802_get_device(inode);
1057 1057
1058 dprintk( 1, "%s\n", __FUNCTION__); 1058 dprintk( 1, "%s\n", __func__);
1059 1059
1060 if (dev == NULL) 1060 if (dev == NULL)
1061 return -ENODEV; 1061 return -ENODEV;
@@ -1065,7 +1065,7 @@ static int mpeg_open(struct inode *inode, struct file *file)
1065 if (drv) { 1065 if (drv) {
1066 err = drv->request_acquire(drv); 1066 err = drv->request_acquire(drv);
1067 if(err != 0) { 1067 if(err != 0) {
1068 dprintk(1,"%s: Unable to acquire hardware, %d\n", __FUNCTION__, err); 1068 dprintk(1,"%s: Unable to acquire hardware, %d\n", __func__, err);
1069 return err; 1069 return err;
1070 } 1070 }
1071 } 1071 }
@@ -1087,8 +1087,8 @@ static int mpeg_open(struct inode *inode, struct file *file)
1087 file->private_data = fh; 1087 file->private_data = fh;
1088 fh->dev = dev; 1088 fh->dev = dev;
1089 1089
1090 videobuf_queue_pci_init(&fh->mpegq, &blackbird_qops, 1090 videobuf_queue_sg_init(&fh->mpegq, &blackbird_qops,
1091 dev->pci, &dev->slock, 1091 &dev->pci->dev, &dev->slock,
1092 V4L2_BUF_TYPE_VIDEO_CAPTURE, 1092 V4L2_BUF_TYPE_VIDEO_CAPTURE,
1093 V4L2_FIELD_INTERLACED, 1093 V4L2_FIELD_INTERLACED,
1094 sizeof(struct cx88_buffer), 1094 sizeof(struct cx88_buffer),
@@ -1284,7 +1284,7 @@ static int cx8802_blackbird_probe(struct cx8802_driver *drv)
1284 struct cx8802_dev *dev = core->dvbdev; 1284 struct cx8802_dev *dev = core->dvbdev;
1285 int err; 1285 int err;
1286 1286
1287 dprintk( 1, "%s\n", __FUNCTION__); 1287 dprintk( 1, "%s\n", __func__);
1288 dprintk( 1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n", 1288 dprintk( 1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
1289 core->boardnr, 1289 core->boardnr,
1290 core->name, 1290 core->name,
diff --git a/drivers/media/video/cx88/cx88-cards.c b/drivers/media/video/cx88/cx88-cards.c
index 8c9a8adf52de..620159d05506 100644
--- a/drivers/media/video/cx88/cx88-cards.c
+++ b/drivers/media/video/cx88/cx88-cards.c
@@ -44,6 +44,16 @@ static unsigned int latency = UNSET;
44module_param(latency,int,0444); 44module_param(latency,int,0444);
45MODULE_PARM_DESC(latency,"pci latency timer"); 45MODULE_PARM_DESC(latency,"pci latency timer");
46 46
47#define info_printk(core, fmt, arg...) \
48 printk(KERN_INFO "%s: " fmt, core->name , ## arg)
49
50#define warn_printk(core, fmt, arg...) \
51 printk(KERN_WARNING "%s: " fmt, core->name , ## arg)
52
53#define err_printk(core, fmt, arg...) \
54 printk(KERN_ERR "%s: " fmt, core->name , ## arg)
55
56
47/* ------------------------------------------------------------------ */ 57/* ------------------------------------------------------------------ */
48/* board config info */ 58/* board config info */
49 59
@@ -1354,6 +1364,10 @@ static const struct cx88_board cx88_boards[] = {
1354 }}, 1364 }},
1355 /* fixme: Add radio support */ 1365 /* fixme: Add radio support */
1356 .mpeg = CX88_MPEG_DVB | CX88_MPEG_BLACKBIRD, 1366 .mpeg = CX88_MPEG_DVB | CX88_MPEG_BLACKBIRD,
1367 .radio = {
1368 .type = CX88_RADIO,
1369 .gpio0 = 0xe780,
1370 },
1357 }, 1371 },
1358 [CX88_BOARD_ADSTECH_PTV_390] = { 1372 [CX88_BOARD_ADSTECH_PTV_390] = {
1359 .name = "ADS Tech Instant Video PCI", 1373 .name = "ADS Tech Instant Video PCI",
@@ -1401,6 +1415,245 @@ static const struct cx88_board cx88_boards[] = {
1401 }}, 1415 }},
1402 .mpeg = CX88_MPEG_DVB, 1416 .mpeg = CX88_MPEG_DVB,
1403 }, 1417 },
1418 [CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO] = {
1419 .name = "DViCO FusionHDTV 5 PCI nano",
1420 /* xc3008 tuner, digital only for now */
1421 .tuner_type = TUNER_ABSENT,
1422 .radio_type = UNSET,
1423 .tuner_addr = ADDR_UNSET,
1424 .radio_addr = ADDR_UNSET,
1425 .input = {{
1426 .type = CX88_VMUX_TELEVISION,
1427 .vmux = 0,
1428 .gpio0 = 0x000027df, /* Unconfirmed */
1429 }, {
1430 .type = CX88_VMUX_COMPOSITE1,
1431 .vmux = 1,
1432 .gpio0 = 0x000027df, /* Unconfirmed */
1433 .audioroute = 1,
1434 }, {
1435 .type = CX88_VMUX_SVIDEO,
1436 .vmux = 2,
1437 .gpio0 = 0x000027df, /* Unconfirmed */
1438 .audioroute = 1,
1439 } },
1440 .mpeg = CX88_MPEG_DVB,
1441 },
1442 [CX88_BOARD_PINNACLE_HYBRID_PCTV] = {
1443 .name = "Pinnacle Hybrid PCTV",
1444 .tuner_type = TUNER_XC2028,
1445 .tuner_addr = 0x61,
1446 .input = { {
1447 .type = CX88_VMUX_TELEVISION,
1448 .vmux = 0,
1449 }, {
1450 .type = CX88_VMUX_COMPOSITE1,
1451 .vmux = 1,
1452 }, {
1453 .type = CX88_VMUX_SVIDEO,
1454 .vmux = 2,
1455 } },
1456 .radio = {
1457 .type = CX88_RADIO,
1458 .gpio0 = 0x004ff,
1459 .gpio1 = 0x010ff,
1460 .gpio2 = 0x0ff,
1461 },
1462 },
1463 [CX88_BOARD_WINFAST_TV2000_XP_GLOBAL] = {
1464 .name = "Winfast TV2000 XP Global",
1465 .tuner_type = TUNER_XC2028,
1466 .tuner_addr = 0x61,
1467 .input = { {
1468 .type = CX88_VMUX_TELEVISION,
1469 .vmux = 0,
1470 .gpio0 = 0x0400, /* pin 2:mute = 0 (off?) */
1471 .gpio1 = 0x0000,
1472 .gpio2 = 0x0800, /* pin 19:audio = 0 (tv) */
1473
1474 }, {
1475 .type = CX88_VMUX_COMPOSITE1,
1476 .vmux = 1,
1477 .gpio0 = 0x0400, /* probably? or 0x0404 to turn mute on */
1478 .gpio1 = 0x0000,
1479 .gpio2 = 0x0808, /* pin 19:audio = 1 (line) */
1480
1481 }, {
1482 .type = CX88_VMUX_SVIDEO,
1483 .vmux = 2,
1484 } },
1485 .radio = {
1486 .type = CX88_RADIO,
1487 .gpio0 = 0x004ff,
1488 .gpio1 = 0x010ff,
1489 .gpio2 = 0x0ff,
1490 },
1491 },
1492 [CX88_BOARD_POWERCOLOR_REAL_ANGEL] = {
1493 .name = "PowerColor Real Angel 330",
1494 .tuner_type = TUNER_XC2028,
1495 .tuner_addr = 0x61,
1496 .input = { {
1497 .type = CX88_VMUX_TELEVISION,
1498 .vmux = 0,
1499 .gpio0 = 0x00ff,
1500 .gpio1 = 0xf35d,
1501 .gpio3 = 0x0000,
1502 }, {
1503 .type = CX88_VMUX_COMPOSITE1,
1504 .vmux = 1,
1505 .gpio0 = 0x00ff,
1506 .gpio1 = 0xf37d,
1507 .gpio3 = 0x0000,
1508 }, {
1509 .type = CX88_VMUX_SVIDEO,
1510 .vmux = 2,
1511 .gpio0 = 0x000ff,
1512 .gpio1 = 0x0f37d,
1513 .gpio3 = 0x00000,
1514 } },
1515 .radio = {
1516 .type = CX88_RADIO,
1517 .gpio0 = 0x000ff,
1518 .gpio1 = 0x0f35d,
1519 .gpio3 = 0x00000,
1520 },
1521 },
1522 [CX88_BOARD_GENIATECH_X8000_MT] = {
1523 /* Also PowerColor Real Angel 330 and Geniatech X800 OEM */
1524 .name = "Geniatech X8000-MT DVBT",
1525 .tuner_type = TUNER_XC2028,
1526 .tuner_addr = 0x61,
1527 .input = { {
1528 .type = CX88_VMUX_TELEVISION,
1529 .vmux = 0,
1530 .gpio0 = 0x00000000,
1531 .gpio1 = 0x00e3e341,
1532 .gpio2 = 0x00000000,
1533 .gpio3 = 0x00000000,
1534 }, {
1535 .type = CX88_VMUX_COMPOSITE1,
1536 .vmux = 1,
1537 .gpio0 = 0x00000000,
1538 .gpio1 = 0x00e3e361,
1539 .gpio2 = 0x00000000,
1540 .gpio3 = 0x00000000,
1541 }, {
1542 .type = CX88_VMUX_SVIDEO,
1543 .vmux = 2,
1544 .gpio0 = 0x00000000,
1545 .gpio1 = 0x00e3e361,
1546 .gpio2 = 0x00000000,
1547 .gpio3 = 0x00000000,
1548 } },
1549 .radio = {
1550 .type = CX88_RADIO,
1551 .gpio0 = 0x00000000,
1552 .gpio1 = 0x00e3e341,
1553 .gpio2 = 0x00000000,
1554 .gpio3 = 0x00000000,
1555 },
1556 .mpeg = CX88_MPEG_DVB,
1557 },
1558 [CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PRO] = {
1559 .name = "DViCO FusionHDTV DVB-T PRO",
1560 .tuner_type = TUNER_ABSENT, /* XXX: Has XC3028 */
1561 .radio_type = UNSET,
1562 .tuner_addr = ADDR_UNSET,
1563 .radio_addr = ADDR_UNSET,
1564 .input = { {
1565 .type = CX88_VMUX_COMPOSITE1,
1566 .vmux = 1,
1567 .gpio0 = 0x000067df,
1568 }, {
1569 .type = CX88_VMUX_SVIDEO,
1570 .vmux = 2,
1571 .gpio0 = 0x000067df,
1572 } },
1573 .mpeg = CX88_MPEG_DVB,
1574 },
1575 [CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD] = {
1576 .name = "DViCO FusionHDTV 7 Gold",
1577 .tuner_type = TUNER_XC5000,
1578 .radio_type = UNSET,
1579 .tuner_addr = ADDR_UNSET,
1580 .radio_addr = ADDR_UNSET,
1581 .input = {{
1582 .type = CX88_VMUX_TELEVISION,
1583 .vmux = 0,
1584 .gpio0 = 0x10df,
1585 },{
1586 .type = CX88_VMUX_COMPOSITE1,
1587 .vmux = 1,
1588 .gpio0 = 0x16d9,
1589 },{
1590 .type = CX88_VMUX_SVIDEO,
1591 .vmux = 2,
1592 .gpio0 = 0x16d9,
1593 }},
1594 },
1595 [CX88_BOARD_PROLINK_PV_8000GT] = {
1596 .name = "Prolink Pixelview MPEG 8000GT",
1597 .tuner_type = TUNER_XC2028,
1598 .tuner_addr = 0x61,
1599 .input = { {
1600 .type = CX88_VMUX_TELEVISION,
1601 .vmux = 0,
1602 .gpio0 = 0x0ff,
1603 .gpio2 = 0x0cfb,
1604 }, {
1605 .type = CX88_VMUX_COMPOSITE1,
1606 .vmux = 1,
1607 .gpio2 = 0x0cfb,
1608 }, {
1609 .type = CX88_VMUX_SVIDEO,
1610 .vmux = 2,
1611 .gpio2 = 0x0cfb,
1612 } },
1613 .radio = {
1614 .type = CX88_RADIO,
1615 .gpio2 = 0x0cfb,
1616 },
1617 },
1618 /* Both radio, analog and ATSC work with this board.
1619 However, for analog to work, s5h1409 gate should be open,
1620 otherwise, tuner-xc3028 won't be detected.
1621 A proper fix require using the newer i2c methods to add
1622 tuner-xc3028 without doing an i2c probe.
1623 */
1624 [CX88_BOARD_KWORLD_ATSC_120] = {
1625 .name = "Kworld PlusTV HD PCI 120 (ATSC 120)",
1626 .tuner_type = TUNER_XC2028,
1627 .radio_type = UNSET,
1628 .tuner_addr = ADDR_UNSET,
1629 .radio_addr = ADDR_UNSET,
1630 .input = { {
1631 .type = CX88_VMUX_TELEVISION,
1632 .vmux = 0,
1633 .gpio0 = 0x000000ff,
1634 .gpio1 = 0x0000f35d,
1635 .gpio2 = 0x00000000,
1636 }, {
1637 .type = CX88_VMUX_COMPOSITE1,
1638 .vmux = 1,
1639 .gpio0 = 0x000000ff,
1640 .gpio1 = 0x0000f37e,
1641 .gpio2 = 0x00000000,
1642 }, {
1643 .type = CX88_VMUX_SVIDEO,
1644 .vmux = 2,
1645 .gpio0 = 0x000000ff,
1646 .gpio1 = 0x0000f37e,
1647 .gpio2 = 0x00000000,
1648 } },
1649 .radio = {
1650 .type = CX88_RADIO,
1651 .gpio0 = 0x000000ff,
1652 .gpio1 = 0x0000f35d,
1653 .gpio2 = 0x00000000,
1654 },
1655 .mpeg = CX88_MPEG_DVB,
1656 },
1404}; 1657};
1405 1658
1406/* ------------------------------------------------------------------ */ 1659/* ------------------------------------------------------------------ */
@@ -1605,7 +1858,11 @@ static const struct cx88_subid cx88_subids[] = {
1605 .subdevice = 0xdb11, 1858 .subdevice = 0xdb11,
1606 .card = CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS, 1859 .card = CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS,
1607 /* Re-branded DViCO: UltraView DVB-T Plus */ 1860 /* Re-branded DViCO: UltraView DVB-T Plus */
1608 },{ 1861 }, {
1862 .subvendor = 0x18ac,
1863 .subdevice = 0xdb30,
1864 .card = CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PRO,
1865 }, {
1609 .subvendor = 0x17de, 1866 .subvendor = 0x17de,
1610 .subdevice = 0x0840, 1867 .subdevice = 0x0840,
1611 .card = CX88_BOARD_KWORLD_HARDWARE_MPEG_TV_XPERT, 1868 .card = CX88_BOARD_KWORLD_HARDWARE_MPEG_TV_XPERT,
@@ -1714,6 +1971,38 @@ static const struct cx88_subid cx88_subids[] = {
1714 .subvendor = 0x11bd, 1971 .subvendor = 0x11bd,
1715 .subdevice = 0x0051, 1972 .subdevice = 0x0051,
1716 .card = CX88_BOARD_PINNACLE_PCTV_HD_800i, 1973 .card = CX88_BOARD_PINNACLE_PCTV_HD_800i,
1974 }, {
1975 .subvendor = 0x18ac,
1976 .subdevice = 0xd530,
1977 .card = CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO,
1978 }, {
1979 .subvendor = 0x12ab,
1980 .subdevice = 0x1788,
1981 .card = CX88_BOARD_PINNACLE_HYBRID_PCTV,
1982 }, {
1983 .subvendor = 0x14f1,
1984 .subdevice = 0xea3d,
1985 .card = CX88_BOARD_POWERCOLOR_REAL_ANGEL,
1986 }, {
1987 .subvendor = 0x107d,
1988 .subdevice = 0x6f18,
1989 .card = CX88_BOARD_WINFAST_TV2000_XP_GLOBAL,
1990 }, {
1991 .subvendor = 0x14f1,
1992 .subdevice = 0x8852,
1993 .card = CX88_BOARD_GENIATECH_X8000_MT,
1994 }, {
1995 .subvendor = 0x18ac,
1996 .subdevice = 0xd610,
1997 .card = CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD,
1998 }, {
1999 .subvendor = 0x1554,
2000 .subdevice = 0x4935,
2001 .card = CX88_BOARD_PROLINK_PV_8000GT,
2002 }, {
2003 .subvendor = 0x17de,
2004 .subdevice = 0x08c1,
2005 .card = CX88_BOARD_KWORLD_ATSC_120,
1717 }, 2006 },
1718}; 2007};
1719 2008
@@ -1731,17 +2020,16 @@ static void leadtek_eeprom(struct cx88_core *core, u8 *eeprom_data)
1731 if (eeprom_data[4] != 0x7d || 2020 if (eeprom_data[4] != 0x7d ||
1732 eeprom_data[5] != 0x10 || 2021 eeprom_data[5] != 0x10 ||
1733 eeprom_data[7] != 0x66) { 2022 eeprom_data[7] != 0x66) {
1734 printk(KERN_WARNING "%s: Leadtek eeprom invalid.\n", 2023 warn_printk(core, "Leadtek eeprom invalid.\n");
1735 core->name);
1736 return; 2024 return;
1737 } 2025 }
1738 2026
1739 core->board.tuner_type = (eeprom_data[6] == 0x13) ? 2027 core->board.tuner_type = (eeprom_data[6] == 0x13) ?
1740 TUNER_PHILIPS_FM1236_MK3 : TUNER_PHILIPS_FM1216ME_MK3; 2028 TUNER_PHILIPS_FM1236_MK3 : TUNER_PHILIPS_FM1216ME_MK3;
1741 2029
1742 printk(KERN_INFO "%s: Leadtek Winfast 2000XP Expert config: " 2030 info_printk(core, "Leadtek Winfast 2000XP Expert config: "
1743 "tuner=%d, eeprom[0]=0x%02x\n", 2031 "tuner=%d, eeprom[0]=0x%02x\n",
1744 core->name, core->board.tuner_type, eeprom_data[0]); 2032 core->board.tuner_type, eeprom_data[0]);
1745} 2033}
1746 2034
1747static void hauppauge_eeprom(struct cx88_core *core, u8 *eeprom_data) 2035static void hauppauge_eeprom(struct cx88_core *core, u8 *eeprom_data)
@@ -1785,13 +2073,12 @@ static void hauppauge_eeprom(struct cx88_core *core, u8 *eeprom_data)
1785 /* known */ 2073 /* known */
1786 break; 2074 break;
1787 default: 2075 default:
1788 printk("%s: warning: unknown hauppauge model #%d\n", 2076 warn_printk(core, "warning: unknown hauppauge model #%d\n",
1789 core->name, tv.model); 2077 tv.model);
1790 break; 2078 break;
1791 } 2079 }
1792 2080
1793 printk(KERN_INFO "%s: hauppauge eeprom: model=%d\n", 2081 info_printk(core, "hauppauge eeprom: model=%d\n", tv.model);
1794 core->name, tv.model);
1795} 2082}
1796 2083
1797/* ----------------------------------------------------------------------- */ 2084/* ----------------------------------------------------------------------- */
@@ -1837,8 +2124,7 @@ static void gdi_eeprom(struct cx88_core *core, u8 *eeprom_data)
1837 char *name = (eeprom_data[0x0d] < ARRAY_SIZE(gdi_tuner)) 2124 char *name = (eeprom_data[0x0d] < ARRAY_SIZE(gdi_tuner))
1838 ? gdi_tuner[eeprom_data[0x0d]].name : NULL; 2125 ? gdi_tuner[eeprom_data[0x0d]].name : NULL;
1839 2126
1840 printk(KERN_INFO "%s: GDI: tuner=%s\n", core->name, 2127 info_printk(core, "GDI: tuner=%s\n", name ? name : "unknown");
1841 name ? name : "unknown");
1842 if (NULL == name) 2128 if (NULL == name)
1843 return; 2129 return;
1844 core->board.tuner_type = gdi_tuner[eeprom_data[0x0d]].id; 2130 core->board.tuner_type = gdi_tuner[eeprom_data[0x0d]].id;
@@ -1846,6 +2132,75 @@ static void gdi_eeprom(struct cx88_core *core, u8 *eeprom_data)
1846 CX88_RADIO : 0; 2132 CX88_RADIO : 0;
1847} 2133}
1848 2134
2135/* ------------------------------------------------------------------- */
2136/* some Divco specific stuff */
2137static int cx88_dvico_xc2028_callback(struct cx88_core *core,
2138 int command, int arg)
2139{
2140 switch (command) {
2141 case XC2028_TUNER_RESET:
2142 cx_write(MO_GP0_IO, 0x101000);
2143 mdelay(5);
2144 cx_set(MO_GP0_IO, 0x101010);
2145 break;
2146 default:
2147 return -EINVAL;
2148 }
2149
2150 return 0;
2151}
2152
2153
2154/* ----------------------------------------------------------------------- */
2155/* some Geniatech specific stuff */
2156
2157static int cx88_xc3028_geniatech_tuner_callback(struct cx88_core *core,
2158 int command, int mode)
2159{
2160 switch (command) {
2161 case XC2028_TUNER_RESET:
2162 switch (INPUT(core->input).type) {
2163 case CX88_RADIO:
2164 break;
2165 case CX88_VMUX_DVB:
2166 cx_write(MO_GP1_IO, 0x030302);
2167 mdelay(50);
2168 break;
2169 default:
2170 cx_write(MO_GP1_IO, 0x030301);
2171 mdelay(50);
2172 }
2173 cx_write(MO_GP1_IO, 0x101010);
2174 mdelay(50);
2175 cx_write(MO_GP1_IO, 0x101000);
2176 mdelay(50);
2177 cx_write(MO_GP1_IO, 0x101010);
2178 mdelay(50);
2179 return 0;
2180 }
2181 return -EINVAL;
2182}
2183
2184/* ------------------------------------------------------------------- */
2185/* some Divco specific stuff */
2186static int cx88_pv_8000gt_callback(struct cx88_core *core,
2187 int command, int arg)
2188{
2189 switch (command) {
2190 case XC2028_TUNER_RESET:
2191 cx_write(MO_GP2_IO, 0xcf7);
2192 mdelay(50);
2193 cx_write(MO_GP2_IO, 0xef5);
2194 mdelay(50);
2195 cx_write(MO_GP2_IO, 0xcf7);
2196 break;
2197 default:
2198 return -EINVAL;
2199 }
2200
2201 return 0;
2202}
2203
1849/* ----------------------------------------------------------------------- */ 2204/* ----------------------------------------------------------------------- */
1850/* some DViCO specific stuff */ 2205/* some DViCO specific stuff */
1851 2206
@@ -1874,32 +2229,85 @@ static void dvico_fusionhdtv_hybrid_init(struct cx88_core *core)
1874 msg.len = (i != 12 ? 5 : 2); 2229 msg.len = (i != 12 ? 5 : 2);
1875 err = i2c_transfer(&core->i2c_adap, &msg, 1); 2230 err = i2c_transfer(&core->i2c_adap, &msg, 1);
1876 if (err != 1) { 2231 if (err != 1) {
1877 printk("dvico_fusionhdtv_hybrid_init buf %d failed (err = %d)!\n", i, err); 2232 warn_printk(core, "dvico_fusionhdtv_hybrid_init buf %d "
2233 "failed (err = %d)!\n", i, err);
1878 return; 2234 return;
1879 } 2235 }
1880 } 2236 }
1881} 2237}
1882 2238
2239static int cx88_xc2028_tuner_callback(struct cx88_core *core,
2240 int command, int arg)
2241{
2242 /* Board-specific callbacks */
2243 switch (core->boardnr) {
2244 case CX88_BOARD_WINFAST_TV2000_XP_GLOBAL:
2245 case CX88_BOARD_POWERCOLOR_REAL_ANGEL:
2246 case CX88_BOARD_GENIATECH_X8000_MT:
2247 case CX88_BOARD_KWORLD_ATSC_120:
2248 return cx88_xc3028_geniatech_tuner_callback(core,
2249 command, arg);
2250 case CX88_BOARD_PROLINK_PV_8000GT:
2251 return cx88_pv_8000gt_callback(core, command, arg);
2252 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PRO:
2253 return cx88_dvico_xc2028_callback(core, command, arg);
2254 }
2255
2256 switch (command) {
2257 case XC2028_TUNER_RESET:
2258 switch (INPUT(core->input).type) {
2259 case CX88_RADIO:
2260 info_printk(core, "setting GPIO to radio!\n");
2261 cx_write(MO_GP0_IO, 0x4ff);
2262 mdelay(250);
2263 cx_write(MO_GP2_IO, 0xff);
2264 mdelay(250);
2265 break;
2266 case CX88_VMUX_DVB: /* Digital TV*/
2267 default: /* Analog TV */
2268 info_printk(core, "setting GPIO to TV!\n");
2269 break;
2270 }
2271 cx_write(MO_GP1_IO, 0x101010);
2272 mdelay(250);
2273 cx_write(MO_GP1_IO, 0x101000);
2274 mdelay(250);
2275 cx_write(MO_GP1_IO, 0x101010);
2276 mdelay(250);
2277 return 0;
2278 }
2279 return -EINVAL;
2280}
2281
1883/* ----------------------------------------------------------------------- */ 2282/* ----------------------------------------------------------------------- */
1884/* Tuner callback function. Currently only needed for the Pinnacle * 2283/* Tuner callback function. Currently only needed for the Pinnacle *
1885 * PCTV HD 800i with an xc5000 sillicon tuner. This is used for both * 2284 * PCTV HD 800i with an xc5000 sillicon tuner. This is used for both *
1886 * analog tuner attach (tuner-core.c) and dvb tuner attach (cx88-dvb.c) */ 2285 * analog tuner attach (tuner-core.c) and dvb tuner attach (cx88-dvb.c) */
1887 2286
1888int cx88_tuner_callback(void *priv, int command, int arg) 2287static int cx88_xc5000_tuner_callback(struct cx88_core *core,
2288 int command, int arg)
1889{ 2289{
1890 struct i2c_algo_bit_data *i2c_algo = priv; 2290 switch (core->boardnr) {
1891 struct cx88_core *core = i2c_algo->data;
1892
1893 switch(core->boardnr) {
1894 case CX88_BOARD_PINNACLE_PCTV_HD_800i: 2291 case CX88_BOARD_PINNACLE_PCTV_HD_800i:
1895 if(command == 0) { /* This is the reset command from xc5000 */ 2292 if (command == 0) { /* This is the reset command from xc5000 */
1896 /* Reset XC5000 tuner via SYS_RSTO_pin */ 2293 /* Reset XC5000 tuner via SYS_RSTO_pin */
1897 cx_write(MO_SRST_IO, 0); 2294 cx_write(MO_SRST_IO, 0);
1898 msleep(10); 2295 msleep(10);
1899 cx_write(MO_SRST_IO, 1); 2296 cx_write(MO_SRST_IO, 1);
1900 return 0; 2297 return 0;
2298 } else {
2299 err_printk(core, "xc5000: unknown tuner "
2300 "callback command.\n");
2301 return -EINVAL;
1901 } 2302 }
1902 else { 2303 break;
2304 case CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD:
2305 if (command == 0) { /* This is the reset command from xc5000 */
2306 cx_clear(MO_GP0_IO, 0x00000010);
2307 msleep(10);
2308 cx_set(MO_GP0_IO, 0x00000010);
2309 return 0;
2310 } else {
1903 printk(KERN_ERR 2311 printk(KERN_ERR
1904 "xc5000: unknown tuner callback command.\n"); 2312 "xc5000: unknown tuner callback command.\n");
1905 return -EINVAL; 2313 return -EINVAL;
@@ -1908,6 +2316,36 @@ int cx88_tuner_callback(void *priv, int command, int arg)
1908 } 2316 }
1909 return 0; /* Should never be here */ 2317 return 0; /* Should never be here */
1910} 2318}
2319
2320int cx88_tuner_callback(void *priv, int command, int arg)
2321{
2322 struct i2c_algo_bit_data *i2c_algo = priv;
2323 struct cx88_core *core;
2324
2325 if (!i2c_algo) {
2326 printk(KERN_ERR "cx88: Error - i2c private data undefined.\n");
2327 return -EINVAL;
2328 }
2329
2330 core = i2c_algo->data;
2331
2332 if (!core) {
2333 printk(KERN_ERR "cx88: Error - device struct undefined.\n");
2334 return -EINVAL;
2335 }
2336
2337 switch (core->board.tuner_type) {
2338 case TUNER_XC2028:
2339 info_printk(core, "Calling XC2028/3028 callback\n");
2340 return cx88_xc2028_tuner_callback(core, command, arg);
2341 case TUNER_XC5000:
2342 info_printk(core, "Calling XC5000 callback\n");
2343 return cx88_xc5000_tuner_callback(core, command, arg);
2344 }
2345 err_printk(core, "Error: Calling callback for tuner %d\n",
2346 core->board.tuner_type);
2347 return -EINVAL;
2348}
1911EXPORT_SYMBOL(cx88_tuner_callback); 2349EXPORT_SYMBOL(cx88_tuner_callback);
1912 2350
1913/* ----------------------------------------------------------------------- */ 2351/* ----------------------------------------------------------------------- */
@@ -1918,23 +2356,25 @@ static void cx88_card_list(struct cx88_core *core, struct pci_dev *pci)
1918 2356
1919 if (0 == pci->subsystem_vendor && 2357 if (0 == pci->subsystem_vendor &&
1920 0 == pci->subsystem_device) { 2358 0 == pci->subsystem_device) {
1921 printk("%s: Your board has no valid PCI Subsystem ID and thus can't\n" 2359 printk(KERN_ERR
2360 "%s: Your board has no valid PCI Subsystem ID and thus can't\n"
1922 "%s: be autodetected. Please pass card=<n> insmod option to\n" 2361 "%s: be autodetected. Please pass card=<n> insmod option to\n"
1923 "%s: workaround that. Redirect complaints to the vendor of\n" 2362 "%s: workaround that. Redirect complaints to the vendor of\n"
1924 "%s: the TV card. Best regards,\n" 2363 "%s: the TV card. Best regards,\n"
1925 "%s: -- tux\n", 2364 "%s: -- tux\n",
1926 core->name,core->name,core->name,core->name,core->name); 2365 core->name,core->name,core->name,core->name,core->name);
1927 } else { 2366 } else {
1928 printk("%s: Your board isn't known (yet) to the driver. You can\n" 2367 printk(KERN_ERR
2368 "%s: Your board isn't known (yet) to the driver. You can\n"
1929 "%s: try to pick one of the existing card configs via\n" 2369 "%s: try to pick one of the existing card configs via\n"
1930 "%s: card=<n> insmod option. Updating to the latest\n" 2370 "%s: card=<n> insmod option. Updating to the latest\n"
1931 "%s: version might help as well.\n", 2371 "%s: version might help as well.\n",
1932 core->name,core->name,core->name,core->name); 2372 core->name,core->name,core->name,core->name);
1933 } 2373 }
1934 printk("%s: Here is a list of valid choices for the card=<n> insmod option:\n", 2374 err_printk(core, "Here is a list of valid choices for the card=<n> "
1935 core->name); 2375 "insmod option:\n");
1936 for (i = 0; i < ARRAY_SIZE(cx88_boards); i++) 2376 for (i = 0; i < ARRAY_SIZE(cx88_boards); i++)
1937 printk("%s: card=%d -> %s\n", 2377 printk(KERN_ERR "%s: card=%d -> %s\n",
1938 core->name, i, cx88_boards[i].name); 2378 core->name, i, cx88_boards[i].name);
1939} 2379}
1940 2380
@@ -1951,9 +2391,57 @@ static void cx88_card_setup_pre_i2c(struct cx88_core *core)
1951 cx_set(MO_GP0_IO, 0x00000080); /* 702 out of reset */ 2391 cx_set(MO_GP0_IO, 0x00000080); /* 702 out of reset */
1952 udelay(1000); 2392 udelay(1000);
1953 break; 2393 break;
2394
2395 case CX88_BOARD_PROLINK_PV_8000GT:
2396 cx_write(MO_GP2_IO, 0xcf7);
2397 mdelay(50);
2398 cx_write(MO_GP2_IO, 0xef5);
2399 mdelay(50);
2400 cx_write(MO_GP2_IO, 0xcf7);
2401 msleep(10);
2402 break;
2403
2404 case CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD:
2405 /* Enable the xc5000 tuner */
2406 cx_set(MO_GP0_IO, 0x00001010);
2407 break;
1954 } 2408 }
1955} 2409}
1956 2410
2411/*
2412 * Sets board-dependent xc3028 configuration
2413 */
2414void cx88_setup_xc3028(struct cx88_core *core, struct xc2028_ctrl *ctl)
2415{
2416 memset(ctl, 0, sizeof(*ctl));
2417
2418 ctl->fname = XC2028_DEFAULT_FIRMWARE;
2419 ctl->max_len = 64;
2420
2421 switch (core->boardnr) {
2422 case CX88_BOARD_POWERCOLOR_REAL_ANGEL:
2423 /* Doesn't work with firmware version 2.7 */
2424 ctl->fname = "xc3028-v25.fw";
2425 break;
2426 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PRO:
2427 ctl->scode_table = XC3028_FE_ZARLINK456;
2428 break;
2429 case CX88_BOARD_KWORLD_ATSC_120:
2430 case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO:
2431 ctl->demod = XC3028_FE_OREN538;
2432 break;
2433 case CX88_BOARD_PROLINK_PV_8000GT:
2434 /*
2435 * This board uses non-MTS firmware
2436 */
2437 break;
2438 default:
2439 ctl->demod = XC3028_FE_OREN538;
2440 ctl->mts = 1;
2441 }
2442}
2443EXPORT_SYMBOL_GPL(cx88_setup_xc3028);
2444
1957static void cx88_card_setup(struct cx88_core *core) 2445static void cx88_card_setup(struct cx88_core *core)
1958{ 2446{
1959 static u8 eeprom[256]; 2447 static u8 eeprom[256];
@@ -1991,6 +2479,13 @@ static void cx88_card_setup(struct cx88_core *core)
1991 cx_write(MO_GP0_IO, 0x000007f8); 2479 cx_write(MO_GP0_IO, 0x000007f8);
1992 cx_write(MO_GP1_IO, 0x00000001); 2480 cx_write(MO_GP1_IO, 0x00000001);
1993 break; 2481 break;
2482 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PRO:
2483 /* GPIO0:0 is hooked to demod reset */
2484 /* GPIO0:4 is hooked to xc3028 reset */
2485 cx_write(MO_GP0_IO, 0x00111100);
2486 msleep(1);
2487 cx_write(MO_GP0_IO, 0x00111111);
2488 break;
1994 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL: 2489 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL:
1995 /* GPIO0:6 is hooked to FX2 reset pin */ 2490 /* GPIO0:6 is hooked to FX2 reset pin */
1996 cx_set(MO_GP0_IO, 0x00004040); 2491 cx_set(MO_GP0_IO, 0x00004040);
@@ -2038,10 +2533,8 @@ static void cx88_card_setup(struct cx88_core *core)
2038 for (i = 0; i < ARRAY_SIZE(buffer); i++) 2533 for (i = 0; i < ARRAY_SIZE(buffer); i++)
2039 if (2 != i2c_master_send(&core->i2c_client, 2534 if (2 != i2c_master_send(&core->i2c_client,
2040 buffer[i],2)) 2535 buffer[i],2))
2041 printk(KERN_WARNING 2536 warn_printk(core, "Unable to enable "
2042 "%s: Unable to enable " 2537 "tuner(%i).\n", i);
2043 "tuner(%i).\n",
2044 core->name, i);
2045 } 2538 }
2046 break; 2539 break;
2047 case CX88_BOARD_MSI_TVANYWHERE_MASTER: 2540 case CX88_BOARD_MSI_TVANYWHERE_MASTER:
@@ -2062,6 +2555,22 @@ static void cx88_card_setup(struct cx88_core *core)
2062 cx88_call_i2c_clients(core, TUNER_SET_CONFIG, &tea5767_cfg); 2555 cx88_call_i2c_clients(core, TUNER_SET_CONFIG, &tea5767_cfg);
2063 } 2556 }
2064 } 2557 }
2558
2559 if (core->board.tuner_type == TUNER_XC2028) {
2560 struct v4l2_priv_tun_config xc2028_cfg;
2561 struct xc2028_ctrl ctl;
2562
2563 /* Fills device-dependent initialization parameters */
2564 cx88_setup_xc3028(core, &ctl);
2565
2566 /* Sends parameters to xc2028/3028 tuner */
2567 memset(&xc2028_cfg, 0, sizeof(xc2028_cfg));
2568 xc2028_cfg.tuner = TUNER_XC2028;
2569 xc2028_cfg.priv = &ctl;
2570 info_printk(core, "Asking xc2028/3028 to load firmware %s\n",
2571 ctl.fname);
2572 cx88_call_i2c_clients(core, TUNER_SET_CONFIG, &xc2028_cfg);
2573 }
2065} 2574}
2066 2575
2067/* ------------------------------------------------------------------ */ 2576/* ------------------------------------------------------------------ */
@@ -2178,9 +2687,8 @@ struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr)
2178 2687
2179 memcpy(&core->board, &cx88_boards[core->boardnr], sizeof(core->board)); 2688 memcpy(&core->board, &cx88_boards[core->boardnr], sizeof(core->board));
2180 2689
2181 printk(KERN_INFO "%s: subsystem: %04x:%04x, board: %s [card=%d,%s]\n", 2690 info_printk(core, "subsystem: %04x:%04x, board: %s [card=%d,%s]\n",
2182 core->name,pci->subsystem_vendor, 2691 pci->subsystem_vendor, pci->subsystem_device, core->board.name,
2183 pci->subsystem_device, core->board.name,
2184 core->boardnr, card[core->nr] == core->boardnr ? 2692 core->boardnr, card[core->nr] == core->boardnr ?
2185 "insmod option" : "autodetected"); 2693 "insmod option" : "autodetected");
2186 2694
@@ -2189,8 +2697,8 @@ struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr)
2189 if (radio[core->nr] != UNSET) 2697 if (radio[core->nr] != UNSET)
2190 core->board.radio_type = radio[core->nr]; 2698 core->board.radio_type = radio[core->nr];
2191 2699
2192 printk(KERN_INFO "%s: TV tuner type %d, Radio tuner type %d\n", 2700 info_printk(core, "TV tuner type %d, Radio tuner type %d\n",
2193 core->name, core->board.tuner_type, core->board.radio_type); 2701 core->board.tuner_type, core->board.radio_type);
2194 2702
2195 /* init hardware */ 2703 /* init hardware */
2196 cx88_reset(core); 2704 cx88_reset(core);
@@ -2207,12 +2715,3 @@ struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr)
2207 2715
2208 return core; 2716 return core;
2209} 2717}
2210
2211/* ------------------------------------------------------------------ */
2212
2213/*
2214 * Local variables:
2215 * c-basic-offset: 8
2216 * End:
2217 * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off
2218 */
diff --git a/drivers/media/video/cx88/cx88-core.c b/drivers/media/video/cx88/cx88-core.c
index 01e2ac98970b..c4d1aff1fdb4 100644
--- a/drivers/media/video/cx88/cx88-core.c
+++ b/drivers/media/video/cx88/cx88-core.c
@@ -47,15 +47,15 @@ MODULE_LICENSE("GPL");
47 47
48/* ------------------------------------------------------------------ */ 48/* ------------------------------------------------------------------ */
49 49
50static unsigned int core_debug = 0; 50static unsigned int core_debug;
51module_param(core_debug,int,0644); 51module_param(core_debug,int,0644);
52MODULE_PARM_DESC(core_debug,"enable debug messages [core]"); 52MODULE_PARM_DESC(core_debug,"enable debug messages [core]");
53 53
54static unsigned int nicam = 0; 54static unsigned int nicam;
55module_param(nicam,int,0644); 55module_param(nicam,int,0644);
56MODULE_PARM_DESC(nicam,"tv audio is nicam"); 56MODULE_PARM_DESC(nicam,"tv audio is nicam");
57 57
58static unsigned int nocomb = 0; 58static unsigned int nocomb;
59module_param(nocomb,int,0644); 59module_param(nocomb,int,0644);
60MODULE_PARM_DESC(nocomb,"disable comb filter"); 60MODULE_PARM_DESC(nocomb,"disable comb filter");
61 61
@@ -219,7 +219,7 @@ cx88_free_buffer(struct videobuf_queue *q, struct cx88_buffer *buf)
219 videobuf_waiton(&buf->vb,0,0); 219 videobuf_waiton(&buf->vb,0,0);
220 videobuf_dma_unmap(q, dma); 220 videobuf_dma_unmap(q, dma);
221 videobuf_dma_free(dma); 221 videobuf_dma_free(dma);
222 btcx_riscmem_free((struct pci_dev *)q->dev, &buf->risc); 222 btcx_riscmem_free(to_pci_dev(q->dev), &buf->risc);
223 buf->vb.state = VIDEOBUF_NEEDS_INIT; 223 buf->vb.state = VIDEOBUF_NEEDS_INIT;
224} 224}
225 225
@@ -548,7 +548,7 @@ void cx88_wakeup(struct cx88_core *core,
548 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT); 548 mod_timer(&q->timeout, jiffies+BUFFER_TIMEOUT);
549 } 549 }
550 if (bc != 1) 550 if (bc != 1)
551 printk("%s: %d buffers handled (should be 1)\n",__FUNCTION__,bc); 551 printk("%s: %d buffers handled (should be 1)\n",__func__,bc);
552} 552}
553 553
554void cx88_shutdown(struct cx88_core *core) 554void cx88_shutdown(struct cx88_core *core)
@@ -577,7 +577,7 @@ void cx88_shutdown(struct cx88_core *core)
577 577
578int cx88_reset(struct cx88_core *core) 578int cx88_reset(struct cx88_core *core)
579{ 579{
580 dprintk(1,"%s\n",__FUNCTION__); 580 dprintk(1,"%s\n",__func__);
581 cx88_shutdown(core); 581 cx88_shutdown(core);
582 582
583 /* clear irq status */ 583 /* clear irq status */
@@ -929,7 +929,10 @@ int cx88_set_tvnorm(struct cx88_core *core, v4l2_std_id norm)
929 929
930 dprintk(1,"set_tvnorm: MO_INPUT_FORMAT 0x%08x [old=0x%08x]\n", 930 dprintk(1,"set_tvnorm: MO_INPUT_FORMAT 0x%08x [old=0x%08x]\n",
931 cxiformat, cx_read(MO_INPUT_FORMAT) & 0x0f); 931 cxiformat, cx_read(MO_INPUT_FORMAT) & 0x0f);
932 cx_andor(MO_INPUT_FORMAT, 0xf, cxiformat); 932 /* Chroma AGC must be disabled if SECAM is used, we enable it
933 by default on PAL and NTSC */
934 cx_andor(MO_INPUT_FORMAT, 0x40f,
935 norm & V4L2_STD_SECAM ? cxiformat : cxiformat | 0x400);
933 936
934 // FIXME: as-is from DScaler 937 // FIXME: as-is from DScaler
935 dprintk(1,"set_tvnorm: MO_OUTPUT_FORMAT 0x%08x [old=0x%08x]\n", 938 dprintk(1,"set_tvnorm: MO_OUTPUT_FORMAT 0x%08x [old=0x%08x]\n",
diff --git a/drivers/media/video/cx88/cx88-dvb.c b/drivers/media/video/cx88/cx88-dvb.c
index f7b41eb1bb5a..f1251b844e08 100644
--- a/drivers/media/video/cx88/cx88-dvb.c
+++ b/drivers/media/video/cx88/cx88-dvb.c
@@ -45,16 +45,20 @@
45#include "nxt200x.h" 45#include "nxt200x.h"
46#include "cx24123.h" 46#include "cx24123.h"
47#include "isl6421.h" 47#include "isl6421.h"
48#include "tuner-simple.h"
49#include "tda9887.h"
48 50
49MODULE_DESCRIPTION("driver for cx2388x based DVB cards"); 51MODULE_DESCRIPTION("driver for cx2388x based DVB cards");
50MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>"); 52MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
51MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]"); 53MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
52MODULE_LICENSE("GPL"); 54MODULE_LICENSE("GPL");
53 55
54static unsigned int debug = 0; 56static unsigned int debug;
55module_param(debug, int, 0644); 57module_param(debug, int, 0644);
56MODULE_PARM_DESC(debug,"enable debug messages [dvb]"); 58MODULE_PARM_DESC(debug,"enable debug messages [dvb]");
57 59
60DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
61
58#define dprintk(level,fmt, arg...) if (debug >= level) \ 62#define dprintk(level,fmt, arg...) if (debug >= level) \
59 printk(KERN_DEBUG "%s/2-dvb: " fmt, core->name, ## arg) 63 printk(KERN_DEBUG "%s/2-dvb: " fmt, core->name, ## arg)
60 64
@@ -235,6 +239,19 @@ static struct zl10353_config dvico_fusionhdtv_hybrid = {
235 .no_tuner = 1, 239 .no_tuner = 1,
236}; 240};
237 241
242static struct zl10353_config dvico_fusionhdtv_xc3028 = {
243 .demod_address = 0x0f,
244 .if2 = 45600,
245 .no_tuner = 1,
246};
247
248static struct mt352_config dvico_fusionhdtv_mt352_xc3028 = {
249 .demod_address = 0x0f,
250 .if2 = 4560,
251 .no_tuner = 1,
252 .demod_init = dvico_fusionhdtv_demod_init,
253};
254
238static struct zl10353_config dvico_fusionhdtv_plus_v1_1 = { 255static struct zl10353_config dvico_fusionhdtv_plus_v1_1 = {
239 .demod_address = 0x0f, 256 .demod_address = 0x0f,
240}; 257};
@@ -266,7 +283,7 @@ static int lgdt330x_pll_rf_set(struct dvb_frontend* fe, int index)
266 struct cx8802_dev *dev= fe->dvb->priv; 283 struct cx8802_dev *dev= fe->dvb->priv;
267 struct cx88_core *core = dev->core; 284 struct cx88_core *core = dev->core;
268 285
269 dprintk(1, "%s: index = %d\n", __FUNCTION__, index); 286 dprintk(1, "%s: index = %d\n", __func__, index);
270 if (index == 0) 287 if (index == 0)
271 cx_clear(MO_GP0_IO, 8); 288 cx_clear(MO_GP0_IO, 8);
272 else 289 else
@@ -357,6 +374,40 @@ static int geniatech_dvbs_set_voltage(struct dvb_frontend *fe,
357 return 0; 374 return 0;
358} 375}
359 376
377static int cx88_pci_nano_callback(void *ptr, int command, int arg)
378{
379 struct cx88_core *core = ptr;
380
381 switch (command) {
382 case XC2028_TUNER_RESET:
383 /* Send the tuner in then out of reset */
384 dprintk(1, "%s: XC2028_TUNER_RESET %d\n", __func__, arg);
385
386 switch (core->boardnr) {
387 case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO:
388 /* GPIO-4 xc3028 tuner */
389
390 cx_set(MO_GP0_IO, 0x00001000);
391 cx_clear(MO_GP0_IO, 0x00000010);
392 msleep(100);
393 cx_set(MO_GP0_IO, 0x00000010);
394 msleep(100);
395 break;
396 }
397
398 break;
399 case XC2028_RESET_CLK:
400 dprintk(1, "%s: XC2028_RESET_CLK %d\n", __func__, arg);
401 break;
402 default:
403 dprintk(1, "%s: unknown command %d, arg %d\n", __func__,
404 command, arg);
405 return -EINVAL;
406 }
407
408 return 0;
409}
410
360static struct cx24123_config geniatech_dvbs_config = { 411static struct cx24123_config geniatech_dvbs_config = {
361 .demod_address = 0x55, 412 .demod_address = 0x55,
362 .set_ts_params = cx24123_set_ts_param, 413 .set_ts_params = cx24123_set_ts_param,
@@ -383,12 +434,76 @@ static struct s5h1409_config pinnacle_pctv_hd_800i_config = {
383 .mpeg_timing = S5H1409_MPEGTIMING_NONCONTINOUS_NONINVERTING_CLOCK, 434 .mpeg_timing = S5H1409_MPEGTIMING_NONCONTINOUS_NONINVERTING_CLOCK,
384}; 435};
385 436
437static struct s5h1409_config dvico_hdtv5_pci_nano_config = {
438 .demod_address = 0x32 >> 1,
439 .output_mode = S5H1409_SERIAL_OUTPUT,
440 .gpio = S5H1409_GPIO_OFF,
441 .inversion = S5H1409_INVERSION_OFF,
442 .status_mode = S5H1409_DEMODLOCKING,
443 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
444};
445
446static struct s5h1409_config kworld_atsc_120_config = {
447 .demod_address = 0x32 >> 1,
448 .output_mode = S5H1409_SERIAL_OUTPUT,
449 .gpio = S5H1409_GPIO_OFF,
450 .inversion = S5H1409_INVERSION_OFF,
451 .status_mode = S5H1409_DEMODLOCKING,
452 .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK,
453};
454
386static struct xc5000_config pinnacle_pctv_hd_800i_tuner_config = { 455static struct xc5000_config pinnacle_pctv_hd_800i_tuner_config = {
387 .i2c_address = 0x64, 456 .i2c_address = 0x64,
388 .if_khz = 5380, 457 .if_khz = 5380,
389 .tuner_callback = cx88_tuner_callback, 458 .tuner_callback = cx88_tuner_callback,
390}; 459};
391 460
461static struct zl10353_config cx88_geniatech_x8000_mt = {
462 .demod_address = (0x1e >> 1),
463 .no_tuner = 1,
464};
465
466static int attach_xc3028(u8 addr, struct cx8802_dev *dev)
467{
468 struct dvb_frontend *fe;
469 struct xc2028_ctrl ctl;
470 struct xc2028_config cfg = {
471 .i2c_adap = &dev->core->i2c_adap,
472 .i2c_addr = addr,
473 .ctrl = &ctl,
474 .callback = cx88_tuner_callback,
475 };
476
477 if (!dev->dvb.frontend) {
478 printk(KERN_ERR "%s/2: dvb frontend not attached. "
479 "Can't attach xc3028\n",
480 dev->core->name);
481 return -EINVAL;
482 }
483
484 /*
485 * Some xc3028 devices may be hidden by an I2C gate. This is known
486 * to happen with some s5h1409-based devices.
487 * Now that I2C gate is open, sets up xc3028 configuration
488 */
489 cx88_setup_xc3028(dev->core, &ctl);
490
491 fe = dvb_attach(xc2028_attach, dev->dvb.frontend, &cfg);
492 if (!fe) {
493 printk(KERN_ERR "%s/2: xc3028 attach failed\n",
494 dev->core->name);
495 dvb_frontend_detach(dev->dvb.frontend);
496 dvb_unregister_frontend(dev->dvb.frontend);
497 dev->dvb.frontend = NULL;
498 return -EINVAL;
499 }
500
501 printk(KERN_INFO "%s/2: xc3028 attached\n",
502 dev->core->name);
503
504 return 0;
505}
506
392static int dvb_register(struct cx8802_dev *dev) 507static int dvb_register(struct cx8802_dev *dev)
393{ 508{
394 /* init struct videobuf_dvb */ 509 /* init struct videobuf_dvb */
@@ -429,8 +544,9 @@ static int dvb_register(struct cx8802_dev *dev)
429 &hauppauge_hvr_config, 544 &hauppauge_hvr_config,
430 &dev->core->i2c_adap); 545 &dev->core->i2c_adap);
431 if (dev->dvb.frontend != NULL) { 546 if (dev->dvb.frontend != NULL) {
432 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61, 547 dvb_attach(simple_tuner_attach, dev->dvb.frontend,
433 &dev->core->i2c_adap, DVB_PLL_FMD1216ME); 548 &dev->core->i2c_adap, 0x61,
549 TUNER_PHILIPS_FMD1216ME_MK3);
434 } 550 }
435 break; 551 break;
436 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS: 552 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PLUS:
@@ -497,8 +613,9 @@ static int dvb_register(struct cx8802_dev *dev)
497 dev->dvb.frontend = dvb_attach(mt352_attach, &dntv_live_dvbt_pro_config, 613 dev->dvb.frontend = dvb_attach(mt352_attach, &dntv_live_dvbt_pro_config,
498 &dev->vp3054->adap); 614 &dev->vp3054->adap);
499 if (dev->dvb.frontend != NULL) { 615 if (dev->dvb.frontend != NULL) {
500 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61, 616 dvb_attach(simple_tuner_attach, dev->dvb.frontend,
501 &dev->core->i2c_adap, DVB_PLL_FMD1216ME); 617 &dev->core->i2c_adap, 0x61,
618 TUNER_PHILIPS_FMD1216ME_MK3);
502 } 619 }
503#else 620#else
504 printk(KERN_ERR "%s/2: built without vp3054 support\n", dev->core->name); 621 printk(KERN_ERR "%s/2: built without vp3054 support\n", dev->core->name);
@@ -509,18 +626,36 @@ static int dvb_register(struct cx8802_dev *dev)
509 &dvico_fusionhdtv_hybrid, 626 &dvico_fusionhdtv_hybrid,
510 &dev->core->i2c_adap); 627 &dev->core->i2c_adap);
511 if (dev->dvb.frontend != NULL) { 628 if (dev->dvb.frontend != NULL) {
512 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61, 629 dvb_attach(simple_tuner_attach, dev->dvb.frontend,
513 &dev->core->i2c_adap, 630 &dev->core->i2c_adap, 0x61,
514 DVB_PLL_THOMSON_FE6600); 631 TUNER_THOMSON_FE6600);
515 } 632 }
516 break; 633 break;
634 case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PRO:
635 dev->dvb.frontend = dvb_attach(zl10353_attach,
636 &dvico_fusionhdtv_xc3028,
637 &dev->core->i2c_adap);
638 if (dev->dvb.frontend == NULL)
639 dev->dvb.frontend = dvb_attach(mt352_attach,
640 &dvico_fusionhdtv_mt352_xc3028,
641 &dev->core->i2c_adap);
642 /*
643 * On this board, the demod provides the I2C bus pullup.
644 * We must not permit gate_ctrl to be performed, or
645 * the xc3028 cannot communicate on the bus.
646 */
647 if (dev->dvb.frontend)
648 dev->dvb.frontend->ops.i2c_gate_ctrl = NULL;
649 if (attach_xc3028(0x61, dev) < 0)
650 return -EINVAL;
651 break;
517 case CX88_BOARD_PCHDTV_HD3000: 652 case CX88_BOARD_PCHDTV_HD3000:
518 dev->dvb.frontend = dvb_attach(or51132_attach, &pchdtv_hd3000, 653 dev->dvb.frontend = dvb_attach(or51132_attach, &pchdtv_hd3000,
519 &dev->core->i2c_adap); 654 &dev->core->i2c_adap);
520 if (dev->dvb.frontend != NULL) { 655 if (dev->dvb.frontend != NULL) {
521 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61, 656 dvb_attach(simple_tuner_attach, dev->dvb.frontend,
522 &dev->core->i2c_adap, 657 &dev->core->i2c_adap, 0x61,
523 DVB_PLL_THOMSON_DTT761X); 658 TUNER_THOMSON_DTT761X);
524 } 659 }
525 break; 660 break;
526 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q: 661 case CX88_BOARD_DVICO_FUSIONHDTV_3_GOLD_Q:
@@ -540,9 +675,9 @@ static int dvb_register(struct cx8802_dev *dev)
540 &fusionhdtv_3_gold, 675 &fusionhdtv_3_gold,
541 &dev->core->i2c_adap); 676 &dev->core->i2c_adap);
542 if (dev->dvb.frontend != NULL) { 677 if (dev->dvb.frontend != NULL) {
543 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61, 678 dvb_attach(simple_tuner_attach, dev->dvb.frontend,
544 &dev->core->i2c_adap, 679 &dev->core->i2c_adap, 0x61,
545 DVB_PLL_MICROTUNE_4042); 680 TUNER_MICROTUNE_4042FI5);
546 } 681 }
547 } 682 }
548 break; 683 break;
@@ -560,9 +695,9 @@ static int dvb_register(struct cx8802_dev *dev)
560 &fusionhdtv_3_gold, 695 &fusionhdtv_3_gold,
561 &dev->core->i2c_adap); 696 &dev->core->i2c_adap);
562 if (dev->dvb.frontend != NULL) { 697 if (dev->dvb.frontend != NULL) {
563 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61, 698 dvb_attach(simple_tuner_attach, dev->dvb.frontend,
564 &dev->core->i2c_adap, 699 &dev->core->i2c_adap, 0x61,
565 DVB_PLL_THOMSON_DTT761X); 700 TUNER_THOMSON_DTT761X);
566 } 701 }
567 } 702 }
568 break; 703 break;
@@ -580,9 +715,11 @@ static int dvb_register(struct cx8802_dev *dev)
580 &fusionhdtv_5_gold, 715 &fusionhdtv_5_gold,
581 &dev->core->i2c_adap); 716 &dev->core->i2c_adap);
582 if (dev->dvb.frontend != NULL) { 717 if (dev->dvb.frontend != NULL) {
583 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61, 718 dvb_attach(simple_tuner_attach, dev->dvb.frontend,
584 &dev->core->i2c_adap, 719 &dev->core->i2c_adap, 0x61,
585 DVB_PLL_LG_TDVS_H06XF); 720 TUNER_LG_TDVS_H06XF);
721 dvb_attach(tda9887_attach, dev->dvb.frontend,
722 &dev->core->i2c_adap, 0x43);
586 } 723 }
587 } 724 }
588 break; 725 break;
@@ -600,9 +737,11 @@ static int dvb_register(struct cx8802_dev *dev)
600 &pchdtv_hd5500, 737 &pchdtv_hd5500,
601 &dev->core->i2c_adap); 738 &dev->core->i2c_adap);
602 if (dev->dvb.frontend != NULL) { 739 if (dev->dvb.frontend != NULL) {
603 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61, 740 dvb_attach(simple_tuner_attach, dev->dvb.frontend,
604 &dev->core->i2c_adap, 741 &dev->core->i2c_adap, 0x61,
605 DVB_PLL_LG_TDVS_H06XF); 742 TUNER_LG_TDVS_H06XF);
743 dvb_attach(tda9887_attach, dev->dvb.frontend,
744 &dev->core->i2c_adap, 0x43);
606 } 745 }
607 } 746 }
608 break; 747 break;
@@ -611,8 +750,9 @@ static int dvb_register(struct cx8802_dev *dev)
611 &ati_hdtvwonder, 750 &ati_hdtvwonder,
612 &dev->core->i2c_adap); 751 &dev->core->i2c_adap);
613 if (dev->dvb.frontend != NULL) { 752 if (dev->dvb.frontend != NULL) {
614 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61, 753 dvb_attach(simple_tuner_attach, dev->dvb.frontend,
615 NULL, DVB_PLL_TUV1236D); 754 &dev->core->i2c_adap, 0x61,
755 TUNER_PHILIPS_TUV1236D);
616 } 756 }
617 break; 757 break;
618 case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1: 758 case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
@@ -658,14 +798,62 @@ static int dvb_register(struct cx8802_dev *dev)
658 &pinnacle_pctv_hd_800i_tuner_config); 798 &pinnacle_pctv_hd_800i_tuner_config);
659 } 799 }
660 break; 800 break;
801 case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO:
802 dev->dvb.frontend = dvb_attach(s5h1409_attach,
803 &dvico_hdtv5_pci_nano_config,
804 &dev->core->i2c_adap);
805 if (dev->dvb.frontend != NULL) {
806 struct dvb_frontend *fe;
807 struct xc2028_config cfg = {
808 .i2c_adap = &dev->core->i2c_adap,
809 .i2c_addr = 0x61,
810 .callback = cx88_pci_nano_callback,
811 };
812 static struct xc2028_ctrl ctl = {
813 .fname = "xc3028-v27.fw",
814 .max_len = 64,
815 .scode_table = XC3028_FE_OREN538,
816 };
817
818 fe = dvb_attach(xc2028_attach,
819 dev->dvb.frontend, &cfg);
820 if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
821 fe->ops.tuner_ops.set_config(fe, &ctl);
822 }
823 break;
824 case CX88_BOARD_PINNACLE_HYBRID_PCTV:
825 dev->dvb.frontend = dvb_attach(zl10353_attach,
826 &cx88_geniatech_x8000_mt,
827 &dev->core->i2c_adap);
828 if (attach_xc3028(0x61, dev) < 0)
829 return -EINVAL;
830 break;
831 case CX88_BOARD_GENIATECH_X8000_MT:
832 dev->ts_gen_cntrl = 0x00;
833
834 dev->dvb.frontend = dvb_attach(zl10353_attach,
835 &cx88_geniatech_x8000_mt,
836 &dev->core->i2c_adap);
837 if (attach_xc3028(0x61, dev) < 0)
838 return -EINVAL;
839 break;
840 case CX88_BOARD_KWORLD_ATSC_120:
841 dev->dvb.frontend = dvb_attach(s5h1409_attach,
842 &kworld_atsc_120_config,
843 &dev->core->i2c_adap);
844 if (attach_xc3028(0x61, dev) < 0)
845 return -EINVAL;
846 break;
661 default: 847 default:
662 printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card isn't supported yet\n", 848 printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card isn't supported yet\n",
663 dev->core->name); 849 dev->core->name);
664 break; 850 break;
665 } 851 }
666 if (NULL == dev->dvb.frontend) { 852 if (NULL == dev->dvb.frontend) {
667 printk(KERN_ERR "%s/2: frontend initialization failed\n", dev->core->name); 853 printk(KERN_ERR
668 return -1; 854 "%s/2: frontend initialization failed\n",
855 dev->core->name);
856 return -EINVAL;
669 } 857 }
670 858
671 /* Ensure all frontends negotiate bus access */ 859 /* Ensure all frontends negotiate bus access */
@@ -675,7 +863,8 @@ static int dvb_register(struct cx8802_dev *dev)
675 cx88_call_i2c_clients (dev->core, TUNER_SET_STANDBY, NULL); 863 cx88_call_i2c_clients (dev->core, TUNER_SET_STANDBY, NULL);
676 864
677 /* register everything */ 865 /* register everything */
678 return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev); 866 return videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev,
867 &dev->pci->dev, adapter_nr);
679} 868}
680 869
681/* ----------------------------------------------------------- */ 870/* ----------------------------------------------------------- */
@@ -685,7 +874,7 @@ static int cx8802_dvb_advise_acquire(struct cx8802_driver *drv)
685{ 874{
686 struct cx88_core *core = drv->core; 875 struct cx88_core *core = drv->core;
687 int err = 0; 876 int err = 0;
688 dprintk( 1, "%s\n", __FUNCTION__); 877 dprintk( 1, "%s\n", __func__);
689 878
690 switch (core->boardnr) { 879 switch (core->boardnr) {
691 case CX88_BOARD_HAUPPAUGE_HVR1300: 880 case CX88_BOARD_HAUPPAUGE_HVR1300:
@@ -708,7 +897,7 @@ static int cx8802_dvb_advise_release(struct cx8802_driver *drv)
708{ 897{
709 struct cx88_core *core = drv->core; 898 struct cx88_core *core = drv->core;
710 int err = 0; 899 int err = 0;
711 dprintk( 1, "%s\n", __FUNCTION__); 900 dprintk( 1, "%s\n", __func__);
712 901
713 switch (core->boardnr) { 902 switch (core->boardnr) {
714 case CX88_BOARD_HAUPPAUGE_HVR1300: 903 case CX88_BOARD_HAUPPAUGE_HVR1300:
@@ -726,7 +915,7 @@ static int cx8802_dvb_probe(struct cx8802_driver *drv)
726 struct cx8802_dev *dev = drv->core->dvbdev; 915 struct cx8802_dev *dev = drv->core->dvbdev;
727 int err; 916 int err;
728 917
729 dprintk( 1, "%s\n", __FUNCTION__); 918 dprintk( 1, "%s\n", __func__);
730 dprintk( 1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n", 919 dprintk( 1, " ->being probed by Card=%d Name=%s, PCI %02x:%02x\n",
731 core->boardnr, 920 core->boardnr,
732 core->name, 921 core->name,
@@ -744,8 +933,8 @@ static int cx8802_dvb_probe(struct cx8802_driver *drv)
744 933
745 /* dvb stuff */ 934 /* dvb stuff */
746 printk(KERN_INFO "%s/2: cx2388x based DVB/ATSC card\n", core->name); 935 printk(KERN_INFO "%s/2: cx2388x based DVB/ATSC card\n", core->name);
747 videobuf_queue_pci_init(&dev->dvb.dvbq, &dvb_qops, 936 videobuf_queue_sg_init(&dev->dvb.dvbq, &dvb_qops,
748 dev->pci, &dev->slock, 937 &dev->pci->dev, &dev->slock,
749 V4L2_BUF_TYPE_VIDEO_CAPTURE, 938 V4L2_BUF_TYPE_VIDEO_CAPTURE,
750 V4L2_FIELD_TOP, 939 V4L2_FIELD_TOP,
751 sizeof(struct cx88_buffer), 940 sizeof(struct cx88_buffer),
@@ -764,7 +953,8 @@ static int cx8802_dvb_remove(struct cx8802_driver *drv)
764 struct cx8802_dev *dev = drv->core->dvbdev; 953 struct cx8802_dev *dev = drv->core->dvbdev;
765 954
766 /* dvb */ 955 /* dvb */
767 videobuf_dvb_unregister(&dev->dvb); 956 if (dev->dvb.frontend)
957 videobuf_dvb_unregister(&dev->dvb);
768 958
769 vp3054_i2c_remove(dev); 959 vp3054_i2c_remove(dev);
770 960
diff --git a/drivers/media/video/cx88/cx88-i2c.c b/drivers/media/video/cx88/cx88-i2c.c
index 566b26af523e..c6b44732a082 100644
--- a/drivers/media/video/cx88/cx88-i2c.c
+++ b/drivers/media/video/cx88/cx88-i2c.c
@@ -35,11 +35,11 @@
35#include "cx88.h" 35#include "cx88.h"
36#include <media/v4l2-common.h> 36#include <media/v4l2-common.h>
37 37
38static unsigned int i2c_debug = 0; 38static unsigned int i2c_debug;
39module_param(i2c_debug, int, 0644); 39module_param(i2c_debug, int, 0644);
40MODULE_PARM_DESC(i2c_debug,"enable debug messages [i2c]"); 40MODULE_PARM_DESC(i2c_debug,"enable debug messages [i2c]");
41 41
42static unsigned int i2c_scan = 0; 42static unsigned int i2c_scan;
43module_param(i2c_scan, int, 0444); 43module_param(i2c_scan, int, 0444);
44MODULE_PARM_DESC(i2c_scan,"scan i2c bus at insmod time"); 44MODULE_PARM_DESC(i2c_scan,"scan i2c bus at insmod time");
45 45
diff --git a/drivers/media/video/cx88/cx88-input.c b/drivers/media/video/cx88/cx88-input.c
index bb0911b4d2f6..53526d997a4e 100644
--- a/drivers/media/video/cx88/cx88-input.c
+++ b/drivers/media/video/cx88/cx88-input.c
@@ -57,7 +57,7 @@ struct cx88_IR {
57 u32 mask_keyup; 57 u32 mask_keyup;
58}; 58};
59 59
60static int ir_debug = 0; 60static int ir_debug;
61module_param(ir_debug, int, 0644); /* debug level [IR] */ 61module_param(ir_debug, int, 0644); /* debug level [IR] */
62MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]"); 62MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");
63 63
@@ -258,6 +258,13 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
258 ir->mask_keyup = 0x80; 258 ir->mask_keyup = 0x80;
259 ir->polling = 1; /* ms */ 259 ir->polling = 1; /* ms */
260 break; 260 break;
261 case CX88_BOARD_PROLINK_PV_8000GT:
262 ir_codes = ir_codes_pixelview_new;
263 ir->gpio_addr = MO_GP1_IO;
264 ir->mask_keycode = 0x3f;
265 ir->mask_keyup = 0x80;
266 ir->polling = 1; /* ms */
267 break;
261 case CX88_BOARD_KWORLD_LTV883: 268 case CX88_BOARD_KWORLD_LTV883:
262 ir_codes = ir_codes_pixelview; 269 ir_codes = ir_codes_pixelview;
263 ir->gpio_addr = MO_GP1_IO; 270 ir->gpio_addr = MO_GP1_IO;
@@ -310,6 +317,12 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
310 ir_type = IR_TYPE_RC5; 317 ir_type = IR_TYPE_RC5;
311 ir->sampling = 1; 318 ir->sampling = 1;
312 break; 319 break;
320 case CX88_BOARD_POWERCOLOR_REAL_ANGEL:
321 ir_codes = ir_codes_powercolor_real_angel;
322 ir->gpio_addr = MO_GP2_IO;
323 ir->mask_keycode = 0x7e;
324 ir->polling = 100; /* ms */
325 break;
313 } 326 }
314 327
315 if (NULL == ir_codes) { 328 if (NULL == ir_codes) {
diff --git a/drivers/media/video/cx88/cx88-mpeg.c b/drivers/media/video/cx88/cx88-mpeg.c
index e357f415db06..a6b061c2644a 100644
--- a/drivers/media/video/cx88/cx88-mpeg.c
+++ b/drivers/media/video/cx88/cx88-mpeg.c
@@ -39,7 +39,7 @@ MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
39MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]"); 39MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
40MODULE_LICENSE("GPL"); 40MODULE_LICENSE("GPL");
41 41
42static unsigned int debug = 0; 42static unsigned int debug;
43module_param(debug,int,0644); 43module_param(debug,int,0644);
44MODULE_PARM_DESC(debug,"enable debug messages [mpeg]"); 44MODULE_PARM_DESC(debug,"enable debug messages [mpeg]");
45 45
@@ -146,7 +146,7 @@ static int cx8802_start_dma(struct cx8802_dev *dev,
146 cx_write(TS_GEN_CNTRL, 0x06); /* punctured clock TS & posedge driven */ 146 cx_write(TS_GEN_CNTRL, 0x06); /* punctured clock TS & posedge driven */
147 udelay(100); 147 udelay(100);
148 } else { 148 } else {
149 printk( "%s() Failed. Unsupported value in .mpeg (0x%08x)\n", __FUNCTION__, 149 printk( "%s() Failed. Unsupported value in .mpeg (0x%08x)\n", __func__,
150 core->board.mpeg ); 150 core->board.mpeg );
151 return -EINVAL; 151 return -EINVAL;
152 } 152 }
@@ -247,7 +247,7 @@ int cx8802_buf_prepare(struct videobuf_queue *q, struct cx8802_dev *dev,
247 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb); 247 struct videobuf_dmabuf *dma=videobuf_to_dma(&buf->vb);
248 int rc; 248 int rc;
249 249
250 dprintk(1, "%s: %p\n", __FUNCTION__, buf); 250 dprintk(1, "%s: %p\n", __func__, buf);
251 if (0 != buf->vb.baddr && buf->vb.bsize < size) 251 if (0 != buf->vb.baddr && buf->vb.bsize < size)
252 return -EINVAL; 252 return -EINVAL;
253 253
@@ -289,7 +289,7 @@ void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf)
289 buf->count = cx88q->count++; 289 buf->count = cx88q->count++;
290 mod_timer(&cx88q->timeout, jiffies+BUFFER_TIMEOUT); 290 mod_timer(&cx88q->timeout, jiffies+BUFFER_TIMEOUT);
291 dprintk(1,"[%p/%d] %s - first active\n", 291 dprintk(1,"[%p/%d] %s - first active\n",
292 buf, buf->vb.i, __FUNCTION__); 292 buf, buf->vb.i, __func__);
293 293
294 } else { 294 } else {
295 dprintk( 1, "queue is not empty - append to active\n" ); 295 dprintk( 1, "queue is not empty - append to active\n" );
@@ -299,7 +299,7 @@ void cx8802_buf_queue(struct cx8802_dev *dev, struct cx88_buffer *buf)
299 buf->count = cx88q->count++; 299 buf->count = cx88q->count++;
300 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 300 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
301 dprintk( 1, "[%p/%d] %s - append to active\n", 301 dprintk( 1, "[%p/%d] %s - append to active\n",
302 buf, buf->vb.i, __FUNCTION__); 302 buf, buf->vb.i, __func__);
303 } 303 }
304} 304}
305 305
@@ -342,7 +342,7 @@ static void cx8802_timeout(unsigned long data)
342{ 342{
343 struct cx8802_dev *dev = (struct cx8802_dev*)data; 343 struct cx8802_dev *dev = (struct cx8802_dev*)data;
344 344
345 dprintk(1, "%s\n",__FUNCTION__); 345 dprintk(1, "%s\n",__func__);
346 346
347 if (debug) 347 if (debug)
348 cx88_sram_channel_dump(dev->core, &cx88_sram_channels[SRAM_CH28]); 348 cx88_sram_channel_dump(dev->core, &cx88_sram_channels[SRAM_CH28]);
@@ -613,6 +613,8 @@ static int cx8802_request_acquire(struct cx8802_driver *drv)
613 core->active_type_id != drv->type_id) 613 core->active_type_id != drv->type_id)
614 return -EBUSY; 614 return -EBUSY;
615 615
616 core->input = CX88_VMUX_DVB;
617
616 if (drv->advise_acquire) 618 if (drv->advise_acquire)
617 { 619 {
618 mutex_lock(&drv->core->lock); 620 mutex_lock(&drv->core->lock);
@@ -623,7 +625,7 @@ static int cx8802_request_acquire(struct cx8802_driver *drv)
623 } 625 }
624 mutex_unlock(&drv->core->lock); 626 mutex_unlock(&drv->core->lock);
625 627
626 mpeg_dbg(1,"%s() Post acquire GPIO=%x\n", __FUNCTION__, cx_read(MO_GP0_IO)); 628 mpeg_dbg(1,"%s() Post acquire GPIO=%x\n", __func__, cx_read(MO_GP0_IO));
627 } 629 }
628 630
629 return 0; 631 return 0;
@@ -639,7 +641,7 @@ static int cx8802_request_release(struct cx8802_driver *drv)
639 { 641 {
640 drv->advise_release(drv); 642 drv->advise_release(drv);
641 core->active_type_id = CX88_BOARD_NONE; 643 core->active_type_id = CX88_BOARD_NONE;
642 mpeg_dbg(1,"%s() Post release GPIO=%x\n", __FUNCTION__, cx_read(MO_GP0_IO)); 644 mpeg_dbg(1,"%s() Post release GPIO=%x\n", __func__, cx_read(MO_GP0_IO));
643 } 645 }
644 mutex_unlock(&drv->core->lock); 646 mutex_unlock(&drv->core->lock);
645 647
@@ -813,7 +815,7 @@ static void __devexit cx8802_remove(struct pci_dev *pci_dev)
813 815
814 dev = pci_get_drvdata(pci_dev); 816 dev = pci_get_drvdata(pci_dev);
815 817
816 dprintk( 1, "%s\n", __FUNCTION__); 818 dprintk( 1, "%s\n", __func__);
817 819
818 if (!list_empty(&dev->drvlist)) { 820 if (!list_empty(&dev->drvlist)) {
819 struct cx8802_driver *drv, *tmp; 821 struct cx8802_driver *drv, *tmp;
diff --git a/drivers/media/video/cx88/cx88-tvaudio.c b/drivers/media/video/cx88/cx88-tvaudio.c
index 76e5c78d8ae4..3a1977f41e27 100644
--- a/drivers/media/video/cx88/cx88-tvaudio.c
+++ b/drivers/media/video/cx88/cx88-tvaudio.c
@@ -53,15 +53,15 @@
53 53
54#include "cx88.h" 54#include "cx88.h"
55 55
56static unsigned int audio_debug = 0; 56static unsigned int audio_debug;
57module_param(audio_debug, int, 0644); 57module_param(audio_debug, int, 0644);
58MODULE_PARM_DESC(audio_debug, "enable debug messages [audio]"); 58MODULE_PARM_DESC(audio_debug, "enable debug messages [audio]");
59 59
60static unsigned int always_analog = 0; 60static unsigned int always_analog;
61module_param(always_analog,int,0644); 61module_param(always_analog,int,0644);
62MODULE_PARM_DESC(always_analog,"force analog audio out"); 62MODULE_PARM_DESC(always_analog,"force analog audio out");
63 63
64static unsigned int radio_deemphasis = 0; 64static unsigned int radio_deemphasis;
65module_param(radio_deemphasis,int,0644); 65module_param(radio_deemphasis,int,0644);
66MODULE_PARM_DESC(radio_deemphasis, "Radio deemphasis time constant, " 66MODULE_PARM_DESC(radio_deemphasis, "Radio deemphasis time constant, "
67 "0=None, 1=50us (elsewhere), 2=75us (USA)"); 67 "0=None, 1=50us (elsewhere), 2=75us (USA)");
@@ -265,12 +265,12 @@ static void set_audio_standard_BTSC(struct cx88_core *core, unsigned int sap,
265 mode |= EN_FMRADIO_EN_RDS; 265 mode |= EN_FMRADIO_EN_RDS;
266 266
267 if (sap) { 267 if (sap) {
268 dprintk("%s SAP (status: unknown)\n", __FUNCTION__); 268 dprintk("%s SAP (status: unknown)\n", __func__);
269 set_audio_start(core, SEL_SAP); 269 set_audio_start(core, SEL_SAP);
270 set_audio_registers(core, btsc_sap); 270 set_audio_registers(core, btsc_sap);
271 set_audio_finish(core, mode); 271 set_audio_finish(core, mode);
272 } else { 272 } else {
273 dprintk("%s (status: known-good)\n", __FUNCTION__); 273 dprintk("%s (status: known-good)\n", __func__);
274 set_audio_start(core, SEL_BTSC); 274 set_audio_start(core, SEL_BTSC);
275 set_audio_registers(core, btsc); 275 set_audio_registers(core, btsc);
276 set_audio_finish(core, mode); 276 set_audio_finish(core, mode);
@@ -351,16 +351,16 @@ static void set_audio_standard_NICAM(struct cx88_core *core, u32 mode)
351 set_audio_start(core,SEL_NICAM); 351 set_audio_start(core,SEL_NICAM);
352 switch (core->tvaudio) { 352 switch (core->tvaudio) {
353 case WW_L: 353 case WW_L:
354 dprintk("%s SECAM-L NICAM (status: devel)\n", __FUNCTION__); 354 dprintk("%s SECAM-L NICAM (status: devel)\n", __func__);
355 set_audio_registers(core, nicam_l); 355 set_audio_registers(core, nicam_l);
356 break; 356 break;
357 case WW_I: 357 case WW_I:
358 dprintk("%s PAL-I NICAM (status: known-good)\n", __FUNCTION__); 358 dprintk("%s PAL-I NICAM (status: known-good)\n", __func__);
359 set_audio_registers(core, nicam_bgdki_common); 359 set_audio_registers(core, nicam_bgdki_common);
360 set_audio_registers(core, nicam_i); 360 set_audio_registers(core, nicam_i);
361 break; 361 break;
362 default: 362 default:
363 dprintk("%s PAL-BGDK NICAM (status: known-good)\n", __FUNCTION__); 363 dprintk("%s PAL-BGDK NICAM (status: known-good)\n", __func__);
364 set_audio_registers(core, nicam_bgdki_common); 364 set_audio_registers(core, nicam_bgdki_common);
365 set_audio_registers(core, nicam_default); 365 set_audio_registers(core, nicam_default);
366 break; 366 break;
@@ -600,28 +600,28 @@ static void set_audio_standard_A2(struct cx88_core *core, u32 mode)
600 set_audio_start(core, SEL_A2); 600 set_audio_start(core, SEL_A2);
601 switch (core->tvaudio) { 601 switch (core->tvaudio) {
602 case WW_BG: 602 case WW_BG:
603 dprintk("%s PAL-BG A1/2 (status: known-good)\n", __FUNCTION__); 603 dprintk("%s PAL-BG A1/2 (status: known-good)\n", __func__);
604 set_audio_registers(core, a2_bgdk_common); 604 set_audio_registers(core, a2_bgdk_common);
605 set_audio_registers(core, a2_bg); 605 set_audio_registers(core, a2_bg);
606 set_audio_registers(core, a2_deemph50); 606 set_audio_registers(core, a2_deemph50);
607 break; 607 break;
608 case WW_DK: 608 case WW_DK:
609 dprintk("%s PAL-DK A1/2 (status: known-good)\n", __FUNCTION__); 609 dprintk("%s PAL-DK A1/2 (status: known-good)\n", __func__);
610 set_audio_registers(core, a2_bgdk_common); 610 set_audio_registers(core, a2_bgdk_common);
611 set_audio_registers(core, a2_dk); 611 set_audio_registers(core, a2_dk);
612 set_audio_registers(core, a2_deemph50); 612 set_audio_registers(core, a2_deemph50);
613 break; 613 break;
614 case WW_I: 614 case WW_I:
615 dprintk("%s PAL-I A1 (status: known-good)\n", __FUNCTION__); 615 dprintk("%s PAL-I A1 (status: known-good)\n", __func__);
616 set_audio_registers(core, a1_i); 616 set_audio_registers(core, a1_i);
617 set_audio_registers(core, a2_deemph50); 617 set_audio_registers(core, a2_deemph50);
618 break; 618 break;
619 case WW_L: 619 case WW_L:
620 dprintk("%s AM-L (status: devel)\n", __FUNCTION__); 620 dprintk("%s AM-L (status: devel)\n", __func__);
621 set_audio_registers(core, am_l); 621 set_audio_registers(core, am_l);
622 break; 622 break;
623 default: 623 default:
624 dprintk("%s Warning: wrong value\n", __FUNCTION__); 624 dprintk("%s Warning: wrong value\n", __func__);
625 return; 625 return;
626 break; 626 break;
627 }; 627 };
@@ -637,7 +637,7 @@ static void set_audio_standard_EIAJ(struct cx88_core *core)
637 637
638 { /* end of list */ }, 638 { /* end of list */ },
639 }; 639 };
640 dprintk("%s (status: unknown)\n", __FUNCTION__); 640 dprintk("%s (status: unknown)\n", __func__);
641 641
642 set_audio_start(core, SEL_EIAJ); 642 set_audio_start(core, SEL_EIAJ);
643 set_audio_registers(core, eiaj); 643 set_audio_registers(core, eiaj);
@@ -691,7 +691,7 @@ static void set_audio_standard_FM(struct cx88_core *core,
691 { /* end of list */ }, 691 { /* end of list */ },
692 }; 692 };
693 693
694 dprintk("%s (status: unknown)\n", __FUNCTION__); 694 dprintk("%s (status: unknown)\n", __func__);
695 set_audio_start(core, SEL_FMRADIO); 695 set_audio_start(core, SEL_FMRADIO);
696 696
697 switch (deemph) { 697 switch (deemph) {
diff --git a/drivers/media/video/cx88/cx88-vbi.c b/drivers/media/video/cx88/cx88-vbi.c
index d96ecfcf393a..0943060682bc 100644
--- a/drivers/media/video/cx88/cx88-vbi.c
+++ b/drivers/media/video/cx88/cx88-vbi.c
@@ -11,7 +11,7 @@ static unsigned int vbibufs = 4;
11module_param(vbibufs,int,0644); 11module_param(vbibufs,int,0644);
12MODULE_PARM_DESC(vbibufs,"number of vbi buffers, range 2-32"); 12MODULE_PARM_DESC(vbibufs,"number of vbi buffers, range 2-32");
13 13
14static unsigned int vbi_debug = 0; 14static unsigned int vbi_debug;
15module_param(vbi_debug,int,0644); 15module_param(vbi_debug,int,0644);
16MODULE_PARM_DESC(vbi_debug,"enable debug messages [vbi]"); 16MODULE_PARM_DESC(vbi_debug,"enable debug messages [vbi]");
17 17
diff --git a/drivers/media/video/cx88/cx88-video.c b/drivers/media/video/cx88/cx88-video.c
index 227179620d13..eea23f95edb7 100644
--- a/drivers/media/video/cx88/cx88-video.c
+++ b/drivers/media/video/cx88/cx88-video.c
@@ -63,11 +63,11 @@ MODULE_PARM_DESC(video_nr,"video device numbers");
63MODULE_PARM_DESC(vbi_nr,"vbi device numbers"); 63MODULE_PARM_DESC(vbi_nr,"vbi device numbers");
64MODULE_PARM_DESC(radio_nr,"radio device numbers"); 64MODULE_PARM_DESC(radio_nr,"radio device numbers");
65 65
66static unsigned int video_debug = 0; 66static unsigned int video_debug;
67module_param(video_debug,int,0644); 67module_param(video_debug,int,0644);
68MODULE_PARM_DESC(video_debug,"enable debug messages [video]"); 68MODULE_PARM_DESC(video_debug,"enable debug messages [video]");
69 69
70static unsigned int irq_debug = 0; 70static unsigned int irq_debug;
71module_param(irq_debug,int,0644); 71module_param(irq_debug,int,0644);
72MODULE_PARM_DESC(irq_debug,"enable debug messages [IRQ handler]"); 72MODULE_PARM_DESC(irq_debug,"enable debug messages [IRQ handler]");
73 73
@@ -228,6 +228,30 @@ static struct cx88_ctrl cx8800_ctls[] = {
228 .mask = 0x00ff, 228 .mask = 0x00ff,
229 .shift = 0, 229 .shift = 0,
230 },{ 230 },{
231 .v = {
232 .id = V4L2_CID_CHROMA_AGC,
233 .name = "Chroma AGC",
234 .minimum = 0,
235 .maximum = 1,
236 .default_value = 0x1,
237 .type = V4L2_CTRL_TYPE_BOOLEAN,
238 },
239 .reg = MO_INPUT_FORMAT,
240 .mask = 1 << 10,
241 .shift = 10,
242 }, {
243 .v = {
244 .id = V4L2_CID_COLOR_KILLER,
245 .name = "Color killer",
246 .minimum = 0,
247 .maximum = 1,
248 .default_value = 0x1,
249 .type = V4L2_CTRL_TYPE_BOOLEAN,
250 },
251 .reg = MO_INPUT_FORMAT,
252 .mask = 1 << 9,
253 .shift = 9,
254 }, {
231 /* --- audio --- */ 255 /* --- audio --- */
232 .v = { 256 .v = {
233 .id = V4L2_CID_AUDIO_MUTE, 257 .id = V4L2_CID_AUDIO_MUTE,
@@ -282,6 +306,8 @@ const u32 cx88_user_ctrls[] = {
282 V4L2_CID_AUDIO_VOLUME, 306 V4L2_CID_AUDIO_VOLUME,
283 V4L2_CID_AUDIO_BALANCE, 307 V4L2_CID_AUDIO_BALANCE,
284 V4L2_CID_AUDIO_MUTE, 308 V4L2_CID_AUDIO_MUTE,
309 V4L2_CID_CHROMA_AGC,
310 V4L2_CID_COLOR_KILLER,
285 0 311 0
286}; 312};
287EXPORT_SYMBOL(cx88_user_ctrls); 313EXPORT_SYMBOL(cx88_user_ctrls);
@@ -291,7 +317,7 @@ static const u32 *ctrl_classes[] = {
291 NULL 317 NULL
292}; 318};
293 319
294int cx8800_ctrl_query(struct v4l2_queryctrl *qctrl) 320int cx8800_ctrl_query(struct cx88_core *core, struct v4l2_queryctrl *qctrl)
295{ 321{
296 int i; 322 int i;
297 323
@@ -306,6 +332,11 @@ int cx8800_ctrl_query(struct v4l2_queryctrl *qctrl)
306 return 0; 332 return 0;
307 } 333 }
308 *qctrl = cx8800_ctls[i].v; 334 *qctrl = cx8800_ctls[i].v;
335 /* Report chroma AGC as inactive when SECAM is selected */
336 if (cx8800_ctls[i].v.id == V4L2_CID_CHROMA_AGC &&
337 core->tvnorm & V4L2_STD_SECAM)
338 qctrl->flags |= V4L2_CTRL_FLAG_INACTIVE;
339
309 return 0; 340 return 0;
310} 341}
311EXPORT_SYMBOL(cx8800_ctrl_query); 342EXPORT_SYMBOL(cx8800_ctrl_query);
@@ -776,14 +807,14 @@ static int video_open(struct inode *inode, struct file *file)
776 fh->height = 240; 807 fh->height = 240;
777 fh->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24); 808 fh->fmt = format_by_fourcc(V4L2_PIX_FMT_BGR24);
778 809
779 videobuf_queue_pci_init(&fh->vidq, &cx8800_video_qops, 810 videobuf_queue_sg_init(&fh->vidq, &cx8800_video_qops,
780 dev->pci, &dev->slock, 811 &dev->pci->dev, &dev->slock,
781 V4L2_BUF_TYPE_VIDEO_CAPTURE, 812 V4L2_BUF_TYPE_VIDEO_CAPTURE,
782 V4L2_FIELD_INTERLACED, 813 V4L2_FIELD_INTERLACED,
783 sizeof(struct cx88_buffer), 814 sizeof(struct cx88_buffer),
784 fh); 815 fh);
785 videobuf_queue_pci_init(&fh->vbiq, &cx8800_vbi_qops, 816 videobuf_queue_sg_init(&fh->vbiq, &cx8800_vbi_qops,
786 dev->pci, &dev->slock, 817 &dev->pci->dev, &dev->slock,
787 V4L2_BUF_TYPE_VBI_CAPTURE, 818 V4L2_BUF_TYPE_VBI_CAPTURE,
788 V4L2_FIELD_SEQ_TB, 819 V4L2_FIELD_SEQ_TB,
789 sizeof(struct cx88_buffer), 820 sizeof(struct cx88_buffer),
@@ -976,6 +1007,12 @@ int cx88_set_control(struct cx88_core *core, struct v4l2_control *ctl)
976 } 1007 }
977 mask=0xffff; 1008 mask=0xffff;
978 break; 1009 break;
1010 case V4L2_CID_CHROMA_AGC:
1011 /* Do not allow chroma AGC to be enabled for SECAM */
1012 value = ((ctl->value - c->off) << c->shift) & c->mask;
1013 if (core->tvnorm & V4L2_STD_SECAM && value)
1014 return -EINVAL;
1015 break;
979 default: 1016 default:
980 value = ((ctl->value - c->off) << c->shift) & c->mask; 1017 value = ((ctl->value - c->off) << c->shift) & c->mask;
981 break; 1018 break;
@@ -1268,10 +1305,12 @@ static int vidioc_s_input (struct file *file, void *priv, unsigned int i)
1268static int vidioc_queryctrl (struct file *file, void *priv, 1305static int vidioc_queryctrl (struct file *file, void *priv,
1269 struct v4l2_queryctrl *qctrl) 1306 struct v4l2_queryctrl *qctrl)
1270{ 1307{
1308 struct cx88_core *core = ((struct cx8800_fh *)priv)->dev->core;
1309
1271 qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id); 1310 qctrl->id = v4l2_ctrl_next(ctrl_classes, qctrl->id);
1272 if (unlikely(qctrl->id == 0)) 1311 if (unlikely(qctrl->id == 0))
1273 return -EINVAL; 1312 return -EINVAL;
1274 return cx8800_ctrl_query(qctrl); 1313 return cx8800_ctrl_query(core, qctrl);
1275} 1314}
1276 1315
1277static int vidioc_g_ctrl (struct file *file, void *priv, 1316static int vidioc_g_ctrl (struct file *file, void *priv,
@@ -1832,8 +1871,11 @@ static int __devinit cx8800_initdev(struct pci_dev *pci_dev,
1832 1871
1833 switch (core->boardnr) { 1872 switch (core->boardnr) {
1834 case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD: 1873 case CX88_BOARD_DVICO_FUSIONHDTV_5_GOLD:
1835 request_module("ir-kbd-i2c"); 1874 case CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD:
1836 request_module("rtc-isl1208"); 1875 request_module("rtc-isl1208");
1876 /* break intentionally omitted */
1877 case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO:
1878 request_module("ir-kbd-i2c");
1837 } 1879 }
1838 1880
1839 /* register v4l devices */ 1881 /* register v4l devices */
@@ -1917,6 +1959,9 @@ static void __devexit cx8800_finidev(struct pci_dev *pci_dev)
1917 core->kthread = NULL; 1959 core->kthread = NULL;
1918 } 1960 }
1919 1961
1962 if (core->ir)
1963 cx88_ir_stop(core, core->ir);
1964
1920 cx88_shutdown(core); /* FIXME */ 1965 cx88_shutdown(core); /* FIXME */
1921 pci_disable_device(pci_dev); 1966 pci_disable_device(pci_dev);
1922 1967
diff --git a/drivers/media/video/cx88/cx88.h b/drivers/media/video/cx88/cx88.h
index 37e6d2e4002f..14ac173f4071 100644
--- a/drivers/media/video/cx88/cx88.h
+++ b/drivers/media/video/cx88/cx88.h
@@ -37,6 +37,7 @@
37 37
38#include "btcx-risc.h" 38#include "btcx-risc.h"
39#include "cx88-reg.h" 39#include "cx88-reg.h"
40#include "tuner-xc2028.h"
40 41
41#include <linux/version.h> 42#include <linux/version.h>
42#include <linux/mutex.h> 43#include <linux/mutex.h>
@@ -211,6 +212,15 @@ extern struct sram_channel cx88_sram_channels[];
211#define CX88_BOARD_HAUPPAUGE_HVR1300 56 212#define CX88_BOARD_HAUPPAUGE_HVR1300 56
212#define CX88_BOARD_ADSTECH_PTV_390 57 213#define CX88_BOARD_ADSTECH_PTV_390 57
213#define CX88_BOARD_PINNACLE_PCTV_HD_800i 58 214#define CX88_BOARD_PINNACLE_PCTV_HD_800i 58
215#define CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO 59
216#define CX88_BOARD_PINNACLE_HYBRID_PCTV 60
217#define CX88_BOARD_WINFAST_TV2000_XP_GLOBAL 61
218#define CX88_BOARD_POWERCOLOR_REAL_ANGEL 62
219#define CX88_BOARD_GENIATECH_X8000_MT 63
220#define CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PRO 64
221#define CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD 65
222#define CX88_BOARD_PROLINK_PV_8000GT 66
223#define CX88_BOARD_KWORLD_ATSC_120 67
214 224
215enum cx88_itype { 225enum cx88_itype {
216 CX88_VMUX_COMPOSITE1 = 1, 226 CX88_VMUX_COMPOSITE1 = 1,
@@ -595,6 +605,7 @@ extern int cx88_tuner_callback(void *dev, int command, int arg);
595extern int cx88_get_resources(const struct cx88_core *core, 605extern int cx88_get_resources(const struct cx88_core *core,
596 struct pci_dev *pci); 606 struct pci_dev *pci);
597extern struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr); 607extern struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr);
608extern void cx88_setup_xc3028(struct cx88_core *core, struct xc2028_ctrl *ctl);
598 609
599/* ----------------------------------------------------------- */ 610/* ----------------------------------------------------------- */
600/* cx88-tvaudio.c */ 611/* cx88-tvaudio.c */
@@ -640,7 +651,8 @@ void cx8802_cancel_buffers(struct cx8802_dev *dev);
640/* ----------------------------------------------------------- */ 651/* ----------------------------------------------------------- */
641/* cx88-video.c*/ 652/* cx88-video.c*/
642extern const u32 cx88_user_ctrls[]; 653extern const u32 cx88_user_ctrls[];
643extern int cx8800_ctrl_query(struct v4l2_queryctrl *qctrl); 654extern int cx8800_ctrl_query(struct cx88_core *core,
655 struct v4l2_queryctrl *qctrl);
644int cx88_enum_input (struct cx88_core *core,struct v4l2_input *i); 656int cx88_enum_input (struct cx88_core *core,struct v4l2_input *i);
645int cx88_set_freq (struct cx88_core *core,struct v4l2_frequency *f); 657int cx88_set_freq (struct cx88_core *core,struct v4l2_frequency *f);
646int cx88_get_control(struct cx88_core *core, struct v4l2_control *ctl); 658int cx88_get_control(struct cx88_core *core, struct v4l2_control *ctl);
diff --git a/drivers/media/video/dabfirmware.h b/drivers/media/video/dabfirmware.h
index d14d803566a3..cbd92635993d 100644
--- a/drivers/media/video/dabfirmware.h
+++ b/drivers/media/video/dabfirmware.h
@@ -1,5 +1,12 @@
1/* 1/*
2 * dabdata.h - dab usb firmware and bitstream data 2 * dabdata.h - dab usb firmware and bitstream data
3 *
4 * Copyright (C) 1999 BayCom GmbH
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that redistributions of source
8 * code retain the above copyright notice and this comment without
9 * modification.
3 */ 10 */
4 11
5static INTEL_HEX_RECORD firmware[] = { 12static INTEL_HEX_RECORD firmware[] = {
diff --git a/drivers/media/video/dabusb.c b/drivers/media/video/dabusb.c
index a5731f90be0f..8d1f8ee2a533 100644
--- a/drivers/media/video/dabusb.c
+++ b/drivers/media/video/dabusb.c
@@ -205,7 +205,7 @@ static void dabusb_iso_complete (struct urb *purb)
205/*-------------------------------------------------------------------*/ 205/*-------------------------------------------------------------------*/
206static int dabusb_alloc_buffers (pdabusb_t s) 206static int dabusb_alloc_buffers (pdabusb_t s)
207{ 207{
208 int buffers = 0; 208 int transfer_len = 0;
209 pbuff_t b; 209 pbuff_t b;
210 unsigned int pipe = usb_rcvisocpipe (s->usbdev, _DABUSB_ISOPIPE); 210 unsigned int pipe = usb_rcvisocpipe (s->usbdev, _DABUSB_ISOPIPE);
211 int pipesize = usb_maxpacket (s->usbdev, pipe, usb_pipeout (pipe)); 211 int pipesize = usb_maxpacket (s->usbdev, pipe, usb_pipeout (pipe));
@@ -216,7 +216,7 @@ static int dabusb_alloc_buffers (pdabusb_t s)
216 dbg("dabusb_alloc_buffers pipesize:%d packets:%d transfer_buffer_len:%d", 216 dbg("dabusb_alloc_buffers pipesize:%d packets:%d transfer_buffer_len:%d",
217 pipesize, packets, transfer_buffer_length); 217 pipesize, packets, transfer_buffer_length);
218 218
219 while (buffers < (s->total_buffer_size << 10)) { 219 while (transfer_len < (s->total_buffer_size << 10)) {
220 b = kzalloc(sizeof (buff_t), GFP_KERNEL); 220 b = kzalloc(sizeof (buff_t), GFP_KERNEL);
221 if (!b) { 221 if (!b) {
222 err("kzalloc(sizeof(buff_t))==NULL"); 222 err("kzalloc(sizeof(buff_t))==NULL");
@@ -251,10 +251,10 @@ static int dabusb_alloc_buffers (pdabusb_t s)
251 b->purb->iso_frame_desc[i].length = pipesize; 251 b->purb->iso_frame_desc[i].length = pipesize;
252 } 252 }
253 253
254 buffers += transfer_buffer_length; 254 transfer_len += transfer_buffer_length;
255 list_add_tail (&b->buff_list, &s->free_buff_list); 255 list_add_tail (&b->buff_list, &s->free_buff_list);
256 } 256 }
257 s->got_mem = buffers; 257 s->got_mem = transfer_len;
258 258
259 return 0; 259 return 0;
260 260
diff --git a/drivers/media/video/dpc7146.c b/drivers/media/video/dpc7146.c
index 9ceb6b2f3949..88d6df71d051 100644
--- a/drivers/media/video/dpc7146.c
+++ b/drivers/media/video/dpc7146.c
@@ -54,11 +54,11 @@
54 54
55#define DPC_BOARD_CAN_DO_VBI(dev) (dev->revision != 0) 55#define DPC_BOARD_CAN_DO_VBI(dev) (dev->revision != 0)
56 56
57static int debug = 0; 57static int debug;
58module_param(debug, int, 0); 58module_param(debug, int, 0);
59MODULE_PARM_DESC(debug, "debug verbosity"); 59MODULE_PARM_DESC(debug, "debug verbosity");
60 60
61static int dpc_num = 0; 61static int dpc_num;
62 62
63#define DPC_INPUTS 2 63#define DPC_INPUTS 2
64static struct v4l2_input dpc_inputs[DPC_INPUTS] = { 64static struct v4l2_input dpc_inputs[DPC_INPUTS] = {
diff --git a/drivers/media/video/em28xx/Kconfig b/drivers/media/video/em28xx/Kconfig
index 0f7a0bd86ff4..9caffed2b6b8 100644
--- a/drivers/media/video/em28xx/Kconfig
+++ b/drivers/media/video/em28xx/Kconfig
@@ -1,11 +1,13 @@
1config VIDEO_EM28XX 1config VIDEO_EM28XX
2 tristate "Empia EM2800/2820/2840 USB video capture support" 2 tristate "Empia EM28xx USB video capture support"
3 depends on VIDEO_DEV && I2C && INPUT 3 depends on VIDEO_DEV && I2C && INPUT
4 select VIDEO_TUNER 4 select VIDEO_TUNER
5 select VIDEO_TVEEPROM 5 select VIDEO_TVEEPROM
6 select VIDEO_IR 6 select VIDEO_IR
7 select VIDEOBUF_VMALLOC
7 select VIDEO_SAA711X if VIDEO_HELPER_CHIPS_AUTO 8 select VIDEO_SAA711X if VIDEO_HELPER_CHIPS_AUTO
8 select VIDEO_TVP5150 if VIDEO_HELPER_CHIPS_AUTO 9 select VIDEO_TVP5150 if VIDEO_HELPER_CHIPS_AUTO
10 select VIDEO_MSP3400 if VIDEO_HELPER_CHIPS_AUTO
9 ---help--- 11 ---help---
10 This is a video4linux driver for Empia 28xx based TV cards. 12 This is a video4linux driver for Empia 28xx based TV cards.
11 13
@@ -27,3 +29,13 @@ config VIDEO_EM28XX_ALSA
27 To compile this driver as a module, choose M here: the 29 To compile this driver as a module, choose M here: the
28 module will be called em28xx-alsa 30 module will be called em28xx-alsa
29 31
32config VIDEO_EM28XX_DVB
33 tristate "DVB/ATSC Support for em28xx based TV cards"
34 depends on VIDEO_EM28XX && DVB_CORE
35 select DVB_LGDT330X if !DVB_FE_CUSTOMISE
36 select DVB_ZL10353 if !DVB_FE_CUSTOMISE
37 select VIDEOBUF_DVB
38 select FW_LOADER
39 ---help---
40 This adds support for DVB cards based on the
41 Empiatech em28xx chips.
diff --git a/drivers/media/video/em28xx/Makefile b/drivers/media/video/em28xx/Makefile
index 0924550992d0..3d1c3cc337fe 100644
--- a/drivers/media/video/em28xx/Makefile
+++ b/drivers/media/video/em28xx/Makefile
@@ -5,6 +5,7 @@ em28xx-alsa-objs := em28xx-audio.o
5 5
6obj-$(CONFIG_VIDEO_EM28XX) += em28xx.o 6obj-$(CONFIG_VIDEO_EM28XX) += em28xx.o
7obj-$(CONFIG_VIDEO_EM28XX_ALSA) += em28xx-alsa.o 7obj-$(CONFIG_VIDEO_EM28XX_ALSA) += em28xx-alsa.o
8obj-$(CONFIG_VIDEO_EM28XX_DVB) += em28xx-dvb.o
8 9
9EXTRA_CFLAGS += -Idrivers/media/video 10EXTRA_CFLAGS += -Idrivers/media/video
10EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core 11EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
diff --git a/drivers/media/video/em28xx/em28xx-audio.c b/drivers/media/video/em28xx/em28xx-audio.c
index 8c67f678266a..92b2a6db4fdc 100644
--- a/drivers/media/video/em28xx/em28xx-audio.c
+++ b/drivers/media/video/em28xx/em28xx-audio.c
@@ -51,7 +51,7 @@ MODULE_PARM_DESC(debug, "activates debug info");
51#define dprintk(fmt, arg...) do { \ 51#define dprintk(fmt, arg...) do { \
52 if (debug) \ 52 if (debug) \
53 printk(KERN_INFO "em28xx-audio %s: " fmt, \ 53 printk(KERN_INFO "em28xx-audio %s: " fmt, \
54 __FUNCTION__, ##arg); \ 54 __func__, ##arg); \
55 } while (0) 55 } while (0)
56 56
57static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; 57static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
diff --git a/drivers/media/video/em28xx/em28xx-cards.c b/drivers/media/video/em28xx/em28xx-cards.c
index aae7753fef11..50ccf3771204 100644
--- a/drivers/media/video/em28xx/em28xx-cards.c
+++ b/drivers/media/video/em28xx/em28xx-cards.c
@@ -36,7 +36,6 @@
36#include <media/v4l2-common.h> 36#include <media/v4l2-common.h>
37 37
38#include "em28xx.h" 38#include "em28xx.h"
39#include "tuner-xc2028.h"
40 39
41static int tuner = -1; 40static int tuner = -1;
42module_param(tuner, int, 0444); 41module_param(tuner, int, 0444);
@@ -52,26 +51,6 @@ struct em28xx_hash_table {
52 unsigned int tuner; 51 unsigned int tuner;
53}; 52};
54 53
55/* Boards supported by driver */
56
57#define EM2800_BOARD_UNKNOWN 0
58#define EM2820_BOARD_UNKNOWN 1
59#define EM2820_BOARD_TERRATEC_CINERGY_250 2
60#define EM2820_BOARD_PINNACLE_USB_2 3
61#define EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 4
62#define EM2820_BOARD_MSI_VOX_USB_2 5
63#define EM2800_BOARD_TERRATEC_CINERGY_200 6
64#define EM2800_BOARD_LEADTEK_WINFAST_USBII 7
65#define EM2800_BOARD_KWORLD_USB2800 8
66#define EM2820_BOARD_PINNACLE_DVC_90 9
67#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 10
68#define EM2880_BOARD_TERRATEC_HYBRID_XS 11
69#define EM2820_BOARD_KWORLD_PVRTV2800RF 12
70#define EM2880_BOARD_TERRATEC_PRODIGY_XS 13
71#define EM2820_BOARD_PROLINK_PLAYTV_USB2 14
72#define EM2800_BOARD_VGEAR_POCKETTV 15
73#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950 16
74
75struct em28xx_board em28xx_boards[] = { 54struct em28xx_board em28xx_boards[] = {
76 [EM2800_BOARD_UNKNOWN] = { 55 [EM2800_BOARD_UNKNOWN] = {
77 .name = "Unknown EM2800 video grabber", 56 .name = "Unknown EM2800 video grabber",
@@ -200,6 +179,7 @@ struct em28xx_board em28xx_boards[] = {
200 .tuner_type = TUNER_XC2028, 179 .tuner_type = TUNER_XC2028,
201 .mts_firmware = 1, 180 .mts_firmware = 1,
202 .has_12mhz_i2s = 1, 181 .has_12mhz_i2s = 1,
182 .has_dvb = 1,
203 .decoder = EM28XX_TVP5150, 183 .decoder = EM28XX_TVP5150,
204 .input = { { 184 .input = { {
205 .type = EM28XX_VMUX_TELEVISION, 185 .type = EM28XX_VMUX_TELEVISION,
@@ -214,9 +194,6 @@ struct em28xx_board em28xx_boards[] = {
214 .vmux = TVP5150_SVIDEO, 194 .vmux = TVP5150_SVIDEO,
215 .amux = 1, 195 .amux = 1,
216 } }, 196 } },
217
218 /* gpio's 4, 1, 0 */
219 .analog_gpio = 0x003d2d,
220 }, 197 },
221 [EM2880_BOARD_TERRATEC_HYBRID_XS] = { 198 [EM2880_BOARD_TERRATEC_HYBRID_XS] = {
222 .name = "Terratec Hybrid XS", 199 .name = "Terratec Hybrid XS",
@@ -331,7 +308,7 @@ struct em28xx_board em28xx_boards[] = {
331 .name = "Kworld USB2800", 308 .name = "Kworld USB2800",
332 .is_em2800 = 1, 309 .is_em2800 = 1,
333 .vchannels = 3, 310 .vchannels = 3,
334 .tuner_type = TUNER_PHILIPS_ATSC, 311 .tuner_type = TUNER_PHILIPS_FCV1236D,
335 .tda9887_conf = TDA9887_PRESENT, 312 .tda9887_conf = TDA9887_PRESENT,
336 .decoder = EM28XX_SAA7113, 313 .decoder = EM28XX_SAA7113,
337 .input = { { 314 .input = { {
@@ -453,7 +430,36 @@ struct usb_device_id em28xx_id_table [] = {
453}; 430};
454MODULE_DEVICE_TABLE(usb, em28xx_id_table); 431MODULE_DEVICE_TABLE(usb, em28xx_id_table);
455 432
456/* EEPROM hash table for devices with generic USB IDs */ 433/*
434 * Reset sequences for analog/digital modes
435 */
436
437/* Board Hauppauge WinTV HVR 900 analog */
438static struct em28xx_reg_seq hauppauge_wintv_hvr_900_analog[] = {
439 {EM28XX_R08_GPIO, 0x2d, ~EM_GPIO_4, 10},
440 {0x05, 0xff, 0x10, 10},
441 { -1, -1, -1, -1},
442};
443
444/* Board Hauppauge WinTV HVR 900 digital */
445static struct em28xx_reg_seq hauppauge_wintv_hvr_900_digital[] = {
446 {EM28XX_R08_GPIO, 0x2e, ~EM_GPIO_4, 10},
447 {EM2880_R04_GPO, 0x04, 0x0f, 10},
448 {EM2880_R04_GPO, 0x0c, 0x0f, 10},
449 { -1, -1, -1, -1},
450};
451
452/* Board Hauppauge WinTV HVR 900 tuner_callback */
453static struct em28xx_reg_seq hauppauge_wintv_hvr_900_tuner_callback[] = {
454 {EM28XX_R08_GPIO, EM_GPIO_4, EM_GPIO_4, 10},
455 {EM28XX_R08_GPIO, 0, EM_GPIO_4, 10},
456 {EM28XX_R08_GPIO, EM_GPIO_4, EM_GPIO_4, 10},
457 { -1, -1, -1, -1},
458};
459
460/*
461 * EEPROM hash table for devices with generic USB IDs
462 */
457static struct em28xx_hash_table em28xx_eeprom_hash [] = { 463static struct em28xx_hash_table em28xx_eeprom_hash [] = {
458 /* P/N: SA 60002070465 Tuner: TVF7533-MF */ 464 /* P/N: SA 60002070465 Tuner: TVF7533-MF */
459 {0x6ce05a8f, EM2820_BOARD_PROLINK_PLAYTV_USB2, TUNER_YMEC_TVF_5533MF}, 465 {0x6ce05a8f, EM2820_BOARD_PROLINK_PLAYTV_USB2, TUNER_YMEC_TVF_5533MF},
@@ -465,79 +471,113 @@ static struct em28xx_hash_table em28xx_i2c_hash[] = {
465 {0xf51200e3, EM2800_BOARD_VGEAR_POCKETTV, TUNER_LG_PAL_NEW_TAPC}, 471 {0xf51200e3, EM2800_BOARD_VGEAR_POCKETTV, TUNER_LG_PAL_NEW_TAPC},
466}; 472};
467 473
474int em28xx_tuner_callback(void *ptr, int command, int arg)
475{
476 int rc = 0;
477 struct em28xx *dev = ptr;
478
479 if (dev->tuner_type != TUNER_XC2028)
480 return 0;
481
482 if (command != XC2028_TUNER_RESET)
483 return 0;
484
485 if (dev->mode == EM28XX_ANALOG_MODE)
486 rc = em28xx_gpio_set(dev, dev->tun_analog_gpio);
487 else
488 rc = em28xx_gpio_set(dev, dev->tun_digital_gpio);
489
490 return rc;
491}
492EXPORT_SYMBOL_GPL(em28xx_tuner_callback);
493
494static void em28xx_set_model(struct em28xx *dev)
495{
496 dev->is_em2800 = em28xx_boards[dev->model].is_em2800;
497 dev->has_msp34xx = em28xx_boards[dev->model].has_msp34xx;
498 dev->tda9887_conf = em28xx_boards[dev->model].tda9887_conf;
499 dev->decoder = em28xx_boards[dev->model].decoder;
500 dev->video_inputs = em28xx_boards[dev->model].vchannels;
501 dev->has_12mhz_i2s = em28xx_boards[dev->model].has_12mhz_i2s;
502 dev->max_range_640_480 = em28xx_boards[dev->model].max_range_640_480;
503 dev->has_dvb = em28xx_boards[dev->model].has_dvb;
504}
505
468/* Since em28xx_pre_card_setup() requires a proper dev->model, 506/* Since em28xx_pre_card_setup() requires a proper dev->model,
469 * this won't work for boards with generic PCI IDs 507 * this won't work for boards with generic PCI IDs
470 */ 508 */
471void em28xx_pre_card_setup(struct em28xx *dev) 509void em28xx_pre_card_setup(struct em28xx *dev)
472{ 510{
511 int rc;
512
513 rc = em28xx_read_reg(dev, EM2880_R04_GPO);
514 if (rc >= 0)
515 dev->reg_gpo = rc;
516
517 dev->wait_after_write = 5;
518 rc = em28xx_read_reg(dev, EM28XX_R0A_CHIPID);
519 if (rc > 0) {
520 switch (rc) {
521 case CHIP_ID_EM2883:
522 em28xx_info("chip ID is em2882/em2883\n");
523 dev->wait_after_write = 0;
524 break;
525 default:
526 em28xx_info("em28xx chip ID = %d\n", rc);
527 }
528 }
529 em28xx_set_model(dev);
530
473 /* request some modules */ 531 /* request some modules */
474 switch (dev->model) { 532 switch (dev->model) {
475 case EM2880_BOARD_TERRATEC_PRODIGY_XS: 533 case EM2880_BOARD_TERRATEC_PRODIGY_XS:
476 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900: 534 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
477 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950:
478 case EM2880_BOARD_TERRATEC_HYBRID_XS: 535 case EM2880_BOARD_TERRATEC_HYBRID_XS:
479 em28xx_write_regs(dev, XCLK_REG, "\x27", 1); 536 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950:
480 em28xx_write_regs(dev, I2C_CLK_REG, "\x40", 1); 537 em28xx_write_regs(dev, EM28XX_R0F_XCLK, "\x27", 1);
481 em28xx_write_regs(dev, 0x08, "\xff", 1); 538 em28xx_write_regs(dev, EM28XX_R06_I2C_CLK, "\x40", 1);
482 em28xx_write_regs(dev, 0x04, "\x00", 1);
483 msleep(100);
484 em28xx_write_regs(dev, 0x04, "\x08", 1);
485 msleep(100);
486 em28xx_write_regs(dev, 0x08, "\xff", 1);
487 msleep(50);
488 em28xx_write_regs(dev, 0x08, "\x2d", 1);
489 msleep(50); 539 msleep(50);
490 em28xx_write_regs(dev, 0x08, "\x3d", 1); 540
541 /* Sets GPO/GPIO sequences for this device */
542 dev->analog_gpio = hauppauge_wintv_hvr_900_analog;
543 dev->digital_gpio = hauppauge_wintv_hvr_900_digital;
544 dev->tun_analog_gpio = hauppauge_wintv_hvr_900_tuner_callback;
545 dev->tun_digital_gpio = hauppauge_wintv_hvr_900_tuner_callback;
546
491 break; 547 break;
492 } 548 }
549
550 em28xx_gpio_set(dev, dev->tun_analog_gpio);
551 em28xx_set_mode(dev, EM28XX_ANALOG_MODE);
552
553 /* Unlock device */
554 em28xx_set_mode(dev, EM28XX_MODE_UNDEFINED);
493} 555}
494 556
495static int em28xx_tuner_callback(void *ptr, int command, int arg) 557static void em28xx_setup_xc3028(struct em28xx *dev, struct xc2028_ctrl *ctl)
496{ 558{
497 int rc = 0; 559 memset(ctl, 0, sizeof(*ctl));
498 struct em28xx *dev = ptr;
499 560
500 if (dev->tuner_type != TUNER_XC2028) 561 ctl->fname = XC2028_DEFAULT_FIRMWARE;
501 return 0; 562 ctl->max_len = 64;
502 563 ctl->mts = em28xx_boards[dev->model].mts_firmware;
503 switch (command) {
504 case XC2028_TUNER_RESET:
505 {
506 /* GPIO and initialization codes for analog TV and radio
507 This code should be complemented for DTV, since reset
508 codes are different.
509 */
510
511 dev->em28xx_write_regs_req(dev, 0x00, 0x48, "\x00", 1);
512 dev->em28xx_write_regs_req(dev, 0x00, 0x12, "\x67", 1);
513
514 if (dev->analog_gpio) {
515 char gpio0 = dev->analog_gpio & 0xff;
516 char gpio1 = (dev->analog_gpio >> 8) & 0xff;
517 char gpio4 = dev->analog_gpio >> 24;
518
519 if (gpio4) {
520 dev->em28xx_write_regs(dev, 0x04, &gpio4, 1);
521 msleep(140);
522 }
523
524 msleep(6);
525 dev->em28xx_write_regs(dev, 0x08, &gpio0, 1);
526 msleep(10);
527 dev->em28xx_write_regs(dev, 0x08, &gpio1, 1);
528 msleep(5);
529 }
530 564
565 switch (dev->model) {
566 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
567 ctl->demod = XC3028_FE_ZARLINK456;
531 break; 568 break;
569 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950:
570 /* FIXME: Better to specify the needed IF */
571 ctl->demod = XC3028_FE_DEFAULT;
572 break;
573 default:
574 ctl->demod = XC3028_FE_OREN538;
532 } 575 }
533 }
534 return rc;
535} 576}
536 577
537static void em28xx_config_tuner(struct em28xx *dev) 578static void em28xx_config_tuner(struct em28xx *dev)
538{ 579{
539 struct v4l2_priv_tun_config xc2028_cfg; 580 struct v4l2_priv_tun_config xc2028_cfg;
540 struct xc2028_ctrl ctl;
541 struct tuner_setup tun_setup; 581 struct tuner_setup tun_setup;
542 struct v4l2_frequency f; 582 struct v4l2_frequency f;
543 583
@@ -552,11 +592,9 @@ static void em28xx_config_tuner(struct em28xx *dev)
552 em28xx_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup); 592 em28xx_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup);
553 593
554 if (dev->tuner_type == TUNER_XC2028) { 594 if (dev->tuner_type == TUNER_XC2028) {
555 memset(&ctl, 0, sizeof(ctl)); 595 struct xc2028_ctrl ctl;
556 596
557 ctl.fname = XC2028_DEFAULT_FIRMWARE; 597 em28xx_setup_xc3028(dev, &ctl);
558 ctl.max_len = 64;
559 ctl.mts = em28xx_boards[dev->model].mts_firmware;
560 598
561 xc2028_cfg.tuner = TUNER_XC2028; 599 xc2028_cfg.tuner = TUNER_XC2028;
562 xc2028_cfg.priv = &ctl; 600 xc2028_cfg.priv = &ctl;
@@ -654,19 +692,6 @@ static int em28xx_hint_board(struct em28xx *dev)
654 return -1; 692 return -1;
655} 693}
656 694
657
658static void em28xx_set_model(struct em28xx *dev)
659{
660 dev->is_em2800 = em28xx_boards[dev->model].is_em2800;
661 dev->has_msp34xx = em28xx_boards[dev->model].has_msp34xx;
662 dev->tda9887_conf = em28xx_boards[dev->model].tda9887_conf;
663 dev->decoder = em28xx_boards[dev->model].decoder;
664 dev->video_inputs = em28xx_boards[dev->model].vchannels;
665 dev->analog_gpio = em28xx_boards[dev->model].analog_gpio;
666 dev->has_12mhz_i2s = em28xx_boards[dev->model].has_12mhz_i2s;
667 dev->max_range_640_480 = em28xx_boards[dev->model].max_range_640_480;
668}
669
670/* ----------------------------------------------------------------------- */ 695/* ----------------------------------------------------------------------- */
671void em28xx_set_ir(struct em28xx *dev, struct IR_i2c *ir) 696void em28xx_set_ir(struct em28xx *dev, struct IR_i2c *ir)
672{ 697{
diff --git a/drivers/media/video/em28xx/em28xx-core.c b/drivers/media/video/em28xx/em28xx-core.c
index c1caaa855b99..f8c41d8c74c4 100644
--- a/drivers/media/video/em28xx/em28xx-core.c
+++ b/drivers/media/video/em28xx/em28xx-core.c
@@ -31,104 +31,33 @@
31 31
32/* #define ENABLE_DEBUG_ISOC_FRAMES */ 32/* #define ENABLE_DEBUG_ISOC_FRAMES */
33 33
34static unsigned int core_debug = 0; 34static unsigned int core_debug;
35module_param(core_debug,int,0644); 35module_param(core_debug,int,0644);
36MODULE_PARM_DESC(core_debug,"enable debug messages [core]"); 36MODULE_PARM_DESC(core_debug,"enable debug messages [core]");
37 37
38#define em28xx_coredbg(fmt, arg...) do {\ 38#define em28xx_coredbg(fmt, arg...) do {\
39 if (core_debug) \ 39 if (core_debug) \
40 printk(KERN_INFO "%s %s :"fmt, \ 40 printk(KERN_INFO "%s %s :"fmt, \
41 dev->name, __FUNCTION__ , ##arg); } while (0) 41 dev->name, __func__ , ##arg); } while (0)
42 42
43static unsigned int reg_debug = 0; 43static unsigned int reg_debug;
44module_param(reg_debug,int,0644); 44module_param(reg_debug,int,0644);
45MODULE_PARM_DESC(reg_debug,"enable debug messages [URB reg]"); 45MODULE_PARM_DESC(reg_debug,"enable debug messages [URB reg]");
46 46
47#define em28xx_regdbg(fmt, arg...) do {\ 47#define em28xx_regdbg(fmt, arg...) do {\
48 if (reg_debug) \ 48 if (reg_debug) \
49 printk(KERN_INFO "%s %s :"fmt, \ 49 printk(KERN_INFO "%s %s :"fmt, \
50 dev->name, __FUNCTION__ , ##arg); } while (0) 50 dev->name, __func__ , ##arg); } while (0)
51
52static unsigned int isoc_debug = 0;
53module_param(isoc_debug,int,0644);
54MODULE_PARM_DESC(isoc_debug,"enable debug messages [isoc transfers]");
55
56#define em28xx_isocdbg(fmt, arg...) do {\
57 if (isoc_debug) \
58 printk(KERN_INFO "%s %s :"fmt, \
59 dev->name, __FUNCTION__ , ##arg); } while (0)
60 51
61static int alt = EM28XX_PINOUT; 52static int alt = EM28XX_PINOUT;
62module_param(alt, int, 0644); 53module_param(alt, int, 0644);
63MODULE_PARM_DESC(alt, "alternate setting to use for video endpoint"); 54MODULE_PARM_DESC(alt, "alternate setting to use for video endpoint");
64 55
65 56/* FIXME */
66/* 57#define em28xx_isocdbg(fmt, arg...) do {\
67 * em28xx_request_buffers() 58 if (core_debug) \
68 * allocate a number of buffers 59 printk(KERN_INFO "%s %s :"fmt, \
69 */ 60 dev->name, __func__ , ##arg); } while (0)
70u32 em28xx_request_buffers(struct em28xx *dev, u32 count)
71{
72 const size_t imagesize = PAGE_ALIGN(dev->frame_size); /*needs to be page aligned cause the buffers can be mapped individually! */
73 void *buff = NULL;
74 u32 i;
75 em28xx_coredbg("requested %i buffers with size %zi\n",
76 count, imagesize);
77 if (count > EM28XX_NUM_FRAMES)
78 count = EM28XX_NUM_FRAMES;
79
80 dev->num_frames = count;
81 while (dev->num_frames > 0) {
82 if ((buff = vmalloc_32(dev->num_frames * imagesize))) {
83 memset(buff, 0, dev->num_frames * imagesize);
84 break;
85 }
86 dev->num_frames--;
87 }
88
89 for (i = 0; i < dev->num_frames; i++) {
90 dev->frame[i].bufmem = buff + i * imagesize;
91 dev->frame[i].buf.index = i;
92 dev->frame[i].buf.m.offset = i * imagesize;
93 dev->frame[i].buf.length = dev->frame_size;
94 dev->frame[i].buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
95 dev->frame[i].buf.sequence = 0;
96 dev->frame[i].buf.field = V4L2_FIELD_NONE;
97 dev->frame[i].buf.memory = V4L2_MEMORY_MMAP;
98 dev->frame[i].buf.flags = 0;
99 }
100 return dev->num_frames;
101}
102
103/*
104 * em28xx_queue_unusedframes()
105 * add all frames that are not currently in use to the inbuffer queue
106 */
107void em28xx_queue_unusedframes(struct em28xx *dev)
108{
109 unsigned long lock_flags;
110 u32 i;
111
112 for (i = 0; i < dev->num_frames; i++)
113 if (dev->frame[i].state == F_UNUSED) {
114 dev->frame[i].state = F_QUEUED;
115 spin_lock_irqsave(&dev->queue_lock, lock_flags);
116 list_add_tail(&dev->frame[i].frame, &dev->inqueue);
117 spin_unlock_irqrestore(&dev->queue_lock, lock_flags);
118 }
119}
120
121/*
122 * em28xx_release_buffers()
123 * free frame buffers
124 */
125void em28xx_release_buffers(struct em28xx *dev)
126{
127 if (dev->num_frames) {
128 vfree(dev->frame[0].bufmem);
129 dev->num_frames = 0;
130 }
131}
132 61
133/* 62/*
134 * em28xx_read_reg_req() 63 * em28xx_read_reg_req()
@@ -148,11 +77,11 @@ int em28xx_read_reg_req_len(struct em28xx *dev, u8 req, u16 reg,
148 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 77 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
149 0x0000, reg, buf, len, HZ); 78 0x0000, reg, buf, len, HZ);
150 79
151 if (reg_debug){ 80 if (reg_debug) {
152 printk(ret < 0 ? " failed!\n" : "%02x values: ", ret); 81 printk(ret < 0 ? " failed!\n" : "%02x values: ", ret);
153 for (byte = 0; byte < len; byte++) { 82 for (byte = 0; byte < len; byte++)
154 printk(" %02x", (unsigned char)buf[byte]); 83 printk(" %02x", (unsigned char)buf[byte]);
155 } 84
156 printk("\n"); 85 printk("\n");
157 } 86 }
158 87
@@ -205,7 +134,10 @@ int em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf,
205 unsigned char *bufs; 134 unsigned char *bufs;
206 135
207 if (dev->state & DEV_DISCONNECTED) 136 if (dev->state & DEV_DISCONNECTED)
208 return(-ENODEV); 137 return -ENODEV;
138
139 if (len < 1)
140 return -EINVAL;
209 141
210 bufs = kmalloc(len, GFP_KERNEL); 142 bufs = kmalloc(len, GFP_KERNEL);
211 143
@@ -214,8 +146,8 @@ int em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf,
214 if (reg_debug) { 146 if (reg_debug) {
215 int i; 147 int i;
216 for (i = 0; i < len; ++i) 148 for (i = 0; i < len; ++i)
217 printk (" %02x", (unsigned char)buf[i]); 149 printk(" %02x", (unsigned char)buf[i]);
218 printk ("\n"); 150 printk("\n");
219 } 151 }
220 152
221 if (!bufs) 153 if (!bufs)
@@ -224,14 +156,32 @@ int em28xx_write_regs_req(struct em28xx *dev, u8 req, u16 reg, char *buf,
224 ret = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), req, 156 ret = usb_control_msg(dev->udev, usb_sndctrlpipe(dev->udev, 0), req,
225 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 157 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
226 0x0000, reg, bufs, len, HZ); 158 0x0000, reg, bufs, len, HZ);
227 msleep(5); /* FIXME: magic number */ 159 if (dev->wait_after_write)
160 msleep(dev->wait_after_write);
161
228 kfree(bufs); 162 kfree(bufs);
229 return ret; 163 return ret;
230} 164}
231 165
232int em28xx_write_regs(struct em28xx *dev, u16 reg, char *buf, int len) 166int em28xx_write_regs(struct em28xx *dev, u16 reg, char *buf, int len)
233{ 167{
234 return em28xx_write_regs_req(dev, USB_REQ_GET_STATUS, reg, buf, len); 168 int rc;
169
170 rc = em28xx_write_regs_req(dev, USB_REQ_GET_STATUS, reg, buf, len);
171
172 /* Stores GPO/GPIO values at the cache, if changed
173 Only write values should be stored, since input on a GPIO
174 register will return the input bits.
175 Not sure what happens on reading GPO register.
176 */
177 if (rc >= 0) {
178 if (reg == EM2880_R04_GPO)
179 dev->reg_gpo = buf[0];
180 else if (reg == EM28XX_R08_GPIO)
181 dev->reg_gpio = buf[0];
182 }
183
184 return rc;
235} 185}
236 186
237/* 187/*
@@ -244,9 +194,20 @@ static int em28xx_write_reg_bits(struct em28xx *dev, u16 reg, u8 val,
244{ 194{
245 int oldval; 195 int oldval;
246 u8 newval; 196 u8 newval;
247 if ((oldval = em28xx_read_reg(dev, reg)) < 0) 197
198 /* Uses cache for gpo/gpio registers */
199 if (reg == EM2880_R04_GPO)
200 oldval = dev->reg_gpo;
201 else if (reg == EM28XX_R08_GPIO)
202 oldval = dev->reg_gpio;
203 else
204 oldval = em28xx_read_reg(dev, reg);
205
206 if (oldval < 0)
248 return oldval; 207 return oldval;
208
249 newval = (((u8) oldval) & ~bitmask) | (val & bitmask); 209 newval = (((u8) oldval) & ~bitmask) | (val & bitmask);
210
250 return em28xx_write_regs(dev, reg, &newval, 1); 211 return em28xx_write_regs(dev, reg, &newval, 1);
251} 212}
252 213
@@ -258,20 +219,26 @@ static int em28xx_write_ac97(struct em28xx *dev, u8 reg, u8 *val)
258{ 219{
259 int ret, i; 220 int ret, i;
260 u8 addr = reg & 0x7f; 221 u8 addr = reg & 0x7f;
261 if ((ret = em28xx_write_regs(dev, AC97LSB_REG, val, 2)) < 0) 222
223 ret = em28xx_write_regs(dev, EM28XX_R40_AC97LSB, val, 2);
224 if (ret < 0)
262 return ret; 225 return ret;
263 if ((ret = em28xx_write_regs(dev, AC97ADDR_REG, &addr, 1)) < 0) 226
227 ret = em28xx_write_regs(dev, EM28XX_R42_AC97ADDR, &addr, 1);
228 if (ret < 0)
264 return ret; 229 return ret;
265 230
266 /* Wait up to 50 ms for AC97 command to complete */ 231 /* Wait up to 50 ms for AC97 command to complete */
267 for (i = 0; i < 10; i++) { 232 for (i = 0; i < 10; i++) {
268 if ((ret = em28xx_read_reg(dev, AC97BUSY_REG)) < 0) 233 ret = em28xx_read_reg(dev, EM28XX_R43_AC97BUSY);
234 if (ret < 0)
269 return ret; 235 return ret;
236
270 if (!(ret & 0x01)) 237 if (!(ret & 0x01))
271 return 0; 238 return 0;
272 msleep(5); 239 msleep(5);
273 } 240 }
274 em28xx_warn ("AC97 command still being executed: not handled properly!\n"); 241 em28xx_warn("AC97 command still being executed: not handled properly!\n");
275 return 0; 242 return 0;
276} 243}
277 244
@@ -289,7 +256,7 @@ static int em28xx_set_audio_source(struct em28xx *dev)
289 else 256 else
290 input = EM2800_AUDIO_SRC_TUNER; 257 input = EM2800_AUDIO_SRC_TUNER;
291 258
292 ret = em28xx_write_regs(dev, EM2800_AUDIOSRC_REG, &input, 1); 259 ret = em28xx_write_regs(dev, EM2800_R08_AUDIOSRC, &input, 1);
293 if (ret < 0) 260 if (ret < 0)
294 return ret; 261 return ret;
295 } 262 }
@@ -315,7 +282,7 @@ static int em28xx_set_audio_source(struct em28xx *dev)
315 } 282 }
316 } 283 }
317 284
318 ret = em28xx_write_reg_bits(dev, AUDIOSRC_REG, input, 0xc0); 285 ret = em28xx_write_reg_bits(dev, EM28XX_R0E_AUDIOSRC, input, 0xc0);
319 if (ret < 0) 286 if (ret < 0)
320 return ret; 287 return ret;
321 msleep(5); 288 msleep(5);
@@ -323,11 +290,11 @@ static int em28xx_set_audio_source(struct em28xx *dev)
323 /* Sets AC97 mixer registers 290 /* Sets AC97 mixer registers
324 This is seems to be needed, even for non-ac97 configs 291 This is seems to be needed, even for non-ac97 configs
325 */ 292 */
326 ret = em28xx_write_ac97(dev, VIDEO_AC97, video); 293 ret = em28xx_write_ac97(dev, EM28XX_R14_VIDEO_AC97, video);
327 if (ret < 0) 294 if (ret < 0)
328 return ret; 295 return ret;
329 296
330 ret = em28xx_write_ac97(dev, LINE_IN_AC97, line); 297 ret = em28xx_write_ac97(dev, EM28XX_R10_LINE_IN_AC97, line);
331 298
332 return ret; 299 return ret;
333} 300}
@@ -343,7 +310,7 @@ int em28xx_audio_analog_set(struct em28xx *dev)
343 310
344 /* Mute */ 311 /* Mute */
345 s[1] |= 0x80; 312 s[1] |= 0x80;
346 ret = em28xx_write_ac97(dev, MASTER_AC97, s); 313 ret = em28xx_write_ac97(dev, EM28XX_R02_MASTER_AC97, s);
347 314
348 if (ret < 0) 315 if (ret < 0)
349 return ret; 316 return ret;
@@ -354,7 +321,7 @@ int em28xx_audio_analog_set(struct em28xx *dev)
354 if (!dev->mute) 321 if (!dev->mute)
355 xclk |= 0x80; 322 xclk |= 0x80;
356 323
357 ret = em28xx_write_reg_bits(dev, XCLK_REG, xclk, 0xa7); 324 ret = em28xx_write_reg_bits(dev, EM28XX_R0F_XCLK, xclk, 0xa7);
358 if (ret < 0) 325 if (ret < 0)
359 return ret; 326 return ret;
360 msleep(10); 327 msleep(10);
@@ -365,7 +332,7 @@ int em28xx_audio_analog_set(struct em28xx *dev)
365 /* Unmute device */ 332 /* Unmute device */
366 if (!dev->mute) 333 if (!dev->mute)
367 s[1] &= ~0x80; 334 s[1] &= ~0x80;
368 ret = em28xx_write_ac97(dev, MASTER_AC97, s); 335 ret = em28xx_write_ac97(dev, EM28XX_R02_MASTER_AC97, s);
369 336
370 return ret; 337 return ret;
371} 338}
@@ -373,50 +340,68 @@ EXPORT_SYMBOL_GPL(em28xx_audio_analog_set);
373 340
374int em28xx_colorlevels_set_default(struct em28xx *dev) 341int em28xx_colorlevels_set_default(struct em28xx *dev)
375{ 342{
376 em28xx_write_regs(dev, YGAIN_REG, "\x10", 1); /* contrast */ 343 em28xx_write_regs(dev, EM28XX_R20_YGAIN, "\x10", 1); /* contrast */
377 em28xx_write_regs(dev, YOFFSET_REG, "\x00", 1); /* brightness */ 344 em28xx_write_regs(dev, EM28XX_R21_YOFFSET, "\x00", 1); /* brightness */
378 em28xx_write_regs(dev, UVGAIN_REG, "\x10", 1); /* saturation */ 345 em28xx_write_regs(dev, EM28XX_R22_UVGAIN, "\x10", 1); /* saturation */
379 em28xx_write_regs(dev, UOFFSET_REG, "\x00", 1); 346 em28xx_write_regs(dev, EM28XX_R23_UOFFSET, "\x00", 1);
380 em28xx_write_regs(dev, VOFFSET_REG, "\x00", 1); 347 em28xx_write_regs(dev, EM28XX_R24_VOFFSET, "\x00", 1);
381 em28xx_write_regs(dev, SHARPNESS_REG, "\x00", 1); 348 em28xx_write_regs(dev, EM28XX_R25_SHARPNESS, "\x00", 1);
382 349
383 em28xx_write_regs(dev, GAMMA_REG, "\x20", 1); 350 em28xx_write_regs(dev, EM28XX_R14_GAMMA, "\x20", 1);
384 em28xx_write_regs(dev, RGAIN_REG, "\x20", 1); 351 em28xx_write_regs(dev, EM28XX_R15_RGAIN, "\x20", 1);
385 em28xx_write_regs(dev, GGAIN_REG, "\x20", 1); 352 em28xx_write_regs(dev, EM28XX_R16_GGAIN, "\x20", 1);
386 em28xx_write_regs(dev, BGAIN_REG, "\x20", 1); 353 em28xx_write_regs(dev, EM28XX_R17_BGAIN, "\x20", 1);
387 em28xx_write_regs(dev, ROFFSET_REG, "\x00", 1); 354 em28xx_write_regs(dev, EM28XX_R18_ROFFSET, "\x00", 1);
388 em28xx_write_regs(dev, GOFFSET_REG, "\x00", 1); 355 em28xx_write_regs(dev, EM28XX_R19_GOFFSET, "\x00", 1);
389 return em28xx_write_regs(dev, BOFFSET_REG, "\x00", 1); 356 return em28xx_write_regs(dev, EM28XX_R1A_BOFFSET, "\x00", 1);
390} 357}
391 358
392int em28xx_capture_start(struct em28xx *dev, int start) 359int em28xx_capture_start(struct em28xx *dev, int start)
393{ 360{
394 int ret; 361 int rc;
395 /* FIXME: which is the best order? */ 362 /* FIXME: which is the best order? */
396 /* video registers are sampled by VREF */ 363 /* video registers are sampled by VREF */
397 if ((ret = em28xx_write_reg_bits(dev, USBSUSP_REG, start ? 0x10 : 0x00, 364 rc = em28xx_write_reg_bits(dev, EM28XX_R0C_USBSUSP,
398 0x10)) < 0) 365 start ? 0x10 : 0x00, 0x10);
399 return ret; 366 if (rc < 0)
367 return rc;
368
369 if (!start) {
370 /* disable video capture */
371 rc = em28xx_write_regs(dev, EM28XX_R12_VINENABLE, "\x27", 1);
372 return rc;
373 }
374
400 /* enable video capture */ 375 /* enable video capture */
401 return em28xx_write_regs(dev, VINENABLE_REG, start ? "\x67" : "\x27", 1); 376 rc = em28xx_write_regs_req(dev, 0x00, 0x48, "\x00", 1);
377
378 if (dev->mode == EM28XX_ANALOG_MODE)
379 rc = em28xx_write_regs(dev, EM28XX_R12_VINENABLE, "\x67", 1);
380 else
381 rc = em28xx_write_regs(dev, EM28XX_R12_VINENABLE, "\x37", 1);
382
383 msleep(6);
384
385 return rc;
402} 386}
403 387
404int em28xx_outfmt_set_yuv422(struct em28xx *dev) 388int em28xx_outfmt_set_yuv422(struct em28xx *dev)
405{ 389{
406 em28xx_write_regs(dev, OUTFMT_REG, "\x34", 1); 390 em28xx_write_regs(dev, EM28XX_R27_OUTFMT, "\x34", 1);
407 em28xx_write_regs(dev, VINMODE_REG, "\x10", 1); 391 em28xx_write_regs(dev, EM28XX_R10_VINMODE, "\x10", 1);
408 return em28xx_write_regs(dev, VINCTRL_REG, "\x11", 1); 392 return em28xx_write_regs(dev, EM28XX_R11_VINCTRL, "\x11", 1);
409} 393}
410 394
411static int em28xx_accumulator_set(struct em28xx *dev, u8 xmin, u8 xmax, 395static int em28xx_accumulator_set(struct em28xx *dev, u8 xmin, u8 xmax,
412 u8 ymin, u8 ymax) 396 u8 ymin, u8 ymax)
413{ 397{
414 em28xx_coredbg("em28xx Scale: (%d,%d)-(%d,%d)\n", xmin, ymin, xmax, ymax); 398 em28xx_coredbg("em28xx Scale: (%d,%d)-(%d,%d)\n",
399 xmin, ymin, xmax, ymax);
415 400
416 em28xx_write_regs(dev, XMIN_REG, &xmin, 1); 401 em28xx_write_regs(dev, EM28XX_R28_XMIN, &xmin, 1);
417 em28xx_write_regs(dev, XMAX_REG, &xmax, 1); 402 em28xx_write_regs(dev, EM28XX_R29_XMAX, &xmax, 1);
418 em28xx_write_regs(dev, YMIN_REG, &ymin, 1); 403 em28xx_write_regs(dev, EM28XX_R2A_YMIN, &ymin, 1);
419 return em28xx_write_regs(dev, YMAX_REG, &ymax, 1); 404 return em28xx_write_regs(dev, EM28XX_R2B_YMAX, &ymax, 1);
420} 405}
421 406
422static int em28xx_capture_area_set(struct em28xx *dev, u8 hstart, u8 vstart, 407static int em28xx_capture_area_set(struct em28xx *dev, u8 hstart, u8 vstart,
@@ -426,34 +411,36 @@ static int em28xx_capture_area_set(struct em28xx *dev, u8 hstart, u8 vstart,
426 u8 cheight = height; 411 u8 cheight = height;
427 u8 overflow = (height >> 7 & 0x02) | (width >> 8 & 0x01); 412 u8 overflow = (height >> 7 & 0x02) | (width >> 8 & 0x01);
428 413
429 em28xx_coredbg("em28xx Area Set: (%d,%d)\n", (width | (overflow & 2) << 7), 414 em28xx_coredbg("em28xx Area Set: (%d,%d)\n",
415 (width | (overflow & 2) << 7),
430 (height | (overflow & 1) << 8)); 416 (height | (overflow & 1) << 8));
431 417
432 em28xx_write_regs(dev, HSTART_REG, &hstart, 1); 418 em28xx_write_regs(dev, EM28XX_R1C_HSTART, &hstart, 1);
433 em28xx_write_regs(dev, VSTART_REG, &vstart, 1); 419 em28xx_write_regs(dev, EM28XX_R1D_VSTART, &vstart, 1);
434 em28xx_write_regs(dev, CWIDTH_REG, &cwidth, 1); 420 em28xx_write_regs(dev, EM28XX_R1E_CWIDTH, &cwidth, 1);
435 em28xx_write_regs(dev, CHEIGHT_REG, &cheight, 1); 421 em28xx_write_regs(dev, EM28XX_R1F_CHEIGHT, &cheight, 1);
436 return em28xx_write_regs(dev, OFLOW_REG, &overflow, 1); 422 return em28xx_write_regs(dev, EM28XX_R1B_OFLOW, &overflow, 1);
437} 423}
438 424
439static int em28xx_scaler_set(struct em28xx *dev, u16 h, u16 v) 425static int em28xx_scaler_set(struct em28xx *dev, u16 h, u16 v)
440{ 426{
441 u8 mode; 427 u8 mode;
442 /* the em2800 scaler only supports scaling down to 50% */ 428 /* the em2800 scaler only supports scaling down to 50% */
443 if(dev->is_em2800) 429 if (dev->is_em2800)
444 mode = (v ? 0x20 : 0x00) | (h ? 0x10 : 0x00); 430 mode = (v ? 0x20 : 0x00) | (h ? 0x10 : 0x00);
445 else { 431 else {
446 u8 buf[2]; 432 u8 buf[2];
447 buf[0] = h; 433 buf[0] = h;
448 buf[1] = h >> 8; 434 buf[1] = h >> 8;
449 em28xx_write_regs(dev, HSCALELOW_REG, (char *)buf, 2); 435 em28xx_write_regs(dev, EM28XX_R30_HSCALELOW, (char *)buf, 2);
450 buf[0] = v; 436 buf[0] = v;
451 buf[1] = v >> 8; 437 buf[1] = v >> 8;
452 em28xx_write_regs(dev, VSCALELOW_REG, (char *)buf, 2); 438 em28xx_write_regs(dev, EM28XX_R32_VSCALELOW, (char *)buf, 2);
453 /* it seems that both H and V scalers must be active to work correctly */ 439 /* it seems that both H and V scalers must be active
440 to work correctly */
454 mode = (h || v)? 0x30: 0x00; 441 mode = (h || v)? 0x30: 0x00;
455 } 442 }
456 return em28xx_write_reg_bits(dev, COMPR_REG, mode, 0x30); 443 return em28xx_write_reg_bits(dev, EM28XX_R26_COMPR, mode, 0x30);
457} 444}
458 445
459/* FIXME: this only function read values from dev */ 446/* FIXME: this only function read values from dev */
@@ -469,376 +456,271 @@ int em28xx_resolution_set(struct em28xx *dev)
469 return em28xx_scaler_set(dev, dev->hscale, dev->vscale); 456 return em28xx_scaler_set(dev, dev->hscale, dev->vscale);
470} 457}
471 458
472 459int em28xx_set_alternate(struct em28xx *dev)
473/******************* isoc transfer handling ****************************/
474
475#ifdef ENABLE_DEBUG_ISOC_FRAMES
476static void em28xx_isoc_dump(struct urb *urb)
477{ 460{
478 int len = 0; 461 int errCode, prev_alt = dev->alt;
479 int ntrans = 0;
480 int i; 462 int i;
463 unsigned int min_pkt_size = dev->width * 2 + 4;
481 464
482 printk(KERN_DEBUG "isocIrq: sf=%d np=%d ec=%x\n", 465 /* When image size is bigger than a certain value,
483 urb->start_frame, urb->number_of_packets, 466 the frame size should be increased, otherwise, only
484 urb->error_count); 467 green screen will be received.
485 for (i = 0; i < urb->number_of_packets; i++) { 468 */
486 unsigned char *buf = 469 if (dev->width * 2 * dev->height > 720 * 240 * 2)
487 urb->transfer_buffer + 470 min_pkt_size *= 2;
488 urb->iso_frame_desc[i].offset; 471
489 int alen = urb->iso_frame_desc[i].actual_length; 472 for (i = 0; i < dev->num_alt; i++) {
490 if (alen > 0) { 473 /* stop when the selected alt setting offers enough bandwidth */
491 if (buf[0] == 0x88) { 474 if (dev->alt_max_pkt_size[i] >= min_pkt_size) {
492 ntrans++; 475 dev->alt = i;
493 len += alen; 476 break;
494 } else if (buf[0] == 0x22) { 477 /* otherwise make sure that we end up with the maximum bandwidth
495 printk(KERN_DEBUG 478 because the min_pkt_size equation might be wrong...
496 "= l=%d nt=%d bpp=%d\n", 479 */
497 len - 4 * ntrans, ntrans, 480 } else if (dev->alt_max_pkt_size[i] >
498 ntrans == 0 ? 0 : len / ntrans); 481 dev->alt_max_pkt_size[dev->alt])
499 ntrans = 1; 482 dev->alt = i;
500 len = alen; 483 }
501 } else 484
502 printk(KERN_DEBUG "!\n"); 485 if (dev->alt != prev_alt) {
486 em28xx_coredbg("minimum isoc packet size: %u (alt=%d)\n",
487 min_pkt_size, dev->alt);
488 dev->max_pkt_size = dev->alt_max_pkt_size[dev->alt];
489 em28xx_coredbg("setting alternate %d with wMaxPacketSize=%u\n",
490 dev->alt, dev->max_pkt_size);
491 errCode = usb_set_interface(dev->udev, 0, dev->alt);
492 if (errCode < 0) {
493 em28xx_errdev("cannot change alternate number to %d (error=%i)\n",
494 dev->alt, errCode);
495 return errCode;
503 } 496 }
504 printk(KERN_DEBUG " n=%d s=%d al=%d %x\n", i,
505 urb->iso_frame_desc[i].status,
506 urb->iso_frame_desc[i].actual_length,
507 (unsigned int)
508 *((unsigned char *)(urb->transfer_buffer +
509 urb->iso_frame_desc[i].
510 offset)));
511 } 497 }
498 return 0;
512} 499}
513#endif
514 500
515static inline int em28xx_isoc_video(struct em28xx *dev,struct em28xx_frame_t **f, 501int em28xx_gpio_set(struct em28xx *dev, struct em28xx_reg_seq *gpio)
516 unsigned long *lock_flags, unsigned char buf)
517{ 502{
518 if (!(buf & 0x01)) { 503 int rc = 0;
519 if ((*f)->state == F_GRABBING) { 504
520 /*previous frame is incomplete */ 505 if (!gpio)
521 if ((*f)->fieldbytesused < dev->field_size) { 506 return rc;
522 (*f)->state = F_ERROR; 507
523 em28xx_isocdbg ("dropping incomplete bottom field (%i missing bytes)", 508 dev->em28xx_write_regs_req(dev, 0x00, 0x48, "\x00", 1);
524 dev->field_size-(*f)->fieldbytesused); 509 if (dev->mode == EM28XX_ANALOG_MODE)
525 } else { 510 dev->em28xx_write_regs_req(dev, 0x00, 0x12, "\x67", 1);
526 (*f)->state = F_DONE; 511 else
527 (*f)->buf.bytesused = dev->frame_size; 512 dev->em28xx_write_regs_req(dev, 0x00, 0x12, "\x37", 1);
528 } 513 msleep(6);
529 } 514
530 if ((*f)->state == F_DONE || (*f)->state == F_ERROR) { 515 /* Send GPIO reset sequences specified at board entry */
531 /* move current frame to outqueue and get next free buffer from inqueue */ 516 while (gpio->sleep >= 0) {
532 spin_lock_irqsave(&dev-> queue_lock, *lock_flags); 517 if (gpio->reg >= 0) {
533 list_move_tail(&(*f)->frame, &dev->outqueue); 518 rc = em28xx_write_reg_bits(dev,
534 if (!list_empty(&dev->inqueue)) 519 gpio->reg,
535 (*f) = list_entry(dev-> inqueue.next, 520 gpio->val,
536 struct em28xx_frame_t,frame); 521 gpio->mask);
537 else 522 if (rc < 0)
538 (*f) = NULL; 523 return rc;
539 spin_unlock_irqrestore(&dev->queue_lock,*lock_flags);
540 }
541 if (!(*f)) {
542 em28xx_isocdbg ("new frame but no buffer is free");
543 return -1;
544 }
545 do_gettimeofday(&(*f)->buf.timestamp);
546 (*f)->buf.sequence = ++dev->frame_count;
547 (*f)->buf.field = V4L2_FIELD_INTERLACED;
548 (*f)->state = F_GRABBING;
549 (*f)->buf.bytesused = 0;
550 (*f)->top_field = 1;
551 (*f)->fieldbytesused = 0;
552 } else {
553 /* acquiring bottom field */
554 if ((*f)->state == F_GRABBING) {
555 if (!(*f)->top_field) {
556 (*f)->state = F_ERROR;
557 em28xx_isocdbg ("unexpected begin of bottom field; discarding it");
558 } else if ((*f)-> fieldbytesused < dev->field_size - 172) {
559 (*f)->state = F_ERROR;
560 em28xx_isocdbg ("dropping incomplete top field (%i missing bytes)",
561 dev->field_size-(*f)->fieldbytesused);
562 } else {
563 (*f)->top_field = 0;
564 (*f)->fieldbytesused = 0;
565 }
566 } 524 }
525 if (gpio->sleep > 0)
526 msleep(gpio->sleep);
527
528 gpio++;
567 } 529 }
568 return (0); 530 return rc;
569} 531}
570 532
571static inline void em28xx_isoc_video_copy(struct em28xx *dev, 533int em28xx_set_mode(struct em28xx *dev, enum em28xx_mode set_mode)
572 struct em28xx_frame_t **f, unsigned char *buf, int len)
573{ 534{
574 void *fieldstart, *startwrite, *startread; 535 if (dev->mode == set_mode)
575 int linesdone, currlinedone, offset, lencopy,remain; 536 return 0;
576 537
577 if(dev->frame_size != (*f)->buf.length){ 538 if (set_mode == EM28XX_MODE_UNDEFINED) {
578 em28xx_err("frame_size %i and buf.length %i are different!!!\n",dev->frame_size,(*f)->buf.length); 539 dev->mode = set_mode;
579 return; 540 return 0;
580 } 541 }
581 542
582 if ((*f)->fieldbytesused + len > dev->field_size) 543 dev->mode = set_mode;
583 len =dev->field_size - (*f)->fieldbytesused;
584
585 if (buf[0] != 0x88 && buf[0] != 0x22) {
586 em28xx_isocdbg("frame is not complete\n");
587 startread = buf;
588 len+=4;
589 } else
590 startread = buf + 4;
591
592 remain = len;
593 544
594 if ((*f)->top_field) 545 if (dev->mode == EM28XX_DIGITAL_MODE)
595 fieldstart = (*f)->bufmem; 546 return em28xx_gpio_set(dev, dev->digital_gpio);
596 else 547 else
597 fieldstart = (*f)->bufmem + dev->bytesperline; 548 return em28xx_gpio_set(dev, dev->analog_gpio);
598
599 linesdone = (*f)->fieldbytesused / dev->bytesperline;
600 currlinedone = (*f)->fieldbytesused % dev->bytesperline;
601 offset = linesdone * dev->bytesperline * 2 + currlinedone;
602 startwrite = fieldstart + offset;
603 lencopy = dev->bytesperline - currlinedone;
604 lencopy = lencopy > remain ? remain : lencopy;
605
606 memcpy(startwrite, startread, lencopy);
607 remain -= lencopy;
608
609 while (remain > 0) {
610 startwrite += lencopy + dev->bytesperline;
611 startread += lencopy;
612 if (dev->bytesperline > remain)
613 lencopy = remain;
614 else
615 lencopy = dev->bytesperline;
616
617 memcpy(startwrite, startread, lencopy);
618 remain -= lencopy;
619 }
620
621 (*f)->fieldbytesused += len;
622} 549}
550EXPORT_SYMBOL_GPL(em28xx_set_mode);
551
552/* ------------------------------------------------------------------
553 URB control
554 ------------------------------------------------------------------*/
623 555
624/* 556/*
625 * em28xx_isoIrq() 557 * IRQ callback, called by URB callback
626 * handles the incoming isoc urbs and fills the frames from our inqueue
627 */ 558 */
628static void em28xx_isocIrq(struct urb *urb) 559static void em28xx_irq_callback(struct urb *urb)
629{ 560{
630 struct em28xx *dev = urb->context; 561 struct em28xx_dmaqueue *dma_q = urb->context;
631 int i, status; 562 struct em28xx *dev = container_of(dma_q, struct em28xx, vidq);
632 struct em28xx_frame_t **f; 563 int rc, i;
633 unsigned long lock_flags;
634
635 if (!dev)
636 return;
637#ifdef ENABLE_DEBUG_ISOC_FRAMES
638 if (isoc_debug>1)
639 em28xx_isoc_dump(urb);
640#endif
641
642 if (urb->status == -ENOENT)
643 return;
644
645 f = &dev->frame_current;
646
647 if (dev->stream == STREAM_INTERRUPT) {
648 dev->stream = STREAM_OFF;
649 if ((*f))
650 (*f)->state = F_QUEUED;
651 em28xx_isocdbg("stream interrupted");
652 wake_up_interruptible(&dev->wait_stream);
653 }
654
655 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED))
656 return;
657
658 if (dev->stream == STREAM_ON && !list_empty(&dev->inqueue)) {
659 if (!(*f))
660 (*f) = list_entry(dev->inqueue.next,
661 struct em28xx_frame_t, frame);
662
663 for (i = 0; i < urb->number_of_packets; i++) {
664 unsigned char *buf = urb->transfer_buffer +
665 urb->iso_frame_desc[i].offset;
666 int len = urb->iso_frame_desc[i].actual_length - 4;
667
668 if (urb->iso_frame_desc[i].status) {
669 em28xx_isocdbg("data error: [%d] len=%d, status=%d", i,
670 urb->iso_frame_desc[i].actual_length,
671 urb->iso_frame_desc[i].status);
672 if (urb->iso_frame_desc[i].status != -EPROTO)
673 continue;
674 }
675 if (urb->iso_frame_desc[i].actual_length <= 0) {
676 em28xx_isocdbg("packet %d is empty",i);
677 continue;
678 }
679 if (urb->iso_frame_desc[i].actual_length >
680 urb->iso_frame_desc[i].length) {
681 em28xx_isocdbg("packet bigger than packet size");
682 continue;
683 }
684 /*new frame */
685 if (buf[0] == 0x22 && buf[1] == 0x5a) {
686 em28xx_isocdbg("Video frame, length=%i!",len);
687
688 if (em28xx_isoc_video(dev,f,&lock_flags,buf[2]))
689 break;
690 } else if (buf[0]==0x33 && buf[1]==0x95 && buf[2]==0x00) {
691 em28xx_isocdbg("VBI HEADER!!!");
692 }
693 564
694 /* actual copying */ 565 /* Copy data from URB */
695 if ((*f)->state == F_GRABBING) { 566 spin_lock(&dev->slock);
696 em28xx_isoc_video_copy(dev,f,buf, len); 567 rc = dev->isoc_ctl.isoc_copy(dev, urb);
697 } 568 spin_unlock(&dev->slock);
698 }
699 }
700 569
570 /* Reset urb buffers */
701 for (i = 0; i < urb->number_of_packets; i++) { 571 for (i = 0; i < urb->number_of_packets; i++) {
702 urb->iso_frame_desc[i].status = 0; 572 urb->iso_frame_desc[i].status = 0;
703 urb->iso_frame_desc[i].actual_length = 0; 573 urb->iso_frame_desc[i].actual_length = 0;
704 } 574 }
705
706 urb->status = 0; 575 urb->status = 0;
707 if ((status = usb_submit_urb(urb, GFP_ATOMIC))) { 576
708 em28xx_errdev("resubmit of urb failed (error=%i)\n", status); 577 urb->status = usb_submit_urb(urb, GFP_ATOMIC);
709 dev->state |= DEV_MISCONFIGURED; 578 if (urb->status) {
579 em28xx_isocdbg("urb resubmit failed (error=%i)\n",
580 urb->status);
710 } 581 }
711 wake_up_interruptible(&dev->wait_frame);
712 return;
713} 582}
714 583
715/* 584/*
716 * em28xx_uninit_isoc() 585 * Stop and Deallocate URBs
717 * deallocates the buffers and urbs allocated during em28xx_init_iosc()
718 */ 586 */
719void em28xx_uninit_isoc(struct em28xx *dev) 587void em28xx_uninit_isoc(struct em28xx *dev)
720{ 588{
589 struct urb *urb;
721 int i; 590 int i;
722 591
723 for (i = 0; i < EM28XX_NUM_BUFS; i++) { 592 em28xx_isocdbg("em28xx: called em28xx_uninit_isoc\n");
724 if (dev->urb[i]) { 593
725 usb_kill_urb(dev->urb[i]); 594 dev->isoc_ctl.nfields = -1;
726 if (dev->transfer_buffer[i]) { 595 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
596 urb = dev->isoc_ctl.urb[i];
597 if (urb) {
598 usb_kill_urb(urb);
599 usb_unlink_urb(urb);
600 if (dev->isoc_ctl.transfer_buffer[i]) {
727 usb_buffer_free(dev->udev, 601 usb_buffer_free(dev->udev,
728 dev->urb[i]->transfer_buffer_length, 602 urb->transfer_buffer_length,
729 dev->transfer_buffer[i], 603 dev->isoc_ctl.transfer_buffer[i],
730 dev->urb[i]->transfer_dma); 604 urb->transfer_dma);
731 } 605 }
732 usb_free_urb(dev->urb[i]); 606 usb_free_urb(urb);
607 dev->isoc_ctl.urb[i] = NULL;
733 } 608 }
734 dev->urb[i] = NULL; 609 dev->isoc_ctl.transfer_buffer[i] = NULL;
735 dev->transfer_buffer[i] = NULL;
736 } 610 }
611
612 kfree(dev->isoc_ctl.urb);
613 kfree(dev->isoc_ctl.transfer_buffer);
614
615 dev->isoc_ctl.urb = NULL;
616 dev->isoc_ctl.transfer_buffer = NULL;
617 dev->isoc_ctl.num_bufs = 0;
618
737 em28xx_capture_start(dev, 0); 619 em28xx_capture_start(dev, 0);
738} 620}
621EXPORT_SYMBOL_GPL(em28xx_uninit_isoc);
739 622
740/* 623/*
741 * em28xx_init_isoc() 624 * Allocate URBs and start IRQ
742 * allocates transfer buffers and submits the urbs for isoc transfer
743 */ 625 */
744int em28xx_init_isoc(struct em28xx *dev) 626int em28xx_init_isoc(struct em28xx *dev, int max_packets,
627 int num_bufs, int max_pkt_size,
628 int (*isoc_copy) (struct em28xx *dev, struct urb *urb))
745{ 629{
746 /* change interface to 3 which allows the biggest packet sizes */ 630 struct em28xx_dmaqueue *dma_q = &dev->vidq;
747 int i, errCode; 631 int i;
748 int sb_size; 632 int sb_size, pipe;
749 633 struct urb *urb;
750 em28xx_set_alternate(dev); 634 int j, k;
751 sb_size = EM28XX_NUM_PACKETS * dev->max_pkt_size; 635 int rc;
752 636
753 /* reset streaming vars */ 637 em28xx_isocdbg("em28xx: called em28xx_prepare_isoc\n");
754 dev->frame_current = NULL; 638
755 dev->frame_count = 0; 639 /* De-allocates all pending stuff */
756 640 em28xx_uninit_isoc(dev);
757 /* allocate urbs */ 641
758 for (i = 0; i < EM28XX_NUM_BUFS; i++) { 642 dev->isoc_ctl.isoc_copy = isoc_copy;
759 struct urb *urb; 643 dev->isoc_ctl.num_bufs = num_bufs;
760 int j; 644
761 /* allocate transfer buffer */ 645 dev->isoc_ctl.urb = kzalloc(sizeof(void *)*num_bufs, GFP_KERNEL);
762 urb = usb_alloc_urb(EM28XX_NUM_PACKETS, GFP_KERNEL); 646 if (!dev->isoc_ctl.urb) {
763 if (!urb){ 647 em28xx_errdev("cannot alloc memory for usb buffers\n");
764 em28xx_errdev("cannot alloc urb %i\n", i); 648 return -ENOMEM;
649 }
650
651 dev->isoc_ctl.transfer_buffer = kzalloc(sizeof(void *)*num_bufs,
652 GFP_KERNEL);
653 if (!dev->isoc_ctl.urb) {
654 em28xx_errdev("cannot allocate memory for usbtransfer\n");
655 kfree(dev->isoc_ctl.urb);
656 return -ENOMEM;
657 }
658
659 dev->isoc_ctl.max_pkt_size = max_pkt_size;
660 dev->isoc_ctl.buf = NULL;
661
662 sb_size = max_packets * dev->isoc_ctl.max_pkt_size;
663
664 /* allocate urbs and transfer buffers */
665 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
666 urb = usb_alloc_urb(max_packets, GFP_KERNEL);
667 if (!urb) {
668 em28xx_err("cannot alloc isoc_ctl.urb %i\n", i);
765 em28xx_uninit_isoc(dev); 669 em28xx_uninit_isoc(dev);
766 return -ENOMEM; 670 return -ENOMEM;
767 } 671 }
768 dev->transfer_buffer[i] = usb_buffer_alloc(dev->udev, sb_size, 672 dev->isoc_ctl.urb[i] = urb;
769 GFP_KERNEL, 673
770 &urb->transfer_dma); 674 dev->isoc_ctl.transfer_buffer[i] = usb_buffer_alloc(dev->udev,
771 if (!dev->transfer_buffer[i]) { 675 sb_size, GFP_KERNEL, &urb->transfer_dma);
772 em28xx_errdev 676 if (!dev->isoc_ctl.transfer_buffer[i]) {
773 ("unable to allocate %i bytes for transfer buffer %i\n", 677 em28xx_err("unable to allocate %i bytes for transfer"
774 sb_size, i); 678 " buffer %i%s\n",
679 sb_size, i,
680 in_interrupt()?" while in int":"");
775 em28xx_uninit_isoc(dev); 681 em28xx_uninit_isoc(dev);
776 usb_free_urb(urb);
777 return -ENOMEM; 682 return -ENOMEM;
778 } 683 }
779 memset(dev->transfer_buffer[i], 0, sb_size); 684 memset(dev->isoc_ctl.transfer_buffer[i], 0, sb_size);
780 urb->dev = dev->udev; 685
781 urb->context = dev; 686 /* FIXME: this is a hack - should be
782 urb->pipe = usb_rcvisocpipe(dev->udev, 0x82); 687 'desc.bEndpointAddress & USB_ENDPOINT_NUMBER_MASK'
783 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; 688 should also be using 'desc.bInterval'
784 urb->interval = 1; 689 */
785 urb->transfer_buffer = dev->transfer_buffer[i]; 690 pipe = usb_rcvisocpipe(dev->udev,
786 urb->complete = em28xx_isocIrq; 691 dev->mode == EM28XX_ANALOG_MODE ? 0x82 : 0x84);
787 urb->number_of_packets = EM28XX_NUM_PACKETS; 692
788 urb->transfer_buffer_length = sb_size; 693 usb_fill_int_urb(urb, dev->udev, pipe,
789 for (j = 0; j < EM28XX_NUM_PACKETS; j++) { 694 dev->isoc_ctl.transfer_buffer[i], sb_size,
790 urb->iso_frame_desc[j].offset = j * dev->max_pkt_size; 695 em28xx_irq_callback, dma_q, 1);
791 urb->iso_frame_desc[j].length = dev->max_pkt_size; 696
697 urb->number_of_packets = max_packets;
698 urb->transfer_flags = URB_ISO_ASAP;
699
700 k = 0;
701 for (j = 0; j < max_packets; j++) {
702 urb->iso_frame_desc[j].offset = k;
703 urb->iso_frame_desc[j].length =
704 dev->isoc_ctl.max_pkt_size;
705 k += dev->isoc_ctl.max_pkt_size;
792 } 706 }
793 dev->urb[i] = urb;
794 } 707 }
795 708
796 /* submit urbs */ 709 init_waitqueue_head(&dma_q->wq);
797 em28xx_coredbg("Submitting %d urbs of %d packets (%d each)\n",
798 EM28XX_NUM_BUFS, EM28XX_NUM_PACKETS, dev->max_pkt_size);
799 for (i = 0; i < EM28XX_NUM_BUFS; i++) {
800 errCode = usb_submit_urb(dev->urb[i], GFP_KERNEL);
801 if (errCode) {
802 em28xx_errdev("submit of urb %i failed (error=%i)\n", i,
803 errCode);
804 em28xx_uninit_isoc(dev);
805 return errCode;
806 }
807 }
808
809 return 0;
810}
811
812int em28xx_set_alternate(struct em28xx *dev)
813{
814 int errCode, prev_alt = dev->alt;
815 int i;
816 unsigned int min_pkt_size = dev->bytesperline+4;
817
818 /* When image size is bigger than a ceirtain value,
819 the frame size should be increased, otherwise, only
820 green screen will be received.
821 */
822 if (dev->frame_size > 720*240*2)
823 min_pkt_size *= 2;
824 710
825 for (i = 0; i < dev->num_alt; i++) 711 em28xx_capture_start(dev, 1);
826 if (dev->alt_max_pkt_size[i] >= min_pkt_size)
827 break;
828 dev->alt = i;
829 712
830 if (dev->alt != prev_alt) { 713 /* submit urbs and enables IRQ */
831 em28xx_coredbg("minimum isoc packet size: %u (alt=%d)\n", 714 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
832 min_pkt_size, dev->alt); 715 rc = usb_submit_urb(dev->isoc_ctl.urb[i], GFP_ATOMIC);
833 dev->max_pkt_size = dev->alt_max_pkt_size[dev->alt]; 716 if (rc) {
834 em28xx_coredbg("setting alternate %d with wMaxPacketSize=%u\n", 717 em28xx_err("submit of urb %i failed (error=%i)\n", i,
835 dev->alt, dev->max_pkt_size); 718 rc);
836 errCode = usb_set_interface(dev->udev, 0, dev->alt); 719 em28xx_uninit_isoc(dev);
837 if (errCode < 0) { 720 return rc;
838 em28xx_errdev ("cannot change alternate number to %d (error=%i)\n",
839 dev->alt, errCode);
840 return errCode;
841 } 721 }
842 } 722 }
723
843 return 0; 724 return 0;
844} 725}
726EXPORT_SYMBOL_GPL(em28xx_init_isoc);
diff --git a/drivers/media/video/em28xx/em28xx-dvb.c b/drivers/media/video/em28xx/em28xx-dvb.c
new file mode 100644
index 000000000000..7df81575b7f2
--- /dev/null
+++ b/drivers/media/video/em28xx/em28xx-dvb.c
@@ -0,0 +1,474 @@
1/*
2 DVB device driver for em28xx
3
4 (c) 2008 Mauro Carvalho Chehab <mchehab@infradead.org>
5
6 (c) 2008 Devin Heitmueller <devin.heitmueller@gmail.com>
7 - Fixes for the driver to properly work with HVR-950
8
9 (c) 2008 Aidan Thornton <makosoft@googlemail.com>
10
11 Based on cx88-dvb, saa7134-dvb and videobuf-dvb originally written by:
12 (c) 2004, 2005 Chris Pascoe <c.pascoe@itee.uq.edu.au>
13 (c) 2004 Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]
14
15 This program is free software; you can redistribute it and/or modify
16 it under the terms of the GNU General Public License as published by
17 the Free Software Foundation; either version 2 of the License.
18 */
19
20#include <linux/kernel.h>
21#include <linux/usb.h>
22
23#include "em28xx.h"
24#include <media/v4l2-common.h>
25#include <media/videobuf-vmalloc.h>
26
27#include "lgdt330x.h"
28#include "zl10353.h"
29
30MODULE_DESCRIPTION("driver for em28xx based DVB cards");
31MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
32MODULE_LICENSE("GPL");
33
34static unsigned int debug;
35module_param(debug, int, 0644);
36MODULE_PARM_DESC(debug, "enable debug messages [dvb]");
37
38DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
39
40#define dprintk(level, fmt, arg...) do { \
41if (debug >= level) \
42 printk(KERN_DEBUG "%s/2-dvb: " fmt, dev->name, ## arg); \
43} while (0)
44
45#define EM28XX_DVB_NUM_BUFS 5
46#define EM28XX_DVB_MAX_PACKETSIZE 564
47#define EM28XX_DVB_MAX_PACKETS 64
48
49struct em28xx_dvb {
50 struct dvb_frontend *frontend;
51
52 /* feed count management */
53 struct mutex lock;
54 int nfeeds;
55
56 /* general boilerplate stuff */
57 struct dvb_adapter adapter;
58 struct dvb_demux demux;
59 struct dmxdev dmxdev;
60 struct dmx_frontend fe_hw;
61 struct dmx_frontend fe_mem;
62 struct dvb_net net;
63};
64
65
66static inline void print_err_status(struct em28xx *dev,
67 int packet, int status)
68{
69 char *errmsg = "Unknown";
70
71 switch (status) {
72 case -ENOENT:
73 errmsg = "unlinked synchronuously";
74 break;
75 case -ECONNRESET:
76 errmsg = "unlinked asynchronuously";
77 break;
78 case -ENOSR:
79 errmsg = "Buffer error (overrun)";
80 break;
81 case -EPIPE:
82 errmsg = "Stalled (device not responding)";
83 break;
84 case -EOVERFLOW:
85 errmsg = "Babble (bad cable?)";
86 break;
87 case -EPROTO:
88 errmsg = "Bit-stuff error (bad cable?)";
89 break;
90 case -EILSEQ:
91 errmsg = "CRC/Timeout (could be anything)";
92 break;
93 case -ETIME:
94 errmsg = "Device does not respond";
95 break;
96 }
97 if (packet < 0) {
98 dprintk(1, "URB status %d [%s].\n", status, errmsg);
99 } else {
100 dprintk(1, "URB packet %d, status %d [%s].\n",
101 packet, status, errmsg);
102 }
103}
104
105static inline int dvb_isoc_copy(struct em28xx *dev, struct urb *urb)
106{
107 int i;
108
109 if (!dev)
110 return 0;
111
112 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED))
113 return 0;
114
115 if (urb->status < 0) {
116 print_err_status(dev, -1, urb->status);
117 if (urb->status == -ENOENT)
118 return 0;
119 }
120
121 for (i = 0; i < urb->number_of_packets; i++) {
122 int status = urb->iso_frame_desc[i].status;
123
124 if (status < 0) {
125 print_err_status(dev, i, status);
126 if (urb->iso_frame_desc[i].status != -EPROTO)
127 continue;
128 }
129
130 dvb_dmx_swfilter(&dev->dvb->demux, urb->transfer_buffer +
131 urb->iso_frame_desc[i].offset,
132 urb->iso_frame_desc[i].actual_length);
133 }
134
135 return 0;
136}
137
138static int start_streaming(struct em28xx_dvb *dvb)
139{
140 int rc;
141 struct em28xx *dev = dvb->adapter.priv;
142
143 usb_set_interface(dev->udev, 0, 1);
144 rc = em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
145 if (rc < 0)
146 return rc;
147
148 return em28xx_init_isoc(dev, EM28XX_DVB_MAX_PACKETS,
149 EM28XX_DVB_NUM_BUFS, EM28XX_DVB_MAX_PACKETSIZE,
150 dvb_isoc_copy);
151}
152
153static int stop_streaming(struct em28xx_dvb *dvb)
154{
155 struct em28xx *dev = dvb->adapter.priv;
156
157 em28xx_uninit_isoc(dev);
158
159 em28xx_set_mode(dev, EM28XX_MODE_UNDEFINED);
160
161 return 0;
162}
163
164static int start_feed(struct dvb_demux_feed *feed)
165{
166 struct dvb_demux *demux = feed->demux;
167 struct em28xx_dvb *dvb = demux->priv;
168 int rc, ret;
169
170 if (!demux->dmx.frontend)
171 return -EINVAL;
172
173 mutex_lock(&dvb->lock);
174 dvb->nfeeds++;
175 rc = dvb->nfeeds;
176
177 if (dvb->nfeeds == 1) {
178 ret = start_streaming(dvb);
179 if (ret < 0)
180 rc = ret;
181 }
182
183 mutex_unlock(&dvb->lock);
184 return rc;
185}
186
187static int stop_feed(struct dvb_demux_feed *feed)
188{
189 struct dvb_demux *demux = feed->demux;
190 struct em28xx_dvb *dvb = demux->priv;
191 int err = 0;
192
193 mutex_lock(&dvb->lock);
194 dvb->nfeeds--;
195
196 if (0 == dvb->nfeeds)
197 err = stop_streaming(dvb);
198
199 mutex_unlock(&dvb->lock);
200 return err;
201}
202
203
204
205/* ------------------------------------------------------------------ */
206static int em28xx_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
207{
208 struct em28xx *dev = fe->dvb->priv;
209
210 if (acquire)
211 return em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
212 else
213 return em28xx_set_mode(dev, EM28XX_MODE_UNDEFINED);
214}
215
216/* ------------------------------------------------------------------ */
217
218static struct lgdt330x_config em2880_lgdt3303_dev = {
219 .demod_address = 0x0e,
220 .demod_chip = LGDT3303,
221};
222
223static struct zl10353_config em28xx_zl10353_with_xc3028 = {
224 .demod_address = (0x1e >> 1),
225 .no_tuner = 1,
226 .parallel_ts = 1,
227 .if2 = 45600,
228};
229
230/* ------------------------------------------------------------------ */
231
232static int attach_xc3028(u8 addr, struct em28xx *dev)
233{
234 struct dvb_frontend *fe;
235 struct xc2028_config cfg;
236
237 memset(&cfg, 0, sizeof(cfg));
238 cfg.i2c_adap = &dev->i2c_adap;
239 cfg.i2c_addr = addr;
240 cfg.callback = em28xx_tuner_callback;
241
242 if (!dev->dvb->frontend) {
243 printk(KERN_ERR "%s/2: dvb frontend not attached. "
244 "Can't attach xc3028\n",
245 dev->name);
246 return -EINVAL;
247 }
248
249 fe = dvb_attach(xc2028_attach, dev->dvb->frontend, &cfg);
250 if (!fe) {
251 printk(KERN_ERR "%s/2: xc3028 attach failed\n",
252 dev->name);
253 dvb_frontend_detach(dev->dvb->frontend);
254 dvb_unregister_frontend(dev->dvb->frontend);
255 dev->dvb->frontend = NULL;
256 return -EINVAL;
257 }
258
259 printk(KERN_INFO "%s/2: xc3028 attached\n", dev->name);
260
261 return 0;
262}
263
264/* ------------------------------------------------------------------ */
265
266int register_dvb(struct em28xx_dvb *dvb,
267 struct module *module,
268 struct em28xx *dev,
269 struct device *device)
270{
271 int result;
272
273 mutex_init(&dvb->lock);
274
275 /* register adapter */
276 result = dvb_register_adapter(&dvb->adapter, dev->name, module, device,
277 adapter_nr);
278 if (result < 0) {
279 printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
280 dev->name, result);
281 goto fail_adapter;
282 }
283
284 /* Ensure all frontends negotiate bus access */
285 dvb->frontend->ops.ts_bus_ctrl = em28xx_dvb_bus_ctrl;
286
287 dvb->adapter.priv = dev;
288
289 /* register frontend */
290 result = dvb_register_frontend(&dvb->adapter, dvb->frontend);
291 if (result < 0) {
292 printk(KERN_WARNING "%s: dvb_register_frontend failed (errno = %d)\n",
293 dev->name, result);
294 goto fail_frontend;
295 }
296
297 /* register demux stuff */
298 dvb->demux.dmx.capabilities =
299 DMX_TS_FILTERING | DMX_SECTION_FILTERING |
300 DMX_MEMORY_BASED_FILTERING;
301 dvb->demux.priv = dvb;
302 dvb->demux.filternum = 256;
303 dvb->demux.feednum = 256;
304 dvb->demux.start_feed = start_feed;
305 dvb->demux.stop_feed = stop_feed;
306
307 result = dvb_dmx_init(&dvb->demux);
308 if (result < 0) {
309 printk(KERN_WARNING "%s: dvb_dmx_init failed (errno = %d)\n",
310 dev->name, result);
311 goto fail_dmx;
312 }
313
314 dvb->dmxdev.filternum = 256;
315 dvb->dmxdev.demux = &dvb->demux.dmx;
316 dvb->dmxdev.capabilities = 0;
317 result = dvb_dmxdev_init(&dvb->dmxdev, &dvb->adapter);
318 if (result < 0) {
319 printk(KERN_WARNING "%s: dvb_dmxdev_init failed (errno = %d)\n",
320 dev->name, result);
321 goto fail_dmxdev;
322 }
323
324 dvb->fe_hw.source = DMX_FRONTEND_0;
325 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_hw);
326 if (result < 0) {
327 printk(KERN_WARNING "%s: add_frontend failed (DMX_FRONTEND_0, errno = %d)\n",
328 dev->name, result);
329 goto fail_fe_hw;
330 }
331
332 dvb->fe_mem.source = DMX_MEMORY_FE;
333 result = dvb->demux.dmx.add_frontend(&dvb->demux.dmx, &dvb->fe_mem);
334 if (result < 0) {
335 printk(KERN_WARNING "%s: add_frontend failed (DMX_MEMORY_FE, errno = %d)\n",
336 dev->name, result);
337 goto fail_fe_mem;
338 }
339
340 result = dvb->demux.dmx.connect_frontend(&dvb->demux.dmx, &dvb->fe_hw);
341 if (result < 0) {
342 printk(KERN_WARNING "%s: connect_frontend failed (errno = %d)\n",
343 dev->name, result);
344 goto fail_fe_conn;
345 }
346
347 /* register network adapter */
348 dvb_net_init(&dvb->adapter, &dvb->net, &dvb->demux.dmx);
349 return 0;
350
351fail_fe_conn:
352 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
353fail_fe_mem:
354 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
355fail_fe_hw:
356 dvb_dmxdev_release(&dvb->dmxdev);
357fail_dmxdev:
358 dvb_dmx_release(&dvb->demux);
359fail_dmx:
360 dvb_unregister_frontend(dvb->frontend);
361fail_frontend:
362 dvb_frontend_detach(dvb->frontend);
363 dvb_unregister_adapter(&dvb->adapter);
364fail_adapter:
365 return result;
366}
367
368static void unregister_dvb(struct em28xx_dvb *dvb)
369{
370 dvb_net_release(&dvb->net);
371 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_mem);
372 dvb->demux.dmx.remove_frontend(&dvb->demux.dmx, &dvb->fe_hw);
373 dvb_dmxdev_release(&dvb->dmxdev);
374 dvb_dmx_release(&dvb->demux);
375 dvb_unregister_frontend(dvb->frontend);
376 dvb_frontend_detach(dvb->frontend);
377 dvb_unregister_adapter(&dvb->adapter);
378}
379
380
381static int dvb_init(struct em28xx *dev)
382{
383 int result = 0;
384 struct em28xx_dvb *dvb;
385
386 dvb = kzalloc(sizeof(struct em28xx_dvb), GFP_KERNEL);
387
388 if (dvb == NULL) {
389 printk(KERN_INFO "em28xx_dvb: memory allocation failed\n");
390 return -ENOMEM;
391 }
392 dev->dvb = dvb;
393
394 em28xx_set_mode(dev, EM28XX_DIGITAL_MODE);
395 /* init frontend */
396 switch (dev->model) {
397 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950:
398 dvb->frontend = dvb_attach(lgdt330x_attach,
399 &em2880_lgdt3303_dev,
400 &dev->i2c_adap);
401 if (attach_xc3028(0x61, dev) < 0) {
402 result = -EINVAL;
403 goto out_free;
404 }
405 break;
406 case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
407 dvb->frontend = dvb_attach(zl10353_attach,
408 &em28xx_zl10353_with_xc3028,
409 &dev->i2c_adap);
410 if (attach_xc3028(0x61, dev) < 0) {
411 result = -EINVAL;
412 goto out_free;
413 }
414 break;
415 default:
416 printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card"
417 " isn't supported yet\n",
418 dev->name);
419 break;
420 }
421 if (NULL == dvb->frontend) {
422 printk(KERN_ERR
423 "%s/2: frontend initialization failed\n",
424 dev->name);
425 result = -EINVAL;
426 goto out_free;
427 }
428
429 /* register everything */
430 result = register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
431
432 if (result < 0)
433 goto out_free;
434
435 em28xx_set_mode(dev, EM28XX_MODE_UNDEFINED);
436 printk(KERN_INFO "Successfully loaded em28xx-dvb\n");
437 return 0;
438
439out_free:
440 em28xx_set_mode(dev, EM28XX_MODE_UNDEFINED);
441 kfree(dvb);
442 dev->dvb = NULL;
443 return result;
444}
445
446static int dvb_fini(struct em28xx *dev)
447{
448 if (dev->dvb) {
449 unregister_dvb(dev->dvb);
450 dev->dvb = NULL;
451 }
452
453 return 0;
454}
455
456static struct em28xx_ops dvb_ops = {
457 .id = EM28XX_DVB,
458 .name = "Em28xx dvb Extension",
459 .init = dvb_init,
460 .fini = dvb_fini,
461};
462
463static int __init em28xx_dvb_register(void)
464{
465 return em28xx_register_extension(&dvb_ops);
466}
467
468static void __exit em28xx_dvb_unregister(void)
469{
470 em28xx_unregister_extension(&dvb_ops);
471}
472
473module_init(em28xx_dvb_register);
474module_exit(em28xx_dvb_unregister);
diff --git a/drivers/media/video/em28xx/em28xx-i2c.c b/drivers/media/video/em28xx/em28xx-i2c.c
index cacd04d46e99..6a78fd294cab 100644
--- a/drivers/media/video/em28xx/em28xx-i2c.c
+++ b/drivers/media/video/em28xx/em28xx-i2c.c
@@ -33,19 +33,29 @@
33 33
34/* ----------------------------------------------------------- */ 34/* ----------------------------------------------------------- */
35 35
36static unsigned int i2c_scan = 0; 36static unsigned int i2c_scan;
37module_param(i2c_scan, int, 0444); 37module_param(i2c_scan, int, 0444);
38MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time"); 38MODULE_PARM_DESC(i2c_scan, "scan i2c bus at insmod time");
39 39
40static unsigned int i2c_debug = 0; 40static unsigned int i2c_debug;
41module_param(i2c_debug, int, 0644); 41module_param(i2c_debug, int, 0644);
42MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]"); 42MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
43 43
44#define dprintk1(lvl,fmt, args...) if (i2c_debug>=lvl) do {\ 44
45 printk(fmt, ##args); } while (0) 45#define dprintk1(lvl, fmt, args...) \
46#define dprintk2(lvl,fmt, args...) if (i2c_debug>=lvl) do{ \ 46do { \
47 printk(KERN_DEBUG "%s at %s: " fmt, \ 47 if (i2c_debug >= lvl) { \
48 dev->name, __FUNCTION__ , ##args); } while (0) 48 printk(fmt, ##args); \
49 } \
50} while (0)
51
52#define dprintk2(lvl, fmt, args...) \
53do { \
54 if (i2c_debug >= lvl) { \
55 printk(KERN_DEBUG "%s at %s: " fmt, \
56 dev->name, __func__ , ##args); \
57 } \
58} while (0)
49 59
50/* 60/*
51 * em2800_i2c_send_max4() 61 * em2800_i2c_send_max4()
@@ -235,16 +245,16 @@ static int em28xx_i2c_xfer(struct i2c_adapter *i2c_adap,
235 return 0; 245 return 0;
236 for (i = 0; i < num; i++) { 246 for (i = 0; i < num; i++) {
237 addr = msgs[i].addr << 1; 247 addr = msgs[i].addr << 1;
238 dprintk2(2,"%s %s addr=%x len=%d:", 248 dprintk2(2, "%s %s addr=%x len=%d:",
239 (msgs[i].flags & I2C_M_RD) ? "read" : "write", 249 (msgs[i].flags & I2C_M_RD) ? "read" : "write",
240 i == num - 1 ? "stop" : "nonstop", addr, msgs[i].len); 250 i == num - 1 ? "stop" : "nonstop", addr, msgs[i].len);
241 if (!msgs[i].len) { /* no len: check only for device presence */ 251 if (!msgs[i].len) { /* no len: check only for device presence */
242 if (dev->is_em2800) 252 if (dev->is_em2800)
243 rc = em2800_i2c_check_for_device(dev, addr); 253 rc = em2800_i2c_check_for_device(dev, addr);
244 else 254 else
245 rc = em28xx_i2c_check_for_device(dev, addr); 255 rc = em28xx_i2c_check_for_device(dev, addr);
246 if (rc < 0) { 256 if (rc < 0) {
247 dprintk2(2," no device\n"); 257 dprintk2(2, " no device\n");
248 return rc; 258 return rc;
249 } 259 }
250 260
@@ -258,14 +268,13 @@ static int em28xx_i2c_xfer(struct i2c_adapter *i2c_adap,
258 rc = em28xx_i2c_recv_bytes(dev, addr, 268 rc = em28xx_i2c_recv_bytes(dev, addr,
259 msgs[i].buf, 269 msgs[i].buf,
260 msgs[i].len); 270 msgs[i].len);
261 if (i2c_debug>=2) { 271 if (i2c_debug >= 2) {
262 for (byte = 0; byte < msgs[i].len; byte++) { 272 for (byte = 0; byte < msgs[i].len; byte++)
263 printk(" %02x", msgs[i].buf[byte]); 273 printk(" %02x", msgs[i].buf[byte]);
264 }
265 } 274 }
266 } else { 275 } else {
267 /* write bytes */ 276 /* write bytes */
268 if (i2c_debug>=2) { 277 if (i2c_debug >= 2) {
269 for (byte = 0; byte < msgs[i].len; byte++) 278 for (byte = 0; byte < msgs[i].len; byte++)
270 printk(" %02x", msgs[i].buf[byte]); 279 printk(" %02x", msgs[i].buf[byte]);
271 } 280 }
@@ -281,13 +290,13 @@ static int em28xx_i2c_xfer(struct i2c_adapter *i2c_adap,
281 } 290 }
282 if (rc < 0) 291 if (rc < 0)
283 goto err; 292 goto err;
284 if (i2c_debug>=2) 293 if (i2c_debug >= 2)
285 printk("\n"); 294 printk("\n");
286 } 295 }
287 296
288 return num; 297 return num;
289 err: 298err:
290 dprintk2(2," ERROR: %i\n", rc); 299 dprintk2(2, " ERROR: %i\n", rc);
291 return rc; 300 return rc;
292} 301}
293 302
@@ -330,7 +339,9 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
330 return -1; 339 return -1;
331 340
332 buf = 0; 341 buf = 0;
333 if (1 != (err = i2c_master_send(&dev->i2c_client, &buf, 1))) { 342
343 err = i2c_master_send(&dev->i2c_client, &buf, 1);
344 if (err != 1) {
334 printk(KERN_INFO "%s: Huh, no eeprom present (err=%d)?\n", 345 printk(KERN_INFO "%s: Huh, no eeprom present (err=%d)?\n",
335 dev->name, err); 346 dev->name, err);
336 return -1; 347 return -1;
@@ -403,8 +414,10 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
403 break; 414 break;
404 } 415 }
405 printk(KERN_INFO "Table at 0x%02x, strings=0x%04x, 0x%04x, 0x%04x\n", 416 printk(KERN_INFO "Table at 0x%02x, strings=0x%04x, 0x%04x, 0x%04x\n",
406 em_eeprom->string_idx_table,em_eeprom->string1, 417 em_eeprom->string_idx_table,
407 em_eeprom->string2,em_eeprom->string3); 418 em_eeprom->string1,
419 em_eeprom->string2,
420 em_eeprom->string3);
408 421
409 return 0; 422 return 0;
410} 423}
@@ -430,58 +443,61 @@ static int attach_inform(struct i2c_client *client)
430 struct em28xx *dev = client->adapter->algo_data; 443 struct em28xx *dev = client->adapter->algo_data;
431 444
432 switch (client->addr << 1) { 445 switch (client->addr << 1) {
433 case 0x86: 446 case 0x86:
434 case 0x84: 447 case 0x84:
435 case 0x96: 448 case 0x96:
436 case 0x94: 449 case 0x94:
437 { 450 {
438 struct v4l2_priv_tun_config tda9887_cfg; 451 struct v4l2_priv_tun_config tda9887_cfg;
439 452
440 struct tuner_setup tun_setup; 453 struct tuner_setup tun_setup;
441 454
442 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO; 455 tun_setup.mode_mask = T_ANALOG_TV | T_RADIO;
443 tun_setup.type = TUNER_TDA9887; 456 tun_setup.type = TUNER_TDA9887;
444 tun_setup.addr = client->addr; 457 tun_setup.addr = client->addr;
445 458
446 em28xx_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR, &tun_setup); 459 em28xx_i2c_call_clients(dev, TUNER_SET_TYPE_ADDR,
447 460 &tun_setup);
448 tda9887_cfg.tuner = TUNER_TDA9887; 461
449 tda9887_cfg.priv = &dev->tda9887_conf; 462 tda9887_cfg.tuner = TUNER_TDA9887;
450 em28xx_i2c_call_clients(dev, TUNER_SET_CONFIG, 463 tda9887_cfg.priv = &dev->tda9887_conf;
451 &tda9887_cfg); 464 em28xx_i2c_call_clients(dev, TUNER_SET_CONFIG,
452 break; 465 &tda9887_cfg);
453 } 466 break;
454 case 0x42: 467 }
455 dprintk1(1,"attach_inform: saa7114 detected.\n"); 468 case 0x42:
456 break; 469 dprintk1(1, "attach_inform: saa7114 detected.\n");
457 case 0x4a: 470 break;
458 dprintk1(1,"attach_inform: saa7113 detected.\n"); 471 case 0x4a:
459 break; 472 dprintk1(1, "attach_inform: saa7113 detected.\n");
460 case 0xa0: 473 break;
461 dprintk1(1,"attach_inform: eeprom detected.\n"); 474 case 0xa0:
462 break; 475 dprintk1(1, "attach_inform: eeprom detected.\n");
463 case 0x60: 476 break;
464 case 0x8e: 477 case 0x60:
465 { 478 case 0x8e:
466 struct IR_i2c *ir = i2c_get_clientdata(client); 479 {
467 dprintk1(1,"attach_inform: IR detected (%s).\n",ir->phys); 480 struct IR_i2c *ir = i2c_get_clientdata(client);
468 em28xx_set_ir(dev,ir); 481 dprintk1(1, "attach_inform: IR detected (%s).\n",
469 break; 482 ir->phys);
470 } 483 em28xx_set_ir(dev, ir);
471 case 0x80: 484 break;
472 case 0x88: 485 }
473 dprintk1(1,"attach_inform: msp34xx detected.\n"); 486 case 0x80:
474 break; 487 case 0x88:
475 case 0xb8: 488 dprintk1(1, "attach_inform: msp34xx detected.\n");
476 case 0xba: 489 break;
477 dprintk1(1,"attach_inform: tvp5150 detected.\n"); 490 case 0xb8:
478 break; 491 case 0xba:
479 492 dprintk1(1, "attach_inform: tvp5150 detected.\n");
480 default: 493 break;
481 if (!dev->tuner_addr) 494
482 dev->tuner_addr = client->addr; 495 default:
483 496 if (!dev->tuner_addr)
484 dprintk1(1,"attach inform: detected I2C address %x\n", client->addr << 1); 497 dev->tuner_addr = client->addr;
498
499 dprintk1(1, "attach inform: detected I2C address %x\n",
500 client->addr << 1);
485 501
486 } 502 }
487 503
diff --git a/drivers/media/video/em28xx/em28xx-input.c b/drivers/media/video/em28xx/em28xx-input.c
index 10da2fd8d987..bb5807159b8d 100644
--- a/drivers/media/video/em28xx/em28xx-input.c
+++ b/drivers/media/video/em28xx/em28xx-input.c
@@ -32,10 +32,12 @@
32 32
33static unsigned int ir_debug; 33static unsigned int ir_debug;
34module_param(ir_debug, int, 0644); 34module_param(ir_debug, int, 0644);
35MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]"); 35MODULE_PARM_DESC(ir_debug, "enable debug messages [IR]");
36 36
37#define dprintk(fmt, arg...) if (ir_debug) \ 37#define dprintk(fmt, arg...) \
38 printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg) 38 if (ir_debug) { \
39 printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg); \
40 }
39 41
40/* ----------------------------------------------------------------------- */ 42/* ----------------------------------------------------------------------- */
41 43
@@ -44,7 +46,7 @@ int em28xx_get_key_terratec(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
44 unsigned char b; 46 unsigned char b;
45 47
46 /* poll IR chip */ 48 /* poll IR chip */
47 if (1 != i2c_master_recv(&ir->c,&b,1)) { 49 if (1 != i2c_master_recv(&ir->c, &b, 1)) {
48 dprintk("read error\n"); 50 dprintk("read error\n");
49 return -EIO; 51 return -EIO;
50 } 52 }
@@ -74,24 +76,25 @@ int em28xx_get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
74 unsigned char code; 76 unsigned char code;
75 77
76 /* poll IR chip */ 78 /* poll IR chip */
77 if (2 != i2c_master_recv(&ir->c,buf,2)) 79 if (2 != i2c_master_recv(&ir->c, buf, 2))
78 return -EIO; 80 return -EIO;
79 81
80 /* Does eliminate repeated parity code */ 82 /* Does eliminate repeated parity code */
81 if (buf[1]==0xff) 83 if (buf[1] == 0xff)
82 return 0; 84 return 0;
83 85
84 ir->old=buf[1]; 86 ir->old = buf[1];
85 87
86 /* Rearranges bits to the right order */ 88 /* Rearranges bits to the right order */
87 code= ((buf[0]&0x01)<<5) | /* 0010 0000 */ 89 code = ((buf[0]&0x01)<<5) | /* 0010 0000 */
88 ((buf[0]&0x02)<<3) | /* 0001 0000 */ 90 ((buf[0]&0x02)<<3) | /* 0001 0000 */
89 ((buf[0]&0x04)<<1) | /* 0000 1000 */ 91 ((buf[0]&0x04)<<1) | /* 0000 1000 */
90 ((buf[0]&0x08)>>1) | /* 0000 0100 */ 92 ((buf[0]&0x08)>>1) | /* 0000 0100 */
91 ((buf[0]&0x10)>>3) | /* 0000 0010 */ 93 ((buf[0]&0x10)>>3) | /* 0000 0010 */
92 ((buf[0]&0x20)>>5); /* 0000 0001 */ 94 ((buf[0]&0x20)>>5); /* 0000 0001 */
93 95
94 dprintk("ir hauppauge (em2840): code=0x%02x (rcv=0x%02x)\n",code,buf[0]); 96 dprintk("ir hauppauge (em2840): code=0x%02x (rcv=0x%02x)\n",
97 code, buf[0]);
95 98
96 /* return key */ 99 /* return key */
97 *ir_key = code; 100 *ir_key = code;
@@ -106,15 +109,14 @@ int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key,
106 109
107 /* poll IR chip */ 110 /* poll IR chip */
108 111
109 if (3 != i2c_master_recv(&ir->c,buf,3)) { 112 if (3 != i2c_master_recv(&ir->c, buf, 3)) {
110 dprintk("read error\n"); 113 dprintk("read error\n");
111 return -EIO; 114 return -EIO;
112 } 115 }
113 116
114 dprintk("key %02x\n", buf[2]&0x3f); 117 dprintk("key %02x\n", buf[2]&0x3f);
115 if (buf[0]!=0x00){ 118 if (buf[0] != 0x00)
116 return 0; 119 return 0;
117 }
118 120
119 *ir_key = buf[2]&0x3f; 121 *ir_key = buf[2]&0x3f;
120 *ir_raw = buf[2]&0x3f; 122 *ir_raw = buf[2]&0x3f;
diff --git a/drivers/media/video/em28xx/em28xx-reg.h b/drivers/media/video/em28xx/em28xx-reg.h
new file mode 100644
index 000000000000..9058bed07953
--- /dev/null
+++ b/drivers/media/video/em28xx/em28xx-reg.h
@@ -0,0 +1,88 @@
1#define EM_GPIO_0 (1 << 0)
2#define EM_GPIO_1 (1 << 1)
3#define EM_GPIO_2 (1 << 2)
4#define EM_GPIO_3 (1 << 3)
5#define EM_GPIO_4 (1 << 4)
6#define EM_GPIO_5 (1 << 5)
7#define EM_GPIO_6 (1 << 6)
8#define EM_GPIO_7 (1 << 7)
9
10#define EM_GPO_0 (1 << 0)
11#define EM_GPO_1 (1 << 1)
12#define EM_GPO_2 (1 << 2)
13#define EM_GPO_3 (1 << 3)
14
15/* em2800 registers */
16#define EM2800_R08_AUDIOSRC 0x08
17
18/* em28xx registers */
19
20 /* GPIO/GPO registers */
21#define EM2880_R04_GPO 0x04 /* em2880-em2883 only */
22#define EM28XX_R08_GPIO 0x08 /* em2820 or upper */
23
24#define EM28XX_R06_I2C_CLK 0x06
25#define EM28XX_R0A_CHIPID 0x0a
26#define EM28XX_R0C_USBSUSP 0x0c /* */
27
28#define EM28XX_R0E_AUDIOSRC 0x0e
29#define EM28XX_R0F_XCLK 0x0f
30
31#define EM28XX_R10_VINMODE 0x10
32#define EM28XX_R11_VINCTRL 0x11
33#define EM28XX_R12_VINENABLE 0x12 /* */
34
35#define EM28XX_R14_GAMMA 0x14
36#define EM28XX_R15_RGAIN 0x15
37#define EM28XX_R16_GGAIN 0x16
38#define EM28XX_R17_BGAIN 0x17
39#define EM28XX_R18_ROFFSET 0x18
40#define EM28XX_R19_GOFFSET 0x19
41#define EM28XX_R1A_BOFFSET 0x1a
42
43#define EM28XX_R1B_OFLOW 0x1b
44#define EM28XX_R1C_HSTART 0x1c
45#define EM28XX_R1D_VSTART 0x1d
46#define EM28XX_R1E_CWIDTH 0x1e
47#define EM28XX_R1F_CHEIGHT 0x1f
48
49#define EM28XX_R20_YGAIN 0x20
50#define EM28XX_R21_YOFFSET 0x21
51#define EM28XX_R22_UVGAIN 0x22
52#define EM28XX_R23_UOFFSET 0x23
53#define EM28XX_R24_VOFFSET 0x24
54#define EM28XX_R25_SHARPNESS 0x25
55
56#define EM28XX_R26_COMPR 0x26
57#define EM28XX_R27_OUTFMT 0x27
58
59#define EM28XX_R28_XMIN 0x28
60#define EM28XX_R29_XMAX 0x29
61#define EM28XX_R2A_YMIN 0x2a
62#define EM28XX_R2B_YMAX 0x2b
63
64#define EM28XX_R30_HSCALELOW 0x30
65#define EM28XX_R31_HSCALEHIGH 0x31
66#define EM28XX_R32_VSCALELOW 0x32
67#define EM28XX_R33_VSCALEHIGH 0x33
68
69#define EM28XX_R40_AC97LSB 0x40
70#define EM28XX_R41_AC97MSB 0x41
71#define EM28XX_R42_AC97ADDR 0x42
72#define EM28XX_R43_AC97BUSY 0x43
73
74/* em202 registers */
75#define EM28XX_R02_MASTER_AC97 0x02
76#define EM28XX_R10_LINE_IN_AC97 0x10
77#define EM28XX_R14_VIDEO_AC97 0x14
78
79/* register settings */
80#define EM2800_AUDIO_SRC_TUNER 0x0d
81#define EM2800_AUDIO_SRC_LINE 0x0c
82#define EM28XX_AUDIO_SRC_TUNER 0xc0
83#define EM28XX_AUDIO_SRC_LINE 0x80
84
85/* FIXME: Need to be populated with the other chip ID's */
86enum em28xx_chip_id {
87 CHIP_ID_EM2883 = 36,
88};
diff --git a/drivers/media/video/em28xx/em28xx-video.c b/drivers/media/video/em28xx/em28xx-video.c
index 4abe6701a770..8996175cc950 100644
--- a/drivers/media/video/em28xx/em28xx-video.c
+++ b/drivers/media/video/em28xx/em28xx-video.c
@@ -1,5 +1,6 @@
1/* 1/*
2 em28xx-video.c - driver for Empia EM2800/EM2820/2840 USB video capture devices 2 em28xx-video.c - driver for Empia EM2800/EM2820/2840 USB
3 video capture devices
3 4
4 Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it> 5 Copyright (C) 2005 Ludovico Cavedon <cavedon@sssup.it>
5 Markus Rechberger <mrechberger@gmail.com> 6 Markus Rechberger <mrechberger@gmail.com>
@@ -52,7 +53,19 @@
52#define em28xx_videodbg(fmt, arg...) do {\ 53#define em28xx_videodbg(fmt, arg...) do {\
53 if (video_debug) \ 54 if (video_debug) \
54 printk(KERN_INFO "%s %s :"fmt, \ 55 printk(KERN_INFO "%s %s :"fmt, \
55 dev->name, __FUNCTION__ , ##arg); } while (0) 56 dev->name, __func__ , ##arg); } while (0)
57
58static unsigned int isoc_debug;
59module_param(isoc_debug, int, 0644);
60MODULE_PARM_DESC(isoc_debug, "enable debug messages [isoc transfers]");
61
62#define em28xx_isocdbg(fmt, arg...) \
63do {\
64 if (isoc_debug) { \
65 printk(KERN_INFO "%s %s :"fmt, \
66 dev->name, __func__ , ##arg); \
67 } \
68 } while (0)
56 69
57MODULE_AUTHOR(DRIVER_AUTHOR); 70MODULE_AUTHOR(DRIVER_AUTHOR);
58MODULE_DESCRIPTION(DRIVER_DESC); 71MODULE_DESCRIPTION(DRIVER_DESC);
@@ -74,9 +87,9 @@ MODULE_PARM_DESC(video_nr, "video device numbers");
74MODULE_PARM_DESC(vbi_nr, "vbi device numbers"); 87MODULE_PARM_DESC(vbi_nr, "vbi device numbers");
75MODULE_PARM_DESC(radio_nr, "radio device numbers"); 88MODULE_PARM_DESC(radio_nr, "radio device numbers");
76 89
77static unsigned int video_debug = 0; 90static unsigned int video_debug;
78module_param(video_debug,int,0644); 91module_param(video_debug, int, 0644);
79MODULE_PARM_DESC(video_debug,"enable debug messages [video]"); 92MODULE_PARM_DESC(video_debug, "enable debug messages [video]");
80 93
81/* Bitmask marking allocated devices from 0 to EM28XX_MAXBOARDS */ 94/* Bitmask marking allocated devices from 0 to EM28XX_MAXBOARDS */
82static unsigned long em28xx_devused; 95static unsigned long em28xx_devused;
@@ -93,7 +106,7 @@ static struct v4l2_queryctrl em28xx_qctrl[] = {
93 .step = 0x1, 106 .step = 0x1,
94 .default_value = 0x1f, 107 .default_value = 0x1f,
95 .flags = 0, 108 .flags = 0,
96 },{ 109 }, {
97 .id = V4L2_CID_AUDIO_MUTE, 110 .id = V4L2_CID_AUDIO_MUTE,
98 .type = V4L2_CTRL_TYPE_BOOLEAN, 111 .type = V4L2_CTRL_TYPE_BOOLEAN,
99 .name = "Mute", 112 .name = "Mute",
@@ -107,8 +120,391 @@ static struct v4l2_queryctrl em28xx_qctrl[] = {
107 120
108static struct usb_driver em28xx_usb_driver; 121static struct usb_driver em28xx_usb_driver;
109 122
123/* ------------------------------------------------------------------
124 DMA and thread functions
125 ------------------------------------------------------------------*/
126
127/*
128 * Announces that a buffer were filled and request the next
129 */
130static inline void buffer_filled(struct em28xx *dev,
131 struct em28xx_dmaqueue *dma_q,
132 struct em28xx_buffer *buf)
133{
134 /* Advice that buffer was filled */
135 em28xx_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i);
136 buf->vb.state = VIDEOBUF_DONE;
137 buf->vb.field_count++;
138 do_gettimeofday(&buf->vb.ts);
110 139
111/********************* v4l2 interface ******************************************/ 140 dev->isoc_ctl.buf = NULL;
141
142 list_del(&buf->vb.queue);
143 wake_up(&buf->vb.done);
144}
145
146/*
147 * Identify the buffer header type and properly handles
148 */
149static void em28xx_copy_video(struct em28xx *dev,
150 struct em28xx_dmaqueue *dma_q,
151 struct em28xx_buffer *buf,
152 unsigned char *p,
153 unsigned char *outp, unsigned long len)
154{
155 void *fieldstart, *startwrite, *startread;
156 int linesdone, currlinedone, offset, lencopy, remain;
157 int bytesperline = dev->width << 1;
158
159 if (dma_q->pos + len > buf->vb.size)
160 len = buf->vb.size - dma_q->pos;
161
162 if (p[0] != 0x88 && p[0] != 0x22) {
163 em28xx_isocdbg("frame is not complete\n");
164 len += 4;
165 } else
166 p += 4;
167
168 startread = p;
169 remain = len;
170
171 /* Interlaces frame */
172 if (buf->top_field)
173 fieldstart = outp;
174 else
175 fieldstart = outp + bytesperline;
176
177 linesdone = dma_q->pos / bytesperline;
178 currlinedone = dma_q->pos % bytesperline;
179 offset = linesdone * bytesperline * 2 + currlinedone;
180 startwrite = fieldstart + offset;
181 lencopy = bytesperline - currlinedone;
182 lencopy = lencopy > remain ? remain : lencopy;
183
184 if ((char *)startwrite + lencopy > (char *)outp + buf->vb.size) {
185 em28xx_isocdbg("Overflow of %zi bytes past buffer end (1)\n",
186 ((char *)startwrite + lencopy) -
187 ((char *)outp + buf->vb.size));
188 lencopy = remain = (char *)outp + buf->vb.size - (char *)startwrite;
189 }
190 if (lencopy <= 0)
191 return;
192 memcpy(startwrite, startread, lencopy);
193
194 remain -= lencopy;
195
196 while (remain > 0) {
197 startwrite += lencopy + bytesperline;
198 startread += lencopy;
199 if (bytesperline > remain)
200 lencopy = remain;
201 else
202 lencopy = bytesperline;
203
204 if ((char *)startwrite + lencopy > (char *)outp + buf->vb.size) {
205 em28xx_isocdbg("Overflow of %zi bytes past buffer end (2)\n",
206 ((char *)startwrite + lencopy) -
207 ((char *)outp + buf->vb.size));
208 lencopy = remain = (char *)outp + buf->vb.size -
209 (char *)startwrite;
210 }
211 if (lencopy <= 0)
212 break;
213
214 memcpy(startwrite, startread, lencopy);
215
216 remain -= lencopy;
217 }
218
219 dma_q->pos += len;
220}
221
222static inline void print_err_status(struct em28xx *dev,
223 int packet, int status)
224{
225 char *errmsg = "Unknown";
226
227 switch (status) {
228 case -ENOENT:
229 errmsg = "unlinked synchronuously";
230 break;
231 case -ECONNRESET:
232 errmsg = "unlinked asynchronuously";
233 break;
234 case -ENOSR:
235 errmsg = "Buffer error (overrun)";
236 break;
237 case -EPIPE:
238 errmsg = "Stalled (device not responding)";
239 break;
240 case -EOVERFLOW:
241 errmsg = "Babble (bad cable?)";
242 break;
243 case -EPROTO:
244 errmsg = "Bit-stuff error (bad cable?)";
245 break;
246 case -EILSEQ:
247 errmsg = "CRC/Timeout (could be anything)";
248 break;
249 case -ETIME:
250 errmsg = "Device does not respond";
251 break;
252 }
253 if (packet < 0) {
254 em28xx_isocdbg("URB status %d [%s].\n", status, errmsg);
255 } else {
256 em28xx_isocdbg("URB packet %d, status %d [%s].\n",
257 packet, status, errmsg);
258 }
259}
260
261/*
262 * video-buf generic routine to get the next available buffer
263 */
264static inline void get_next_buf(struct em28xx_dmaqueue *dma_q,
265 struct em28xx_buffer **buf)
266{
267 struct em28xx *dev = container_of(dma_q, struct em28xx, vidq);
268 char *outp;
269
270 if (list_empty(&dma_q->active)) {
271 em28xx_isocdbg("No active queue to serve\n");
272 dev->isoc_ctl.buf = NULL;
273 *buf = NULL;
274 return;
275 }
276
277 /* Get the next buffer */
278 *buf = list_entry(dma_q->active.next, struct em28xx_buffer, vb.queue);
279
280 /* Cleans up buffer - Usefull for testing for frame/URB loss */
281 outp = videobuf_to_vmalloc(&(*buf)->vb);
282 memset(outp, 0, (*buf)->vb.size);
283
284 dev->isoc_ctl.buf = *buf;
285
286 return;
287}
288
289/*
290 * Controls the isoc copy of each urb packet
291 */
292static inline int em28xx_isoc_copy(struct em28xx *dev, struct urb *urb)
293{
294 struct em28xx_buffer *buf;
295 struct em28xx_dmaqueue *dma_q = urb->context;
296 unsigned char *outp = NULL;
297 int i, len = 0, rc = 1;
298 unsigned char *p;
299
300 if (!dev)
301 return 0;
302
303 if ((dev->state & DEV_DISCONNECTED) || (dev->state & DEV_MISCONFIGURED))
304 return 0;
305
306 if (urb->status < 0) {
307 print_err_status(dev, -1, urb->status);
308 if (urb->status == -ENOENT)
309 return 0;
310 }
311
312 buf = dev->isoc_ctl.buf;
313 if (buf != NULL)
314 outp = videobuf_to_vmalloc(&buf->vb);
315
316 for (i = 0; i < urb->number_of_packets; i++) {
317 int status = urb->iso_frame_desc[i].status;
318
319 if (status < 0) {
320 print_err_status(dev, i, status);
321 if (urb->iso_frame_desc[i].status != -EPROTO)
322 continue;
323 }
324
325 len = urb->iso_frame_desc[i].actual_length - 4;
326
327 if (urb->iso_frame_desc[i].actual_length <= 0) {
328 /* em28xx_isocdbg("packet %d is empty",i); - spammy */
329 continue;
330 }
331 if (urb->iso_frame_desc[i].actual_length >
332 dev->max_pkt_size) {
333 em28xx_isocdbg("packet bigger than packet size");
334 continue;
335 }
336
337 p = urb->transfer_buffer + urb->iso_frame_desc[i].offset;
338
339 /* FIXME: incomplete buffer checks where removed to make
340 logic simpler. Impacts of those changes should be evaluated
341 */
342 if (p[0] == 0x33 && p[1] == 0x95 && p[2] == 0x00) {
343 em28xx_isocdbg("VBI HEADER!!!\n");
344 /* FIXME: Should add vbi copy */
345 continue;
346 }
347 if (p[0] == 0x22 && p[1] == 0x5a) {
348 em28xx_isocdbg("Video frame %d, length=%i, %s\n", p[2],
349 len, (p[2] & 1)? "odd" : "even");
350
351 if (!(p[2] & 1)) {
352 if (buf != NULL)
353 buffer_filled(dev, dma_q, buf);
354 get_next_buf(dma_q, &buf);
355 if (buf == NULL)
356 outp = NULL;
357 else
358 outp = videobuf_to_vmalloc(&buf->vb);
359 }
360
361 if (buf != NULL) {
362 if (p[2] & 1)
363 buf->top_field = 0;
364 else
365 buf->top_field = 1;
366 }
367
368 dma_q->pos = 0;
369 }
370 if (buf != NULL)
371 em28xx_copy_video(dev, dma_q, buf, p, outp, len);
372 }
373 return rc;
374}
375
376/* ------------------------------------------------------------------
377 Videobuf operations
378 ------------------------------------------------------------------*/
379
380static int
381buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
382{
383 struct em28xx_fh *fh = vq->priv_data;
384 struct em28xx *dev = fh->dev;
385 struct v4l2_frequency f;
386
387 *size = 16 * fh->dev->width * fh->dev->height >> 3;
388 if (0 == *count)
389 *count = EM28XX_DEF_BUF;
390
391 if (*count < EM28XX_MIN_BUF)
392 *count = EM28XX_MIN_BUF;
393
394 /* Ask tuner to go to analog mode */
395 memset(&f, 0, sizeof(f));
396 f.frequency = dev->ctl_freq;
397
398 em28xx_i2c_call_clients(dev, VIDIOC_S_FREQUENCY, &f);
399
400 return 0;
401}
402
403/* This is called *without* dev->slock held; please keep it that way */
404static void free_buffer(struct videobuf_queue *vq, struct em28xx_buffer *buf)
405{
406 struct em28xx_fh *fh = vq->priv_data;
407 struct em28xx *dev = fh->dev;
408 unsigned long flags = 0;
409 if (in_interrupt())
410 BUG();
411
412 /* We used to wait for the buffer to finish here, but this didn't work
413 because, as we were keeping the state as VIDEOBUF_QUEUED,
414 videobuf_queue_cancel marked it as finished for us.
415 (Also, it could wedge forever if the hardware was misconfigured.)
416
417 This should be safe; by the time we get here, the buffer isn't
418 queued anymore. If we ever start marking the buffers as
419 VIDEOBUF_ACTIVE, it won't be, though.
420 */
421 spin_lock_irqsave(&dev->slock, flags);
422 if (dev->isoc_ctl.buf == buf)
423 dev->isoc_ctl.buf = NULL;
424 spin_unlock_irqrestore(&dev->slock, flags);
425
426 videobuf_vmalloc_free(&buf->vb);
427 buf->vb.state = VIDEOBUF_NEEDS_INIT;
428}
429
430static int
431buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
432 enum v4l2_field field)
433{
434 struct em28xx_fh *fh = vq->priv_data;
435 struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb);
436 struct em28xx *dev = fh->dev;
437 int rc = 0, urb_init = 0;
438
439 /* FIXME: It assumes depth = 16 */
440 /* The only currently supported format is 16 bits/pixel */
441 buf->vb.size = 16 * dev->width * dev->height >> 3;
442
443 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
444 return -EINVAL;
445
446 buf->vb.width = dev->width;
447 buf->vb.height = dev->height;
448 buf->vb.field = field;
449
450 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
451 rc = videobuf_iolock(vq, &buf->vb, NULL);
452 if (rc < 0)
453 goto fail;
454 }
455
456 if (!dev->isoc_ctl.num_bufs)
457 urb_init = 1;
458
459 if (urb_init) {
460 rc = em28xx_init_isoc(dev, EM28XX_NUM_PACKETS,
461 EM28XX_NUM_BUFS, dev->max_pkt_size,
462 em28xx_isoc_copy);
463 if (rc < 0)
464 goto fail;
465 }
466
467 buf->vb.state = VIDEOBUF_PREPARED;
468 return 0;
469
470fail:
471 free_buffer(vq, buf);
472 return rc;
473}
474
475static void
476buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
477{
478 struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb);
479 struct em28xx_fh *fh = vq->priv_data;
480 struct em28xx *dev = fh->dev;
481 struct em28xx_dmaqueue *vidq = &dev->vidq;
482
483 buf->vb.state = VIDEOBUF_QUEUED;
484 list_add_tail(&buf->vb.queue, &vidq->active);
485
486}
487
488static void buffer_release(struct videobuf_queue *vq,
489 struct videobuf_buffer *vb)
490{
491 struct em28xx_buffer *buf = container_of(vb, struct em28xx_buffer, vb);
492 struct em28xx_fh *fh = vq->priv_data;
493 struct em28xx *dev = (struct em28xx *)fh->dev;
494
495 em28xx_isocdbg("em28xx: called buffer_release\n");
496
497 free_buffer(vq, buf);
498}
499
500static struct videobuf_queue_ops em28xx_video_qops = {
501 .buf_setup = buffer_setup,
502 .buf_prepare = buffer_prepare,
503 .buf_queue = buffer_queue,
504 .buf_release = buffer_release,
505};
506
507/********************* v4l2 interface **************************************/
112 508
113/* 509/*
114 * em28xx_config() 510 * em28xx_config()
@@ -123,9 +519,9 @@ static int em28xx_config(struct em28xx *dev)
123 519
124 /* enable vbi capturing */ 520 /* enable vbi capturing */
125 521
126/* em28xx_write_regs_req(dev,0x00,0x0e,"\xC0",1); audio register */ 522/* em28xx_write_regs_req(dev, 0x00, 0x0e, "\xC0", 1); audio register */
127/* em28xx_write_regs_req(dev,0x00,0x0f,"\x80",1); clk register */ 523/* em28xx_write_regs_req(dev, 0x00, 0x0f, "\x80", 1); clk register */
128 em28xx_write_regs_req(dev,0x00,0x11,"\x51",1); 524 em28xx_write_regs_req(dev, 0x00, 0x11, "\x51", 1);
129 525
130 dev->mute = 1; /* maybe not the right place... */ 526 dev->mute = 1; /* maybe not the right place... */
131 dev->volume = 0x1f; 527 dev->volume = 0x1f;
@@ -152,23 +548,6 @@ static void em28xx_config_i2c(struct em28xx *dev)
152 em28xx_i2c_call_clients(dev, VIDIOC_STREAMON, NULL); 548 em28xx_i2c_call_clients(dev, VIDIOC_STREAMON, NULL);
153} 549}
154 550
155/*
156 * em28xx_empty_framequeues()
157 * prepare queues for incoming and outgoing frames
158 */
159static void em28xx_empty_framequeues(struct em28xx *dev)
160{
161 u32 i;
162
163 INIT_LIST_HEAD(&dev->inqueue);
164 INIT_LIST_HEAD(&dev->outqueue);
165
166 for (i = 0; i < EM28XX_NUM_FRAMES; i++) {
167 dev->frame[i].state = F_UNUSED;
168 dev->frame[i].buf.bytesused = 0;
169 }
170}
171
172static void video_mux(struct em28xx *dev, int index) 551static void video_mux(struct em28xx *dev, int index)
173{ 552{
174 struct v4l2_routing route; 553 struct v4l2_routing route;
@@ -181,12 +560,15 @@ static void video_mux(struct em28xx *dev, int index)
181 em28xx_i2c_call_clients(dev, VIDIOC_INT_S_VIDEO_ROUTING, &route); 560 em28xx_i2c_call_clients(dev, VIDIOC_INT_S_VIDEO_ROUTING, &route);
182 561
183 if (dev->has_msp34xx) { 562 if (dev->has_msp34xx) {
184 if (dev->i2s_speed) 563 if (dev->i2s_speed) {
185 em28xx_i2c_call_clients(dev, VIDIOC_INT_I2S_CLOCK_FREQ, &dev->i2s_speed); 564 em28xx_i2c_call_clients(dev, VIDIOC_INT_I2S_CLOCK_FREQ,
565 &dev->i2s_speed);
566 }
186 route.input = dev->ctl_ainput; 567 route.input = dev->ctl_ainput;
187 route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1); 568 route.output = MSP_OUTPUT(MSP_SC_IN_DSP_SCART1);
188 /* Note: this is msp3400 specific */ 569 /* Note: this is msp3400 specific */
189 em28xx_i2c_call_clients(dev, VIDIOC_INT_S_AUDIO_ROUTING, &route); 570 em28xx_i2c_call_clients(dev, VIDIOC_INT_S_AUDIO_ROUTING,
571 &route);
190 } 572 }
191 573
192 em28xx_audio_analog_set(dev); 574 em28xx_audio_analog_set(dev);
@@ -202,15 +584,12 @@ static int res_get(struct em28xx_fh *fh)
202 if (fh->stream_on) 584 if (fh->stream_on)
203 return rc; 585 return rc;
204 586
205 mutex_lock(&dev->lock);
206
207 if (dev->stream_on) 587 if (dev->stream_on)
208 rc = -EINVAL; 588 return -EINVAL;
209 else {
210 dev->stream_on = 1;
211 fh->stream_on = 1;
212 }
213 589
590 mutex_lock(&dev->lock);
591 dev->stream_on = 1;
592 fh->stream_on = 1;
214 mutex_unlock(&dev->lock); 593 mutex_unlock(&dev->lock);
215 return rc; 594 return rc;
216} 595}
@@ -231,33 +610,6 @@ static void res_free(struct em28xx_fh *fh)
231} 610}
232 611
233/* 612/*
234 * em28xx_vm_open()
235 */
236static void em28xx_vm_open(struct vm_area_struct *vma)
237{
238 struct em28xx_frame_t *f = vma->vm_private_data;
239 f->vma_use_count++;
240}
241
242/*
243 * em28xx_vm_close()
244 */
245static void em28xx_vm_close(struct vm_area_struct *vma)
246{
247 /* NOTE: buffers are not freed here */
248 struct em28xx_frame_t *f = vma->vm_private_data;
249
250 if (f->vma_use_count)
251 f->vma_use_count--;
252}
253
254static struct vm_operations_struct em28xx_vm_ops = {
255 .open = em28xx_vm_open,
256 .close = em28xx_vm_close,
257};
258
259
260/*
261 * em28xx_get_ctrl() 613 * em28xx_get_ctrl()
262 * return the current saturation, brightness or contrast, mute state 614 * return the current saturation, brightness or contrast, mute state
263 */ 615 */
@@ -296,34 +648,6 @@ static int em28xx_set_ctrl(struct em28xx *dev, const struct v4l2_control *ctrl)
296 } 648 }
297} 649}
298 650
299/*
300 * em28xx_stream_interrupt()
301 * stops streaming
302 */
303static int em28xx_stream_interrupt(struct em28xx *dev)
304{
305 int rc = 0;
306
307 /* stop reading from the device */
308
309 dev->stream = STREAM_INTERRUPT;
310 rc = wait_event_timeout(dev->wait_stream,
311 (dev->stream == STREAM_OFF) ||
312 (dev->state & DEV_DISCONNECTED),
313 EM28XX_URB_TIMEOUT);
314
315 if (rc) {
316 dev->state |= DEV_MISCONFIGURED;
317 em28xx_videodbg("device is misconfigured; close and "
318 "open /dev/video%d again\n",
319 dev->vdev->minor-MINOR_VFL_TYPE_GRABBER_MIN);
320 return rc;
321 }
322
323 return 0;
324}
325
326
327static int check_dev(struct em28xx *dev) 651static int check_dev(struct em28xx *dev)
328{ 652{
329 if (dev->state & DEV_DISCONNECTED) { 653 if (dev->state & DEV_DISCONNECTED) {
@@ -370,8 +694,8 @@ static int vidioc_g_fmt_cap(struct file *file, void *priv,
370 f->fmt.pix.width = dev->width; 694 f->fmt.pix.width = dev->width;
371 f->fmt.pix.height = dev->height; 695 f->fmt.pix.height = dev->height;
372 f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV; 696 f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
373 f->fmt.pix.bytesperline = dev->bytesperline; 697 f->fmt.pix.bytesperline = dev->width * 2;
374 f->fmt.pix.sizeimage = dev->frame_size; 698 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline * dev->height;
375 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M; 699 f->fmt.pix.colorspace = V4L2_COLORSPACE_SMPTE170M;
376 700
377 /* FIXME: TOP? NONE? BOTTOM? ALTENATE? */ 701 /* FIXME: TOP? NONE? BOTTOM? ALTENATE? */
@@ -447,7 +771,7 @@ static int vidioc_s_fmt_cap(struct file *file, void *priv,
447{ 771{
448 struct em28xx_fh *fh = priv; 772 struct em28xx_fh *fh = priv;
449 struct em28xx *dev = fh->dev; 773 struct em28xx *dev = fh->dev;
450 int rc, i; 774 int rc;
451 775
452 rc = check_dev(dev); 776 rc = check_dev(dev);
453 if (rc < 0) 777 if (rc < 0)
@@ -457,49 +781,34 @@ static int vidioc_s_fmt_cap(struct file *file, void *priv,
457 781
458 mutex_lock(&dev->lock); 782 mutex_lock(&dev->lock);
459 783
460 for (i = 0; i < dev->num_frames; i++) 784 if (videobuf_queue_is_busy(&fh->vb_vidq)) {
461 if (dev->frame[i].vma_use_count) { 785 em28xx_errdev("%s queue busy\n", __func__);
462 em28xx_videodbg("VIDIOC_S_FMT failed. " 786 rc = -EBUSY;
463 "Unmap the buffers first.\n"); 787 goto out;
464 rc = -EINVAL;
465 goto err;
466 }
467
468 /* stop io in case it is already in progress */
469 if (dev->stream == STREAM_ON) {
470 em28xx_videodbg("VIDIOC_SET_FMT: interrupting stream\n");
471 rc = em28xx_stream_interrupt(dev);
472 if (rc < 0)
473 goto err;
474 } 788 }
475 789
476 em28xx_release_buffers(dev); 790 if (dev->stream_on && !fh->stream_on) {
477 dev->io = IO_NONE; 791 em28xx_errdev("%s device in use by another fh\n", __func__);
792 rc = -EBUSY;
793 goto out;
794 }
478 795
479 /* set new image size */ 796 /* set new image size */
480 dev->width = f->fmt.pix.width; 797 dev->width = f->fmt.pix.width;
481 dev->height = f->fmt.pix.height; 798 dev->height = f->fmt.pix.height;
482 dev->frame_size = dev->width * dev->height * 2;
483 dev->field_size = dev->frame_size >> 1;
484 dev->bytesperline = dev->width * 2;
485 get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale); 799 get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
486 800
487 /* FIXME: This is really weird! Why capture is starting with
488 this ioctl ???
489 */
490 em28xx_uninit_isoc(dev);
491 em28xx_set_alternate(dev); 801 em28xx_set_alternate(dev);
492 em28xx_capture_start(dev, 1);
493 em28xx_resolution_set(dev); 802 em28xx_resolution_set(dev);
494 em28xx_init_isoc(dev); 803
495 rc = 0; 804 rc = 0;
496 805
497err: 806out:
498 mutex_unlock(&dev->lock); 807 mutex_unlock(&dev->lock);
499 return rc; 808 return rc;
500} 809}
501 810
502static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm) 811static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id * norm)
503{ 812{
504 struct em28xx_fh *fh = priv; 813 struct em28xx_fh *fh = priv;
505 struct em28xx *dev = fh->dev; 814 struct em28xx *dev = fh->dev;
@@ -524,9 +833,6 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *norm)
524 /* set new image size */ 833 /* set new image size */
525 dev->width = f.fmt.pix.width; 834 dev->width = f.fmt.pix.width;
526 dev->height = f.fmt.pix.height; 835 dev->height = f.fmt.pix.height;
527 dev->frame_size = dev->width * dev->height * 2;
528 dev->field_size = dev->frame_size >> 1;
529 dev->bytesperline = dev->width * 2;
530 get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale); 836 get_scale(dev, dev->width, dev->height, &dev->hscale, &dev->vscale);
531 837
532 em28xx_resolution_set(dev); 838 em28xx_resolution_set(dev);
@@ -619,11 +925,11 @@ static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
619 925
620 index = dev->ctl_ainput; 926 index = dev->ctl_ainput;
621 927
622 if (index == 0) { 928 if (index == 0)
623 strcpy(a->name, "Television"); 929 strcpy(a->name, "Television");
624 } else { 930 else
625 strcpy(a->name, "Line In"); 931 strcpy(a->name, "Line In");
626 } 932
627 a->capability = V4L2_AUDCAP_STEREO; 933 a->capability = V4L2_AUDCAP_STEREO;
628 a->index = index; 934 a->index = index;
629 935
@@ -834,9 +1140,9 @@ static int vidioc_s_frequency(struct file *file, void *priv,
834static int em28xx_reg_len(int reg) 1140static int em28xx_reg_len(int reg)
835{ 1141{
836 switch (reg) { 1142 switch (reg) {
837 case AC97LSB_REG: 1143 case EM28XX_R40_AC97LSB:
838 case HSCALELOW_REG: 1144 case EM28XX_R30_HSCALELOW:
839 case VSCALELOW_REG: 1145 case EM28XX_R32_VSCALELOW:
840 return 2; 1146 return 2;
841 default: 1147 default:
842 return 1; 1148 return 1;
@@ -918,23 +1224,11 @@ static int vidioc_streamon(struct file *file, void *priv,
918 if (rc < 0) 1224 if (rc < 0)
919 return rc; 1225 return rc;
920 1226
921 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE || dev->io != IO_MMAP)
922 return -EINVAL;
923
924 if (list_empty(&dev->inqueue))
925 return -EINVAL;
926
927 mutex_lock(&dev->lock);
928 1227
929 if (unlikely(res_get(fh) < 0)) { 1228 if (unlikely(res_get(fh) < 0))
930 mutex_unlock(&dev->lock);
931 return -EBUSY; 1229 return -EBUSY;
932 }
933 1230
934 dev->stream = STREAM_ON; /* FIXME: Start video capture here? */ 1231 return (videobuf_streamon(&fh->vb_vidq));
935
936 mutex_unlock(&dev->lock);
937 return 0;
938} 1232}
939 1233
940static int vidioc_streamoff(struct file *file, void *priv, 1234static int vidioc_streamoff(struct file *file, void *priv,
@@ -948,23 +1242,14 @@ static int vidioc_streamoff(struct file *file, void *priv,
948 if (rc < 0) 1242 if (rc < 0)
949 return rc; 1243 return rc;
950 1244
951 if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE || dev->io != IO_MMAP) 1245 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1246 return -EINVAL;
1247 if (type != fh->type)
952 return -EINVAL; 1248 return -EINVAL;
953 1249
954 mutex_lock(&dev->lock); 1250 videobuf_streamoff(&fh->vb_vidq);
955 1251 res_free(fh);
956 if (dev->stream == STREAM_ON) {
957 em28xx_videodbg("VIDIOC_STREAMOFF: interrupting stream\n");
958 rc = em28xx_stream_interrupt(dev);
959 if (rc < 0) {
960 mutex_unlock(&dev->lock);
961 return rc;
962 }
963 }
964
965 em28xx_empty_framequeues(dev);
966 1252
967 mutex_unlock(&dev->lock);
968 return 0; 1253 return 0;
969} 1254}
970 1255
@@ -1058,53 +1343,13 @@ static int vidioc_reqbufs(struct file *file, void *priv,
1058{ 1343{
1059 struct em28xx_fh *fh = priv; 1344 struct em28xx_fh *fh = priv;
1060 struct em28xx *dev = fh->dev; 1345 struct em28xx *dev = fh->dev;
1061 u32 i;
1062 int rc; 1346 int rc;
1063 1347
1064 rc = check_dev(dev); 1348 rc = check_dev(dev);
1065 if (rc < 0) 1349 if (rc < 0)
1066 return rc; 1350 return rc;
1067 1351
1068 if (rb->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || 1352 return (videobuf_reqbufs(&fh->vb_vidq, rb));
1069 rb->memory != V4L2_MEMORY_MMAP)
1070 return -EINVAL;
1071
1072 if (dev->io == IO_READ) {
1073 em28xx_videodbg("method is set to read;"
1074 " close and open the device again to"
1075 " choose the mmap I/O method\n");
1076 return -EINVAL;
1077 }
1078
1079 for (i = 0; i < dev->num_frames; i++)
1080 if (dev->frame[i].vma_use_count) {
1081 em28xx_videodbg("VIDIOC_REQBUFS failed; "
1082 "previous buffers are still mapped\n");
1083 return -EINVAL;
1084 }
1085
1086 mutex_lock(&dev->lock);
1087
1088 if (dev->stream == STREAM_ON) {
1089 em28xx_videodbg("VIDIOC_REQBUFS: interrupting stream\n");
1090 rc = em28xx_stream_interrupt(dev);
1091 if (rc < 0) {
1092 mutex_unlock(&dev->lock);
1093 return rc;
1094 }
1095 }
1096
1097 em28xx_empty_framequeues(dev);
1098
1099 em28xx_release_buffers(dev);
1100 if (rb->count)
1101 rb->count = em28xx_request_buffers(dev, rb->count);
1102
1103 dev->frame_current = NULL;
1104 dev->io = rb->count ? IO_MMAP : IO_NONE;
1105
1106 mutex_unlock(&dev->lock);
1107 return 0;
1108} 1353}
1109 1354
1110static int vidioc_querybuf(struct file *file, void *priv, 1355static int vidioc_querybuf(struct file *file, void *priv,
@@ -1118,52 +1363,20 @@ static int vidioc_querybuf(struct file *file, void *priv,
1118 if (rc < 0) 1363 if (rc < 0)
1119 return rc; 1364 return rc;
1120 1365
1121 if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || 1366 return (videobuf_querybuf(&fh->vb_vidq, b));
1122 b->index >= dev->num_frames || dev->io != IO_MMAP)
1123 return -EINVAL;
1124
1125 mutex_lock(&dev->lock);
1126
1127 memcpy(b, &dev->frame[b->index].buf, sizeof(*b));
1128
1129 if (dev->frame[b->index].vma_use_count)
1130 b->flags |= V4L2_BUF_FLAG_MAPPED;
1131
1132 if (dev->frame[b->index].state == F_DONE)
1133 b->flags |= V4L2_BUF_FLAG_DONE;
1134 else if (dev->frame[b->index].state != F_UNUSED)
1135 b->flags |= V4L2_BUF_FLAG_QUEUED;
1136
1137 mutex_unlock(&dev->lock);
1138 return 0;
1139} 1367}
1140 1368
1141static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b) 1369static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
1142{ 1370{
1143 struct em28xx_fh *fh = priv; 1371 struct em28xx_fh *fh = priv;
1144 struct em28xx *dev = fh->dev; 1372 struct em28xx *dev = fh->dev;
1145 unsigned long lock_flags;
1146 int rc; 1373 int rc;
1147 1374
1148 rc = check_dev(dev); 1375 rc = check_dev(dev);
1149 if (rc < 0) 1376 if (rc < 0)
1150 return rc; 1377 return rc;
1151 1378
1152 if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || dev->io != IO_MMAP || 1379 return (videobuf_qbuf(&fh->vb_vidq, b));
1153 b->index >= dev->num_frames)
1154 return -EINVAL;
1155
1156 if (dev->frame[b->index].state != F_UNUSED)
1157 return -EAGAIN;
1158
1159 dev->frame[b->index].state = F_QUEUED;
1160
1161 /* add frame to fifo */
1162 spin_lock_irqsave(&dev->queue_lock, lock_flags);
1163 list_add_tail(&dev->frame[b->index].frame, &dev->inqueue);
1164 spin_unlock_irqrestore(&dev->queue_lock, lock_flags);
1165
1166 return 0;
1167} 1380}
1168 1381
1169static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b) 1382static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
@@ -1171,46 +1384,24 @@ static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
1171 struct em28xx_fh *fh = priv; 1384 struct em28xx_fh *fh = priv;
1172 struct em28xx *dev = fh->dev; 1385 struct em28xx *dev = fh->dev;
1173 int rc; 1386 int rc;
1174 struct em28xx_frame_t *f;
1175 unsigned long lock_flags;
1176 1387
1177 rc = check_dev(dev); 1388 rc = check_dev(dev);
1178 if (rc < 0) 1389 if (rc < 0)
1179 return rc; 1390 return rc;
1180 1391
1181 if (b->type != V4L2_BUF_TYPE_VIDEO_CAPTURE || dev->io != IO_MMAP) 1392 return (videobuf_dqbuf(&fh->vb_vidq, b,
1182 return -EINVAL; 1393 file->f_flags & O_NONBLOCK));
1183 1394}
1184 if (list_empty(&dev->outqueue)) {
1185 if (dev->stream == STREAM_OFF)
1186 return -EINVAL;
1187
1188 if (file->f_flags & O_NONBLOCK)
1189 return -EAGAIN;
1190
1191 rc = wait_event_interruptible(dev->wait_frame,
1192 (!list_empty(&dev->outqueue)) ||
1193 (dev->state & DEV_DISCONNECTED));
1194 if (rc)
1195 return rc;
1196
1197 if (dev->state & DEV_DISCONNECTED)
1198 return -ENODEV;
1199 }
1200
1201 spin_lock_irqsave(&dev->queue_lock, lock_flags);
1202 f = list_entry(dev->outqueue.next, struct em28xx_frame_t, frame);
1203 list_del(dev->outqueue.next);
1204 spin_unlock_irqrestore(&dev->queue_lock, lock_flags);
1205
1206 f->state = F_UNUSED;
1207 memcpy(b, &f->buf, sizeof(*b));
1208 1395
1209 if (f->vma_use_count) 1396#ifdef CONFIG_VIDEO_V4L1_COMPAT
1210 b->flags |= V4L2_BUF_FLAG_MAPPED; 1397static int vidiocgmbuf(struct file *file, void *priv, struct video_mbuf *mbuf)
1398{
1399 struct em28xx_fh *fh = priv;
1211 1400
1212 return 0; 1401 return videobuf_cgmbuf(&fh->vb_vidq, mbuf, 8);
1213} 1402}
1403#endif
1404
1214 1405
1215/* ----------------------------------------------------------- */ 1406/* ----------------------------------------------------------- */
1216/* RADIO ESPECIFIC IOCTLS */ 1407/* RADIO ESPECIFIC IOCTLS */
@@ -1316,17 +1507,18 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
1316{ 1507{
1317 int minor = iminor(inode); 1508 int minor = iminor(inode);
1318 int errCode = 0, radio = 0; 1509 int errCode = 0, radio = 0;
1319 struct em28xx *h,*dev = NULL; 1510 struct em28xx *h, *dev = NULL;
1320 struct em28xx_fh *fh; 1511 struct em28xx_fh *fh;
1512 enum v4l2_buf_type fh_type = 0;
1321 1513
1322 list_for_each_entry(h, &em28xx_devlist, devlist) { 1514 list_for_each_entry(h, &em28xx_devlist, devlist) {
1323 if (h->vdev->minor == minor) { 1515 if (h->vdev->minor == minor) {
1324 dev = h; 1516 dev = h;
1325 dev->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1517 fh_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1326 } 1518 }
1327 if (h->vbi_dev->minor == minor) { 1519 if (h->vbi_dev->minor == minor) {
1328 dev = h; 1520 dev = h;
1329 dev->type = V4L2_BUF_TYPE_VBI_CAPTURE; 1521 fh_type = V4L2_BUF_TYPE_VBI_CAPTURE;
1330 } 1522 }
1331 if (h->radio_dev && 1523 if (h->radio_dev &&
1332 h->radio_dev->minor == minor) { 1524 h->radio_dev->minor == minor) {
@@ -1338,10 +1530,10 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
1338 return -ENODEV; 1530 return -ENODEV;
1339 1531
1340 em28xx_videodbg("open minor=%d type=%s users=%d\n", 1532 em28xx_videodbg("open minor=%d type=%s users=%d\n",
1341 minor,v4l2_type_names[dev->type],dev->users); 1533 minor, v4l2_type_names[fh_type], dev->users);
1342 1534
1343 fh = kzalloc(sizeof(struct em28xx_fh), GFP_KERNEL);
1344 1535
1536 fh = kzalloc(sizeof(struct em28xx_fh), GFP_KERNEL);
1345 if (!fh) { 1537 if (!fh) {
1346 em28xx_errdev("em28xx-video.c: Out of memory?!\n"); 1538 em28xx_errdev("em28xx-video.c: Out of memory?!\n");
1347 return -ENOMEM; 1539 return -ENOMEM;
@@ -1349,28 +1541,24 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
1349 mutex_lock(&dev->lock); 1541 mutex_lock(&dev->lock);
1350 fh->dev = dev; 1542 fh->dev = dev;
1351 fh->radio = radio; 1543 fh->radio = radio;
1544 fh->type = fh_type;
1352 filp->private_data = fh; 1545 filp->private_data = fh;
1353 1546
1354 if (dev->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) { 1547 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE && dev->users == 0) {
1355 dev->width = norm_maxw(dev); 1548 dev->width = norm_maxw(dev);
1356 dev->height = norm_maxh(dev); 1549 dev->height = norm_maxh(dev);
1357 dev->frame_size = dev->width * dev->height * 2;
1358 dev->field_size = dev->frame_size >> 1; /*both_fileds ? dev->frame_size>>1 : dev->frame_size; */
1359 dev->bytesperline = dev->width * 2;
1360 dev->hscale = 0; 1550 dev->hscale = 0;
1361 dev->vscale = 0; 1551 dev->vscale = 0;
1362 1552
1553 em28xx_set_mode(dev, EM28XX_ANALOG_MODE);
1363 em28xx_set_alternate(dev); 1554 em28xx_set_alternate(dev);
1364 em28xx_capture_start(dev, 1);
1365 em28xx_resolution_set(dev); 1555 em28xx_resolution_set(dev);
1366 1556
1557 /* Needed, since GPIO might have disabled power of
1558 some i2c device
1559 */
1560 em28xx_config_i2c(dev);
1367 1561
1368 /* start the transfer */
1369 errCode = em28xx_init_isoc(dev);
1370 if (errCode)
1371 goto err;
1372
1373 em28xx_empty_framequeues(dev);
1374 } 1562 }
1375 if (fh->radio) { 1563 if (fh->radio) {
1376 em28xx_videodbg("video_open: setting radio device\n"); 1564 em28xx_videodbg("video_open: setting radio device\n");
@@ -1379,8 +1567,12 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
1379 1567
1380 dev->users++; 1568 dev->users++;
1381 1569
1382err: 1570 videobuf_queue_vmalloc_init(&fh->vb_vidq, &em28xx_video_qops,
1571 NULL, &dev->slock, fh->type, V4L2_FIELD_INTERLACED,
1572 sizeof(struct em28xx_buffer), fh);
1573
1383 mutex_unlock(&dev->lock); 1574 mutex_unlock(&dev->lock);
1575
1384 return errCode; 1576 return errCode;
1385} 1577}
1386 1578
@@ -1423,12 +1615,13 @@ static void em28xx_release_resources(struct em28xx *dev)
1423 usb_put_dev(dev->udev); 1615 usb_put_dev(dev->udev);
1424 1616
1425 /* Mark device as unused */ 1617 /* Mark device as unused */
1426 em28xx_devused&=~(1<<dev->devno); 1618 em28xx_devused &= ~(1<<dev->devno);
1427} 1619}
1428 1620
1429/* 1621/*
1430 * em28xx_v4l2_close() 1622 * em28xx_v4l2_close()
1431 * stops streaming and deallocates all resources allocated by the v4l2 calls and ioctls 1623 * stops streaming and deallocates all resources allocated by the v4l2
1624 * calls and ioctls
1432 */ 1625 */
1433static int em28xx_v4l2_close(struct inode *inode, struct file *filp) 1626static int em28xx_v4l2_close(struct inode *inode, struct file *filp)
1434{ 1627{
@@ -1445,9 +1638,8 @@ static int em28xx_v4l2_close(struct inode *inode, struct file *filp)
1445 mutex_lock(&dev->lock); 1638 mutex_lock(&dev->lock);
1446 1639
1447 if (dev->users == 1) { 1640 if (dev->users == 1) {
1448 em28xx_uninit_isoc(dev); 1641 videobuf_stop(&fh->vb_vidq);
1449 em28xx_release_buffers(dev); 1642 videobuf_mmap_free(&fh->vb_vidq);
1450 dev->io = IO_NONE;
1451 1643
1452 /* the device is already disconnect, 1644 /* the device is already disconnect,
1453 free the remaining resources */ 1645 free the remaining resources */
@@ -1458,6 +1650,10 @@ static int em28xx_v4l2_close(struct inode *inode, struct file *filp)
1458 return 0; 1650 return 0;
1459 } 1651 }
1460 1652
1653 /* do this before setting alternate! */
1654 em28xx_uninit_isoc(dev);
1655 em28xx_set_mode(dev, EM28XX_MODE_UNDEFINED);
1656
1461 /* set alternate 0 */ 1657 /* set alternate 0 */
1462 dev->alt = 0; 1658 dev->alt = 0;
1463 em28xx_videodbg("setting alternate 0\n"); 1659 em28xx_videodbg("setting alternate 0\n");
@@ -1479,135 +1675,29 @@ static int em28xx_v4l2_close(struct inode *inode, struct file *filp)
1479 * will allocate buffers when called for the first time 1675 * will allocate buffers when called for the first time
1480 */ 1676 */
1481static ssize_t 1677static ssize_t
1482em28xx_v4l2_read(struct file *filp, char __user * buf, size_t count, 1678em28xx_v4l2_read(struct file *filp, char __user *buf, size_t count,
1483 loff_t * f_pos) 1679 loff_t *pos)
1484{ 1680{
1485 struct em28xx_frame_t *f, *i;
1486 unsigned long lock_flags;
1487 int ret = 0;
1488 struct em28xx_fh *fh = filp->private_data; 1681 struct em28xx_fh *fh = filp->private_data;
1489 struct em28xx *dev = fh->dev; 1682 struct em28xx *dev = fh->dev;
1683 int rc;
1684
1685 rc = check_dev(dev);
1686 if (rc < 0)
1687 return rc;
1490 1688
1491 /* FIXME: read() is not prepared to allow changing the video 1689 /* FIXME: read() is not prepared to allow changing the video
1492 resolution while streaming. Seems a bug at em28xx_set_fmt 1690 resolution while streaming. Seems a bug at em28xx_set_fmt
1493 */ 1691 */
1494 1692
1495 if (unlikely(res_get(fh) < 0)) 1693 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1496 return -EBUSY; 1694 if (unlikely(res_get(fh)))
1497 1695 return -EBUSY;
1498 mutex_lock(&dev->lock);
1499
1500 if (dev->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1501 em28xx_videodbg("V4l2_Buf_type_videocapture is set\n");
1502 1696
1503 if (dev->type == V4L2_BUF_TYPE_VBI_CAPTURE) { 1697 return videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0,
1504 em28xx_videodbg("V4L2_BUF_TYPE_VBI_CAPTURE is set\n"); 1698 filp->f_flags & O_NONBLOCK);
1505 em28xx_videodbg("not supported yet! ...\n");
1506 if (copy_to_user(buf, "", 1)) {
1507 mutex_unlock(&dev->lock);
1508 return -EFAULT;
1509 }
1510 mutex_unlock(&dev->lock);
1511 return (1);
1512 }
1513 if (dev->type == V4L2_BUF_TYPE_SLICED_VBI_CAPTURE) {
1514 em28xx_videodbg("V4L2_BUF_TYPE_SLICED_VBI_CAPTURE is set\n");
1515 em28xx_videodbg("not supported yet! ...\n");
1516 if (copy_to_user(buf, "", 1)) {
1517 mutex_unlock(&dev->lock);
1518 return -EFAULT;
1519 }
1520 mutex_unlock(&dev->lock);
1521 return (1);
1522 } 1699 }
1523 1700 return 0;
1524 if (dev->state & DEV_DISCONNECTED) {
1525 em28xx_videodbg("device not present\n");
1526 mutex_unlock(&dev->lock);
1527 return -ENODEV;
1528 }
1529
1530 if (dev->state & DEV_MISCONFIGURED) {
1531 em28xx_videodbg("device misconfigured; close and open it again\n");
1532 mutex_unlock(&dev->lock);
1533 return -EIO;
1534 }
1535
1536 if (dev->io == IO_MMAP) {
1537 em28xx_videodbg ("IO method is set to mmap; close and open"
1538 " the device again to choose the read method\n");
1539 mutex_unlock(&dev->lock);
1540 return -EINVAL;
1541 }
1542
1543 if (dev->io == IO_NONE) {
1544 if (!em28xx_request_buffers(dev, EM28XX_NUM_READ_FRAMES)) {
1545 em28xx_errdev("read failed, not enough memory\n");
1546 mutex_unlock(&dev->lock);
1547 return -ENOMEM;
1548 }
1549 dev->io = IO_READ;
1550 dev->stream = STREAM_ON;
1551 em28xx_queue_unusedframes(dev);
1552 }
1553
1554 if (!count) {
1555 mutex_unlock(&dev->lock);
1556 return 0;
1557 }
1558
1559 if (list_empty(&dev->outqueue)) {
1560 if (filp->f_flags & O_NONBLOCK) {
1561 mutex_unlock(&dev->lock);
1562 return -EAGAIN;
1563 }
1564 ret = wait_event_interruptible
1565 (dev->wait_frame,
1566 (!list_empty(&dev->outqueue)) ||
1567 (dev->state & DEV_DISCONNECTED));
1568 if (ret) {
1569 mutex_unlock(&dev->lock);
1570 return ret;
1571 }
1572 if (dev->state & DEV_DISCONNECTED) {
1573 mutex_unlock(&dev->lock);
1574 return -ENODEV;
1575 }
1576 dev->video_bytesread = 0;
1577 }
1578
1579 f = list_entry(dev->outqueue.prev, struct em28xx_frame_t, frame);
1580
1581 em28xx_queue_unusedframes(dev);
1582
1583 if (count > f->buf.length)
1584 count = f->buf.length;
1585
1586 if ((dev->video_bytesread + count) > dev->frame_size)
1587 count = dev->frame_size - dev->video_bytesread;
1588
1589 if (copy_to_user(buf, f->bufmem+dev->video_bytesread, count)) {
1590 em28xx_err("Error while copying to user\n");
1591 return -EFAULT;
1592 }
1593 dev->video_bytesread += count;
1594
1595 if (dev->video_bytesread == dev->frame_size) {
1596 spin_lock_irqsave(&dev->queue_lock, lock_flags);
1597 list_for_each_entry(i, &dev->outqueue, frame)
1598 i->state = F_UNUSED;
1599 INIT_LIST_HEAD(&dev->outqueue);
1600 spin_unlock_irqrestore(&dev->queue_lock, lock_flags);
1601
1602 em28xx_queue_unusedframes(dev);
1603 dev->video_bytesread = 0;
1604 }
1605
1606 *f_pos += count;
1607
1608 mutex_unlock(&dev->lock);
1609
1610 return count;
1611} 1701}
1612 1702
1613/* 1703/*
@@ -1616,46 +1706,21 @@ em28xx_v4l2_read(struct file *filp, char __user * buf, size_t count,
1616 */ 1706 */
1617static unsigned int em28xx_v4l2_poll(struct file *filp, poll_table * wait) 1707static unsigned int em28xx_v4l2_poll(struct file *filp, poll_table * wait)
1618{ 1708{
1619 unsigned int mask = 0;
1620 struct em28xx_fh *fh = filp->private_data; 1709 struct em28xx_fh *fh = filp->private_data;
1621 struct em28xx *dev = fh->dev; 1710 struct em28xx *dev = fh->dev;
1711 int rc;
1712
1713 rc = check_dev(dev);
1714 if (rc < 0)
1715 return rc;
1622 1716
1623 if (unlikely(res_get(fh) < 0)) 1717 if (unlikely(res_get(fh) < 0))
1624 return POLLERR; 1718 return POLLERR;
1625 1719
1626 mutex_lock(&dev->lock); 1720 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
1627 1721 return POLLERR;
1628 if (dev->state & DEV_DISCONNECTED) {
1629 em28xx_videodbg("device not present\n");
1630 } else if (dev->state & DEV_MISCONFIGURED) {
1631 em28xx_videodbg("device is misconfigured; close and open it again\n");
1632 } else {
1633 if (dev->io == IO_NONE) {
1634 if (!em28xx_request_buffers
1635 (dev, EM28XX_NUM_READ_FRAMES)) {
1636 em28xx_warn
1637 ("poll() failed, not enough memory\n");
1638 } else {
1639 dev->io = IO_READ;
1640 dev->stream = STREAM_ON;
1641 }
1642 }
1643
1644 if (dev->io == IO_READ) {
1645 em28xx_queue_unusedframes(dev);
1646 poll_wait(filp, &dev->wait_frame, wait);
1647
1648 if (!list_empty(&dev->outqueue))
1649 mask |= POLLIN | POLLRDNORM;
1650
1651 mutex_unlock(&dev->lock);
1652
1653 return mask;
1654 }
1655 }
1656 1722
1657 mutex_unlock(&dev->lock); 1723 return videobuf_poll_stream(filp, &fh->vb_vidq, wait);
1658 return POLLERR;
1659} 1724}
1660 1725
1661/* 1726/*
@@ -1665,69 +1730,23 @@ static int em28xx_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
1665{ 1730{
1666 struct em28xx_fh *fh = filp->private_data; 1731 struct em28xx_fh *fh = filp->private_data;
1667 struct em28xx *dev = fh->dev; 1732 struct em28xx *dev = fh->dev;
1668 unsigned long size = vma->vm_end - vma->vm_start; 1733 int rc;
1669 unsigned long start = vma->vm_start;
1670 void *pos;
1671 u32 i;
1672 1734
1673 if (unlikely(res_get(fh) < 0)) 1735 if (unlikely(res_get(fh) < 0))
1674 return -EBUSY; 1736 return -EBUSY;
1675 1737
1676 mutex_lock(&dev->lock); 1738 rc = check_dev(dev);
1677 1739 if (rc < 0)
1678 if (dev->state & DEV_DISCONNECTED) { 1740 return rc;
1679 em28xx_videodbg("mmap: device not present\n");
1680 mutex_unlock(&dev->lock);
1681 return -ENODEV;
1682 }
1683
1684 if (dev->state & DEV_MISCONFIGURED) {
1685 em28xx_videodbg ("mmap: Device is misconfigured; close and "
1686 "open it again\n");
1687 mutex_unlock(&dev->lock);
1688 return -EIO;
1689 }
1690
1691 if (dev->io != IO_MMAP || !(vma->vm_flags & VM_WRITE)) {
1692 mutex_unlock(&dev->lock);
1693 return -EINVAL;
1694 }
1695
1696 if (size > PAGE_ALIGN(dev->frame[0].buf.length))
1697 size = PAGE_ALIGN(dev->frame[0].buf.length);
1698
1699 for (i = 0; i < dev->num_frames; i++) {
1700 if ((dev->frame[i].buf.m.offset >> PAGE_SHIFT) == vma->vm_pgoff)
1701 break;
1702 }
1703 if (i == dev->num_frames) {
1704 em28xx_videodbg("mmap: user supplied mapping address is out of range\n");
1705 mutex_unlock(&dev->lock);
1706 return -EINVAL;
1707 }
1708
1709 /* VM_IO is eventually going to replace PageReserved altogether */
1710 vma->vm_flags |= VM_IO;
1711 vma->vm_flags |= VM_RESERVED; /* avoid to swap out this VMA */
1712 1741
1713 pos = dev->frame[i].bufmem; 1742 rc = videobuf_mmap_mapper(&fh->vb_vidq, vma);
1714 while (size > 0) { /* size is page-aligned */
1715 if (vm_insert_page(vma, start, vmalloc_to_page(pos))) {
1716 em28xx_videodbg("mmap: vm_insert_page failed\n");
1717 mutex_unlock(&dev->lock);
1718 return -EAGAIN;
1719 }
1720 start += PAGE_SIZE;
1721 pos += PAGE_SIZE;
1722 size -= PAGE_SIZE;
1723 }
1724 1743
1725 vma->vm_ops = &em28xx_vm_ops; 1744 em28xx_videodbg("vma start=0x%08lx, size=%ld, ret=%d\n",
1726 vma->vm_private_data = &dev->frame[i]; 1745 (unsigned long)vma->vm_start,
1746 (unsigned long)vma->vm_end-(unsigned long)vma->vm_start,
1747 rc);
1727 1748
1728 em28xx_vm_open(vma); 1749 return rc;
1729 mutex_unlock(&dev->lock);
1730 return 0;
1731} 1750}
1732 1751
1733static const struct file_operations em28xx_v4l_fops = { 1752static const struct file_operations em28xx_v4l_fops = {
@@ -1790,6 +1809,9 @@ static const struct video_device em28xx_video_template = {
1790 .vidioc_g_register = vidioc_g_register, 1809 .vidioc_g_register = vidioc_g_register,
1791 .vidioc_s_register = vidioc_s_register, 1810 .vidioc_s_register = vidioc_s_register,
1792#endif 1811#endif
1812#ifdef CONFIG_VIDEO_V4L1_COMPAT
1813 .vidiocgmbuf = vidiocgmbuf,
1814#endif
1793 1815
1794 .tvnorms = V4L2_STD_ALL, 1816 .tvnorms = V4L2_STD_ALL,
1795 .current_norm = V4L2_STD_PAL, 1817 .current_norm = V4L2_STD_PAL,
@@ -1818,7 +1840,7 @@ static struct video_device em28xx_radio_template = {
1818#endif 1840#endif
1819}; 1841};
1820 1842
1821/******************************** usb interface *****************************************/ 1843/******************************** usb interface ******************************/
1822 1844
1823 1845
1824static LIST_HEAD(em28xx_extension_devlist); 1846static LIST_HEAD(em28xx_extension_devlist);
@@ -1875,6 +1897,7 @@ static struct video_device *em28xx_vdev_init(struct em28xx *dev,
1875 vfd->dev = &dev->udev->dev; 1897 vfd->dev = &dev->udev->dev;
1876 vfd->release = video_device_release; 1898 vfd->release = video_device_release;
1877 vfd->type = type; 1899 vfd->type = type;
1900 vfd->debug = video_debug;
1878 1901
1879 snprintf(vfd->name, sizeof(vfd->name), "%s %s", 1902 snprintf(vfd->name, sizeof(vfd->name), "%s %s",
1880 dev->name, type_name); 1903 dev->name, type_name);
@@ -1898,7 +1921,7 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
1898 1921
1899 dev->udev = udev; 1922 dev->udev = udev;
1900 mutex_init(&dev->lock); 1923 mutex_init(&dev->lock);
1901 spin_lock_init(&dev->queue_lock); 1924 spin_lock_init(&dev->slock);
1902 init_waitqueue_head(&dev->open); 1925 init_waitqueue_head(&dev->open);
1903 init_waitqueue_head(&dev->wait_frame); 1926 init_waitqueue_head(&dev->wait_frame);
1904 init_waitqueue_head(&dev->wait_stream); 1927 init_waitqueue_head(&dev->wait_stream);
@@ -1910,10 +1933,6 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
1910 dev->em28xx_read_reg_req = em28xx_read_reg_req; 1933 dev->em28xx_read_reg_req = em28xx_read_reg_req;
1911 dev->is_em2800 = em28xx_boards[dev->model].is_em2800; 1934 dev->is_em2800 = em28xx_boards[dev->model].is_em2800;
1912 1935
1913 errCode = em28xx_read_reg(dev, CHIPID_REG);
1914 if (errCode >= 0)
1915 em28xx_info("em28xx chip ID = %d\n", errCode);
1916
1917 em28xx_pre_card_setup(dev); 1936 em28xx_pre_card_setup(dev);
1918 1937
1919 errCode = em28xx_config(dev); 1938 errCode = em28xx_config(dev);
@@ -1946,10 +1965,6 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
1946 dev->width = maxw; 1965 dev->width = maxw;
1947 dev->height = maxh; 1966 dev->height = maxh;
1948 dev->interlaced = EM28XX_INTERLACED_DEFAULT; 1967 dev->interlaced = EM28XX_INTERLACED_DEFAULT;
1949 dev->field_size = dev->width * dev->height;
1950 dev->frame_size =
1951 dev->interlaced ? dev->field_size << 1 : dev->field_size;
1952 dev->bytesperline = dev->width * 2;
1953 dev->hscale = 0; 1968 dev->hscale = 0;
1954 dev->vscale = 0; 1969 dev->vscale = 0;
1955 dev->ctl_input = 2; 1970 dev->ctl_input = 2;
@@ -2005,6 +2020,10 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
2005 dev->radio_dev->minor & 0x1f); 2020 dev->radio_dev->minor & 0x1f);
2006 } 2021 }
2007 2022
2023 /* init video dma queues */
2024 INIT_LIST_HEAD(&dev->vidq.active);
2025 INIT_LIST_HEAD(&dev->vidq.queued);
2026
2008 2027
2009 if (dev->has_msp34xx) { 2028 if (dev->has_msp34xx) {
2010 /* Send a reset to other chips via gpio */ 2029 /* Send a reset to other chips via gpio */
@@ -2048,6 +2067,9 @@ static void request_module_async(struct work_struct *work)
2048 request_module("snd-usb-audio"); 2067 request_module("snd-usb-audio");
2049 else 2068 else
2050 request_module("em28xx-alsa"); 2069 request_module("em28xx-alsa");
2070
2071 if (dev->has_dvb)
2072 request_module("em28xx-dvb");
2051} 2073}
2052 2074
2053static void request_modules(struct em28xx *dev) 2075static void request_modules(struct em28xx *dev)
@@ -2077,22 +2099,24 @@ static int em28xx_usb_probe(struct usb_interface *interface,
2077 ifnum = interface->altsetting[0].desc.bInterfaceNumber; 2099 ifnum = interface->altsetting[0].desc.bInterfaceNumber;
2078 2100
2079 /* Check to see next free device and mark as used */ 2101 /* Check to see next free device and mark as used */
2080 nr=find_first_zero_bit(&em28xx_devused,EM28XX_MAXBOARDS); 2102 nr = find_first_zero_bit(&em28xx_devused, EM28XX_MAXBOARDS);
2081 em28xx_devused|=1<<nr; 2103 em28xx_devused |= 1<<nr;
2082 2104
2083 /* Don't register audio interfaces */ 2105 /* Don't register audio interfaces */
2084 if (interface->altsetting[0].desc.bInterfaceClass == USB_CLASS_AUDIO) { 2106 if (interface->altsetting[0].desc.bInterfaceClass == USB_CLASS_AUDIO) {
2085 em28xx_err(DRIVER_NAME " audio device (%04x:%04x): interface %i, class %i\n", 2107 em28xx_err(DRIVER_NAME " audio device (%04x:%04x): interface %i, class %i\n",
2086 udev->descriptor.idVendor,udev->descriptor.idProduct, 2108 udev->descriptor.idVendor,
2109 udev->descriptor.idProduct,
2087 ifnum, 2110 ifnum,
2088 interface->altsetting[0].desc.bInterfaceClass); 2111 interface->altsetting[0].desc.bInterfaceClass);
2089 2112
2090 em28xx_devused&=~(1<<nr); 2113 em28xx_devused &= ~(1<<nr);
2091 return -ENODEV; 2114 return -ENODEV;
2092 } 2115 }
2093 2116
2094 em28xx_err(DRIVER_NAME " new video device (%04x:%04x): interface %i, class %i\n", 2117 em28xx_err(DRIVER_NAME " new video device (%04x:%04x): interface %i, class %i\n",
2095 udev->descriptor.idVendor,udev->descriptor.idProduct, 2118 udev->descriptor.idVendor,
2119 udev->descriptor.idProduct,
2096 ifnum, 2120 ifnum,
2097 interface->altsetting[0].desc.bInterfaceClass); 2121 interface->altsetting[0].desc.bInterfaceClass);
2098 2122
@@ -2102,18 +2126,19 @@ static int em28xx_usb_probe(struct usb_interface *interface,
2102 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != 2126 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) !=
2103 USB_ENDPOINT_XFER_ISOC) { 2127 USB_ENDPOINT_XFER_ISOC) {
2104 em28xx_err(DRIVER_NAME " probing error: endpoint is non-ISO endpoint!\n"); 2128 em28xx_err(DRIVER_NAME " probing error: endpoint is non-ISO endpoint!\n");
2105 em28xx_devused&=~(1<<nr); 2129 em28xx_devused &= ~(1<<nr);
2106 return -ENODEV; 2130 return -ENODEV;
2107 } 2131 }
2108 if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) { 2132 if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == USB_DIR_OUT) {
2109 em28xx_err(DRIVER_NAME " probing error: endpoint is ISO OUT endpoint!\n"); 2133 em28xx_err(DRIVER_NAME " probing error: endpoint is ISO OUT endpoint!\n");
2110 em28xx_devused&=~(1<<nr); 2134 em28xx_devused &= ~(1<<nr);
2111 return -ENODEV; 2135 return -ENODEV;
2112 } 2136 }
2113 2137
2114 if (nr >= EM28XX_MAXBOARDS) { 2138 if (nr >= EM28XX_MAXBOARDS) {
2115 printk (DRIVER_NAME ": Supports only %i em28xx boards.\n",EM28XX_MAXBOARDS); 2139 printk(DRIVER_NAME ": Supports only %i em28xx boards.\n",
2116 em28xx_devused&=~(1<<nr); 2140 EM28XX_MAXBOARDS);
2141 em28xx_devused &= ~(1<<nr);
2117 return -ENOMEM; 2142 return -ENOMEM;
2118 } 2143 }
2119 2144
@@ -2121,7 +2146,7 @@ static int em28xx_usb_probe(struct usb_interface *interface,
2121 dev = kzalloc(sizeof(*dev), GFP_KERNEL); 2146 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
2122 if (dev == NULL) { 2147 if (dev == NULL) {
2123 em28xx_err(DRIVER_NAME ": out of memory!\n"); 2148 em28xx_err(DRIVER_NAME ": out of memory!\n");
2124 em28xx_devused&=~(1<<nr); 2149 em28xx_devused &= ~(1<<nr);
2125 return -ENOMEM; 2150 return -ENOMEM;
2126 } 2151 }
2127 2152
@@ -2145,14 +2170,14 @@ static int em28xx_usb_probe(struct usb_interface *interface,
2145 /* compute alternate max packet sizes */ 2170 /* compute alternate max packet sizes */
2146 uif = udev->actconfig->interface[0]; 2171 uif = udev->actconfig->interface[0];
2147 2172
2148 dev->num_alt=uif->num_altsetting; 2173 dev->num_alt = uif->num_altsetting;
2149 em28xx_info("Alternate settings: %i\n",dev->num_alt); 2174 em28xx_info("Alternate settings: %i\n", dev->num_alt);
2150// dev->alt_max_pkt_size = kmalloc(sizeof(*dev->alt_max_pkt_size)* 2175/* dev->alt_max_pkt_size = kmalloc(sizeof(*dev->alt_max_pkt_size)* */
2151 dev->alt_max_pkt_size = kmalloc(32* 2176 dev->alt_max_pkt_size = kmalloc(32 * dev->num_alt, GFP_KERNEL);
2152 dev->num_alt,GFP_KERNEL); 2177
2153 if (dev->alt_max_pkt_size == NULL) { 2178 if (dev->alt_max_pkt_size == NULL) {
2154 em28xx_errdev("out of memory!\n"); 2179 em28xx_errdev("out of memory!\n");
2155 em28xx_devused&=~(1<<nr); 2180 em28xx_devused &= ~(1<<nr);
2156 kfree(dev); 2181 kfree(dev);
2157 return -ENOMEM; 2182 return -ENOMEM;
2158 } 2183 }
@@ -2162,11 +2187,11 @@ static int em28xx_usb_probe(struct usb_interface *interface,
2162 wMaxPacketSize); 2187 wMaxPacketSize);
2163 dev->alt_max_pkt_size[i] = 2188 dev->alt_max_pkt_size[i] =
2164 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1); 2189 (tmp & 0x07ff) * (((tmp & 0x1800) >> 11) + 1);
2165 em28xx_info("Alternate setting %i, max size= %i\n",i, 2190 em28xx_info("Alternate setting %i, max size= %i\n", i,
2166 dev->alt_max_pkt_size[i]); 2191 dev->alt_max_pkt_size[i]);
2167 } 2192 }
2168 2193
2169 if ((card[nr]>=0)&&(card[nr]<em28xx_bcount)) 2194 if ((card[nr] >= 0) && (card[nr] < em28xx_bcount))
2170 dev->model = card[nr]; 2195 dev->model = card[nr];
2171 2196
2172 /* allocate device struct */ 2197 /* allocate device struct */
@@ -2202,7 +2227,8 @@ static void em28xx_usb_disconnect(struct usb_interface *interface)
2202 2227
2203 em28xx_info("disconnecting %s\n", dev->vdev->name); 2228 em28xx_info("disconnecting %s\n", dev->vdev->name);
2204 2229
2205 /* wait until all current v4l2 io is finished then deallocate resources */ 2230 /* wait until all current v4l2 io is finished then deallocate
2231 resources */
2206 mutex_lock(&dev->lock); 2232 mutex_lock(&dev->lock);
2207 2233
2208 wake_up_interruptible_all(&dev->open); 2234 wake_up_interruptible_all(&dev->open);
diff --git a/drivers/media/video/em28xx/em28xx.h b/drivers/media/video/em28xx/em28xx.h
index 04e0e48ecabe..002f170b211a 100644
--- a/drivers/media/video/em28xx/em28xx.h
+++ b/drivers/media/video/em28xx/em28xx.h
@@ -26,11 +26,39 @@
26#define _EM28XX_H 26#define _EM28XX_H
27 27
28#include <linux/videodev2.h> 28#include <linux/videodev2.h>
29#include <media/videobuf-vmalloc.h>
30
29#include <linux/i2c.h> 31#include <linux/i2c.h>
30#include <linux/mutex.h> 32#include <linux/mutex.h>
31#include <media/ir-kbd-i2c.h> 33#include <media/ir-kbd-i2c.h>
32 34#if defined(CONFIG_VIDEO_EM28XX_DVB) || defined(CONFIG_VIDEO_EM28XX_DVB_MODULE)
33#define UNSET -1 35#include <media/videobuf-dvb.h>
36#endif
37#include "tuner-xc2028.h"
38#include "em28xx-reg.h"
39
40/* Boards supported by driver */
41#define EM2800_BOARD_UNKNOWN 0
42#define EM2820_BOARD_UNKNOWN 1
43#define EM2820_BOARD_TERRATEC_CINERGY_250 2
44#define EM2820_BOARD_PINNACLE_USB_2 3
45#define EM2820_BOARD_HAUPPAUGE_WINTV_USB_2 4
46#define EM2820_BOARD_MSI_VOX_USB_2 5
47#define EM2800_BOARD_TERRATEC_CINERGY_200 6
48#define EM2800_BOARD_LEADTEK_WINFAST_USBII 7
49#define EM2800_BOARD_KWORLD_USB2800 8
50#define EM2820_BOARD_PINNACLE_DVC_90 9
51#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900 10
52#define EM2880_BOARD_TERRATEC_HYBRID_XS 11
53#define EM2820_BOARD_KWORLD_PVRTV2800RF 12
54#define EM2880_BOARD_TERRATEC_PRODIGY_XS 13
55#define EM2820_BOARD_PROLINK_PLAYTV_USB2 14
56#define EM2800_BOARD_VGEAR_POCKETTV 15
57#define EM2880_BOARD_HAUPPAUGE_WINTV_HVR_950 16
58
59/* Limits minimum and default number of buffers */
60#define EM28XX_MIN_BUF 4
61#define EM28XX_DEF_BUF 8
34 62
35/* maximum number of em28xx boards */ 63/* maximum number of em28xx boards */
36#define EM28XX_MAXBOARDS 4 /*FIXME: should be bigger */ 64#define EM28XX_MAXBOARDS 4 /*FIXME: should be bigger */
@@ -81,31 +109,78 @@
81/* time in msecs to wait for i2c writes to finish */ 109/* time in msecs to wait for i2c writes to finish */
82#define EM2800_I2C_WRITE_TIMEOUT 20 110#define EM2800_I2C_WRITE_TIMEOUT 20
83 111
84/* the various frame states */ 112enum em28xx_mode {
85enum em28xx_frame_state { 113 EM28XX_MODE_UNDEFINED,
86 F_UNUSED = 0, 114 EM28XX_ANALOG_MODE,
87 F_QUEUED, 115 EM28XX_DIGITAL_MODE,
88 F_GRABBING,
89 F_DONE,
90 F_ERROR,
91}; 116};
92 117
93/* stream states */
94enum em28xx_stream_state { 118enum em28xx_stream_state {
95 STREAM_OFF, 119 STREAM_OFF,
96 STREAM_INTERRUPT, 120 STREAM_INTERRUPT,
97 STREAM_ON, 121 STREAM_ON,
98}; 122};
99 123
100/* frames */ 124struct em28xx;
101struct em28xx_frame_t { 125
102 void *bufmem; 126struct em28xx_usb_isoc_ctl {
103 struct v4l2_buffer buf; 127 /* max packet size of isoc transaction */
104 enum em28xx_frame_state state; 128 int max_pkt_size;
129
130 /* number of allocated urbs */
131 int num_bufs;
132
133 /* urb for isoc transfers */
134 struct urb **urb;
135
136 /* transfer buffers for isoc transfer */
137 char **transfer_buffer;
138
139 /* Last buffer command and region */
140 u8 cmd;
141 int pos, size, pktsize;
142
143 /* Last field: ODD or EVEN? */
144 int field;
145
146 /* Stores incomplete commands */
147 u32 tmp_buf;
148 int tmp_buf_len;
149
150 /* Stores already requested buffers */
151 struct em28xx_buffer *buf;
152
153 /* Stores the number of received fields */
154 int nfields;
155
156 /* isoc urb callback */
157 int (*isoc_copy) (struct em28xx *dev, struct urb *urb);
158
159};
160
161struct em28xx_fmt {
162 char *name;
163 u32 fourcc; /* v4l2 format id */
164};
165
166/* buffer for one video frame */
167struct em28xx_buffer {
168 /* common v4l buffer stuff -- must be first */
169 struct videobuf_buffer vb;
170
105 struct list_head frame; 171 struct list_head frame;
106 unsigned long vma_use_count;
107 int top_field; 172 int top_field;
108 int fieldbytesused; 173 int receiving;
174};
175
176struct em28xx_dmaqueue {
177 struct list_head active;
178 struct list_head queued;
179
180 wait_queue_head_t wq;
181
182 /* Counters to control buffer fill */
183 int pos;
109}; 184};
110 185
111/* io methods */ 186/* io methods */
@@ -152,6 +227,12 @@ enum em28xx_decoder {
152 EM28XX_SAA7114 227 EM28XX_SAA7114
153}; 228};
154 229
230struct em28xx_reg_seq {
231 int reg;
232 unsigned char val, mask;
233 int sleep;
234};
235
155struct em28xx_board { 236struct em28xx_board {
156 char *name; 237 char *name;
157 int vchannels; 238 int vchannels;
@@ -165,8 +246,7 @@ struct em28xx_board {
165 unsigned int mts_firmware:1; 246 unsigned int mts_firmware:1;
166 unsigned int has_12mhz_i2s:1; 247 unsigned int has_12mhz_i2s:1;
167 unsigned int max_range_640_480:1; 248 unsigned int max_range_640_480:1;
168 249 unsigned int has_dvb:1;
169 unsigned int analog_gpio;
170 250
171 enum em28xx_decoder decoder; 251 enum em28xx_decoder decoder;
172 252
@@ -199,7 +279,10 @@ enum em28xx_dev_state {
199#define EM28XX_NUM_AUDIO_PACKETS 64 279#define EM28XX_NUM_AUDIO_PACKETS 64
200#define EM28XX_AUDIO_MAX_PACKET_SIZE 196 /* static value */ 280#define EM28XX_AUDIO_MAX_PACKET_SIZE 196 /* static value */
201#define EM28XX_CAPTURE_STREAM_EN 1 281#define EM28XX_CAPTURE_STREAM_EN 1
282
283/* em28xx extensions */
202#define EM28XX_AUDIO 0x10 284#define EM28XX_AUDIO 0x10
285#define EM28XX_DVB 0x20
203 286
204struct em28xx_audio { 287struct em28xx_audio {
205 char name[50]; 288 char name[50];
@@ -217,13 +300,24 @@ struct em28xx_audio {
217 spinlock_t slock; 300 spinlock_t slock;
218}; 301};
219 302
303struct em28xx;
304
305struct em28xx_fh {
306 struct em28xx *dev;
307 unsigned int stream_on:1; /* Locks streams */
308 int radio;
309
310 struct videobuf_queue vb_vidq;
311
312 enum v4l2_buf_type type;
313};
314
220/* main device struct */ 315/* main device struct */
221struct em28xx { 316struct em28xx {
222 /* generic device properties */ 317 /* generic device properties */
223 char name[30]; /* name (including minor) of the device */ 318 char name[30]; /* name (including minor) of the device */
224 int model; /* index in the device_data struct */ 319 int model; /* index in the device_data struct */
225 int devno; /* marks the number of this device */ 320 int devno; /* marks the number of this device */
226 unsigned int analog_gpio;
227 unsigned int is_em2800:1; 321 unsigned int is_em2800:1;
228 unsigned int has_msp34xx:1; 322 unsigned int has_msp34xx:1;
229 unsigned int has_tda9887:1; 323 unsigned int has_tda9887:1;
@@ -231,6 +325,16 @@ struct em28xx {
231 unsigned int has_audio_class:1; 325 unsigned int has_audio_class:1;
232 unsigned int has_12mhz_i2s:1; 326 unsigned int has_12mhz_i2s:1;
233 unsigned int max_range_640_480:1; 327 unsigned int max_range_640_480:1;
328 unsigned int has_dvb:1;
329
330 /* Some older em28xx chips needs a waiting time after writing */
331 unsigned int wait_after_write;
332
333 /* GPIO sequences for analog and digital mode */
334 struct em28xx_reg_seq *analog_gpio, *digital_gpio;
335
336 /* GPIO sequences for tuner callbacks */
337 struct em28xx_reg_seq *tun_analog_gpio, *tun_digital_gpio;
234 338
235 int video_inputs; /* number of video inputs */ 339 int video_inputs; /* number of video inputs */
236 struct list_head devlist; 340 struct list_head devlist;
@@ -255,36 +359,28 @@ struct em28xx {
255 int mute; 359 int mute;
256 int volume; 360 int volume;
257 /* frame properties */ 361 /* frame properties */
258 struct em28xx_frame_t frame[EM28XX_NUM_FRAMES]; /* list of frames */
259 int num_frames; /* number of frames currently in use */
260 unsigned int frame_count; /* total number of transfered frames */
261 struct em28xx_frame_t *frame_current; /* the frame that is being filled */
262 int width; /* current frame width */ 362 int width; /* current frame width */
263 int height; /* current frame height */ 363 int height; /* current frame height */
264 int frame_size; /* current frame size */
265 int field_size; /* current field size */
266 int bytesperline;
267 int hscale; /* horizontal scale factor (see datasheet) */ 364 int hscale; /* horizontal scale factor (see datasheet) */
268 int vscale; /* vertical scale factor (see datasheet) */ 365 int vscale; /* vertical scale factor (see datasheet) */
269 int interlaced; /* 1=interlace fileds, 0=just top fileds */ 366 int interlaced; /* 1=interlace fileds, 0=just top fileds */
270 int type;
271 unsigned int video_bytesread; /* Number of bytes read */ 367 unsigned int video_bytesread; /* Number of bytes read */
272 368
273 unsigned long hash; /* eeprom hash - for boards with generic ID */ 369 unsigned long hash; /* eeprom hash - for boards with generic ID */
274 unsigned long i2c_hash; /* i2c devicelist hash - for boards with generic ID */ 370 unsigned long i2c_hash; /* i2c devicelist hash -
371 for boards with generic ID */
275 372
276 struct em28xx_audio *adev; 373 struct em28xx_audio *adev;
277 374
278 /* states */ 375 /* states */
279 enum em28xx_dev_state state; 376 enum em28xx_dev_state state;
280 enum em28xx_stream_state stream;
281 enum em28xx_io_method io; 377 enum em28xx_io_method io;
282 378
283 struct work_struct request_module_wk; 379 struct work_struct request_module_wk;
284 380
285 /* locks */ 381 /* locks */
286 struct mutex lock; 382 struct mutex lock;
287 spinlock_t queue_lock; 383 /* spinlock_t queue_lock; */
288 struct list_head inqueue, outqueue; 384 struct list_head inqueue, outqueue;
289 wait_queue_head_t open, wait_frame, wait_stream; 385 wait_queue_head_t open, wait_frame, wait_stream;
290 struct video_device *vbi_dev; 386 struct video_device *vbi_dev;
@@ -292,6 +388,11 @@ struct em28xx {
292 388
293 unsigned char eedata[256]; 389 unsigned char eedata[256];
294 390
391 /* Isoc control struct */
392 struct em28xx_dmaqueue vidq;
393 struct em28xx_usb_isoc_ctl isoc_ctl;
394 spinlock_t slock;
395
295 /* usb transfer */ 396 /* usb transfer */
296 struct usb_device *udev; /* the usb device */ 397 struct usb_device *udev; /* the usb device */
297 int alt; /* alternate */ 398 int alt; /* alternate */
@@ -301,20 +402,21 @@ struct em28xx {
301 struct urb *urb[EM28XX_NUM_BUFS]; /* urb for isoc transfers */ 402 struct urb *urb[EM28XX_NUM_BUFS]; /* urb for isoc transfers */
302 char *transfer_buffer[EM28XX_NUM_BUFS]; /* transfer buffers for isoc transfer */ 403 char *transfer_buffer[EM28XX_NUM_BUFS]; /* transfer buffers for isoc transfer */
303 /* helper funcs that call usb_control_msg */ 404 /* helper funcs that call usb_control_msg */
304 int (*em28xx_write_regs) (struct em28xx * dev, u16 reg, char *buf, 405 int (*em28xx_write_regs) (struct em28xx *dev, u16 reg,
305 int len);
306 int (*em28xx_read_reg) (struct em28xx * dev, u16 reg);
307 int (*em28xx_read_reg_req_len) (struct em28xx * dev, u8 req, u16 reg,
308 char *buf, int len); 406 char *buf, int len);
309 int (*em28xx_write_regs_req) (struct em28xx * dev, u8 req, u16 reg, 407 int (*em28xx_read_reg) (struct em28xx *dev, u16 reg);
408 int (*em28xx_read_reg_req_len) (struct em28xx *dev, u8 req, u16 reg,
409 char *buf, int len);
410 int (*em28xx_write_regs_req) (struct em28xx *dev, u8 req, u16 reg,
310 char *buf, int len); 411 char *buf, int len);
311 int (*em28xx_read_reg_req) (struct em28xx * dev, u8 req, u16 reg); 412 int (*em28xx_read_reg_req) (struct em28xx *dev, u8 req, u16 reg);
312};
313 413
314struct em28xx_fh { 414 enum em28xx_mode mode;
315 struct em28xx *dev; 415
316 unsigned int stream_on:1; /* Locks streams */ 416 /* Caches GPO and GPIO registers */
317 int radio; 417 unsigned char reg_gpo, reg_gpio;
418
419 struct em28xx_dvb *dvb;
318}; 420};
319 421
320struct em28xx_ops { 422struct em28xx_ops {
@@ -351,22 +453,27 @@ int em28xx_colorlevels_set_default(struct em28xx *dev);
351int em28xx_capture_start(struct em28xx *dev, int start); 453int em28xx_capture_start(struct em28xx *dev, int start);
352int em28xx_outfmt_set_yuv422(struct em28xx *dev); 454int em28xx_outfmt_set_yuv422(struct em28xx *dev);
353int em28xx_resolution_set(struct em28xx *dev); 455int em28xx_resolution_set(struct em28xx *dev);
354int em28xx_init_isoc(struct em28xx *dev);
355void em28xx_uninit_isoc(struct em28xx *dev);
356int em28xx_set_alternate(struct em28xx *dev); 456int em28xx_set_alternate(struct em28xx *dev);
457int em28xx_init_isoc(struct em28xx *dev, int max_packets,
458 int num_bufs, int max_pkt_size,
459 int (*isoc_copy) (struct em28xx *dev, struct urb *urb));
460void em28xx_uninit_isoc(struct em28xx *dev);
461int em28xx_set_mode(struct em28xx *dev, enum em28xx_mode set_mode);
462int em28xx_gpio_set(struct em28xx *dev, struct em28xx_reg_seq *gpio);
357 463
358/* Provided by em28xx-video.c */ 464/* Provided by em28xx-video.c */
359int em28xx_register_extension(struct em28xx_ops *dev); 465int em28xx_register_extension(struct em28xx_ops *dev);
360void em28xx_unregister_extension(struct em28xx_ops *dev); 466void em28xx_unregister_extension(struct em28xx_ops *dev);
361 467
362/* Provided by em28xx-cards.c */ 468/* Provided by em28xx-cards.c */
363extern int em2800_variant_detect(struct usb_device* udev,int model); 469extern int em2800_variant_detect(struct usb_device *udev, int model);
364extern void em28xx_pre_card_setup(struct em28xx *dev); 470extern void em28xx_pre_card_setup(struct em28xx *dev);
365extern void em28xx_card_setup(struct em28xx *dev); 471extern void em28xx_card_setup(struct em28xx *dev);
366extern struct em28xx_board em28xx_boards[]; 472extern struct em28xx_board em28xx_boards[];
367extern struct usb_device_id em28xx_id_table[]; 473extern struct usb_device_id em28xx_id_table[];
368extern const unsigned int em28xx_bcount; 474extern const unsigned int em28xx_bcount;
369void em28xx_set_ir(struct em28xx *dev, struct IR_i2c *ir); 475void em28xx_set_ir(struct em28xx *dev, struct IR_i2c *ir);
476int em28xx_tuner_callback(void *ptr, int command, int arg);
370 477
371/* Provided by em28xx-input.c */ 478/* Provided by em28xx-input.c */
372/* TODO: Check if the standard get_key handlers on ir-common can be used */ 479/* TODO: Check if the standard get_key handlers on ir-common can be used */
@@ -375,71 +482,6 @@ int em28xx_get_key_em_haup(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw);
375int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key, 482int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key,
376 u32 *ir_raw); 483 u32 *ir_raw);
377 484
378/* em2800 registers */
379#define EM2800_AUDIOSRC_REG 0x08
380
381/* em28xx registers */
382#define I2C_CLK_REG 0x06
383#define CHIPID_REG 0x0a
384#define USBSUSP_REG 0x0c /* */
385
386#define AUDIOSRC_REG 0x0e
387#define XCLK_REG 0x0f
388
389#define VINMODE_REG 0x10
390#define VINCTRL_REG 0x11
391#define VINENABLE_REG 0x12 /* */
392
393#define GAMMA_REG 0x14
394#define RGAIN_REG 0x15
395#define GGAIN_REG 0x16
396#define BGAIN_REG 0x17
397#define ROFFSET_REG 0x18
398#define GOFFSET_REG 0x19
399#define BOFFSET_REG 0x1a
400
401#define OFLOW_REG 0x1b
402#define HSTART_REG 0x1c
403#define VSTART_REG 0x1d
404#define CWIDTH_REG 0x1e
405#define CHEIGHT_REG 0x1f
406
407#define YGAIN_REG 0x20
408#define YOFFSET_REG 0x21
409#define UVGAIN_REG 0x22
410#define UOFFSET_REG 0x23
411#define VOFFSET_REG 0x24
412#define SHARPNESS_REG 0x25
413
414#define COMPR_REG 0x26
415#define OUTFMT_REG 0x27
416
417#define XMIN_REG 0x28
418#define XMAX_REG 0x29
419#define YMIN_REG 0x2a
420#define YMAX_REG 0x2b
421
422#define HSCALELOW_REG 0x30
423#define HSCALEHIGH_REG 0x31
424#define VSCALELOW_REG 0x32
425#define VSCALEHIGH_REG 0x33
426
427#define AC97LSB_REG 0x40
428#define AC97MSB_REG 0x41
429#define AC97ADDR_REG 0x42
430#define AC97BUSY_REG 0x43
431
432/* em202 registers */
433#define MASTER_AC97 0x02
434#define LINE_IN_AC97 0x10
435#define VIDEO_AC97 0x14
436
437/* register settings */
438#define EM2800_AUDIO_SRC_TUNER 0x0d
439#define EM2800_AUDIO_SRC_LINE 0x0c
440#define EM28XX_AUDIO_SRC_TUNER 0xc0
441#define EM28XX_AUDIO_SRC_LINE 0x80
442
443/* printk macros */ 485/* printk macros */
444 486
445#define em28xx_err(fmt, arg...) do {\ 487#define em28xx_err(fmt, arg...) do {\
@@ -456,80 +498,80 @@ int em28xx_get_key_pinnacle_usb_grey(struct IR_i2c *ir, u32 *ir_key,
456 printk(KERN_WARNING "%s: "fmt,\ 498 printk(KERN_WARNING "%s: "fmt,\
457 dev->name , ##arg); } while (0) 499 dev->name , ##arg); } while (0)
458 500
459inline static int em28xx_compression_disable(struct em28xx *dev) 501static inline int em28xx_compression_disable(struct em28xx *dev)
460{ 502{
461 /* side effect of disabling scaler and mixer */ 503 /* side effect of disabling scaler and mixer */
462 return em28xx_write_regs(dev, COMPR_REG, "\x00", 1); 504 return em28xx_write_regs(dev, EM28XX_R26_COMPR, "\x00", 1);
463} 505}
464 506
465inline static int em28xx_contrast_get(struct em28xx *dev) 507static inline int em28xx_contrast_get(struct em28xx *dev)
466{ 508{
467 return em28xx_read_reg(dev, YGAIN_REG) & 0x1f; 509 return em28xx_read_reg(dev, EM28XX_R20_YGAIN) & 0x1f;
468} 510}
469 511
470inline static int em28xx_brightness_get(struct em28xx *dev) 512static inline int em28xx_brightness_get(struct em28xx *dev)
471{ 513{
472 return em28xx_read_reg(dev, YOFFSET_REG); 514 return em28xx_read_reg(dev, EM28XX_R21_YOFFSET);
473} 515}
474 516
475inline static int em28xx_saturation_get(struct em28xx *dev) 517static inline int em28xx_saturation_get(struct em28xx *dev)
476{ 518{
477 return em28xx_read_reg(dev, UVGAIN_REG) & 0x1f; 519 return em28xx_read_reg(dev, EM28XX_R22_UVGAIN) & 0x1f;
478} 520}
479 521
480inline static int em28xx_u_balance_get(struct em28xx *dev) 522static inline int em28xx_u_balance_get(struct em28xx *dev)
481{ 523{
482 return em28xx_read_reg(dev, UOFFSET_REG); 524 return em28xx_read_reg(dev, EM28XX_R23_UOFFSET);
483} 525}
484 526
485inline static int em28xx_v_balance_get(struct em28xx *dev) 527static inline int em28xx_v_balance_get(struct em28xx *dev)
486{ 528{
487 return em28xx_read_reg(dev, VOFFSET_REG); 529 return em28xx_read_reg(dev, EM28XX_R24_VOFFSET);
488} 530}
489 531
490inline static int em28xx_gamma_get(struct em28xx *dev) 532static inline int em28xx_gamma_get(struct em28xx *dev)
491{ 533{
492 return em28xx_read_reg(dev, GAMMA_REG) & 0x3f; 534 return em28xx_read_reg(dev, EM28XX_R14_GAMMA) & 0x3f;
493} 535}
494 536
495inline static int em28xx_contrast_set(struct em28xx *dev, s32 val) 537static inline int em28xx_contrast_set(struct em28xx *dev, s32 val)
496{ 538{
497 u8 tmp = (u8) val; 539 u8 tmp = (u8) val;
498 return em28xx_write_regs(dev, YGAIN_REG, &tmp, 1); 540 return em28xx_write_regs(dev, EM28XX_R20_YGAIN, &tmp, 1);
499} 541}
500 542
501inline static int em28xx_brightness_set(struct em28xx *dev, s32 val) 543static inline int em28xx_brightness_set(struct em28xx *dev, s32 val)
502{ 544{
503 u8 tmp = (u8) val; 545 u8 tmp = (u8) val;
504 return em28xx_write_regs(dev, YOFFSET_REG, &tmp, 1); 546 return em28xx_write_regs(dev, EM28XX_R21_YOFFSET, &tmp, 1);
505} 547}
506 548
507inline static int em28xx_saturation_set(struct em28xx *dev, s32 val) 549static inline int em28xx_saturation_set(struct em28xx *dev, s32 val)
508{ 550{
509 u8 tmp = (u8) val; 551 u8 tmp = (u8) val;
510 return em28xx_write_regs(dev, UVGAIN_REG, &tmp, 1); 552 return em28xx_write_regs(dev, EM28XX_R22_UVGAIN, &tmp, 1);
511} 553}
512 554
513inline static int em28xx_u_balance_set(struct em28xx *dev, s32 val) 555static inline int em28xx_u_balance_set(struct em28xx *dev, s32 val)
514{ 556{
515 u8 tmp = (u8) val; 557 u8 tmp = (u8) val;
516 return em28xx_write_regs(dev, UOFFSET_REG, &tmp, 1); 558 return em28xx_write_regs(dev, EM28XX_R23_UOFFSET, &tmp, 1);
517} 559}
518 560
519inline static int em28xx_v_balance_set(struct em28xx *dev, s32 val) 561static inline int em28xx_v_balance_set(struct em28xx *dev, s32 val)
520{ 562{
521 u8 tmp = (u8) val; 563 u8 tmp = (u8) val;
522 return em28xx_write_regs(dev, VOFFSET_REG, &tmp, 1); 564 return em28xx_write_regs(dev, EM28XX_R24_VOFFSET, &tmp, 1);
523} 565}
524 566
525inline static int em28xx_gamma_set(struct em28xx *dev, s32 val) 567static inline int em28xx_gamma_set(struct em28xx *dev, s32 val)
526{ 568{
527 u8 tmp = (u8) val; 569 u8 tmp = (u8) val;
528 return em28xx_write_regs(dev, GAMMA_REG, &tmp, 1); 570 return em28xx_write_regs(dev, EM28XX_R14_GAMMA, &tmp, 1);
529} 571}
530 572
531/*FIXME: maxw should be dependent of alt mode */ 573/*FIXME: maxw should be dependent of alt mode */
532inline static unsigned int norm_maxw(struct em28xx *dev) 574static inline unsigned int norm_maxw(struct em28xx *dev)
533{ 575{
534 if (dev->max_range_640_480) 576 if (dev->max_range_640_480)
535 return 640; 577 return 640;
@@ -537,7 +579,7 @@ inline static unsigned int norm_maxw(struct em28xx *dev)
537 return 720; 579 return 720;
538} 580}
539 581
540inline static unsigned int norm_maxh(struct em28xx *dev) 582static inline unsigned int norm_maxh(struct em28xx *dev)
541{ 583{
542 if (dev->max_range_640_480) 584 if (dev->max_range_640_480)
543 return 480; 585 return 480;
diff --git a/drivers/media/video/et61x251/et61x251.h b/drivers/media/video/et61x251/et61x251.h
index 02c741d8f85a..cc77d144df3c 100644
--- a/drivers/media/video/et61x251/et61x251.h
+++ b/drivers/media/video/et61x251/et61x251.h
@@ -199,7 +199,7 @@ do { \
199 dev_info(&cam->usbdev->dev, fmt "\n", ## args); \ 199 dev_info(&cam->usbdev->dev, fmt "\n", ## args); \
200 else if ((level) >= 3) \ 200 else if ((level) >= 3) \
201 dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n", \ 201 dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n", \
202 __FILE__, __FUNCTION__, __LINE__ , ## args); \ 202 __FILE__, __func__, __LINE__ , ## args); \
203 } \ 203 } \
204} while (0) 204} while (0)
205# define KDBG(level, fmt, args...) \ 205# define KDBG(level, fmt, args...) \
@@ -209,7 +209,7 @@ do { \
209 pr_info("et61x251: " fmt "\n", ## args); \ 209 pr_info("et61x251: " fmt "\n", ## args); \
210 else if ((level) == 3) \ 210 else if ((level) == 3) \
211 pr_debug("sn9c102: [%s:%s:%d] " fmt "\n", __FILE__, \ 211 pr_debug("sn9c102: [%s:%s:%d] " fmt "\n", __FILE__, \
212 __FUNCTION__, __LINE__ , ## args); \ 212 __func__, __LINE__ , ## args); \
213 } \ 213 } \
214} while (0) 214} while (0)
215# define V4LDBG(level, name, cmd) \ 215# define V4LDBG(level, name, cmd) \
@@ -225,7 +225,7 @@ do { \
225 225
226#undef PDBG 226#undef PDBG
227#define PDBG(fmt, args...) \ 227#define PDBG(fmt, args...) \
228dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n", __FILE__, __FUNCTION__, \ 228dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n", __FILE__, __func__, \
229 __LINE__ , ## args) 229 __LINE__ , ## args)
230 230
231#undef PDBGG 231#undef PDBGG
diff --git a/drivers/media/video/et61x251/et61x251_core.c b/drivers/media/video/et61x251/et61x251_core.c
index 06b6a3ae06c4..5e749c528a62 100644
--- a/drivers/media/video/et61x251/et61x251_core.c
+++ b/drivers/media/video/et61x251/et61x251_core.c
@@ -2523,7 +2523,9 @@ static const struct file_operations et61x251_fops = {
2523 .open = et61x251_open, 2523 .open = et61x251_open,
2524 .release = et61x251_release, 2524 .release = et61x251_release,
2525 .ioctl = et61x251_ioctl, 2525 .ioctl = et61x251_ioctl,
2526#ifdef CONFIG_COMPAT
2526 .compat_ioctl = v4l_compat_ioctl32, 2527 .compat_ioctl = v4l_compat_ioctl32,
2528#endif
2527 .read = et61x251_read, 2529 .read = et61x251_read,
2528 .poll = et61x251_poll, 2530 .poll = et61x251_poll,
2529 .mmap = et61x251_mmap, 2531 .mmap = et61x251_mmap,
@@ -2538,7 +2540,7 @@ et61x251_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
2538{ 2540{
2539 struct usb_device *udev = interface_to_usbdev(intf); 2541 struct usb_device *udev = interface_to_usbdev(intf);
2540 struct et61x251_device* cam; 2542 struct et61x251_device* cam;
2541 static unsigned int dev_nr = 0; 2543 static unsigned int dev_nr;
2542 unsigned int i; 2544 unsigned int i;
2543 int err = 0; 2545 int err = 0;
2544 2546
diff --git a/drivers/media/video/hexium_gemini.c b/drivers/media/video/hexium_gemini.c
index c7fed3405655..352f84d440fb 100644
--- a/drivers/media/video/hexium_gemini.c
+++ b/drivers/media/video/hexium_gemini.c
@@ -25,12 +25,12 @@
25 25
26#include <media/saa7146_vv.h> 26#include <media/saa7146_vv.h>
27 27
28static int debug = 0; 28static int debug;
29module_param(debug, int, 0); 29module_param(debug, int, 0);
30MODULE_PARM_DESC(debug, "debug verbosity"); 30MODULE_PARM_DESC(debug, "debug verbosity");
31 31
32/* global variables */ 32/* global variables */
33static int hexium_num = 0; 33static int hexium_num;
34 34
35#define HEXIUM_GEMINI 4 35#define HEXIUM_GEMINI 4
36#define HEXIUM_GEMINI_DUAL 5 36#define HEXIUM_GEMINI_DUAL 5
diff --git a/drivers/media/video/hexium_orion.c b/drivers/media/video/hexium_orion.c
index 137c4736da04..8d3c1482e7ea 100644
--- a/drivers/media/video/hexium_orion.c
+++ b/drivers/media/video/hexium_orion.c
@@ -25,12 +25,12 @@
25 25
26#include <media/saa7146_vv.h> 26#include <media/saa7146_vv.h>
27 27
28static int debug = 0; 28static int debug;
29module_param(debug, int, 0); 29module_param(debug, int, 0);
30MODULE_PARM_DESC(debug, "debug verbosity"); 30MODULE_PARM_DESC(debug, "debug verbosity");
31 31
32/* global variables */ 32/* global variables */
33static int hexium_num = 0; 33static int hexium_num;
34 34
35#define HEXIUM_HV_PCI6_ORION 1 35#define HEXIUM_HV_PCI6_ORION 1
36#define HEXIUM_ORION_1SVHS_3BNC 2 36#define HEXIUM_ORION_1SVHS_3BNC 2
diff --git a/drivers/media/video/ir-kbd-i2c.c b/drivers/media/video/ir-kbd-i2c.c
index dabafdf71e60..11c5fdedc23b 100644
--- a/drivers/media/video/ir-kbd-i2c.c
+++ b/drivers/media/video/ir-kbd-i2c.c
@@ -50,7 +50,7 @@
50static int debug; 50static int debug;
51module_param(debug, int, 0644); /* debug level (0,1,2) */ 51module_param(debug, int, 0644); /* debug level (0,1,2) */
52 52
53static int hauppauge = 0; 53static int hauppauge;
54module_param(hauppauge, int, 0644); /* Choose Hauppauge remote */ 54module_param(hauppauge, int, 0644); /* Choose Hauppauge remote */
55MODULE_PARM_DESC(hauppauge, "Specify Hauppauge remote: 0=black, 1=grey (defaults to 0)"); 55MODULE_PARM_DESC(hauppauge, "Specify Hauppauge remote: 0=black, 1=grey (defaults to 0)");
56 56
@@ -153,7 +153,7 @@ static int get_key_fusionhdtv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
153 } 153 }
154 154
155 if(buf[0] !=0 || buf[1] !=0 || buf[2] !=0 || buf[3] != 0) 155 if(buf[0] !=0 || buf[1] !=0 || buf[2] !=0 || buf[3] != 0)
156 dprintk(2, "%s: 0x%2x 0x%2x 0x%2x 0x%2x\n", __FUNCTION__, 156 dprintk(2, "%s: 0x%2x 0x%2x 0x%2x 0x%2x\n", __func__,
157 buf[0], buf[1], buf[2], buf[3]); 157 buf[0], buf[1], buf[2], buf[3]);
158 158
159 /* no key pressed or signal from other ir remote */ 159 /* no key pressed or signal from other ir remote */
@@ -508,10 +508,10 @@ static int ir_probe(struct i2c_adapter *adap)
508 static const int probe_em28XX[] = { 0x30, 0x47, -1 }; 508 static const int probe_em28XX[] = { 0x30, 0x47, -1 };
509 static const int probe_cx88[] = { 0x18, 0x6b, 0x71, -1 }; 509 static const int probe_cx88[] = { 0x18, 0x6b, 0x71, -1 };
510 static const int probe_cx23885[] = { 0x6b, -1 }; 510 static const int probe_cx23885[] = { 0x6b, -1 };
511 const int *probe = NULL; 511 const int *probe;
512 struct i2c_client c; 512 struct i2c_client *c;
513 unsigned char buf; 513 unsigned char buf;
514 int i,rc; 514 int i, rc;
515 515
516 switch (adap->id) { 516 switch (adap->id) {
517 case I2C_HW_B_BT848: 517 case I2C_HW_B_BT848:
@@ -532,23 +532,27 @@ static int ir_probe(struct i2c_adapter *adap)
532 case I2C_HW_B_CX23885: 532 case I2C_HW_B_CX23885:
533 probe = probe_cx23885; 533 probe = probe_cx23885;
534 break; 534 break;
535 } 535 default:
536 if (NULL == probe)
537 return 0; 536 return 0;
537 }
538
539 c = kzalloc(sizeof(*c), GFP_KERNEL);
540 if (!c)
541 return -ENOMEM;
538 542
539 memset(&c,0,sizeof(c)); 543 c->adapter = adap;
540 c.adapter = adap;
541 for (i = 0; -1 != probe[i]; i++) { 544 for (i = 0; -1 != probe[i]; i++) {
542 c.addr = probe[i]; 545 c->addr = probe[i];
543 rc = i2c_master_recv(&c,&buf,0); 546 rc = i2c_master_recv(c, &buf, 0);
544 dprintk(1,"probe 0x%02x @ %s: %s\n", 547 dprintk(1,"probe 0x%02x @ %s: %s\n",
545 probe[i], adap->name, 548 probe[i], adap->name,
546 (0 == rc) ? "yes" : "no"); 549 (0 == rc) ? "yes" : "no");
547 if (0 == rc) { 550 if (0 == rc) {
548 ir_attach(adap,probe[i],0,0); 551 ir_attach(adap, probe[i], 0, 0);
549 break; 552 break;
550 } 553 }
551 } 554 }
555 kfree(c);
552 return 0; 556 return 0;
553} 557}
554 558
diff --git a/drivers/media/video/ivtv/Kconfig b/drivers/media/video/ivtv/Kconfig
index 270906fc3146..b6171702c4d0 100644
--- a/drivers/media/video/ivtv/Kconfig
+++ b/drivers/media/video/ivtv/Kconfig
@@ -10,6 +10,7 @@ config VIDEO_IVTV
10 select VIDEO_CX25840 10 select VIDEO_CX25840
11 select VIDEO_MSP3400 11 select VIDEO_MSP3400
12 select VIDEO_SAA711X 12 select VIDEO_SAA711X
13 select VIDEO_SAA717X
13 select VIDEO_SAA7127 14 select VIDEO_SAA7127
14 select VIDEO_TVAUDIO 15 select VIDEO_TVAUDIO
15 select VIDEO_CS53L32A 16 select VIDEO_CS53L32A
diff --git a/drivers/media/video/ivtv/ivtv-cards.c b/drivers/media/video/ivtv/ivtv-cards.c
index f23c6b8d6911..e908649ea37c 100644
--- a/drivers/media/video/ivtv/ivtv-cards.c
+++ b/drivers/media/video/ivtv/ivtv-cards.c
@@ -416,11 +416,10 @@ static const struct ivtv_card ivtv_card_avc2410 = {
416 on the country/region setting of the user to decide which tuner 416 on the country/region setting of the user to decide which tuner
417 is available. */ 417 is available. */
418 .tuners = { 418 .tuners = {
419 /* This tuner has been verified for the AVC2410 */
420 { .std = V4L2_STD_625_50, .tuner = TUNER_PHILIPS_FM1216ME_MK3 }, 419 { .std = V4L2_STD_625_50, .tuner = TUNER_PHILIPS_FM1216ME_MK3 },
421 /* This is a good guess, but I'm not totally sure this is 420 { .std = V4L2_STD_ALL - V4L2_STD_NTSC_M_JP,
422 the correct tuner for NTSC. */ 421 .tuner = TUNER_PHILIPS_FM1236_MK3 },
423 { .std = V4L2_STD_ALL, .tuner = TUNER_PHILIPS_FM1236_MK3 }, 422 { .std = V4L2_STD_NTSC_M_JP, .tuner = TUNER_PHILIPS_FQ1286 },
424 }, 423 },
425 .pci_list = ivtv_pci_avc2410, 424 .pci_list = ivtv_pci_avc2410,
426 .i2c = &ivtv_i2c_std, 425 .i2c = &ivtv_i2c_std,
diff --git a/drivers/media/video/ivtv/ivtv-cards.h b/drivers/media/video/ivtv/ivtv-cards.h
index 191aafdd9968..9186fa2ee5fc 100644
--- a/drivers/media/video/ivtv/ivtv-cards.h
+++ b/drivers/media/video/ivtv/ivtv-cards.h
@@ -119,7 +119,7 @@
119 119
120#define IVTV_CARD_MAX_VIDEO_INPUTS 6 120#define IVTV_CARD_MAX_VIDEO_INPUTS 6
121#define IVTV_CARD_MAX_AUDIO_INPUTS 3 121#define IVTV_CARD_MAX_AUDIO_INPUTS 3
122#define IVTV_CARD_MAX_TUNERS 2 122#define IVTV_CARD_MAX_TUNERS 3
123 123
124/* SAA71XX HW inputs */ 124/* SAA71XX HW inputs */
125#define IVTV_SAA71XX_COMPOSITE0 0 125#define IVTV_SAA71XX_COMPOSITE0 0
diff --git a/drivers/media/video/ivtv/ivtv-driver.c b/drivers/media/video/ivtv/ivtv-driver.c
index 948ca35e7ee8..065df53f80fd 100644
--- a/drivers/media/video/ivtv/ivtv-driver.c
+++ b/drivers/media/video/ivtv/ivtv-driver.c
@@ -101,7 +101,7 @@ static int radio[IVTV_MAX_CARDS] = { -1, -1, -1, -1, -1, -1, -1, -1,
101static unsigned int cardtype_c = 1; 101static unsigned int cardtype_c = 1;
102static unsigned int tuner_c = 1; 102static unsigned int tuner_c = 1;
103static unsigned int radio_c = 1; 103static unsigned int radio_c = 1;
104static char pal[] = "--"; 104static char pal[] = "---";
105static char secam[] = "--"; 105static char secam[] = "--";
106static char ntsc[] = "-"; 106static char ntsc[] = "-";
107 107
@@ -126,12 +126,13 @@ static int dec_mpg_buffers = IVTV_DEFAULT_DEC_MPG_BUFFERS;
126static int dec_yuv_buffers = IVTV_DEFAULT_DEC_YUV_BUFFERS; 126static int dec_yuv_buffers = IVTV_DEFAULT_DEC_YUV_BUFFERS;
127static int dec_vbi_buffers = IVTV_DEFAULT_DEC_VBI_BUFFERS; 127static int dec_vbi_buffers = IVTV_DEFAULT_DEC_VBI_BUFFERS;
128 128
129static int ivtv_yuv_mode = 0; 129static int ivtv_yuv_mode;
130static int ivtv_yuv_threshold=-1; 130static int ivtv_yuv_threshold = -1;
131static int ivtv_pci_latency = 1; 131static int ivtv_pci_latency = 1;
132 132
133int ivtv_debug = 0; 133int ivtv_debug;
134 134
135static int tunertype = -1;
135static int newi2c = -1; 136static int newi2c = -1;
136 137
137module_param_array(tuner, int, &tuner_c, 0644); 138module_param_array(tuner, int, &tuner_c, 0644);
@@ -154,6 +155,7 @@ module_param(dec_mpg_buffers, int, 0644);
154module_param(dec_yuv_buffers, int, 0644); 155module_param(dec_yuv_buffers, int, 0644);
155module_param(dec_vbi_buffers, int, 0644); 156module_param(dec_vbi_buffers, int, 0644);
156 157
158module_param(tunertype, int, 0644);
157module_param(newi2c, int, 0644); 159module_param(newi2c, int, 0644);
158 160
159MODULE_PARM_DESC(tuner, "Tuner type selection,\n" 161MODULE_PARM_DESC(tuner, "Tuner type selection,\n"
@@ -190,9 +192,14 @@ MODULE_PARM_DESC(cardtype,
190 "\t\t\t24 = AverMedia EZMaker PCI Deluxe\n" 192 "\t\t\t24 = AverMedia EZMaker PCI Deluxe\n"
191 "\t\t\t 0 = Autodetect (default)\n" 193 "\t\t\t 0 = Autodetect (default)\n"
192 "\t\t\t-1 = Ignore this card\n\t\t"); 194 "\t\t\t-1 = Ignore this card\n\t\t");
193MODULE_PARM_DESC(pal, "Set PAL standard: B, G, H, D, K, I, M, N, Nc, 60"); 195MODULE_PARM_DESC(pal, "Set PAL standard: BGH, DK, I, M, N, Nc, 60");
194MODULE_PARM_DESC(secam, "Set SECAM standard: B, G, H, D, K, L, LC"); 196MODULE_PARM_DESC(secam, "Set SECAM standard: BGH, DK, L, LC");
195MODULE_PARM_DESC(ntsc, "Set NTSC standard: M, J, K"); 197MODULE_PARM_DESC(ntsc, "Set NTSC standard: M, J (Japan), K (South Korea)");
198MODULE_PARM_DESC(tunertype,
199 "Specify tuner type:\n"
200 "\t\t\t 0 = tuner for PAL-B/G/H/D/K/I, SECAM-B/G/H/D/K/L/Lc\n"
201 "\t\t\t 1 = tuner for NTSC-M/J/K, PAL-M/N/Nc\n"
202 "\t\t\t-1 = Autodetect (default)\n");
196MODULE_PARM_DESC(debug, 203MODULE_PARM_DESC(debug,
197 "Debug level (bitmask). Default: 0\n" 204 "Debug level (bitmask). Default: 0\n"
198 "\t\t\t 1/0x0001: warning\n" 205 "\t\t\t 1/0x0001: warning\n"
@@ -490,30 +497,35 @@ static v4l2_std_id ivtv_parse_std(struct ivtv *itv)
490{ 497{
491 switch (pal[0]) { 498 switch (pal[0]) {
492 case '6': 499 case '6':
500 tunertype = 0;
493 return V4L2_STD_PAL_60; 501 return V4L2_STD_PAL_60;
494 case 'b': 502 case 'b':
495 case 'B': 503 case 'B':
496 case 'g': 504 case 'g':
497 case 'G': 505 case 'G':
498 return V4L2_STD_PAL_BG;
499 case 'h': 506 case 'h':
500 case 'H': 507 case 'H':
501 return V4L2_STD_PAL_H; 508 tunertype = 0;
509 return V4L2_STD_PAL_BG | V4L2_STD_PAL_H;
502 case 'n': 510 case 'n':
503 case 'N': 511 case 'N':
512 tunertype = 1;
504 if (pal[1] == 'c' || pal[1] == 'C') 513 if (pal[1] == 'c' || pal[1] == 'C')
505 return V4L2_STD_PAL_Nc; 514 return V4L2_STD_PAL_Nc;
506 return V4L2_STD_PAL_N; 515 return V4L2_STD_PAL_N;
507 case 'i': 516 case 'i':
508 case 'I': 517 case 'I':
518 tunertype = 0;
509 return V4L2_STD_PAL_I; 519 return V4L2_STD_PAL_I;
510 case 'd': 520 case 'd':
511 case 'D': 521 case 'D':
512 case 'k': 522 case 'k':
513 case 'K': 523 case 'K':
524 tunertype = 0;
514 return V4L2_STD_PAL_DK; 525 return V4L2_STD_PAL_DK;
515 case 'M': 526 case 'M':
516 case 'm': 527 case 'm':
528 tunertype = 1;
517 return V4L2_STD_PAL_M; 529 return V4L2_STD_PAL_M;
518 case '-': 530 case '-':
519 break; 531 break;
@@ -529,14 +541,17 @@ static v4l2_std_id ivtv_parse_std(struct ivtv *itv)
529 case 'G': 541 case 'G':
530 case 'h': 542 case 'h':
531 case 'H': 543 case 'H':
544 tunertype = 0;
532 return V4L2_STD_SECAM_B | V4L2_STD_SECAM_G | V4L2_STD_SECAM_H; 545 return V4L2_STD_SECAM_B | V4L2_STD_SECAM_G | V4L2_STD_SECAM_H;
533 case 'd': 546 case 'd':
534 case 'D': 547 case 'D':
535 case 'k': 548 case 'k':
536 case 'K': 549 case 'K':
550 tunertype = 0;
537 return V4L2_STD_SECAM_DK; 551 return V4L2_STD_SECAM_DK;
538 case 'l': 552 case 'l':
539 case 'L': 553 case 'L':
554 tunertype = 0;
540 if (secam[1] == 'C' || secam[1] == 'c') 555 if (secam[1] == 'C' || secam[1] == 'c')
541 return V4L2_STD_SECAM_LC; 556 return V4L2_STD_SECAM_LC;
542 return V4L2_STD_SECAM_L; 557 return V4L2_STD_SECAM_L;
@@ -550,12 +565,15 @@ static v4l2_std_id ivtv_parse_std(struct ivtv *itv)
550 switch (ntsc[0]) { 565 switch (ntsc[0]) {
551 case 'm': 566 case 'm':
552 case 'M': 567 case 'M':
568 tunertype = 1;
553 return V4L2_STD_NTSC_M; 569 return V4L2_STD_NTSC_M;
554 case 'j': 570 case 'j':
555 case 'J': 571 case 'J':
572 tunertype = 1;
556 return V4L2_STD_NTSC_M_JP; 573 return V4L2_STD_NTSC_M_JP;
557 case 'k': 574 case 'k':
558 case 'K': 575 case 'K':
576 tunertype = 1;
559 return V4L2_STD_NTSC_M_KR; 577 return V4L2_STD_NTSC_M_KR;
560 case '-': 578 case '-':
561 break; 579 break;
@@ -584,8 +602,13 @@ static void ivtv_process_options(struct ivtv *itv)
584 itv->options.tuner = tuner[itv->num]; 602 itv->options.tuner = tuner[itv->num];
585 itv->options.radio = radio[itv->num]; 603 itv->options.radio = radio[itv->num];
586 itv->options.newi2c = newi2c; 604 itv->options.newi2c = newi2c;
587 605 if (tunertype < -1 || tunertype > 1) {
606 IVTV_WARN("Invalid tunertype argument, will autodetect instead\n");
607 tunertype = -1;
608 }
588 itv->std = ivtv_parse_std(itv); 609 itv->std = ivtv_parse_std(itv);
610 if (itv->std == 0 && tunertype >= 0)
611 itv->std = tunertype ? V4L2_STD_MN : (V4L2_STD_ALL & ~V4L2_STD_MN);
589 itv->has_cx23415 = (itv->dev->device == PCI_DEVICE_ID_IVTV15); 612 itv->has_cx23415 = (itv->dev->device == PCI_DEVICE_ID_IVTV15);
590 chipname = itv->has_cx23415 ? "cx23415" : "cx23416"; 613 chipname = itv->has_cx23415 ? "cx23415" : "cx23416";
591 if (itv->options.cardtype == -1) { 614 if (itv->options.cardtype == -1) {
@@ -711,6 +734,7 @@ static int __devinit ivtv_init_struct1(struct ivtv *itv)
711 itv->yuv_info.lace_mode = ivtv_yuv_mode; 734 itv->yuv_info.lace_mode = ivtv_yuv_mode;
712 itv->yuv_info.lace_threshold = ivtv_yuv_threshold; 735 itv->yuv_info.lace_threshold = ivtv_yuv_threshold;
713 itv->yuv_info.max_frames_buffered = 3; 736 itv->yuv_info.max_frames_buffered = 3;
737 itv->yuv_info.track_osd = 1;
714 return 0; 738 return 0;
715} 739}
716 740
@@ -859,7 +883,9 @@ static void ivtv_load_and_init_modules(struct ivtv *itv)
859#ifndef CONFIG_VIDEO_SAA7127 883#ifndef CONFIG_VIDEO_SAA7127
860 hw = ivtv_request_module(itv, hw, "saa7127", IVTV_HW_SAA7127); 884 hw = ivtv_request_module(itv, hw, "saa7127", IVTV_HW_SAA7127);
861#endif 885#endif
886#ifndef CONFIG_VIDEO_SAA717X
862 hw = ivtv_request_module(itv, hw, "saa717x", IVTV_HW_SAA717X); 887 hw = ivtv_request_module(itv, hw, "saa717x", IVTV_HW_SAA717X);
888#endif
863#ifndef CONFIG_VIDEO_UPD64031A 889#ifndef CONFIG_VIDEO_UPD64031A
864 hw = ivtv_request_module(itv, hw, "upd64031a", IVTV_HW_UPD64031A); 890 hw = ivtv_request_module(itv, hw, "upd64031a", IVTV_HW_UPD64031A);
865#endif 891#endif
diff --git a/drivers/media/video/ivtv/ivtv-driver.h b/drivers/media/video/ivtv/ivtv-driver.h
index 536140f0c19e..ba06e813c58c 100644
--- a/drivers/media/video/ivtv/ivtv-driver.h
+++ b/drivers/media/video/ivtv/ivtv-driver.h
@@ -456,6 +456,8 @@ struct yuv_playback_info
456 int v_filter_2; 456 int v_filter_2;
457 int h_filter; 457 int h_filter;
458 458
459 u8 track_osd; /* Should yuv output track the OSD size & position */
460
459 u32 osd_x_offset; 461 u32 osd_x_offset;
460 u32 osd_y_offset; 462 u32 osd_y_offset;
461 463
diff --git a/drivers/media/video/ivtv/ivtv-fileops.c b/drivers/media/video/ivtv/ivtv-fileops.c
index 6fb96f19a866..a7640c49f1d8 100644
--- a/drivers/media/video/ivtv/ivtv-fileops.c
+++ b/drivers/media/video/ivtv/ivtv-fileops.c
@@ -219,7 +219,9 @@ static struct ivtv_buffer *ivtv_get_buffer(struct ivtv_stream *s, int non_block,
219 /* Process pending program info updates and pending VBI data */ 219 /* Process pending program info updates and pending VBI data */
220 ivtv_update_pgm_info(itv); 220 ivtv_update_pgm_info(itv);
221 221
222 if (jiffies - itv->dualwatch_jiffies > msecs_to_jiffies(1000)) { 222 if (time_after(jiffies,
223 itv->dualwatch_jiffies +
224 msecs_to_jiffies(1000))) {
223 itv->dualwatch_jiffies = jiffies; 225 itv->dualwatch_jiffies = jiffies;
224 ivtv_dualwatch(itv); 226 ivtv_dualwatch(itv);
225 } 227 }
@@ -753,7 +755,7 @@ unsigned int ivtv_v4l2_enc_poll(struct file *filp, poll_table * wait)
753 IVTV_DEBUG_HI_FILE("Encoder poll\n"); 755 IVTV_DEBUG_HI_FILE("Encoder poll\n");
754 poll_wait(filp, &s->waitq, wait); 756 poll_wait(filp, &s->waitq, wait);
755 757
756 if (eof || s->q_full.length) 758 if (eof || s->q_full.length || s->q_io.length)
757 return POLLIN | POLLRDNORM; 759 return POLLIN | POLLRDNORM;
758 return 0; 760 return 0;
759} 761}
diff --git a/drivers/media/video/ivtv/ivtv-i2c.c b/drivers/media/video/ivtv/ivtv-i2c.c
index fa5ab1eb1800..9824eafee021 100644
--- a/drivers/media/video/ivtv/ivtv-i2c.c
+++ b/drivers/media/video/ivtv/ivtv-i2c.c
@@ -177,10 +177,16 @@ int ivtv_i2c_register(struct ivtv *itv, unsigned idx)
177 } 177 }
178 178
179 if (id != I2C_DRIVERID_TUNER) { 179 if (id != I2C_DRIVERID_TUNER) {
180 c = i2c_new_device(&itv->i2c_adap, &info); 180 if (id == I2C_DRIVERID_UPD64031A ||
181 if (c->driver == NULL) 181 id == I2C_DRIVERID_UPD64083) {
182 unsigned short addrs[2] = { info.addr, I2C_CLIENT_END };
183
184 c = i2c_new_probed_device(&itv->i2c_adap, &info, addrs);
185 } else
186 c = i2c_new_device(&itv->i2c_adap, &info);
187 if (c && c->driver == NULL)
182 i2c_unregister_device(c); 188 i2c_unregister_device(c);
183 else 189 else if (c)
184 itv->i2c_clients[i] = c; 190 itv->i2c_clients[i] = c;
185 return itv->i2c_clients[i] ? 0 : -ENODEV; 191 return itv->i2c_clients[i] ? 0 : -ENODEV;
186 } 192 }
diff --git a/drivers/media/video/ivtv/ivtv-ioctl.c b/drivers/media/video/ivtv/ivtv-ioctl.c
index edef2a579617..15cac1812122 100644
--- a/drivers/media/video/ivtv/ivtv-ioctl.c
+++ b/drivers/media/video/ivtv/ivtv-ioctl.c
@@ -712,6 +712,7 @@ static int ivtv_debug_ioctls(struct file *filp, unsigned int cmd, void *arg)
712int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void *arg) 712int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void *arg)
713{ 713{
714 struct ivtv_open_id *id = NULL; 714 struct ivtv_open_id *id = NULL;
715 struct yuv_playback_info *yi = &itv->yuv_info;
715 u32 data[CX2341X_MBOX_MAX_DATA]; 716 u32 data[CX2341X_MBOX_MAX_DATA];
716 int streamtype = 0; 717 int streamtype = 0;
717 718
@@ -741,7 +742,8 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
741 742
742 memset(vcap, 0, sizeof(*vcap)); 743 memset(vcap, 0, sizeof(*vcap));
743 strcpy(vcap->driver, IVTV_DRIVER_NAME); /* driver name */ 744 strcpy(vcap->driver, IVTV_DRIVER_NAME); /* driver name */
744 strcpy(vcap->card, itv->card_name); /* card type */ 745 strncpy(vcap->card, itv->card_name,
746 sizeof(vcap->card)-1); /* card type */
745 strcpy(vcap->bus_info, pci_name(itv->dev)); /* bus info... */ 747 strcpy(vcap->bus_info, pci_name(itv->dev)); /* bus info... */
746 vcap->version = IVTV_DRIVER_VERSION; /* version */ 748 vcap->version = IVTV_DRIVER_VERSION; /* version */
747 vcap->capabilities = itv->v4l2_cap; /* capabilities */ 749 vcap->capabilities = itv->v4l2_cap; /* capabilities */
@@ -827,8 +829,7 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
827 case VIDIOC_CROPCAP: { 829 case VIDIOC_CROPCAP: {
828 struct v4l2_cropcap *cropcap = arg; 830 struct v4l2_cropcap *cropcap = arg;
829 831
830 if (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE && 832 if (cropcap->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
831 cropcap->type != V4L2_BUF_TYPE_VIDEO_OUTPUT)
832 return -EINVAL; 833 return -EINVAL;
833 cropcap->bounds.top = cropcap->bounds.left = 0; 834 cropcap->bounds.top = cropcap->bounds.left = 0;
834 cropcap->bounds.width = 720; 835 cropcap->bounds.width = 720;
@@ -837,8 +838,14 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
837 cropcap->pixelaspect.numerator = itv->is_50hz ? 59 : 10; 838 cropcap->pixelaspect.numerator = itv->is_50hz ? 59 : 10;
838 cropcap->pixelaspect.denominator = itv->is_50hz ? 54 : 11; 839 cropcap->pixelaspect.denominator = itv->is_50hz ? 54 : 11;
839 } else if (streamtype == IVTV_DEC_STREAM_TYPE_YUV) { 840 } else if (streamtype == IVTV_DEC_STREAM_TYPE_YUV) {
840 cropcap->bounds.width = itv->yuv_info.osd_full_w; 841 if (yi->track_osd) {
841 cropcap->bounds.height = itv->yuv_info.osd_full_h; 842 cropcap->bounds.width = yi->osd_full_w;
843 cropcap->bounds.height = yi->osd_full_h;
844 } else {
845 cropcap->bounds.width = 720;
846 cropcap->bounds.height =
847 itv->is_out_50hz ? 576 : 480;
848 }
842 cropcap->pixelaspect.numerator = itv->is_out_50hz ? 59 : 10; 849 cropcap->pixelaspect.numerator = itv->is_out_50hz ? 59 : 10;
843 cropcap->pixelaspect.denominator = itv->is_out_50hz ? 54 : 11; 850 cropcap->pixelaspect.denominator = itv->is_out_50hz ? 54 : 11;
844 } else { 851 } else {
@@ -856,7 +863,7 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
856 if (crop->type == V4L2_BUF_TYPE_VIDEO_OUTPUT && 863 if (crop->type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
857 (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) { 864 (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) {
858 if (streamtype == IVTV_DEC_STREAM_TYPE_YUV) { 865 if (streamtype == IVTV_DEC_STREAM_TYPE_YUV) {
859 itv->yuv_info.main_rect = crop->c; 866 yi->main_rect = crop->c;
860 return 0; 867 return 0;
861 } else { 868 } else {
862 if (!ivtv_vapi(itv, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW, 4, 869 if (!ivtv_vapi(itv, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW, 4,
@@ -867,9 +874,7 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
867 } 874 }
868 return -EINVAL; 875 return -EINVAL;
869 } 876 }
870 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 877 return -EINVAL;
871 return -EINVAL;
872 return itv->video_dec_func(itv, VIDIOC_S_CROP, arg);
873 } 878 }
874 879
875 case VIDIOC_G_CROP: { 880 case VIDIOC_G_CROP: {
@@ -878,14 +883,12 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
878 if (crop->type == V4L2_BUF_TYPE_VIDEO_OUTPUT && 883 if (crop->type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
879 (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) { 884 (itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT)) {
880 if (streamtype == IVTV_DEC_STREAM_TYPE_YUV) 885 if (streamtype == IVTV_DEC_STREAM_TYPE_YUV)
881 crop->c = itv->yuv_info.main_rect; 886 crop->c = yi->main_rect;
882 else 887 else
883 crop->c = itv->main_rect; 888 crop->c = itv->main_rect;
884 return 0; 889 return 0;
885 } 890 }
886 if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 891 return -EINVAL;
887 return -EINVAL;
888 return itv->video_dec_func(itv, VIDIOC_G_CROP, arg);
889 } 892 }
890 893
891 case VIDIOC_ENUM_FMT: { 894 case VIDIOC_ENUM_FMT: {
@@ -1070,11 +1073,10 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
1070 itv->main_rect.height = itv->params.height; 1073 itv->main_rect.height = itv->params.height;
1071 ivtv_vapi(itv, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW, 4, 1074 ivtv_vapi(itv, CX2341X_OSD_SET_FRAMEBUFFER_WINDOW, 4,
1072 720, itv->main_rect.height, 0, 0); 1075 720, itv->main_rect.height, 0, 0);
1073 itv->yuv_info.main_rect = itv->main_rect; 1076 yi->main_rect = itv->main_rect;
1074 if (!itv->osd_info) { 1077 if (!itv->osd_info) {
1075 itv->yuv_info.osd_full_w = 720; 1078 yi->osd_full_w = 720;
1076 itv->yuv_info.osd_full_h = 1079 yi->osd_full_h = itv->is_out_50hz ? 576 : 480;
1077 itv->is_out_50hz ? 576 : 480;
1078 } 1080 }
1079 } 1081 }
1080 break; 1082 break;
@@ -1272,6 +1274,8 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
1272 else 1274 else
1273 fb->flags |= V4L2_FBUF_FLAG_LOCAL_ALPHA; 1275 fb->flags |= V4L2_FBUF_FLAG_LOCAL_ALPHA;
1274 } 1276 }
1277 if (yi->track_osd)
1278 fb->flags |= V4L2_FBUF_FLAG_OVERLAY;
1275 break; 1279 break;
1276 } 1280 }
1277 1281
@@ -1285,6 +1289,7 @@ int ivtv_v4l2_ioctls(struct ivtv *itv, struct file *filp, unsigned int cmd, void
1285 (fb->flags & (V4L2_FBUF_FLAG_LOCAL_ALPHA|V4L2_FBUF_FLAG_LOCAL_INV_ALPHA)) != 0; 1289 (fb->flags & (V4L2_FBUF_FLAG_LOCAL_ALPHA|V4L2_FBUF_FLAG_LOCAL_INV_ALPHA)) != 0;
1286 itv->osd_chroma_key_state = (fb->flags & V4L2_FBUF_FLAG_CHROMAKEY) != 0; 1290 itv->osd_chroma_key_state = (fb->flags & V4L2_FBUF_FLAG_CHROMAKEY) != 0;
1287 ivtv_set_osd_alpha(itv); 1291 ivtv_set_osd_alpha(itv);
1292 yi->track_osd = (fb->flags & V4L2_FBUF_FLAG_OVERLAY) != 0;
1288 break; 1293 break;
1289 } 1294 }
1290 1295
@@ -1628,6 +1633,7 @@ static int ivtv_v4l2_do_ioctl(struct inode *inode, struct file *filp,
1628 if (ivtv_debug & IVTV_DBGFLG_IOCTL) { 1633 if (ivtv_debug & IVTV_DBGFLG_IOCTL) {
1629 printk(KERN_INFO "ivtv%d ioctl: ", itv->num); 1634 printk(KERN_INFO "ivtv%d ioctl: ", itv->num);
1630 v4l_printk_ioctl(cmd); 1635 v4l_printk_ioctl(cmd);
1636 printk("\n");
1631 } 1637 }
1632 return ivtv_debug_ioctls(filp, cmd, arg); 1638 return ivtv_debug_ioctls(filp, cmd, arg);
1633 1639
@@ -1671,6 +1677,7 @@ static int ivtv_v4l2_do_ioctl(struct inode *inode, struct file *filp,
1671 if (ivtv_debug & IVTV_DBGFLG_IOCTL) { 1677 if (ivtv_debug & IVTV_DBGFLG_IOCTL) {
1672 printk(KERN_INFO "ivtv%d ioctl: ", itv->num); 1678 printk(KERN_INFO "ivtv%d ioctl: ", itv->num);
1673 v4l_printk_ioctl(cmd); 1679 v4l_printk_ioctl(cmd);
1680 printk("\n");
1674 } 1681 }
1675 return ivtv_v4l2_ioctls(itv, filp, cmd, arg); 1682 return ivtv_v4l2_ioctls(itv, filp, cmd, arg);
1676 1683
@@ -1684,6 +1691,7 @@ static int ivtv_v4l2_do_ioctl(struct inode *inode, struct file *filp,
1684 if (ivtv_debug & IVTV_DBGFLG_IOCTL) { 1691 if (ivtv_debug & IVTV_DBGFLG_IOCTL) {
1685 printk(KERN_INFO "ivtv%d ioctl: ", itv->num); 1692 printk(KERN_INFO "ivtv%d ioctl: ", itv->num);
1686 v4l_printk_ioctl(cmd); 1693 v4l_printk_ioctl(cmd);
1694 printk("\n");
1687 } 1695 }
1688 return ivtv_control_ioctls(itv, cmd, arg); 1696 return ivtv_control_ioctls(itv, cmd, arg);
1689 1697
diff --git a/drivers/media/video/ivtv/ivtv-irq.c b/drivers/media/video/ivtv/ivtv-irq.c
index 65604dde9726..a329c4689dbf 100644
--- a/drivers/media/video/ivtv/ivtv-irq.c
+++ b/drivers/media/video/ivtv/ivtv-irq.c
@@ -384,6 +384,8 @@ static void ivtv_dma_enc_start_xfer(struct ivtv_stream *s)
384 ivtv_stream_sync_for_device(s); 384 ivtv_stream_sync_for_device(s);
385 write_reg(s->sg_handle, IVTV_REG_ENCDMAADDR); 385 write_reg(s->sg_handle, IVTV_REG_ENCDMAADDR);
386 write_reg_sync(read_reg(IVTV_REG_DMAXFER) | 0x02, IVTV_REG_DMAXFER); 386 write_reg_sync(read_reg(IVTV_REG_DMAXFER) | 0x02, IVTV_REG_DMAXFER);
387 itv->dma_timer.expires = jiffies + msecs_to_jiffies(100);
388 add_timer(&itv->dma_timer);
387} 389}
388 390
389static void ivtv_dma_dec_start_xfer(struct ivtv_stream *s) 391static void ivtv_dma_dec_start_xfer(struct ivtv_stream *s)
@@ -398,6 +400,8 @@ static void ivtv_dma_dec_start_xfer(struct ivtv_stream *s)
398 ivtv_stream_sync_for_device(s); 400 ivtv_stream_sync_for_device(s);
399 write_reg(s->sg_handle, IVTV_REG_DECDMAADDR); 401 write_reg(s->sg_handle, IVTV_REG_DECDMAADDR);
400 write_reg_sync(read_reg(IVTV_REG_DMAXFER) | 0x01, IVTV_REG_DMAXFER); 402 write_reg_sync(read_reg(IVTV_REG_DMAXFER) | 0x01, IVTV_REG_DMAXFER);
403 itv->dma_timer.expires = jiffies + msecs_to_jiffies(100);
404 add_timer(&itv->dma_timer);
401} 405}
402 406
403/* start the encoder DMA */ 407/* start the encoder DMA */
@@ -459,8 +463,6 @@ static void ivtv_dma_enc_start(struct ivtv_stream *s)
459 ivtv_dma_enc_start_xfer(s); 463 ivtv_dma_enc_start_xfer(s);
460 set_bit(IVTV_F_I_DMA, &itv->i_flags); 464 set_bit(IVTV_F_I_DMA, &itv->i_flags);
461 itv->cur_dma_stream = s->type; 465 itv->cur_dma_stream = s->type;
462 itv->dma_timer.expires = jiffies + msecs_to_jiffies(100);
463 add_timer(&itv->dma_timer);
464 } 466 }
465} 467}
466 468
@@ -481,8 +483,6 @@ static void ivtv_dma_dec_start(struct ivtv_stream *s)
481 ivtv_dma_dec_start_xfer(s); 483 ivtv_dma_dec_start_xfer(s);
482 set_bit(IVTV_F_I_DMA, &itv->i_flags); 484 set_bit(IVTV_F_I_DMA, &itv->i_flags);
483 itv->cur_dma_stream = s->type; 485 itv->cur_dma_stream = s->type;
484 itv->dma_timer.expires = jiffies + msecs_to_jiffies(100);
485 add_timer(&itv->dma_timer);
486} 486}
487 487
488static void ivtv_irq_dma_read(struct ivtv *itv) 488static void ivtv_irq_dma_read(struct ivtv *itv)
@@ -492,10 +492,11 @@ static void ivtv_irq_dma_read(struct ivtv *itv)
492 int hw_stream_type = 0; 492 int hw_stream_type = 0;
493 493
494 IVTV_DEBUG_HI_IRQ("DEC DMA READ\n"); 494 IVTV_DEBUG_HI_IRQ("DEC DMA READ\n");
495 if (!test_bit(IVTV_F_I_UDMA, &itv->i_flags) && itv->cur_dma_stream < 0) { 495
496 del_timer(&itv->dma_timer); 496 del_timer(&itv->dma_timer);
497
498 if (!test_bit(IVTV_F_I_UDMA, &itv->i_flags) && itv->cur_dma_stream < 0)
497 return; 499 return;
498 }
499 500
500 if (!test_bit(IVTV_F_I_UDMA, &itv->i_flags)) { 501 if (!test_bit(IVTV_F_I_UDMA, &itv->i_flags)) {
501 s = &itv->streams[itv->cur_dma_stream]; 502 s = &itv->streams[itv->cur_dma_stream];
@@ -543,7 +544,6 @@ static void ivtv_irq_dma_read(struct ivtv *itv)
543 } 544 }
544 wake_up(&s->waitq); 545 wake_up(&s->waitq);
545 } 546 }
546 del_timer(&itv->dma_timer);
547 clear_bit(IVTV_F_I_UDMA, &itv->i_flags); 547 clear_bit(IVTV_F_I_UDMA, &itv->i_flags);
548 clear_bit(IVTV_F_I_DMA, &itv->i_flags); 548 clear_bit(IVTV_F_I_DMA, &itv->i_flags);
549 itv->cur_dma_stream = -1; 549 itv->cur_dma_stream = -1;
@@ -557,10 +557,12 @@ static void ivtv_irq_enc_dma_complete(struct ivtv *itv)
557 557
558 ivtv_api_get_data(&itv->enc_mbox, IVTV_MBOX_DMA_END, data); 558 ivtv_api_get_data(&itv->enc_mbox, IVTV_MBOX_DMA_END, data);
559 IVTV_DEBUG_HI_IRQ("ENC DMA COMPLETE %x %d (%d)\n", data[0], data[1], itv->cur_dma_stream); 559 IVTV_DEBUG_HI_IRQ("ENC DMA COMPLETE %x %d (%d)\n", data[0], data[1], itv->cur_dma_stream);
560 if (itv->cur_dma_stream < 0) { 560
561 del_timer(&itv->dma_timer); 561 del_timer(&itv->dma_timer);
562
563 if (itv->cur_dma_stream < 0)
562 return; 564 return;
563 } 565
564 s = &itv->streams[itv->cur_dma_stream]; 566 s = &itv->streams[itv->cur_dma_stream];
565 ivtv_stream_sync_for_cpu(s); 567 ivtv_stream_sync_for_cpu(s);
566 568
@@ -585,7 +587,6 @@ static void ivtv_irq_enc_dma_complete(struct ivtv *itv)
585 ivtv_dma_enc_start_xfer(s); 587 ivtv_dma_enc_start_xfer(s);
586 return; 588 return;
587 } 589 }
588 del_timer(&itv->dma_timer);
589 clear_bit(IVTV_F_I_DMA, &itv->i_flags); 590 clear_bit(IVTV_F_I_DMA, &itv->i_flags);
590 itv->cur_dma_stream = -1; 591 itv->cur_dma_stream = -1;
591 dma_post(s); 592 dma_post(s);
diff --git a/drivers/media/video/ivtv/ivtv-mailbox.c b/drivers/media/video/ivtv/ivtv-mailbox.c
index 13a6c374d2db..1b5c0ac09a85 100644
--- a/drivers/media/video/ivtv/ivtv-mailbox.c
+++ b/drivers/media/video/ivtv/ivtv-mailbox.c
@@ -177,7 +177,8 @@ static int get_mailbox(struct ivtv *itv, struct ivtv_mailbox_data *mbdata, int f
177 177
178 /* Sleep before a retry, if not atomic */ 178 /* Sleep before a retry, if not atomic */
179 if (!(flags & API_NO_WAIT_MB)) { 179 if (!(flags & API_NO_WAIT_MB)) {
180 if (jiffies - then > msecs_to_jiffies(10*retries)) 180 if (time_after(jiffies,
181 then + msecs_to_jiffies(10*retries)))
181 break; 182 break;
182 ivtv_msleep_timeout(10, 0); 183 ivtv_msleep_timeout(10, 0);
183 } 184 }
@@ -244,7 +245,9 @@ static int ivtv_api_call(struct ivtv *itv, int cmd, int args, u32 data[])
244 data, then just return 0 as there is no need to issue this command again. 245 data, then just return 0 as there is no need to issue this command again.
245 Just an optimization to prevent unnecessary use of mailboxes. */ 246 Just an optimization to prevent unnecessary use of mailboxes. */
246 if (itv->api_cache[cmd].last_jiffies && 247 if (itv->api_cache[cmd].last_jiffies &&
247 jiffies - itv->api_cache[cmd].last_jiffies < msecs_to_jiffies(1800000) && 248 time_before(jiffies,
249 itv->api_cache[cmd].last_jiffies +
250 msecs_to_jiffies(1800000)) &&
248 !memcmp(data, itv->api_cache[cmd].data, sizeof(itv->api_cache[cmd].data))) { 251 !memcmp(data, itv->api_cache[cmd].data, sizeof(itv->api_cache[cmd].data))) {
249 itv->api_cache[cmd].last_jiffies = jiffies; 252 itv->api_cache[cmd].last_jiffies = jiffies;
250 return 0; 253 return 0;
@@ -299,7 +302,7 @@ static int ivtv_api_call(struct ivtv *itv, int cmd, int args, u32 data[])
299 } 302 }
300 } 303 }
301 while (!(readl(&mbox->flags) & IVTV_MBOX_FIRMWARE_DONE)) { 304 while (!(readl(&mbox->flags) & IVTV_MBOX_FIRMWARE_DONE)) {
302 if (jiffies - then > api_timeout) { 305 if (time_after(jiffies, then + api_timeout)) {
303 IVTV_DEBUG_WARN("Could not get result (%s)\n", api_info[cmd].name); 306 IVTV_DEBUG_WARN("Could not get result (%s)\n", api_info[cmd].name);
304 /* reset the mailbox, but it is likely too late already */ 307 /* reset the mailbox, but it is likely too late already */
305 write_sync(0, &mbox->flags); 308 write_sync(0, &mbox->flags);
@@ -311,7 +314,7 @@ static int ivtv_api_call(struct ivtv *itv, int cmd, int args, u32 data[])
311 else 314 else
312 ivtv_msleep_timeout(1, 0); 315 ivtv_msleep_timeout(1, 0);
313 } 316 }
314 if (jiffies - then > msecs_to_jiffies(100)) 317 if (time_after(jiffies, then + msecs_to_jiffies(100)))
315 IVTV_DEBUG_WARN("%s took %u jiffies\n", 318 IVTV_DEBUG_WARN("%s took %u jiffies\n",
316 api_info[cmd].name, 319 api_info[cmd].name,
317 jiffies_to_msecs(jiffies - then)); 320 jiffies_to_msecs(jiffies - then));
diff --git a/drivers/media/video/ivtv/ivtv-queue.c b/drivers/media/video/ivtv/ivtv-queue.c
index 39a216713244..3e1deec67a5e 100644
--- a/drivers/media/video/ivtv/ivtv-queue.c
+++ b/drivers/media/video/ivtv/ivtv-queue.c
@@ -51,7 +51,7 @@ void ivtv_queue_init(struct ivtv_queue *q)
51 51
52void ivtv_enqueue(struct ivtv_stream *s, struct ivtv_buffer *buf, struct ivtv_queue *q) 52void ivtv_enqueue(struct ivtv_stream *s, struct ivtv_buffer *buf, struct ivtv_queue *q)
53{ 53{
54 unsigned long flags = 0; 54 unsigned long flags;
55 55
56 /* clear the buffer if it is going to be enqueued to the free queue */ 56 /* clear the buffer if it is going to be enqueued to the free queue */
57 if (q == &s->q_free) { 57 if (q == &s->q_free) {
@@ -71,7 +71,7 @@ void ivtv_enqueue(struct ivtv_stream *s, struct ivtv_buffer *buf, struct ivtv_qu
71struct ivtv_buffer *ivtv_dequeue(struct ivtv_stream *s, struct ivtv_queue *q) 71struct ivtv_buffer *ivtv_dequeue(struct ivtv_stream *s, struct ivtv_queue *q)
72{ 72{
73 struct ivtv_buffer *buf = NULL; 73 struct ivtv_buffer *buf = NULL;
74 unsigned long flags = 0; 74 unsigned long flags;
75 75
76 spin_lock_irqsave(&s->qlock, flags); 76 spin_lock_irqsave(&s->qlock, flags);
77 if (!list_empty(&q->list)) { 77 if (!list_empty(&q->list)) {
diff --git a/drivers/media/video/ivtv/ivtv-streams.c b/drivers/media/video/ivtv/ivtv-streams.c
index 24d98ecf35ad..4ab8d36831ba 100644
--- a/drivers/media/video/ivtv/ivtv-streams.c
+++ b/drivers/media/video/ivtv/ivtv-streams.c
@@ -768,7 +768,8 @@ int ivtv_stop_v4l2_encode_stream(struct ivtv_stream *s, int gop_end)
768 768
769 /* wait 2s for EOS interrupt */ 769 /* wait 2s for EOS interrupt */
770 while (!test_bit(IVTV_F_I_EOS, &itv->i_flags) && 770 while (!test_bit(IVTV_F_I_EOS, &itv->i_flags) &&
771 jiffies < then + msecs_to_jiffies (2000)) { 771 time_before(jiffies,
772 then + msecs_to_jiffies(2000))) {
772 schedule_timeout(msecs_to_jiffies(10)); 773 schedule_timeout(msecs_to_jiffies(10));
773 } 774 }
774 775
diff --git a/drivers/media/video/ivtv/ivtv-yuv.c b/drivers/media/video/ivtv/ivtv-yuv.c
index 85183480a225..393d917cd672 100644
--- a/drivers/media/video/ivtv/ivtv-yuv.c
+++ b/drivers/media/video/ivtv/ivtv-yuv.c
@@ -718,9 +718,11 @@ static u32 ivtv_yuv_window_setup(struct ivtv *itv, struct yuv_frame_info *f)
718 f->src_w -= (osd_scale * osd_crop) >> 16; 718 f->src_w -= (osd_scale * osd_crop) >> 16;
719 } 719 }
720 720
721 /* The OSD can be moved. Track to it */ 721 if (itv->yuv_info.track_osd) {
722 f->dst_x += itv->yuv_info.osd_x_offset; 722 /* The OSD can be moved. Track to it */
723 f->dst_y += itv->yuv_info.osd_y_offset; 723 f->dst_x += itv->yuv_info.osd_x_offset;
724 f->dst_y += itv->yuv_info.osd_y_offset;
725 }
724 726
725 /* Width & height for both src & dst must be even. 727 /* Width & height for both src & dst must be even.
726 Same for coordinates. */ 728 Same for coordinates. */
@@ -792,11 +794,19 @@ void ivtv_yuv_work_handler(struct ivtv *itv)
792 IVTV_DEBUG_YUV("Update yuv registers for frame %d\n", frame); 794 IVTV_DEBUG_YUV("Update yuv registers for frame %d\n", frame);
793 f = yi->new_frame_info[frame]; 795 f = yi->new_frame_info[frame];
794 796
795 /* Update the osd pan info */ 797 if (yi->track_osd) {
796 f.pan_x = yi->osd_x_pan; 798 /* Snapshot the osd pan info */
797 f.pan_y = yi->osd_y_pan; 799 f.pan_x = yi->osd_x_pan;
798 f.vis_w = yi->osd_vis_w; 800 f.pan_y = yi->osd_y_pan;
799 f.vis_h = yi->osd_vis_h; 801 f.vis_w = yi->osd_vis_w;
802 f.vis_h = yi->osd_vis_h;
803 } else {
804 /* Not tracking the osd, so assume full screen */
805 f.pan_x = 0;
806 f.pan_y = 0;
807 f.vis_w = 720;
808 f.vis_h = yi->decode_height;
809 }
800 810
801 /* Calculate the display window coordinates. Exit if nothing left */ 811 /* Calculate the display window coordinates. Exit if nothing left */
802 if (!(yuv_update = ivtv_yuv_window_setup(itv, &f))) 812 if (!(yuv_update = ivtv_yuv_window_setup(itv, &f)))
@@ -914,7 +924,7 @@ static void ivtv_yuv_init(struct ivtv *itv)
914} 924}
915 925
916/* Get next available yuv buffer on PVR350 */ 926/* Get next available yuv buffer on PVR350 */
917void ivtv_yuv_next_free(struct ivtv *itv) 927static void ivtv_yuv_next_free(struct ivtv *itv)
918{ 928{
919 int draw, display; 929 int draw, display;
920 struct yuv_playback_info *yi = &itv->yuv_info; 930 struct yuv_playback_info *yi = &itv->yuv_info;
@@ -937,7 +947,7 @@ void ivtv_yuv_next_free(struct ivtv *itv)
937} 947}
938 948
939/* Set up frame according to ivtv_dma_frame parameters */ 949/* Set up frame according to ivtv_dma_frame parameters */
940void ivtv_yuv_setup_frame(struct ivtv *itv, struct ivtv_dma_frame *args) 950static void ivtv_yuv_setup_frame(struct ivtv *itv, struct ivtv_dma_frame *args)
941{ 951{
942 struct yuv_playback_info *yi = &itv->yuv_info; 952 struct yuv_playback_info *yi = &itv->yuv_info;
943 u8 frame = yi->draw_frame; 953 u8 frame = yi->draw_frame;
@@ -965,12 +975,6 @@ void ivtv_yuv_setup_frame(struct ivtv *itv, struct ivtv_dma_frame *args)
965 /* Are we going to offset the Y plane */ 975 /* Are we going to offset the Y plane */
966 nf->offset_y = (nf->tru_h + nf->src_x < 512 - 16) ? 1 : 0; 976 nf->offset_y = (nf->tru_h + nf->src_x < 512 - 16) ? 1 : 0;
967 977
968 /* Snapshot the osd pan info */
969 nf->pan_x = yi->osd_x_pan;
970 nf->pan_y = yi->osd_y_pan;
971 nf->vis_w = yi->osd_vis_w;
972 nf->vis_h = yi->osd_vis_h;
973
974 nf->update = 0; 978 nf->update = 0;
975 nf->interlaced_y = 0; 979 nf->interlaced_y = 0;
976 nf->interlaced_uv = 0; 980 nf->interlaced_uv = 0;
@@ -1042,7 +1046,7 @@ void ivtv_yuv_frame_complete(struct ivtv *itv)
1042 (itv->yuv_info.draw_frame + 1) % IVTV_YUV_BUFFERS); 1046 (itv->yuv_info.draw_frame + 1) % IVTV_YUV_BUFFERS);
1043} 1047}
1044 1048
1045int ivtv_yuv_udma_frame(struct ivtv *itv, struct ivtv_dma_frame *args) 1049static int ivtv_yuv_udma_frame(struct ivtv *itv, struct ivtv_dma_frame *args)
1046{ 1050{
1047 DEFINE_WAIT(wait); 1051 DEFINE_WAIT(wait);
1048 int rc = 0; 1052 int rc = 0;
diff --git a/drivers/media/video/meye.c b/drivers/media/video/meye.c
index 3d51fa0a52b6..e7ccbc895d7a 100644
--- a/drivers/media/video/meye.c
+++ b/drivers/media/video/meye.c
@@ -42,15 +42,10 @@
42#include <linux/meye.h> 42#include <linux/meye.h>
43 43
44MODULE_AUTHOR("Stelian Pop <stelian@popies.net>"); 44MODULE_AUTHOR("Stelian Pop <stelian@popies.net>");
45MODULE_DESCRIPTION("v4l/v4l2 driver for the MotionEye camera"); 45MODULE_DESCRIPTION("v4l2 driver for the MotionEye camera");
46MODULE_LICENSE("GPL"); 46MODULE_LICENSE("GPL");
47MODULE_VERSION(MEYE_DRIVER_VERSION); 47MODULE_VERSION(MEYE_DRIVER_VERSION);
48 48
49/* force usage of V4L1 API */
50static int forcev4l1; /* = 0 */
51module_param(forcev4l1, int, 0644);
52MODULE_PARM_DESC(forcev4l1, "force use of V4L1 instead of V4L2");
53
54/* number of grab buffers */ 49/* number of grab buffers */
55static unsigned int gbuffers = 2; 50static unsigned int gbuffers = 2;
56module_param(gbuffers, int, 0444); 51module_param(gbuffers, int, 0444);
@@ -789,7 +784,7 @@ static irqreturn_t meye_irq(int irq, void *dev_id)
789{ 784{
790 u32 v; 785 u32 v;
791 int reqnr; 786 int reqnr;
792 static int sequence = 0; 787 static int sequence;
793 788
794 v = mchip_read(MCHIP_MM_INTA); 789 v = mchip_read(MCHIP_MM_INTA);
795 790
@@ -876,795 +871,735 @@ static int meye_release(struct inode *inode, struct file *file)
876 return 0; 871 return 0;
877} 872}
878 873
879static int meye_do_ioctl(struct inode *inode, struct file *file, 874static int meyeioc_g_params(struct meye_params *p)
880 unsigned int cmd, void *arg)
881{ 875{
882 switch (cmd) { 876 *p = meye.params;
877 return 0;
878}
883 879
884 case VIDIOCGCAP: { 880static int meyeioc_s_params(struct meye_params *jp)
885 struct video_capability *b = arg; 881{
886 strcpy(b->name,meye.video_dev->name); 882 if (jp->subsample > 1)
887 b->type = VID_TYPE_CAPTURE; 883 return -EINVAL;
888 b->channels = 1;
889 b->audios = 0;
890 b->maxwidth = 640;
891 b->maxheight = 480;
892 b->minwidth = 320;
893 b->minheight = 240;
894 break;
895 }
896 884
897 case VIDIOCGCHAN: { 885 if (jp->quality > 10)
898 struct video_channel *v = arg; 886 return -EINVAL;
899 v->flags = 0;
900 v->tuners = 0;
901 v->type = VIDEO_TYPE_CAMERA;
902 if (v->channel != 0)
903 return -EINVAL;
904 strcpy(v->name,"Camera");
905 break;
906 }
907 887
908 case VIDIOCSCHAN: { 888 if (jp->sharpness > 63 || jp->agc > 63 || jp->picture > 63)
909 struct video_channel *v = arg; 889 return -EINVAL;
910 if (v->channel != 0)
911 return -EINVAL;
912 break;
913 }
914 890
915 case VIDIOCGPICT: { 891 if (jp->framerate > 31)
916 struct video_picture *p = arg; 892 return -EINVAL;
917 *p = meye.picture;
918 break;
919 }
920 893
921 case VIDIOCSPICT: { 894 mutex_lock(&meye.lock);
922 struct video_picture *p = arg;
923 if (p->depth != 16)
924 return -EINVAL;
925 if (p->palette != VIDEO_PALETTE_YUV422 && p->palette != VIDEO_PALETTE_YUYV)
926 return -EINVAL;
927 mutex_lock(&meye.lock);
928 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERABRIGHTNESS,
929 p->brightness >> 10);
930 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAHUE,
931 p->hue >> 10);
932 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERACOLOR,
933 p->colour >> 10);
934 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERACONTRAST,
935 p->contrast >> 10);
936 meye.picture = *p;
937 mutex_unlock(&meye.lock);
938 break;
939 }
940 895
941 case VIDIOCSYNC: { 896 if (meye.params.subsample != jp->subsample ||
942 int *i = arg; 897 meye.params.quality != jp->quality)
943 int unused; 898 mchip_hic_stop(); /* need restart */
899
900 meye.params = *jp;
901 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERASHARPNESS,
902 meye.params.sharpness);
903 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAAGC,
904 meye.params.agc);
905 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAPICTURE,
906 meye.params.picture);
907 mutex_unlock(&meye.lock);
944 908
945 if (*i < 0 || *i >= gbuffers) 909 return 0;
946 return -EINVAL; 910}
947 911
948 mutex_lock(&meye.lock); 912static int meyeioc_qbuf_capt(int *nb)
913{
914 if (!meye.grab_fbuffer)
915 return -EINVAL;
949 916
950 switch (meye.grab_buffer[*i].state) { 917 if (*nb >= gbuffers)
918 return -EINVAL;
951 919
952 case MEYE_BUF_UNUSED: 920 if (*nb < 0) {
953 mutex_unlock(&meye.lock); 921 /* stop capture */
954 return -EINVAL; 922 mchip_hic_stop();
955 case MEYE_BUF_USING: 923 return 0;
956 if (file->f_flags & O_NONBLOCK) {
957 mutex_unlock(&meye.lock);
958 return -EAGAIN;
959 }
960 if (wait_event_interruptible(meye.proc_list,
961 (meye.grab_buffer[*i].state != MEYE_BUF_USING))) {
962 mutex_unlock(&meye.lock);
963 return -EINTR;
964 }
965 /* fall through */
966 case MEYE_BUF_DONE:
967 meye.grab_buffer[*i].state = MEYE_BUF_UNUSED;
968 kfifo_get(meye.doneq, (unsigned char *)&unused, sizeof(int));
969 }
970 mutex_unlock(&meye.lock);
971 break;
972 } 924 }
973 925
974 case VIDIOCMCAPTURE: { 926 if (meye.grab_buffer[*nb].state != MEYE_BUF_UNUSED)
975 struct video_mmap *vm = arg; 927 return -EBUSY;
976 int restart = 0;
977
978 if (vm->frame >= gbuffers || vm->frame < 0)
979 return -EINVAL;
980 if (vm->format != VIDEO_PALETTE_YUV422 && vm->format != VIDEO_PALETTE_YUYV)
981 return -EINVAL;
982 if (vm->height * vm->width * 2 > gbufsize)
983 return -EINVAL;
984 if (!meye.grab_fbuffer)
985 return -EINVAL;
986 if (meye.grab_buffer[vm->frame].state != MEYE_BUF_UNUSED)
987 return -EBUSY;
988
989 mutex_lock(&meye.lock);
990 if (vm->width == 640 && vm->height == 480) {
991 if (meye.params.subsample) {
992 meye.params.subsample = 0;
993 restart = 1;
994 }
995 } else if (vm->width == 320 && vm->height == 240) {
996 if (!meye.params.subsample) {
997 meye.params.subsample = 1;
998 restart = 1;
999 }
1000 } else {
1001 mutex_unlock(&meye.lock);
1002 return -EINVAL;
1003 }
1004 928
1005 if (restart || meye.mchip_mode != MCHIP_HIC_MODE_CONT_OUT) 929 mutex_lock(&meye.lock);
1006 mchip_continuous_start();
1007 meye.grab_buffer[vm->frame].state = MEYE_BUF_USING;
1008 kfifo_put(meye.grabq, (unsigned char *)&vm->frame, sizeof(int));
1009 mutex_unlock(&meye.lock);
1010 break;
1011 }
1012 930
1013 case VIDIOCGMBUF: { 931 if (meye.mchip_mode != MCHIP_HIC_MODE_CONT_COMP)
1014 struct video_mbuf *vm = arg; 932 mchip_cont_compression_start();
1015 int i;
1016 933
1017 memset(vm, 0 , sizeof(*vm)); 934 meye.grab_buffer[*nb].state = MEYE_BUF_USING;
1018 vm->size = gbufsize * gbuffers; 935 kfifo_put(meye.grabq, (unsigned char *)nb, sizeof(int));
1019 vm->frames = gbuffers; 936 mutex_unlock(&meye.lock);
1020 for (i = 0; i < gbuffers; i++)
1021 vm->offsets[i] = i * gbufsize;
1022 break;
1023 }
1024 937
1025 case MEYEIOC_G_PARAMS: { 938 return 0;
1026 struct meye_params *p = arg; 939}
1027 *p = meye.params;
1028 break;
1029 }
1030 940
1031 case MEYEIOC_S_PARAMS: { 941static int meyeioc_sync(struct file *file, void *fh, int *i)
1032 struct meye_params *jp = arg; 942{
1033 if (jp->subsample > 1) 943 int unused;
1034 return -EINVAL;
1035 if (jp->quality > 10)
1036 return -EINVAL;
1037 if (jp->sharpness > 63 || jp->agc > 63 || jp->picture > 63)
1038 return -EINVAL;
1039 if (jp->framerate > 31)
1040 return -EINVAL;
1041 mutex_lock(&meye.lock);
1042 if (meye.params.subsample != jp->subsample ||
1043 meye.params.quality != jp->quality)
1044 mchip_hic_stop(); /* need restart */
1045 meye.params = *jp;
1046 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERASHARPNESS,
1047 meye.params.sharpness);
1048 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAAGC,
1049 meye.params.agc);
1050 sony_pic_camera_command(SONY_PIC_COMMAND_SETCAMERAPICTURE,
1051 meye.params.picture);
1052 mutex_unlock(&meye.lock);
1053 break;
1054 }
1055 944
1056 case MEYEIOC_QBUF_CAPT: { 945 if (*i < 0 || *i >= gbuffers)
1057 int *nb = arg; 946 return -EINVAL;
1058 947
1059 if (!meye.grab_fbuffer) 948 mutex_lock(&meye.lock);
1060 return -EINVAL; 949 switch (meye.grab_buffer[*i].state) {
1061 if (*nb >= gbuffers) 950
1062 return -EINVAL; 951 case MEYE_BUF_UNUSED:
1063 if (*nb < 0) {
1064 /* stop capture */
1065 mchip_hic_stop();
1066 return 0;
1067 }
1068 if (meye.grab_buffer[*nb].state != MEYE_BUF_UNUSED)
1069 return -EBUSY;
1070 mutex_lock(&meye.lock);
1071 if (meye.mchip_mode != MCHIP_HIC_MODE_CONT_COMP)
1072 mchip_cont_compression_start();
1073 meye.grab_buffer[*nb].state = MEYE_BUF_USING;
1074 kfifo_put(meye.grabq, (unsigned char *)nb, sizeof(int));
1075 mutex_unlock(&meye.lock); 952 mutex_unlock(&meye.lock);
1076 break; 953 return -EINVAL;
954 case MEYE_BUF_USING:
955 if (file->f_flags & O_NONBLOCK) {
956 mutex_unlock(&meye.lock);
957 return -EAGAIN;
958 }
959 if (wait_event_interruptible(meye.proc_list,
960 (meye.grab_buffer[*i].state != MEYE_BUF_USING))) {
961 mutex_unlock(&meye.lock);
962 return -EINTR;
963 }
964 /* fall through */
965 case MEYE_BUF_DONE:
966 meye.grab_buffer[*i].state = MEYE_BUF_UNUSED;
967 kfifo_get(meye.doneq, (unsigned char *)&unused, sizeof(int));
1077 } 968 }
969 *i = meye.grab_buffer[*i].size;
970 mutex_unlock(&meye.lock);
971 return 0;
972}
1078 973
1079 case MEYEIOC_SYNC: { 974static int meyeioc_stillcapt(void)
1080 int *i = arg; 975{
1081 int unused; 976 if (!meye.grab_fbuffer)
977 return -EINVAL;
1082 978
1083 if (*i < 0 || *i >= gbuffers) 979 if (meye.grab_buffer[0].state != MEYE_BUF_UNUSED)
1084 return -EINVAL; 980 return -EBUSY;
1085 981
1086 mutex_lock(&meye.lock); 982 mutex_lock(&meye.lock);
1087 switch (meye.grab_buffer[*i].state) { 983 meye.grab_buffer[0].state = MEYE_BUF_USING;
984 mchip_take_picture();
1088 985
1089 case MEYE_BUF_UNUSED: 986 mchip_get_picture(meye.grab_fbuffer,
1090 mutex_unlock(&meye.lock); 987 mchip_hsize() * mchip_vsize() * 2);
1091 return -EINVAL;
1092 case MEYE_BUF_USING:
1093 if (file->f_flags & O_NONBLOCK) {
1094 mutex_unlock(&meye.lock);
1095 return -EAGAIN;
1096 }
1097 if (wait_event_interruptible(meye.proc_list,
1098 (meye.grab_buffer[*i].state != MEYE_BUF_USING))) {
1099 mutex_unlock(&meye.lock);
1100 return -EINTR;
1101 }
1102 /* fall through */
1103 case MEYE_BUF_DONE:
1104 meye.grab_buffer[*i].state = MEYE_BUF_UNUSED;
1105 kfifo_get(meye.doneq, (unsigned char *)&unused, sizeof(int));
1106 }
1107 *i = meye.grab_buffer[*i].size;
1108 mutex_unlock(&meye.lock);
1109 break;
1110 }
1111 988
1112 case MEYEIOC_STILLCAPT: { 989 meye.grab_buffer[0].state = MEYE_BUF_DONE;
990 mutex_unlock(&meye.lock);
1113 991
1114 if (!meye.grab_fbuffer) 992 return 0;
1115 return -EINVAL; 993}
1116 if (meye.grab_buffer[0].state != MEYE_BUF_UNUSED) 994
1117 return -EBUSY; 995static int meyeioc_stilljcapt(int *len)
1118 mutex_lock(&meye.lock); 996{
1119 meye.grab_buffer[0].state = MEYE_BUF_USING; 997 if (!meye.grab_fbuffer)
998 return -EINVAL;
999
1000 if (meye.grab_buffer[0].state != MEYE_BUF_UNUSED)
1001 return -EBUSY;
1002
1003 mutex_lock(&meye.lock);
1004 meye.grab_buffer[0].state = MEYE_BUF_USING;
1005 *len = -1;
1006
1007 while (*len == -1) {
1120 mchip_take_picture(); 1008 mchip_take_picture();
1121 mchip_get_picture( 1009 *len = mchip_compress_frame(meye.grab_fbuffer, gbufsize);
1122 meye.grab_fbuffer,
1123 mchip_hsize() * mchip_vsize() * 2);
1124 meye.grab_buffer[0].state = MEYE_BUF_DONE;
1125 mutex_unlock(&meye.lock);
1126 break;
1127 } 1010 }
1128 1011
1129 case MEYEIOC_STILLJCAPT: { 1012 meye.grab_buffer[0].state = MEYE_BUF_DONE;
1130 int *len = arg; 1013 mutex_unlock(&meye.lock);
1131 1014 return 0;
1132 if (!meye.grab_fbuffer) 1015}
1133 return -EINVAL;
1134 if (meye.grab_buffer[0].state != MEYE_BUF_UNUSED)
1135 return -EBUSY;
1136 mutex_lock(&meye.lock);
1137 meye.grab_buffer[0].state = MEYE_BUF_USING;
1138 *len = -1;
1139 while (*len == -1) {
1140 mchip_take_picture();
1141 *len = mchip_compress_frame(meye.grab_fbuffer, gbufsize);
1142 }
1143 meye.grab_buffer[0].state = MEYE_BUF_DONE;
1144 mutex_unlock(&meye.lock);
1145 break;
1146 }
1147 1016
1148 case VIDIOC_QUERYCAP: { 1017static int vidioc_querycap(struct file *file, void *fh,
1149 struct v4l2_capability *cap = arg; 1018 struct v4l2_capability *cap)
1019{
1020 memset(cap, 0, sizeof(*cap));
1021 strcpy(cap->driver, "meye");
1022 strcpy(cap->card, "meye");
1023 sprintf(cap->bus_info, "PCI:%s", pci_name(meye.mchip_dev));
1150 1024
1151 if (forcev4l1) 1025 cap->version = (MEYE_DRIVER_MAJORVERSION << 8) +
1152 return -EINVAL; 1026 MEYE_DRIVER_MINORVERSION;
1153 1027
1154 memset(cap, 0, sizeof(*cap)); 1028 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE |
1155 strcpy(cap->driver, "meye"); 1029 V4L2_CAP_STREAMING;
1156 strcpy(cap->card, "meye"); 1030
1157 sprintf(cap->bus_info, "PCI:%s", pci_name(meye.mchip_dev)); 1031 return 0;
1158 cap->version = (MEYE_DRIVER_MAJORVERSION << 8) + 1032}
1159 MEYE_DRIVER_MINORVERSION; 1033
1160 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | 1034static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *i)
1161 V4L2_CAP_STREAMING; 1035{
1162 break; 1036 if (i->index != 0)
1163 } 1037 return -EINVAL;
1164 1038
1165 case VIDIOC_ENUMINPUT: { 1039 memset(i, 0, sizeof(*i));
1166 struct v4l2_input *i = arg; 1040 i->index = 0;
1041 strcpy(i->name, "Camera");
1042 i->type = V4L2_INPUT_TYPE_CAMERA;
1167 1043
1168 if (i->index != 0) 1044 return 0;
1169 return -EINVAL; 1045}
1170 memset(i, 0, sizeof(*i)); 1046
1171 i->index = 0; 1047static int vidioc_g_input(struct file *file, void *fh, unsigned int *i)
1172 strcpy(i->name, "Camera"); 1048{
1173 i->type = V4L2_INPUT_TYPE_CAMERA; 1049 *i = 0;
1050 return 0;
1051}
1052
1053static int vidioc_s_input(struct file *file, void *fh, unsigned int i)
1054{
1055 if (i != 0)
1056 return -EINVAL;
1057
1058 return 0;
1059}
1060
1061static int vidioc_queryctrl(struct file *file, void *fh,
1062 struct v4l2_queryctrl *c)
1063{
1064 switch (c->id) {
1065
1066 case V4L2_CID_BRIGHTNESS:
1067 c->type = V4L2_CTRL_TYPE_INTEGER;
1068 strcpy(c->name, "Brightness");
1069 c->minimum = 0;
1070 c->maximum = 63;
1071 c->step = 1;
1072 c->default_value = 32;
1073 c->flags = 0;
1074 break;
1075 case V4L2_CID_HUE:
1076 c->type = V4L2_CTRL_TYPE_INTEGER;
1077 strcpy(c->name, "Hue");
1078 c->minimum = 0;
1079 c->maximum = 63;
1080 c->step = 1;
1081 c->default_value = 32;
1082 c->flags = 0;
1083 break;
1084 case V4L2_CID_CONTRAST:
1085 c->type = V4L2_CTRL_TYPE_INTEGER;
1086 strcpy(c->name, "Contrast");
1087 c->minimum = 0;
1088 c->maximum = 63;
1089 c->step = 1;
1090 c->default_value = 32;
1091 c->flags = 0;
1092 break;
1093 case V4L2_CID_SATURATION:
1094 c->type = V4L2_CTRL_TYPE_INTEGER;
1095 strcpy(c->name, "Saturation");
1096 c->minimum = 0;
1097 c->maximum = 63;
1098 c->step = 1;
1099 c->default_value = 32;
1100 c->flags = 0;
1101 break;
1102 case V4L2_CID_AGC:
1103 c->type = V4L2_CTRL_TYPE_INTEGER;
1104 strcpy(c->name, "Agc");
1105 c->minimum = 0;
1106 c->maximum = 63;
1107 c->step = 1;
1108 c->default_value = 48;
1109 c->flags = 0;
1174 break; 1110 break;
1111 case V4L2_CID_MEYE_SHARPNESS:
1112 case V4L2_CID_SHARPNESS:
1113 c->type = V4L2_CTRL_TYPE_INTEGER;
1114 strcpy(c->name, "Sharpness");
1115 c->minimum = 0;
1116 c->maximum = 63;
1117 c->step = 1;
1118 c->default_value = 32;
1119
1120 /* Continue to report legacy private SHARPNESS ctrl but
1121 * say it is disabled in preference to ctrl in the spec
1122 */
1123 c->flags = (c->id == V4L2_CID_SHARPNESS) ? 0 :
1124 V4L2_CTRL_FLAG_DISABLED;
1125 break;
1126 case V4L2_CID_PICTURE:
1127 c->type = V4L2_CTRL_TYPE_INTEGER;
1128 strcpy(c->name, "Picture");
1129 c->minimum = 0;
1130 c->maximum = 63;
1131 c->step = 1;
1132 c->default_value = 0;
1133 c->flags = 0;
1134 break;
1135 case V4L2_CID_JPEGQUAL:
1136 c->type = V4L2_CTRL_TYPE_INTEGER;
1137 strcpy(c->name, "JPEG quality");
1138 c->minimum = 0;
1139 c->maximum = 10;
1140 c->step = 1;
1141 c->default_value = 8;
1142 c->flags = 0;
1143 break;
1144 case V4L2_CID_FRAMERATE:
1145 c->type = V4L2_CTRL_TYPE_INTEGER;
1146 strcpy(c->name, "Framerate");
1147 c->minimum = 0;
1148 c->maximum = 31;
1149 c->step = 1;
1150 c->default_value = 0;
1151 c->flags = 0;
1152 break;
1153 default:
1154 return -EINVAL;
1175 } 1155 }
1176 1156
1177 case VIDIOC_G_INPUT: { 1157 return 0;
1178 int *i = arg; 1158}
1179 1159
1180 *i = 0; 1160static int vidioc_s_ctrl(struct file *file, void *fh, struct v4l2_control *c)
1161{
1162 mutex_lock(&meye.lock);
1163 switch (c->id) {
1164 case V4L2_CID_BRIGHTNESS:
1165 sony_pic_camera_command(
1166 SONY_PIC_COMMAND_SETCAMERABRIGHTNESS, c->value);
1167 meye.picture.brightness = c->value << 10;
1168 break;
1169 case V4L2_CID_HUE:
1170 sony_pic_camera_command(
1171 SONY_PIC_COMMAND_SETCAMERAHUE, c->value);
1172 meye.picture.hue = c->value << 10;
1173 break;
1174 case V4L2_CID_CONTRAST:
1175 sony_pic_camera_command(
1176 SONY_PIC_COMMAND_SETCAMERACONTRAST, c->value);
1177 meye.picture.contrast = c->value << 10;
1178 break;
1179 case V4L2_CID_SATURATION:
1180 sony_pic_camera_command(
1181 SONY_PIC_COMMAND_SETCAMERACOLOR, c->value);
1182 meye.picture.colour = c->value << 10;
1183 break;
1184 case V4L2_CID_AGC:
1185 sony_pic_camera_command(
1186 SONY_PIC_COMMAND_SETCAMERAAGC, c->value);
1187 meye.params.agc = c->value;
1188 break;
1189 case V4L2_CID_SHARPNESS:
1190 case V4L2_CID_MEYE_SHARPNESS:
1191 sony_pic_camera_command(
1192 SONY_PIC_COMMAND_SETCAMERASHARPNESS, c->value);
1193 meye.params.sharpness = c->value;
1194 break;
1195 case V4L2_CID_PICTURE:
1196 sony_pic_camera_command(
1197 SONY_PIC_COMMAND_SETCAMERAPICTURE, c->value);
1198 meye.params.picture = c->value;
1199 break;
1200 case V4L2_CID_JPEGQUAL:
1201 meye.params.quality = c->value;
1202 break;
1203 case V4L2_CID_FRAMERATE:
1204 meye.params.framerate = c->value;
1181 break; 1205 break;
1206 default:
1207 mutex_unlock(&meye.lock);
1208 return -EINVAL;
1182 } 1209 }
1210 mutex_unlock(&meye.lock);
1183 1211
1184 case VIDIOC_S_INPUT: { 1212 return 0;
1185 int *i = arg; 1213}
1186 1214
1187 if (*i != 0) 1215static int vidioc_g_ctrl(struct file *file, void *fh, struct v4l2_control *c)
1188 return -EINVAL; 1216{
1217 mutex_lock(&meye.lock);
1218 switch (c->id) {
1219 case V4L2_CID_BRIGHTNESS:
1220 c->value = meye.picture.brightness >> 10;
1221 break;
1222 case V4L2_CID_HUE:
1223 c->value = meye.picture.hue >> 10;
1224 break;
1225 case V4L2_CID_CONTRAST:
1226 c->value = meye.picture.contrast >> 10;
1227 break;
1228 case V4L2_CID_SATURATION:
1229 c->value = meye.picture.colour >> 10;
1230 break;
1231 case V4L2_CID_AGC:
1232 c->value = meye.params.agc;
1233 break;
1234 case V4L2_CID_SHARPNESS:
1235 case V4L2_CID_MEYE_SHARPNESS:
1236 c->value = meye.params.sharpness;
1189 break; 1237 break;
1238 case V4L2_CID_PICTURE:
1239 c->value = meye.params.picture;
1240 break;
1241 case V4L2_CID_JPEGQUAL:
1242 c->value = meye.params.quality;
1243 break;
1244 case V4L2_CID_FRAMERATE:
1245 c->value = meye.params.framerate;
1246 break;
1247 default:
1248 mutex_unlock(&meye.lock);
1249 return -EINVAL;
1190 } 1250 }
1251 mutex_unlock(&meye.lock);
1191 1252
1192 case VIDIOC_QUERYCTRL: { 1253 return 0;
1193 struct v4l2_queryctrl *c = arg; 1254}
1194 1255
1195 switch (c->id) { 1256static int vidioc_enum_fmt_cap(struct file *file, void *fh,
1257 struct v4l2_fmtdesc *f)
1258{
1259 if (f->index > 1)
1260 return -EINVAL;
1196 1261
1197 case V4L2_CID_BRIGHTNESS: 1262 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1198 c->type = V4L2_CTRL_TYPE_INTEGER; 1263 return -EINVAL;
1199 strcpy(c->name, "Brightness"); 1264
1200 c->minimum = 0; 1265 if (f->index == 0) {
1201 c->maximum = 63; 1266 /* standard YUV 422 capture */
1202 c->step = 1; 1267 memset(f, 0, sizeof(*f));
1203 c->default_value = 32; 1268 f->index = 0;
1204 c->flags = 0; 1269 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1205 break; 1270 f->flags = 0;
1206 case V4L2_CID_HUE: 1271 strcpy(f->description, "YUV422");
1207 c->type = V4L2_CTRL_TYPE_INTEGER; 1272 f->pixelformat = V4L2_PIX_FMT_YUYV;
1208 strcpy(c->name, "Hue"); 1273 } else {
1209 c->minimum = 0; 1274 /* compressed MJPEG capture */
1210 c->maximum = 63; 1275 memset(f, 0, sizeof(*f));
1211 c->step = 1; 1276 f->index = 1;
1212 c->default_value = 32; 1277 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1213 c->flags = 0; 1278 f->flags = V4L2_FMT_FLAG_COMPRESSED;
1214 break; 1279 strcpy(f->description, "MJPEG");
1215 case V4L2_CID_CONTRAST: 1280 f->pixelformat = V4L2_PIX_FMT_MJPEG;
1216 c->type = V4L2_CTRL_TYPE_INTEGER;
1217 strcpy(c->name, "Contrast");
1218 c->minimum = 0;
1219 c->maximum = 63;
1220 c->step = 1;
1221 c->default_value = 32;
1222 c->flags = 0;
1223 break;
1224 case V4L2_CID_SATURATION:
1225 c->type = V4L2_CTRL_TYPE_INTEGER;
1226 strcpy(c->name, "Saturation");
1227 c->minimum = 0;
1228 c->maximum = 63;
1229 c->step = 1;
1230 c->default_value = 32;
1231 c->flags = 0;
1232 break;
1233 case V4L2_CID_AGC:
1234 c->type = V4L2_CTRL_TYPE_INTEGER;
1235 strcpy(c->name, "Agc");
1236 c->minimum = 0;
1237 c->maximum = 63;
1238 c->step = 1;
1239 c->default_value = 48;
1240 c->flags = 0;
1241 break;
1242 case V4L2_CID_SHARPNESS:
1243 c->type = V4L2_CTRL_TYPE_INTEGER;
1244 strcpy(c->name, "Sharpness");
1245 c->minimum = 0;
1246 c->maximum = 63;
1247 c->step = 1;
1248 c->default_value = 32;
1249 c->flags = 0;
1250 break;
1251 case V4L2_CID_PICTURE:
1252 c->type = V4L2_CTRL_TYPE_INTEGER;
1253 strcpy(c->name, "Picture");
1254 c->minimum = 0;
1255 c->maximum = 63;
1256 c->step = 1;
1257 c->default_value = 0;
1258 c->flags = 0;
1259 break;
1260 case V4L2_CID_JPEGQUAL:
1261 c->type = V4L2_CTRL_TYPE_INTEGER;
1262 strcpy(c->name, "JPEG quality");
1263 c->minimum = 0;
1264 c->maximum = 10;
1265 c->step = 1;
1266 c->default_value = 8;
1267 c->flags = 0;
1268 break;
1269 case V4L2_CID_FRAMERATE:
1270 c->type = V4L2_CTRL_TYPE_INTEGER;
1271 strcpy(c->name, "Framerate");
1272 c->minimum = 0;
1273 c->maximum = 31;
1274 c->step = 1;
1275 c->default_value = 0;
1276 c->flags = 0;
1277 break;
1278 default:
1279 return -EINVAL;
1280 }
1281 break;
1282 } 1281 }
1283 1282
1284 case VIDIOC_S_CTRL: { 1283 return 0;
1285 struct v4l2_control *c = arg; 1284}
1286 1285
1287 mutex_lock(&meye.lock); 1286static int vidioc_try_fmt_cap(struct file *file, void *fh,
1288 switch (c->id) { 1287 struct v4l2_format *f)
1289 case V4L2_CID_BRIGHTNESS: 1288{
1290 sony_pic_camera_command( 1289 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1291 SONY_PIC_COMMAND_SETCAMERABRIGHTNESS, c->value); 1290 return -EINVAL;
1292 meye.picture.brightness = c->value << 10; 1291
1293 break; 1292 if (f->fmt.pix.pixelformat != V4L2_PIX_FMT_YUYV &&
1294 case V4L2_CID_HUE: 1293 f->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG)
1295 sony_pic_camera_command( 1294 return -EINVAL;
1296 SONY_PIC_COMMAND_SETCAMERAHUE, c->value); 1295
1297 meye.picture.hue = c->value << 10; 1296 if (f->fmt.pix.field != V4L2_FIELD_ANY &&
1298 break; 1297 f->fmt.pix.field != V4L2_FIELD_NONE)
1299 case V4L2_CID_CONTRAST: 1298 return -EINVAL;
1300 sony_pic_camera_command( 1299
1301 SONY_PIC_COMMAND_SETCAMERACONTRAST, c->value); 1300 f->fmt.pix.field = V4L2_FIELD_NONE;
1302 meye.picture.contrast = c->value << 10; 1301
1303 break; 1302 if (f->fmt.pix.width <= 320) {
1304 case V4L2_CID_SATURATION: 1303 f->fmt.pix.width = 320;
1305 sony_pic_camera_command( 1304 f->fmt.pix.height = 240;
1306 SONY_PIC_COMMAND_SETCAMERACOLOR, c->value); 1305 } else {
1307 meye.picture.colour = c->value << 10; 1306 f->fmt.pix.width = 640;
1308 break; 1307 f->fmt.pix.height = 480;
1309 case V4L2_CID_AGC:
1310 sony_pic_camera_command(
1311 SONY_PIC_COMMAND_SETCAMERAAGC, c->value);
1312 meye.params.agc = c->value;
1313 break;
1314 case V4L2_CID_SHARPNESS:
1315 sony_pic_camera_command(
1316 SONY_PIC_COMMAND_SETCAMERASHARPNESS, c->value);
1317 meye.params.sharpness = c->value;
1318 break;
1319 case V4L2_CID_PICTURE:
1320 sony_pic_camera_command(
1321 SONY_PIC_COMMAND_SETCAMERAPICTURE, c->value);
1322 meye.params.picture = c->value;
1323 break;
1324 case V4L2_CID_JPEGQUAL:
1325 meye.params.quality = c->value;
1326 break;
1327 case V4L2_CID_FRAMERATE:
1328 meye.params.framerate = c->value;
1329 break;
1330 default:
1331 mutex_unlock(&meye.lock);
1332 return -EINVAL;
1333 }
1334 mutex_unlock(&meye.lock);
1335 break;
1336 } 1308 }
1337 1309
1338 case VIDIOC_G_CTRL: { 1310 f->fmt.pix.bytesperline = f->fmt.pix.width * 2;
1339 struct v4l2_control *c = arg; 1311 f->fmt.pix.sizeimage = f->fmt.pix.height *
1312 f->fmt.pix.bytesperline;
1313 f->fmt.pix.colorspace = 0;
1314 f->fmt.pix.priv = 0;
1340 1315
1341 mutex_lock(&meye.lock); 1316 return 0;
1342 switch (c->id) { 1317}
1343 case V4L2_CID_BRIGHTNESS: 1318
1344 c->value = meye.picture.brightness >> 10; 1319static int vidioc_g_fmt_cap(struct file *file, void *fh, struct v4l2_format *f)
1345 break; 1320{
1346 case V4L2_CID_HUE: 1321 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1347 c->value = meye.picture.hue >> 10; 1322 return -EINVAL;
1348 break; 1323
1349 case V4L2_CID_CONTRAST: 1324 memset(&f->fmt.pix, 0, sizeof(struct v4l2_pix_format));
1350 c->value = meye.picture.contrast >> 10; 1325 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1351 break; 1326
1352 case V4L2_CID_SATURATION: 1327 switch (meye.mchip_mode) {
1353 c->value = meye.picture.colour >> 10; 1328 case MCHIP_HIC_MODE_CONT_OUT:
1354 break; 1329 default:
1355 case V4L2_CID_AGC: 1330 f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
1356 c->value = meye.params.agc; 1331 break;
1357 break; 1332 case MCHIP_HIC_MODE_CONT_COMP:
1358 case V4L2_CID_SHARPNESS: 1333 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;
1359 c->value = meye.params.sharpness;
1360 break;
1361 case V4L2_CID_PICTURE:
1362 c->value = meye.params.picture;
1363 break;
1364 case V4L2_CID_JPEGQUAL:
1365 c->value = meye.params.quality;
1366 break;
1367 case V4L2_CID_FRAMERATE:
1368 c->value = meye.params.framerate;
1369 break;
1370 default:
1371 mutex_unlock(&meye.lock);
1372 return -EINVAL;
1373 }
1374 mutex_unlock(&meye.lock);
1375 break; 1334 break;
1376 } 1335 }
1377 1336
1378 case VIDIOC_ENUM_FMT: { 1337 f->fmt.pix.field = V4L2_FIELD_NONE;
1379 struct v4l2_fmtdesc *f = arg; 1338 f->fmt.pix.width = mchip_hsize();
1380 1339 f->fmt.pix.height = mchip_vsize();
1381 if (f->index > 1) 1340 f->fmt.pix.bytesperline = f->fmt.pix.width * 2;
1382 return -EINVAL; 1341 f->fmt.pix.sizeimage = f->fmt.pix.height *
1383 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1342 f->fmt.pix.bytesperline;
1384 return -EINVAL; 1343 f->fmt.pix.colorspace = 0;
1385 if (f->index == 0) { 1344 f->fmt.pix.priv = 0;
1386 /* standard YUV 422 capture */ 1345
1387 memset(f, 0, sizeof(*f)); 1346 return 0;
1388 f->index = 0; 1347}
1389 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1348
1390 f->flags = 0; 1349static int vidioc_s_fmt_cap(struct file *file, void *fh, struct v4l2_format *f)
1391 strcpy(f->description, "YUV422"); 1350{
1392 f->pixelformat = V4L2_PIX_FMT_YUYV; 1351 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1393 } else { 1352 return -EINVAL;
1394 /* compressed MJPEG capture */ 1353
1395 memset(f, 0, sizeof(*f)); 1354 if (f->fmt.pix.pixelformat != V4L2_PIX_FMT_YUYV &&
1396 f->index = 1; 1355 f->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG)
1397 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1356 return -EINVAL;
1398 f->flags = V4L2_FMT_FLAG_COMPRESSED; 1357
1399 strcpy(f->description, "MJPEG"); 1358 if (f->fmt.pix.field != V4L2_FIELD_ANY &&
1400 f->pixelformat = V4L2_PIX_FMT_MJPEG; 1359 f->fmt.pix.field != V4L2_FIELD_NONE)
1401 } 1360 return -EINVAL;
1402 break; 1361
1362 f->fmt.pix.field = V4L2_FIELD_NONE;
1363 mutex_lock(&meye.lock);
1364
1365 if (f->fmt.pix.width <= 320) {
1366 f->fmt.pix.width = 320;
1367 f->fmt.pix.height = 240;
1368 meye.params.subsample = 1;
1369 } else {
1370 f->fmt.pix.width = 640;
1371 f->fmt.pix.height = 480;
1372 meye.params.subsample = 0;
1403 } 1373 }
1404 1374
1405 case VIDIOC_TRY_FMT: { 1375 switch (f->fmt.pix.pixelformat) {
1406 struct v4l2_format *f = arg; 1376 case V4L2_PIX_FMT_YUYV:
1407 1377 meye.mchip_mode = MCHIP_HIC_MODE_CONT_OUT;
1408 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1378 break;
1409 return -EINVAL; 1379 case V4L2_PIX_FMT_MJPEG:
1410 if (f->fmt.pix.pixelformat != V4L2_PIX_FMT_YUYV && 1380 meye.mchip_mode = MCHIP_HIC_MODE_CONT_COMP;
1411 f->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG)
1412 return -EINVAL;
1413 if (f->fmt.pix.field != V4L2_FIELD_ANY &&
1414 f->fmt.pix.field != V4L2_FIELD_NONE)
1415 return -EINVAL;
1416 f->fmt.pix.field = V4L2_FIELD_NONE;
1417 if (f->fmt.pix.width <= 320) {
1418 f->fmt.pix.width = 320;
1419 f->fmt.pix.height = 240;
1420 } else {
1421 f->fmt.pix.width = 640;
1422 f->fmt.pix.height = 480;
1423 }
1424 f->fmt.pix.bytesperline = f->fmt.pix.width * 2;
1425 f->fmt.pix.sizeimage = f->fmt.pix.height *
1426 f->fmt.pix.bytesperline;
1427 f->fmt.pix.colorspace = 0;
1428 f->fmt.pix.priv = 0;
1429 break; 1381 break;
1430 } 1382 }
1431 1383
1432 case VIDIOC_G_FMT: { 1384 mutex_unlock(&meye.lock);
1433 struct v4l2_format *f = arg; 1385 f->fmt.pix.bytesperline = f->fmt.pix.width * 2;
1386 f->fmt.pix.sizeimage = f->fmt.pix.height *
1387 f->fmt.pix.bytesperline;
1388 f->fmt.pix.colorspace = 0;
1389 f->fmt.pix.priv = 0;
1434 1390
1435 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1391 return 0;
1436 return -EINVAL; 1392}
1437 memset(&f->fmt.pix, 0, sizeof(struct v4l2_pix_format));
1438 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1439 switch (meye.mchip_mode) {
1440 case MCHIP_HIC_MODE_CONT_OUT:
1441 default:
1442 f->fmt.pix.pixelformat = V4L2_PIX_FMT_YUYV;
1443 break;
1444 case MCHIP_HIC_MODE_CONT_COMP:
1445 f->fmt.pix.pixelformat = V4L2_PIX_FMT_MJPEG;
1446 break;
1447 }
1448 f->fmt.pix.field = V4L2_FIELD_NONE;
1449 f->fmt.pix.width = mchip_hsize();
1450 f->fmt.pix.height = mchip_vsize();
1451 f->fmt.pix.bytesperline = f->fmt.pix.width * 2;
1452 f->fmt.pix.sizeimage = f->fmt.pix.height *
1453 f->fmt.pix.bytesperline;
1454 f->fmt.pix.colorspace = 0;
1455 f->fmt.pix.priv = 0;
1456 break;
1457 }
1458 1393
1459 case VIDIOC_S_FMT: { 1394static int vidioc_reqbufs(struct file *file, void *fh,
1460 struct v4l2_format *f = arg; 1395 struct v4l2_requestbuffers *req)
1461 1396{
1462 if (f->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1397 int i;
1463 return -EINVAL;
1464 if (f->fmt.pix.pixelformat != V4L2_PIX_FMT_YUYV &&
1465 f->fmt.pix.pixelformat != V4L2_PIX_FMT_MJPEG)
1466 return -EINVAL;
1467 if (f->fmt.pix.field != V4L2_FIELD_ANY &&
1468 f->fmt.pix.field != V4L2_FIELD_NONE)
1469 return -EINVAL;
1470 f->fmt.pix.field = V4L2_FIELD_NONE;
1471 mutex_lock(&meye.lock);
1472 if (f->fmt.pix.width <= 320) {
1473 f->fmt.pix.width = 320;
1474 f->fmt.pix.height = 240;
1475 meye.params.subsample = 1;
1476 } else {
1477 f->fmt.pix.width = 640;
1478 f->fmt.pix.height = 480;
1479 meye.params.subsample = 0;
1480 }
1481 switch (f->fmt.pix.pixelformat) {
1482 case V4L2_PIX_FMT_YUYV:
1483 meye.mchip_mode = MCHIP_HIC_MODE_CONT_OUT;
1484 break;
1485 case V4L2_PIX_FMT_MJPEG:
1486 meye.mchip_mode = MCHIP_HIC_MODE_CONT_COMP;
1487 break;
1488 }
1489 mutex_unlock(&meye.lock);
1490 f->fmt.pix.bytesperline = f->fmt.pix.width * 2;
1491 f->fmt.pix.sizeimage = f->fmt.pix.height *
1492 f->fmt.pix.bytesperline;
1493 f->fmt.pix.colorspace = 0;
1494 f->fmt.pix.priv = 0;
1495 1398
1496 break; 1399 if (req->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1497 } 1400 return -EINVAL;
1498 1401
1499 case VIDIOC_REQBUFS: { 1402 if (req->memory != V4L2_MEMORY_MMAP)
1500 struct v4l2_requestbuffers *req = arg; 1403 return -EINVAL;
1501 int i;
1502 1404
1503 if (req->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1405 if (meye.grab_fbuffer && req->count == gbuffers) {
1504 return -EINVAL; 1406 /* already allocated, no modifications */
1505 if (req->memory != V4L2_MEMORY_MMAP) 1407 return 0;
1506 return -EINVAL;
1507 if (meye.grab_fbuffer && req->count == gbuffers) {
1508 /* already allocated, no modifications */
1509 break;
1510 }
1511 mutex_lock(&meye.lock);
1512 if (meye.grab_fbuffer) {
1513 for (i = 0; i < gbuffers; i++)
1514 if (meye.vma_use_count[i]) {
1515 mutex_unlock(&meye.lock);
1516 return -EINVAL;
1517 }
1518 rvfree(meye.grab_fbuffer, gbuffers * gbufsize);
1519 meye.grab_fbuffer = NULL;
1520 }
1521 gbuffers = max(2, min((int)req->count, MEYE_MAX_BUFNBRS));
1522 req->count = gbuffers;
1523 meye.grab_fbuffer = rvmalloc(gbuffers * gbufsize);
1524 if (!meye.grab_fbuffer) {
1525 printk(KERN_ERR "meye: v4l framebuffer allocation"
1526 " failed\n");
1527 mutex_unlock(&meye.lock);
1528 return -ENOMEM;
1529 }
1530 for (i = 0; i < gbuffers; i++)
1531 meye.vma_use_count[i] = 0;
1532 mutex_unlock(&meye.lock);
1533 break;
1534 } 1408 }
1535 1409
1536 case VIDIOC_QUERYBUF: { 1410 mutex_lock(&meye.lock);
1537 struct v4l2_buffer *buf = arg; 1411 if (meye.grab_fbuffer) {
1538 int index = buf->index; 1412 for (i = 0; i < gbuffers; i++)
1539 1413 if (meye.vma_use_count[i]) {
1540 if (index < 0 || index >= gbuffers) 1414 mutex_unlock(&meye.lock);
1541 return -EINVAL; 1415 return -EINVAL;
1542 memset(buf, 0, sizeof(*buf)); 1416 }
1543 buf->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1417 rvfree(meye.grab_fbuffer, gbuffers * gbufsize);
1544 buf->index = index; 1418 meye.grab_fbuffer = NULL;
1545 buf->bytesused = meye.grab_buffer[index].size;
1546 buf->flags = V4L2_BUF_FLAG_MAPPED;
1547 if (meye.grab_buffer[index].state == MEYE_BUF_USING)
1548 buf->flags |= V4L2_BUF_FLAG_QUEUED;
1549 if (meye.grab_buffer[index].state == MEYE_BUF_DONE)
1550 buf->flags |= V4L2_BUF_FLAG_DONE;
1551 buf->field = V4L2_FIELD_NONE;
1552 buf->timestamp = meye.grab_buffer[index].timestamp;
1553 buf->sequence = meye.grab_buffer[index].sequence;
1554 buf->memory = V4L2_MEMORY_MMAP;
1555 buf->m.offset = index * gbufsize;
1556 buf->length = gbufsize;
1557 break;
1558 } 1419 }
1559 1420
1560 case VIDIOC_QBUF: { 1421 gbuffers = max(2, min((int)req->count, MEYE_MAX_BUFNBRS));
1561 struct v4l2_buffer *buf = arg; 1422 req->count = gbuffers;
1562 1423 meye.grab_fbuffer = rvmalloc(gbuffers * gbufsize);
1563 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1424
1564 return -EINVAL; 1425 if (!meye.grab_fbuffer) {
1565 if (buf->memory != V4L2_MEMORY_MMAP) 1426 printk(KERN_ERR "meye: v4l framebuffer allocation"
1566 return -EINVAL; 1427 " failed\n");
1567 if (buf->index < 0 || buf->index >= gbuffers)
1568 return -EINVAL;
1569 if (meye.grab_buffer[buf->index].state != MEYE_BUF_UNUSED)
1570 return -EINVAL;
1571 mutex_lock(&meye.lock);
1572 buf->flags |= V4L2_BUF_FLAG_QUEUED;
1573 buf->flags &= ~V4L2_BUF_FLAG_DONE;
1574 meye.grab_buffer[buf->index].state = MEYE_BUF_USING;
1575 kfifo_put(meye.grabq, (unsigned char *)&buf->index, sizeof(int));
1576 mutex_unlock(&meye.lock); 1428 mutex_unlock(&meye.lock);
1577 break; 1429 return -ENOMEM;
1578 } 1430 }
1579 1431
1580 case VIDIOC_DQBUF: { 1432 for (i = 0; i < gbuffers; i++)
1581 struct v4l2_buffer *buf = arg; 1433 meye.vma_use_count[i] = 0;
1582 int reqnr;
1583 1434
1584 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1435 mutex_unlock(&meye.lock);
1585 return -EINVAL;
1586 if (buf->memory != V4L2_MEMORY_MMAP)
1587 return -EINVAL;
1588 1436
1589 mutex_lock(&meye.lock); 1437 return 0;
1590 if (kfifo_len(meye.doneq) == 0 && file->f_flags & O_NONBLOCK) { 1438}
1591 mutex_unlock(&meye.lock); 1439
1592 return -EAGAIN; 1440static int vidioc_querybuf(struct file *file, void *fh, struct v4l2_buffer *buf)
1593 } 1441{
1594 if (wait_event_interruptible(meye.proc_list, 1442 int index = buf->index;
1595 kfifo_len(meye.doneq) != 0) < 0) { 1443
1596 mutex_unlock(&meye.lock); 1444 if (index < 0 || index >= gbuffers)
1597 return -EINTR; 1445 return -EINVAL;
1598 } 1446
1599 if (!kfifo_get(meye.doneq, (unsigned char *)&reqnr, 1447 memset(buf, 0, sizeof(*buf));
1600 sizeof(int))) { 1448
1601 mutex_unlock(&meye.lock); 1449 buf->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1602 return -EBUSY; 1450 buf->index = index;
1603 } 1451 buf->bytesused = meye.grab_buffer[index].size;
1604 if (meye.grab_buffer[reqnr].state != MEYE_BUF_DONE) { 1452 buf->flags = V4L2_BUF_FLAG_MAPPED;
1605 mutex_unlock(&meye.lock); 1453
1606 return -EINVAL; 1454 if (meye.grab_buffer[index].state == MEYE_BUF_USING)
1607 } 1455 buf->flags |= V4L2_BUF_FLAG_QUEUED;
1608 buf->index = reqnr; 1456
1609 buf->bytesused = meye.grab_buffer[reqnr].size; 1457 if (meye.grab_buffer[index].state == MEYE_BUF_DONE)
1610 buf->flags = V4L2_BUF_FLAG_MAPPED; 1458 buf->flags |= V4L2_BUF_FLAG_DONE;
1611 buf->field = V4L2_FIELD_NONE; 1459
1612 buf->timestamp = meye.grab_buffer[reqnr].timestamp; 1460 buf->field = V4L2_FIELD_NONE;
1613 buf->sequence = meye.grab_buffer[reqnr].sequence; 1461 buf->timestamp = meye.grab_buffer[index].timestamp;
1614 buf->memory = V4L2_MEMORY_MMAP; 1462 buf->sequence = meye.grab_buffer[index].sequence;
1615 buf->m.offset = reqnr * gbufsize; 1463 buf->memory = V4L2_MEMORY_MMAP;
1616 buf->length = gbufsize; 1464 buf->m.offset = index * gbufsize;
1617 meye.grab_buffer[reqnr].state = MEYE_BUF_UNUSED; 1465 buf->length = gbufsize;
1466
1467 return 0;
1468}
1469
1470static int vidioc_qbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
1471{
1472 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1473 return -EINVAL;
1474
1475 if (buf->memory != V4L2_MEMORY_MMAP)
1476 return -EINVAL;
1477
1478 if (buf->index < 0 || buf->index >= gbuffers)
1479 return -EINVAL;
1480
1481 if (meye.grab_buffer[buf->index].state != MEYE_BUF_UNUSED)
1482 return -EINVAL;
1483
1484 mutex_lock(&meye.lock);
1485 buf->flags |= V4L2_BUF_FLAG_QUEUED;
1486 buf->flags &= ~V4L2_BUF_FLAG_DONE;
1487 meye.grab_buffer[buf->index].state = MEYE_BUF_USING;
1488 kfifo_put(meye.grabq, (unsigned char *)&buf->index, sizeof(int));
1489 mutex_unlock(&meye.lock);
1490
1491 return 0;
1492}
1493
1494static int vidioc_dqbuf(struct file *file, void *fh, struct v4l2_buffer *buf)
1495{
1496 int reqnr;
1497
1498 if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1499 return -EINVAL;
1500
1501 if (buf->memory != V4L2_MEMORY_MMAP)
1502 return -EINVAL;
1503
1504 mutex_lock(&meye.lock);
1505
1506 if (kfifo_len(meye.doneq) == 0 && file->f_flags & O_NONBLOCK) {
1618 mutex_unlock(&meye.lock); 1507 mutex_unlock(&meye.lock);
1619 break; 1508 return -EAGAIN;
1620 } 1509 }
1621 1510
1622 case VIDIOC_STREAMON: { 1511 if (wait_event_interruptible(meye.proc_list,
1623 mutex_lock(&meye.lock); 1512 kfifo_len(meye.doneq) != 0) < 0) {
1624 switch (meye.mchip_mode) {
1625 case MCHIP_HIC_MODE_CONT_OUT:
1626 mchip_continuous_start();
1627 break;
1628 case MCHIP_HIC_MODE_CONT_COMP:
1629 mchip_cont_compression_start();
1630 break;
1631 default:
1632 mutex_unlock(&meye.lock);
1633 return -EINVAL;
1634 }
1635 mutex_unlock(&meye.lock); 1513 mutex_unlock(&meye.lock);
1636 break; 1514 return -EINTR;
1637 } 1515 }
1638 1516
1639 case VIDIOC_STREAMOFF: { 1517 if (!kfifo_get(meye.doneq, (unsigned char *)&reqnr,
1640 int i; 1518 sizeof(int))) {
1519 mutex_unlock(&meye.lock);
1520 return -EBUSY;
1521 }
1641 1522
1642 mutex_lock(&meye.lock); 1523 if (meye.grab_buffer[reqnr].state != MEYE_BUF_DONE) {
1643 mchip_hic_stop();
1644 kfifo_reset(meye.grabq);
1645 kfifo_reset(meye.doneq);
1646 for (i = 0; i < MEYE_MAX_BUFNBRS; i++)
1647 meye.grab_buffer[i].state = MEYE_BUF_UNUSED;
1648 mutex_unlock(&meye.lock); 1524 mutex_unlock(&meye.lock);
1649 break; 1525 return -EINVAL;
1650 } 1526 }
1651 1527
1652 /* 1528 buf->index = reqnr;
1653 * XXX what about private snapshot ioctls ? 1529 buf->bytesused = meye.grab_buffer[reqnr].size;
1654 * Do they need to be converted to V4L2 ? 1530 buf->flags = V4L2_BUF_FLAG_MAPPED;
1655 */ 1531 buf->field = V4L2_FIELD_NONE;
1532 buf->timestamp = meye.grab_buffer[reqnr].timestamp;
1533 buf->sequence = meye.grab_buffer[reqnr].sequence;
1534 buf->memory = V4L2_MEMORY_MMAP;
1535 buf->m.offset = reqnr * gbufsize;
1536 buf->length = gbufsize;
1537 meye.grab_buffer[reqnr].state = MEYE_BUF_UNUSED;
1538 mutex_unlock(&meye.lock);
1539
1540 return 0;
1541}
1656 1542
1543static int vidioc_streamon(struct file *file, void *fh, enum v4l2_buf_type i)
1544{
1545 mutex_lock(&meye.lock);
1546
1547 switch (meye.mchip_mode) {
1548 case MCHIP_HIC_MODE_CONT_OUT:
1549 mchip_continuous_start();
1550 break;
1551 case MCHIP_HIC_MODE_CONT_COMP:
1552 mchip_cont_compression_start();
1553 break;
1657 default: 1554 default:
1658 return -ENOIOCTLCMD; 1555 mutex_unlock(&meye.lock);
1556 return -EINVAL;
1659 } 1557 }
1660 1558
1559 mutex_unlock(&meye.lock);
1560
1661 return 0; 1561 return 0;
1662} 1562}
1663 1563
1664static int meye_ioctl(struct inode *inode, struct file *file, 1564static int vidioc_streamoff(struct file *file, void *fh, enum v4l2_buf_type i)
1665 unsigned int cmd, unsigned long arg)
1666{ 1565{
1667 return video_usercopy(inode, file, cmd, arg, meye_do_ioctl); 1566 mutex_lock(&meye.lock);
1567 mchip_hic_stop();
1568 kfifo_reset(meye.grabq);
1569 kfifo_reset(meye.doneq);
1570
1571 for (i = 0; i < MEYE_MAX_BUFNBRS; i++)
1572 meye.grab_buffer[i].state = MEYE_BUF_UNUSED;
1573
1574 mutex_unlock(&meye.lock);
1575 return 0;
1576}
1577
1578static int vidioc_default(struct file *file, void *fh, int cmd, void *arg)
1579{
1580 switch (cmd) {
1581 case MEYEIOC_G_PARAMS:
1582 return meyeioc_g_params((struct meye_params *) arg);
1583
1584 case MEYEIOC_S_PARAMS:
1585 return meyeioc_s_params((struct meye_params *) arg);
1586
1587 case MEYEIOC_QBUF_CAPT:
1588 return meyeioc_qbuf_capt((int *) arg);
1589
1590 case MEYEIOC_SYNC:
1591 return meyeioc_sync(file, fh, (int *) arg);
1592
1593 case MEYEIOC_STILLCAPT:
1594 return meyeioc_stillcapt();
1595
1596 case MEYEIOC_STILLJCAPT:
1597 return meyeioc_stilljcapt((int *) arg);
1598
1599 default:
1600 return -EINVAL;
1601 }
1602
1668} 1603}
1669 1604
1670static unsigned int meye_poll(struct file *file, poll_table *wait) 1605static unsigned int meye_poll(struct file *file, poll_table *wait)
@@ -1752,8 +1687,10 @@ static const struct file_operations meye_fops = {
1752 .open = meye_open, 1687 .open = meye_open,
1753 .release = meye_release, 1688 .release = meye_release,
1754 .mmap = meye_mmap, 1689 .mmap = meye_mmap,
1755 .ioctl = meye_ioctl, 1690 .ioctl = video_ioctl2,
1691#ifdef CONFIG_COMPAT
1756 .compat_ioctl = v4l_compat_ioctl32, 1692 .compat_ioctl = v4l_compat_ioctl32,
1693#endif
1757 .poll = meye_poll, 1694 .poll = meye_poll,
1758 .llseek = no_llseek, 1695 .llseek = no_llseek,
1759}; 1696};
@@ -1765,6 +1702,24 @@ static struct video_device meye_template = {
1765 .fops = &meye_fops, 1702 .fops = &meye_fops,
1766 .release = video_device_release, 1703 .release = video_device_release,
1767 .minor = -1, 1704 .minor = -1,
1705 .vidioc_querycap = vidioc_querycap,
1706 .vidioc_enum_input = vidioc_enum_input,
1707 .vidioc_g_input = vidioc_g_input,
1708 .vidioc_s_input = vidioc_s_input,
1709 .vidioc_queryctrl = vidioc_queryctrl,
1710 .vidioc_s_ctrl = vidioc_s_ctrl,
1711 .vidioc_g_ctrl = vidioc_g_ctrl,
1712 .vidioc_enum_fmt_cap = vidioc_enum_fmt_cap,
1713 .vidioc_try_fmt_cap = vidioc_try_fmt_cap,
1714 .vidioc_g_fmt_cap = vidioc_g_fmt_cap,
1715 .vidioc_s_fmt_cap = vidioc_s_fmt_cap,
1716 .vidioc_reqbufs = vidioc_reqbufs,
1717 .vidioc_querybuf = vidioc_querybuf,
1718 .vidioc_qbuf = vidioc_qbuf,
1719 .vidioc_dqbuf = vidioc_dqbuf,
1720 .vidioc_streamon = vidioc_streamon,
1721 .vidioc_streamoff = vidioc_streamoff,
1722 .vidioc_default = vidioc_default,
1768}; 1723};
1769 1724
1770#ifdef CONFIG_PM 1725#ifdef CONFIG_PM
diff --git a/drivers/media/video/msp3400-driver.c b/drivers/media/video/msp3400-driver.c
index 7a11f3159e32..b73c740f7fb2 100644
--- a/drivers/media/video/msp3400-driver.c
+++ b/drivers/media/video/msp3400-driver.c
@@ -366,7 +366,7 @@ int msp_sleep(struct msp_state *state, int timeout)
366} 366}
367 367
368/* ------------------------------------------------------------------------ */ 368/* ------------------------------------------------------------------------ */
369#ifdef CONFIG_VIDEO_V4L1 369#ifdef CONFIG_VIDEO_ALLOW_V4L1
370static int msp_mode_v4l2_to_v4l1(int rxsubchans, int audmode) 370static int msp_mode_v4l2_to_v4l1(int rxsubchans, int audmode)
371{ 371{
372 if (rxsubchans == V4L2_TUNER_SUB_MONO) 372 if (rxsubchans == V4L2_TUNER_SUB_MONO)
@@ -514,7 +514,7 @@ static int msp_command(struct i2c_client *client, unsigned int cmd, void *arg)
514 /* --- v4l ioctls --- */ 514 /* --- v4l ioctls --- */
515 /* take care: bttv does userspace copying, we'll get a 515 /* take care: bttv does userspace copying, we'll get a
516 kernel pointer here... */ 516 kernel pointer here... */
517#ifdef CONFIG_VIDEO_V4L1 517#ifdef CONFIG_VIDEO_ALLOW_V4L1
518 case VIDIOCGAUDIO: 518 case VIDIOCGAUDIO:
519 { 519 {
520 struct video_audio *va = arg; 520 struct video_audio *va = arg;
diff --git a/drivers/media/video/msp3400-kthreads.c b/drivers/media/video/msp3400-kthreads.c
index 61ec794a737e..7f5568592793 100644
--- a/drivers/media/video/msp3400-kthreads.c
+++ b/drivers/media/video/msp3400-kthreads.c
@@ -833,11 +833,6 @@ static int msp34xxg_modus(struct i2c_client *client)
833 v4l_dbg(1, msp_debug, client, "selected radio modus\n"); 833 v4l_dbg(1, msp_debug, client, "selected radio modus\n");
834 return 0x0001; 834 return 0x0001;
835 } 835 }
836
837 if (state->v4l2_std & V4L2_STD_PAL) {
838 v4l_dbg(1, msp_debug, client, "selected PAL modus\n");
839 return 0x7001;
840 }
841 if (state->v4l2_std == V4L2_STD_NTSC_M_JP) { 836 if (state->v4l2_std == V4L2_STD_NTSC_M_JP) {
842 v4l_dbg(1, msp_debug, client, "selected M (EIA-J) modus\n"); 837 v4l_dbg(1, msp_debug, client, "selected M (EIA-J) modus\n");
843 return 0x4001; 838 return 0x4001;
@@ -846,15 +841,15 @@ static int msp34xxg_modus(struct i2c_client *client)
846 v4l_dbg(1, msp_debug, client, "selected M (A2) modus\n"); 841 v4l_dbg(1, msp_debug, client, "selected M (A2) modus\n");
847 return 0x0001; 842 return 0x0001;
848 } 843 }
844 if (state->v4l2_std == V4L2_STD_SECAM_L) {
845 v4l_dbg(1, msp_debug, client, "selected SECAM-L modus\n");
846 return 0x6001;
847 }
849 if (state->v4l2_std & V4L2_STD_MN) { 848 if (state->v4l2_std & V4L2_STD_MN) {
850 v4l_dbg(1, msp_debug, client, "selected M (BTSC) modus\n"); 849 v4l_dbg(1, msp_debug, client, "selected M (BTSC) modus\n");
851 return 0x2001; 850 return 0x2001;
852 } 851 }
853 if (state->v4l2_std & V4L2_STD_SECAM) { 852 return 0x7001;
854 v4l_dbg(1, msp_debug, client, "selected SECAM modus\n");
855 return 0x6001;
856 }
857 return 0x0001;
858} 853}
859 854
860static void msp34xxg_set_source(struct i2c_client *client, u16 reg, int in) 855static void msp34xxg_set_source(struct i2c_client *client, u16 reg, int in)
diff --git a/drivers/media/video/mt20xx.c b/drivers/media/video/mt20xx.c
index 74fd6a01d4c4..fbcb28233737 100644
--- a/drivers/media/video/mt20xx.c
+++ b/drivers/media/video/mt20xx.c
@@ -10,12 +10,10 @@
10#include "tuner-i2c.h" 10#include "tuner-i2c.h"
11#include "mt20xx.h" 11#include "mt20xx.h"
12 12
13static int debug = 0; 13static int debug;
14module_param(debug, int, 0644); 14module_param(debug, int, 0644);
15MODULE_PARM_DESC(debug, "enable verbose debug messages"); 15MODULE_PARM_DESC(debug, "enable verbose debug messages");
16 16
17#define PREFIX "mt20xx"
18
19/* ---------------------------------------------------------------------- */ 17/* ---------------------------------------------------------------------- */
20 18
21static unsigned int optimize_vco = 1; 19static unsigned int optimize_vco = 1;
@@ -24,7 +22,7 @@ module_param(optimize_vco, int, 0644);
24static unsigned int tv_antenna = 1; 22static unsigned int tv_antenna = 1;
25module_param(tv_antenna, int, 0644); 23module_param(tv_antenna, int, 0644);
26 24
27static unsigned int radio_antenna = 0; 25static unsigned int radio_antenna;
28module_param(radio_antenna, int, 0644); 26module_param(radio_antenna, int, 0644);
29 27
30/* ---------------------------------------------------------------------- */ 28/* ---------------------------------------------------------------------- */
@@ -611,6 +609,7 @@ struct dvb_frontend *microtune_attach(struct dvb_frontend *fe,
611 609
612 priv->i2c_props.addr = i2c_addr; 610 priv->i2c_props.addr = i2c_addr;
613 priv->i2c_props.adap = i2c_adap; 611 priv->i2c_props.adap = i2c_adap;
612 priv->i2c_props.name = "mt20xx";
614 613
615 //priv->radio_if2 = 10700 * 1000; /* 10.7MHz - FM radio */ 614 //priv->radio_if2 = 10700 * 1000; /* 10.7MHz - FM radio */
616 615
diff --git a/drivers/media/video/mt20xx.h b/drivers/media/video/mt20xx.h
index 5e9c825d2e91..aa848e14ce5e 100644
--- a/drivers/media/video/mt20xx.h
+++ b/drivers/media/video/mt20xx.h
@@ -29,7 +29,7 @@ static inline struct dvb_frontend *microtune_attach(struct dvb_frontend *fe,
29 struct i2c_adapter* i2c_adap, 29 struct i2c_adapter* i2c_adap,
30 u8 i2c_addr) 30 u8 i2c_addr)
31{ 31{
32 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 32 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
33 return NULL; 33 return NULL;
34} 34}
35#endif 35#endif
diff --git a/drivers/media/video/mt9m001.c b/drivers/media/video/mt9m001.c
new file mode 100644
index 000000000000..3fb5f63df1e6
--- /dev/null
+++ b/drivers/media/video/mt9m001.c
@@ -0,0 +1,722 @@
1/*
2 * Driver for MT9M001 CMOS Image Sensor from Micron
3 *
4 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/videodev2.h>
12#include <linux/slab.h>
13#include <linux/i2c.h>
14#include <linux/log2.h>
15
16#include <media/v4l2-common.h>
17#include <media/v4l2-chip-ident.h>
18#include <media/soc_camera.h>
19
20#ifdef CONFIG_MT9M001_PCA9536_SWITCH
21#include <asm/gpio.h>
22#endif
23
24/* mt9m001 i2c address 0x5d
25 * The platform has to define i2c_board_info
26 * and call i2c_register_board_info() */
27
28/* mt9m001 selected register addresses */
29#define MT9M001_CHIP_VERSION 0x00
30#define MT9M001_ROW_START 0x01
31#define MT9M001_COLUMN_START 0x02
32#define MT9M001_WINDOW_HEIGHT 0x03
33#define MT9M001_WINDOW_WIDTH 0x04
34#define MT9M001_HORIZONTAL_BLANKING 0x05
35#define MT9M001_VERTICAL_BLANKING 0x06
36#define MT9M001_OUTPUT_CONTROL 0x07
37#define MT9M001_SHUTTER_WIDTH 0x09
38#define MT9M001_FRAME_RESTART 0x0b
39#define MT9M001_SHUTTER_DELAY 0x0c
40#define MT9M001_RESET 0x0d
41#define MT9M001_READ_OPTIONS1 0x1e
42#define MT9M001_READ_OPTIONS2 0x20
43#define MT9M001_GLOBAL_GAIN 0x35
44#define MT9M001_CHIP_ENABLE 0xF1
45
46static const struct soc_camera_data_format mt9m001_colour_formats[] = {
47 /* Order important: first natively supported,
48 * second supported with a GPIO extender */
49 {
50 .name = "Bayer (sRGB) 10 bit",
51 .depth = 10,
52 .fourcc = V4L2_PIX_FMT_SBGGR16,
53 .colorspace = V4L2_COLORSPACE_SRGB,
54 }, {
55 .name = "Bayer (sRGB) 8 bit",
56 .depth = 8,
57 .fourcc = V4L2_PIX_FMT_SBGGR8,
58 .colorspace = V4L2_COLORSPACE_SRGB,
59 }
60};
61
62static const struct soc_camera_data_format mt9m001_monochrome_formats[] = {
63 /* Order important - see above */
64 {
65 .name = "Monochrome 10 bit",
66 .depth = 10,
67 .fourcc = V4L2_PIX_FMT_Y16,
68 }, {
69 .name = "Monochrome 8 bit",
70 .depth = 8,
71 .fourcc = V4L2_PIX_FMT_GREY,
72 },
73};
74
75struct mt9m001 {
76 struct i2c_client *client;
77 struct soc_camera_device icd;
78 int model; /* V4L2_IDENT_MT9M001* codes from v4l2-chip-ident.h */
79 int switch_gpio;
80 unsigned char autoexposure;
81 unsigned char datawidth;
82};
83
84static int reg_read(struct soc_camera_device *icd, const u8 reg)
85{
86 struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
87 struct i2c_client *client = mt9m001->client;
88 s32 data = i2c_smbus_read_word_data(client, reg);
89 return data < 0 ? data : swab16(data);
90}
91
92static int reg_write(struct soc_camera_device *icd, const u8 reg,
93 const u16 data)
94{
95 struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
96 return i2c_smbus_write_word_data(mt9m001->client, reg, swab16(data));
97}
98
99static int reg_set(struct soc_camera_device *icd, const u8 reg,
100 const u16 data)
101{
102 int ret;
103
104 ret = reg_read(icd, reg);
105 if (ret < 0)
106 return ret;
107 return reg_write(icd, reg, ret | data);
108}
109
110static int reg_clear(struct soc_camera_device *icd, const u8 reg,
111 const u16 data)
112{
113 int ret;
114
115 ret = reg_read(icd, reg);
116 if (ret < 0)
117 return ret;
118 return reg_write(icd, reg, ret & ~data);
119}
120
121static int mt9m001_init(struct soc_camera_device *icd)
122{
123 int ret;
124
125 /* Disable chip, synchronous option update */
126 dev_dbg(icd->vdev->dev, "%s\n", __func__);
127
128 ret = reg_write(icd, MT9M001_RESET, 1);
129 if (ret >= 0)
130 ret = reg_write(icd, MT9M001_RESET, 0);
131 if (ret >= 0)
132 ret = reg_write(icd, MT9M001_OUTPUT_CONTROL, 0);
133
134 return ret >= 0 ? 0 : -EIO;
135}
136
137static int mt9m001_release(struct soc_camera_device *icd)
138{
139 /* Disable the chip */
140 reg_write(icd, MT9M001_OUTPUT_CONTROL, 0);
141 return 0;
142}
143
144static int mt9m001_start_capture(struct soc_camera_device *icd)
145{
146 /* Switch to master "normal" mode */
147 if (reg_write(icd, MT9M001_OUTPUT_CONTROL, 2) < 0)
148 return -EIO;
149 return 0;
150}
151
152static int mt9m001_stop_capture(struct soc_camera_device *icd)
153{
154 /* Stop sensor readout */
155 if (reg_write(icd, MT9M001_OUTPUT_CONTROL, 0) < 0)
156 return -EIO;
157 return 0;
158}
159
160static int bus_switch_request(struct mt9m001 *mt9m001,
161 struct soc_camera_link *icl)
162{
163#ifdef CONFIG_MT9M001_PCA9536_SWITCH
164 int ret;
165 unsigned int gpio = icl->gpio;
166
167 if (gpio_is_valid(gpio)) {
168 /* We have a data bus switch. */
169 ret = gpio_request(gpio, "mt9m001");
170 if (ret < 0) {
171 dev_err(&mt9m001->client->dev, "Cannot get GPIO %u\n",
172 gpio);
173 return ret;
174 }
175
176 ret = gpio_direction_output(gpio, 0);
177 if (ret < 0) {
178 dev_err(&mt9m001->client->dev,
179 "Cannot set GPIO %u to output\n", gpio);
180 gpio_free(gpio);
181 return ret;
182 }
183 }
184
185 mt9m001->switch_gpio = gpio;
186#else
187 mt9m001->switch_gpio = -EINVAL;
188#endif
189 return 0;
190}
191
192static void bus_switch_release(struct mt9m001 *mt9m001)
193{
194#ifdef CONFIG_MT9M001_PCA9536_SWITCH
195 if (gpio_is_valid(mt9m001->switch_gpio))
196 gpio_free(mt9m001->switch_gpio);
197#endif
198}
199
200static int bus_switch_act(struct mt9m001 *mt9m001, int go8bit)
201{
202#ifdef CONFIG_MT9M001_PCA9536_SWITCH
203 if (!gpio_is_valid(mt9m001->switch_gpio))
204 return -ENODEV;
205
206 gpio_set_value_cansleep(mt9m001->switch_gpio, go8bit);
207 return 0;
208#else
209 return -ENODEV;
210#endif
211}
212
213static int bus_switch_possible(struct mt9m001 *mt9m001)
214{
215#ifdef CONFIG_MT9M001_PCA9536_SWITCH
216 return gpio_is_valid(mt9m001->switch_gpio);
217#else
218 return 0;
219#endif
220}
221
222static int mt9m001_set_bus_param(struct soc_camera_device *icd,
223 unsigned long flags)
224{
225 struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
226 unsigned int width_flag = flags & SOCAM_DATAWIDTH_MASK;
227 int ret;
228
229 /* Flags validity verified in test_bus_param */
230
231 if ((mt9m001->datawidth != 10 && (width_flag == SOCAM_DATAWIDTH_10)) ||
232 (mt9m001->datawidth != 9 && (width_flag == SOCAM_DATAWIDTH_9)) ||
233 (mt9m001->datawidth != 8 && (width_flag == SOCAM_DATAWIDTH_8))) {
234 /* Well, we actually only can do 10 or 8 bits... */
235 if (width_flag == SOCAM_DATAWIDTH_9)
236 return -EINVAL;
237 ret = bus_switch_act(mt9m001,
238 width_flag == SOCAM_DATAWIDTH_8);
239 if (ret < 0)
240 return ret;
241
242 mt9m001->datawidth = width_flag == SOCAM_DATAWIDTH_8 ? 8 : 10;
243 }
244
245 return 0;
246}
247
248static unsigned long mt9m001_query_bus_param(struct soc_camera_device *icd)
249{
250 struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
251 unsigned int width_flag = SOCAM_DATAWIDTH_10;
252
253 if (bus_switch_possible(mt9m001))
254 width_flag |= SOCAM_DATAWIDTH_8;
255
256 /* MT9M001 has all capture_format parameters fixed */
257 return SOCAM_PCLK_SAMPLE_RISING |
258 SOCAM_HSYNC_ACTIVE_HIGH |
259 SOCAM_VSYNC_ACTIVE_HIGH |
260 SOCAM_MASTER |
261 width_flag;
262}
263
264static int mt9m001_set_fmt_cap(struct soc_camera_device *icd,
265 __u32 pixfmt, struct v4l2_rect *rect)
266{
267 struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
268 int ret;
269 const u16 hblank = 9, vblank = 25;
270
271 /* Blanking and start values - default... */
272 ret = reg_write(icd, MT9M001_HORIZONTAL_BLANKING, hblank);
273 if (ret >= 0)
274 ret = reg_write(icd, MT9M001_VERTICAL_BLANKING, vblank);
275
276 /* The caller provides a supported format, as verified per
277 * call to icd->try_fmt_cap() */
278 if (ret >= 0)
279 ret = reg_write(icd, MT9M001_COLUMN_START, rect->left);
280 if (ret >= 0)
281 ret = reg_write(icd, MT9M001_ROW_START, rect->top);
282 if (ret >= 0)
283 ret = reg_write(icd, MT9M001_WINDOW_WIDTH, rect->width - 1);
284 if (ret >= 0)
285 ret = reg_write(icd, MT9M001_WINDOW_HEIGHT,
286 rect->height + icd->y_skip_top - 1);
287 if (ret >= 0 && mt9m001->autoexposure) {
288 ret = reg_write(icd, MT9M001_SHUTTER_WIDTH,
289 rect->height + icd->y_skip_top + vblank);
290 if (ret >= 0) {
291 const struct v4l2_queryctrl *qctrl =
292 soc_camera_find_qctrl(icd->ops,
293 V4L2_CID_EXPOSURE);
294 icd->exposure = (524 + (rect->height + icd->y_skip_top +
295 vblank - 1) *
296 (qctrl->maximum - qctrl->minimum)) /
297 1048 + qctrl->minimum;
298 }
299 }
300
301 return ret < 0 ? ret : 0;
302}
303
304static int mt9m001_try_fmt_cap(struct soc_camera_device *icd,
305 struct v4l2_format *f)
306{
307 if (f->fmt.pix.height < 32 + icd->y_skip_top)
308 f->fmt.pix.height = 32 + icd->y_skip_top;
309 if (f->fmt.pix.height > 1024 + icd->y_skip_top)
310 f->fmt.pix.height = 1024 + icd->y_skip_top;
311 if (f->fmt.pix.width < 48)
312 f->fmt.pix.width = 48;
313 if (f->fmt.pix.width > 1280)
314 f->fmt.pix.width = 1280;
315 f->fmt.pix.width &= ~0x01; /* has to be even, unsure why was ~3 */
316
317 return 0;
318}
319
320static int mt9m001_get_chip_id(struct soc_camera_device *icd,
321 struct v4l2_chip_ident *id)
322{
323 struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
324
325 if (id->match_type != V4L2_CHIP_MATCH_I2C_ADDR)
326 return -EINVAL;
327
328 if (id->match_chip != mt9m001->client->addr)
329 return -ENODEV;
330
331 id->ident = mt9m001->model;
332 id->revision = 0;
333
334 return 0;
335}
336
337#ifdef CONFIG_VIDEO_ADV_DEBUG
338static int mt9m001_get_register(struct soc_camera_device *icd,
339 struct v4l2_register *reg)
340{
341 struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
342
343 if (reg->match_type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff)
344 return -EINVAL;
345
346 if (reg->match_chip != mt9m001->client->addr)
347 return -ENODEV;
348
349 reg->val = reg_read(icd, reg->reg);
350
351 if (reg->val > 0xffff)
352 return -EIO;
353
354 return 0;
355}
356
357static int mt9m001_set_register(struct soc_camera_device *icd,
358 struct v4l2_register *reg)
359{
360 struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
361
362 if (reg->match_type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff)
363 return -EINVAL;
364
365 if (reg->match_chip != mt9m001->client->addr)
366 return -ENODEV;
367
368 if (reg_write(icd, reg->reg, reg->val) < 0)
369 return -EIO;
370
371 return 0;
372}
373#endif
374
375const struct v4l2_queryctrl mt9m001_controls[] = {
376 {
377 .id = V4L2_CID_VFLIP,
378 .type = V4L2_CTRL_TYPE_BOOLEAN,
379 .name = "Flip Vertically",
380 .minimum = 0,
381 .maximum = 1,
382 .step = 1,
383 .default_value = 0,
384 }, {
385 .id = V4L2_CID_GAIN,
386 .type = V4L2_CTRL_TYPE_INTEGER,
387 .name = "Gain",
388 .minimum = 0,
389 .maximum = 127,
390 .step = 1,
391 .default_value = 64,
392 .flags = V4L2_CTRL_FLAG_SLIDER,
393 }, {
394 .id = V4L2_CID_EXPOSURE,
395 .type = V4L2_CTRL_TYPE_INTEGER,
396 .name = "Exposure",
397 .minimum = 1,
398 .maximum = 255,
399 .step = 1,
400 .default_value = 255,
401 .flags = V4L2_CTRL_FLAG_SLIDER,
402 }, {
403 .id = V4L2_CID_EXPOSURE_AUTO,
404 .type = V4L2_CTRL_TYPE_BOOLEAN,
405 .name = "Automatic Exposure",
406 .minimum = 0,
407 .maximum = 1,
408 .step = 1,
409 .default_value = 1,
410 }
411};
412
413static int mt9m001_video_probe(struct soc_camera_device *);
414static void mt9m001_video_remove(struct soc_camera_device *);
415static int mt9m001_get_control(struct soc_camera_device *, struct v4l2_control *);
416static int mt9m001_set_control(struct soc_camera_device *, struct v4l2_control *);
417
418static struct soc_camera_ops mt9m001_ops = {
419 .owner = THIS_MODULE,
420 .probe = mt9m001_video_probe,
421 .remove = mt9m001_video_remove,
422 .init = mt9m001_init,
423 .release = mt9m001_release,
424 .start_capture = mt9m001_start_capture,
425 .stop_capture = mt9m001_stop_capture,
426 .set_fmt_cap = mt9m001_set_fmt_cap,
427 .try_fmt_cap = mt9m001_try_fmt_cap,
428 .set_bus_param = mt9m001_set_bus_param,
429 .query_bus_param = mt9m001_query_bus_param,
430 .controls = mt9m001_controls,
431 .num_controls = ARRAY_SIZE(mt9m001_controls),
432 .get_control = mt9m001_get_control,
433 .set_control = mt9m001_set_control,
434 .get_chip_id = mt9m001_get_chip_id,
435#ifdef CONFIG_VIDEO_ADV_DEBUG
436 .get_register = mt9m001_get_register,
437 .set_register = mt9m001_set_register,
438#endif
439};
440
441static int mt9m001_get_control(struct soc_camera_device *icd, struct v4l2_control *ctrl)
442{
443 struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
444 int data;
445
446 switch (ctrl->id) {
447 case V4L2_CID_VFLIP:
448 data = reg_read(icd, MT9M001_READ_OPTIONS2);
449 if (data < 0)
450 return -EIO;
451 ctrl->value = !!(data & 0x8000);
452 break;
453 case V4L2_CID_EXPOSURE_AUTO:
454 ctrl->value = mt9m001->autoexposure;
455 break;
456 }
457 return 0;
458}
459
460static int mt9m001_set_control(struct soc_camera_device *icd, struct v4l2_control *ctrl)
461{
462 struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
463 const struct v4l2_queryctrl *qctrl;
464 int data;
465
466 qctrl = soc_camera_find_qctrl(&mt9m001_ops, ctrl->id);
467
468 if (!qctrl)
469 return -EINVAL;
470
471 switch (ctrl->id) {
472 case V4L2_CID_VFLIP:
473 if (ctrl->value)
474 data = reg_set(icd, MT9M001_READ_OPTIONS2, 0x8000);
475 else
476 data = reg_clear(icd, MT9M001_READ_OPTIONS2, 0x8000);
477 if (data < 0)
478 return -EIO;
479 break;
480 case V4L2_CID_GAIN:
481 if (ctrl->value > qctrl->maximum || ctrl->value < qctrl->minimum)
482 return -EINVAL;
483 /* See Datasheet Table 7, Gain settings. */
484 if (ctrl->value <= qctrl->default_value) {
485 /* Pack it into 0..1 step 0.125, register values 0..8 */
486 unsigned long range = qctrl->default_value - qctrl->minimum;
487 data = ((ctrl->value - qctrl->minimum) * 8 + range / 2) / range;
488
489 dev_dbg(&icd->dev, "Setting gain %d\n", data);
490 data = reg_write(icd, MT9M001_GLOBAL_GAIN, data);
491 if (data < 0)
492 return -EIO;
493 } else {
494 /* Pack it into 1.125..15 variable step, register values 9..67 */
495 /* We assume qctrl->maximum - qctrl->default_value - 1 > 0 */
496 unsigned long range = qctrl->maximum - qctrl->default_value - 1;
497 unsigned long gain = ((ctrl->value - qctrl->default_value - 1) *
498 111 + range / 2) / range + 9;
499
500 if (gain <= 32)
501 data = gain;
502 else if (gain <= 64)
503 data = ((gain - 32) * 16 + 16) / 32 + 80;
504 else
505 data = ((gain - 64) * 7 + 28) / 56 + 96;
506
507 dev_dbg(&icd->dev, "Setting gain from %d to %d\n",
508 reg_read(icd, MT9M001_GLOBAL_GAIN), data);
509 data = reg_write(icd, MT9M001_GLOBAL_GAIN, data);
510 if (data < 0)
511 return -EIO;
512 }
513
514 /* Success */
515 icd->gain = ctrl->value;
516 break;
517 case V4L2_CID_EXPOSURE:
518 /* mt9m001 has maximum == default */
519 if (ctrl->value > qctrl->maximum || ctrl->value < qctrl->minimum)
520 return -EINVAL;
521 else {
522 unsigned long range = qctrl->maximum - qctrl->minimum;
523 unsigned long shutter = ((ctrl->value - qctrl->minimum) * 1048 +
524 range / 2) / range + 1;
525
526 dev_dbg(&icd->dev, "Setting shutter width from %d to %lu\n",
527 reg_read(icd, MT9M001_SHUTTER_WIDTH), shutter);
528 if (reg_write(icd, MT9M001_SHUTTER_WIDTH, shutter) < 0)
529 return -EIO;
530 icd->exposure = ctrl->value;
531 mt9m001->autoexposure = 0;
532 }
533 break;
534 case V4L2_CID_EXPOSURE_AUTO:
535 if (ctrl->value) {
536 const u16 vblank = 25;
537 if (reg_write(icd, MT9M001_SHUTTER_WIDTH, icd->height +
538 icd->y_skip_top + vblank) < 0)
539 return -EIO;
540 qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_EXPOSURE);
541 icd->exposure = (524 + (icd->height + icd->y_skip_top + vblank - 1) *
542 (qctrl->maximum - qctrl->minimum)) /
543 1048 + qctrl->minimum;
544 mt9m001->autoexposure = 1;
545 } else
546 mt9m001->autoexposure = 0;
547 break;
548 }
549 return 0;
550}
551
552/* Interface active, can use i2c. If it fails, it can indeed mean, that
553 * this wasn't our capture interface, so, we wait for the right one */
554static int mt9m001_video_probe(struct soc_camera_device *icd)
555{
556 struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
557 s32 data;
558 int ret;
559
560 /* We must have a parent by now. And it cannot be a wrong one.
561 * So this entire test is completely redundant. */
562 if (!icd->dev.parent ||
563 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
564 return -ENODEV;
565
566 /* Enable the chip */
567 data = reg_write(&mt9m001->icd, MT9M001_CHIP_ENABLE, 1);
568 dev_dbg(&icd->dev, "write: %d\n", data);
569
570 /* Read out the chip version register */
571 data = reg_read(icd, MT9M001_CHIP_VERSION);
572
573 /* must be 0x8411 or 0x8421 for colour sensor and 8431 for bw */
574 switch (data) {
575 case 0x8411:
576 case 0x8421:
577 mt9m001->model = V4L2_IDENT_MT9M001C12ST;
578 icd->formats = mt9m001_colour_formats;
579 if (mt9m001->client->dev.platform_data)
580 icd->num_formats = ARRAY_SIZE(mt9m001_colour_formats);
581 else
582 icd->num_formats = 1;
583 break;
584 case 0x8431:
585 mt9m001->model = V4L2_IDENT_MT9M001C12STM;
586 icd->formats = mt9m001_monochrome_formats;
587 if (mt9m001->client->dev.platform_data)
588 icd->num_formats = ARRAY_SIZE(mt9m001_monochrome_formats);
589 else
590 icd->num_formats = 1;
591 break;
592 default:
593 ret = -ENODEV;
594 dev_err(&icd->dev,
595 "No MT9M001 chip detected, register read %x\n", data);
596 goto ei2c;
597 }
598
599 dev_info(&icd->dev, "Detected a MT9M001 chip ID %x (%s)\n", data,
600 data == 0x8431 ? "C12STM" : "C12ST");
601
602 /* Now that we know the model, we can start video */
603 ret = soc_camera_video_start(icd);
604 if (ret)
605 goto eisis;
606
607 return 0;
608
609eisis:
610ei2c:
611 return ret;
612}
613
614static void mt9m001_video_remove(struct soc_camera_device *icd)
615{
616 struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
617
618 dev_dbg(&icd->dev, "Video %x removed: %p, %p\n", mt9m001->client->addr,
619 mt9m001->icd.dev.parent, mt9m001->icd.vdev);
620 soc_camera_video_stop(&mt9m001->icd);
621}
622
623static int mt9m001_probe(struct i2c_client *client)
624{
625 struct mt9m001 *mt9m001;
626 struct soc_camera_device *icd;
627 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
628 struct soc_camera_link *icl = client->dev.platform_data;
629 int ret;
630
631 if (!icl) {
632 dev_err(&client->dev, "MT9M001 driver needs platform data\n");
633 return -EINVAL;
634 }
635
636 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) {
637 dev_warn(&adapter->dev,
638 "I2C-Adapter doesn't support I2C_FUNC_SMBUS_WORD\n");
639 return -EIO;
640 }
641
642 mt9m001 = kzalloc(sizeof(struct mt9m001), GFP_KERNEL);
643 if (!mt9m001)
644 return -ENOMEM;
645
646 mt9m001->client = client;
647 i2c_set_clientdata(client, mt9m001);
648
649 /* Second stage probe - when a capture adapter is there */
650 icd = &mt9m001->icd;
651 icd->ops = &mt9m001_ops;
652 icd->control = &client->dev;
653 icd->x_min = 20;
654 icd->y_min = 12;
655 icd->x_current = 20;
656 icd->y_current = 12;
657 icd->width_min = 48;
658 icd->width_max = 1280;
659 icd->height_min = 32;
660 icd->height_max = 1024;
661 icd->y_skip_top = 1;
662 icd->iface = icl->bus_id;
663 /* Default datawidth - this is the only width this camera (normally)
664 * supports. It is only with extra logic that it can support
665 * other widths. Therefore it seems to be a sensible default. */
666 mt9m001->datawidth = 10;
667 /* Simulated autoexposure. If enabled, we calculate shutter width
668 * ourselves in the driver based on vertical blanking and frame width */
669 mt9m001->autoexposure = 1;
670
671 ret = bus_switch_request(mt9m001, icl);
672 if (ret)
673 goto eswinit;
674
675 ret = soc_camera_device_register(icd);
676 if (ret)
677 goto eisdr;
678
679 return 0;
680
681eisdr:
682 bus_switch_release(mt9m001);
683eswinit:
684 kfree(mt9m001);
685 return ret;
686}
687
688static int mt9m001_remove(struct i2c_client *client)
689{
690 struct mt9m001 *mt9m001 = i2c_get_clientdata(client);
691
692 soc_camera_device_unregister(&mt9m001->icd);
693 bus_switch_release(mt9m001);
694 kfree(mt9m001);
695
696 return 0;
697}
698
699static struct i2c_driver mt9m001_i2c_driver = {
700 .driver = {
701 .name = "mt9m001",
702 },
703 .probe = mt9m001_probe,
704 .remove = mt9m001_remove,
705};
706
707static int __init mt9m001_mod_init(void)
708{
709 return i2c_add_driver(&mt9m001_i2c_driver);
710}
711
712static void __exit mt9m001_mod_exit(void)
713{
714 i2c_del_driver(&mt9m001_i2c_driver);
715}
716
717module_init(mt9m001_mod_init);
718module_exit(mt9m001_mod_exit);
719
720MODULE_DESCRIPTION("Micron MT9M001 Camera driver");
721MODULE_AUTHOR("Guennadi Liakhovetski <kernel@pengutronix.de>");
722MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/mt9v022.c b/drivers/media/video/mt9v022.c
new file mode 100644
index 000000000000..d4b9e2744343
--- /dev/null
+++ b/drivers/media/video/mt9v022.c
@@ -0,0 +1,844 @@
1/*
2 * Driver for MT9V022 CMOS Image Sensor from Micron
3 *
4 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10
11#include <linux/videodev2.h>
12#include <linux/slab.h>
13#include <linux/i2c.h>
14#include <linux/delay.h>
15#include <linux/log2.h>
16
17#include <media/v4l2-common.h>
18#include <media/v4l2-chip-ident.h>
19#include <media/soc_camera.h>
20
21#ifdef CONFIG_MT9M001_PCA9536_SWITCH
22#include <asm/gpio.h>
23#endif
24
25/* mt9v022 i2c address 0x48, 0x4c, 0x58, 0x5c
26 * The platform has to define i2c_board_info
27 * and call i2c_register_board_info() */
28
29static char *sensor_type;
30module_param(sensor_type, charp, S_IRUGO);
31MODULE_PARM_DESC(sensor_type, "Sensor type: \"colour\" or \"monochrome\"\n");
32
33/* mt9v022 selected register addresses */
34#define MT9V022_CHIP_VERSION 0x00
35#define MT9V022_COLUMN_START 0x01
36#define MT9V022_ROW_START 0x02
37#define MT9V022_WINDOW_HEIGHT 0x03
38#define MT9V022_WINDOW_WIDTH 0x04
39#define MT9V022_HORIZONTAL_BLANKING 0x05
40#define MT9V022_VERTICAL_BLANKING 0x06
41#define MT9V022_CHIP_CONTROL 0x07
42#define MT9V022_SHUTTER_WIDTH1 0x08
43#define MT9V022_SHUTTER_WIDTH2 0x09
44#define MT9V022_SHUTTER_WIDTH_CTRL 0x0a
45#define MT9V022_TOTAL_SHUTTER_WIDTH 0x0b
46#define MT9V022_RESET 0x0c
47#define MT9V022_READ_MODE 0x0d
48#define MT9V022_MONITOR_MODE 0x0e
49#define MT9V022_PIXEL_OPERATION_MODE 0x0f
50#define MT9V022_LED_OUT_CONTROL 0x1b
51#define MT9V022_ADC_MODE_CONTROL 0x1c
52#define MT9V022_ANALOG_GAIN 0x34
53#define MT9V022_BLACK_LEVEL_CALIB_CTRL 0x47
54#define MT9V022_PIXCLK_FV_LV 0x74
55#define MT9V022_DIGITAL_TEST_PATTERN 0x7f
56#define MT9V022_AEC_AGC_ENABLE 0xAF
57#define MT9V022_MAX_TOTAL_SHUTTER_WIDTH 0xBD
58
59/* Progressive scan, master, defaults */
60#define MT9V022_CHIP_CONTROL_DEFAULT 0x188
61
62static const struct soc_camera_data_format mt9v022_colour_formats[] = {
63 /* Order important: first natively supported,
64 * second supported with a GPIO extender */
65 {
66 .name = "Bayer (sRGB) 10 bit",
67 .depth = 10,
68 .fourcc = V4L2_PIX_FMT_SBGGR16,
69 .colorspace = V4L2_COLORSPACE_SRGB,
70 }, {
71 .name = "Bayer (sRGB) 8 bit",
72 .depth = 8,
73 .fourcc = V4L2_PIX_FMT_SBGGR8,
74 .colorspace = V4L2_COLORSPACE_SRGB,
75 }
76};
77
78static const struct soc_camera_data_format mt9v022_monochrome_formats[] = {
79 /* Order important - see above */
80 {
81 .name = "Monochrome 10 bit",
82 .depth = 10,
83 .fourcc = V4L2_PIX_FMT_Y16,
84 }, {
85 .name = "Monochrome 8 bit",
86 .depth = 8,
87 .fourcc = V4L2_PIX_FMT_GREY,
88 },
89};
90
91struct mt9v022 {
92 struct i2c_client *client;
93 struct soc_camera_device icd;
94 int model; /* V4L2_IDENT_MT9M001* codes from v4l2-chip-ident.h */
95 int switch_gpio;
96 u16 chip_control;
97 unsigned char datawidth;
98};
99
100static int reg_read(struct soc_camera_device *icd, const u8 reg)
101{
102 struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
103 struct i2c_client *client = mt9v022->client;
104 s32 data = i2c_smbus_read_word_data(client, reg);
105 return data < 0 ? data : swab16(data);
106}
107
108static int reg_write(struct soc_camera_device *icd, const u8 reg,
109 const u16 data)
110{
111 struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
112 return i2c_smbus_write_word_data(mt9v022->client, reg, swab16(data));
113}
114
115static int reg_set(struct soc_camera_device *icd, const u8 reg,
116 const u16 data)
117{
118 int ret;
119
120 ret = reg_read(icd, reg);
121 if (ret < 0)
122 return ret;
123 return reg_write(icd, reg, ret | data);
124}
125
126static int reg_clear(struct soc_camera_device *icd, const u8 reg,
127 const u16 data)
128{
129 int ret;
130
131 ret = reg_read(icd, reg);
132 if (ret < 0)
133 return ret;
134 return reg_write(icd, reg, ret & ~data);
135}
136
137static int mt9v022_init(struct soc_camera_device *icd)
138{
139 struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
140 int ret;
141
142 /* Almost the default mode: master, parallel, simultaneous, and an
143 * undocumented bit 0x200, which is present in table 7, but not in 8,
144 * plus snapshot mode to disable scan for now */
145 mt9v022->chip_control |= 0x10;
146 ret = reg_write(icd, MT9V022_CHIP_CONTROL, mt9v022->chip_control);
147 if (ret >= 0)
148 reg_write(icd, MT9V022_READ_MODE, 0x300);
149
150 /* All defaults */
151 if (ret >= 0)
152 /* AEC, AGC on */
153 ret = reg_set(icd, MT9V022_AEC_AGC_ENABLE, 0x3);
154 if (ret >= 0)
155 ret = reg_write(icd, MT9V022_MAX_TOTAL_SHUTTER_WIDTH, 480);
156 if (ret >= 0)
157 /* default - auto */
158 ret = reg_clear(icd, MT9V022_BLACK_LEVEL_CALIB_CTRL, 1);
159 if (ret >= 0)
160 ret = reg_write(icd, MT9V022_DIGITAL_TEST_PATTERN, 0);
161
162 return ret >= 0 ? 0 : -EIO;
163}
164
165static int mt9v022_release(struct soc_camera_device *icd)
166{
167 /* Nothing? */
168 return 0;
169}
170
171static int mt9v022_start_capture(struct soc_camera_device *icd)
172{
173 struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
174 /* Switch to master "normal" mode */
175 mt9v022->chip_control &= ~0x10;
176 if (reg_write(icd, MT9V022_CHIP_CONTROL,
177 mt9v022->chip_control) < 0)
178 return -EIO;
179 return 0;
180}
181
182static int mt9v022_stop_capture(struct soc_camera_device *icd)
183{
184 struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
185 /* Switch to snapshot mode */
186 mt9v022->chip_control |= 0x10;
187 if (reg_write(icd, MT9V022_CHIP_CONTROL,
188 mt9v022->chip_control) < 0)
189 return -EIO;
190 return 0;
191}
192
193static int bus_switch_request(struct mt9v022 *mt9v022, struct soc_camera_link *icl)
194{
195#ifdef CONFIG_MT9V022_PCA9536_SWITCH
196 int ret;
197 unsigned int gpio = icl->gpio;
198
199 if (gpio_is_valid(gpio)) {
200 /* We have a data bus switch. */
201 ret = gpio_request(gpio, "mt9v022");
202 if (ret < 0) {
203 dev_err(&mt9v022->client->dev, "Cannot get GPIO %u\n", gpio);
204 return ret;
205 }
206
207 ret = gpio_direction_output(gpio, 0);
208 if (ret < 0) {
209 dev_err(&mt9v022->client->dev,
210 "Cannot set GPIO %u to output\n", gpio);
211 gpio_free(gpio);
212 return ret;
213 }
214 }
215
216 mt9v022->switch_gpio = gpio;
217#else
218 mt9v022->switch_gpio = -EINVAL;
219#endif
220 return 0;
221}
222
223static void bus_switch_release(struct mt9v022 *mt9v022)
224{
225#ifdef CONFIG_MT9V022_PCA9536_SWITCH
226 if (gpio_is_valid(mt9v022->switch_gpio))
227 gpio_free(mt9v022->switch_gpio);
228#endif
229}
230
231static int bus_switch_act(struct mt9v022 *mt9v022, int go8bit)
232{
233#ifdef CONFIG_MT9V022_PCA9536_SWITCH
234 if (!gpio_is_valid(mt9v022->switch_gpio))
235 return -ENODEV;
236
237 gpio_set_value_cansleep(mt9v022->switch_gpio, go8bit);
238 return 0;
239#else
240 return -ENODEV;
241#endif
242}
243
244static int bus_switch_possible(struct mt9v022 *mt9v022)
245{
246#ifdef CONFIG_MT9V022_PCA9536_SWITCH
247 return gpio_is_valid(mt9v022->switch_gpio);
248#else
249 return 0;
250#endif
251}
252
253static int mt9v022_set_bus_param(struct soc_camera_device *icd,
254 unsigned long flags)
255{
256 struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
257 unsigned int width_flag = flags & SOCAM_DATAWIDTH_MASK;
258 int ret;
259 u16 pixclk = 0;
260
261 /* Only one width bit may be set */
262 if (!is_power_of_2(width_flag))
263 return -EINVAL;
264
265 if ((mt9v022->datawidth != 10 && (width_flag == SOCAM_DATAWIDTH_10)) ||
266 (mt9v022->datawidth != 9 && (width_flag == SOCAM_DATAWIDTH_9)) ||
267 (mt9v022->datawidth != 8 && (width_flag == SOCAM_DATAWIDTH_8))) {
268 /* Well, we actually only can do 10 or 8 bits... */
269 if (width_flag == SOCAM_DATAWIDTH_9)
270 return -EINVAL;
271
272 ret = bus_switch_act(mt9v022,
273 width_flag == SOCAM_DATAWIDTH_8);
274 if (ret < 0)
275 return ret;
276
277 mt9v022->datawidth = width_flag == SOCAM_DATAWIDTH_8 ? 8 : 10;
278 }
279
280 if (flags & SOCAM_PCLK_SAMPLE_RISING)
281 pixclk |= 0x10;
282
283 if (!(flags & SOCAM_HSYNC_ACTIVE_HIGH))
284 pixclk |= 0x1;
285
286 if (!(flags & SOCAM_VSYNC_ACTIVE_HIGH))
287 pixclk |= 0x2;
288
289 ret = reg_write(icd, MT9V022_PIXCLK_FV_LV, pixclk);
290 if (ret < 0)
291 return ret;
292
293 if (!(flags & SOCAM_MASTER))
294 mt9v022->chip_control &= ~0x8;
295
296 ret = reg_write(icd, MT9V022_CHIP_CONTROL, mt9v022->chip_control);
297 if (ret < 0)
298 return ret;
299
300 dev_dbg(&icd->dev, "Calculated pixclk 0x%x, chip control 0x%x\n",
301 pixclk, mt9v022->chip_control);
302
303 return 0;
304}
305
306static unsigned long mt9v022_query_bus_param(struct soc_camera_device *icd)
307{
308 struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
309 unsigned int width_flag = SOCAM_DATAWIDTH_10;
310
311 if (bus_switch_possible(mt9v022))
312 width_flag |= SOCAM_DATAWIDTH_8;
313
314 return SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING |
315 SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW |
316 SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW |
317 SOCAM_MASTER | SOCAM_SLAVE |
318 width_flag;
319}
320
321static int mt9v022_set_fmt_cap(struct soc_camera_device *icd,
322 __u32 pixfmt, struct v4l2_rect *rect)
323{
324 struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
325 int ret;
326
327 /* The caller provides a supported format, as verified per call to
328 * icd->try_fmt_cap(), datawidth is from our supported format list */
329 switch (pixfmt) {
330 case V4L2_PIX_FMT_GREY:
331 case V4L2_PIX_FMT_Y16:
332 if (mt9v022->model != V4L2_IDENT_MT9V022IX7ATM)
333 return -EINVAL;
334 break;
335 case V4L2_PIX_FMT_SBGGR8:
336 case V4L2_PIX_FMT_SBGGR16:
337 if (mt9v022->model != V4L2_IDENT_MT9V022IX7ATC)
338 return -EINVAL;
339 break;
340 case 0:
341 /* No format change, only geometry */
342 break;
343 default:
344 return -EINVAL;
345 }
346
347 /* Like in example app. Contradicts the datasheet though */
348 ret = reg_read(icd, MT9V022_AEC_AGC_ENABLE);
349 if (ret >= 0) {
350 if (ret & 1) /* Autoexposure */
351 ret = reg_write(icd, MT9V022_MAX_TOTAL_SHUTTER_WIDTH,
352 rect->height + icd->y_skip_top + 43);
353 else
354 ret = reg_write(icd, MT9V022_TOTAL_SHUTTER_WIDTH,
355 rect->height + icd->y_skip_top + 43);
356 }
357 /* Setup frame format: defaults apart from width and height */
358 if (ret >= 0)
359 ret = reg_write(icd, MT9V022_COLUMN_START, rect->left);
360 if (ret >= 0)
361 ret = reg_write(icd, MT9V022_ROW_START, rect->top);
362 if (ret >= 0)
363 /* Default 94, Phytec driver says:
364 * "width + horizontal blank >= 660" */
365 ret = reg_write(icd, MT9V022_HORIZONTAL_BLANKING,
366 rect->width > 660 - 43 ? 43 :
367 660 - rect->width);
368 if (ret >= 0)
369 ret = reg_write(icd, MT9V022_VERTICAL_BLANKING, 45);
370 if (ret >= 0)
371 ret = reg_write(icd, MT9V022_WINDOW_WIDTH, rect->width);
372 if (ret >= 0)
373 ret = reg_write(icd, MT9V022_WINDOW_HEIGHT,
374 rect->height + icd->y_skip_top);
375
376 if (ret < 0)
377 return ret;
378
379 dev_dbg(&icd->dev, "Frame %ux%u pixel\n", rect->width, rect->height);
380
381 return 0;
382}
383
384static int mt9v022_try_fmt_cap(struct soc_camera_device *icd,
385 struct v4l2_format *f)
386{
387 if (f->fmt.pix.height < 32 + icd->y_skip_top)
388 f->fmt.pix.height = 32 + icd->y_skip_top;
389 if (f->fmt.pix.height > 480 + icd->y_skip_top)
390 f->fmt.pix.height = 480 + icd->y_skip_top;
391 if (f->fmt.pix.width < 48)
392 f->fmt.pix.width = 48;
393 if (f->fmt.pix.width > 752)
394 f->fmt.pix.width = 752;
395 f->fmt.pix.width &= ~0x03; /* ? */
396
397 return 0;
398}
399
400static int mt9v022_get_chip_id(struct soc_camera_device *icd,
401 struct v4l2_chip_ident *id)
402{
403 struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
404
405 if (id->match_type != V4L2_CHIP_MATCH_I2C_ADDR)
406 return -EINVAL;
407
408 if (id->match_chip != mt9v022->client->addr)
409 return -ENODEV;
410
411 id->ident = mt9v022->model;
412 id->revision = 0;
413
414 return 0;
415}
416
417#ifdef CONFIG_VIDEO_ADV_DEBUG
418static int mt9v022_get_register(struct soc_camera_device *icd,
419 struct v4l2_register *reg)
420{
421 struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
422
423 if (reg->match_type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff)
424 return -EINVAL;
425
426 if (reg->match_chip != mt9v022->client->addr)
427 return -ENODEV;
428
429 reg->val = reg_read(icd, reg->reg);
430
431 if (reg->val > 0xffff)
432 return -EIO;
433
434 return 0;
435}
436
437static int mt9v022_set_register(struct soc_camera_device *icd,
438 struct v4l2_register *reg)
439{
440 struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
441
442 if (reg->match_type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0xff)
443 return -EINVAL;
444
445 if (reg->match_chip != mt9v022->client->addr)
446 return -ENODEV;
447
448 if (reg_write(icd, reg->reg, reg->val) < 0)
449 return -EIO;
450
451 return 0;
452}
453#endif
454
455const struct v4l2_queryctrl mt9v022_controls[] = {
456 {
457 .id = V4L2_CID_VFLIP,
458 .type = V4L2_CTRL_TYPE_BOOLEAN,
459 .name = "Flip Vertically",
460 .minimum = 0,
461 .maximum = 1,
462 .step = 1,
463 .default_value = 0,
464 }, {
465 .id = V4L2_CID_HFLIP,
466 .type = V4L2_CTRL_TYPE_BOOLEAN,
467 .name = "Flip Horizontally",
468 .minimum = 0,
469 .maximum = 1,
470 .step = 1,
471 .default_value = 0,
472 }, {
473 .id = V4L2_CID_GAIN,
474 .type = V4L2_CTRL_TYPE_INTEGER,
475 .name = "Analog Gain",
476 .minimum = 64,
477 .maximum = 127,
478 .step = 1,
479 .default_value = 64,
480 .flags = V4L2_CTRL_FLAG_SLIDER,
481 }, {
482 .id = V4L2_CID_EXPOSURE,
483 .type = V4L2_CTRL_TYPE_INTEGER,
484 .name = "Exposure",
485 .minimum = 1,
486 .maximum = 255,
487 .step = 1,
488 .default_value = 255,
489 .flags = V4L2_CTRL_FLAG_SLIDER,
490 }, {
491 .id = V4L2_CID_AUTOGAIN,
492 .type = V4L2_CTRL_TYPE_BOOLEAN,
493 .name = "Automatic Gain",
494 .minimum = 0,
495 .maximum = 1,
496 .step = 1,
497 .default_value = 1,
498 }, {
499 .id = V4L2_CID_EXPOSURE_AUTO,
500 .type = V4L2_CTRL_TYPE_BOOLEAN,
501 .name = "Automatic Exposure",
502 .minimum = 0,
503 .maximum = 1,
504 .step = 1,
505 .default_value = 1,
506 }
507};
508
509static int mt9v022_video_probe(struct soc_camera_device *);
510static void mt9v022_video_remove(struct soc_camera_device *);
511static int mt9v022_get_control(struct soc_camera_device *, struct v4l2_control *);
512static int mt9v022_set_control(struct soc_camera_device *, struct v4l2_control *);
513
514static struct soc_camera_ops mt9v022_ops = {
515 .owner = THIS_MODULE,
516 .probe = mt9v022_video_probe,
517 .remove = mt9v022_video_remove,
518 .init = mt9v022_init,
519 .release = mt9v022_release,
520 .start_capture = mt9v022_start_capture,
521 .stop_capture = mt9v022_stop_capture,
522 .set_fmt_cap = mt9v022_set_fmt_cap,
523 .try_fmt_cap = mt9v022_try_fmt_cap,
524 .set_bus_param = mt9v022_set_bus_param,
525 .query_bus_param = mt9v022_query_bus_param,
526 .controls = mt9v022_controls,
527 .num_controls = ARRAY_SIZE(mt9v022_controls),
528 .get_control = mt9v022_get_control,
529 .set_control = mt9v022_set_control,
530 .get_chip_id = mt9v022_get_chip_id,
531#ifdef CONFIG_VIDEO_ADV_DEBUG
532 .get_register = mt9v022_get_register,
533 .set_register = mt9v022_set_register,
534#endif
535};
536
537static int mt9v022_get_control(struct soc_camera_device *icd,
538 struct v4l2_control *ctrl)
539{
540 int data;
541
542 switch (ctrl->id) {
543 case V4L2_CID_VFLIP:
544 data = reg_read(icd, MT9V022_READ_MODE);
545 if (data < 0)
546 return -EIO;
547 ctrl->value = !!(data & 0x10);
548 break;
549 case V4L2_CID_HFLIP:
550 data = reg_read(icd, MT9V022_READ_MODE);
551 if (data < 0)
552 return -EIO;
553 ctrl->value = !!(data & 0x20);
554 break;
555 case V4L2_CID_EXPOSURE_AUTO:
556 data = reg_read(icd, MT9V022_AEC_AGC_ENABLE);
557 if (data < 0)
558 return -EIO;
559 ctrl->value = !!(data & 0x1);
560 break;
561 case V4L2_CID_AUTOGAIN:
562 data = reg_read(icd, MT9V022_AEC_AGC_ENABLE);
563 if (data < 0)
564 return -EIO;
565 ctrl->value = !!(data & 0x2);
566 break;
567 }
568 return 0;
569}
570
571static int mt9v022_set_control(struct soc_camera_device *icd,
572 struct v4l2_control *ctrl)
573{
574 int data;
575 const struct v4l2_queryctrl *qctrl;
576
577 qctrl = soc_camera_find_qctrl(&mt9v022_ops, ctrl->id);
578
579 if (!qctrl)
580 return -EINVAL;
581
582 switch (ctrl->id) {
583 case V4L2_CID_VFLIP:
584 if (ctrl->value)
585 data = reg_set(icd, MT9V022_READ_MODE, 0x10);
586 else
587 data = reg_clear(icd, MT9V022_READ_MODE, 0x10);
588 if (data < 0)
589 return -EIO;
590 break;
591 case V4L2_CID_HFLIP:
592 if (ctrl->value)
593 data = reg_set(icd, MT9V022_READ_MODE, 0x20);
594 else
595 data = reg_clear(icd, MT9V022_READ_MODE, 0x20);
596 if (data < 0)
597 return -EIO;
598 break;
599 case V4L2_CID_GAIN:
600 /* mt9v022 has minimum == default */
601 if (ctrl->value > qctrl->maximum || ctrl->value < qctrl->minimum)
602 return -EINVAL;
603 else {
604 unsigned long range = qctrl->maximum - qctrl->minimum;
605 /* Datasheet says 16 to 64. autogain only works properly
606 * after setting gain to maximum 14. Larger values
607 * produce "white fly" noise effect. On the whole,
608 * manually setting analog gain does no good. */
609 unsigned long gain = ((ctrl->value - qctrl->minimum) *
610 10 + range / 2) / range + 4;
611 if (gain >= 32)
612 gain &= ~1;
613 /* The user wants to set gain manually, hope, she
614 * knows, what she's doing... Switch AGC off. */
615
616 if (reg_clear(icd, MT9V022_AEC_AGC_ENABLE, 0x2) < 0)
617 return -EIO;
618
619 dev_info(&icd->dev, "Setting gain from %d to %lu\n",
620 reg_read(icd, MT9V022_ANALOG_GAIN), gain);
621 if (reg_write(icd, MT9V022_ANALOG_GAIN, gain) < 0)
622 return -EIO;
623 icd->gain = ctrl->value;
624 }
625 break;
626 case V4L2_CID_EXPOSURE:
627 /* mt9v022 has maximum == default */
628 if (ctrl->value > qctrl->maximum || ctrl->value < qctrl->minimum)
629 return -EINVAL;
630 else {
631 unsigned long range = qctrl->maximum - qctrl->minimum;
632 unsigned long shutter = ((ctrl->value - qctrl->minimum) *
633 479 + range / 2) / range + 1;
634 /* The user wants to set shutter width manually, hope,
635 * she knows, what she's doing... Switch AEC off. */
636
637 if (reg_clear(icd, MT9V022_AEC_AGC_ENABLE, 0x1) < 0)
638 return -EIO;
639
640 dev_dbg(&icd->dev, "Shutter width from %d to %lu\n",
641 reg_read(icd, MT9V022_TOTAL_SHUTTER_WIDTH),
642 shutter);
643 if (reg_write(icd, MT9V022_TOTAL_SHUTTER_WIDTH,
644 shutter) < 0)
645 return -EIO;
646 icd->exposure = ctrl->value;
647 }
648 break;
649 case V4L2_CID_AUTOGAIN:
650 if (ctrl->value)
651 data = reg_set(icd, MT9V022_AEC_AGC_ENABLE, 0x2);
652 else
653 data = reg_clear(icd, MT9V022_AEC_AGC_ENABLE, 0x2);
654 if (data < 0)
655 return -EIO;
656 break;
657 case V4L2_CID_EXPOSURE_AUTO:
658 if (ctrl->value)
659 data = reg_set(icd, MT9V022_AEC_AGC_ENABLE, 0x1);
660 else
661 data = reg_clear(icd, MT9V022_AEC_AGC_ENABLE, 0x1);
662 if (data < 0)
663 return -EIO;
664 break;
665 }
666 return 0;
667}
668
669/* Interface active, can use i2c. If it fails, it can indeed mean, that
670 * this wasn't our capture interface, so, we wait for the right one */
671static int mt9v022_video_probe(struct soc_camera_device *icd)
672{
673 struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
674 s32 data;
675 int ret;
676
677 if (!icd->dev.parent ||
678 to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
679 return -ENODEV;
680
681 /* Read out the chip version register */
682 data = reg_read(icd, MT9V022_CHIP_VERSION);
683
684 /* must be 0x1311 or 0x1313 */
685 if (data != 0x1311 && data != 0x1313) {
686 ret = -ENODEV;
687 dev_info(&icd->dev, "No MT9V022 detected, ID register 0x%x\n",
688 data);
689 goto ei2c;
690 }
691
692 /* Soft reset */
693 ret = reg_write(icd, MT9V022_RESET, 1);
694 if (ret < 0)
695 goto ei2c;
696 /* 15 clock cycles */
697 udelay(200);
698 if (reg_read(icd, MT9V022_RESET)) {
699 dev_err(&icd->dev, "Resetting MT9V022 failed!\n");
700 goto ei2c;
701 }
702
703 /* Set monochrome or colour sensor type */
704 if (sensor_type && (!strcmp("colour", sensor_type) ||
705 !strcmp("color", sensor_type))) {
706 ret = reg_write(icd, MT9V022_PIXEL_OPERATION_MODE, 4 | 0x11);
707 mt9v022->model = V4L2_IDENT_MT9V022IX7ATC;
708 icd->formats = mt9v022_colour_formats;
709 if (mt9v022->client->dev.platform_data)
710 icd->num_formats = ARRAY_SIZE(mt9v022_colour_formats);
711 else
712 icd->num_formats = 1;
713 } else {
714 ret = reg_write(icd, MT9V022_PIXEL_OPERATION_MODE, 0x11);
715 mt9v022->model = V4L2_IDENT_MT9V022IX7ATM;
716 icd->formats = mt9v022_monochrome_formats;
717 if (mt9v022->client->dev.platform_data)
718 icd->num_formats = ARRAY_SIZE(mt9v022_monochrome_formats);
719 else
720 icd->num_formats = 1;
721 }
722
723 if (ret >= 0)
724 ret = soc_camera_video_start(icd);
725 if (ret < 0)
726 goto eisis;
727
728 dev_info(&icd->dev, "Detected a MT9V022 chip ID %x, %s sensor\n",
729 data, mt9v022->model == V4L2_IDENT_MT9V022IX7ATM ?
730 "monochrome" : "colour");
731
732 return 0;
733
734eisis:
735ei2c:
736 return ret;
737}
738
739static void mt9v022_video_remove(struct soc_camera_device *icd)
740{
741 struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
742
743 dev_dbg(&icd->dev, "Video %x removed: %p, %p\n", mt9v022->client->addr,
744 mt9v022->icd.dev.parent, mt9v022->icd.vdev);
745 soc_camera_video_stop(&mt9v022->icd);
746}
747
748static int mt9v022_probe(struct i2c_client *client)
749{
750 struct mt9v022 *mt9v022;
751 struct soc_camera_device *icd;
752 struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
753 struct soc_camera_link *icl = client->dev.platform_data;
754 int ret;
755
756 if (!icl) {
757 dev_err(&client->dev, "MT9V022 driver needs platform data\n");
758 return -EINVAL;
759 }
760
761 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) {
762 dev_warn(&adapter->dev,
763 "I2C-Adapter doesn't support I2C_FUNC_SMBUS_WORD\n");
764 return -EIO;
765 }
766
767 mt9v022 = kzalloc(sizeof(struct mt9v022), GFP_KERNEL);
768 if (!mt9v022)
769 return -ENOMEM;
770
771 mt9v022->chip_control = MT9V022_CHIP_CONTROL_DEFAULT;
772 mt9v022->client = client;
773 i2c_set_clientdata(client, mt9v022);
774
775 icd = &mt9v022->icd;
776 icd->ops = &mt9v022_ops;
777 icd->control = &client->dev;
778 icd->x_min = 1;
779 icd->y_min = 4;
780 icd->x_current = 1;
781 icd->y_current = 4;
782 icd->width_min = 48;
783 icd->width_max = 752;
784 icd->height_min = 32;
785 icd->height_max = 480;
786 icd->y_skip_top = 1;
787 icd->iface = icl->bus_id;
788 /* Default datawidth - this is the only width this camera (normally)
789 * supports. It is only with extra logic that it can support
790 * other widths. Therefore it seems to be a sensible default. */
791 mt9v022->datawidth = 10;
792
793 ret = bus_switch_request(mt9v022, icl);
794 if (ret)
795 goto eswinit;
796
797 ret = soc_camera_device_register(icd);
798 if (ret)
799 goto eisdr;
800
801 return 0;
802
803eisdr:
804 bus_switch_release(mt9v022);
805eswinit:
806 kfree(mt9v022);
807 return ret;
808}
809
810static int mt9v022_remove(struct i2c_client *client)
811{
812 struct mt9v022 *mt9v022 = i2c_get_clientdata(client);
813
814 soc_camera_device_unregister(&mt9v022->icd);
815 bus_switch_release(mt9v022);
816 kfree(mt9v022);
817
818 return 0;
819}
820
821static struct i2c_driver mt9v022_i2c_driver = {
822 .driver = {
823 .name = "mt9v022",
824 },
825 .probe = mt9v022_probe,
826 .remove = mt9v022_remove,
827};
828
829static int __init mt9v022_mod_init(void)
830{
831 return i2c_add_driver(&mt9v022_i2c_driver);
832}
833
834static void __exit mt9v022_mod_exit(void)
835{
836 i2c_del_driver(&mt9v022_i2c_driver);
837}
838
839module_init(mt9v022_mod_init);
840module_exit(mt9v022_mod_exit);
841
842MODULE_DESCRIPTION("Micron MT9V022 Camera driver");
843MODULE_AUTHOR("Guennadi Liakhovetski <kernel@pengutronix.de>");
844MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/mxb.c b/drivers/media/video/mxb.c
index cb5a510f9251..f68e91fbe7fb 100644
--- a/drivers/media/video/mxb.c
+++ b/drivers/media/video/mxb.c
@@ -38,7 +38,7 @@
38#define MXB_BOARD_CAN_DO_VBI(dev) (dev->revision != 0) 38#define MXB_BOARD_CAN_DO_VBI(dev) (dev->revision != 0)
39 39
40/* global variable */ 40/* global variable */
41static int mxb_num = 0; 41static int mxb_num;
42 42
43/* initial frequence the tuner will be tuned to. 43/* initial frequence the tuner will be tuned to.
44 in verden (lower saxony, germany) 4148 is a 44 in verden (lower saxony, germany) 4148 is a
@@ -47,7 +47,7 @@ static int freq = 4148;
47module_param(freq, int, 0644); 47module_param(freq, int, 0644);
48MODULE_PARM_DESC(freq, "initial frequency the tuner will be tuned to while setup"); 48MODULE_PARM_DESC(freq, "initial frequency the tuner will be tuned to while setup");
49 49
50static int debug = 0; 50static int debug;
51module_param(debug, int, 0644); 51module_param(debug, int, 0644);
52MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off)."); 52MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off).");
53 53
diff --git a/drivers/media/video/ov511.c b/drivers/media/video/ov511.c
index 6590058e8ff0..eafb0c7736e6 100644
--- a/drivers/media/video/ov511.c
+++ b/drivers/media/video/ov511.c
@@ -4659,7 +4659,9 @@ static const struct file_operations ov511_fops = {
4659 .read = ov51x_v4l1_read, 4659 .read = ov51x_v4l1_read,
4660 .mmap = ov51x_v4l1_mmap, 4660 .mmap = ov51x_v4l1_mmap,
4661 .ioctl = ov51x_v4l1_ioctl, 4661 .ioctl = ov51x_v4l1_ioctl,
4662#ifdef CONFIG_COMPAT
4662 .compat_ioctl = v4l_compat_ioctl32, 4663 .compat_ioctl = v4l_compat_ioctl32,
4664#endif
4663 .llseek = no_llseek, 4665 .llseek = no_llseek,
4664}; 4666};
4665 4667
@@ -5831,7 +5833,7 @@ ov51x_probe(struct usb_interface *intf, const struct usb_device_id *id)
5831 goto error; 5833 goto error;
5832 5834
5833 memcpy(ov->vdev, &vdev_template, sizeof(*ov->vdev)); 5835 memcpy(ov->vdev, &vdev_template, sizeof(*ov->vdev));
5834 ov->vdev->dev = &dev->dev; 5836 ov->vdev->dev = &intf->dev;
5835 video_set_drvdata(ov->vdev, ov); 5837 video_set_drvdata(ov->vdev, ov);
5836 5838
5837 for (i = 0; i < OV511_MAX_UNIT_VIDEO; i++) { 5839 for (i = 0; i < OV511_MAX_UNIT_VIDEO; i++) {
diff --git a/drivers/media/video/ov511.h b/drivers/media/video/ov511.h
index 18c64222dd11..1010e51189b7 100644
--- a/drivers/media/video/ov511.h
+++ b/drivers/media/video/ov511.h
@@ -12,7 +12,7 @@
12#ifdef OV511_DEBUG 12#ifdef OV511_DEBUG
13 #define PDEBUG(level, fmt, args...) \ 13 #define PDEBUG(level, fmt, args...) \
14 if (debug >= (level)) info("[%s:%d] " fmt, \ 14 if (debug >= (level)) info("[%s:%d] " fmt, \
15 __FUNCTION__, __LINE__ , ## args) 15 __func__, __LINE__ , ## args)
16#else 16#else
17 #define PDEBUG(level, fmt, args...) do {} while(0) 17 #define PDEBUG(level, fmt, args...) do {} while(0)
18#endif 18#endif
diff --git a/drivers/media/video/ovcamchip/ovcamchip_priv.h b/drivers/media/video/ovcamchip/ovcamchip_priv.h
index 50c7763d44b3..9afa4fe47726 100644
--- a/drivers/media/video/ovcamchip/ovcamchip_priv.h
+++ b/drivers/media/video/ovcamchip/ovcamchip_priv.h
@@ -24,11 +24,11 @@ extern int ovcamchip_debug;
24 24
25#define PDEBUG(level, fmt, args...) \ 25#define PDEBUG(level, fmt, args...) \
26 if (ovcamchip_debug >= (level)) pr_debug("[%s:%d] " fmt "\n", \ 26 if (ovcamchip_debug >= (level)) pr_debug("[%s:%d] " fmt "\n", \
27 __FUNCTION__, __LINE__ , ## args) 27 __func__, __LINE__ , ## args)
28 28
29#define DDEBUG(level, dev, fmt, args...) \ 29#define DDEBUG(level, dev, fmt, args...) \
30 if (ovcamchip_debug >= (level)) dev_dbg(dev, "[%s:%d] " fmt "\n", \ 30 if (ovcamchip_debug >= (level)) dev_dbg(dev, "[%s:%d] " fmt "\n", \
31 __FUNCTION__, __LINE__ , ## args) 31 __func__, __LINE__ , ## args)
32 32
33/* Number of times to retry chip detection. Increase this if you are getting 33/* Number of times to retry chip detection. Increase this if you are getting
34 * "Failed to init camera chip" */ 34 * "Failed to init camera chip" */
diff --git a/drivers/media/video/pms.c b/drivers/media/video/pms.c
index 6820c2aabd30..51b1461d8fb6 100644
--- a/drivers/media/video/pms.c
+++ b/drivers/media/video/pms.c
@@ -57,11 +57,11 @@ struct i2c_info
57 u8 hits; 57 u8 hits;
58}; 58};
59 59
60static int i2c_count = 0; 60static int i2c_count;
61static struct i2c_info i2cinfo[64]; 61static struct i2c_info i2cinfo[64];
62 62
63static int decoder = PHILIPS2; 63static int decoder = PHILIPS2;
64static int standard = 0; /* 0 - auto 1 - ntsc 2 - pal 3 - secam */ 64static int standard; /* 0 - auto 1 - ntsc 2 - pal 3 - secam */
65 65
66/* 66/*
67 * I/O ports and Shared Memory 67 * I/O ports and Shared Memory
@@ -885,7 +885,9 @@ static const struct file_operations pms_fops = {
885 .open = video_exclusive_open, 885 .open = video_exclusive_open,
886 .release = video_exclusive_release, 886 .release = video_exclusive_release,
887 .ioctl = pms_ioctl, 887 .ioctl = pms_ioctl,
888#ifdef CONFIG_COMPAT
888 .compat_ioctl = v4l_compat_ioctl32, 889 .compat_ioctl = v4l_compat_ioctl32,
890#endif
889 .read = pms_read, 891 .read = pms_read,
890 .llseek = no_llseek, 892 .llseek = no_llseek,
891}; 893};
diff --git a/drivers/media/video/pvrusb2/Kconfig b/drivers/media/video/pvrusb2/Kconfig
index 6fc1b8be1a1f..a8da90f69dd9 100644
--- a/drivers/media/video/pvrusb2/Kconfig
+++ b/drivers/media/video/pvrusb2/Kconfig
@@ -58,6 +58,30 @@ config VIDEO_PVRUSB2_SYSFS
58 58
59 Note: This feature is experimental and subject to change. 59 Note: This feature is experimental and subject to change.
60 60
61config VIDEO_PVRUSB2_DVB
62 bool "pvrusb2 DVB support (EXPERIMENTAL)"
63 default n
64 depends on VIDEO_PVRUSB2 && DVB_CORE && EXPERIMENTAL
65 select DVB_LGDT330X if !DVB_FE_CUSTOMISE
66 select DVB_S5H1409 if !DVB_FE_CUSTOMISE
67 select DVB_TDA10048 if !DVB_FE_CUSTOMIZE
68 select DVB_TDA18271 if !DVB_FE_CUSTOMIZE
69 select TUNER_SIMPLE if !DVB_FE_CUSTOMISE
70 select TUNER_TDA8290 if !DVB_FE_CUSTOMIZE
71 ---help---
72
73 This option enables compilation of a DVB interface for the
74 pvrusb2 driver. Currently this is very very experimental.
75 It is also limiting - the DVB interface can only access the
76 digital side of hybrid devices, and there are going to be
77 issues if you attempt to mess with the V4L side at the same
78 time. Don't turn this on unless you know what you are
79 doing.
80
81 If you are in doubt, say N.
82
83 Note: This feature is very experimental and might break
84
61config VIDEO_PVRUSB2_DEBUGIFC 85config VIDEO_PVRUSB2_DEBUGIFC
62 bool "pvrusb2 debug interface" 86 bool "pvrusb2 debug interface"
63 depends on VIDEO_PVRUSB2_SYSFS 87 depends on VIDEO_PVRUSB2_SYSFS
diff --git a/drivers/media/video/pvrusb2/Makefile b/drivers/media/video/pvrusb2/Makefile
index 47284e558648..5b3083c89aa9 100644
--- a/drivers/media/video/pvrusb2/Makefile
+++ b/drivers/media/video/pvrusb2/Makefile
@@ -1,5 +1,6 @@
1obj-pvrusb2-sysfs-$(CONFIG_VIDEO_PVRUSB2_SYSFS) := pvrusb2-sysfs.o 1obj-pvrusb2-sysfs-$(CONFIG_VIDEO_PVRUSB2_SYSFS) := pvrusb2-sysfs.o
2obj-pvrusb2-debugifc-$(CONFIG_VIDEO_PVRUSB2_DEBUGIFC) := pvrusb2-debugifc.o 2obj-pvrusb2-debugifc-$(CONFIG_VIDEO_PVRUSB2_DEBUGIFC) := pvrusb2-debugifc.o
3obj-pvrusb2-dvb-$(CONFIG_VIDEO_PVRUSB2_DVB) := pvrusb2-dvb.o
3 4
4pvrusb2-objs := pvrusb2-i2c-core.o pvrusb2-i2c-cmd-v4l2.o \ 5pvrusb2-objs := pvrusb2-i2c-core.o pvrusb2-i2c-cmd-v4l2.o \
5 pvrusb2-audio.o pvrusb2-i2c-chips-v4l2.o \ 6 pvrusb2-audio.o pvrusb2-i2c-chips-v4l2.o \
@@ -9,6 +10,11 @@ pvrusb2-objs := pvrusb2-i2c-core.o pvrusb2-i2c-cmd-v4l2.o \
9 pvrusb2-ctrl.o pvrusb2-std.o pvrusb2-devattr.o \ 10 pvrusb2-ctrl.o pvrusb2-std.o pvrusb2-devattr.o \
10 pvrusb2-context.o pvrusb2-io.o pvrusb2-ioread.o \ 11 pvrusb2-context.o pvrusb2-io.o pvrusb2-ioread.o \
11 pvrusb2-cx2584x-v4l.o pvrusb2-wm8775.o \ 12 pvrusb2-cx2584x-v4l.o pvrusb2-wm8775.o \
13 $(obj-pvrusb2-dvb-y) \
12 $(obj-pvrusb2-sysfs-y) $(obj-pvrusb2-debugifc-y) 14 $(obj-pvrusb2-sysfs-y) $(obj-pvrusb2-debugifc-y)
13 15
14obj-$(CONFIG_VIDEO_PVRUSB2) += pvrusb2.o 16obj-$(CONFIG_VIDEO_PVRUSB2) += pvrusb2.o
17
18EXTRA_CFLAGS += -Idrivers/media/video
19EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core
20EXTRA_CFLAGS += -Idrivers/media/dvb/frontends
diff --git a/drivers/media/video/pvrusb2/pvrusb2-context.c b/drivers/media/video/pvrusb2/pvrusb2-context.c
index 160437b21e6d..b5db6a5bab31 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-context.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-context.c
@@ -23,39 +23,193 @@
23#include "pvrusb2-ioread.h" 23#include "pvrusb2-ioread.h"
24#include "pvrusb2-hdw.h" 24#include "pvrusb2-hdw.h"
25#include "pvrusb2-debug.h" 25#include "pvrusb2-debug.h"
26#include <linux/wait.h>
27#include <linux/kthread.h>
26#include <linux/errno.h> 28#include <linux/errno.h>
27#include <linux/string.h> 29#include <linux/string.h>
28#include <linux/slab.h> 30#include <linux/slab.h>
29 31
32static struct pvr2_context *pvr2_context_exist_first;
33static struct pvr2_context *pvr2_context_exist_last;
34static struct pvr2_context *pvr2_context_notify_first;
35static struct pvr2_context *pvr2_context_notify_last;
36static DEFINE_MUTEX(pvr2_context_mutex);
37static DECLARE_WAIT_QUEUE_HEAD(pvr2_context_sync_data);
38static DECLARE_WAIT_QUEUE_HEAD(pvr2_context_cleanup_data);
39static int pvr2_context_cleanup_flag;
40static int pvr2_context_cleaned_flag;
41static struct task_struct *pvr2_context_thread_ptr;
42
43
44static void pvr2_context_set_notify(struct pvr2_context *mp, int fl)
45{
46 int signal_flag = 0;
47 mutex_lock(&pvr2_context_mutex);
48 if (fl) {
49 if (!mp->notify_flag) {
50 signal_flag = (pvr2_context_notify_first == NULL);
51 mp->notify_prev = pvr2_context_notify_last;
52 mp->notify_next = NULL;
53 pvr2_context_notify_last = mp;
54 if (mp->notify_prev) {
55 mp->notify_prev->notify_next = mp;
56 } else {
57 pvr2_context_notify_first = mp;
58 }
59 mp->notify_flag = !0;
60 }
61 } else {
62 if (mp->notify_flag) {
63 mp->notify_flag = 0;
64 if (mp->notify_next) {
65 mp->notify_next->notify_prev = mp->notify_prev;
66 } else {
67 pvr2_context_notify_last = mp->notify_prev;
68 }
69 if (mp->notify_prev) {
70 mp->notify_prev->notify_next = mp->notify_next;
71 } else {
72 pvr2_context_notify_first = mp->notify_next;
73 }
74 }
75 }
76 mutex_unlock(&pvr2_context_mutex);
77 if (signal_flag) wake_up(&pvr2_context_sync_data);
78}
79
30 80
31static void pvr2_context_destroy(struct pvr2_context *mp) 81static void pvr2_context_destroy(struct pvr2_context *mp)
32{ 82{
33 pvr2_trace(PVR2_TRACE_STRUCT,"Destroying pvr_main id=%p",mp); 83 pvr2_trace(PVR2_TRACE_CTXT,"pvr2_context %p (destroy)",mp);
34 if (mp->hdw) pvr2_hdw_destroy(mp->hdw); 84 if (mp->hdw) pvr2_hdw_destroy(mp->hdw);
85 pvr2_context_set_notify(mp, 0);
86 mutex_lock(&pvr2_context_mutex);
87 if (mp->exist_next) {
88 mp->exist_next->exist_prev = mp->exist_prev;
89 } else {
90 pvr2_context_exist_last = mp->exist_prev;
91 }
92 if (mp->exist_prev) {
93 mp->exist_prev->exist_next = mp->exist_next;
94 } else {
95 pvr2_context_exist_first = mp->exist_next;
96 }
97 if (!pvr2_context_exist_first) {
98 /* Trigger wakeup on control thread in case it is waiting
99 for an exit condition. */
100 wake_up(&pvr2_context_sync_data);
101 }
102 mutex_unlock(&pvr2_context_mutex);
35 kfree(mp); 103 kfree(mp);
36} 104}
37 105
38 106
39static void pvr2_context_state_check(struct pvr2_context *mp) 107static void pvr2_context_notify(struct pvr2_context *mp)
40{ 108{
41 if (mp->init_flag) return; 109 pvr2_context_set_notify(mp,!0);
110}
111
42 112
43 switch (pvr2_hdw_get_state(mp->hdw)) { 113static void pvr2_context_check(struct pvr2_context *mp)
44 case PVR2_STATE_WARM: break; 114{
45 case PVR2_STATE_ERROR: break; 115 struct pvr2_channel *ch1, *ch2;
46 case PVR2_STATE_READY: break; 116 pvr2_trace(PVR2_TRACE_CTXT,
47 case PVR2_STATE_RUN: break; 117 "pvr2_context %p (notify)", mp);
48 default: return; 118 if (!mp->initialized_flag && !mp->disconnect_flag) {
119 mp->initialized_flag = !0;
120 pvr2_trace(PVR2_TRACE_CTXT,
121 "pvr2_context %p (initialize)", mp);
122 /* Finish hardware initialization */
123 if (pvr2_hdw_initialize(mp->hdw,
124 (void (*)(void *))pvr2_context_notify,
125 mp)) {
126 mp->video_stream.stream =
127 pvr2_hdw_get_video_stream(mp->hdw);
128 /* Trigger interface initialization. By doing this
129 here initialization runs in our own safe and
130 cozy thread context. */
131 if (mp->setup_func) mp->setup_func(mp);
132 } else {
133 pvr2_trace(PVR2_TRACE_CTXT,
134 "pvr2_context %p (thread skipping setup)",
135 mp);
136 /* Even though initialization did not succeed,
137 we're still going to continue anyway. We need
138 to do this in order to await the expected
139 disconnect (which we will detect in the normal
140 course of operation). */
141 }
49 } 142 }
50 143
51 pvr2_context_enter(mp); do { 144 for (ch1 = mp->mc_first; ch1; ch1 = ch2) {
52 mp->init_flag = !0; 145 ch2 = ch1->mc_next;
53 mp->video_stream.stream = pvr2_hdw_get_video_stream(mp->hdw); 146 if (ch1->check_func) ch1->check_func(ch1);
54 if (mp->setup_func) { 147 }
55 mp->setup_func(mp); 148
149 if (mp->disconnect_flag && !mp->mc_first) {
150 /* Go away... */
151 pvr2_context_destroy(mp);
152 return;
153 }
154}
155
156
157static int pvr2_context_shutok(void)
158{
159 return pvr2_context_cleanup_flag && (pvr2_context_exist_first == NULL);
160}
161
162
163static int pvr2_context_thread_func(void *foo)
164{
165 struct pvr2_context *mp;
166
167 pvr2_trace(PVR2_TRACE_CTXT,"pvr2_context thread start");
168
169 do {
170 while ((mp = pvr2_context_notify_first) != NULL) {
171 pvr2_context_set_notify(mp, 0);
172 pvr2_context_check(mp);
56 } 173 }
57 } while (0); pvr2_context_exit(mp); 174 wait_event_interruptible(
58 } 175 pvr2_context_sync_data,
176 ((pvr2_context_notify_first != NULL) ||
177 pvr2_context_shutok()));
178 } while (!pvr2_context_shutok());
179
180 pvr2_context_cleaned_flag = !0;
181 wake_up(&pvr2_context_cleanup_data);
182
183 pvr2_trace(PVR2_TRACE_CTXT,"pvr2_context thread cleaned up");
184
185 wait_event_interruptible(
186 pvr2_context_sync_data,
187 kthread_should_stop());
188
189 pvr2_trace(PVR2_TRACE_CTXT,"pvr2_context thread end");
190
191 return 0;
192}
193
194
195int pvr2_context_global_init(void)
196{
197 pvr2_context_thread_ptr = kthread_run(pvr2_context_thread_func,
198 0,
199 "pvrusb2-context");
200 return (pvr2_context_thread_ptr ? 0 : -ENOMEM);
201}
202
203
204void pvr2_context_global_done(void)
205{
206 pvr2_context_cleanup_flag = !0;
207 wake_up(&pvr2_context_sync_data);
208 wait_event_interruptible(
209 pvr2_context_cleanup_data,
210 pvr2_context_cleaned_flag);
211 kthread_stop(pvr2_context_thread_ptr);
212}
59 213
60 214
61struct pvr2_context *pvr2_context_create( 215struct pvr2_context *pvr2_context_create(
@@ -66,67 +220,75 @@ struct pvr2_context *pvr2_context_create(
66 struct pvr2_context *mp = NULL; 220 struct pvr2_context *mp = NULL;
67 mp = kzalloc(sizeof(*mp),GFP_KERNEL); 221 mp = kzalloc(sizeof(*mp),GFP_KERNEL);
68 if (!mp) goto done; 222 if (!mp) goto done;
69 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr_main id=%p",mp); 223 pvr2_trace(PVR2_TRACE_CTXT,"pvr2_context %p (create)",mp);
70 mp->setup_func = setup_func; 224 mp->setup_func = setup_func;
71 mutex_init(&mp->mutex); 225 mutex_init(&mp->mutex);
226 mutex_lock(&pvr2_context_mutex);
227 mp->exist_prev = pvr2_context_exist_last;
228 mp->exist_next = NULL;
229 pvr2_context_exist_last = mp;
230 if (mp->exist_prev) {
231 mp->exist_prev->exist_next = mp;
232 } else {
233 pvr2_context_exist_first = mp;
234 }
235 mutex_unlock(&pvr2_context_mutex);
72 mp->hdw = pvr2_hdw_create(intf,devid); 236 mp->hdw = pvr2_hdw_create(intf,devid);
73 if (!mp->hdw) { 237 if (!mp->hdw) {
74 pvr2_context_destroy(mp); 238 pvr2_context_destroy(mp);
75 mp = NULL; 239 mp = NULL;
76 goto done; 240 goto done;
77 } 241 }
78 pvr2_hdw_set_state_callback(mp->hdw, 242 pvr2_context_set_notify(mp, !0);
79 (void (*)(void *))pvr2_context_state_check,
80 mp);
81 pvr2_context_state_check(mp);
82 done: 243 done:
83 return mp; 244 return mp;
84} 245}
85 246
86 247
87void pvr2_context_enter(struct pvr2_context *mp) 248static void pvr2_context_reset_input_limits(struct pvr2_context *mp)
249{
250 unsigned int tmsk,mmsk;
251 struct pvr2_channel *cp;
252 struct pvr2_hdw *hdw = mp->hdw;
253 mmsk = pvr2_hdw_get_input_available(hdw);
254 tmsk = mmsk;
255 for (cp = mp->mc_first; cp; cp = cp->mc_next) {
256 if (!cp->input_mask) continue;
257 tmsk &= cp->input_mask;
258 }
259 pvr2_hdw_set_input_allowed(hdw,mmsk,tmsk);
260 pvr2_hdw_commit_ctl(hdw);
261}
262
263
264static void pvr2_context_enter(struct pvr2_context *mp)
88{ 265{
89 mutex_lock(&mp->mutex); 266 mutex_lock(&mp->mutex);
90 pvr2_trace(PVR2_TRACE_CREG,"pvr2_context_enter(id=%p)",mp);
91} 267}
92 268
93 269
94void pvr2_context_exit(struct pvr2_context *mp) 270static void pvr2_context_exit(struct pvr2_context *mp)
95{ 271{
96 int destroy_flag = 0; 272 int destroy_flag = 0;
97 if (!(mp->mc_first || !mp->disconnect_flag)) { 273 if (!(mp->mc_first || !mp->disconnect_flag)) {
98 destroy_flag = !0; 274 destroy_flag = !0;
99 } 275 }
100 pvr2_trace(PVR2_TRACE_CREG,"pvr2_context_exit(id=%p) outside",mp);
101 mutex_unlock(&mp->mutex); 276 mutex_unlock(&mp->mutex);
102 if (destroy_flag) pvr2_context_destroy(mp); 277 if (destroy_flag) pvr2_context_notify(mp);
103}
104
105
106static void pvr2_context_run_checks(struct pvr2_context *mp)
107{
108 struct pvr2_channel *ch1,*ch2;
109 for (ch1 = mp->mc_first; ch1; ch1 = ch2) {
110 ch2 = ch1->mc_next;
111 if (ch1->check_func) {
112 ch1->check_func(ch1);
113 }
114 }
115} 278}
116 279
117 280
118void pvr2_context_disconnect(struct pvr2_context *mp) 281void pvr2_context_disconnect(struct pvr2_context *mp)
119{ 282{
120 pvr2_context_enter(mp); do { 283 pvr2_hdw_disconnect(mp->hdw);
121 pvr2_hdw_disconnect(mp->hdw); 284 mp->disconnect_flag = !0;
122 mp->disconnect_flag = !0; 285 pvr2_context_notify(mp);
123 pvr2_context_run_checks(mp);
124 } while (0); pvr2_context_exit(mp);
125} 286}
126 287
127 288
128void pvr2_channel_init(struct pvr2_channel *cp,struct pvr2_context *mp) 289void pvr2_channel_init(struct pvr2_channel *cp,struct pvr2_context *mp)
129{ 290{
291 pvr2_context_enter(mp);
130 cp->hdw = mp->hdw; 292 cp->hdw = mp->hdw;
131 cp->mc_head = mp; 293 cp->mc_head = mp;
132 cp->mc_next = NULL; 294 cp->mc_next = NULL;
@@ -137,6 +299,7 @@ void pvr2_channel_init(struct pvr2_channel *cp,struct pvr2_context *mp)
137 mp->mc_first = cp; 299 mp->mc_first = cp;
138 } 300 }
139 mp->mc_last = cp; 301 mp->mc_last = cp;
302 pvr2_context_exit(mp);
140} 303}
141 304
142 305
@@ -152,7 +315,10 @@ static void pvr2_channel_disclaim_stream(struct pvr2_channel *cp)
152void pvr2_channel_done(struct pvr2_channel *cp) 315void pvr2_channel_done(struct pvr2_channel *cp)
153{ 316{
154 struct pvr2_context *mp = cp->mc_head; 317 struct pvr2_context *mp = cp->mc_head;
318 pvr2_context_enter(mp);
319 cp->input_mask = 0;
155 pvr2_channel_disclaim_stream(cp); 320 pvr2_channel_disclaim_stream(cp);
321 pvr2_context_reset_input_limits(mp);
156 if (cp->mc_next) { 322 if (cp->mc_next) {
157 cp->mc_next->mc_prev = cp->mc_prev; 323 cp->mc_next->mc_prev = cp->mc_prev;
158 } else { 324 } else {
@@ -164,6 +330,58 @@ void pvr2_channel_done(struct pvr2_channel *cp)
164 mp->mc_first = cp->mc_next; 330 mp->mc_first = cp->mc_next;
165 } 331 }
166 cp->hdw = NULL; 332 cp->hdw = NULL;
333 pvr2_context_exit(mp);
334}
335
336
337int pvr2_channel_limit_inputs(struct pvr2_channel *cp,unsigned int cmsk)
338{
339 unsigned int tmsk,mmsk;
340 int ret = 0;
341 struct pvr2_channel *p2;
342 struct pvr2_hdw *hdw = cp->hdw;
343
344 mmsk = pvr2_hdw_get_input_available(hdw);
345 cmsk &= mmsk;
346 if (cmsk == cp->input_mask) {
347 /* No change; nothing to do */
348 return 0;
349 }
350
351 pvr2_context_enter(cp->mc_head);
352 do {
353 if (!cmsk) {
354 cp->input_mask = 0;
355 pvr2_context_reset_input_limits(cp->mc_head);
356 break;
357 }
358 tmsk = mmsk;
359 for (p2 = cp->mc_head->mc_first; p2; p2 = p2->mc_next) {
360 if (p2 == cp) continue;
361 if (!p2->input_mask) continue;
362 tmsk &= p2->input_mask;
363 }
364 if (!(tmsk & cmsk)) {
365 ret = -EPERM;
366 break;
367 }
368 tmsk &= cmsk;
369 if ((ret = pvr2_hdw_set_input_allowed(hdw,mmsk,tmsk)) != 0) {
370 /* Internal failure changing allowed list; probably
371 should not happen, but react if it does. */
372 break;
373 }
374 cp->input_mask = cmsk;
375 pvr2_hdw_commit_ctl(hdw);
376 } while (0);
377 pvr2_context_exit(cp->mc_head);
378 return ret;
379}
380
381
382unsigned int pvr2_channel_get_limited_inputs(struct pvr2_channel *cp)
383{
384 return cp->input_mask;
167} 385}
168 386
169 387
@@ -173,7 +391,7 @@ int pvr2_channel_claim_stream(struct pvr2_channel *cp,
173 int code = 0; 391 int code = 0;
174 pvr2_context_enter(cp->mc_head); do { 392 pvr2_context_enter(cp->mc_head); do {
175 if (sp == cp->stream) break; 393 if (sp == cp->stream) break;
176 if (sp->user) { 394 if (sp && sp->user) {
177 code = -EBUSY; 395 code = -EBUSY;
178 break; 396 break;
179 } 397 }
diff --git a/drivers/media/video/pvrusb2/pvrusb2-context.h b/drivers/media/video/pvrusb2/pvrusb2-context.h
index a04187a93225..745e270233c2 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-context.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-context.h
@@ -30,7 +30,6 @@ struct pvr2_stream; /* stream interface - defined elsewhere */
30struct pvr2_context; /* All central state */ 30struct pvr2_context; /* All central state */
31struct pvr2_channel; /* One I/O pathway to a user */ 31struct pvr2_channel; /* One I/O pathway to a user */
32struct pvr2_context_stream; /* Wrapper for a stream */ 32struct pvr2_context_stream; /* Wrapper for a stream */
33struct pvr2_crit_reg; /* Critical region pointer */
34struct pvr2_ioread; /* Low level stream structure */ 33struct pvr2_ioread; /* Low level stream structure */
35 34
36struct pvr2_context_stream { 35struct pvr2_context_stream {
@@ -41,11 +40,16 @@ struct pvr2_context_stream {
41struct pvr2_context { 40struct pvr2_context {
42 struct pvr2_channel *mc_first; 41 struct pvr2_channel *mc_first;
43 struct pvr2_channel *mc_last; 42 struct pvr2_channel *mc_last;
43 struct pvr2_context *exist_next;
44 struct pvr2_context *exist_prev;
45 struct pvr2_context *notify_next;
46 struct pvr2_context *notify_prev;
44 struct pvr2_hdw *hdw; 47 struct pvr2_hdw *hdw;
45 struct pvr2_context_stream video_stream; 48 struct pvr2_context_stream video_stream;
46 struct mutex mutex; 49 struct mutex mutex;
50 int notify_flag;
51 int initialized_flag;
47 int disconnect_flag; 52 int disconnect_flag;
48 int init_flag;
49 53
50 /* Called after pvr2_context initialization is complete */ 54 /* Called after pvr2_context initialization is complete */
51 void (*setup_func)(struct pvr2_context *); 55 void (*setup_func)(struct pvr2_context *);
@@ -58,12 +62,10 @@ struct pvr2_channel {
58 struct pvr2_channel *mc_prev; 62 struct pvr2_channel *mc_prev;
59 struct pvr2_context_stream *stream; 63 struct pvr2_context_stream *stream;
60 struct pvr2_hdw *hdw; 64 struct pvr2_hdw *hdw;
65 unsigned int input_mask;
61 void (*check_func)(struct pvr2_channel *); 66 void (*check_func)(struct pvr2_channel *);
62}; 67};
63 68
64void pvr2_context_enter(struct pvr2_context *);
65void pvr2_context_exit(struct pvr2_context *);
66
67struct pvr2_context *pvr2_context_create(struct usb_interface *intf, 69struct pvr2_context *pvr2_context_create(struct usb_interface *intf,
68 const struct usb_device_id *devid, 70 const struct usb_device_id *devid,
69 void (*setup_func)(struct pvr2_context *)); 71 void (*setup_func)(struct pvr2_context *));
@@ -71,11 +73,15 @@ void pvr2_context_disconnect(struct pvr2_context *);
71 73
72void pvr2_channel_init(struct pvr2_channel *,struct pvr2_context *); 74void pvr2_channel_init(struct pvr2_channel *,struct pvr2_context *);
73void pvr2_channel_done(struct pvr2_channel *); 75void pvr2_channel_done(struct pvr2_channel *);
76int pvr2_channel_limit_inputs(struct pvr2_channel *,unsigned int);
77unsigned int pvr2_channel_get_limited_inputs(struct pvr2_channel *);
74int pvr2_channel_claim_stream(struct pvr2_channel *, 78int pvr2_channel_claim_stream(struct pvr2_channel *,
75 struct pvr2_context_stream *); 79 struct pvr2_context_stream *);
76struct pvr2_ioread *pvr2_channel_create_mpeg_stream( 80struct pvr2_ioread *pvr2_channel_create_mpeg_stream(
77 struct pvr2_context_stream *); 81 struct pvr2_context_stream *);
78 82
83int pvr2_context_global_init(void);
84void pvr2_context_global_done(void);
79 85
80#endif /* __PVRUSB2_CONTEXT_H */ 86#endif /* __PVRUSB2_CONTEXT_H */
81/* 87/*
diff --git a/drivers/media/video/pvrusb2/pvrusb2-ctrl.c b/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
index 5a3e8d21a38a..91a42f2473a7 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-ctrl.c
@@ -30,6 +30,9 @@ static int pvr2_ctrl_range_check(struct pvr2_ctrl *cptr,int val)
30{ 30{
31 if (cptr->info->check_value) { 31 if (cptr->info->check_value) {
32 if (!cptr->info->check_value(cptr,val)) return -ERANGE; 32 if (!cptr->info->check_value(cptr,val)) return -ERANGE;
33 } else if (cptr->info->type == pvr2_ctl_enum) {
34 if (val < 0) return -ERANGE;
35 if (val >= cptr->info->def.type_enum.count) return -ERANGE;
33 } else { 36 } else {
34 int lim; 37 int lim;
35 lim = cptr->info->def.type_int.min_value; 38 lim = cptr->info->def.type_int.min_value;
@@ -63,13 +66,10 @@ int pvr2_ctrl_set_mask_value(struct pvr2_ctrl *cptr,int mask,int val)
63 if (cptr->info->set_value) { 66 if (cptr->info->set_value) {
64 if (cptr->info->type == pvr2_ctl_bitmask) { 67 if (cptr->info->type == pvr2_ctl_bitmask) {
65 mask &= cptr->info->def.type_bitmask.valid_bits; 68 mask &= cptr->info->def.type_bitmask.valid_bits;
66 } else if (cptr->info->type == pvr2_ctl_int) { 69 } else if ((cptr->info->type == pvr2_ctl_int)||
70 (cptr->info->type == pvr2_ctl_enum)) {
67 ret = pvr2_ctrl_range_check(cptr,val); 71 ret = pvr2_ctrl_range_check(cptr,val);
68 if (ret < 0) break; 72 if (ret < 0) break;
69 } else if (cptr->info->type == pvr2_ctl_enum) {
70 if (val >= cptr->info->def.type_enum.count) {
71 break;
72 }
73 } else if (cptr->info->type != pvr2_ctl_bool) { 73 } else if (cptr->info->type != pvr2_ctl_bool) {
74 break; 74 break;
75 } 75 }
@@ -204,8 +204,7 @@ int pvr2_ctrl_get_valname(struct pvr2_ctrl *cptr,int val,
204 if (cptr->info->type == pvr2_ctl_enum) { 204 if (cptr->info->type == pvr2_ctl_enum) {
205 const char **names; 205 const char **names;
206 names = cptr->info->def.type_enum.value_names; 206 names = cptr->info->def.type_enum.value_names;
207 if ((val >= 0) && 207 if (pvr2_ctrl_range_check(cptr,val) == 0) {
208 (val < cptr->info->def.type_enum.count)) {
209 if (names[val]) { 208 if (names[val]) {
210 *blen = scnprintf( 209 *blen = scnprintf(
211 bptr,bmax,"%s", 210 bptr,bmax,"%s",
@@ -528,10 +527,8 @@ int pvr2_ctrl_sym_to_value(struct pvr2_ctrl *cptr,
528 ptr,len,valptr, 527 ptr,len,valptr,
529 cptr->info->def.type_enum.value_names, 528 cptr->info->def.type_enum.value_names,
530 cptr->info->def.type_enum.count); 529 cptr->info->def.type_enum.count);
531 if ((ret >= 0) && 530 if (ret >= 0) {
532 ((*valptr < 0) || 531 ret = pvr2_ctrl_range_check(cptr,*valptr);
533 (*valptr >= cptr->info->def.type_enum.count))) {
534 ret = -ERANGE;
535 } 532 }
536 if (maskptr) *maskptr = ~0; 533 if (maskptr) *maskptr = ~0;
537 } else if (cptr->info->type == pvr2_ctl_bitmask) { 534 } else if (cptr->info->type == pvr2_ctl_bitmask) {
diff --git a/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c b/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
index ffdc45c324e5..97350b048b8d 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-cx2584x-v4l.c
@@ -84,7 +84,9 @@ static const struct routing_scheme_item routing_schemegv[] = {
84 .vid = CX25840_COMPOSITE2, 84 .vid = CX25840_COMPOSITE2,
85 .aud = CX25840_AUDIO5, 85 .aud = CX25840_AUDIO5,
86 }, 86 },
87 [PVR2_CVAL_INPUT_RADIO] = { /* Treat the same as composite */ 87 [PVR2_CVAL_INPUT_RADIO] = {
88 /* line-in is used for radio and composite. A GPIO is
89 used to switch between the two choices. */
88 .vid = CX25840_COMPOSITE1, 90 .vid = CX25840_COMPOSITE1,
89 .aud = CX25840_AUDIO_SERIAL, 91 .aud = CX25840_AUDIO_SERIAL,
90 }, 92 },
diff --git a/drivers/media/video/pvrusb2/pvrusb2-debug.h b/drivers/media/video/pvrusb2/pvrusb2-debug.h
index fca49d8a9311..11537ddf8aa3 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-debug.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-debug.h
@@ -39,7 +39,7 @@ extern int pvrusb2_debug;
39#define PVR2_TRACE_EEPROM (1 << 10) /* eeprom parsing / report */ 39#define PVR2_TRACE_EEPROM (1 << 10) /* eeprom parsing / report */
40#define PVR2_TRACE_STRUCT (1 << 11) /* internal struct creation */ 40#define PVR2_TRACE_STRUCT (1 << 11) /* internal struct creation */
41#define PVR2_TRACE_OPEN_CLOSE (1 << 12) /* application open / close */ 41#define PVR2_TRACE_OPEN_CLOSE (1 << 12) /* application open / close */
42#define PVR2_TRACE_CREG (1 << 13) /* Main critical region entry / exit */ 42#define PVR2_TRACE_CTXT (1 << 13) /* Main context tracking */
43#define PVR2_TRACE_SYSFS (1 << 14) /* Sysfs driven I/O */ 43#define PVR2_TRACE_SYSFS (1 << 14) /* Sysfs driven I/O */
44#define PVR2_TRACE_FIRMWARE (1 << 15) /* firmware upload actions */ 44#define PVR2_TRACE_FIRMWARE (1 << 15) /* firmware upload actions */
45#define PVR2_TRACE_CHIPS (1 << 16) /* chip broadcast operation */ 45#define PVR2_TRACE_CHIPS (1 << 16) /* chip broadcast operation */
diff --git a/drivers/media/video/pvrusb2/pvrusb2-debugifc.c b/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
index b0687430fdd4..b53121c78ff9 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-debugifc.c
@@ -164,6 +164,8 @@ int pvr2_debugifc_print_status(struct pvr2_hdw *hdw,
164 int ccnt; 164 int ccnt;
165 int ret; 165 int ret;
166 u32 gpio_dir,gpio_in,gpio_out; 166 u32 gpio_dir,gpio_in,gpio_out;
167 struct pvr2_stream_stats stats;
168 struct pvr2_stream *sp;
167 169
168 ret = pvr2_hdw_is_hsm(hdw); 170 ret = pvr2_hdw_is_hsm(hdw);
169 ccnt = scnprintf(buf,acnt,"USB link speed: %s\n", 171 ccnt = scnprintf(buf,acnt,"USB link speed: %s\n",
@@ -182,6 +184,24 @@ int pvr2_debugifc_print_status(struct pvr2_hdw *hdw,
182 pvr2_hdw_get_streaming(hdw) ? "on" : "off"); 184 pvr2_hdw_get_streaming(hdw) ? "on" : "off");
183 bcnt += ccnt; acnt -= ccnt; buf += ccnt; 185 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
184 186
187
188 sp = pvr2_hdw_get_video_stream(hdw);
189 if (sp) {
190 pvr2_stream_get_stats(sp, &stats, 0);
191 ccnt = scnprintf(
192 buf,acnt,
193 "Bytes streamed=%u"
194 " URBs: queued=%u idle=%u ready=%u"
195 " processed=%u failed=%u\n",
196 stats.bytes_processed,
197 stats.buffers_in_queue,
198 stats.buffers_in_idle,
199 stats.buffers_in_ready,
200 stats.buffers_processed,
201 stats.buffers_failed);
202 bcnt += ccnt; acnt -= ccnt; buf += ccnt;
203 }
204
185 return bcnt; 205 return bcnt;
186} 206}
187 207
@@ -220,6 +240,10 @@ static int pvr2_debugifc_do1cmd(struct pvr2_hdw *hdw,const char *buf,
220 return pvr2_hdw_cmd_decoder_reset(hdw); 240 return pvr2_hdw_cmd_decoder_reset(hdw);
221 } else if (debugifc_match_keyword(wptr,wlen,"worker")) { 241 } else if (debugifc_match_keyword(wptr,wlen,"worker")) {
222 return pvr2_hdw_untrip(hdw); 242 return pvr2_hdw_untrip(hdw);
243 } else if (debugifc_match_keyword(wptr,wlen,"usbstats")) {
244 pvr2_stream_get_stats(pvr2_hdw_get_video_stream(hdw),
245 NULL, !0);
246 return 0;
223 } 247 }
224 return -EINVAL; 248 return -EINVAL;
225 } else if (debugifc_match_keyword(wptr,wlen,"cpufw")) { 249 } else if (debugifc_match_keyword(wptr,wlen,"cpufw")) {
diff --git a/drivers/media/video/pvrusb2/pvrusb2-devattr.c b/drivers/media/video/pvrusb2/pvrusb2-devattr.c
index fe9991c10cf4..2dd06a90adce 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-devattr.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-devattr.c
@@ -32,7 +32,15 @@ pvr2_device_desc structures.
32/* This is needed in order to pull in tuner type ids... */ 32/* This is needed in order to pull in tuner type ids... */
33#include <linux/i2c.h> 33#include <linux/i2c.h>
34#include <media/tuner.h> 34#include <media/tuner.h>
35 35#ifdef CONFIG_VIDEO_PVRUSB2_DVB
36#include "pvrusb2-hdw-internal.h"
37#include "lgdt330x.h"
38#include "s5h1409.h"
39#include "tda10048.h"
40#include "tda18271.h"
41#include "tda8290.h"
42#include "tuner-simple.h"
43#endif
36 44
37 45
38/*------------------------------------------------------------------------*/ 46/*------------------------------------------------------------------------*/
@@ -49,14 +57,19 @@ static const char *pvr2_fw1_names_29xxx[] = {
49}; 57};
50 58
51static const struct pvr2_device_desc pvr2_device_29xxx = { 59static const struct pvr2_device_desc pvr2_device_29xxx = {
52 .description = "WinTV PVR USB2 Model Category 29xxxx", 60 .description = "WinTV PVR USB2 Model Category 29xxx",
53 .shortname = "29xxx", 61 .shortname = "29xxx",
54 .client_modules.lst = pvr2_client_29xxx, 62 .client_modules.lst = pvr2_client_29xxx,
55 .client_modules.cnt = ARRAY_SIZE(pvr2_client_29xxx), 63 .client_modules.cnt = ARRAY_SIZE(pvr2_client_29xxx),
56 .fx2_firmware.lst = pvr2_fw1_names_29xxx, 64 .fx2_firmware.lst = pvr2_fw1_names_29xxx,
57 .fx2_firmware.cnt = ARRAY_SIZE(pvr2_fw1_names_29xxx), 65 .fx2_firmware.cnt = ARRAY_SIZE(pvr2_fw1_names_29xxx),
58 .flag_has_hauppauge_rom = !0, 66 .flag_has_hauppauge_rom = !0,
67 .flag_has_analogtuner = !0,
68 .flag_has_fmradio = !0,
69 .flag_has_composite = !0,
70 .flag_has_svideo = !0,
59 .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE, 71 .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE,
72 .led_scheme = PVR2_LED_SCHEME_HAUPPAUGE,
60}; 73};
61 74
62 75
@@ -75,7 +88,7 @@ static const char *pvr2_fw1_names_24xxx[] = {
75}; 88};
76 89
77static const struct pvr2_device_desc pvr2_device_24xxx = { 90static const struct pvr2_device_desc pvr2_device_24xxx = {
78 .description = "WinTV PVR USB2 Model Category 24xxxx", 91 .description = "WinTV PVR USB2 Model Category 24xxx",
79 .shortname = "24xxx", 92 .shortname = "24xxx",
80 .client_modules.lst = pvr2_client_24xxx, 93 .client_modules.lst = pvr2_client_24xxx,
81 .client_modules.cnt = ARRAY_SIZE(pvr2_client_24xxx), 94 .client_modules.cnt = ARRAY_SIZE(pvr2_client_24xxx),
@@ -85,7 +98,12 @@ static const struct pvr2_device_desc pvr2_device_24xxx = {
85 .flag_has_wm8775 = !0, 98 .flag_has_wm8775 = !0,
86 .flag_has_hauppauge_rom = !0, 99 .flag_has_hauppauge_rom = !0,
87 .flag_has_hauppauge_custom_ir = !0, 100 .flag_has_hauppauge_custom_ir = !0,
101 .flag_has_analogtuner = !0,
102 .flag_has_fmradio = !0,
103 .flag_has_composite = !0,
104 .flag_has_svideo = !0,
88 .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE, 105 .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE,
106 .led_scheme = PVR2_LED_SCHEME_HAUPPAUGE,
89}; 107};
90 108
91 109
@@ -105,6 +123,30 @@ static const struct pvr2_device_desc pvr2_device_gotview_2 = {
105 .client_modules.cnt = ARRAY_SIZE(pvr2_client_gotview_2), 123 .client_modules.cnt = ARRAY_SIZE(pvr2_client_gotview_2),
106 .flag_has_cx25840 = !0, 124 .flag_has_cx25840 = !0,
107 .default_tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 125 .default_tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
126 .flag_has_analogtuner = !0,
127 .flag_has_fmradio = !0,
128 .flag_has_composite = !0,
129 .flag_has_svideo = !0,
130 .signal_routing_scheme = PVR2_ROUTING_SCHEME_GOTVIEW,
131};
132
133
134
135/*------------------------------------------------------------------------*/
136/* GOTVIEW USB2.0 DVD Deluxe */
137
138/* (same module list as gotview_2) */
139
140static const struct pvr2_device_desc pvr2_device_gotview_2d = {
141 .description = "Gotview USB 2.0 DVD Deluxe",
142 .shortname = "gv2d",
143 .client_modules.lst = pvr2_client_gotview_2,
144 .client_modules.cnt = ARRAY_SIZE(pvr2_client_gotview_2),
145 .flag_has_cx25840 = !0,
146 .default_tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
147 .flag_has_analogtuner = !0,
148 .flag_has_composite = !0,
149 .flag_has_svideo = !0,
108 .signal_routing_scheme = PVR2_ROUTING_SCHEME_GOTVIEW, 150 .signal_routing_scheme = PVR2_ROUTING_SCHEME_GOTVIEW,
109}; 151};
110 152
@@ -114,6 +156,38 @@ static const struct pvr2_device_desc pvr2_device_gotview_2 = {
114/*------------------------------------------------------------------------*/ 156/*------------------------------------------------------------------------*/
115/* OnAir Creator */ 157/* OnAir Creator */
116 158
159#ifdef CONFIG_VIDEO_PVRUSB2_DVB
160static struct lgdt330x_config pvr2_lgdt3303_config = {
161 .demod_address = 0x0e,
162 .demod_chip = LGDT3303,
163 .clock_polarity_flip = 1,
164};
165
166static int pvr2_lgdt3303_attach(struct pvr2_dvb_adapter *adap)
167{
168 adap->fe = dvb_attach(lgdt330x_attach, &pvr2_lgdt3303_config,
169 &adap->channel.hdw->i2c_adap);
170 if (adap->fe)
171 return 0;
172
173 return -EIO;
174}
175
176static int pvr2_lgh06xf_attach(struct pvr2_dvb_adapter *adap)
177{
178 dvb_attach(simple_tuner_attach, adap->fe,
179 &adap->channel.hdw->i2c_adap, 0x61,
180 TUNER_LG_TDVS_H06XF);
181
182 return 0;
183}
184
185struct pvr2_dvb_props pvr2_onair_creator_fe_props = {
186 .frontend_attach = pvr2_lgdt3303_attach,
187 .tuner_attach = pvr2_lgh06xf_attach,
188};
189#endif
190
117static const char *pvr2_client_onair_creator[] = { 191static const char *pvr2_client_onair_creator[] = {
118 "saa7115", 192 "saa7115",
119 "tuner", 193 "tuner",
@@ -126,7 +200,16 @@ static const struct pvr2_device_desc pvr2_device_onair_creator = {
126 .client_modules.lst = pvr2_client_onair_creator, 200 .client_modules.lst = pvr2_client_onair_creator,
127 .client_modules.cnt = ARRAY_SIZE(pvr2_client_onair_creator), 201 .client_modules.cnt = ARRAY_SIZE(pvr2_client_onair_creator),
128 .default_tuner_type = TUNER_LG_TDVS_H06XF, 202 .default_tuner_type = TUNER_LG_TDVS_H06XF,
203 .flag_has_analogtuner = !0,
204 .flag_has_composite = !0,
205 .flag_has_svideo = !0,
206 .flag_digital_requires_cx23416 = !0,
129 .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE, 207 .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE,
208 .digital_control_scheme = PVR2_DIGITAL_SCHEME_ONAIR,
209 .default_std_mask = V4L2_STD_NTSC_M,
210#ifdef CONFIG_VIDEO_PVRUSB2_DVB
211 .dvb_props = &pvr2_onair_creator_fe_props,
212#endif
130}; 213};
131#endif 214#endif
132 215
@@ -136,6 +219,37 @@ static const struct pvr2_device_desc pvr2_device_onair_creator = {
136/*------------------------------------------------------------------------*/ 219/*------------------------------------------------------------------------*/
137/* OnAir USB 2.0 */ 220/* OnAir USB 2.0 */
138 221
222#ifdef CONFIG_VIDEO_PVRUSB2_DVB
223static struct lgdt330x_config pvr2_lgdt3302_config = {
224 .demod_address = 0x0e,
225 .demod_chip = LGDT3302,
226};
227
228static int pvr2_lgdt3302_attach(struct pvr2_dvb_adapter *adap)
229{
230 adap->fe = dvb_attach(lgdt330x_attach, &pvr2_lgdt3302_config,
231 &adap->channel.hdw->i2c_adap);
232 if (adap->fe)
233 return 0;
234
235 return -EIO;
236}
237
238static int pvr2_fcv1236d_attach(struct pvr2_dvb_adapter *adap)
239{
240 dvb_attach(simple_tuner_attach, adap->fe,
241 &adap->channel.hdw->i2c_adap, 0x61,
242 TUNER_PHILIPS_FCV1236D);
243
244 return 0;
245}
246
247struct pvr2_dvb_props pvr2_onair_usb2_fe_props = {
248 .frontend_attach = pvr2_lgdt3302_attach,
249 .tuner_attach = pvr2_fcv1236d_attach,
250};
251#endif
252
139static const char *pvr2_client_onair_usb2[] = { 253static const char *pvr2_client_onair_usb2[] = {
140 "saa7115", 254 "saa7115",
141 "tuner", 255 "tuner",
@@ -147,8 +261,17 @@ static const struct pvr2_device_desc pvr2_device_onair_usb2 = {
147 .shortname = "oa2", 261 .shortname = "oa2",
148 .client_modules.lst = pvr2_client_onair_usb2, 262 .client_modules.lst = pvr2_client_onair_usb2,
149 .client_modules.cnt = ARRAY_SIZE(pvr2_client_onair_usb2), 263 .client_modules.cnt = ARRAY_SIZE(pvr2_client_onair_usb2),
150 .default_tuner_type = TUNER_PHILIPS_ATSC, 264 .default_tuner_type = TUNER_PHILIPS_FCV1236D,
265 .flag_has_analogtuner = !0,
266 .flag_has_composite = !0,
267 .flag_has_svideo = !0,
268 .flag_digital_requires_cx23416 = !0,
151 .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE, 269 .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE,
270 .digital_control_scheme = PVR2_DIGITAL_SCHEME_ONAIR,
271 .default_std_mask = V4L2_STD_NTSC_M,
272#ifdef CONFIG_VIDEO_PVRUSB2_DVB
273 .dvb_props = &pvr2_onair_usb2_fe_props,
274#endif
152}; 275};
153#endif 276#endif
154 277
@@ -157,6 +280,50 @@ static const struct pvr2_device_desc pvr2_device_onair_usb2 = {
157/*------------------------------------------------------------------------*/ 280/*------------------------------------------------------------------------*/
158/* Hauppauge PVR-USB2 Model 73xxx */ 281/* Hauppauge PVR-USB2 Model 73xxx */
159 282
283#ifdef CONFIG_VIDEO_PVRUSB2_DVB
284static struct tda10048_config hauppauge_tda10048_config = {
285 .demod_address = 0x10 >> 1,
286 .output_mode = TDA10048_PARALLEL_OUTPUT,
287 .fwbulkwritelen = TDA10048_BULKWRITE_50,
288 .inversion = TDA10048_INVERSION_ON,
289};
290
291static struct tda829x_config tda829x_no_probe = {
292 .probe_tuner = TDA829X_DONT_PROBE,
293};
294
295static struct tda18271_config hauppauge_tda18271_dvb_config = {
296 .gate = TDA18271_GATE_ANALOG,
297};
298
299static int pvr2_tda10048_attach(struct pvr2_dvb_adapter *adap)
300{
301 adap->fe = dvb_attach(tda10048_attach, &hauppauge_tda10048_config,
302 &adap->channel.hdw->i2c_adap);
303 if (adap->fe)
304 return 0;
305
306 return -EIO;
307}
308
309static int pvr2_73xxx_tda18271_8295_attach(struct pvr2_dvb_adapter *adap)
310{
311 dvb_attach(tda829x_attach, adap->fe,
312 &adap->channel.hdw->i2c_adap, 0x42,
313 &tda829x_no_probe);
314 dvb_attach(tda18271_attach, adap->fe, 0x60,
315 &adap->channel.hdw->i2c_adap,
316 &hauppauge_tda18271_dvb_config);
317
318 return 0;
319}
320
321struct pvr2_dvb_props pvr2_73xxx_dvb_props = {
322 .frontend_attach = pvr2_tda10048_attach,
323 .tuner_attach = pvr2_73xxx_tda18271_8295_attach,
324};
325#endif
326
160static const char *pvr2_client_73xxx[] = { 327static const char *pvr2_client_73xxx[] = {
161 "cx25840", 328 "cx25840",
162 "tuner", 329 "tuner",
@@ -167,7 +334,7 @@ static const char *pvr2_fw1_names_73xxx[] = {
167}; 334};
168 335
169static const struct pvr2_device_desc pvr2_device_73xxx = { 336static const struct pvr2_device_desc pvr2_device_73xxx = {
170 .description = "WinTV PVR USB2 Model Category 73xxxx", 337 .description = "WinTV PVR USB2 Model Category 73xxx",
171 .shortname = "73xxx", 338 .shortname = "73xxx",
172 .client_modules.lst = pvr2_client_73xxx, 339 .client_modules.lst = pvr2_client_73xxx,
173 .client_modules.cnt = ARRAY_SIZE(pvr2_client_73xxx), 340 .client_modules.cnt = ARRAY_SIZE(pvr2_client_73xxx),
@@ -175,15 +342,14 @@ static const struct pvr2_device_desc pvr2_device_73xxx = {
175 .fx2_firmware.cnt = ARRAY_SIZE(pvr2_fw1_names_73xxx), 342 .fx2_firmware.cnt = ARRAY_SIZE(pvr2_fw1_names_73xxx),
176 .flag_has_cx25840 = !0, 343 .flag_has_cx25840 = !0,
177 .flag_has_hauppauge_rom = !0, 344 .flag_has_hauppauge_rom = !0,
178#if 0
179 .flag_has_analogtuner = !0, 345 .flag_has_analogtuner = !0,
180 .flag_has_composite = !0, 346 .flag_has_composite = !0,
181 .flag_has_svideo = !0, 347 .flag_has_svideo = !0,
182 .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE, 348 .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE,
183 .digital_control_scheme = PVR2_DIGITAL_SCHEME_HAUPPAUGE, 349 .digital_control_scheme = PVR2_DIGITAL_SCHEME_HAUPPAUGE,
184 .led_scheme = PVR2_LED_SCHEME_HAUPPAUGE, 350 .led_scheme = PVR2_LED_SCHEME_HAUPPAUGE,
185#else 351#ifdef CONFIG_VIDEO_PVRUSB2_DVB
186 .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE, 352 .dvb_props = &pvr2_73xxx_dvb_props,
187#endif 353#endif
188}; 354};
189 355
@@ -192,6 +358,56 @@ static const struct pvr2_device_desc pvr2_device_73xxx = {
192/*------------------------------------------------------------------------*/ 358/*------------------------------------------------------------------------*/
193/* Hauppauge PVR-USB2 Model 75xxx */ 359/* Hauppauge PVR-USB2 Model 75xxx */
194 360
361#ifdef CONFIG_VIDEO_PVRUSB2_DVB
362static struct s5h1409_config pvr2_s5h1409_config = {
363 .demod_address = 0x32 >> 1,
364 .output_mode = S5H1409_PARALLEL_OUTPUT,
365 .gpio = S5H1409_GPIO_OFF,
366 .qam_if = 4000,
367 .inversion = S5H1409_INVERSION_ON,
368 .status_mode = S5H1409_DEMODLOCKING,
369};
370
371static struct tda18271_std_map hauppauge_tda18271_std_map = {
372 .atsc_6 = { .if_freq = 5380, .agc_mode = 3, .std = 3,
373 .if_lvl = 6, .rfagc_top = 0x37, },
374 .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 0,
375 .if_lvl = 6, .rfagc_top = 0x37, },
376};
377
378static struct tda18271_config hauppauge_tda18271_config = {
379 .std_map = &hauppauge_tda18271_std_map,
380 .gate = TDA18271_GATE_ANALOG,
381};
382
383static int pvr2_s5h1409_attach(struct pvr2_dvb_adapter *adap)
384{
385 adap->fe = dvb_attach(s5h1409_attach, &pvr2_s5h1409_config,
386 &adap->channel.hdw->i2c_adap);
387 if (adap->fe)
388 return 0;
389
390 return -EIO;
391}
392
393static int pvr2_tda18271_8295_attach(struct pvr2_dvb_adapter *adap)
394{
395 dvb_attach(tda829x_attach, adap->fe,
396 &adap->channel.hdw->i2c_adap, 0x42,
397 &tda829x_no_probe);
398 dvb_attach(tda18271_attach, adap->fe, 0x60,
399 &adap->channel.hdw->i2c_adap,
400 &hauppauge_tda18271_config);
401
402 return 0;
403}
404
405struct pvr2_dvb_props pvr2_750xx_dvb_props = {
406 .frontend_attach = pvr2_s5h1409_attach,
407 .tuner_attach = pvr2_tda18271_8295_attach,
408};
409#endif
410
195static const char *pvr2_client_75xxx[] = { 411static const char *pvr2_client_75xxx[] = {
196 "cx25840", 412 "cx25840",
197 "tuner", 413 "tuner",
@@ -201,17 +417,43 @@ static const char *pvr2_fw1_names_75xxx[] = {
201 "v4l-pvrusb2-73xxx-01.fw", 417 "v4l-pvrusb2-73xxx-01.fw",
202}; 418};
203 419
204static const struct pvr2_device_desc pvr2_device_75xxx = { 420static const struct pvr2_device_desc pvr2_device_750xx = {
205 .description = "WinTV PVR USB2 Model Category 75xxxx", 421 .description = "WinTV PVR USB2 Model Category 750xx",
206 .shortname = "75xxx", 422 .shortname = "750xx",
423 .client_modules.lst = pvr2_client_75xxx,
424 .client_modules.cnt = ARRAY_SIZE(pvr2_client_75xxx),
425 .fx2_firmware.lst = pvr2_fw1_names_75xxx,
426 .fx2_firmware.cnt = ARRAY_SIZE(pvr2_fw1_names_75xxx),
427 .flag_has_cx25840 = !0,
428 .flag_has_hauppauge_rom = !0,
429 .flag_has_analogtuner = !0,
430 .flag_has_composite = !0,
431 .flag_has_svideo = !0,
432 .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE,
433 .digital_control_scheme = PVR2_DIGITAL_SCHEME_HAUPPAUGE,
434 .default_std_mask = V4L2_STD_NTSC_M,
435 .led_scheme = PVR2_LED_SCHEME_HAUPPAUGE,
436#ifdef CONFIG_VIDEO_PVRUSB2_DVB
437 .dvb_props = &pvr2_750xx_dvb_props,
438#endif
439};
440
441static const struct pvr2_device_desc pvr2_device_751xx = {
442 .description = "WinTV PVR USB2 Model Category 751xx",
443 .shortname = "751xx",
207 .client_modules.lst = pvr2_client_75xxx, 444 .client_modules.lst = pvr2_client_75xxx,
208 .client_modules.cnt = ARRAY_SIZE(pvr2_client_75xxx), 445 .client_modules.cnt = ARRAY_SIZE(pvr2_client_75xxx),
209 .fx2_firmware.lst = pvr2_fw1_names_75xxx, 446 .fx2_firmware.lst = pvr2_fw1_names_75xxx,
210 .fx2_firmware.cnt = ARRAY_SIZE(pvr2_fw1_names_75xxx), 447 .fx2_firmware.cnt = ARRAY_SIZE(pvr2_fw1_names_75xxx),
211 .flag_has_cx25840 = !0, 448 .flag_has_cx25840 = !0,
212 .flag_has_hauppauge_rom = !0, 449 .flag_has_hauppauge_rom = !0,
450 .flag_has_analogtuner = !0,
451 .flag_has_composite = !0,
452 .flag_has_svideo = !0,
213 .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE, 453 .signal_routing_scheme = PVR2_ROUTING_SCHEME_HAUPPAUGE,
454 .digital_control_scheme = PVR2_DIGITAL_SCHEME_HAUPPAUGE,
214 .default_std_mask = V4L2_STD_NTSC_M, 455 .default_std_mask = V4L2_STD_NTSC_M,
456 .led_scheme = PVR2_LED_SCHEME_HAUPPAUGE,
215}; 457};
216 458
217 459
@@ -225,6 +467,8 @@ struct usb_device_id pvr2_device_table[] = {
225 .driver_info = (kernel_ulong_t)&pvr2_device_24xxx}, 467 .driver_info = (kernel_ulong_t)&pvr2_device_24xxx},
226 { USB_DEVICE(0x1164, 0x0622), 468 { USB_DEVICE(0x1164, 0x0622),
227 .driver_info = (kernel_ulong_t)&pvr2_device_gotview_2}, 469 .driver_info = (kernel_ulong_t)&pvr2_device_gotview_2},
470 { USB_DEVICE(0x1164, 0x0602),
471 .driver_info = (kernel_ulong_t)&pvr2_device_gotview_2d},
228#ifdef CONFIG_VIDEO_PVRUSB2_ONAIR_CREATOR 472#ifdef CONFIG_VIDEO_PVRUSB2_ONAIR_CREATOR
229 { USB_DEVICE(0x11ba, 0x1003), 473 { USB_DEVICE(0x11ba, 0x1003),
230 .driver_info = (kernel_ulong_t)&pvr2_device_onair_creator}, 474 .driver_info = (kernel_ulong_t)&pvr2_device_onair_creator},
@@ -236,9 +480,9 @@ struct usb_device_id pvr2_device_table[] = {
236 { USB_DEVICE(0x2040, 0x7300), 480 { USB_DEVICE(0x2040, 0x7300),
237 .driver_info = (kernel_ulong_t)&pvr2_device_73xxx}, 481 .driver_info = (kernel_ulong_t)&pvr2_device_73xxx},
238 { USB_DEVICE(0x2040, 0x7500), 482 { USB_DEVICE(0x2040, 0x7500),
239 .driver_info = (kernel_ulong_t)&pvr2_device_75xxx}, 483 .driver_info = (kernel_ulong_t)&pvr2_device_750xx},
240 { USB_DEVICE(0x2040, 0x7501), 484 { USB_DEVICE(0x2040, 0x7501),
241 .driver_info = (kernel_ulong_t)&pvr2_device_75xxx}, 485 .driver_info = (kernel_ulong_t)&pvr2_device_751xx},
242 { } 486 { }
243}; 487};
244 488
diff --git a/drivers/media/video/pvrusb2/pvrusb2-devattr.h b/drivers/media/video/pvrusb2/pvrusb2-devattr.h
index 64b467f0637f..c2e2b06fe2e0 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-devattr.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-devattr.h
@@ -23,6 +23,9 @@
23 23
24#include <linux/mod_devicetable.h> 24#include <linux/mod_devicetable.h>
25#include <linux/videodev2.h> 25#include <linux/videodev2.h>
26#ifdef CONFIG_VIDEO_PVRUSB2_DVB
27#include "pvrusb2-dvb.h"
28#endif
26 29
27/* 30/*
28 31
@@ -39,6 +42,13 @@ struct pvr2_string_table {
39#define PVR2_ROUTING_SCHEME_HAUPPAUGE 0 42#define PVR2_ROUTING_SCHEME_HAUPPAUGE 0
40#define PVR2_ROUTING_SCHEME_GOTVIEW 1 43#define PVR2_ROUTING_SCHEME_GOTVIEW 1
41 44
45#define PVR2_DIGITAL_SCHEME_NONE 0
46#define PVR2_DIGITAL_SCHEME_HAUPPAUGE 1
47#define PVR2_DIGITAL_SCHEME_ONAIR 2
48
49#define PVR2_LED_SCHEME_NONE 0
50#define PVR2_LED_SCHEME_HAUPPAUGE 1
51
42/* This describes a particular hardware type (except for the USB device ID 52/* This describes a particular hardware type (except for the USB device ID
43 which must live in a separate structure due to environmental 53 which must live in a separate structure due to environmental
44 constraints). See the top of pvrusb2-hdw.c for where this is 54 constraints). See the top of pvrusb2-hdw.c for where this is
@@ -58,40 +68,64 @@ struct pvr2_device_desc {
58 was initialized from internal ROM. */ 68 was initialized from internal ROM. */
59 struct pvr2_string_table fx2_firmware; 69 struct pvr2_string_table fx2_firmware;
60 70
71#ifdef CONFIG_VIDEO_PVRUSB2_DVB
72 /* callback functions to handle attachment of digital tuner & demod */
73 struct pvr2_dvb_props *dvb_props;
74
75#endif
76 /* Initial standard bits to use for this device, if not zero.
77 Anything set here is also implied as an available standard.
78 Note: This is ignored if overridden on the module load line via
79 the video_std module option. */
80 v4l2_std_id default_std_mask;
81
82 /* V4L tuner type ID to use with this device (only used if the
83 driver could not discover the type any other way). */
84 int default_tuner_type;
85
61 /* Signal routing scheme used by device, contains one of 86 /* Signal routing scheme used by device, contains one of
62 PVR2_ROUTING_SCHEME_XXX. Schemes have to be defined as we 87 PVR2_ROUTING_SCHEME_XXX. Schemes have to be defined as we
63 encounter them. This is an arbitrary integer scheme id; its 88 encounter them. This is an arbitrary integer scheme id; its
64 meaning is contained entirely within the driver and is 89 meaning is contained entirely within the driver and is
65 interpreted by logic which must send commands to the chip-level 90 interpreted by logic which must send commands to the chip-level
66 drivers (search for things which touch this field). */ 91 drivers (search for things which touch this field). */
67 unsigned int signal_routing_scheme; 92 unsigned char signal_routing_scheme;
68 93
69 /* V4L tuner type ID to use with this device (only used if the 94 /* Indicates scheme for controlling device's LED (if any). The
70 driver could not discover the type any other way). */ 95 driver will turn on the LED when streaming is underway. This
71 int default_tuner_type; 96 contains one of PVR2_LED_SCHEME_XXX. */
97 unsigned char led_scheme;
72 98
73 /* Initial standard bits to use for this device, if not zero. 99 /* Control scheme to use if there is a digital tuner. This
74 Anything set here is also implied as an available standard. 100 contains one of PVR2_DIGITAL_SCHEME_XXX. This is an arbitrary
75 Note: This is ignored if overridden on the module load line via 101 integer scheme id; its meaning is contained entirely within the
76 the video_std module option. */ 102 driver and is interpreted by logic which must control the
77 v4l2_std_id default_std_mask; 103 streaming pathway (search for things which touch this field). */
104 unsigned char digital_control_scheme;
78 105
79 /* If set, we don't bother trying to load cx23416 firmware. */ 106 /* If set, we don't bother trying to load cx23416 firmware. */
80 char flag_skip_cx23416_firmware; 107 int flag_skip_cx23416_firmware:1;
108
109 /* If set, the encoder must be healthy in order for digital mode to
110 work (otherwise we assume that digital streaming will work even
111 if we fail to locate firmware for the encoder). If the device
112 doesn't support digital streaming then this flag has no
113 effect. */
114 int flag_digital_requires_cx23416:1;
81 115
82 /* Device has a hauppauge eeprom which we can interrogate. */ 116 /* Device has a hauppauge eeprom which we can interrogate. */
83 char flag_has_hauppauge_rom; 117 int flag_has_hauppauge_rom:1;
84 118
85 /* Device does not require a powerup command to be issued. */ 119 /* Device does not require a powerup command to be issued. */
86 char flag_no_powerup; 120 int flag_no_powerup:1;
87 121
88 /* Device has a cx25840 - this enables special additional logic to 122 /* Device has a cx25840 - this enables special additional logic to
89 handle it. */ 123 handle it. */
90 char flag_has_cx25840; 124 int flag_has_cx25840:1;
91 125
92 /* Device has a wm8775 - this enables special additional logic to 126 /* Device has a wm8775 - this enables special additional logic to
93 ensure that it is found. */ 127 ensure that it is found. */
94 char flag_has_wm8775; 128 int flag_has_wm8775:1;
95 129
96 /* Device has IR hardware that can be faked into looking like a 130 /* Device has IR hardware that can be faked into looking like a
97 normal Hauppauge i2c IR receiver. This is currently very 131 normal Hauppauge i2c IR receiver. This is currently very
@@ -101,7 +135,15 @@ struct pvr2_device_desc {
101 to virtualize the presence of the non-existant IR receiver chip and 135 to virtualize the presence of the non-existant IR receiver chip and
102 implement the virtual receiver in terms of appropriate FX2 136 implement the virtual receiver in terms of appropriate FX2
103 commands. */ 137 commands. */
104 char flag_has_hauppauge_custom_ir; 138 int flag_has_hauppauge_custom_ir:1;
139
140 /* These bits define which kinds of sources the device can handle.
141 Note: Digital tuner presence is inferred by the
142 digital_control_scheme enumeration. */
143 int flag_has_fmradio:1; /* Has FM radio receiver */
144 int flag_has_analogtuner:1; /* Has analog tuner */
145 int flag_has_composite:1; /* Has composite input */
146 int flag_has_svideo:1; /* Has s-video input */
105}; 147};
106 148
107extern struct usb_device_id pvr2_device_table[]; 149extern struct usb_device_id pvr2_device_table[];
diff --git a/drivers/media/video/pvrusb2/pvrusb2-dvb.c b/drivers/media/video/pvrusb2/pvrusb2-dvb.c
new file mode 100644
index 000000000000..2e64f98d1241
--- /dev/null
+++ b/drivers/media/video/pvrusb2/pvrusb2-dvb.c
@@ -0,0 +1,425 @@
1/*
2 * pvrusb2-dvb.c - linux-dvb api interface to the pvrusb2 driver.
3 *
4 * Copyright (C) 2007, 2008 Michael Krufky <mkrufky@linuxtv.org>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 */
20
21#include <linux/kthread.h>
22#include <linux/freezer.h>
23#include "dvbdev.h"
24#include "pvrusb2-hdw-internal.h"
25#include "pvrusb2-hdw.h"
26#include "pvrusb2-io.h"
27#include "pvrusb2-dvb.h"
28
29DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
30
31static int pvr2_dvb_feed_func(struct pvr2_dvb_adapter *adap)
32{
33 int ret;
34 unsigned int count;
35 struct pvr2_buffer *bp;
36 struct pvr2_stream *stream;
37
38 printk(KERN_DEBUG "dvb thread started\n");
39 set_freezable();
40
41 stream = adap->channel.stream->stream;
42
43 for (;;) {
44 if (kthread_should_stop()) break;
45
46 /* Not sure about this... */
47 try_to_freeze();
48
49 bp = pvr2_stream_get_ready_buffer(stream);
50 if (bp != NULL) {
51 count = pvr2_buffer_get_count(bp);
52 if (count) {
53 dvb_dmx_swfilter(
54 &adap->demux,
55 adap->buffer_storage[
56 pvr2_buffer_get_id(bp)],
57 count);
58 } else {
59 ret = pvr2_buffer_get_status(bp);
60 if (ret < 0) break;
61 }
62 ret = pvr2_buffer_queue(bp);
63 if (ret < 0) break;
64
65 /* Since we know we did something to a buffer,
66 just go back and try again. No point in
67 blocking unless we really ran out of
68 buffers to process. */
69 continue;
70 }
71
72
73 /* Wait until more buffers become available or we're
74 told not to wait any longer. */
75 ret = wait_event_interruptible(
76 adap->buffer_wait_data,
77 (pvr2_stream_get_ready_count(stream) > 0) ||
78 kthread_should_stop());
79 if (ret < 0) break;
80 }
81
82 /* If we get here and ret is < 0, then an error has occurred.
83 Probably would be a good idea to communicate that to DVB core... */
84
85 printk(KERN_DEBUG "dvb thread stopped\n");
86
87 return 0;
88}
89
90static int pvr2_dvb_feed_thread(void *data)
91{
92 int stat = pvr2_dvb_feed_func(data);
93 /* from videobuf-dvb.c: */
94 while (!kthread_should_stop()) {
95 set_current_state(TASK_INTERRUPTIBLE);
96 schedule();
97 }
98 return stat;
99}
100
101static void pvr2_dvb_notify(struct pvr2_dvb_adapter *adap)
102{
103 wake_up(&adap->buffer_wait_data);
104}
105
106static void pvr2_dvb_stream_end(struct pvr2_dvb_adapter *adap)
107{
108 unsigned int idx;
109 struct pvr2_stream *stream;
110
111 if (adap->thread) {
112 kthread_stop(adap->thread);
113 adap->thread = NULL;
114 }
115
116 if (adap->channel.stream) {
117 stream = adap->channel.stream->stream;
118 } else {
119 stream = NULL;
120 }
121 if (stream) {
122 pvr2_hdw_set_streaming(adap->channel.hdw, 0);
123 pvr2_stream_set_callback(stream, NULL, NULL);
124 pvr2_stream_kill(stream);
125 pvr2_stream_set_buffer_count(stream, 0);
126 pvr2_channel_claim_stream(&adap->channel, NULL);
127 }
128
129 if (adap->stream_run) {
130 for (idx = 0; idx < PVR2_DVB_BUFFER_COUNT; idx++) {
131 if (!(adap->buffer_storage[idx])) continue;
132 kfree(adap->buffer_storage[idx]);
133 adap->buffer_storage[idx] = 0;
134 }
135 adap->stream_run = 0;
136 }
137}
138
139static int pvr2_dvb_stream_do_start(struct pvr2_dvb_adapter *adap)
140{
141 struct pvr2_context *pvr = adap->channel.mc_head;
142 unsigned int idx;
143 int ret;
144 struct pvr2_buffer *bp;
145 struct pvr2_stream *stream = 0;
146
147 if (adap->stream_run) return -EIO;
148
149 ret = pvr2_channel_claim_stream(&adap->channel, &pvr->video_stream);
150 /* somebody else already has the stream */
151 if (ret < 0) return ret;
152
153 stream = adap->channel.stream->stream;
154
155 for (idx = 0; idx < PVR2_DVB_BUFFER_COUNT; idx++) {
156 adap->buffer_storage[idx] = kmalloc(PVR2_DVB_BUFFER_SIZE,
157 GFP_KERNEL);
158 if (!(adap->buffer_storage[idx])) return -ENOMEM;
159 }
160
161 pvr2_stream_set_callback(pvr->video_stream.stream,
162 (pvr2_stream_callback) pvr2_dvb_notify, adap);
163
164 ret = pvr2_stream_set_buffer_count(stream, PVR2_DVB_BUFFER_COUNT);
165 if (ret < 0) return ret;
166
167 for (idx = 0; idx < PVR2_DVB_BUFFER_COUNT; idx++) {
168 bp = pvr2_stream_get_buffer(stream, idx);
169 pvr2_buffer_set_buffer(bp,
170 adap->buffer_storage[idx],
171 PVR2_DVB_BUFFER_SIZE);
172 }
173
174 ret = pvr2_hdw_set_streaming(adap->channel.hdw, 1);
175 if (ret < 0) return ret;
176
177 while ((bp = pvr2_stream_get_idle_buffer(stream)) != 0) {
178 ret = pvr2_buffer_queue(bp);
179 if (ret < 0) return ret;
180 }
181
182 adap->thread = kthread_run(pvr2_dvb_feed_thread, adap, "pvrusb2-dvb");
183
184 if (IS_ERR(adap->thread)) {
185 ret = PTR_ERR(adap->thread);
186 adap->thread = NULL;
187 return ret;
188 }
189
190 adap->stream_run = !0;
191
192 return 0;
193}
194
195static int pvr2_dvb_stream_start(struct pvr2_dvb_adapter *adap)
196{
197 int ret = pvr2_dvb_stream_do_start(adap);
198 if (ret < 0) pvr2_dvb_stream_end(adap);
199 return ret;
200}
201
202static int pvr2_dvb_ctrl_feed(struct dvb_demux_feed *dvbdmxfeed, int onoff)
203{
204 struct pvr2_dvb_adapter *adap = dvbdmxfeed->demux->priv;
205 int ret = 0;
206
207 if (adap == NULL) return -ENODEV;
208
209 mutex_lock(&adap->lock);
210 do {
211 if (onoff) {
212 if (!adap->feedcount) {
213 printk(KERN_DEBUG "start feeding\n");
214 ret = pvr2_dvb_stream_start(adap);
215 if (ret < 0) break;
216 }
217 (adap->feedcount)++;
218 } else if (adap->feedcount > 0) {
219 (adap->feedcount)--;
220 if (!adap->feedcount) {
221 printk(KERN_DEBUG "stop feeding\n");
222 pvr2_dvb_stream_end(adap);
223 }
224 }
225 } while (0);
226 mutex_unlock(&adap->lock);
227
228 return ret;
229}
230
231static int pvr2_dvb_start_feed(struct dvb_demux_feed *dvbdmxfeed)
232{
233 printk(KERN_DEBUG "start pid: 0x%04x, feedtype: %d\n",
234 dvbdmxfeed->pid, dvbdmxfeed->type);
235 return pvr2_dvb_ctrl_feed(dvbdmxfeed, 1);
236}
237
238static int pvr2_dvb_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
239{
240 printk(KERN_DEBUG "stop pid: 0x%04x, feedtype: %d\n",
241 dvbdmxfeed->pid, dvbdmxfeed->type);
242 return pvr2_dvb_ctrl_feed(dvbdmxfeed, 0);
243}
244
245static int pvr2_dvb_bus_ctrl(struct dvb_frontend *fe, int acquire)
246{
247 struct pvr2_dvb_adapter *adap = fe->dvb->priv;
248 return pvr2_channel_limit_inputs(
249 &adap->channel,
250 (acquire ? (1 << PVR2_CVAL_INPUT_DTV) : 0));
251}
252
253static int pvr2_dvb_adapter_init(struct pvr2_dvb_adapter *adap)
254{
255 int ret;
256
257 ret = dvb_register_adapter(&adap->dvb_adap, "pvrusb2-dvb",
258 THIS_MODULE/*&hdw->usb_dev->owner*/,
259 &adap->channel.hdw->usb_dev->dev,
260 adapter_nr);
261 if (ret < 0) {
262 err("dvb_register_adapter failed: error %d", ret);
263 goto err;
264 }
265 adap->dvb_adap.priv = adap;
266
267 adap->demux.dmx.capabilities = DMX_TS_FILTERING |
268 DMX_SECTION_FILTERING |
269 DMX_MEMORY_BASED_FILTERING;
270 adap->demux.priv = adap;
271 adap->demux.filternum = 256;
272 adap->demux.feednum = 256;
273 adap->demux.start_feed = pvr2_dvb_start_feed;
274 adap->demux.stop_feed = pvr2_dvb_stop_feed;
275 adap->demux.write_to_decoder = NULL;
276
277 ret = dvb_dmx_init(&adap->demux);
278 if (ret < 0) {
279 err("dvb_dmx_init failed: error %d", ret);
280 goto err_dmx;
281 }
282
283 adap->dmxdev.filternum = adap->demux.filternum;
284 adap->dmxdev.demux = &adap->demux.dmx;
285 adap->dmxdev.capabilities = 0;
286
287 ret = dvb_dmxdev_init(&adap->dmxdev, &adap->dvb_adap);
288 if (ret < 0) {
289 err("dvb_dmxdev_init failed: error %d", ret);
290 goto err_dmx_dev;
291 }
292
293 dvb_net_init(&adap->dvb_adap, &adap->dvb_net, &adap->demux.dmx);
294
295 return 0;
296
297err_dmx_dev:
298 dvb_dmx_release(&adap->demux);
299err_dmx:
300 dvb_unregister_adapter(&adap->dvb_adap);
301err:
302 return ret;
303}
304
305static int pvr2_dvb_adapter_exit(struct pvr2_dvb_adapter *adap)
306{
307 printk(KERN_DEBUG "unregistering DVB devices\n");
308 dvb_net_release(&adap->dvb_net);
309 adap->demux.dmx.close(&adap->demux.dmx);
310 dvb_dmxdev_release(&adap->dmxdev);
311 dvb_dmx_release(&adap->demux);
312 dvb_unregister_adapter(&adap->dvb_adap);
313 return 0;
314}
315
316static int pvr2_dvb_frontend_init(struct pvr2_dvb_adapter *adap)
317{
318 struct pvr2_hdw *hdw = adap->channel.hdw;
319 struct pvr2_dvb_props *dvb_props = hdw->hdw_desc->dvb_props;
320 int ret = 0;
321
322 if (dvb_props == NULL) {
323 err("fe_props not defined!");
324 return -EINVAL;
325 }
326
327 ret = pvr2_channel_limit_inputs(
328 &adap->channel,
329 (1 << PVR2_CVAL_INPUT_DTV));
330 if (ret) {
331 err("failed to grab control of dtv input (code=%d)",
332 ret);
333 return ret;
334 }
335
336 if (dvb_props->frontend_attach == NULL) {
337 err("frontend_attach not defined!");
338 ret = -EINVAL;
339 goto done;
340 }
341
342 if ((dvb_props->frontend_attach(adap) == 0) && (adap->fe)) {
343
344 if (dvb_register_frontend(&adap->dvb_adap, adap->fe)) {
345 err("frontend registration failed!");
346 dvb_frontend_detach(adap->fe);
347 adap->fe = NULL;
348 ret = -ENODEV;
349 goto done;
350 }
351
352 if (dvb_props->tuner_attach)
353 dvb_props->tuner_attach(adap);
354
355 if (adap->fe->ops.analog_ops.standby)
356 adap->fe->ops.analog_ops.standby(adap->fe);
357
358 /* Ensure all frontends negotiate bus access */
359 adap->fe->ops.ts_bus_ctrl = pvr2_dvb_bus_ctrl;
360
361 } else {
362 err("no frontend was attached!");
363 ret = -ENODEV;
364 return ret;
365 }
366
367 done:
368 pvr2_channel_limit_inputs(&adap->channel, 0);
369 return ret;
370}
371
372static int pvr2_dvb_frontend_exit(struct pvr2_dvb_adapter *adap)
373{
374 if (adap->fe != NULL) {
375 dvb_unregister_frontend(adap->fe);
376 dvb_frontend_detach(adap->fe);
377 }
378 return 0;
379}
380
381static void pvr2_dvb_destroy(struct pvr2_dvb_adapter *adap)
382{
383 pvr2_dvb_stream_end(adap);
384 pvr2_dvb_frontend_exit(adap);
385 pvr2_dvb_adapter_exit(adap);
386 pvr2_channel_done(&adap->channel);
387 kfree(adap);
388}
389
390static void pvr2_dvb_internal_check(struct pvr2_channel *chp)
391{
392 struct pvr2_dvb_adapter *adap;
393 adap = container_of(chp, struct pvr2_dvb_adapter, channel);
394 if (!adap->channel.mc_head->disconnect_flag) return;
395 pvr2_dvb_destroy(adap);
396}
397
398struct pvr2_dvb_adapter *pvr2_dvb_create(struct pvr2_context *pvr)
399{
400 int ret = 0;
401 struct pvr2_dvb_adapter *adap;
402 if (!pvr->hdw->hdw_desc->dvb_props) {
403 /* Device lacks a digital interface so don't set up
404 the DVB side of the driver either. For now. */
405 return NULL;
406 }
407 adap = kzalloc(sizeof(*adap), GFP_KERNEL);
408 if (!adap) return adap;
409 pvr2_channel_init(&adap->channel, pvr);
410 adap->channel.check_func = pvr2_dvb_internal_check;
411 init_waitqueue_head(&adap->buffer_wait_data);
412 mutex_init(&adap->lock);
413 ret = pvr2_dvb_adapter_init(adap);
414 if (ret < 0) goto fail1;
415 ret = pvr2_dvb_frontend_init(adap);
416 if (ret < 0) goto fail2;
417 return adap;
418
419fail2:
420 pvr2_dvb_adapter_exit(adap);
421fail1:
422 pvr2_channel_done(&adap->channel);
423 return NULL;
424}
425
diff --git a/drivers/media/video/pvrusb2/pvrusb2-dvb.h b/drivers/media/video/pvrusb2/pvrusb2-dvb.h
new file mode 100644
index 000000000000..884ff916a352
--- /dev/null
+++ b/drivers/media/video/pvrusb2/pvrusb2-dvb.h
@@ -0,0 +1,41 @@
1#ifndef __PVRUSB2_DVB_H__
2#define __PVRUSB2_DVB_H__
3
4#include "dvb_frontend.h"
5#include "dvb_demux.h"
6#include "dvb_net.h"
7#include "dmxdev.h"
8#include "pvrusb2-context.h"
9
10#define PVR2_DVB_BUFFER_COUNT 32
11#define PVR2_DVB_BUFFER_SIZE PAGE_ALIGN(0x4000)
12
13struct pvr2_dvb_adapter {
14 struct pvr2_channel channel;
15
16 struct dvb_adapter dvb_adap;
17 struct dmxdev dmxdev;
18 struct dvb_demux demux;
19 struct dvb_net dvb_net;
20 struct dvb_frontend *fe;
21
22 int feedcount;
23 int max_feed_count;
24
25 struct task_struct *thread;
26 struct mutex lock;
27
28 unsigned int stream_run:1;
29
30 wait_queue_head_t buffer_wait_data;
31 char *buffer_storage[PVR2_DVB_BUFFER_COUNT];
32};
33
34struct pvr2_dvb_props {
35 int (*frontend_attach) (struct pvr2_dvb_adapter *);
36 int (*tuner_attach) (struct pvr2_dvb_adapter *);
37};
38
39struct pvr2_dvb_adapter *pvr2_dvb_create(struct pvr2_context *pvr);
40
41#endif /* __PVRUSB2_DVB_H__ */
diff --git a/drivers/media/video/pvrusb2/pvrusb2-encoder.c b/drivers/media/video/pvrusb2/pvrusb2-encoder.c
index 64062879981e..c46d367f7472 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-encoder.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-encoder.c
@@ -278,11 +278,20 @@ static int pvr2_encoder_cmd(void *ctxt,
278 ret = -EBUSY; 278 ret = -EBUSY;
279 } 279 }
280 if (ret) { 280 if (ret) {
281 del_timer_sync(&hdw->encoder_run_timer);
281 hdw->state_encoder_ok = 0; 282 hdw->state_encoder_ok = 0;
282 pvr2_trace(PVR2_TRACE_STBITS, 283 pvr2_trace(PVR2_TRACE_STBITS,
283 "State bit %s <-- %s", 284 "State bit %s <-- %s",
284 "state_encoder_ok", 285 "state_encoder_ok",
285 (hdw->state_encoder_ok ? "true" : "false")); 286 (hdw->state_encoder_ok ? "true" : "false"));
287 if (hdw->state_encoder_runok) {
288 hdw->state_encoder_runok = 0;
289 pvr2_trace(PVR2_TRACE_STBITS,
290 "State bit %s <-- %s",
291 "state_encoder_runok",
292 (hdw->state_encoder_runok ?
293 "true" : "false"));
294 }
286 pvr2_trace( 295 pvr2_trace(
287 PVR2_TRACE_ERROR_LEGS, 296 PVR2_TRACE_ERROR_LEGS,
288 "Giving up on command." 297 "Giving up on command."
@@ -480,10 +489,6 @@ int pvr2_encoder_start(struct pvr2_hdw *hdw)
480 /* unmask some interrupts */ 489 /* unmask some interrupts */
481 pvr2_write_register(hdw, 0x0048, 0xbfffffff); 490 pvr2_write_register(hdw, 0x0048, 0xbfffffff);
482 491
483 /* change some GPIO data */
484 pvr2_hdw_gpio_chg_dir(hdw,0xffffffff,0x00000481);
485 pvr2_hdw_gpio_chg_out(hdw,0xffffffff,0x00000000);
486
487 pvr2_encoder_vcmd(hdw,CX2341X_ENC_MUTE_VIDEO,1, 492 pvr2_encoder_vcmd(hdw,CX2341X_ENC_MUTE_VIDEO,1,
488 hdw->input_val == PVR2_CVAL_INPUT_RADIO ? 1 : 0); 493 hdw->input_val == PVR2_CVAL_INPUT_RADIO ? 1 : 0);
489 494
@@ -526,12 +531,6 @@ int pvr2_encoder_stop(struct pvr2_hdw *hdw)
526 break; 531 break;
527 } 532 }
528 533
529 /* change some GPIO data */
530 /* Note: Bit d7 of dir appears to control the LED. So we shut it
531 off here. */
532 pvr2_hdw_gpio_chg_dir(hdw,0xffffffff,0x00000401);
533 pvr2_hdw_gpio_chg_out(hdw,0xffffffff,0x00000000);
534
535 return status; 534 return status;
536} 535}
537 536
diff --git a/drivers/media/video/pvrusb2/pvrusb2-fx2-cmd.h b/drivers/media/video/pvrusb2/pvrusb2-fx2-cmd.h
index ffbc6d096108..abaada31e66e 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-fx2-cmd.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-fx2-cmd.h
@@ -22,32 +22,41 @@
22#ifndef _PVRUSB2_FX2_CMD_H_ 22#ifndef _PVRUSB2_FX2_CMD_H_
23#define _PVRUSB2_FX2_CMD_H_ 23#define _PVRUSB2_FX2_CMD_H_
24 24
25#define FX2CMD_MEM_WRITE_DWORD 0x01 25#define FX2CMD_MEM_WRITE_DWORD 0x01u
26#define FX2CMD_MEM_READ_DWORD 0x02 26#define FX2CMD_MEM_READ_DWORD 0x02u
27 27
28#define FX2CMD_MEM_READ_64BYTES 0x28 28#define FX2CMD_MEM_READ_64BYTES 0x28u
29 29
30#define FX2CMD_REG_WRITE 0x04 30#define FX2CMD_REG_WRITE 0x04u
31#define FX2CMD_REG_READ 0x05 31#define FX2CMD_REG_READ 0x05u
32#define FX2CMD_MEMSEL 0x06 32#define FX2CMD_MEMSEL 0x06u
33 33
34#define FX2CMD_I2C_WRITE 0x08 34#define FX2CMD_I2C_WRITE 0x08u
35#define FX2CMD_I2C_READ 0x09 35#define FX2CMD_I2C_READ 0x09u
36 36
37#define FX2CMD_GET_USB_SPEED 0x0b 37#define FX2CMD_GET_USB_SPEED 0x0bu
38 38
39#define FX2CMD_STREAMING_ON 0x36 39#define FX2CMD_STREAMING_ON 0x36u
40#define FX2CMD_STREAMING_OFF 0x37 40#define FX2CMD_STREAMING_OFF 0x37u
41 41
42#define FX2CMD_FWPOST1 0x52 42#define FX2CMD_FWPOST1 0x52u
43 43
44#define FX2CMD_POWER_OFF 0xdc 44#define FX2CMD_POWER_OFF 0xdcu
45#define FX2CMD_POWER_ON 0xde 45#define FX2CMD_POWER_ON 0xdeu
46 46
47#define FX2CMD_DEEP_RESET 0xdd 47#define FX2CMD_DEEP_RESET 0xddu
48 48
49#define FX2CMD_GET_EEPROM_ADDR 0xeb 49#define FX2CMD_GET_EEPROM_ADDR 0xebu
50#define FX2CMD_GET_IR_CODE 0xec 50#define FX2CMD_GET_IR_CODE 0xecu
51
52#define FX2CMD_HCW_DEMOD_RESETIN 0xf0u
53#define FX2CMD_HCW_DTV_STREAMING_ON 0xf1u
54#define FX2CMD_HCW_DTV_STREAMING_OFF 0xf2u
55
56#define FX2CMD_ONAIR_DTV_STREAMING_ON 0xa0u
57#define FX2CMD_ONAIR_DTV_STREAMING_OFF 0xa1u
58#define FX2CMD_ONAIR_DTV_POWER_ON 0xa2u
59#define FX2CMD_ONAIR_DTV_POWER_OFF 0xa3u
51 60
52#endif /* _PVRUSB2_FX2_CMD_H_ */ 61#endif /* _PVRUSB2_FX2_CMD_H_ */
53 62
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
index d7a216b41b72..a3fe251d6fd9 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
@@ -163,6 +163,11 @@ struct pvr2_decoder_ctrl {
163#define FW1_STATE_RELOAD 3 163#define FW1_STATE_RELOAD 3
164#define FW1_STATE_OK 4 164#define FW1_STATE_OK 4
165 165
166/* What state the device is in if it is a hybrid */
167#define PVR2_PATHWAY_UNKNOWN 0
168#define PVR2_PATHWAY_ANALOG 1
169#define PVR2_PATHWAY_DIGITAL 2
170
166typedef int (*pvr2_i2c_func)(struct pvr2_hdw *,u8,u8 *,u16,u8 *, u16); 171typedef int (*pvr2_i2c_func)(struct pvr2_hdw *,u8,u8 *,u16,u8 *, u16);
167#define PVR2_I2C_FUNC_CNT 128 172#define PVR2_I2C_FUNC_CNT 128
168 173
@@ -182,7 +187,6 @@ struct pvr2_hdw {
182 struct workqueue_struct *workqueue; 187 struct workqueue_struct *workqueue;
183 struct work_struct workpoll; /* Update driver state */ 188 struct work_struct workpoll; /* Update driver state */
184 struct work_struct worki2csync; /* Update i2c clients */ 189 struct work_struct worki2csync; /* Update i2c clients */
185 struct work_struct workinit; /* Driver initialization sequence */
186 190
187 /* Video spigot */ 191 /* Video spigot */
188 struct pvr2_stream *vid_stream; 192 struct pvr2_stream *vid_stream;
@@ -229,17 +233,19 @@ struct pvr2_hdw {
229 233
230 /* Bits of state that describe what is going on with various parts 234 /* Bits of state that describe what is going on with various parts
231 of the driver. */ 235 of the driver. */
236 int state_pathway_ok; /* Pathway config is ok */
232 int state_encoder_ok; /* Encoder is operational */ 237 int state_encoder_ok; /* Encoder is operational */
233 int state_encoder_run; /* Encoder is running */ 238 int state_encoder_run; /* Encoder is running */
234 int state_encoder_config; /* Encoder is configured */ 239 int state_encoder_config; /* Encoder is configured */
235 int state_encoder_waitok; /* Encoder pre-wait done */ 240 int state_encoder_waitok; /* Encoder pre-wait done */
241 int state_encoder_runok; /* Encoder has run for >= .25 sec */
236 int state_decoder_run; /* Decoder is running */ 242 int state_decoder_run; /* Decoder is running */
237 int state_usbstream_run; /* FX2 is streaming */ 243 int state_usbstream_run; /* FX2 is streaming */
238 int state_decoder_quiescent; /* Decoder idle for > 50msec */ 244 int state_decoder_quiescent; /* Decoder idle for > 50msec */
239 int state_pipeline_config; /* Pipeline is configured */ 245 int state_pipeline_config; /* Pipeline is configured */
240 int state_pipeline_req; /* Somebody wants to stream */ 246 int state_pipeline_req; /* Somebody wants to stream */
241 int state_pipeline_pause; /* Pipeline must be paused */ 247 int state_pipeline_pause; /* Pipeline must be paused */
242 int state_pipeline_idle; /* Pipeline not running */ 248 int state_pipeline_idle; /* Pipeline not running */
243 249
244 /* This is the master state of the driver. It is the combined 250 /* This is the master state of the driver. It is the combined
245 result of other bits of state. Examining this will indicate the 251 result of other bits of state. Examining this will indicate the
@@ -247,6 +253,9 @@ struct pvr2_hdw {
247 PVR2_STATE_xxxx */ 253 PVR2_STATE_xxxx */
248 unsigned int master_state; 254 unsigned int master_state;
249 255
256 /* True if device led is currently on */
257 int led_on;
258
250 /* True if states must be re-evaluated */ 259 /* True if states must be re-evaluated */
251 int state_stale; 260 int state_stale;
252 261
@@ -259,6 +268,9 @@ struct pvr2_hdw {
259 /* Timer for measuring encoder pre-wait time */ 268 /* Timer for measuring encoder pre-wait time */
260 struct timer_list encoder_wait_timer; 269 struct timer_list encoder_wait_timer;
261 270
271 /* Timer for measuring encoder minimum run time */
272 struct timer_list encoder_run_timer;
273
262 /* Place to block while waiting for state changes */ 274 /* Place to block while waiting for state changes */
263 wait_queue_head_t state_wait_data; 275 wait_queue_head_t state_wait_data;
264 276
@@ -267,6 +279,7 @@ struct pvr2_hdw {
267 int flag_disconnected; /* flag_ok == 0 due to disconnect */ 279 int flag_disconnected; /* flag_ok == 0 due to disconnect */
268 int flag_init_ok; /* true if structure is fully initialized */ 280 int flag_init_ok; /* true if structure is fully initialized */
269 int fw1_state; /* current situation with fw1 */ 281 int fw1_state; /* current situation with fw1 */
282 int pathway_state; /* one of PVR2_PATHWAY_xxx */
270 int flag_decoder_missed;/* We've noticed missing decoder */ 283 int flag_decoder_missed;/* We've noticed missing decoder */
271 int flag_tripped; /* Indicates overall failure to start */ 284 int flag_tripped; /* Indicates overall failure to start */
272 285
@@ -323,6 +336,11 @@ struct pvr2_hdw {
323 int v4l_minor_number_vbi; 336 int v4l_minor_number_vbi;
324 int v4l_minor_number_radio; 337 int v4l_minor_number_radio;
325 338
339 /* Bit mask of PVR2_CVAL_INPUT choices which are valid for the hardware */
340 unsigned int input_avail_mask;
341 /* Bit mask of PVR2_CVAL_INPUT choices which are currenly allowed */
342 unsigned int input_allowed_mask;
343
326 /* Location of eeprom or a negative number if none */ 344 /* Location of eeprom or a negative number if none */
327 int eeprom_addr; 345 int eeprom_addr;
328 346
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.c b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
index 2404053a4d85..0a868888f389 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.c
@@ -43,13 +43,13 @@
43static struct pvr2_hdw *unit_pointers[PVR_NUM] = {[ 0 ... PVR_NUM-1 ] = NULL}; 43static struct pvr2_hdw *unit_pointers[PVR_NUM] = {[ 0 ... PVR_NUM-1 ] = NULL};
44static DEFINE_MUTEX(pvr2_unit_mtx); 44static DEFINE_MUTEX(pvr2_unit_mtx);
45 45
46static int ctlchg = 0; 46static int ctlchg;
47static int initusbreset = 1; 47static int initusbreset = 1;
48static int procreload = 0; 48static int procreload;
49static int tuner[PVR_NUM] = { [0 ... PVR_NUM-1] = -1 }; 49static int tuner[PVR_NUM] = { [0 ... PVR_NUM-1] = -1 };
50static int tolerance[PVR_NUM] = { [0 ... PVR_NUM-1] = 0 }; 50static int tolerance[PVR_NUM] = { [0 ... PVR_NUM-1] = 0 };
51static int video_std[PVR_NUM] = { [0 ... PVR_NUM-1] = 0 }; 51static int video_std[PVR_NUM] = { [0 ... PVR_NUM-1] = 0 };
52static int init_pause_msec = 0; 52static int init_pause_msec;
53 53
54module_param(ctlchg, int, S_IRUGO|S_IWUSR); 54module_param(ctlchg, int, S_IRUGO|S_IWUSR);
55MODULE_PARM_DESC(ctlchg, "0=optimize ctl change 1=always accept new ctl value"); 55MODULE_PARM_DESC(ctlchg, "0=optimize ctl change 1=always accept new ctl value");
@@ -182,6 +182,7 @@ static const char *control_values_srate[] = {
182 182
183static const char *control_values_input[] = { 183static const char *control_values_input[] = {
184 [PVR2_CVAL_INPUT_TV] = "television", /*xawtv needs this name*/ 184 [PVR2_CVAL_INPUT_TV] = "television", /*xawtv needs this name*/
185 [PVR2_CVAL_INPUT_DTV] = "dtv",
185 [PVR2_CVAL_INPUT_RADIO] = "radio", 186 [PVR2_CVAL_INPUT_RADIO] = "radio",
186 [PVR2_CVAL_INPUT_SVIDEO] = "s-video", 187 [PVR2_CVAL_INPUT_SVIDEO] = "s-video",
187 [PVR2_CVAL_INPUT_COMPOSITE] = "composite", 188 [PVR2_CVAL_INPUT_COMPOSITE] = "composite",
@@ -215,12 +216,45 @@ static const char *pvr2_state_names[] = {
215}; 216};
216 217
217 218
219struct pvr2_fx2cmd_descdef {
220 unsigned char id;
221 unsigned char *desc;
222};
223
224static const struct pvr2_fx2cmd_descdef pvr2_fx2cmd_desc[] = {
225 {FX2CMD_MEM_WRITE_DWORD, "write encoder dword"},
226 {FX2CMD_MEM_READ_DWORD, "read encoder dword"},
227 {FX2CMD_MEM_READ_64BYTES, "read encoder 64bytes"},
228 {FX2CMD_REG_WRITE, "write encoder register"},
229 {FX2CMD_REG_READ, "read encoder register"},
230 {FX2CMD_MEMSEL, "encoder memsel"},
231 {FX2CMD_I2C_WRITE, "i2c write"},
232 {FX2CMD_I2C_READ, "i2c read"},
233 {FX2CMD_GET_USB_SPEED, "get USB speed"},
234 {FX2CMD_STREAMING_ON, "stream on"},
235 {FX2CMD_STREAMING_OFF, "stream off"},
236 {FX2CMD_FWPOST1, "fwpost1"},
237 {FX2CMD_POWER_OFF, "power off"},
238 {FX2CMD_POWER_ON, "power on"},
239 {FX2CMD_DEEP_RESET, "deep reset"},
240 {FX2CMD_GET_EEPROM_ADDR, "get rom addr"},
241 {FX2CMD_GET_IR_CODE, "get IR code"},
242 {FX2CMD_HCW_DEMOD_RESETIN, "hcw demod resetin"},
243 {FX2CMD_HCW_DTV_STREAMING_ON, "hcw dtv stream on"},
244 {FX2CMD_HCW_DTV_STREAMING_OFF, "hcw dtv stream off"},
245 {FX2CMD_ONAIR_DTV_STREAMING_ON, "onair dtv stream on"},
246 {FX2CMD_ONAIR_DTV_STREAMING_OFF, "onair dtv stream off"},
247 {FX2CMD_ONAIR_DTV_POWER_ON, "onair dtv power on"},
248 {FX2CMD_ONAIR_DTV_POWER_OFF, "onair dtv power off"},
249};
250
251
252static int pvr2_hdw_set_input(struct pvr2_hdw *hdw,int v);
218static void pvr2_hdw_state_sched(struct pvr2_hdw *); 253static void pvr2_hdw_state_sched(struct pvr2_hdw *);
219static int pvr2_hdw_state_eval(struct pvr2_hdw *); 254static int pvr2_hdw_state_eval(struct pvr2_hdw *);
220static void pvr2_hdw_set_cur_freq(struct pvr2_hdw *,unsigned long); 255static void pvr2_hdw_set_cur_freq(struct pvr2_hdw *,unsigned long);
221static void pvr2_hdw_worker_i2c(struct work_struct *work); 256static void pvr2_hdw_worker_i2c(struct work_struct *work);
222static void pvr2_hdw_worker_poll(struct work_struct *work); 257static void pvr2_hdw_worker_poll(struct work_struct *work);
223static void pvr2_hdw_worker_init(struct work_struct *work);
224static int pvr2_hdw_wait(struct pvr2_hdw *,int state); 258static int pvr2_hdw_wait(struct pvr2_hdw *,int state);
225static int pvr2_hdw_untrip_unlocked(struct pvr2_hdw *); 259static int pvr2_hdw_untrip_unlocked(struct pvr2_hdw *);
226static void pvr2_hdw_state_log_state(struct pvr2_hdw *); 260static void pvr2_hdw_state_log_state(struct pvr2_hdw *);
@@ -231,6 +265,8 @@ static void pvr2_hdw_internal_find_stdenum(struct pvr2_hdw *hdw);
231static void pvr2_hdw_internal_set_std_avail(struct pvr2_hdw *hdw); 265static void pvr2_hdw_internal_set_std_avail(struct pvr2_hdw *hdw);
232static void pvr2_hdw_quiescent_timeout(unsigned long); 266static void pvr2_hdw_quiescent_timeout(unsigned long);
233static void pvr2_hdw_encoder_wait_timeout(unsigned long); 267static void pvr2_hdw_encoder_wait_timeout(unsigned long);
268static void pvr2_hdw_encoder_run_timeout(unsigned long);
269static int pvr2_issue_simple_cmd(struct pvr2_hdw *,u32);
234static int pvr2_send_request_ex(struct pvr2_hdw *hdw, 270static int pvr2_send_request_ex(struct pvr2_hdw *hdw,
235 unsigned int timeout,int probe_fl, 271 unsigned int timeout,int probe_fl,
236 void *write_data,unsigned int write_len, 272 void *write_data,unsigned int write_len,
@@ -367,26 +403,14 @@ static int ctrl_get_input(struct pvr2_ctrl *cptr,int *vp)
367 return 0; 403 return 0;
368} 404}
369 405
370static int ctrl_set_input(struct pvr2_ctrl *cptr,int m,int v) 406static int ctrl_check_input(struct pvr2_ctrl *cptr,int v)
371{ 407{
372 struct pvr2_hdw *hdw = cptr->hdw; 408 return ((1 << v) & cptr->hdw->input_allowed_mask) != 0;
373 409}
374 if (hdw->input_val != v) {
375 hdw->input_val = v;
376 hdw->input_dirty = !0;
377 }
378 410
379 /* Handle side effects - if we switch to a mode that needs the RF 411static int ctrl_set_input(struct pvr2_ctrl *cptr,int m,int v)
380 tuner, then select the right frequency choice as well and mark 412{
381 it dirty. */ 413 return pvr2_hdw_set_input(cptr->hdw,v);
382 if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
383 hdw->freqSelector = 0;
384 hdw->freqDirty = !0;
385 } else if (hdw->input_val == PVR2_CVAL_INPUT_TV) {
386 hdw->freqSelector = 1;
387 hdw->freqDirty = !0;
388 }
389 return 0;
390} 414}
391 415
392static int ctrl_isdirty_input(struct pvr2_ctrl *cptr) 416static int ctrl_isdirty_input(struct pvr2_ctrl *cptr)
@@ -803,6 +827,7 @@ static const struct pvr2_ctl_info control_defs[] = {
803 .name = "input", 827 .name = "input",
804 .internal_id = PVR2_CID_INPUT, 828 .internal_id = PVR2_CID_INPUT,
805 .default_value = PVR2_CVAL_INPUT_TV, 829 .default_value = PVR2_CVAL_INPUT_TV,
830 .check_value = ctrl_check_input,
806 DEFREF(input), 831 DEFREF(input),
807 DEFENUM(control_values_input), 832 DEFENUM(control_values_input),
808 },{ 833 },{
@@ -982,7 +1007,7 @@ unsigned long pvr2_hdw_get_cur_freq(struct pvr2_hdw *hdw)
982 1007
983/* Set the currently tuned frequency and account for all possible 1008/* Set the currently tuned frequency and account for all possible
984 driver-core side effects of this action. */ 1009 driver-core side effects of this action. */
985void pvr2_hdw_set_cur_freq(struct pvr2_hdw *hdw,unsigned long val) 1010static void pvr2_hdw_set_cur_freq(struct pvr2_hdw *hdw,unsigned long val)
986{ 1011{
987 if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) { 1012 if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
988 if (hdw->freqSelector) { 1013 if (hdw->freqSelector) {
@@ -1195,6 +1220,14 @@ int pvr2_upload_firmware2(struct pvr2_hdw *hdw)
1195 time we configure the encoder, then we'll fully configure it. */ 1220 time we configure the encoder, then we'll fully configure it. */
1196 hdw->enc_cur_valid = 0; 1221 hdw->enc_cur_valid = 0;
1197 1222
1223 /* Encoder is about to be reset so note that as far as we're
1224 concerned now, the encoder has never been run. */
1225 del_timer_sync(&hdw->encoder_run_timer);
1226 if (hdw->state_encoder_runok) {
1227 hdw->state_encoder_runok = 0;
1228 trace_stbit("state_encoder_runok",hdw->state_encoder_runok);
1229 }
1230
1198 /* First prepare firmware loading */ 1231 /* First prepare firmware loading */
1199 ret |= pvr2_write_register(hdw, 0x0048, 0xffffffff); /*interrupt mask*/ 1232 ret |= pvr2_write_register(hdw, 0x0048, 0xffffffff); /*interrupt mask*/
1200 ret |= pvr2_hdw_gpio_chg_dir(hdw,0xffffffff,0x00000088); /*gpio dir*/ 1233 ret |= pvr2_hdw_gpio_chg_dir(hdw,0xffffffff,0x00000088); /*gpio dir*/
@@ -1212,19 +1245,14 @@ int pvr2_upload_firmware2(struct pvr2_hdw *hdw)
1212 ret |= pvr2_write_register(hdw, 0xaa04, 0x00057810); /*unknown*/ 1245 ret |= pvr2_write_register(hdw, 0xaa04, 0x00057810); /*unknown*/
1213 ret |= pvr2_write_register(hdw, 0xaa10, 0x00148500); /*unknown*/ 1246 ret |= pvr2_write_register(hdw, 0xaa10, 0x00148500); /*unknown*/
1214 ret |= pvr2_write_register(hdw, 0xaa18, 0x00840000); /*unknown*/ 1247 ret |= pvr2_write_register(hdw, 0xaa18, 0x00840000); /*unknown*/
1215 LOCK_TAKE(hdw->ctl_lock); do { 1248 ret |= pvr2_issue_simple_cmd(hdw,FX2CMD_FWPOST1);
1216 hdw->cmd_buffer[0] = FX2CMD_FWPOST1; 1249 ret |= pvr2_issue_simple_cmd(hdw,FX2CMD_MEMSEL | (1 << 8) | (0 << 16));
1217 ret |= pvr2_send_request(hdw,hdw->cmd_buffer,1,NULL,0);
1218 hdw->cmd_buffer[0] = FX2CMD_MEMSEL;
1219 hdw->cmd_buffer[1] = 0;
1220 ret |= pvr2_send_request(hdw,hdw->cmd_buffer,2,NULL,0);
1221 } while (0); LOCK_GIVE(hdw->ctl_lock);
1222 1250
1223 if (ret) { 1251 if (ret) {
1224 pvr2_trace(PVR2_TRACE_ERROR_LEGS, 1252 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1225 "firmware2 upload prep failed, ret=%d",ret); 1253 "firmware2 upload prep failed, ret=%d",ret);
1226 release_firmware(fw_entry); 1254 release_firmware(fw_entry);
1227 return ret; 1255 goto done;
1228 } 1256 }
1229 1257
1230 /* Now send firmware */ 1258 /* Now send firmware */
@@ -1237,7 +1265,8 @@ int pvr2_upload_firmware2(struct pvr2_hdw *hdw)
1237 " must be a multiple of %zu bytes", 1265 " must be a multiple of %zu bytes",
1238 fw_files[fwidx],sizeof(u32)); 1266 fw_files[fwidx],sizeof(u32));
1239 release_firmware(fw_entry); 1267 release_firmware(fw_entry);
1240 return -1; 1268 ret = -EINVAL;
1269 goto done;
1241 } 1270 }
1242 1271
1243 fw_ptr = kmalloc(FIRMWARE_CHUNK_SIZE, GFP_KERNEL); 1272 fw_ptr = kmalloc(FIRMWARE_CHUNK_SIZE, GFP_KERNEL);
@@ -1245,7 +1274,8 @@ int pvr2_upload_firmware2(struct pvr2_hdw *hdw)
1245 release_firmware(fw_entry); 1274 release_firmware(fw_entry);
1246 pvr2_trace(PVR2_TRACE_ERROR_LEGS, 1275 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1247 "failed to allocate memory for firmware2 upload"); 1276 "failed to allocate memory for firmware2 upload");
1248 return -ENOMEM; 1277 ret = -ENOMEM;
1278 goto done;
1249 } 1279 }
1250 1280
1251 pipe = usb_sndbulkpipe(hdw->usb_dev, PVR2_FIRMWARE_ENDPOINT); 1281 pipe = usb_sndbulkpipe(hdw->usb_dev, PVR2_FIRMWARE_ENDPOINT);
@@ -1276,23 +1306,27 @@ int pvr2_upload_firmware2(struct pvr2_hdw *hdw)
1276 if (ret) { 1306 if (ret) {
1277 pvr2_trace(PVR2_TRACE_ERROR_LEGS, 1307 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1278 "firmware2 upload transfer failure"); 1308 "firmware2 upload transfer failure");
1279 return ret; 1309 goto done;
1280 } 1310 }
1281 1311
1282 /* Finish upload */ 1312 /* Finish upload */
1283 1313
1284 ret |= pvr2_write_register(hdw, 0x9054, 0xffffffff); /*reset hw blocks*/ 1314 ret |= pvr2_write_register(hdw, 0x9054, 0xffffffff); /*reset hw blocks*/
1285 ret |= pvr2_write_register(hdw, 0x9058, 0xffffffe8); /*VPU ctrl*/ 1315 ret |= pvr2_write_register(hdw, 0x9058, 0xffffffe8); /*VPU ctrl*/
1286 LOCK_TAKE(hdw->ctl_lock); do { 1316 ret |= pvr2_issue_simple_cmd(hdw,FX2CMD_MEMSEL | (1 << 8) | (0 << 16));
1287 hdw->cmd_buffer[0] = FX2CMD_MEMSEL;
1288 hdw->cmd_buffer[1] = 0;
1289 ret |= pvr2_send_request(hdw,hdw->cmd_buffer,2,NULL,0);
1290 } while (0); LOCK_GIVE(hdw->ctl_lock);
1291 1317
1292 if (ret) { 1318 if (ret) {
1293 pvr2_trace(PVR2_TRACE_ERROR_LEGS, 1319 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
1294 "firmware2 upload post-proc failure"); 1320 "firmware2 upload post-proc failure");
1295 } 1321 }
1322
1323 done:
1324 if (hdw->hdw_desc->signal_routing_scheme ==
1325 PVR2_ROUTING_SCHEME_GOTVIEW) {
1326 /* Ensure that GPIO 11 is set to output for GOTVIEW
1327 hardware. */
1328 pvr2_hdw_gpio_chg_dir(hdw,(1 << 11),~0);
1329 }
1296 return ret; 1330 return ret;
1297} 1331}
1298 1332
@@ -1364,11 +1398,6 @@ int pvr2_hdw_untrip(struct pvr2_hdw *hdw)
1364} 1398}
1365 1399
1366 1400
1367const char *pvr2_hdw_get_state_name(unsigned int id)
1368{
1369 if (id >= ARRAY_SIZE(pvr2_state_names)) return NULL;
1370 return pvr2_state_names[id];
1371}
1372 1401
1373 1402
1374int pvr2_hdw_get_streaming(struct pvr2_hdw *hdw) 1403int pvr2_hdw_get_streaming(struct pvr2_hdw *hdw)
@@ -1495,7 +1524,7 @@ struct pvr2_std_hack {
1495 default - which can always be overridden explicitly - and if the user 1524 default - which can always be overridden explicitly - and if the user
1496 has otherwise named a default then that default will always be used in 1525 has otherwise named a default then that default will always be used in
1497 place of this table. */ 1526 place of this table. */
1498const static struct pvr2_std_hack std_eeprom_maps[] = { 1527static const struct pvr2_std_hack std_eeprom_maps[] = {
1499 { /* PAL(B/G) */ 1528 { /* PAL(B/G) */
1500 .pat = V4L2_STD_B|V4L2_STD_GH, 1529 .pat = V4L2_STD_B|V4L2_STD_GH,
1501 .std = V4L2_STD_PAL_B|V4L2_STD_PAL_B1|V4L2_STD_PAL_G, 1530 .std = V4L2_STD_PAL_B|V4L2_STD_PAL_B1|V4L2_STD_PAL_G,
@@ -1712,6 +1741,13 @@ static void pvr2_hdw_setup_low(struct pvr2_hdw *hdw)
1712 1741
1713 if (!pvr2_hdw_dev_ok(hdw)) return; 1742 if (!pvr2_hdw_dev_ok(hdw)) return;
1714 1743
1744 if (hdw->hdw_desc->signal_routing_scheme ==
1745 PVR2_ROUTING_SCHEME_GOTVIEW) {
1746 /* Ensure that GPIO 11 is set to output for GOTVIEW
1747 hardware. */
1748 pvr2_hdw_gpio_chg_dir(hdw,(1 << 11),~0);
1749 }
1750
1715 pvr2_hdw_commit_setup(hdw); 1751 pvr2_hdw_commit_setup(hdw);
1716 1752
1717 hdw->vid_stream = pvr2_stream_create(); 1753 hdw->vid_stream = pvr2_stream_create();
@@ -1805,12 +1841,37 @@ static void pvr2_hdw_setup(struct pvr2_hdw *hdw)
1805} 1841}
1806 1842
1807 1843
1808/* Create and return a structure for interacting with the underlying 1844/* Perform second stage initialization. Set callback pointer first so that
1809 hardware */ 1845 we can avoid a possible initialization race (if the kernel thread runs
1846 before the callback has been set). */
1847int pvr2_hdw_initialize(struct pvr2_hdw *hdw,
1848 void (*callback_func)(void *),
1849 void *callback_data)
1850{
1851 LOCK_TAKE(hdw->big_lock); do {
1852 if (hdw->flag_disconnected) {
1853 /* Handle a race here: If we're already
1854 disconnected by this point, then give up. If we
1855 get past this then we'll remain connected for
1856 the duration of initialization since the entire
1857 initialization sequence is now protected by the
1858 big_lock. */
1859 break;
1860 }
1861 hdw->state_data = callback_data;
1862 hdw->state_func = callback_func;
1863 pvr2_hdw_setup(hdw);
1864 } while (0); LOCK_GIVE(hdw->big_lock);
1865 return hdw->flag_init_ok;
1866}
1867
1868
1869/* Create, set up, and return a structure for interacting with the
1870 underlying hardware. */
1810struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf, 1871struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
1811 const struct usb_device_id *devid) 1872 const struct usb_device_id *devid)
1812{ 1873{
1813 unsigned int idx,cnt1,cnt2; 1874 unsigned int idx,cnt1,cnt2,m;
1814 struct pvr2_hdw *hdw; 1875 struct pvr2_hdw *hdw;
1815 int valid_std_mask; 1876 int valid_std_mask;
1816 struct pvr2_ctrl *cptr; 1877 struct pvr2_ctrl *cptr;
@@ -1834,6 +1895,10 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
1834 hdw->encoder_wait_timer.data = (unsigned long)hdw; 1895 hdw->encoder_wait_timer.data = (unsigned long)hdw;
1835 hdw->encoder_wait_timer.function = pvr2_hdw_encoder_wait_timeout; 1896 hdw->encoder_wait_timer.function = pvr2_hdw_encoder_wait_timeout;
1836 1897
1898 init_timer(&hdw->encoder_run_timer);
1899 hdw->encoder_run_timer.data = (unsigned long)hdw;
1900 hdw->encoder_run_timer.function = pvr2_hdw_encoder_run_timeout;
1901
1837 hdw->master_state = PVR2_STATE_DEAD; 1902 hdw->master_state = PVR2_STATE_DEAD;
1838 1903
1839 init_waitqueue_head(&hdw->state_wait_data); 1904 init_waitqueue_head(&hdw->state_wait_data);
@@ -1841,6 +1906,26 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
1841 hdw->tuner_signal_stale = !0; 1906 hdw->tuner_signal_stale = !0;
1842 cx2341x_fill_defaults(&hdw->enc_ctl_state); 1907 cx2341x_fill_defaults(&hdw->enc_ctl_state);
1843 1908
1909 /* Calculate which inputs are OK */
1910 m = 0;
1911 if (hdw_desc->flag_has_analogtuner) m |= 1 << PVR2_CVAL_INPUT_TV;
1912 if (hdw_desc->digital_control_scheme != PVR2_DIGITAL_SCHEME_NONE) {
1913 m |= 1 << PVR2_CVAL_INPUT_DTV;
1914 }
1915 if (hdw_desc->flag_has_svideo) m |= 1 << PVR2_CVAL_INPUT_SVIDEO;
1916 if (hdw_desc->flag_has_composite) m |= 1 << PVR2_CVAL_INPUT_COMPOSITE;
1917 if (hdw_desc->flag_has_fmradio) m |= 1 << PVR2_CVAL_INPUT_RADIO;
1918 hdw->input_avail_mask = m;
1919 hdw->input_allowed_mask = hdw->input_avail_mask;
1920
1921 /* If not a hybrid device, pathway_state never changes. So
1922 initialize it here to what it should forever be. */
1923 if (!(hdw->input_avail_mask & (1 << PVR2_CVAL_INPUT_DTV))) {
1924 hdw->pathway_state = PVR2_PATHWAY_ANALOG;
1925 } else if (!(hdw->input_avail_mask & (1 << PVR2_CVAL_INPUT_TV))) {
1926 hdw->pathway_state = PVR2_PATHWAY_DIGITAL;
1927 }
1928
1844 hdw->control_cnt = CTRLDEF_COUNT; 1929 hdw->control_cnt = CTRLDEF_COUNT;
1845 hdw->control_cnt += MPEGDEF_COUNT; 1930 hdw->control_cnt += MPEGDEF_COUNT;
1846 hdw->controls = kzalloc(sizeof(struct pvr2_ctrl) * hdw->control_cnt, 1931 hdw->controls = kzalloc(sizeof(struct pvr2_ctrl) * hdw->control_cnt,
@@ -1858,6 +1943,15 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
1858 cptr = hdw->controls + idx; 1943 cptr = hdw->controls + idx;
1859 cptr->info = control_defs+idx; 1944 cptr->info = control_defs+idx;
1860 } 1945 }
1946
1947 /* Ensure that default input choice is a valid one. */
1948 m = hdw->input_avail_mask;
1949 if (m) for (idx = 0; idx < (sizeof(m) << 3); idx++) {
1950 if (!((1 << idx) & m)) continue;
1951 hdw->input_val = idx;
1952 break;
1953 }
1954
1861 /* Define and configure additional controls from cx2341x module. */ 1955 /* Define and configure additional controls from cx2341x module. */
1862 hdw->mpeg_ctrl_info = kzalloc( 1956 hdw->mpeg_ctrl_info = kzalloc(
1863 sizeof(*(hdw->mpeg_ctrl_info)) * MPEGDEF_COUNT, GFP_KERNEL); 1957 sizeof(*(hdw->mpeg_ctrl_info)) * MPEGDEF_COUNT, GFP_KERNEL);
@@ -1981,7 +2075,6 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
1981 hdw->workqueue = create_singlethread_workqueue(hdw->name); 2075 hdw->workqueue = create_singlethread_workqueue(hdw->name);
1982 INIT_WORK(&hdw->workpoll,pvr2_hdw_worker_poll); 2076 INIT_WORK(&hdw->workpoll,pvr2_hdw_worker_poll);
1983 INIT_WORK(&hdw->worki2csync,pvr2_hdw_worker_i2c); 2077 INIT_WORK(&hdw->worki2csync,pvr2_hdw_worker_i2c);
1984 INIT_WORK(&hdw->workinit,pvr2_hdw_worker_init);
1985 2078
1986 pvr2_trace(PVR2_TRACE_INIT,"Driver unit number is %d, name is %s", 2079 pvr2_trace(PVR2_TRACE_INIT,"Driver unit number is %d, name is %s",
1987 hdw->unit_number,hdw->name); 2080 hdw->unit_number,hdw->name);
@@ -2003,11 +2096,11 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
2003 mutex_init(&hdw->ctl_lock_mutex); 2096 mutex_init(&hdw->ctl_lock_mutex);
2004 mutex_init(&hdw->big_lock_mutex); 2097 mutex_init(&hdw->big_lock_mutex);
2005 2098
2006 queue_work(hdw->workqueue,&hdw->workinit);
2007 return hdw; 2099 return hdw;
2008 fail: 2100 fail:
2009 if (hdw) { 2101 if (hdw) {
2010 del_timer_sync(&hdw->quiescent_timer); 2102 del_timer_sync(&hdw->quiescent_timer);
2103 del_timer_sync(&hdw->encoder_run_timer);
2011 del_timer_sync(&hdw->encoder_wait_timer); 2104 del_timer_sync(&hdw->encoder_wait_timer);
2012 if (hdw->workqueue) { 2105 if (hdw->workqueue) {
2013 flush_workqueue(hdw->workqueue); 2106 flush_workqueue(hdw->workqueue);
@@ -2064,13 +2157,14 @@ void pvr2_hdw_destroy(struct pvr2_hdw *hdw)
2064{ 2157{
2065 if (!hdw) return; 2158 if (!hdw) return;
2066 pvr2_trace(PVR2_TRACE_INIT,"pvr2_hdw_destroy: hdw=%p",hdw); 2159 pvr2_trace(PVR2_TRACE_INIT,"pvr2_hdw_destroy: hdw=%p",hdw);
2067 del_timer_sync(&hdw->quiescent_timer);
2068 del_timer_sync(&hdw->encoder_wait_timer);
2069 if (hdw->workqueue) { 2160 if (hdw->workqueue) {
2070 flush_workqueue(hdw->workqueue); 2161 flush_workqueue(hdw->workqueue);
2071 destroy_workqueue(hdw->workqueue); 2162 destroy_workqueue(hdw->workqueue);
2072 hdw->workqueue = NULL; 2163 hdw->workqueue = NULL;
2073 } 2164 }
2165 del_timer_sync(&hdw->quiescent_timer);
2166 del_timer_sync(&hdw->encoder_run_timer);
2167 del_timer_sync(&hdw->encoder_wait_timer);
2074 if (hdw->fw_buffer) { 2168 if (hdw->fw_buffer) {
2075 kfree(hdw->fw_buffer); 2169 kfree(hdw->fw_buffer);
2076 hdw->fw_buffer = NULL; 2170 hdw->fw_buffer = NULL;
@@ -2352,6 +2446,18 @@ static int pvr2_hdw_commit_execute(struct pvr2_hdw *hdw)
2352 } 2446 }
2353 } 2447 }
2354 2448
2449 if (hdw->input_dirty && hdw->state_pathway_ok &&
2450 (((hdw->input_val == PVR2_CVAL_INPUT_DTV) ?
2451 PVR2_PATHWAY_DIGITAL : PVR2_PATHWAY_ANALOG) !=
2452 hdw->pathway_state)) {
2453 /* Change of mode being asked for... */
2454 hdw->state_pathway_ok = 0;
2455 trace_stbit("state_pathway_ok",hdw->state_pathway_ok);
2456 }
2457 if (!hdw->state_pathway_ok) {
2458 /* Can't commit anything until pathway is ok. */
2459 return 0;
2460 }
2355 /* If any of the below has changed, then we can't do the update 2461 /* If any of the below has changed, then we can't do the update
2356 while the pipeline is running. Pipeline must be paused first 2462 while the pipeline is running. Pipeline must be paused first
2357 and decoder -> encoder connection be made quiescent before we 2463 and decoder -> encoder connection be made quiescent before we
@@ -2405,12 +2511,28 @@ static int pvr2_hdw_commit_execute(struct pvr2_hdw *hdw)
2405 hdw->active_stream_type = hdw->desired_stream_type; 2511 hdw->active_stream_type = hdw->desired_stream_type;
2406 } 2512 }
2407 2513
2514 if (hdw->hdw_desc->signal_routing_scheme ==
2515 PVR2_ROUTING_SCHEME_GOTVIEW) {
2516 u32 b;
2517 /* Handle GOTVIEW audio switching */
2518 pvr2_hdw_gpio_get_out(hdw,&b);
2519 if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
2520 /* Set GPIO 11 */
2521 pvr2_hdw_gpio_chg_out(hdw,(1 << 11),~0);
2522 } else {
2523 /* Clear GPIO 11 */
2524 pvr2_hdw_gpio_chg_out(hdw,(1 << 11),0);
2525 }
2526 }
2527
2408 /* Now execute i2c core update */ 2528 /* Now execute i2c core update */
2409 pvr2_i2c_core_sync(hdw); 2529 pvr2_i2c_core_sync(hdw);
2410 2530
2411 if (hdw->state_encoder_run) { 2531 if ((hdw->pathway_state == PVR2_PATHWAY_ANALOG) &&
2412 /* If encoder isn't running, then this will get worked out 2532 hdw->state_encoder_run) {
2413 later when we start the encoder. */ 2533 /* If encoder isn't running or it can't be touched, then
2534 this will get worked out later when we start the
2535 encoder. */
2414 if (pvr2_encoder_adjust(hdw) < 0) return !0; 2536 if (pvr2_encoder_adjust(hdw) < 0) return !0;
2415 } 2537 }
2416 2538
@@ -2453,15 +2575,6 @@ static void pvr2_hdw_worker_poll(struct work_struct *work)
2453} 2575}
2454 2576
2455 2577
2456static void pvr2_hdw_worker_init(struct work_struct *work)
2457{
2458 struct pvr2_hdw *hdw = container_of(work,struct pvr2_hdw,workinit);
2459 LOCK_TAKE(hdw->big_lock); do {
2460 pvr2_hdw_setup(hdw);
2461 } while (0); LOCK_GIVE(hdw->big_lock);
2462}
2463
2464
2465static int pvr2_hdw_wait(struct pvr2_hdw *hdw,int state) 2578static int pvr2_hdw_wait(struct pvr2_hdw *hdw,int state)
2466{ 2579{
2467 return wait_event_interruptible( 2580 return wait_event_interruptible(
@@ -2471,17 +2584,6 @@ static int pvr2_hdw_wait(struct pvr2_hdw *hdw,int state)
2471} 2584}
2472 2585
2473 2586
2474void pvr2_hdw_set_state_callback(struct pvr2_hdw *hdw,
2475 void (*callback_func)(void *),
2476 void *callback_data)
2477{
2478 LOCK_TAKE(hdw->big_lock); do {
2479 hdw->state_data = callback_data;
2480 hdw->state_func = callback_func;
2481 } while (0); LOCK_GIVE(hdw->big_lock);
2482}
2483
2484
2485/* Return name for this driver instance */ 2587/* Return name for this driver instance */
2486const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *hdw) 2588const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *hdw)
2487{ 2589{
@@ -3050,6 +3152,67 @@ int pvr2_send_request(struct pvr2_hdw *hdw,
3050 read_data,read_len); 3152 read_data,read_len);
3051} 3153}
3052 3154
3155
3156static int pvr2_issue_simple_cmd(struct pvr2_hdw *hdw,u32 cmdcode)
3157{
3158 int ret;
3159 unsigned int cnt = 1;
3160 unsigned int args = 0;
3161 LOCK_TAKE(hdw->ctl_lock);
3162 hdw->cmd_buffer[0] = cmdcode & 0xffu;
3163 args = (cmdcode >> 8) & 0xffu;
3164 args = (args > 2) ? 2 : args;
3165 if (args) {
3166 cnt += args;
3167 hdw->cmd_buffer[1] = (cmdcode >> 16) & 0xffu;
3168 if (args > 1) {
3169 hdw->cmd_buffer[2] = (cmdcode >> 24) & 0xffu;
3170 }
3171 }
3172 if (pvrusb2_debug & PVR2_TRACE_INIT) {
3173 unsigned int idx;
3174 unsigned int ccnt,bcnt;
3175 char tbuf[50];
3176 cmdcode &= 0xffu;
3177 bcnt = 0;
3178 ccnt = scnprintf(tbuf+bcnt,
3179 sizeof(tbuf)-bcnt,
3180 "Sending FX2 command 0x%x",cmdcode);
3181 bcnt += ccnt;
3182 for (idx = 0; idx < ARRAY_SIZE(pvr2_fx2cmd_desc); idx++) {
3183 if (pvr2_fx2cmd_desc[idx].id == cmdcode) {
3184 ccnt = scnprintf(tbuf+bcnt,
3185 sizeof(tbuf)-bcnt,
3186 " \"%s\"",
3187 pvr2_fx2cmd_desc[idx].desc);
3188 bcnt += ccnt;
3189 break;
3190 }
3191 }
3192 if (args) {
3193 ccnt = scnprintf(tbuf+bcnt,
3194 sizeof(tbuf)-bcnt,
3195 " (%u",hdw->cmd_buffer[1]);
3196 bcnt += ccnt;
3197 if (args > 1) {
3198 ccnt = scnprintf(tbuf+bcnt,
3199 sizeof(tbuf)-bcnt,
3200 ",%u",hdw->cmd_buffer[2]);
3201 bcnt += ccnt;
3202 }
3203 ccnt = scnprintf(tbuf+bcnt,
3204 sizeof(tbuf)-bcnt,
3205 ")");
3206 bcnt += ccnt;
3207 }
3208 pvr2_trace(PVR2_TRACE_INIT,"%.*s",bcnt,tbuf);
3209 }
3210 ret = pvr2_send_request(hdw,hdw->cmd_buffer,cnt,NULL,0);
3211 LOCK_GIVE(hdw->ctl_lock);
3212 return ret;
3213}
3214
3215
3053int pvr2_write_register(struct pvr2_hdw *hdw, u16 reg, u32 data) 3216int pvr2_write_register(struct pvr2_hdw *hdw, u16 reg, u32 data)
3054{ 3217{
3055 int ret; 3218 int ret;
@@ -3157,25 +3320,19 @@ void pvr2_hdw_cpureset_assert(struct pvr2_hdw *hdw,int val)
3157 3320
3158int pvr2_hdw_cmd_deep_reset(struct pvr2_hdw *hdw) 3321int pvr2_hdw_cmd_deep_reset(struct pvr2_hdw *hdw)
3159{ 3322{
3160 int status; 3323 return pvr2_issue_simple_cmd(hdw,FX2CMD_DEEP_RESET);
3161 LOCK_TAKE(hdw->ctl_lock); do {
3162 pvr2_trace(PVR2_TRACE_INIT,"Requesting uproc hard reset");
3163 hdw->cmd_buffer[0] = FX2CMD_DEEP_RESET;
3164 status = pvr2_send_request(hdw,hdw->cmd_buffer,1,NULL,0);
3165 } while (0); LOCK_GIVE(hdw->ctl_lock);
3166 return status;
3167} 3324}
3168 3325
3169 3326
3170int pvr2_hdw_cmd_powerup(struct pvr2_hdw *hdw) 3327int pvr2_hdw_cmd_powerup(struct pvr2_hdw *hdw)
3171{ 3328{
3172 int status; 3329 return pvr2_issue_simple_cmd(hdw,FX2CMD_POWER_ON);
3173 LOCK_TAKE(hdw->ctl_lock); do { 3330}
3174 pvr2_trace(PVR2_TRACE_INIT,"Requesting powerup"); 3331
3175 hdw->cmd_buffer[0] = FX2CMD_POWER_ON; 3332
3176 status = pvr2_send_request(hdw,hdw->cmd_buffer,1,NULL,0); 3333int pvr2_hdw_cmd_powerdown(struct pvr2_hdw *hdw)
3177 } while (0); LOCK_GIVE(hdw->ctl_lock); 3334{
3178 return status; 3335 return pvr2_issue_simple_cmd(hdw,FX2CMD_POWER_OFF);
3179} 3336}
3180 3337
3181 3338
@@ -3200,16 +3357,173 @@ int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *hdw)
3200} 3357}
3201 3358
3202 3359
3360static int pvr2_hdw_cmd_hcw_demod_reset(struct pvr2_hdw *hdw, int onoff)
3361{
3362 hdw->flag_ok = !0;
3363 return pvr2_issue_simple_cmd(hdw,
3364 FX2CMD_HCW_DEMOD_RESETIN |
3365 (1 << 8) |
3366 ((onoff ? 1 : 0) << 16));
3367}
3368
3369
3370static int pvr2_hdw_cmd_onair_fe_power_ctrl(struct pvr2_hdw *hdw, int onoff)
3371{
3372 hdw->flag_ok = !0;
3373 return pvr2_issue_simple_cmd(hdw,(onoff ?
3374 FX2CMD_ONAIR_DTV_POWER_ON :
3375 FX2CMD_ONAIR_DTV_POWER_OFF));
3376}
3377
3378
3379static int pvr2_hdw_cmd_onair_digital_path_ctrl(struct pvr2_hdw *hdw,
3380 int onoff)
3381{
3382 return pvr2_issue_simple_cmd(hdw,(onoff ?
3383 FX2CMD_ONAIR_DTV_STREAMING_ON :
3384 FX2CMD_ONAIR_DTV_STREAMING_OFF));
3385}
3386
3387
3388static void pvr2_hdw_cmd_modeswitch(struct pvr2_hdw *hdw,int digitalFl)
3389{
3390 int cmode;
3391 /* Compare digital/analog desired setting with current setting. If
3392 they don't match, fix it... */
3393 cmode = (digitalFl ? PVR2_PATHWAY_DIGITAL : PVR2_PATHWAY_ANALOG);
3394 if (cmode == hdw->pathway_state) {
3395 /* They match; nothing to do */
3396 return;
3397 }
3398
3399 switch (hdw->hdw_desc->digital_control_scheme) {
3400 case PVR2_DIGITAL_SCHEME_HAUPPAUGE:
3401 pvr2_hdw_cmd_hcw_demod_reset(hdw,digitalFl);
3402 if (cmode == PVR2_PATHWAY_ANALOG) {
3403 /* If moving to analog mode, also force the decoder
3404 to reset. If no decoder is attached, then it's
3405 ok to ignore this because if/when the decoder
3406 attaches, it will reset itself at that time. */
3407 pvr2_hdw_cmd_decoder_reset(hdw);
3408 }
3409 break;
3410 case PVR2_DIGITAL_SCHEME_ONAIR:
3411 /* Supposedly we should always have the power on whether in
3412 digital or analog mode. But for now do what appears to
3413 work... */
3414 pvr2_hdw_cmd_onair_fe_power_ctrl(hdw,digitalFl);
3415 break;
3416 default: break;
3417 }
3418
3419 pvr2_hdw_untrip_unlocked(hdw);
3420 hdw->pathway_state = cmode;
3421}
3422
3423
3424void pvr2_led_ctrl_hauppauge(struct pvr2_hdw *hdw, int onoff)
3425{
3426 /* change some GPIO data
3427 *
3428 * note: bit d7 of dir appears to control the LED,
3429 * so we shut it off here.
3430 *
3431 */
3432 if (onoff) {
3433 pvr2_hdw_gpio_chg_dir(hdw, 0xffffffff, 0x00000481);
3434 } else {
3435 pvr2_hdw_gpio_chg_dir(hdw, 0xffffffff, 0x00000401);
3436 }
3437 pvr2_hdw_gpio_chg_out(hdw, 0xffffffff, 0x00000000);
3438}
3439
3440
3441typedef void (*led_method_func)(struct pvr2_hdw *,int);
3442
3443static led_method_func led_methods[] = {
3444 [PVR2_LED_SCHEME_HAUPPAUGE] = pvr2_led_ctrl_hauppauge,
3445};
3446
3447
3448/* Toggle LED */
3449static void pvr2_led_ctrl(struct pvr2_hdw *hdw,int onoff)
3450{
3451 unsigned int scheme_id;
3452 led_method_func fp;
3453
3454 if ((!onoff) == (!hdw->led_on)) return;
3455
3456 hdw->led_on = onoff != 0;
3457
3458 scheme_id = hdw->hdw_desc->led_scheme;
3459 if (scheme_id < ARRAY_SIZE(led_methods)) {
3460 fp = led_methods[scheme_id];
3461 } else {
3462 fp = NULL;
3463 }
3464
3465 if (fp) (*fp)(hdw,onoff);
3466}
3467
3468
3203/* Stop / start video stream transport */ 3469/* Stop / start video stream transport */
3204static int pvr2_hdw_cmd_usbstream(struct pvr2_hdw *hdw,int runFl) 3470static int pvr2_hdw_cmd_usbstream(struct pvr2_hdw *hdw,int runFl)
3205{ 3471{
3206 int status; 3472 int ret;
3207 LOCK_TAKE(hdw->ctl_lock); do { 3473
3208 hdw->cmd_buffer[0] = 3474 /* If we're in analog mode, then just issue the usual analog
3209 (runFl ? FX2CMD_STREAMING_ON : FX2CMD_STREAMING_OFF); 3475 command. */
3210 status = pvr2_send_request(hdw,hdw->cmd_buffer,1,NULL,0); 3476 if (hdw->pathway_state == PVR2_PATHWAY_ANALOG) {
3211 } while (0); LOCK_GIVE(hdw->ctl_lock); 3477 return pvr2_issue_simple_cmd(hdw,
3212 return status; 3478 (runFl ?
3479 FX2CMD_STREAMING_ON :
3480 FX2CMD_STREAMING_OFF));
3481 /*Note: Not reached */
3482 }
3483
3484 if (hdw->pathway_state != PVR2_PATHWAY_DIGITAL) {
3485 /* Whoops, we don't know what mode we're in... */
3486 return -EINVAL;
3487 }
3488
3489 /* To get here we have to be in digital mode. The mechanism here
3490 is unfortunately different for different vendors. So we switch
3491 on the device's digital scheme attribute in order to figure out
3492 what to do. */
3493 switch (hdw->hdw_desc->digital_control_scheme) {
3494 case PVR2_DIGITAL_SCHEME_HAUPPAUGE:
3495 return pvr2_issue_simple_cmd(hdw,
3496 (runFl ?
3497 FX2CMD_HCW_DTV_STREAMING_ON :
3498 FX2CMD_HCW_DTV_STREAMING_OFF));
3499 case PVR2_DIGITAL_SCHEME_ONAIR:
3500 ret = pvr2_issue_simple_cmd(hdw,
3501 (runFl ?
3502 FX2CMD_STREAMING_ON :
3503 FX2CMD_STREAMING_OFF));
3504 if (ret) return ret;
3505 return pvr2_hdw_cmd_onair_digital_path_ctrl(hdw,runFl);
3506 default:
3507 return -EINVAL;
3508 }
3509}
3510
3511
3512/* Evaluate whether or not state_pathway_ok can change */
3513static int state_eval_pathway_ok(struct pvr2_hdw *hdw)
3514{
3515 if (hdw->state_pathway_ok) {
3516 /* Nothing to do if pathway is already ok */
3517 return 0;
3518 }
3519 if (!hdw->state_pipeline_idle) {
3520 /* Not allowed to change anything if pipeline is not idle */
3521 return 0;
3522 }
3523 pvr2_hdw_cmd_modeswitch(hdw,hdw->input_val == PVR2_CVAL_INPUT_DTV);
3524 hdw->state_pathway_ok = !0;
3525 trace_stbit("state_pathway_ok",hdw->state_pathway_ok);
3526 return !0;
3213} 3527}
3214 3528
3215 3529
@@ -3222,6 +3536,12 @@ static int state_eval_encoder_ok(struct pvr2_hdw *hdw)
3222 if (hdw->state_encoder_config) return 0; 3536 if (hdw->state_encoder_config) return 0;
3223 if (hdw->state_decoder_run) return 0; 3537 if (hdw->state_decoder_run) return 0;
3224 if (hdw->state_usbstream_run) return 0; 3538 if (hdw->state_usbstream_run) return 0;
3539 if (hdw->pathway_state == PVR2_PATHWAY_DIGITAL) {
3540 if (!hdw->hdw_desc->flag_digital_requires_cx23416) return 0;
3541 } else if (hdw->pathway_state != PVR2_PATHWAY_ANALOG) {
3542 return 0;
3543 }
3544
3225 if (pvr2_upload_firmware2(hdw) < 0) { 3545 if (pvr2_upload_firmware2(hdw) < 0) {
3226 hdw->flag_tripped = !0; 3546 hdw->flag_tripped = !0;
3227 trace_stbit("flag_tripped",hdw->flag_tripped); 3547 trace_stbit("flag_tripped",hdw->flag_tripped);
@@ -3247,7 +3567,9 @@ static int state_eval_encoder_config(struct pvr2_hdw *hdw)
3247 /* paranoia - solve race if timer just completed */ 3567 /* paranoia - solve race if timer just completed */
3248 del_timer_sync(&hdw->encoder_wait_timer); 3568 del_timer_sync(&hdw->encoder_wait_timer);
3249 } else { 3569 } else {
3250 if (!hdw->state_encoder_ok || 3570 if (!hdw->state_pathway_ok ||
3571 (hdw->pathway_state != PVR2_PATHWAY_ANALOG) ||
3572 !hdw->state_encoder_ok ||
3251 !hdw->state_pipeline_idle || 3573 !hdw->state_pipeline_idle ||
3252 hdw->state_pipeline_pause || 3574 hdw->state_pipeline_pause ||
3253 !hdw->state_pipeline_req || 3575 !hdw->state_pipeline_req ||
@@ -3296,20 +3618,116 @@ static int state_eval_encoder_config(struct pvr2_hdw *hdw)
3296} 3618}
3297 3619
3298 3620
3621/* Return true if the encoder should not be running. */
3622static int state_check_disable_encoder_run(struct pvr2_hdw *hdw)
3623{
3624 if (!hdw->state_encoder_ok) {
3625 /* Encoder isn't healthy at the moment, so stop it. */
3626 return !0;
3627 }
3628 if (!hdw->state_pathway_ok) {
3629 /* Mode is not understood at the moment (i.e. it wants to
3630 change), so encoder must be stopped. */
3631 return !0;
3632 }
3633
3634 switch (hdw->pathway_state) {
3635 case PVR2_PATHWAY_ANALOG:
3636 if (!hdw->state_decoder_run) {
3637 /* We're in analog mode and the decoder is not
3638 running; thus the encoder should be stopped as
3639 well. */
3640 return !0;
3641 }
3642 break;
3643 case PVR2_PATHWAY_DIGITAL:
3644 if (hdw->state_encoder_runok) {
3645 /* This is a funny case. We're in digital mode so
3646 really the encoder should be stopped. However
3647 if it really is running, only kill it after
3648 runok has been set. This gives a chance for the
3649 onair quirk to function (encoder must run
3650 briefly first, at least once, before onair
3651 digital streaming can work). */
3652 return !0;
3653 }
3654 break;
3655 default:
3656 /* Unknown mode; so encoder should be stopped. */
3657 return !0;
3658 }
3659
3660 /* If we get here, we haven't found a reason to stop the
3661 encoder. */
3662 return 0;
3663}
3664
3665
3666/* Return true if the encoder should be running. */
3667static int state_check_enable_encoder_run(struct pvr2_hdw *hdw)
3668{
3669 if (!hdw->state_encoder_ok) {
3670 /* Don't run the encoder if it isn't healthy... */
3671 return 0;
3672 }
3673 if (!hdw->state_pathway_ok) {
3674 /* Don't run the encoder if we don't (yet) know what mode
3675 we need to be in... */
3676 return 0;
3677 }
3678
3679 switch (hdw->pathway_state) {
3680 case PVR2_PATHWAY_ANALOG:
3681 if (hdw->state_decoder_run) {
3682 /* In analog mode, if the decoder is running, then
3683 run the encoder. */
3684 return !0;
3685 }
3686 break;
3687 case PVR2_PATHWAY_DIGITAL:
3688 if ((hdw->hdw_desc->digital_control_scheme ==
3689 PVR2_DIGITAL_SCHEME_ONAIR) &&
3690 !hdw->state_encoder_runok) {
3691 /* This is a quirk. OnAir hardware won't stream
3692 digital until the encoder has been run at least
3693 once, for a minimal period of time (empiricially
3694 measured to be 1/4 second). So if we're on
3695 OnAir hardware and the encoder has never been
3696 run at all, then start the encoder. Normal
3697 state machine logic in the driver will
3698 automatically handle the remaining bits. */
3699 return !0;
3700 }
3701 break;
3702 default:
3703 /* For completeness (unknown mode; encoder won't run ever) */
3704 break;
3705 }
3706 /* If we get here, then we haven't found any reason to run the
3707 encoder, so don't run it. */
3708 return 0;
3709}
3710
3711
3299/* Evaluate whether or not state_encoder_run can change */ 3712/* Evaluate whether or not state_encoder_run can change */
3300static int state_eval_encoder_run(struct pvr2_hdw *hdw) 3713static int state_eval_encoder_run(struct pvr2_hdw *hdw)
3301{ 3714{
3302 if (hdw->state_encoder_run) { 3715 if (hdw->state_encoder_run) {
3716 if (!state_check_disable_encoder_run(hdw)) return 0;
3303 if (hdw->state_encoder_ok) { 3717 if (hdw->state_encoder_ok) {
3304 if (hdw->state_decoder_run) return 0; 3718 del_timer_sync(&hdw->encoder_run_timer);
3305 if (pvr2_encoder_stop(hdw) < 0) return !0; 3719 if (pvr2_encoder_stop(hdw) < 0) return !0;
3306 } 3720 }
3307 hdw->state_encoder_run = 0; 3721 hdw->state_encoder_run = 0;
3308 } else { 3722 } else {
3309 if (!hdw->state_encoder_ok) return 0; 3723 if (!state_check_enable_encoder_run(hdw)) return 0;
3310 if (!hdw->state_decoder_run) return 0;
3311 if (pvr2_encoder_start(hdw) < 0) return !0; 3724 if (pvr2_encoder_start(hdw) < 0) return !0;
3312 hdw->state_encoder_run = !0; 3725 hdw->state_encoder_run = !0;
3726 if (!hdw->state_encoder_runok) {
3727 hdw->encoder_run_timer.expires =
3728 jiffies + (HZ*250/1000);
3729 add_timer(&hdw->encoder_run_timer);
3730 }
3313 } 3731 }
3314 trace_stbit("state_encoder_run",hdw->state_encoder_run); 3732 trace_stbit("state_encoder_run",hdw->state_encoder_run);
3315 return !0; 3733 return !0;
@@ -3338,13 +3756,27 @@ static void pvr2_hdw_encoder_wait_timeout(unsigned long data)
3338} 3756}
3339 3757
3340 3758
3759/* Timeout function for encoder run timer. */
3760static void pvr2_hdw_encoder_run_timeout(unsigned long data)
3761{
3762 struct pvr2_hdw *hdw = (struct pvr2_hdw *)data;
3763 if (!hdw->state_encoder_runok) {
3764 hdw->state_encoder_runok = !0;
3765 trace_stbit("state_encoder_runok",hdw->state_encoder_runok);
3766 hdw->state_stale = !0;
3767 queue_work(hdw->workqueue,&hdw->workpoll);
3768 }
3769}
3770
3771
3341/* Evaluate whether or not state_decoder_run can change */ 3772/* Evaluate whether or not state_decoder_run can change */
3342static int state_eval_decoder_run(struct pvr2_hdw *hdw) 3773static int state_eval_decoder_run(struct pvr2_hdw *hdw)
3343{ 3774{
3344 if (hdw->state_decoder_run) { 3775 if (hdw->state_decoder_run) {
3345 if (hdw->state_encoder_ok) { 3776 if (hdw->state_encoder_ok) {
3346 if (hdw->state_pipeline_req && 3777 if (hdw->state_pipeline_req &&
3347 !hdw->state_pipeline_pause) return 0; 3778 !hdw->state_pipeline_pause &&
3779 hdw->state_pathway_ok) return 0;
3348 } 3780 }
3349 if (!hdw->flag_decoder_missed) { 3781 if (!hdw->flag_decoder_missed) {
3350 pvr2_decoder_enable(hdw,0); 3782 pvr2_decoder_enable(hdw,0);
@@ -3377,7 +3809,9 @@ static int state_eval_decoder_run(struct pvr2_hdw *hdw)
3377 hopefully further stabilize the encoder. */ 3809 hopefully further stabilize the encoder. */
3378 return 0; 3810 return 0;
3379 } 3811 }
3380 if (!hdw->state_pipeline_req || 3812 if (!hdw->state_pathway_ok ||
3813 (hdw->pathway_state != PVR2_PATHWAY_ANALOG) ||
3814 !hdw->state_pipeline_req ||
3381 hdw->state_pipeline_pause || 3815 hdw->state_pipeline_pause ||
3382 !hdw->state_pipeline_config || 3816 !hdw->state_pipeline_config ||
3383 !hdw->state_encoder_config || 3817 !hdw->state_encoder_config ||
@@ -3398,16 +3832,43 @@ static int state_eval_decoder_run(struct pvr2_hdw *hdw)
3398static int state_eval_usbstream_run(struct pvr2_hdw *hdw) 3832static int state_eval_usbstream_run(struct pvr2_hdw *hdw)
3399{ 3833{
3400 if (hdw->state_usbstream_run) { 3834 if (hdw->state_usbstream_run) {
3401 if (hdw->state_encoder_ok) { 3835 int fl = !0;
3402 if (hdw->state_encoder_run) return 0; 3836 if (hdw->pathway_state == PVR2_PATHWAY_ANALOG) {
3837 fl = (hdw->state_encoder_ok &&
3838 hdw->state_encoder_run);
3839 } else if ((hdw->pathway_state == PVR2_PATHWAY_DIGITAL) &&
3840 (hdw->hdw_desc->flag_digital_requires_cx23416)) {
3841 fl = hdw->state_encoder_ok;
3842 }
3843 if (fl &&
3844 hdw->state_pipeline_req &&
3845 !hdw->state_pipeline_pause &&
3846 hdw->state_pathway_ok) {
3847 return 0;
3403 } 3848 }
3404 pvr2_hdw_cmd_usbstream(hdw,0); 3849 pvr2_hdw_cmd_usbstream(hdw,0);
3405 hdw->state_usbstream_run = 0; 3850 hdw->state_usbstream_run = 0;
3406 } else { 3851 } else {
3407 if (!hdw->state_encoder_ok || 3852 if (!hdw->state_pipeline_req ||
3408 !hdw->state_encoder_run || 3853 hdw->state_pipeline_pause ||
3409 !hdw->state_pipeline_req || 3854 !hdw->state_pathway_ok) return 0;
3410 hdw->state_pipeline_pause) return 0; 3855 if (hdw->pathway_state == PVR2_PATHWAY_ANALOG) {
3856 if (!hdw->state_encoder_ok ||
3857 !hdw->state_encoder_run) return 0;
3858 } else if ((hdw->pathway_state == PVR2_PATHWAY_DIGITAL) &&
3859 (hdw->hdw_desc->flag_digital_requires_cx23416)) {
3860 if (!hdw->state_encoder_ok) return 0;
3861 if (hdw->state_encoder_run) return 0;
3862 if (hdw->hdw_desc->digital_control_scheme ==
3863 PVR2_DIGITAL_SCHEME_ONAIR) {
3864 /* OnAir digital receivers won't stream
3865 unless the analog encoder has run first.
3866 Why? I have no idea. But don't even
3867 try until we know the analog side is
3868 known to have run. */
3869 if (!hdw->state_encoder_runok) return 0;
3870 }
3871 }
3411 if (pvr2_hdw_cmd_usbstream(hdw,!0) < 0) return 0; 3872 if (pvr2_hdw_cmd_usbstream(hdw,!0) < 0) return 0;
3412 hdw->state_usbstream_run = !0; 3873 hdw->state_usbstream_run = !0;
3413 } 3874 }
@@ -3453,7 +3914,8 @@ static int state_update_pipeline_state(struct pvr2_hdw *hdw)
3453typedef int (*state_eval_func)(struct pvr2_hdw *); 3914typedef int (*state_eval_func)(struct pvr2_hdw *);
3454 3915
3455/* Set of functions to be run to evaluate various states in the driver. */ 3916/* Set of functions to be run to evaluate various states in the driver. */
3456const static state_eval_func eval_funcs[] = { 3917static const state_eval_func eval_funcs[] = {
3918 state_eval_pathway_ok,
3457 state_eval_pipeline_config, 3919 state_eval_pipeline_config,
3458 state_eval_encoder_ok, 3920 state_eval_encoder_ok,
3459 state_eval_encoder_config, 3921 state_eval_encoder_config,
@@ -3501,6 +3963,34 @@ static int pvr2_hdw_state_update(struct pvr2_hdw *hdw)
3501} 3963}
3502 3964
3503 3965
3966static unsigned int print_input_mask(unsigned int msk,
3967 char *buf,unsigned int acnt)
3968{
3969 unsigned int idx,ccnt;
3970 unsigned int tcnt = 0;
3971 for (idx = 0; idx < ARRAY_SIZE(control_values_input); idx++) {
3972 if (!((1 << idx) & msk)) continue;
3973 ccnt = scnprintf(buf+tcnt,
3974 acnt-tcnt,
3975 "%s%s",
3976 (tcnt ? ", " : ""),
3977 control_values_input[idx]);
3978 tcnt += ccnt;
3979 }
3980 return tcnt;
3981}
3982
3983
3984static const char *pvr2_pathway_state_name(int id)
3985{
3986 switch (id) {
3987 case PVR2_PATHWAY_ANALOG: return "analog";
3988 case PVR2_PATHWAY_DIGITAL: return "digital";
3989 default: return "unknown";
3990 }
3991}
3992
3993
3504static unsigned int pvr2_hdw_report_unlocked(struct pvr2_hdw *hdw,int which, 3994static unsigned int pvr2_hdw_report_unlocked(struct pvr2_hdw *hdw,int which,
3505 char *buf,unsigned int acnt) 3995 char *buf,unsigned int acnt)
3506{ 3996{
@@ -3508,13 +3998,15 @@ static unsigned int pvr2_hdw_report_unlocked(struct pvr2_hdw *hdw,int which,
3508 case 0: 3998 case 0:
3509 return scnprintf( 3999 return scnprintf(
3510 buf,acnt, 4000 buf,acnt,
3511 "driver:%s%s%s%s%s", 4001 "driver:%s%s%s%s%s <mode=%s>",
3512 (hdw->flag_ok ? " <ok>" : " <fail>"), 4002 (hdw->flag_ok ? " <ok>" : " <fail>"),
3513 (hdw->flag_init_ok ? " <init>" : " <uninitialized>"), 4003 (hdw->flag_init_ok ? " <init>" : " <uninitialized>"),
3514 (hdw->flag_disconnected ? " <disconnected>" : 4004 (hdw->flag_disconnected ? " <disconnected>" :
3515 " <connected>"), 4005 " <connected>"),
3516 (hdw->flag_tripped ? " <tripped>" : ""), 4006 (hdw->flag_tripped ? " <tripped>" : ""),
3517 (hdw->flag_decoder_missed ? " <no decoder>" : "")); 4007 (hdw->flag_decoder_missed ? " <no decoder>" : ""),
4008 pvr2_pathway_state_name(hdw->pathway_state));
4009
3518 case 1: 4010 case 1:
3519 return scnprintf( 4011 return scnprintf(
3520 buf,acnt, 4012 buf,acnt,
@@ -3527,7 +4019,7 @@ static unsigned int pvr2_hdw_report_unlocked(struct pvr2_hdw *hdw,int which,
3527 case 2: 4019 case 2:
3528 return scnprintf( 4020 return scnprintf(
3529 buf,acnt, 4021 buf,acnt,
3530 "worker:%s%s%s%s%s%s", 4022 "worker:%s%s%s%s%s%s%s",
3531 (hdw->state_decoder_run ? 4023 (hdw->state_decoder_run ?
3532 " <decode:run>" : 4024 " <decode:run>" :
3533 (hdw->state_decoder_quiescent ? 4025 (hdw->state_decoder_quiescent ?
@@ -3537,20 +4029,65 @@ static unsigned int pvr2_hdw_report_unlocked(struct pvr2_hdw *hdw,int which,
3537 (hdw->state_encoder_ok ? 4029 (hdw->state_encoder_ok ?
3538 "" : " <encode:init>"), 4030 "" : " <encode:init>"),
3539 (hdw->state_encoder_run ? 4031 (hdw->state_encoder_run ?
3540 " <encode:run>" : " <encode:stop>"), 4032 (hdw->state_encoder_runok ?
4033 " <encode:run>" :
4034 " <encode:firstrun>") :
4035 (hdw->state_encoder_runok ?
4036 " <encode:stop>" :
4037 " <encode:virgin>")),
3541 (hdw->state_encoder_config ? 4038 (hdw->state_encoder_config ?
3542 " <encode:configok>" : 4039 " <encode:configok>" :
3543 (hdw->state_encoder_waitok ? 4040 (hdw->state_encoder_waitok ?
3544 "" : " <encode:wait>")), 4041 "" : " <encode:waitok>")),
3545 (hdw->state_usbstream_run ? 4042 (hdw->state_usbstream_run ?
3546 " <usb:run>" : " <usb:stop>")); 4043 " <usb:run>" : " <usb:stop>"),
3547 break; 4044 (hdw->state_pathway_ok ?
4045 " <pathway:ok>" : ""));
3548 case 3: 4046 case 3:
3549 return scnprintf( 4047 return scnprintf(
3550 buf,acnt, 4048 buf,acnt,
3551 "state: %s", 4049 "state: %s",
3552 pvr2_get_state_name(hdw->master_state)); 4050 pvr2_get_state_name(hdw->master_state));
3553 break; 4051 case 4: {
4052 unsigned int tcnt = 0;
4053 unsigned int ccnt;
4054
4055 ccnt = scnprintf(buf,
4056 acnt,
4057 "Hardware supported inputs: ");
4058 tcnt += ccnt;
4059 tcnt += print_input_mask(hdw->input_avail_mask,
4060 buf+tcnt,
4061 acnt-tcnt);
4062 if (hdw->input_avail_mask != hdw->input_allowed_mask) {
4063 ccnt = scnprintf(buf+tcnt,
4064 acnt-tcnt,
4065 "; allowed inputs: ");
4066 tcnt += ccnt;
4067 tcnt += print_input_mask(hdw->input_allowed_mask,
4068 buf+tcnt,
4069 acnt-tcnt);
4070 }
4071 return tcnt;
4072 }
4073 case 5: {
4074 struct pvr2_stream_stats stats;
4075 if (!hdw->vid_stream) break;
4076 pvr2_stream_get_stats(hdw->vid_stream,
4077 &stats,
4078 0);
4079 return scnprintf(
4080 buf,acnt,
4081 "Bytes streamed=%u"
4082 " URBs: queued=%u idle=%u ready=%u"
4083 " processed=%u failed=%u",
4084 stats.bytes_processed,
4085 stats.buffers_in_queue,
4086 stats.buffers_in_idle,
4087 stats.buffers_in_ready,
4088 stats.buffers_processed,
4089 stats.buffers_failed);
4090 }
3554 default: break; 4091 default: break;
3555 } 4092 }
3556 return 0; 4093 return 0;
@@ -3596,6 +4133,7 @@ static int pvr2_hdw_state_eval(struct pvr2_hdw *hdw)
3596 unsigned int st; 4133 unsigned int st;
3597 int state_updated = 0; 4134 int state_updated = 0;
3598 int callback_flag = 0; 4135 int callback_flag = 0;
4136 int analog_mode;
3599 4137
3600 pvr2_trace(PVR2_TRACE_STBITS, 4138 pvr2_trace(PVR2_TRACE_STBITS,
3601 "Drive state check START"); 4139 "Drive state check START");
@@ -3606,18 +4144,23 @@ static int pvr2_hdw_state_eval(struct pvr2_hdw *hdw)
3606 /* Process all state and get back over disposition */ 4144 /* Process all state and get back over disposition */
3607 state_updated = pvr2_hdw_state_update(hdw); 4145 state_updated = pvr2_hdw_state_update(hdw);
3608 4146
4147 analog_mode = (hdw->pathway_state != PVR2_PATHWAY_DIGITAL);
4148
3609 /* Update master state based upon all other states. */ 4149 /* Update master state based upon all other states. */
3610 if (!hdw->flag_ok) { 4150 if (!hdw->flag_ok) {
3611 st = PVR2_STATE_DEAD; 4151 st = PVR2_STATE_DEAD;
3612 } else if (hdw->fw1_state != FW1_STATE_OK) { 4152 } else if (hdw->fw1_state != FW1_STATE_OK) {
3613 st = PVR2_STATE_COLD; 4153 st = PVR2_STATE_COLD;
3614 } else if (!hdw->state_encoder_ok) { 4154 } else if ((analog_mode ||
4155 hdw->hdw_desc->flag_digital_requires_cx23416) &&
4156 !hdw->state_encoder_ok) {
3615 st = PVR2_STATE_WARM; 4157 st = PVR2_STATE_WARM;
3616 } else if (hdw->flag_tripped || hdw->flag_decoder_missed) { 4158 } else if (hdw->flag_tripped ||
4159 (analog_mode && hdw->flag_decoder_missed)) {
3617 st = PVR2_STATE_ERROR; 4160 st = PVR2_STATE_ERROR;
3618 } else if (hdw->state_encoder_run && 4161 } else if (hdw->state_usbstream_run &&
3619 hdw->state_decoder_run && 4162 (!analog_mode ||
3620 hdw->state_usbstream_run) { 4163 (hdw->state_encoder_run && hdw->state_decoder_run))) {
3621 st = PVR2_STATE_RUN; 4164 st = PVR2_STATE_RUN;
3622 } else { 4165 } else {
3623 st = PVR2_STATE_READY; 4166 st = PVR2_STATE_READY;
@@ -3627,6 +4170,7 @@ static int pvr2_hdw_state_eval(struct pvr2_hdw *hdw)
3627 "Device state change from %s to %s", 4170 "Device state change from %s to %s",
3628 pvr2_get_state_name(hdw->master_state), 4171 pvr2_get_state_name(hdw->master_state),
3629 pvr2_get_state_name(st)); 4172 pvr2_get_state_name(st));
4173 pvr2_led_ctrl(hdw,st == PVR2_STATE_RUN);
3630 hdw->master_state = st; 4174 hdw->master_state = st;
3631 state_updated = !0; 4175 state_updated = !0;
3632 callback_flag = !0; 4176 callback_flag = !0;
@@ -3656,47 +4200,6 @@ static void pvr2_hdw_state_sched(struct pvr2_hdw *hdw)
3656} 4200}
3657 4201
3658 4202
3659void pvr2_hdw_get_debug_info_unlocked(const struct pvr2_hdw *hdw,
3660 struct pvr2_hdw_debug_info *ptr)
3661{
3662 ptr->big_lock_held = hdw->big_lock_held;
3663 ptr->ctl_lock_held = hdw->ctl_lock_held;
3664 ptr->flag_disconnected = hdw->flag_disconnected;
3665 ptr->flag_init_ok = hdw->flag_init_ok;
3666 ptr->flag_ok = hdw->flag_ok;
3667 ptr->fw1_state = hdw->fw1_state;
3668 ptr->flag_decoder_missed = hdw->flag_decoder_missed;
3669 ptr->flag_tripped = hdw->flag_tripped;
3670 ptr->state_encoder_ok = hdw->state_encoder_ok;
3671 ptr->state_encoder_run = hdw->state_encoder_run;
3672 ptr->state_decoder_run = hdw->state_decoder_run;
3673 ptr->state_usbstream_run = hdw->state_usbstream_run;
3674 ptr->state_decoder_quiescent = hdw->state_decoder_quiescent;
3675 ptr->state_pipeline_config = hdw->state_pipeline_config;
3676 ptr->state_pipeline_req = hdw->state_pipeline_req;
3677 ptr->state_pipeline_pause = hdw->state_pipeline_pause;
3678 ptr->state_pipeline_idle = hdw->state_pipeline_idle;
3679 ptr->cmd_debug_state = hdw->cmd_debug_state;
3680 ptr->cmd_code = hdw->cmd_debug_code;
3681 ptr->cmd_debug_write_len = hdw->cmd_debug_write_len;
3682 ptr->cmd_debug_read_len = hdw->cmd_debug_read_len;
3683 ptr->cmd_debug_timeout = hdw->ctl_timeout_flag;
3684 ptr->cmd_debug_write_pend = hdw->ctl_write_pend_flag;
3685 ptr->cmd_debug_read_pend = hdw->ctl_read_pend_flag;
3686 ptr->cmd_debug_rstatus = hdw->ctl_read_urb->status;
3687 ptr->cmd_debug_wstatus = hdw->ctl_read_urb->status;
3688}
3689
3690
3691void pvr2_hdw_get_debug_info_locked(struct pvr2_hdw *hdw,
3692 struct pvr2_hdw_debug_info *ptr)
3693{
3694 LOCK_TAKE(hdw->ctl_lock); do {
3695 pvr2_hdw_get_debug_info_unlocked(hdw,ptr);
3696 } while(0); LOCK_GIVE(hdw->ctl_lock);
3697}
3698
3699
3700int pvr2_hdw_gpio_get_dir(struct pvr2_hdw *hdw,u32 *dp) 4203int pvr2_hdw_gpio_get_dir(struct pvr2_hdw *hdw,u32 *dp)
3701{ 4204{
3702 return pvr2_read_register(hdw,PVR2_GPIO_DIR,dp); 4205 return pvr2_read_register(hdw,PVR2_GPIO_DIR,dp);
@@ -3756,6 +4259,80 @@ int pvr2_hdw_gpio_chg_out(struct pvr2_hdw *hdw,u32 msk,u32 val)
3756} 4259}
3757 4260
3758 4261
4262unsigned int pvr2_hdw_get_input_available(struct pvr2_hdw *hdw)
4263{
4264 return hdw->input_avail_mask;
4265}
4266
4267
4268unsigned int pvr2_hdw_get_input_allowed(struct pvr2_hdw *hdw)
4269{
4270 return hdw->input_allowed_mask;
4271}
4272
4273
4274static int pvr2_hdw_set_input(struct pvr2_hdw *hdw,int v)
4275{
4276 if (hdw->input_val != v) {
4277 hdw->input_val = v;
4278 hdw->input_dirty = !0;
4279 }
4280
4281 /* Handle side effects - if we switch to a mode that needs the RF
4282 tuner, then select the right frequency choice as well and mark
4283 it dirty. */
4284 if (hdw->input_val == PVR2_CVAL_INPUT_RADIO) {
4285 hdw->freqSelector = 0;
4286 hdw->freqDirty = !0;
4287 } else if ((hdw->input_val == PVR2_CVAL_INPUT_TV) ||
4288 (hdw->input_val == PVR2_CVAL_INPUT_DTV)) {
4289 hdw->freqSelector = 1;
4290 hdw->freqDirty = !0;
4291 }
4292 return 0;
4293}
4294
4295
4296int pvr2_hdw_set_input_allowed(struct pvr2_hdw *hdw,
4297 unsigned int change_mask,
4298 unsigned int change_val)
4299{
4300 int ret = 0;
4301 unsigned int nv,m,idx;
4302 LOCK_TAKE(hdw->big_lock);
4303 do {
4304 nv = hdw->input_allowed_mask & ~change_mask;
4305 nv |= (change_val & change_mask);
4306 nv &= hdw->input_avail_mask;
4307 if (!nv) {
4308 /* No legal modes left; return error instead. */
4309 ret = -EPERM;
4310 break;
4311 }
4312 hdw->input_allowed_mask = nv;
4313 if ((1 << hdw->input_val) & hdw->input_allowed_mask) {
4314 /* Current mode is still in the allowed mask, so
4315 we're done. */
4316 break;
4317 }
4318 /* Select and switch to a mode that is still in the allowed
4319 mask */
4320 if (!hdw->input_allowed_mask) {
4321 /* Nothing legal; give up */
4322 break;
4323 }
4324 m = hdw->input_allowed_mask;
4325 for (idx = 0; idx < (sizeof(m) << 3); idx++) {
4326 if (!((1 << idx) & m)) continue;
4327 pvr2_hdw_set_input(hdw,idx);
4328 break;
4329 }
4330 } while (0);
4331 LOCK_GIVE(hdw->big_lock);
4332 return ret;
4333}
4334
4335
3759/* Find I2C address of eeprom */ 4336/* Find I2C address of eeprom */
3760static int pvr2_hdw_get_eeprom_addr(struct pvr2_hdw *hdw) 4337static int pvr2_hdw_get_eeprom_addr(struct pvr2_hdw *hdw)
3761{ 4338{
diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw.h b/drivers/media/video/pvrusb2/pvrusb2-hdw.h
index 3ad7a13d6c39..20295e0c1995 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-hdw.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-hdw.h
@@ -40,9 +40,10 @@
40 40
41/* Legal values for the INPUT state variable */ 41/* Legal values for the INPUT state variable */
42#define PVR2_CVAL_INPUT_TV 0 42#define PVR2_CVAL_INPUT_TV 0
43#define PVR2_CVAL_INPUT_SVIDEO 1 43#define PVR2_CVAL_INPUT_DTV 1
44#define PVR2_CVAL_INPUT_COMPOSITE 2 44#define PVR2_CVAL_INPUT_COMPOSITE 2
45#define PVR2_CVAL_INPUT_RADIO 3 45#define PVR2_CVAL_INPUT_SVIDEO 3
46#define PVR2_CVAL_INPUT_RADIO 4
46 47
47enum pvr2_config { 48enum pvr2_config {
48 pvr2_config_empty, /* No configuration */ 49 pvr2_config_empty, /* No configuration */
@@ -90,9 +91,6 @@ enum pvr2_v4l_type {
90/* Translate configuration enum to a string label */ 91/* Translate configuration enum to a string label */
91const char *pvr2_config_get_name(enum pvr2_config); 92const char *pvr2_config_get_name(enum pvr2_config);
92 93
93/* Translate a master state enum to a string label */
94const char *pvr2_hdw_get_state_name(unsigned int);
95
96struct pvr2_hdw; 94struct pvr2_hdw;
97 95
98/* Create and return a structure for interacting with the underlying 96/* Create and return a structure for interacting with the underlying
@@ -100,14 +98,15 @@ struct pvr2_hdw;
100struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf, 98struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
101 const struct usb_device_id *devid); 99 const struct usb_device_id *devid);
102 100
101/* Perform second stage initialization, passing in a notification callback
102 for when the master state changes. */
103int pvr2_hdw_initialize(struct pvr2_hdw *,
104 void (*callback_func)(void *),
105 void *callback_data);
106
103/* Destroy hardware interaction structure */ 107/* Destroy hardware interaction structure */
104void pvr2_hdw_destroy(struct pvr2_hdw *); 108void pvr2_hdw_destroy(struct pvr2_hdw *);
105 109
106/* Register a function to be called whenever the master state changes. */
107void pvr2_hdw_set_state_callback(struct pvr2_hdw *,
108 void (*callback_func)(void *),
109 void *callback_data);
110
111/* Return true if in the ready (normal) state */ 110/* Return true if in the ready (normal) state */
112int pvr2_hdw_dev_ok(struct pvr2_hdw *); 111int pvr2_hdw_dev_ok(struct pvr2_hdw *);
113 112
@@ -146,6 +145,23 @@ struct pvr2_ctrl *pvr2_hdw_get_ctrl_nextv4l(struct pvr2_hdw *,
146/* Commit all control changes made up to this point */ 145/* Commit all control changes made up to this point */
147int pvr2_hdw_commit_ctl(struct pvr2_hdw *); 146int pvr2_hdw_commit_ctl(struct pvr2_hdw *);
148 147
148/* Return a bit mask of valid input selections for this device. Mask bits
149 * will be according to PVR_CVAL_INPUT_xxxx definitions. */
150unsigned int pvr2_hdw_get_input_available(struct pvr2_hdw *);
151
152/* Return a bit mask of allowed input selections for this device. Mask bits
153 * will be according to PVR_CVAL_INPUT_xxxx definitions. */
154unsigned int pvr2_hdw_get_input_allowed(struct pvr2_hdw *);
155
156/* Change the set of allowed input selections for this device. Both
157 change_mask and change_valu are mask bits according to
158 PVR_CVAL_INPUT_xxxx definitions. The change_mask parameter indicate
159 which settings are being changed and the change_val parameter indicates
160 whether corresponding settings are being set or cleared. */
161int pvr2_hdw_set_input_allowed(struct pvr2_hdw *,
162 unsigned int change_mask,
163 unsigned int change_val);
164
149/* Return name for this driver instance */ 165/* Return name for this driver instance */
150const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *); 166const char *pvr2_hdw_get_driver_name(struct pvr2_hdw *);
151 167
@@ -250,6 +266,9 @@ int pvr2_hdw_cmd_deep_reset(struct pvr2_hdw *);
250/* Execute simple reset command */ 266/* Execute simple reset command */
251int pvr2_hdw_cmd_powerup(struct pvr2_hdw *); 267int pvr2_hdw_cmd_powerup(struct pvr2_hdw *);
252 268
269/* suspend */
270int pvr2_hdw_cmd_powerdown(struct pvr2_hdw *);
271
253/* Order decoder to reset */ 272/* Order decoder to reset */
254int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *); 273int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *);
255 274
diff --git a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
index 62867fa3517a..793c89a8d672 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
@@ -35,7 +35,7 @@
35 35
36*/ 36*/
37 37
38static unsigned int i2c_scan = 0; 38static unsigned int i2c_scan;
39module_param(i2c_scan, int, S_IRUGO|S_IWUSR); 39module_param(i2c_scan, int, S_IRUGO|S_IWUSR);
40MODULE_PARM_DESC(i2c_scan,"scan i2c bus at insmod time"); 40MODULE_PARM_DESC(i2c_scan,"scan i2c bus at insmod time");
41 41
diff --git a/drivers/media/video/pvrusb2/pvrusb2-io.c b/drivers/media/video/pvrusb2/pvrusb2-io.c
index a9889ff96ecc..7aff8b720064 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-io.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-io.c
@@ -80,6 +80,10 @@ struct pvr2_stream {
80 /* Tracking state for tolerating errors */ 80 /* Tracking state for tolerating errors */
81 unsigned int fail_count; 81 unsigned int fail_count;
82 unsigned int fail_tolerance; 82 unsigned int fail_tolerance;
83
84 unsigned int buffers_processed;
85 unsigned int buffers_failed;
86 unsigned int bytes_processed;
83}; 87};
84 88
85struct pvr2_buffer { 89struct pvr2_buffer {
@@ -446,6 +450,8 @@ static void buffer_complete(struct urb *urb)
446 (urb->status == -ENOENT) || 450 (urb->status == -ENOENT) ||
447 (urb->status == -ECONNRESET) || 451 (urb->status == -ECONNRESET) ||
448 (urb->status == -ESHUTDOWN)) { 452 (urb->status == -ESHUTDOWN)) {
453 (sp->buffers_processed)++;
454 sp->bytes_processed += urb->actual_length;
449 bp->used_count = urb->actual_length; 455 bp->used_count = urb->actual_length;
450 if (sp->fail_count) { 456 if (sp->fail_count) {
451 pvr2_trace(PVR2_TRACE_TOLERANCE, 457 pvr2_trace(PVR2_TRACE_TOLERANCE,
@@ -457,11 +463,13 @@ static void buffer_complete(struct urb *urb)
457 // We can tolerate this error, because we're below the 463 // We can tolerate this error, because we're below the
458 // threshold... 464 // threshold...
459 (sp->fail_count)++; 465 (sp->fail_count)++;
466 (sp->buffers_failed)++;
460 pvr2_trace(PVR2_TRACE_TOLERANCE, 467 pvr2_trace(PVR2_TRACE_TOLERANCE,
461 "stream %p ignoring error %d" 468 "stream %p ignoring error %d"
462 " - fail count increased to %u", 469 " - fail count increased to %u",
463 sp,urb->status,sp->fail_count); 470 sp,urb->status,sp->fail_count);
464 } else { 471 } else {
472 (sp->buffers_failed)++;
465 bp->status = urb->status; 473 bp->status = urb->status;
466 } 474 }
467 spin_unlock_irqrestore(&sp->list_lock,irq_flags); 475 spin_unlock_irqrestore(&sp->list_lock,irq_flags);
@@ -515,6 +523,28 @@ void pvr2_stream_set_callback(struct pvr2_stream *sp,
515 } while(0); mutex_unlock(&sp->mutex); 523 } while(0); mutex_unlock(&sp->mutex);
516} 524}
517 525
526void pvr2_stream_get_stats(struct pvr2_stream *sp,
527 struct pvr2_stream_stats *stats,
528 int zero_counts)
529{
530 unsigned long irq_flags;
531 spin_lock_irqsave(&sp->list_lock,irq_flags);
532 if (stats) {
533 stats->buffers_in_queue = sp->q_count;
534 stats->buffers_in_idle = sp->i_count;
535 stats->buffers_in_ready = sp->r_count;
536 stats->buffers_processed = sp->buffers_processed;
537 stats->buffers_failed = sp->buffers_failed;
538 stats->bytes_processed = sp->bytes_processed;
539 }
540 if (zero_counts) {
541 sp->buffers_processed = 0;
542 sp->buffers_failed = 0;
543 sp->bytes_processed = 0;
544 }
545 spin_unlock_irqrestore(&sp->list_lock,irq_flags);
546}
547
518/* Query / set the nominal buffer count */ 548/* Query / set the nominal buffer count */
519int pvr2_stream_get_buffer_count(struct pvr2_stream *sp) 549int pvr2_stream_get_buffer_count(struct pvr2_stream *sp)
520{ 550{
diff --git a/drivers/media/video/pvrusb2/pvrusb2-io.h b/drivers/media/video/pvrusb2/pvrusb2-io.h
index 93279cc2a35e..42fcf8281a87 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-io.h
+++ b/drivers/media/video/pvrusb2/pvrusb2-io.h
@@ -36,6 +36,15 @@ enum pvr2_buffer_state {
36struct pvr2_stream; 36struct pvr2_stream;
37struct pvr2_buffer; 37struct pvr2_buffer;
38 38
39struct pvr2_stream_stats {
40 unsigned int buffers_in_queue;
41 unsigned int buffers_in_idle;
42 unsigned int buffers_in_ready;
43 unsigned int buffers_processed;
44 unsigned int buffers_failed;
45 unsigned int bytes_processed;
46};
47
39/* Initialize / tear down stream structure */ 48/* Initialize / tear down stream structure */
40struct pvr2_stream *pvr2_stream_create(void); 49struct pvr2_stream *pvr2_stream_create(void);
41void pvr2_stream_destroy(struct pvr2_stream *); 50void pvr2_stream_destroy(struct pvr2_stream *);
@@ -45,6 +54,9 @@ void pvr2_stream_setup(struct pvr2_stream *,
45void pvr2_stream_set_callback(struct pvr2_stream *, 54void pvr2_stream_set_callback(struct pvr2_stream *,
46 pvr2_stream_callback func, 55 pvr2_stream_callback func,
47 void *data); 56 void *data);
57void pvr2_stream_get_stats(struct pvr2_stream *,
58 struct pvr2_stream_stats *,
59 int zero_counts);
48 60
49/* Query / set the nominal buffer count */ 61/* Query / set the nominal buffer count */
50int pvr2_stream_get_buffer_count(struct pvr2_stream *); 62int pvr2_stream_get_buffer_count(struct pvr2_stream *);
diff --git a/drivers/media/video/pvrusb2/pvrusb2-main.c b/drivers/media/video/pvrusb2/pvrusb2-main.c
index b63b2265503a..332aced8a5a1 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-main.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-main.c
@@ -60,6 +60,10 @@ static void pvr_setup_attach(struct pvr2_context *pvr)
60{ 60{
61 /* Create association with v4l layer */ 61 /* Create association with v4l layer */
62 pvr2_v4l2_create(pvr); 62 pvr2_v4l2_create(pvr);
63#ifdef CONFIG_VIDEO_PVRUSB2_DVB
64 /* Create association with dvb layer */
65 pvr2_dvb_create(pvr);
66#endif
63#ifdef CONFIG_VIDEO_PVRUSB2_SYSFS 67#ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
64 pvr2_sysfs_create(pvr,class_ptr); 68 pvr2_sysfs_create(pvr,class_ptr);
65#endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */ 69#endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
@@ -121,6 +125,12 @@ static int __init pvr_init(void)
121 125
122 pvr2_trace(PVR2_TRACE_INIT,"pvr_init"); 126 pvr2_trace(PVR2_TRACE_INIT,"pvr_init");
123 127
128 ret = pvr2_context_global_init();
129 if (ret != 0) {
130 pvr2_trace(PVR2_TRACE_INIT,"pvr_init failure code=%d",ret);
131 return ret;
132 }
133
124#ifdef CONFIG_VIDEO_PVRUSB2_SYSFS 134#ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
125 class_ptr = pvr2_sysfs_class_create(); 135 class_ptr = pvr2_sysfs_class_create();
126#endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */ 136#endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
@@ -132,6 +142,8 @@ static int __init pvr_init(void)
132 if (pvrusb2_debug) info("Debug mask is %d (0x%x)", 142 if (pvrusb2_debug) info("Debug mask is %d (0x%x)",
133 pvrusb2_debug,pvrusb2_debug); 143 pvrusb2_debug,pvrusb2_debug);
134 144
145 pvr2_trace(PVR2_TRACE_INIT,"pvr_init complete");
146
135 return ret; 147 return ret;
136} 148}
137 149
@@ -144,6 +156,10 @@ static void __exit pvr_exit(void)
144#ifdef CONFIG_VIDEO_PVRUSB2_SYSFS 156#ifdef CONFIG_VIDEO_PVRUSB2_SYSFS
145 pvr2_sysfs_class_destroy(class_ptr); 157 pvr2_sysfs_class_destroy(class_ptr);
146#endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */ 158#endif /* CONFIG_VIDEO_PVRUSB2_SYSFS */
159
160 pvr2_context_global_done();
161
162 pvr2_trace(PVR2_TRACE_INIT,"pvr_exit complete");
147} 163}
148 164
149module_init(pvr_init); 165module_init(pvr_init);
diff --git a/drivers/media/video/pvrusb2/pvrusb2-std.c b/drivers/media/video/pvrusb2/pvrusb2-std.c
index da309288daa4..fdc5a2b49ca8 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-std.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-std.c
@@ -79,7 +79,7 @@ struct std_name {
79#define TSTD_Nc (V4L2_STD_PAL_Nc) 79#define TSTD_Nc (V4L2_STD_PAL_Nc)
80#define TSTD_60 (V4L2_STD_PAL_60) 80#define TSTD_60 (V4L2_STD_PAL_60)
81 81
82#define CSTD_ALL (CSTD_PAL|CSTD_NTSC|CSTD_SECAM) 82#define CSTD_ALL (CSTD_PAL|CSTD_NTSC|CSTD_ATSC|CSTD_SECAM)
83 83
84/* Mapping of standard bits to color system */ 84/* Mapping of standard bits to color system */
85static const struct std_name std_groups[] = { 85static const struct std_name std_groups[] = {
@@ -328,7 +328,7 @@ struct v4l2_standard *pvr2_std_create_enum(unsigned int *countptr,
328 struct v4l2_standard *stddefs; 328 struct v4l2_standard *stddefs;
329 329
330 if (pvrusb2_debug & PVR2_TRACE_STD) { 330 if (pvrusb2_debug & PVR2_TRACE_STD) {
331 char buf[50]; 331 char buf[100];
332 bcnt = pvr2_std_id_to_str(buf,sizeof(buf),id); 332 bcnt = pvr2_std_id_to_str(buf,sizeof(buf),id);
333 pvr2_trace( 333 pvr2_trace(
334 PVR2_TRACE_STD,"Mapping standards mask=0x%x (%.*s)", 334 PVR2_TRACE_STD,"Mapping standards mask=0x%x (%.*s)",
@@ -352,8 +352,11 @@ struct v4l2_standard *pvr2_std_create_enum(unsigned int *countptr,
352 if ((id & std_mixes[idx2]) == std_mixes[idx2]) std_cnt++; 352 if ((id & std_mixes[idx2]) == std_mixes[idx2]) std_cnt++;
353 } 353 }
354 354
355 /* Don't complain about ATSC standard values */
356 fmsk &= ~CSTD_ATSC;
357
355 if (fmsk) { 358 if (fmsk) {
356 char buf[50]; 359 char buf[100];
357 bcnt = pvr2_std_id_to_str(buf,sizeof(buf),fmsk); 360 bcnt = pvr2_std_id_to_str(buf,sizeof(buf),fmsk);
358 pvr2_trace( 361 pvr2_trace(
359 PVR2_TRACE_ERROR_LEGS, 362 PVR2_TRACE_ERROR_LEGS,
diff --git a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
index 07f4eae18433..0ff7a836a8a2 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-sysfs.c
@@ -287,6 +287,8 @@ static ssize_t store_val_norm(int id,struct device *class_dev,
287 struct pvr2_sysfs *sfp; 287 struct pvr2_sysfs *sfp;
288 int ret; 288 int ret;
289 sfp = (struct pvr2_sysfs *)class_dev->driver_data; 289 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
290 pvr2_sysfs_trace("pvr2_sysfs(%p) store_val_norm(cid=%d) \"%.*s\"",
291 sfp,id,(int)count,buf);
290 ret = store_val_any(id,0,sfp,buf,count); 292 ret = store_val_any(id,0,sfp,buf,count);
291 if (!ret) ret = count; 293 if (!ret) ret = count;
292 return ret; 294 return ret;
@@ -298,6 +300,8 @@ static ssize_t store_val_custom(int id,struct device *class_dev,
298 struct pvr2_sysfs *sfp; 300 struct pvr2_sysfs *sfp;
299 int ret; 301 int ret;
300 sfp = (struct pvr2_sysfs *)class_dev->driver_data; 302 sfp = (struct pvr2_sysfs *)class_dev->driver_data;
303 pvr2_sysfs_trace("pvr2_sysfs(%p) store_val_custom(cid=%d) \"%.*s\"",
304 sfp,id,(int)count,buf);
301 ret = store_val_any(id,1,sfp,buf,count); 305 ret = store_val_any(id,1,sfp,buf,count);
302 if (!ret) ret = count; 306 if (!ret) ret = count;
303 return ret; 307 return ret;
@@ -604,8 +608,9 @@ static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
604 608
605 ret = sysfs_create_group(&sfp->class_dev->kobj,&cip->grp); 609 ret = sysfs_create_group(&sfp->class_dev->kobj,&cip->grp);
606 if (ret) { 610 if (ret) {
607 printk(KERN_WARNING "%s: sysfs_create_group error: %d\n", 611 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
608 __FUNCTION__, ret); 612 "sysfs_create_group error: %d",
613 ret);
609 return; 614 return;
610 } 615 }
611 cip->created_ok = !0; 616 cip->created_ok = !0;
@@ -636,15 +641,17 @@ static void pvr2_sysfs_add_debugifc(struct pvr2_sysfs *sfp)
636 sfp->debugifc = dip; 641 sfp->debugifc = dip;
637 ret = device_create_file(sfp->class_dev,&dip->attr_debugcmd); 642 ret = device_create_file(sfp->class_dev,&dip->attr_debugcmd);
638 if (ret < 0) { 643 if (ret < 0) {
639 printk(KERN_WARNING "%s: device_create_file error: %d\n", 644 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
640 __FUNCTION__, ret); 645 "device_create_file error: %d",
646 ret);
641 } else { 647 } else {
642 dip->debugcmd_created_ok = !0; 648 dip->debugcmd_created_ok = !0;
643 } 649 }
644 ret = device_create_file(sfp->class_dev,&dip->attr_debuginfo); 650 ret = device_create_file(sfp->class_dev,&dip->attr_debuginfo);
645 if (ret < 0) { 651 if (ret < 0) {
646 printk(KERN_WARNING "%s: device_create_file error: %d\n", 652 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
647 __FUNCTION__, ret); 653 "device_create_file error: %d",
654 ret);
648 } else { 655 } else {
649 dip->debuginfo_created_ok = !0; 656 dip->debuginfo_created_ok = !0;
650 } 657 }
@@ -847,8 +854,8 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
847 class_dev->driver_data = sfp; 854 class_dev->driver_data = sfp;
848 ret = device_register(class_dev); 855 ret = device_register(class_dev);
849 if (ret) { 856 if (ret) {
850 printk(KERN_ERR "%s: device_register failed\n", 857 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
851 __FUNCTION__); 858 "device_register failed");
852 kfree(class_dev); 859 kfree(class_dev);
853 return; 860 return;
854 } 861 }
@@ -860,8 +867,9 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
860 ret = device_create_file(sfp->class_dev, 867 ret = device_create_file(sfp->class_dev,
861 &sfp->attr_v4l_minor_number); 868 &sfp->attr_v4l_minor_number);
862 if (ret < 0) { 869 if (ret < 0) {
863 printk(KERN_WARNING "%s: device_create_file error: %d\n", 870 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
864 __FUNCTION__, ret); 871 "device_create_file error: %d",
872 ret);
865 } else { 873 } else {
866 sfp->v4l_minor_number_created_ok = !0; 874 sfp->v4l_minor_number_created_ok = !0;
867 } 875 }
@@ -873,8 +881,9 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
873 ret = device_create_file(sfp->class_dev, 881 ret = device_create_file(sfp->class_dev,
874 &sfp->attr_v4l_radio_minor_number); 882 &sfp->attr_v4l_radio_minor_number);
875 if (ret < 0) { 883 if (ret < 0) {
876 printk(KERN_WARNING "%s: device_create_file error: %d\n", 884 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
877 __FUNCTION__, ret); 885 "device_create_file error: %d",
886 ret);
878 } else { 887 } else {
879 sfp->v4l_radio_minor_number_created_ok = !0; 888 sfp->v4l_radio_minor_number_created_ok = !0;
880 } 889 }
@@ -885,8 +894,9 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
885 sfp->attr_unit_number.store = NULL; 894 sfp->attr_unit_number.store = NULL;
886 ret = device_create_file(sfp->class_dev,&sfp->attr_unit_number); 895 ret = device_create_file(sfp->class_dev,&sfp->attr_unit_number);
887 if (ret < 0) { 896 if (ret < 0) {
888 printk(KERN_WARNING "%s: device_create_file error: %d\n", 897 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
889 __FUNCTION__, ret); 898 "device_create_file error: %d",
899 ret);
890 } else { 900 } else {
891 sfp->unit_number_created_ok = !0; 901 sfp->unit_number_created_ok = !0;
892 } 902 }
@@ -898,8 +908,9 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
898 ret = device_create_file(sfp->class_dev, 908 ret = device_create_file(sfp->class_dev,
899 &sfp->attr_bus_info); 909 &sfp->attr_bus_info);
900 if (ret < 0) { 910 if (ret < 0) {
901 printk(KERN_WARNING "%s: device_create_file error: %d\n", 911 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
902 __FUNCTION__, ret); 912 "device_create_file error: %d",
913 ret);
903 } else { 914 } else {
904 sfp->bus_info_created_ok = !0; 915 sfp->bus_info_created_ok = !0;
905 } 916 }
@@ -911,8 +922,9 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
911 ret = device_create_file(sfp->class_dev, 922 ret = device_create_file(sfp->class_dev,
912 &sfp->attr_hdw_name); 923 &sfp->attr_hdw_name);
913 if (ret < 0) { 924 if (ret < 0) {
914 printk(KERN_WARNING "%s: device_create_file error: %d\n", 925 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
915 __FUNCTION__, ret); 926 "device_create_file error: %d",
927 ret);
916 } else { 928 } else {
917 sfp->hdw_name_created_ok = !0; 929 sfp->hdw_name_created_ok = !0;
918 } 930 }
@@ -924,8 +936,9 @@ static void class_dev_create(struct pvr2_sysfs *sfp,
924 ret = device_create_file(sfp->class_dev, 936 ret = device_create_file(sfp->class_dev,
925 &sfp->attr_hdw_desc); 937 &sfp->attr_hdw_desc);
926 if (ret < 0) { 938 if (ret < 0) {
927 printk(KERN_WARNING "%s: device_create_file error: %d\n", 939 pvr2_trace(PVR2_TRACE_ERROR_LEGS,
928 __FUNCTION__, ret); 940 "device_create_file error: %d",
941 ret);
929 } else { 942 } else {
930 sfp->hdw_desc_created_ok = !0; 943 sfp->hdw_desc_created_ok = !0;
931 } 944 }
diff --git a/drivers/media/video/pvrusb2/pvrusb2-v4l2.c b/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
index 8f0587ebd4bd..087a18245560 100644
--- a/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
+++ b/drivers/media/video/pvrusb2/pvrusb2-v4l2.c
@@ -57,7 +57,9 @@ struct pvr2_v4l2_fh {
57 struct pvr2_v4l2_fh *vprev; 57 struct pvr2_v4l2_fh *vprev;
58 wait_queue_head_t wait_data; 58 wait_queue_head_t wait_data;
59 int fw_mode_flag; 59 int fw_mode_flag;
60 int prev_input_val; 60 /* Map contiguous ordinal value to input id */
61 unsigned char *input_map;
62 unsigned int input_cnt;
61}; 63};
62 64
63struct pvr2_v4l2 { 65struct pvr2_v4l2 {
@@ -259,14 +261,21 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
259 struct v4l2_input *vi = (struct v4l2_input *)arg; 261 struct v4l2_input *vi = (struct v4l2_input *)arg;
260 struct v4l2_input tmp; 262 struct v4l2_input tmp;
261 unsigned int cnt; 263 unsigned int cnt;
264 int val;
262 265
263 cptr = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT); 266 cptr = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT);
264 267
265 memset(&tmp,0,sizeof(tmp)); 268 memset(&tmp,0,sizeof(tmp));
266 tmp.index = vi->index; 269 tmp.index = vi->index;
267 ret = 0; 270 ret = 0;
268 switch (vi->index) { 271 if ((vi->index < 0) || (vi->index >= fh->input_cnt)) {
272 ret = -EINVAL;
273 break;
274 }
275 val = fh->input_map[vi->index];
276 switch (val) {
269 case PVR2_CVAL_INPUT_TV: 277 case PVR2_CVAL_INPUT_TV:
278 case PVR2_CVAL_INPUT_DTV:
270 case PVR2_CVAL_INPUT_RADIO: 279 case PVR2_CVAL_INPUT_RADIO:
271 tmp.type = V4L2_INPUT_TYPE_TUNER; 280 tmp.type = V4L2_INPUT_TYPE_TUNER;
272 break; 281 break;
@@ -281,7 +290,7 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
281 if (ret < 0) break; 290 if (ret < 0) break;
282 291
283 cnt = 0; 292 cnt = 0;
284 pvr2_ctrl_get_valname(cptr,vi->index, 293 pvr2_ctrl_get_valname(cptr,val,
285 tmp.name,sizeof(tmp.name)-1,&cnt); 294 tmp.name,sizeof(tmp.name)-1,&cnt);
286 tmp.name[cnt] = 0; 295 tmp.name[cnt] = 0;
287 296
@@ -303,22 +312,33 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
303 312
304 case VIDIOC_G_INPUT: 313 case VIDIOC_G_INPUT:
305 { 314 {
315 unsigned int idx;
306 struct pvr2_ctrl *cptr; 316 struct pvr2_ctrl *cptr;
307 struct v4l2_input *vi = (struct v4l2_input *)arg; 317 struct v4l2_input *vi = (struct v4l2_input *)arg;
308 int val; 318 int val;
309 cptr = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT); 319 cptr = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT);
310 val = 0; 320 val = 0;
311 ret = pvr2_ctrl_get_value(cptr,&val); 321 ret = pvr2_ctrl_get_value(cptr,&val);
312 vi->index = val; 322 vi->index = 0;
323 for (idx = 0; idx < fh->input_cnt; idx++) {
324 if (fh->input_map[idx] == val) {
325 vi->index = idx;
326 break;
327 }
328 }
313 break; 329 break;
314 } 330 }
315 331
316 case VIDIOC_S_INPUT: 332 case VIDIOC_S_INPUT:
317 { 333 {
318 struct v4l2_input *vi = (struct v4l2_input *)arg; 334 struct v4l2_input *vi = (struct v4l2_input *)arg;
335 if ((vi->index < 0) || (vi->index >= fh->input_cnt)) {
336 ret = -ERANGE;
337 break;
338 }
319 ret = pvr2_ctrl_set_value( 339 ret = pvr2_ctrl_set_value(
320 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT), 340 pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT),
321 vi->index); 341 fh->input_map[vi->index]);
322 break; 342 break;
323 } 343 }
324 344
@@ -858,7 +878,6 @@ static int pvr2_v4l2_release(struct inode *inode, struct file *file)
858{ 878{
859 struct pvr2_v4l2_fh *fhp = file->private_data; 879 struct pvr2_v4l2_fh *fhp = file->private_data;
860 struct pvr2_v4l2 *vp = fhp->vhead; 880 struct pvr2_v4l2 *vp = fhp->vhead;
861 struct pvr2_context *mp = fhp->vhead->channel.mc_head;
862 struct pvr2_hdw *hdw = fhp->channel.mc_head->hdw; 881 struct pvr2_hdw *hdw = fhp->channel.mc_head->hdw;
863 882
864 pvr2_trace(PVR2_TRACE_OPEN_CLOSE,"pvr2_v4l2_release"); 883 pvr2_trace(PVR2_TRACE_OPEN_CLOSE,"pvr2_v4l2_release");
@@ -875,42 +894,30 @@ static int pvr2_v4l2_release(struct inode *inode, struct file *file)
875 v4l2_prio_close(&vp->prio, &fhp->prio); 894 v4l2_prio_close(&vp->prio, &fhp->prio);
876 file->private_data = NULL; 895 file->private_data = NULL;
877 896
878 pvr2_context_enter(mp); do { 897 if (fhp->vnext) {
879 /* Restore the previous input selection, if it makes sense 898 fhp->vnext->vprev = fhp->vprev;
880 to do so. */ 899 } else {
881 if (fhp->dev_info->v4l_type == VFL_TYPE_RADIO) { 900 vp->vlast = fhp->vprev;
882 struct pvr2_ctrl *cp; 901 }
883 int pval; 902 if (fhp->vprev) {
884 cp = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT); 903 fhp->vprev->vnext = fhp->vnext;
885 pvr2_ctrl_get_value(cp,&pval); 904 } else {
886 /* Only restore if we're still selecting the radio */ 905 vp->vfirst = fhp->vnext;
887 if (pval == PVR2_CVAL_INPUT_RADIO) { 906 }
888 pvr2_ctrl_set_value(cp,fhp->prev_input_val); 907 fhp->vnext = NULL;
889 pvr2_hdw_commit_ctl(hdw); 908 fhp->vprev = NULL;
890 } 909 fhp->vhead = NULL;
891 } 910 pvr2_channel_done(&fhp->channel);
892 911 pvr2_trace(PVR2_TRACE_STRUCT,
893 if (fhp->vnext) { 912 "Destroying pvr_v4l2_fh id=%p",fhp);
894 fhp->vnext->vprev = fhp->vprev; 913 if (fhp->input_map) {
895 } else { 914 kfree(fhp->input_map);
896 vp->vlast = fhp->vprev; 915 fhp->input_map = NULL;
897 } 916 }
898 if (fhp->vprev) { 917 kfree(fhp);
899 fhp->vprev->vnext = fhp->vnext; 918 if (vp->channel.mc_head->disconnect_flag && !vp->vfirst) {
900 } else { 919 pvr2_v4l2_destroy_no_lock(vp);
901 vp->vfirst = fhp->vnext; 920 }
902 }
903 fhp->vnext = NULL;
904 fhp->vprev = NULL;
905 fhp->vhead = NULL;
906 pvr2_channel_done(&fhp->channel);
907 pvr2_trace(PVR2_TRACE_STRUCT,
908 "Destroying pvr_v4l2_fh id=%p",fhp);
909 kfree(fhp);
910 if (vp->channel.mc_head->disconnect_flag && !vp->vfirst) {
911 pvr2_v4l2_destroy_no_lock(vp);
912 }
913 } while (0); pvr2_context_exit(mp);
914 return 0; 921 return 0;
915} 922}
916 923
@@ -921,6 +928,9 @@ static int pvr2_v4l2_open(struct inode *inode, struct file *file)
921 struct pvr2_v4l2_fh *fhp; 928 struct pvr2_v4l2_fh *fhp;
922 struct pvr2_v4l2 *vp; 929 struct pvr2_v4l2 *vp;
923 struct pvr2_hdw *hdw; 930 struct pvr2_hdw *hdw;
931 unsigned int input_mask = 0;
932 unsigned int input_cnt,idx;
933 int ret = 0;
924 934
925 dip = container_of(video_devdata(file),struct pvr2_v4l2_dev,devbase); 935 dip = container_of(video_devdata(file),struct pvr2_v4l2_dev,devbase);
926 936
@@ -943,32 +953,62 @@ static int pvr2_v4l2_open(struct inode *inode, struct file *file)
943 init_waitqueue_head(&fhp->wait_data); 953 init_waitqueue_head(&fhp->wait_data);
944 fhp->dev_info = dip; 954 fhp->dev_info = dip;
945 955
946 pvr2_context_enter(vp->channel.mc_head); do { 956 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr_v4l2_fh id=%p",fhp);
947 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr_v4l2_fh id=%p",fhp); 957 pvr2_channel_init(&fhp->channel,vp->channel.mc_head);
948 pvr2_channel_init(&fhp->channel,vp->channel.mc_head);
949 958
950 fhp->vnext = NULL; 959 if (dip->v4l_type == VFL_TYPE_RADIO) {
951 fhp->vprev = vp->vlast; 960 /* Opening device as a radio, legal input selection subset
952 if (vp->vlast) { 961 is just the radio. */
953 vp->vlast->vnext = fhp; 962 input_mask = (1 << PVR2_CVAL_INPUT_RADIO);
954 } else { 963 } else {
955 vp->vfirst = fhp; 964 /* Opening the main V4L device, legal input selection
956 } 965 subset includes all analog inputs. */
957 vp->vlast = fhp; 966 input_mask = ((1 << PVR2_CVAL_INPUT_RADIO) |
958 fhp->vhead = vp; 967 (1 << PVR2_CVAL_INPUT_TV) |
959 968 (1 << PVR2_CVAL_INPUT_COMPOSITE) |
960 /* Opening the /dev/radioX device implies a mode switch. 969 (1 << PVR2_CVAL_INPUT_SVIDEO));
961 So execute that here. Note that you can get the 970 }
962 IDENTICAL effect merely by opening the normal video 971 ret = pvr2_channel_limit_inputs(&fhp->channel,input_mask);
963 device and setting the input appropriately. */ 972 if (ret) {
964 if (dip->v4l_type == VFL_TYPE_RADIO) { 973 pvr2_channel_done(&fhp->channel);
965 struct pvr2_ctrl *cp; 974 pvr2_trace(PVR2_TRACE_STRUCT,
966 cp = pvr2_hdw_get_ctrl_by_id(hdw,PVR2_CID_INPUT); 975 "Destroying pvr_v4l2_fh id=%p (input mask error)",
967 pvr2_ctrl_get_value(cp,&fhp->prev_input_val); 976 fhp);
968 pvr2_ctrl_set_value(cp,PVR2_CVAL_INPUT_RADIO); 977
969 pvr2_hdw_commit_ctl(hdw); 978 kfree(fhp);
970 } 979 return ret;
971 } while (0); pvr2_context_exit(vp->channel.mc_head); 980 }
981
982 input_mask &= pvr2_hdw_get_input_available(hdw);
983 input_cnt = 0;
984 for (idx = 0; idx < (sizeof(input_mask) << 3); idx++) {
985 if (input_mask & (1 << idx)) input_cnt++;
986 }
987 fhp->input_cnt = input_cnt;
988 fhp->input_map = kzalloc(input_cnt,GFP_KERNEL);
989 if (!fhp->input_map) {
990 pvr2_channel_done(&fhp->channel);
991 pvr2_trace(PVR2_TRACE_STRUCT,
992 "Destroying pvr_v4l2_fh id=%p (input map failure)",
993 fhp);
994 kfree(fhp);
995 return -ENOMEM;
996 }
997 input_cnt = 0;
998 for (idx = 0; idx < (sizeof(input_mask) << 3); idx++) {
999 if (!(input_mask & (1 << idx))) continue;
1000 fhp->input_map[input_cnt++] = idx;
1001 }
1002
1003 fhp->vnext = NULL;
1004 fhp->vprev = vp->vlast;
1005 if (vp->vlast) {
1006 vp->vlast->vnext = fhp;
1007 } else {
1008 vp->vfirst = fhp;
1009 }
1010 vp->vlast = fhp;
1011 fhp->vhead = vp;
972 1012
973 fhp->file = file; 1013 fhp->file = file;
974 file->private_data = fhp; 1014 file->private_data = fhp;
@@ -1201,24 +1241,27 @@ struct pvr2_v4l2 *pvr2_v4l2_create(struct pvr2_context *mnp)
1201 1241
1202 vp = kzalloc(sizeof(*vp),GFP_KERNEL); 1242 vp = kzalloc(sizeof(*vp),GFP_KERNEL);
1203 if (!vp) return vp; 1243 if (!vp) return vp;
1204 vp->dev_video = kzalloc(sizeof(*vp->dev_video),GFP_KERNEL);
1205 vp->dev_radio = kzalloc(sizeof(*vp->dev_radio),GFP_KERNEL);
1206 if (!(vp->dev_video && vp->dev_radio)) {
1207 kfree(vp->dev_video);
1208 kfree(vp->dev_radio);
1209 kfree(vp);
1210 return NULL;
1211 }
1212 pvr2_channel_init(&vp->channel,mnp); 1244 pvr2_channel_init(&vp->channel,mnp);
1213 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr2_v4l2 id=%p",vp); 1245 pvr2_trace(PVR2_TRACE_STRUCT,"Creating pvr2_v4l2 id=%p",vp);
1214 1246
1215 vp->channel.check_func = pvr2_v4l2_internal_check; 1247 vp->channel.check_func = pvr2_v4l2_internal_check;
1216 1248
1217 /* register streams */ 1249 /* register streams */
1250 vp->dev_video = kzalloc(sizeof(*vp->dev_video),GFP_KERNEL);
1251 if (!vp->dev_video) goto fail;
1218 pvr2_v4l2_dev_init(vp->dev_video,vp,VFL_TYPE_GRABBER); 1252 pvr2_v4l2_dev_init(vp->dev_video,vp,VFL_TYPE_GRABBER);
1219 pvr2_v4l2_dev_init(vp->dev_radio,vp,VFL_TYPE_RADIO); 1253 if (pvr2_hdw_get_input_available(vp->channel.mc_head->hdw) &
1254 (1 << PVR2_CVAL_INPUT_RADIO)) {
1255 vp->dev_radio = kzalloc(sizeof(*vp->dev_radio),GFP_KERNEL);
1256 if (!vp->dev_radio) goto fail;
1257 pvr2_v4l2_dev_init(vp->dev_radio,vp,VFL_TYPE_RADIO);
1258 }
1220 1259
1221 return vp; 1260 return vp;
1261 fail:
1262 pvr2_trace(PVR2_TRACE_STRUCT,"Failure creating pvr2_v4l2 id=%p",vp);
1263 pvr2_v4l2_destroy_no_lock(vp);
1264 return 0;
1222} 1265}
1223 1266
1224/* 1267/*
diff --git a/drivers/media/video/pwc/pwc-if.c b/drivers/media/video/pwc/pwc-if.c
index e0a453a6543d..423fa7c2d0c9 100644
--- a/drivers/media/video/pwc/pwc-if.c
+++ b/drivers/media/video/pwc/pwc-if.c
@@ -130,8 +130,8 @@ static int default_fbufs = 3; /* Default number of frame buffers */
130#ifdef CONFIG_USB_PWC_DEBUG 130#ifdef CONFIG_USB_PWC_DEBUG
131 int pwc_trace = PWC_DEBUG_LEVEL; 131 int pwc_trace = PWC_DEBUG_LEVEL;
132#endif 132#endif
133static int power_save = 0; 133static int power_save;
134static int led_on = 100, led_off = 0; /* defaults to LED that is on while in use */ 134static int led_on = 100, led_off; /* defaults to LED that is on while in use */
135static int pwc_preferred_compression = 1; /* 0..3 = uncompressed..high */ 135static int pwc_preferred_compression = 1; /* 0..3 = uncompressed..high */
136static struct { 136static struct {
137 int type; 137 int type;
@@ -159,7 +159,9 @@ static const struct file_operations pwc_fops = {
159 .poll = pwc_video_poll, 159 .poll = pwc_video_poll,
160 .mmap = pwc_video_mmap, 160 .mmap = pwc_video_mmap,
161 .ioctl = pwc_video_ioctl, 161 .ioctl = pwc_video_ioctl,
162#ifdef CONFIG_COMPAT
162 .compat_ioctl = v4l_compat_ioctl32, 163 .compat_ioctl = v4l_compat_ioctl32,
164#endif
163 .llseek = no_llseek, 165 .llseek = no_llseek,
164}; 166};
165static struct video_device pwc_template = { 167static struct video_device pwc_template = {
@@ -487,7 +489,7 @@ static void pwc_reset_buffers(struct pwc_device *pdev)
487 int i; 489 int i;
488 unsigned long flags; 490 unsigned long flags;
489 491
490 PWC_DEBUG_MEMORY(">> %s __enter__\n", __FUNCTION__); 492 PWC_DEBUG_MEMORY(">> %s __enter__\n", __func__);
491 493
492 spin_lock_irqsave(&pdev->ptrlock, flags); 494 spin_lock_irqsave(&pdev->ptrlock, flags);
493 pdev->full_frames = NULL; 495 pdev->full_frames = NULL;
@@ -509,7 +511,7 @@ static void pwc_reset_buffers(struct pwc_device *pdev)
509 pdev->fill_image = 0; 511 pdev->fill_image = 0;
510 spin_unlock_irqrestore(&pdev->ptrlock, flags); 512 spin_unlock_irqrestore(&pdev->ptrlock, flags);
511 513
512 PWC_DEBUG_MEMORY("<< %s __leaving__\n", __FUNCTION__); 514 PWC_DEBUG_MEMORY("<< %s __leaving__\n", __func__);
513} 515}
514 516
515 517
@@ -786,8 +788,8 @@ static void pwc_isoc_handler(struct urb *urb)
786 } /* ..status == 0 */ 788 } /* ..status == 0 */
787 else { 789 else {
788 /* This is normally not interesting to the user, unless 790 /* This is normally not interesting to the user, unless
789 * you are really debugging something */ 791 * you are really debugging something, default = 0 */
790 static int iso_error = 0; 792 static int iso_error;
791 iso_error++; 793 iso_error++;
792 if (iso_error < 20) 794 if (iso_error < 20)
793 PWC_DEBUG_FLOW("Iso frame %d of USB has error %d\n", i, fst); 795 PWC_DEBUG_FLOW("Iso frame %d of USB has error %d\n", i, fst);
@@ -1426,7 +1428,7 @@ static int pwc_video_mmap(struct file *file, struct vm_area_struct *vma)
1426 unsigned long page, pos = 0; 1428 unsigned long page, pos = 0;
1427 int index; 1429 int index;
1428 1430
1429 PWC_DEBUG_MEMORY(">> %s\n", __FUNCTION__); 1431 PWC_DEBUG_MEMORY(">> %s\n", __func__);
1430 pdev = vdev->priv; 1432 pdev = vdev->priv;
1431 size = vma->vm_end - vma->vm_start; 1433 size = vma->vm_end - vma->vm_start;
1432 start = vma->vm_start; 1434 start = vma->vm_start;
diff --git a/drivers/media/video/pwc/pwc-v4l.c b/drivers/media/video/pwc/pwc-v4l.c
index 32fbe1ae6251..1742889874df 100644
--- a/drivers/media/video/pwc/pwc-v4l.c
+++ b/drivers/media/video/pwc/pwc-v4l.c
@@ -351,8 +351,10 @@ int pwc_video_do_ioctl(struct inode *inode, struct file *file,
351 return -EFAULT; 351 return -EFAULT;
352 352
353#ifdef CONFIG_USB_PWC_DEBUG 353#ifdef CONFIG_USB_PWC_DEBUG
354 if (PWC_DEBUG_LEVEL_IOCTL & pwc_trace) 354 if (PWC_DEBUG_LEVEL_IOCTL & pwc_trace) {
355 v4l_printk_ioctl(cmd); 355 v4l_printk_ioctl(cmd);
356 printk("\n");
357 }
356#endif 358#endif
357 359
358 360
diff --git a/drivers/media/video/pxa_camera.c b/drivers/media/video/pxa_camera.c
new file mode 100644
index 000000000000..7cc8e9b19fb7
--- /dev/null
+++ b/drivers/media/video/pxa_camera.c
@@ -0,0 +1,1206 @@
1/*
2 * V4L2 Driver for PXA camera host
3 *
4 * Copyright (C) 2006, Sascha Hauer, Pengutronix
5 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 */
12
13#include <linux/init.h>
14#include <linux/module.h>
15#include <linux/io.h>
16#include <linux/delay.h>
17#include <linux/dma-mapping.h>
18#include <linux/errno.h>
19#include <linux/fs.h>
20#include <linux/interrupt.h>
21#include <linux/kernel.h>
22#include <linux/mm.h>
23#include <linux/moduleparam.h>
24#include <linux/time.h>
25#include <linux/version.h>
26#include <linux/device.h>
27#include <linux/platform_device.h>
28#include <linux/mutex.h>
29#include <linux/clk.h>
30
31#include <media/v4l2-common.h>
32#include <media/v4l2-dev.h>
33#include <media/soc_camera.h>
34
35#include <linux/videodev2.h>
36
37#include <asm/dma.h>
38#include <asm/arch/pxa-regs.h>
39#include <asm/arch/camera.h>
40
41#define PXA_CAM_VERSION_CODE KERNEL_VERSION(0, 0, 5)
42#define PXA_CAM_DRV_NAME "pxa27x-camera"
43
44#define CICR0_SIM_MP (0 << 24)
45#define CICR0_SIM_SP (1 << 24)
46#define CICR0_SIM_MS (2 << 24)
47#define CICR0_SIM_EP (3 << 24)
48#define CICR0_SIM_ES (4 << 24)
49
50#define CICR1_DW_VAL(x) ((x) & CICR1_DW) /* Data bus width */
51#define CICR1_PPL_VAL(x) (((x) << 15) & CICR1_PPL) /* Pixels per line */
52#define CICR1_COLOR_SP_VAL(x) (((x) << 3) & CICR1_COLOR_SP) /* color space */
53#define CICR1_RGB_BPP_VAL(x) (((x) << 7) & CICR1_RGB_BPP) /* bpp for rgb */
54#define CICR1_RGBT_CONV_VAL(x) (((x) << 29) & CICR1_RGBT_CONV) /* rgbt conv */
55
56#define CICR2_BLW_VAL(x) (((x) << 24) & CICR2_BLW) /* Beginning-of-line pixel clock wait count */
57#define CICR2_ELW_VAL(x) (((x) << 16) & CICR2_ELW) /* End-of-line pixel clock wait count */
58#define CICR2_HSW_VAL(x) (((x) << 10) & CICR2_HSW) /* Horizontal sync pulse width */
59#define CICR2_BFPW_VAL(x) (((x) << 3) & CICR2_BFPW) /* Beginning-of-frame pixel clock wait count */
60#define CICR2_FSW_VAL(x) (((x) << 0) & CICR2_FSW) /* Frame stabilization wait count */
61
62#define CICR3_BFW_VAL(x) (((x) << 24) & CICR3_BFW) /* Beginning-of-frame line clock wait count */
63#define CICR3_EFW_VAL(x) (((x) << 16) & CICR3_EFW) /* End-of-frame line clock wait count */
64#define CICR3_VSW_VAL(x) (((x) << 11) & CICR3_VSW) /* Vertical sync pulse width */
65#define CICR3_LPF_VAL(x) (((x) << 0) & CICR3_LPF) /* Lines per frame */
66
67#define CICR0_IRQ_MASK (CICR0_TOM | CICR0_RDAVM | CICR0_FEM | CICR0_EOLM | \
68 CICR0_PERRM | CICR0_QDM | CICR0_CDM | CICR0_SOFM | \
69 CICR0_EOFM | CICR0_FOM)
70
71static DEFINE_MUTEX(camera_lock);
72
73/*
74 * Structures
75 */
76enum pxa_camera_active_dma {
77 DMA_Y = 0x1,
78 DMA_U = 0x2,
79 DMA_V = 0x4,
80};
81
82/* descriptor needed for the PXA DMA engine */
83struct pxa_cam_dma {
84 dma_addr_t sg_dma;
85 struct pxa_dma_desc *sg_cpu;
86 size_t sg_size;
87 int sglen;
88};
89
90/* buffer for one video frame */
91struct pxa_buffer {
92 /* common v4l buffer stuff -- must be first */
93 struct videobuf_buffer vb;
94
95 const struct soc_camera_data_format *fmt;
96
97 /* our descriptor lists for Y, U and V channels */
98 struct pxa_cam_dma dmas[3];
99
100 int inwork;
101
102 enum pxa_camera_active_dma active_dma;
103};
104
105struct pxa_camera_dev {
106 struct device *dev;
107 /* PXA27x is only supposed to handle one camera on its Quick Capture
108 * interface. If anyone ever builds hardware to enable more than
109 * one camera, they will have to modify this driver too */
110 struct soc_camera_device *icd;
111 struct clk *clk;
112
113 unsigned int irq;
114 void __iomem *base;
115
116 int channels;
117 unsigned int dma_chans[3];
118
119 struct pxacamera_platform_data *pdata;
120 struct resource *res;
121 unsigned long platform_flags;
122 unsigned long platform_mclk_10khz;
123
124 struct list_head capture;
125
126 spinlock_t lock;
127
128 struct pxa_buffer *active;
129 struct pxa_dma_desc *sg_tail[3];
130};
131
132static const char *pxa_cam_driver_description = "PXA_Camera";
133
134static unsigned int vid_limit = 16; /* Video memory limit, in Mb */
135
136/*
137 * Videobuf operations
138 */
139static int pxa_videobuf_setup(struct videobuf_queue *vq, unsigned int *count,
140 unsigned int *size)
141{
142 struct soc_camera_device *icd = vq->priv_data;
143 struct soc_camera_host *ici =
144 to_soc_camera_host(icd->dev.parent);
145 struct pxa_camera_dev *pcdev = ici->priv;
146
147 dev_dbg(&icd->dev, "count=%d, size=%d\n", *count, *size);
148
149 /* planar capture requires Y, U and V buffers to be page aligned */
150 if (pcdev->channels == 3) {
151 *size = PAGE_ALIGN(icd->width * icd->height); /* Y pages */
152 *size += PAGE_ALIGN(icd->width * icd->height / 2); /* U pages */
153 *size += PAGE_ALIGN(icd->width * icd->height / 2); /* V pages */
154 } else {
155 *size = icd->width * icd->height *
156 ((icd->current_fmt->depth + 7) >> 3);
157 }
158
159 if (0 == *count)
160 *count = 32;
161 while (*size * *count > vid_limit * 1024 * 1024)
162 (*count)--;
163
164 return 0;
165}
166
167static void free_buffer(struct videobuf_queue *vq, struct pxa_buffer *buf)
168{
169 struct soc_camera_device *icd = vq->priv_data;
170 struct soc_camera_host *ici =
171 to_soc_camera_host(icd->dev.parent);
172 struct pxa_camera_dev *pcdev = ici->priv;
173 struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb);
174 int i;
175
176 BUG_ON(in_interrupt());
177
178 dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
179 &buf->vb, buf->vb.baddr, buf->vb.bsize);
180
181 /* This waits until this buffer is out of danger, i.e., until it is no
182 * longer in STATE_QUEUED or STATE_ACTIVE */
183 videobuf_waiton(&buf->vb, 0, 0);
184 videobuf_dma_unmap(vq, dma);
185 videobuf_dma_free(dma);
186
187 for (i = 0; i < ARRAY_SIZE(buf->dmas); i++) {
188 if (buf->dmas[i].sg_cpu)
189 dma_free_coherent(pcdev->dev, buf->dmas[i].sg_size,
190 buf->dmas[i].sg_cpu,
191 buf->dmas[i].sg_dma);
192 buf->dmas[i].sg_cpu = NULL;
193 }
194
195 buf->vb.state = VIDEOBUF_NEEDS_INIT;
196}
197
198static int pxa_init_dma_channel(struct pxa_camera_dev *pcdev,
199 struct pxa_buffer *buf,
200 struct videobuf_dmabuf *dma, int channel,
201 int sglen, int sg_start, int cibr,
202 unsigned int size)
203{
204 struct pxa_cam_dma *pxa_dma = &buf->dmas[channel];
205 int i;
206
207 if (pxa_dma->sg_cpu)
208 dma_free_coherent(pcdev->dev, pxa_dma->sg_size,
209 pxa_dma->sg_cpu, pxa_dma->sg_dma);
210
211 pxa_dma->sg_size = (sglen + 1) * sizeof(struct pxa_dma_desc);
212 pxa_dma->sg_cpu = dma_alloc_coherent(pcdev->dev, pxa_dma->sg_size,
213 &pxa_dma->sg_dma, GFP_KERNEL);
214 if (!pxa_dma->sg_cpu)
215 return -ENOMEM;
216
217 pxa_dma->sglen = sglen;
218
219 for (i = 0; i < sglen; i++) {
220 int sg_i = sg_start + i;
221 struct scatterlist *sg = dma->sglist;
222 unsigned int dma_len = sg_dma_len(&sg[sg_i]), xfer_len;
223
224 pxa_dma->sg_cpu[i].dsadr = pcdev->res->start + cibr;
225 pxa_dma->sg_cpu[i].dtadr = sg_dma_address(&sg[sg_i]);
226
227 /* PXA27x Developer's Manual 27.4.4.1: round up to 8 bytes */
228 xfer_len = (min(dma_len, size) + 7) & ~7;
229
230 pxa_dma->sg_cpu[i].dcmd =
231 DCMD_FLOWSRC | DCMD_BURST8 | DCMD_INCTRGADDR | xfer_len;
232 size -= dma_len;
233 pxa_dma->sg_cpu[i].ddadr =
234 pxa_dma->sg_dma + (i + 1) * sizeof(struct pxa_dma_desc);
235 }
236
237 pxa_dma->sg_cpu[sglen - 1].ddadr = DDADR_STOP;
238 pxa_dma->sg_cpu[sglen - 1].dcmd |= DCMD_ENDIRQEN;
239
240 return 0;
241}
242
243static int pxa_videobuf_prepare(struct videobuf_queue *vq,
244 struct videobuf_buffer *vb, enum v4l2_field field)
245{
246 struct soc_camera_device *icd = vq->priv_data;
247 struct soc_camera_host *ici =
248 to_soc_camera_host(icd->dev.parent);
249 struct pxa_camera_dev *pcdev = ici->priv;
250 struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb);
251 int ret;
252 int sglen_y, sglen_yu = 0, sglen_u = 0, sglen_v = 0;
253 int size_y, size_u = 0, size_v = 0;
254
255 dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
256 vb, vb->baddr, vb->bsize);
257
258 /* Added list head initialization on alloc */
259 WARN_ON(!list_empty(&vb->queue));
260
261#ifdef DEBUG
262 /* This can be useful if you want to see if we actually fill
263 * the buffer with something */
264 memset((void *)vb->baddr, 0xaa, vb->bsize);
265#endif
266
267 BUG_ON(NULL == icd->current_fmt);
268
269 /* I think, in buf_prepare you only have to protect global data,
270 * the actual buffer is yours */
271 buf->inwork = 1;
272
273 if (buf->fmt != icd->current_fmt ||
274 vb->width != icd->width ||
275 vb->height != icd->height ||
276 vb->field != field) {
277 buf->fmt = icd->current_fmt;
278 vb->width = icd->width;
279 vb->height = icd->height;
280 vb->field = field;
281 vb->state = VIDEOBUF_NEEDS_INIT;
282 }
283
284 vb->size = vb->width * vb->height * ((buf->fmt->depth + 7) >> 3);
285 if (0 != vb->baddr && vb->bsize < vb->size) {
286 ret = -EINVAL;
287 goto out;
288 }
289
290 if (vb->state == VIDEOBUF_NEEDS_INIT) {
291 unsigned int size = vb->size;
292 struct videobuf_dmabuf *dma = videobuf_to_dma(vb);
293
294 ret = videobuf_iolock(vq, vb, NULL);
295 if (ret)
296 goto fail;
297
298 if (pcdev->channels == 3) {
299 /* FIXME the calculations should be more precise */
300 sglen_y = dma->sglen / 2;
301 sglen_u = sglen_v = dma->sglen / 4 + 1;
302 sglen_yu = sglen_y + sglen_u;
303 size_y = size / 2;
304 size_u = size_v = size / 4;
305 } else {
306 sglen_y = dma->sglen;
307 size_y = size;
308 }
309
310 /* init DMA for Y channel */
311 ret = pxa_init_dma_channel(pcdev, buf, dma, 0, sglen_y,
312 0, 0x28, size_y);
313
314 if (ret) {
315 dev_err(pcdev->dev,
316 "DMA initialization for Y/RGB failed\n");
317 goto fail;
318 }
319
320 if (pcdev->channels == 3) {
321 /* init DMA for U channel */
322 ret = pxa_init_dma_channel(pcdev, buf, dma, 1, sglen_u,
323 sglen_y, 0x30, size_u);
324 if (ret) {
325 dev_err(pcdev->dev,
326 "DMA initialization for U failed\n");
327 goto fail_u;
328 }
329
330 /* init DMA for V channel */
331 ret = pxa_init_dma_channel(pcdev, buf, dma, 2, sglen_v,
332 sglen_yu, 0x38, size_v);
333 if (ret) {
334 dev_err(pcdev->dev,
335 "DMA initialization for V failed\n");
336 goto fail_v;
337 }
338 }
339
340 vb->state = VIDEOBUF_PREPARED;
341 }
342
343 buf->inwork = 0;
344 buf->active_dma = DMA_Y;
345 if (pcdev->channels == 3)
346 buf->active_dma |= DMA_U | DMA_V;
347
348 return 0;
349
350fail_v:
351 dma_free_coherent(pcdev->dev, buf->dmas[1].sg_size,
352 buf->dmas[1].sg_cpu, buf->dmas[1].sg_dma);
353fail_u:
354 dma_free_coherent(pcdev->dev, buf->dmas[0].sg_size,
355 buf->dmas[0].sg_cpu, buf->dmas[0].sg_dma);
356fail:
357 free_buffer(vq, buf);
358out:
359 buf->inwork = 0;
360 return ret;
361}
362
363static void pxa_videobuf_queue(struct videobuf_queue *vq,
364 struct videobuf_buffer *vb)
365{
366 struct soc_camera_device *icd = vq->priv_data;
367 struct soc_camera_host *ici =
368 to_soc_camera_host(icd->dev.parent);
369 struct pxa_camera_dev *pcdev = ici->priv;
370 struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb);
371 struct pxa_buffer *active;
372 unsigned long flags;
373 int i;
374
375 dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
376 vb, vb->baddr, vb->bsize);
377 spin_lock_irqsave(&pcdev->lock, flags);
378
379 list_add_tail(&vb->queue, &pcdev->capture);
380
381 vb->state = VIDEOBUF_ACTIVE;
382 active = pcdev->active;
383
384 if (!active) {
385 CIFR |= CIFR_RESET_F;
386
387 for (i = 0; i < pcdev->channels; i++) {
388 DDADR(pcdev->dma_chans[i]) = buf->dmas[i].sg_dma;
389 DCSR(pcdev->dma_chans[i]) = DCSR_RUN;
390 pcdev->sg_tail[i] = buf->dmas[i].sg_cpu + buf->dmas[i].sglen - 1;
391 }
392
393 pcdev->active = buf;
394 CICR0 |= CICR0_ENB;
395 } else {
396 struct pxa_cam_dma *buf_dma;
397 struct pxa_cam_dma *act_dma;
398 int nents;
399
400 for (i = 0; i < pcdev->channels; i++) {
401 buf_dma = &buf->dmas[i];
402 act_dma = &active->dmas[i];
403 nents = buf_dma->sglen;
404
405 /* Stop DMA engine */
406 DCSR(pcdev->dma_chans[i]) = 0;
407
408 /* Add the descriptors we just initialized to
409 the currently running chain */
410 pcdev->sg_tail[i]->ddadr = buf_dma->sg_dma;
411 pcdev->sg_tail[i] = buf_dma->sg_cpu + buf_dma->sglen - 1;
412
413 /* Setup a dummy descriptor with the DMA engines current
414 * state
415 */
416 buf_dma->sg_cpu[nents].dsadr =
417 pcdev->res->start + 0x28 + i*8; /* CIBRx */
418 buf_dma->sg_cpu[nents].dtadr =
419 DTADR(pcdev->dma_chans[i]);
420 buf_dma->sg_cpu[nents].dcmd =
421 DCMD(pcdev->dma_chans[i]);
422
423 if (DDADR(pcdev->dma_chans[i]) == DDADR_STOP) {
424 /* The DMA engine is on the last
425 descriptor, set the next descriptors
426 address to the descriptors we just
427 initialized */
428 buf_dma->sg_cpu[nents].ddadr = buf_dma->sg_dma;
429 } else {
430 buf_dma->sg_cpu[nents].ddadr =
431 DDADR(pcdev->dma_chans[i]);
432 }
433
434 /* The next descriptor is the dummy descriptor */
435 DDADR(pcdev->dma_chans[i]) = buf_dma->sg_dma + nents *
436 sizeof(struct pxa_dma_desc);
437
438 DCSR(pcdev->dma_chans[i]) = DCSR_RUN;
439 }
440 }
441
442 spin_unlock_irqrestore(&pcdev->lock, flags);
443}
444
445static void pxa_videobuf_release(struct videobuf_queue *vq,
446 struct videobuf_buffer *vb)
447{
448 struct pxa_buffer *buf = container_of(vb, struct pxa_buffer, vb);
449#ifdef DEBUG
450 struct soc_camera_device *icd = vq->priv_data;
451
452 dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
453 vb, vb->baddr, vb->bsize);
454
455 switch (vb->state) {
456 case VIDEOBUF_ACTIVE:
457 dev_dbg(&icd->dev, "%s (active)\n", __func__);
458 break;
459 case VIDEOBUF_QUEUED:
460 dev_dbg(&icd->dev, "%s (queued)\n", __func__);
461 break;
462 case VIDEOBUF_PREPARED:
463 dev_dbg(&icd->dev, "%s (prepared)\n", __func__);
464 break;
465 default:
466 dev_dbg(&icd->dev, "%s (unknown)\n", __func__);
467 break;
468 }
469#endif
470
471 free_buffer(vq, buf);
472}
473
474static void pxa_camera_wakeup(struct pxa_camera_dev *pcdev,
475 struct videobuf_buffer *vb,
476 struct pxa_buffer *buf)
477{
478 /* _init is used to debug races, see comment in pxa_camera_reqbufs() */
479 list_del_init(&vb->queue);
480 vb->state = VIDEOBUF_DONE;
481 do_gettimeofday(&vb->ts);
482 vb->field_count++;
483 wake_up(&vb->done);
484
485 if (list_empty(&pcdev->capture)) {
486 pcdev->active = NULL;
487 DCSR(pcdev->dma_chans[0]) = 0;
488 DCSR(pcdev->dma_chans[1]) = 0;
489 DCSR(pcdev->dma_chans[2]) = 0;
490 CICR0 &= ~CICR0_ENB;
491 return;
492 }
493
494 pcdev->active = list_entry(pcdev->capture.next,
495 struct pxa_buffer, vb.queue);
496}
497
498static void pxa_camera_dma_irq(int channel, struct pxa_camera_dev *pcdev,
499 enum pxa_camera_active_dma act_dma)
500{
501 struct pxa_buffer *buf;
502 unsigned long flags;
503 u32 status, camera_status, overrun;
504 struct videobuf_buffer *vb;
505
506 spin_lock_irqsave(&pcdev->lock, flags);
507
508 status = DCSR(channel);
509 DCSR(channel) = status | DCSR_ENDINTR;
510
511 if (status & DCSR_BUSERR) {
512 dev_err(pcdev->dev, "DMA Bus Error IRQ!\n");
513 goto out;
514 }
515
516 if (!(status & DCSR_ENDINTR)) {
517 dev_err(pcdev->dev, "Unknown DMA IRQ source, "
518 "status: 0x%08x\n", status);
519 goto out;
520 }
521
522 if (!pcdev->active) {
523 dev_err(pcdev->dev, "DMA End IRQ with no active buffer!\n");
524 goto out;
525 }
526
527 camera_status = CISR;
528 overrun = CISR_IFO_0;
529 if (pcdev->channels == 3)
530 overrun |= CISR_IFO_1 | CISR_IFO_2;
531 if (camera_status & overrun) {
532 dev_dbg(pcdev->dev, "FIFO overrun! CISR: %x\n", camera_status);
533 /* Stop the Capture Interface */
534 CICR0 &= ~CICR0_ENB;
535 /* Stop DMA */
536 DCSR(channel) = 0;
537 /* Reset the FIFOs */
538 CIFR |= CIFR_RESET_F;
539 /* Enable End-Of-Frame Interrupt */
540 CICR0 &= ~CICR0_EOFM;
541 /* Restart the Capture Interface */
542 CICR0 |= CICR0_ENB;
543 goto out;
544 }
545
546 vb = &pcdev->active->vb;
547 buf = container_of(vb, struct pxa_buffer, vb);
548 WARN_ON(buf->inwork || list_empty(&vb->queue));
549 dev_dbg(pcdev->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
550 vb, vb->baddr, vb->bsize);
551
552 buf->active_dma &= ~act_dma;
553 if (!buf->active_dma)
554 pxa_camera_wakeup(pcdev, vb, buf);
555
556out:
557 spin_unlock_irqrestore(&pcdev->lock, flags);
558}
559
560static void pxa_camera_dma_irq_y(int channel, void *data)
561{
562 struct pxa_camera_dev *pcdev = data;
563 pxa_camera_dma_irq(channel, pcdev, DMA_Y);
564}
565
566static void pxa_camera_dma_irq_u(int channel, void *data)
567{
568 struct pxa_camera_dev *pcdev = data;
569 pxa_camera_dma_irq(channel, pcdev, DMA_U);
570}
571
572static void pxa_camera_dma_irq_v(int channel, void *data)
573{
574 struct pxa_camera_dev *pcdev = data;
575 pxa_camera_dma_irq(channel, pcdev, DMA_V);
576}
577
578static struct videobuf_queue_ops pxa_videobuf_ops = {
579 .buf_setup = pxa_videobuf_setup,
580 .buf_prepare = pxa_videobuf_prepare,
581 .buf_queue = pxa_videobuf_queue,
582 .buf_release = pxa_videobuf_release,
583};
584
585static int mclk_get_divisor(struct pxa_camera_dev *pcdev)
586{
587 unsigned int mclk_10khz = pcdev->platform_mclk_10khz;
588 unsigned long div;
589 unsigned long lcdclk;
590
591 lcdclk = clk_get_rate(pcdev->clk) / 10000;
592
593 /* We verify platform_mclk_10khz != 0, so if anyone breaks it, here
594 * they get a nice Oops */
595 div = (lcdclk + 2 * mclk_10khz - 1) / (2 * mclk_10khz) - 1;
596
597 dev_dbg(pcdev->dev, "LCD clock %lukHz, target freq %dkHz, "
598 "divisor %lu\n", lcdclk * 10, mclk_10khz * 10, div);
599
600 return div;
601}
602
603static void pxa_camera_activate(struct pxa_camera_dev *pcdev)
604{
605 struct pxacamera_platform_data *pdata = pcdev->pdata;
606 u32 cicr4 = 0;
607
608 dev_dbg(pcdev->dev, "Registered platform device at %p data %p\n",
609 pcdev, pdata);
610
611 if (pdata && pdata->init) {
612 dev_dbg(pcdev->dev, "%s: Init gpios\n", __func__);
613 pdata->init(pcdev->dev);
614 }
615
616 if (pdata && pdata->power) {
617 dev_dbg(pcdev->dev, "%s: Power on camera\n", __func__);
618 pdata->power(pcdev->dev, 1);
619 }
620
621 if (pdata && pdata->reset) {
622 dev_dbg(pcdev->dev, "%s: Releasing camera reset\n",
623 __func__);
624 pdata->reset(pcdev->dev, 1);
625 }
626
627 CICR0 = 0x3FF; /* disable all interrupts */
628
629 if (pcdev->platform_flags & PXA_CAMERA_PCLK_EN)
630 cicr4 |= CICR4_PCLK_EN;
631 if (pcdev->platform_flags & PXA_CAMERA_MCLK_EN)
632 cicr4 |= CICR4_MCLK_EN;
633 if (pcdev->platform_flags & PXA_CAMERA_PCP)
634 cicr4 |= CICR4_PCP;
635 if (pcdev->platform_flags & PXA_CAMERA_HSP)
636 cicr4 |= CICR4_HSP;
637 if (pcdev->platform_flags & PXA_CAMERA_VSP)
638 cicr4 |= CICR4_VSP;
639
640 CICR4 = mclk_get_divisor(pcdev) | cicr4;
641
642 clk_enable(pcdev->clk);
643}
644
645static void pxa_camera_deactivate(struct pxa_camera_dev *pcdev)
646{
647 struct pxacamera_platform_data *board = pcdev->pdata;
648
649 clk_disable(pcdev->clk);
650
651 if (board && board->reset) {
652 dev_dbg(pcdev->dev, "%s: Asserting camera reset\n",
653 __func__);
654 board->reset(pcdev->dev, 0);
655 }
656
657 if (board && board->power) {
658 dev_dbg(pcdev->dev, "%s: Power off camera\n", __func__);
659 board->power(pcdev->dev, 0);
660 }
661}
662
663static irqreturn_t pxa_camera_irq(int irq, void *data)
664{
665 struct pxa_camera_dev *pcdev = data;
666 unsigned int status = CISR;
667
668 dev_dbg(pcdev->dev, "Camera interrupt status 0x%x\n", status);
669
670 if (!status)
671 return IRQ_NONE;
672
673 CISR = status;
674
675 if (status & CISR_EOF) {
676 int i;
677 for (i = 0; i < pcdev->channels; i++) {
678 DDADR(pcdev->dma_chans[i]) =
679 pcdev->active->dmas[i].sg_dma;
680 DCSR(pcdev->dma_chans[i]) = DCSR_RUN;
681 }
682 CICR0 |= CICR0_EOFM;
683 }
684
685 return IRQ_HANDLED;
686}
687
688/* The following two functions absolutely depend on the fact, that
689 * there can be only one camera on PXA quick capture interface */
690static int pxa_camera_add_device(struct soc_camera_device *icd)
691{
692 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
693 struct pxa_camera_dev *pcdev = ici->priv;
694 int ret;
695
696 mutex_lock(&camera_lock);
697
698 if (pcdev->icd) {
699 ret = -EBUSY;
700 goto ebusy;
701 }
702
703 dev_info(&icd->dev, "PXA Camera driver attached to camera %d\n",
704 icd->devnum);
705
706 pxa_camera_activate(pcdev);
707 ret = icd->ops->init(icd);
708
709 if (!ret)
710 pcdev->icd = icd;
711
712ebusy:
713 mutex_unlock(&camera_lock);
714
715 return ret;
716}
717
718static void pxa_camera_remove_device(struct soc_camera_device *icd)
719{
720 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
721 struct pxa_camera_dev *pcdev = ici->priv;
722
723 BUG_ON(icd != pcdev->icd);
724
725 dev_info(&icd->dev, "PXA Camera driver detached from camera %d\n",
726 icd->devnum);
727
728 /* disable capture, disable interrupts */
729 CICR0 = 0x3ff;
730
731 /* Stop DMA engine */
732 DCSR(pcdev->dma_chans[0]) = 0;
733 DCSR(pcdev->dma_chans[1]) = 0;
734 DCSR(pcdev->dma_chans[2]) = 0;
735
736 icd->ops->release(icd);
737
738 pxa_camera_deactivate(pcdev);
739
740 pcdev->icd = NULL;
741}
742
743static int test_platform_param(struct pxa_camera_dev *pcdev,
744 unsigned char buswidth, unsigned long *flags)
745{
746 /*
747 * Platform specified synchronization and pixel clock polarities are
748 * only a recommendation and are only used during probing. The PXA270
749 * quick capture interface supports both.
750 */
751 *flags = (pcdev->platform_flags & PXA_CAMERA_MASTER ?
752 SOCAM_MASTER : SOCAM_SLAVE) |
753 SOCAM_HSYNC_ACTIVE_HIGH |
754 SOCAM_HSYNC_ACTIVE_LOW |
755 SOCAM_VSYNC_ACTIVE_HIGH |
756 SOCAM_VSYNC_ACTIVE_LOW |
757 SOCAM_PCLK_SAMPLE_RISING |
758 SOCAM_PCLK_SAMPLE_FALLING;
759
760 /* If requested data width is supported by the platform, use it */
761 switch (buswidth) {
762 case 10:
763 if (!(pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_10))
764 return -EINVAL;
765 *flags |= SOCAM_DATAWIDTH_10;
766 break;
767 case 9:
768 if (!(pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_9))
769 return -EINVAL;
770 *flags |= SOCAM_DATAWIDTH_9;
771 break;
772 case 8:
773 if (!(pcdev->platform_flags & PXA_CAMERA_DATAWIDTH_8))
774 return -EINVAL;
775 *flags |= SOCAM_DATAWIDTH_8;
776 }
777
778 return 0;
779}
780
781static int pxa_camera_set_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
782{
783 struct soc_camera_host *ici =
784 to_soc_camera_host(icd->dev.parent);
785 struct pxa_camera_dev *pcdev = ici->priv;
786 unsigned long dw, bpp, bus_flags, camera_flags, common_flags;
787 u32 cicr0, cicr1, cicr4 = 0;
788 int ret = test_platform_param(pcdev, icd->buswidth, &bus_flags);
789
790 if (ret < 0)
791 return ret;
792
793 camera_flags = icd->ops->query_bus_param(icd);
794
795 common_flags = soc_camera_bus_param_compatible(camera_flags, bus_flags);
796 if (!common_flags)
797 return -EINVAL;
798
799 pcdev->channels = 1;
800
801 /* Make choises, based on platform preferences */
802 if ((common_flags & SOCAM_HSYNC_ACTIVE_HIGH) &&
803 (common_flags & SOCAM_HSYNC_ACTIVE_LOW)) {
804 if (pcdev->platform_flags & PXA_CAMERA_HSP)
805 common_flags &= ~SOCAM_HSYNC_ACTIVE_HIGH;
806 else
807 common_flags &= ~SOCAM_HSYNC_ACTIVE_LOW;
808 }
809
810 if ((common_flags & SOCAM_VSYNC_ACTIVE_HIGH) &&
811 (common_flags & SOCAM_VSYNC_ACTIVE_LOW)) {
812 if (pcdev->platform_flags & PXA_CAMERA_VSP)
813 common_flags &= ~SOCAM_VSYNC_ACTIVE_HIGH;
814 else
815 common_flags &= ~SOCAM_VSYNC_ACTIVE_LOW;
816 }
817
818 if ((common_flags & SOCAM_PCLK_SAMPLE_RISING) &&
819 (common_flags & SOCAM_PCLK_SAMPLE_FALLING)) {
820 if (pcdev->platform_flags & PXA_CAMERA_PCP)
821 common_flags &= ~SOCAM_PCLK_SAMPLE_RISING;
822 else
823 common_flags &= ~SOCAM_PCLK_SAMPLE_FALLING;
824 }
825
826 ret = icd->ops->set_bus_param(icd, common_flags);
827 if (ret < 0)
828 return ret;
829
830 /* Datawidth is now guaranteed to be equal to one of the three values.
831 * We fix bit-per-pixel equal to data-width... */
832 switch (common_flags & SOCAM_DATAWIDTH_MASK) {
833 case SOCAM_DATAWIDTH_10:
834 icd->buswidth = 10;
835 dw = 4;
836 bpp = 0x40;
837 break;
838 case SOCAM_DATAWIDTH_9:
839 icd->buswidth = 9;
840 dw = 3;
841 bpp = 0x20;
842 break;
843 default:
844 /* Actually it can only be 8 now,
845 * default is just to silence compiler warnings */
846 case SOCAM_DATAWIDTH_8:
847 icd->buswidth = 8;
848 dw = 2;
849 bpp = 0;
850 }
851
852 if (pcdev->platform_flags & PXA_CAMERA_PCLK_EN)
853 cicr4 |= CICR4_PCLK_EN;
854 if (pcdev->platform_flags & PXA_CAMERA_MCLK_EN)
855 cicr4 |= CICR4_MCLK_EN;
856 if (common_flags & SOCAM_PCLK_SAMPLE_FALLING)
857 cicr4 |= CICR4_PCP;
858 if (common_flags & SOCAM_HSYNC_ACTIVE_LOW)
859 cicr4 |= CICR4_HSP;
860 if (common_flags & SOCAM_VSYNC_ACTIVE_LOW)
861 cicr4 |= CICR4_VSP;
862
863 cicr0 = CICR0;
864 if (cicr0 & CICR0_ENB)
865 CICR0 = cicr0 & ~CICR0_ENB;
866
867 cicr1 = CICR1_PPL_VAL(icd->width - 1) | bpp | dw;
868
869 switch (pixfmt) {
870 case V4L2_PIX_FMT_YUV422P:
871 pcdev->channels = 3;
872 cicr1 |= CICR1_YCBCR_F;
873 case V4L2_PIX_FMT_YUYV:
874 cicr1 |= CICR1_COLOR_SP_VAL(2);
875 break;
876 case V4L2_PIX_FMT_RGB555:
877 cicr1 |= CICR1_RGB_BPP_VAL(1) | CICR1_RGBT_CONV_VAL(2) |
878 CICR1_TBIT | CICR1_COLOR_SP_VAL(1);
879 break;
880 case V4L2_PIX_FMT_RGB565:
881 cicr1 |= CICR1_COLOR_SP_VAL(1) | CICR1_RGB_BPP_VAL(2);
882 break;
883 }
884
885 CICR1 = cicr1;
886 CICR2 = 0;
887 CICR3 = CICR3_LPF_VAL(icd->height - 1) |
888 CICR3_BFW_VAL(min((unsigned short)255, icd->y_skip_top));
889 CICR4 = mclk_get_divisor(pcdev) | cicr4;
890
891 /* CIF interrupts are not used, only DMA */
892 CICR0 = (pcdev->platform_flags & PXA_CAMERA_MASTER ?
893 CICR0_SIM_MP : (CICR0_SL_CAP_EN | CICR0_SIM_SP)) |
894 CICR0_DMAEN | CICR0_IRQ_MASK | (cicr0 & CICR0_ENB);
895
896 return 0;
897}
898
899static int pxa_camera_try_bus_param(struct soc_camera_device *icd, __u32 pixfmt)
900{
901 struct soc_camera_host *ici =
902 to_soc_camera_host(icd->dev.parent);
903 struct pxa_camera_dev *pcdev = ici->priv;
904 unsigned long bus_flags, camera_flags;
905 int ret = test_platform_param(pcdev, icd->buswidth, &bus_flags);
906
907 if (ret < 0)
908 return ret;
909
910 camera_flags = icd->ops->query_bus_param(icd);
911
912 return soc_camera_bus_param_compatible(camera_flags, bus_flags) ? 0 : -EINVAL;
913}
914
915static int pxa_camera_set_fmt_cap(struct soc_camera_device *icd,
916 __u32 pixfmt, struct v4l2_rect *rect)
917{
918 return icd->ops->set_fmt_cap(icd, pixfmt, rect);
919}
920
921static int pxa_camera_try_fmt_cap(struct soc_camera_device *icd,
922 struct v4l2_format *f)
923{
924 /* limit to pxa hardware capabilities */
925 if (f->fmt.pix.height < 32)
926 f->fmt.pix.height = 32;
927 if (f->fmt.pix.height > 2048)
928 f->fmt.pix.height = 2048;
929 if (f->fmt.pix.width < 48)
930 f->fmt.pix.width = 48;
931 if (f->fmt.pix.width > 2048)
932 f->fmt.pix.width = 2048;
933 f->fmt.pix.width &= ~0x01;
934
935 /* limit to sensor capabilities */
936 return icd->ops->try_fmt_cap(icd, f);
937}
938
939static int pxa_camera_reqbufs(struct soc_camera_file *icf,
940 struct v4l2_requestbuffers *p)
941{
942 int i;
943
944 /* This is for locking debugging only. I removed spinlocks and now I
945 * check whether .prepare is ever called on a linked buffer, or whether
946 * a dma IRQ can occur for an in-work or unlinked buffer. Until now
947 * it hadn't triggered */
948 for (i = 0; i < p->count; i++) {
949 struct pxa_buffer *buf = container_of(icf->vb_vidq.bufs[i],
950 struct pxa_buffer, vb);
951 buf->inwork = 0;
952 INIT_LIST_HEAD(&buf->vb.queue);
953 }
954
955 return 0;
956}
957
958static unsigned int pxa_camera_poll(struct file *file, poll_table *pt)
959{
960 struct soc_camera_file *icf = file->private_data;
961 struct pxa_buffer *buf;
962
963 buf = list_entry(icf->vb_vidq.stream.next, struct pxa_buffer,
964 vb.stream);
965
966 poll_wait(file, &buf->vb.done, pt);
967
968 if (buf->vb.state == VIDEOBUF_DONE ||
969 buf->vb.state == VIDEOBUF_ERROR)
970 return POLLIN|POLLRDNORM;
971
972 return 0;
973}
974
975static int pxa_camera_querycap(struct soc_camera_host *ici,
976 struct v4l2_capability *cap)
977{
978 /* cap->name is set by the firendly caller:-> */
979 strlcpy(cap->card, pxa_cam_driver_description, sizeof(cap->card));
980 cap->version = PXA_CAM_VERSION_CODE;
981 cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
982
983 return 0;
984}
985
986static spinlock_t *pxa_camera_spinlock_alloc(struct soc_camera_file *icf)
987{
988 struct soc_camera_host *ici =
989 to_soc_camera_host(icf->icd->dev.parent);
990 struct pxa_camera_dev *pcdev = ici->priv;
991
992 return &pcdev->lock;
993}
994
995static struct soc_camera_host_ops pxa_soc_camera_host_ops = {
996 .owner = THIS_MODULE,
997 .add = pxa_camera_add_device,
998 .remove = pxa_camera_remove_device,
999 .set_fmt_cap = pxa_camera_set_fmt_cap,
1000 .try_fmt_cap = pxa_camera_try_fmt_cap,
1001 .reqbufs = pxa_camera_reqbufs,
1002 .poll = pxa_camera_poll,
1003 .querycap = pxa_camera_querycap,
1004 .try_bus_param = pxa_camera_try_bus_param,
1005 .set_bus_param = pxa_camera_set_bus_param,
1006 .spinlock_alloc = pxa_camera_spinlock_alloc,
1007};
1008
1009/* Should be allocated dynamically too, but we have only one. */
1010static struct soc_camera_host pxa_soc_camera_host = {
1011 .drv_name = PXA_CAM_DRV_NAME,
1012 .vbq_ops = &pxa_videobuf_ops,
1013 .msize = sizeof(struct pxa_buffer),
1014 .ops = &pxa_soc_camera_host_ops,
1015};
1016
1017static int pxa_camera_probe(struct platform_device *pdev)
1018{
1019 struct pxa_camera_dev *pcdev;
1020 struct resource *res;
1021 void __iomem *base;
1022 unsigned int irq;
1023 int err = 0;
1024
1025 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1026 irq = platform_get_irq(pdev, 0);
1027 if (!res || !irq) {
1028 err = -ENODEV;
1029 goto exit;
1030 }
1031
1032 pcdev = kzalloc(sizeof(*pcdev), GFP_KERNEL);
1033 if (!pcdev) {
1034 dev_err(&pdev->dev, "Could not allocate pcdev\n");
1035 err = -ENOMEM;
1036 goto exit;
1037 }
1038
1039 pcdev->clk = clk_get(&pdev->dev, "CAMCLK");
1040 if (IS_ERR(pcdev->clk)) {
1041 err = PTR_ERR(pcdev->clk);
1042 goto exit_kfree;
1043 }
1044
1045 dev_set_drvdata(&pdev->dev, pcdev);
1046 pcdev->res = res;
1047
1048 pcdev->pdata = pdev->dev.platform_data;
1049 pcdev->platform_flags = pcdev->pdata->flags;
1050 if (!(pcdev->platform_flags & (PXA_CAMERA_DATAWIDTH_8 |
1051 PXA_CAMERA_DATAWIDTH_9 | PXA_CAMERA_DATAWIDTH_10))) {
1052 /* Platform hasn't set available data widths. This is bad.
1053 * Warn and use a default. */
1054 dev_warn(&pdev->dev, "WARNING! Platform hasn't set available "
1055 "data widths, using default 10 bit\n");
1056 pcdev->platform_flags |= PXA_CAMERA_DATAWIDTH_10;
1057 }
1058 pcdev->platform_mclk_10khz = pcdev->pdata->mclk_10khz;
1059 if (!pcdev->platform_mclk_10khz) {
1060 dev_warn(&pdev->dev,
1061 "mclk_10khz == 0! Please, fix your platform data. "
1062 "Using default 20MHz\n");
1063 pcdev->platform_mclk_10khz = 2000;
1064 }
1065
1066 INIT_LIST_HEAD(&pcdev->capture);
1067 spin_lock_init(&pcdev->lock);
1068
1069 /*
1070 * Request the regions.
1071 */
1072 if (!request_mem_region(res->start, res->end - res->start + 1,
1073 PXA_CAM_DRV_NAME)) {
1074 err = -EBUSY;
1075 goto exit_clk;
1076 }
1077
1078 base = ioremap(res->start, res->end - res->start + 1);
1079 if (!base) {
1080 err = -ENOMEM;
1081 goto exit_release;
1082 }
1083 pcdev->irq = irq;
1084 pcdev->base = base;
1085 pcdev->dev = &pdev->dev;
1086
1087 /* request dma */
1088 pcdev->dma_chans[0] = pxa_request_dma("CI_Y", DMA_PRIO_HIGH,
1089 pxa_camera_dma_irq_y, pcdev);
1090 if (pcdev->dma_chans[0] < 0) {
1091 dev_err(pcdev->dev, "Can't request DMA for Y\n");
1092 err = -ENOMEM;
1093 goto exit_iounmap;
1094 }
1095 dev_dbg(pcdev->dev, "got DMA channel %d\n", pcdev->dma_chans[0]);
1096
1097 pcdev->dma_chans[1] = pxa_request_dma("CI_U", DMA_PRIO_HIGH,
1098 pxa_camera_dma_irq_u, pcdev);
1099 if (pcdev->dma_chans[1] < 0) {
1100 dev_err(pcdev->dev, "Can't request DMA for U\n");
1101 err = -ENOMEM;
1102 goto exit_free_dma_y;
1103 }
1104 dev_dbg(pcdev->dev, "got DMA channel (U) %d\n", pcdev->dma_chans[1]);
1105
1106 pcdev->dma_chans[2] = pxa_request_dma("CI_V", DMA_PRIO_HIGH,
1107 pxa_camera_dma_irq_v, pcdev);
1108 if (pcdev->dma_chans[0] < 0) {
1109 dev_err(pcdev->dev, "Can't request DMA for V\n");
1110 err = -ENOMEM;
1111 goto exit_free_dma_u;
1112 }
1113 dev_dbg(pcdev->dev, "got DMA channel (V) %d\n", pcdev->dma_chans[2]);
1114
1115 DRCMR68 = pcdev->dma_chans[0] | DRCMR_MAPVLD;
1116 DRCMR69 = pcdev->dma_chans[1] | DRCMR_MAPVLD;
1117 DRCMR70 = pcdev->dma_chans[2] | DRCMR_MAPVLD;
1118
1119 /* request irq */
1120 err = request_irq(pcdev->irq, pxa_camera_irq, 0, PXA_CAM_DRV_NAME,
1121 pcdev);
1122 if (err) {
1123 dev_err(pcdev->dev, "Camera interrupt register failed \n");
1124 goto exit_free_dma;
1125 }
1126
1127 pxa_soc_camera_host.priv = pcdev;
1128 pxa_soc_camera_host.dev.parent = &pdev->dev;
1129 pxa_soc_camera_host.nr = pdev->id;
1130 err = soc_camera_host_register(&pxa_soc_camera_host);
1131 if (err)
1132 goto exit_free_irq;
1133
1134 return 0;
1135
1136exit_free_irq:
1137 free_irq(pcdev->irq, pcdev);
1138exit_free_dma:
1139 pxa_free_dma(pcdev->dma_chans[2]);
1140exit_free_dma_u:
1141 pxa_free_dma(pcdev->dma_chans[1]);
1142exit_free_dma_y:
1143 pxa_free_dma(pcdev->dma_chans[0]);
1144exit_iounmap:
1145 iounmap(base);
1146exit_release:
1147 release_mem_region(res->start, res->end - res->start + 1);
1148exit_clk:
1149 clk_put(pcdev->clk);
1150exit_kfree:
1151 kfree(pcdev);
1152exit:
1153 return err;
1154}
1155
1156static int __devexit pxa_camera_remove(struct platform_device *pdev)
1157{
1158 struct pxa_camera_dev *pcdev = platform_get_drvdata(pdev);
1159 struct resource *res;
1160
1161 clk_put(pcdev->clk);
1162
1163 pxa_free_dma(pcdev->dma_chans[0]);
1164 pxa_free_dma(pcdev->dma_chans[1]);
1165 pxa_free_dma(pcdev->dma_chans[2]);
1166 free_irq(pcdev->irq, pcdev);
1167
1168 soc_camera_host_unregister(&pxa_soc_camera_host);
1169
1170 iounmap(pcdev->base);
1171
1172 res = pcdev->res;
1173 release_mem_region(res->start, res->end - res->start + 1);
1174
1175 kfree(pcdev);
1176
1177 dev_info(&pdev->dev, "PXA Camera driver unloaded\n");
1178
1179 return 0;
1180}
1181
1182static struct platform_driver pxa_camera_driver = {
1183 .driver = {
1184 .name = PXA_CAM_DRV_NAME,
1185 },
1186 .probe = pxa_camera_probe,
1187 .remove = __exit_p(pxa_camera_remove),
1188};
1189
1190
1191static int __devinit pxa_camera_init(void)
1192{
1193 return platform_driver_register(&pxa_camera_driver);
1194}
1195
1196static void __exit pxa_camera_exit(void)
1197{
1198 return platform_driver_unregister(&pxa_camera_driver);
1199}
1200
1201module_init(pxa_camera_init);
1202module_exit(pxa_camera_exit);
1203
1204MODULE_DESCRIPTION("PXA27x SoC Camera Host driver");
1205MODULE_AUTHOR("Guennadi Liakhovetski <kernel@pengutronix.de>");
1206MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/saa5249.c b/drivers/media/video/saa5249.c
index f55d6e85f20f..ec8c65dc8408 100644
--- a/drivers/media/video/saa5249.c
+++ b/drivers/media/video/saa5249.c
@@ -701,7 +701,9 @@ static const struct file_operations saa_fops = {
701 .open = saa5249_open, 701 .open = saa5249_open,
702 .release = saa5249_release, 702 .release = saa5249_release,
703 .ioctl = saa5249_ioctl, 703 .ioctl = saa5249_ioctl,
704#ifdef CONFIG_COMPAT
704 .compat_ioctl = v4l_compat_ioctl32, 705 .compat_ioctl = v4l_compat_ioctl32,
706#endif
705 .llseek = no_llseek, 707 .llseek = no_llseek,
706}; 708};
707 709
diff --git a/drivers/media/video/saa6588.c b/drivers/media/video/saa6588.c
index 72e344a12c79..716ee7f64df3 100644
--- a/drivers/media/video/saa6588.c
+++ b/drivers/media/video/saa6588.c
@@ -44,10 +44,10 @@ static unsigned short normal_i2c[] = {
44I2C_CLIENT_INSMOD; 44I2C_CLIENT_INSMOD;
45 45
46/* insmod options */ 46/* insmod options */
47static unsigned int debug = 0; 47static unsigned int debug;
48static unsigned int xtal = 0; 48static unsigned int xtal;
49static unsigned int rbds = 0; 49static unsigned int rbds;
50static unsigned int plvl = 0; 50static unsigned int plvl;
51static unsigned int bufblocks = 100; 51static unsigned int bufblocks = 100;
52 52
53module_param(debug, int, 0644); 53module_param(debug, int, 0644);
diff --git a/drivers/media/video/saa7110.c b/drivers/media/video/saa7110.c
index 1df2602cd184..4aa82b310708 100644
--- a/drivers/media/video/saa7110.c
+++ b/drivers/media/video/saa7110.c
@@ -46,7 +46,7 @@ MODULE_LICENSE("GPL");
46#include <media/v4l2-common.h> 46#include <media/v4l2-common.h>
47#include <linux/video_decoder.h> 47#include <linux/video_decoder.h>
48 48
49static int debug = 0; 49static int debug;
50module_param(debug, int, 0); 50module_param(debug, int, 0);
51MODULE_PARM_DESC(debug, "Debug level (0-1)"); 51MODULE_PARM_DESC(debug, "Debug level (0-1)");
52 52
diff --git a/drivers/media/video/saa7111.c b/drivers/media/video/saa7111.c
index a0772c53bb1f..96c3d4357722 100644
--- a/drivers/media/video/saa7111.c
+++ b/drivers/media/video/saa7111.c
@@ -55,7 +55,7 @@ MODULE_LICENSE("GPL");
55#define I2C_NAME(s) (s)->name 55#define I2C_NAME(s) (s)->name
56 56
57 57
58static int debug = 0; 58static int debug;
59module_param(debug, int, 0644); 59module_param(debug, int, 0644);
60MODULE_PARM_DESC(debug, "Debug level (0-1)"); 60MODULE_PARM_DESC(debug, "Debug level (0-1)");
61 61
diff --git a/drivers/media/video/saa7114.c b/drivers/media/video/saa7114.c
index bf91a4faa706..e79075533beb 100644
--- a/drivers/media/video/saa7114.c
+++ b/drivers/media/video/saa7114.c
@@ -56,7 +56,7 @@ MODULE_LICENSE("GPL");
56#define I2C_NAME(x) (x)->name 56#define I2C_NAME(x) (x)->name
57 57
58 58
59static int debug = 0; 59static int debug;
60module_param(debug, int, 0); 60module_param(debug, int, 0);
61MODULE_PARM_DESC(debug, "Debug level (0-1)"); 61MODULE_PARM_DESC(debug, "Debug level (0-1)");
62 62
diff --git a/drivers/media/video/saa7115.c b/drivers/media/video/saa7115.c
index 41e5e518a47e..416d05d4a969 100644
--- a/drivers/media/video/saa7115.c
+++ b/drivers/media/video/saa7115.c
@@ -57,7 +57,7 @@ MODULE_AUTHOR( "Maxim Yevtyushkin, Kevin Thayer, Chris Kennedy, "
57 "Hans Verkuil, Mauro Carvalho Chehab"); 57 "Hans Verkuil, Mauro Carvalho Chehab");
58MODULE_LICENSE("GPL"); 58MODULE_LICENSE("GPL");
59 59
60static int debug = 0; 60static int debug;
61module_param(debug, bool, 0644); 61module_param(debug, bool, 0644);
62 62
63MODULE_PARM_DESC(debug, "Debug level (0-1)"); 63MODULE_PARM_DESC(debug, "Debug level (0-1)");
@@ -957,7 +957,7 @@ static void saa711x_set_v4lstd(struct i2c_client *client, v4l2_std_id std)
957 957
958 if (std == V4L2_STD_PAL_M) { 958 if (std == V4L2_STD_PAL_M) {
959 reg |= 0x30; 959 reg |= 0x30;
960 } else if (std == V4L2_STD_PAL_N) { 960 } else if (std == V4L2_STD_PAL_Nc) {
961 reg |= 0x20; 961 reg |= 0x20;
962 } else if (std == V4L2_STD_PAL_60) { 962 } else if (std == V4L2_STD_PAL_60) {
963 reg |= 0x10; 963 reg |= 0x10;
diff --git a/drivers/media/video/saa711x.c b/drivers/media/video/saa711x.c
index 80bf91187856..cedb988574bd 100644
--- a/drivers/media/video/saa711x.c
+++ b/drivers/media/video/saa711x.c
@@ -48,7 +48,7 @@ MODULE_LICENSE("GPL");
48 48
49#include <linux/video_decoder.h> 49#include <linux/video_decoder.h>
50 50
51static int debug = 0; 51static int debug;
52module_param(debug, int, 0644); 52module_param(debug, int, 0644);
53MODULE_PARM_DESC(debug, " Set the default Debug level. Default: 0 (Off) - (0-1)"); 53MODULE_PARM_DESC(debug, " Set the default Debug level. Default: 0 (Off) - (0-1)");
54 54
diff --git a/drivers/media/video/saa7134/Kconfig b/drivers/media/video/saa7134/Kconfig
index 96bc3b1298a2..e086f14d5663 100644
--- a/drivers/media/video/saa7134/Kconfig
+++ b/drivers/media/video/saa7134/Kconfig
@@ -37,6 +37,7 @@ config VIDEO_SAA7134_DVB
37 select DVB_TDA826X if !DVB_FE_CUSTOMISE 37 select DVB_TDA826X if !DVB_FE_CUSTOMISE
38 select DVB_TDA827X if !DVB_FE_CUSTOMISE 38 select DVB_TDA827X if !DVB_FE_CUSTOMISE
39 select DVB_ISL6421 if !DVB_FE_CUSTOMISE 39 select DVB_ISL6421 if !DVB_FE_CUSTOMISE
40 select TUNER_SIMPLE if !DVB_FE_CUSTOMISE
40 ---help--- 41 ---help---
41 This adds support for DVB cards based on the 42 This adds support for DVB cards based on the
42 Philips saa7134 chip. 43 Philips saa7134 chip.
diff --git a/drivers/media/video/saa7134/saa7134-alsa.c b/drivers/media/video/saa7134/saa7134-alsa.c
index 047add8f3010..ba3082422a01 100644
--- a/drivers/media/video/saa7134/saa7134-alsa.c
+++ b/drivers/media/video/saa7134/saa7134-alsa.c
@@ -31,7 +31,7 @@
31#include "saa7134.h" 31#include "saa7134.h"
32#include "saa7134-reg.h" 32#include "saa7134-reg.h"
33 33
34static unsigned int debug = 0; 34static unsigned int debug;
35module_param(debug, int, 0644); 35module_param(debug, int, 0644);
36MODULE_PARM_DESC(debug,"enable debug messages [alsa]"); 36MODULE_PARM_DESC(debug,"enable debug messages [alsa]");
37 37
@@ -503,7 +503,7 @@ static int snd_card_saa7134_hw_params(struct snd_pcm_substream * substream,
503 /* release the old buffer */ 503 /* release the old buffer */
504 if (substream->runtime->dma_area) { 504 if (substream->runtime->dma_area) {
505 saa7134_pgtable_free(dev->pci, &dev->dmasound.pt); 505 saa7134_pgtable_free(dev->pci, &dev->dmasound.pt);
506 videobuf_pci_dma_unmap(dev->pci, &dev->dmasound.dma); 506 videobuf_sg_dma_unmap(&dev->pci->dev, &dev->dmasound.dma);
507 dsp_buffer_free(dev); 507 dsp_buffer_free(dev);
508 substream->runtime->dma_area = NULL; 508 substream->runtime->dma_area = NULL;
509 } 509 }
@@ -519,12 +519,12 @@ static int snd_card_saa7134_hw_params(struct snd_pcm_substream * substream,
519 return err; 519 return err;
520 } 520 }
521 521
522 if (0 != (err = videobuf_pci_dma_map(dev->pci, &dev->dmasound.dma))) { 522 if (0 != (err = videobuf_sg_dma_map(&dev->pci->dev, &dev->dmasound.dma))) {
523 dsp_buffer_free(dev); 523 dsp_buffer_free(dev);
524 return err; 524 return err;
525 } 525 }
526 if (0 != (err = saa7134_pgtable_alloc(dev->pci,&dev->dmasound.pt))) { 526 if (0 != (err = saa7134_pgtable_alloc(dev->pci,&dev->dmasound.pt))) {
527 videobuf_pci_dma_unmap(dev->pci, &dev->dmasound.dma); 527 videobuf_sg_dma_unmap(&dev->pci->dev, &dev->dmasound.dma);
528 dsp_buffer_free(dev); 528 dsp_buffer_free(dev);
529 return err; 529 return err;
530 } 530 }
@@ -533,7 +533,7 @@ static int snd_card_saa7134_hw_params(struct snd_pcm_substream * substream,
533 dev->dmasound.dma.sglen, 533 dev->dmasound.dma.sglen,
534 0))) { 534 0))) {
535 saa7134_pgtable_free(dev->pci, &dev->dmasound.pt); 535 saa7134_pgtable_free(dev->pci, &dev->dmasound.pt);
536 videobuf_pci_dma_unmap(dev->pci, &dev->dmasound.dma); 536 videobuf_sg_dma_unmap(&dev->pci->dev, &dev->dmasound.dma);
537 dsp_buffer_free(dev); 537 dsp_buffer_free(dev);
538 return err; 538 return err;
539 } 539 }
@@ -569,7 +569,7 @@ static int snd_card_saa7134_hw_free(struct snd_pcm_substream * substream)
569 569
570 if (substream->runtime->dma_area) { 570 if (substream->runtime->dma_area) {
571 saa7134_pgtable_free(dev->pci, &dev->dmasound.pt); 571 saa7134_pgtable_free(dev->pci, &dev->dmasound.pt);
572 videobuf_pci_dma_unmap(dev->pci, &dev->dmasound.dma); 572 videobuf_sg_dma_unmap(&dev->pci->dev, &dev->dmasound.dma);
573 dsp_buffer_free(dev); 573 dsp_buffer_free(dev);
574 substream->runtime->dma_area = NULL; 574 substream->runtime->dma_area = NULL;
575 } 575 }
@@ -954,10 +954,8 @@ static void snd_saa7134_free(struct snd_card * card)
954 if (chip->dev->dmasound.priv_data == NULL) 954 if (chip->dev->dmasound.priv_data == NULL)
955 return; 955 return;
956 956
957 if (chip->irq >= 0) { 957 if (chip->irq >= 0)
958 synchronize_irq(chip->irq);
959 free_irq(chip->irq, &chip->dev->dmasound); 958 free_irq(chip->irq, &chip->dev->dmasound);
960 }
961 959
962 chip->dev->dmasound.priv_data = NULL; 960 chip->dev->dmasound.priv_data = NULL;
963 961
diff --git a/drivers/media/video/saa7134/saa7134-cards.c b/drivers/media/video/saa7134/saa7134-cards.c
index 6f5744286e8c..98375955a84b 100644
--- a/drivers/media/video/saa7134/saa7134-cards.c
+++ b/drivers/media/video/saa7134/saa7134-cards.c
@@ -22,11 +22,15 @@
22 22
23#include <linux/init.h> 23#include <linux/init.h>
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/i2c.h>
26#include <linux/i2c-algo-bit.h>
25 27
26#include "saa7134-reg.h" 28#include "saa7134-reg.h"
27#include "saa7134.h" 29#include "saa7134.h"
30#include "tuner-xc2028.h"
28#include <media/v4l2-common.h> 31#include <media/v4l2-common.h>
29#include <media/tveeprom.h> 32#include <media/tveeprom.h>
33#include "tea5767.h"
30 34
31/* commly used strings */ 35/* commly used strings */
32static char name_mute[] = "mute"; 36static char name_mute[] = "mute";
@@ -1046,7 +1050,7 @@ struct saa7134_board saa7134_boards[] = {
1046 }, 1050 },
1047 [SAA7134_BOARD_MANLI_MTV002] = { 1051 [SAA7134_BOARD_MANLI_MTV002] = {
1048 /* Ognjen Nastic <ognjen@logosoft.ba> */ 1052 /* Ognjen Nastic <ognjen@logosoft.ba> */
1049 .name = "Manli MuchTV M-TV002/Behold TV 403 FM", 1053 .name = "Manli MuchTV M-TV002",
1050 .audio_clock = 0x00200000, 1054 .audio_clock = 0x00200000,
1051 .tuner_type = TUNER_PHILIPS_PAL, 1055 .tuner_type = TUNER_PHILIPS_PAL,
1052 .radio_type = UNSET, 1056 .radio_type = UNSET,
@@ -1073,7 +1077,7 @@ struct saa7134_board saa7134_boards[] = {
1073 }, 1077 },
1074 [SAA7134_BOARD_MANLI_MTV001] = { 1078 [SAA7134_BOARD_MANLI_MTV001] = {
1075 /* Ognjen Nastic <ognjen@logosoft.ba> UNTESTED */ 1079 /* Ognjen Nastic <ognjen@logosoft.ba> UNTESTED */
1076 .name = "Manli MuchTV M-TV001/Behold TV 401", 1080 .name = "Manli MuchTV M-TV001",
1077 .audio_clock = 0x00200000, 1081 .audio_clock = 0x00200000,
1078 .tuner_type = TUNER_PHILIPS_PAL, 1082 .tuner_type = TUNER_PHILIPS_PAL,
1079 .radio_type = UNSET, 1083 .radio_type = UNSET,
@@ -2195,6 +2199,8 @@ struct saa7134_board saa7134_boards[] = {
2195 }, 2199 },
2196 [SAA7134_BOARD_BEHOLD_409FM] = { 2200 [SAA7134_BOARD_BEHOLD_409FM] = {
2197 /* <http://tuner.beholder.ru>, Sergey <skiv@orel.ru> */ 2201 /* <http://tuner.beholder.ru>, Sergey <skiv@orel.ru> */
2202 /* Beholder Intl. Ltd. 2008 */
2203 /*Dmitry Belimov <d.belimov@gmail.com> */
2198 .name = "Beholder BeholdTV 409 FM", 2204 .name = "Beholder BeholdTV 409 FM",
2199 .audio_clock = 0x00187de7, 2205 .audio_clock = 0x00187de7,
2200 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 2206 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
@@ -2202,6 +2208,7 @@ struct saa7134_board saa7134_boards[] = {
2202 .tuner_addr = ADDR_UNSET, 2208 .tuner_addr = ADDR_UNSET,
2203 .radio_addr = ADDR_UNSET, 2209 .radio_addr = ADDR_UNSET,
2204 .tda9887_conf = TDA9887_PRESENT, 2210 .tda9887_conf = TDA9887_PRESENT,
2211 .gpiomask = 0x00008000,
2205 .inputs = {{ 2212 .inputs = {{
2206 .name = name_tv, 2213 .name = name_tv,
2207 .vmux = 3, 2214 .vmux = 3,
@@ -2908,15 +2915,13 @@ struct saa7134_board saa7134_boards[] = {
2908 }}, 2915 }},
2909 }, 2916 },
2910 [SAA7134_BOARD_MD7134_BRIDGE_2] = { 2917 [SAA7134_BOARD_MD7134_BRIDGE_2] = {
2911 /* This card has two saa7134 chips on it, 2918 /* The second saa7134 on this card only serves as DVB-S host bridge */
2912 but only one of them is currently working.
2913 The programming for the primary decoder is
2914 in SAA7134_BOARD_MD7134 */
2915 .name = "Medion 7134 Bridge #2", 2919 .name = "Medion 7134 Bridge #2",
2916 .audio_clock = 0x00187de7, 2920 .audio_clock = 0x00187de7,
2917 .radio_type = UNSET, 2921 .radio_type = UNSET,
2918 .tuner_addr = ADDR_UNSET, 2922 .tuner_addr = ADDR_UNSET,
2919 .radio_addr = ADDR_UNSET, 2923 .radio_addr = ADDR_UNSET,
2924 .mpeg = SAA7134_MPEG_DVB,
2920 }, 2925 },
2921 [SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS] = { 2926 [SAA7134_BOARD_FLYDVBT_HYBRID_CARDBUS] = {
2922 .name = "LifeView FlyDVB-T Hybrid Cardbus/MSI TV @nywhere A/D NB", 2927 .name = "LifeView FlyDVB-T Hybrid Cardbus/MSI TV @nywhere A/D NB",
@@ -3330,7 +3335,7 @@ struct saa7134_board saa7134_boards[] = {
3330 /* Juan Pablo Sormani <sorman@gmail.com> */ 3335 /* Juan Pablo Sormani <sorman@gmail.com> */
3331 .name = "Encore ENLTV-FM", 3336 .name = "Encore ENLTV-FM",
3332 .audio_clock = 0x00200000, 3337 .audio_clock = 0x00200000,
3333 .tuner_type = TUNER_PHILIPS_ATSC, 3338 .tuner_type = TUNER_PHILIPS_FCV1236D,
3334 .radio_type = UNSET, 3339 .radio_type = UNSET,
3335 .tuner_addr = ADDR_UNSET, 3340 .tuner_addr = ADDR_UNSET,
3336 .radio_addr = ADDR_UNSET, 3341 .radio_addr = ADDR_UNSET,
@@ -3575,12 +3580,15 @@ struct saa7134_board saa7134_boards[] = {
3575 }}, 3580 }},
3576 }, 3581 },
3577 [SAA7134_BOARD_BEHOLD_401] = { 3582 [SAA7134_BOARD_BEHOLD_401] = {
3583 /* Beholder Intl. Ltd. 2008 */
3584 /*Dmitry Belimov <d.belimov@gmail.com> */
3578 .name = "Beholder BeholdTV 401", 3585 .name = "Beholder BeholdTV 401",
3579 .audio_clock = 0x00187de7, 3586 .audio_clock = 0x00187de7,
3580 .tuner_type = TUNER_PHILIPS_FQ1216ME, 3587 .tuner_type = TUNER_PHILIPS_FQ1216ME,
3581 .radio_type = UNSET, 3588 .radio_type = UNSET,
3582 .tuner_addr = ADDR_UNSET, 3589 .tuner_addr = ADDR_UNSET,
3583 .radio_addr = ADDR_UNSET, 3590 .radio_addr = ADDR_UNSET,
3591 .gpiomask = 0x00008000,
3584 .inputs = {{ 3592 .inputs = {{
3585 .name = name_svideo, 3593 .name = name_svideo,
3586 .vmux = 8, 3594 .vmux = 8,
@@ -3601,12 +3609,15 @@ struct saa7134_board saa7134_boards[] = {
3601 }, 3609 },
3602 }, 3610 },
3603 [SAA7134_BOARD_BEHOLD_403] = { 3611 [SAA7134_BOARD_BEHOLD_403] = {
3612 /* Beholder Intl. Ltd. 2008 */
3613 /*Dmitry Belimov <d.belimov@gmail.com> */
3604 .name = "Beholder BeholdTV 403", 3614 .name = "Beholder BeholdTV 403",
3605 .audio_clock = 0x00187de7, 3615 .audio_clock = 0x00187de7,
3606 .tuner_type = TUNER_PHILIPS_FQ1216ME, 3616 .tuner_type = TUNER_PHILIPS_FQ1216ME,
3607 .radio_type = UNSET, 3617 .radio_type = UNSET,
3608 .tuner_addr = ADDR_UNSET, 3618 .tuner_addr = ADDR_UNSET,
3609 .radio_addr = ADDR_UNSET, 3619 .radio_addr = ADDR_UNSET,
3620 .gpiomask = 0x00008000,
3610 .inputs = {{ 3621 .inputs = {{
3611 .name = name_svideo, 3622 .name = name_svideo,
3612 .vmux = 8, 3623 .vmux = 8,
@@ -3623,12 +3634,15 @@ struct saa7134_board saa7134_boards[] = {
3623 }}, 3634 }},
3624 }, 3635 },
3625 [SAA7134_BOARD_BEHOLD_403FM] = { 3636 [SAA7134_BOARD_BEHOLD_403FM] = {
3637 /* Beholder Intl. Ltd. 2008 */
3638 /*Dmitry Belimov <d.belimov@gmail.com> */
3626 .name = "Beholder BeholdTV 403 FM", 3639 .name = "Beholder BeholdTV 403 FM",
3627 .audio_clock = 0x00187de7, 3640 .audio_clock = 0x00187de7,
3628 .tuner_type = TUNER_PHILIPS_FQ1216ME, 3641 .tuner_type = TUNER_PHILIPS_FQ1216ME,
3629 .radio_type = UNSET, 3642 .radio_type = UNSET,
3630 .tuner_addr = ADDR_UNSET, 3643 .tuner_addr = ADDR_UNSET,
3631 .radio_addr = ADDR_UNSET, 3644 .radio_addr = ADDR_UNSET,
3645 .gpiomask = 0x00008000,
3632 .inputs = {{ 3646 .inputs = {{
3633 .name = name_svideo, 3647 .name = name_svideo,
3634 .vmux = 8, 3648 .vmux = 8,
@@ -3649,6 +3663,8 @@ struct saa7134_board saa7134_boards[] = {
3649 }, 3663 },
3650 }, 3664 },
3651 [SAA7134_BOARD_BEHOLD_405] = { 3665 [SAA7134_BOARD_BEHOLD_405] = {
3666 /* Beholder Intl. Ltd. 2008 */
3667 /*Dmitry Belimov <d.belimov@gmail.com> */
3652 .name = "Beholder BeholdTV 405", 3668 .name = "Beholder BeholdTV 405",
3653 .audio_clock = 0x00187de7, 3669 .audio_clock = 0x00187de7,
3654 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 3670 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
@@ -3656,6 +3672,7 @@ struct saa7134_board saa7134_boards[] = {
3656 .tuner_addr = ADDR_UNSET, 3672 .tuner_addr = ADDR_UNSET,
3657 .radio_addr = ADDR_UNSET, 3673 .radio_addr = ADDR_UNSET,
3658 .tda9887_conf = TDA9887_PRESENT, 3674 .tda9887_conf = TDA9887_PRESENT,
3675 .gpiomask = 0x00008000,
3659 .inputs = {{ 3676 .inputs = {{
3660 .name = name_svideo, 3677 .name = name_svideo,
3661 .vmux = 8, 3678 .vmux = 8,
@@ -3673,6 +3690,8 @@ struct saa7134_board saa7134_boards[] = {
3673 }, 3690 },
3674 [SAA7134_BOARD_BEHOLD_405FM] = { 3691 [SAA7134_BOARD_BEHOLD_405FM] = {
3675 /* Sergey <skiv@orel.ru> */ 3692 /* Sergey <skiv@orel.ru> */
3693 /* Beholder Intl. Ltd. 2008 */
3694 /*Dmitry Belimov <d.belimov@gmail.com> */
3676 .name = "Beholder BeholdTV 405 FM", 3695 .name = "Beholder BeholdTV 405 FM",
3677 .audio_clock = 0x00187de7, 3696 .audio_clock = 0x00187de7,
3678 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 3697 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
@@ -3680,6 +3699,7 @@ struct saa7134_board saa7134_boards[] = {
3680 .tuner_addr = ADDR_UNSET, 3699 .tuner_addr = ADDR_UNSET,
3681 .radio_addr = ADDR_UNSET, 3700 .radio_addr = ADDR_UNSET,
3682 .tda9887_conf = TDA9887_PRESENT, 3701 .tda9887_conf = TDA9887_PRESENT,
3702 .gpiomask = 0x00008000,
3683 .inputs = {{ 3703 .inputs = {{
3684 .name = name_svideo, 3704 .name = name_svideo,
3685 .vmux = 8, 3705 .vmux = 8,
@@ -3700,6 +3720,8 @@ struct saa7134_board saa7134_boards[] = {
3700 }, 3720 },
3701 }, 3721 },
3702 [SAA7134_BOARD_BEHOLD_407] = { 3722 [SAA7134_BOARD_BEHOLD_407] = {
3723 /* Beholder Intl. Ltd. 2008 */
3724 /*Dmitry Belimov <d.belimov@gmail.com> */
3703 .name = "Beholder BeholdTV 407", 3725 .name = "Beholder BeholdTV 407",
3704 .audio_clock = 0x00187de7, 3726 .audio_clock = 0x00187de7,
3705 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 3727 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
@@ -3707,7 +3729,7 @@ struct saa7134_board saa7134_boards[] = {
3707 .tuner_addr = ADDR_UNSET, 3729 .tuner_addr = ADDR_UNSET,
3708 .radio_addr = ADDR_UNSET, 3730 .radio_addr = ADDR_UNSET,
3709 .tda9887_conf = TDA9887_PRESENT, 3731 .tda9887_conf = TDA9887_PRESENT,
3710 .gpiomask = 0xc0c000, 3732 .gpiomask = 0x00008000,
3711 .inputs = {{ 3733 .inputs = {{
3712 .name = name_svideo, 3734 .name = name_svideo,
3713 .vmux = 8, 3735 .vmux = 8,
@@ -3727,6 +3749,8 @@ struct saa7134_board saa7134_boards[] = {
3727 }}, 3749 }},
3728 }, 3750 },
3729 [SAA7134_BOARD_BEHOLD_407FM] = { 3751 [SAA7134_BOARD_BEHOLD_407FM] = {
3752 /* Beholder Intl. Ltd. 2008 */
3753 /*Dmitry Belimov <d.belimov@gmail.com> */
3730 .name = "Beholder BeholdTV 407 FM", 3754 .name = "Beholder BeholdTV 407 FM",
3731 .audio_clock = 0x00187de7, 3755 .audio_clock = 0x00187de7,
3732 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 3756 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
@@ -3734,7 +3758,7 @@ struct saa7134_board saa7134_boards[] = {
3734 .tuner_addr = ADDR_UNSET, 3758 .tuner_addr = ADDR_UNSET,
3735 .radio_addr = ADDR_UNSET, 3759 .radio_addr = ADDR_UNSET,
3736 .tda9887_conf = TDA9887_PRESENT, 3760 .tda9887_conf = TDA9887_PRESENT,
3737 .gpiomask = 0xc0c000, 3761 .gpiomask = 0x00008000,
3738 .inputs = {{ 3762 .inputs = {{
3739 .name = name_svideo, 3763 .name = name_svideo,
3740 .vmux = 8, 3764 .vmux = 8,
@@ -3759,6 +3783,8 @@ struct saa7134_board saa7134_boards[] = {
3759 }, 3783 },
3760 }, 3784 },
3761 [SAA7134_BOARD_BEHOLD_409] = { 3785 [SAA7134_BOARD_BEHOLD_409] = {
3786 /* Beholder Intl. Ltd. 2008 */
3787 /*Dmitry Belimov <d.belimov@gmail.com> */
3762 .name = "Beholder BeholdTV 409", 3788 .name = "Beholder BeholdTV 409",
3763 .audio_clock = 0x00187de7, 3789 .audio_clock = 0x00187de7,
3764 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 3790 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
@@ -3766,6 +3792,7 @@ struct saa7134_board saa7134_boards[] = {
3766 .tuner_addr = ADDR_UNSET, 3792 .tuner_addr = ADDR_UNSET,
3767 .radio_addr = ADDR_UNSET, 3793 .radio_addr = ADDR_UNSET,
3768 .tda9887_conf = TDA9887_PRESENT, 3794 .tda9887_conf = TDA9887_PRESENT,
3795 .gpiomask = 0x00008000,
3769 .inputs = {{ 3796 .inputs = {{
3770 .name = name_tv, 3797 .name = name_tv,
3771 .vmux = 3, 3798 .vmux = 3,
@@ -3782,6 +3809,8 @@ struct saa7134_board saa7134_boards[] = {
3782 }}, 3809 }},
3783 }, 3810 },
3784 [SAA7134_BOARD_BEHOLD_505FM] = { 3811 [SAA7134_BOARD_BEHOLD_505FM] = {
3812 /* Beholder Intl. Ltd. 2008 */
3813 /*Dmitry Belimov <d.belimov@gmail.com> */
3785 .name = "Beholder BeholdTV 505 FM/RDS", 3814 .name = "Beholder BeholdTV 505 FM/RDS",
3786 .audio_clock = 0x00200000, 3815 .audio_clock = 0x00200000,
3787 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 3816 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
@@ -3789,6 +3818,7 @@ struct saa7134_board saa7134_boards[] = {
3789 .tuner_addr = ADDR_UNSET, 3818 .tuner_addr = ADDR_UNSET,
3790 .radio_addr = ADDR_UNSET, 3819 .radio_addr = ADDR_UNSET,
3791 .tda9887_conf = TDA9887_PRESENT, 3820 .tda9887_conf = TDA9887_PRESENT,
3821 .gpiomask = 0x00008000,
3792 .inputs = {{ 3822 .inputs = {{
3793 .name = name_tv, 3823 .name = name_tv,
3794 .vmux = 3, 3824 .vmux = 3,
@@ -3813,6 +3843,8 @@ struct saa7134_board saa7134_boards[] = {
3813 }, 3843 },
3814 }, 3844 },
3815 [SAA7134_BOARD_BEHOLD_507_9FM] = { 3845 [SAA7134_BOARD_BEHOLD_507_9FM] = {
3846 /* Beholder Intl. Ltd. 2008 */
3847 /*Dmitry Belimov <d.belimov@gmail.com> */
3816 .name = "Beholder BeholdTV 507 FM/RDS / BeholdTV 509 FM", 3848 .name = "Beholder BeholdTV 507 FM/RDS / BeholdTV 509 FM",
3817 .audio_clock = 0x00187de7, 3849 .audio_clock = 0x00187de7,
3818 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3, 3850 .tuner_type = TUNER_PHILIPS_FM1216ME_MK3,
@@ -3820,6 +3852,7 @@ struct saa7134_board saa7134_boards[] = {
3820 .tuner_addr = ADDR_UNSET, 3852 .tuner_addr = ADDR_UNSET,
3821 .radio_addr = ADDR_UNSET, 3853 .radio_addr = ADDR_UNSET,
3822 .tda9887_conf = TDA9887_PRESENT, 3854 .tda9887_conf = TDA9887_PRESENT,
3855 .gpiomask = 0x00008000,
3823 .inputs = {{ 3856 .inputs = {{
3824 .name = name_tv, 3857 .name = name_tv,
3825 .vmux = 3, 3858 .vmux = 3,
@@ -3840,6 +3873,8 @@ struct saa7134_board saa7134_boards[] = {
3840 }, 3873 },
3841 }, 3874 },
3842 [SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM] = { 3875 [SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM] = {
3876 /* Beholder Intl. Ltd. 2008 */
3877 /*Dmitry Belimov <d.belimov@gmail.com> */
3843 .name = "Beholder BeholdTV Columbus TVFM", 3878 .name = "Beholder BeholdTV Columbus TVFM",
3844 .audio_clock = 0x00187de7, 3879 .audio_clock = 0x00187de7,
3845 .tuner_type = TUNER_ALPS_TSBE5_PAL, 3880 .tuner_type = TUNER_ALPS_TSBE5_PAL,
@@ -3847,23 +3882,28 @@ struct saa7134_board saa7134_boards[] = {
3847 .tuner_addr = ADDR_UNSET, 3882 .tuner_addr = ADDR_UNSET,
3848 .radio_addr = ADDR_UNSET, 3883 .radio_addr = ADDR_UNSET,
3849 .tda9887_conf = TDA9887_PRESENT, 3884 .tda9887_conf = TDA9887_PRESENT,
3885 .gpiomask = 0x000A8004,
3850 .inputs = {{ 3886 .inputs = {{
3851 .name = name_tv, 3887 .name = name_tv,
3852 .vmux = 3, 3888 .vmux = 3,
3853 .amux = TV, 3889 .amux = TV,
3854 .tv = 1, 3890 .tv = 1,
3855 },{ 3891 .gpio = 0x000A8004,
3892 }, {
3856 .name = name_comp1, 3893 .name = name_comp1,
3857 .vmux = 1, 3894 .vmux = 1,
3858 .amux = LINE1, 3895 .amux = LINE1,
3859 },{ 3896 .gpio = 0x000A8000,
3897 }, {
3860 .name = name_svideo, 3898 .name = name_svideo,
3861 .vmux = 8, 3899 .vmux = 8,
3862 .amux = LINE1, 3900 .amux = LINE1,
3863 }}, 3901 .gpio = 0x000A8000,
3902 } },
3864 .radio = { 3903 .radio = {
3865 .name = name_radio, 3904 .name = name_radio,
3866 .amux = LINE2, 3905 .amux = LINE2,
3906 .gpio = 0x000A8000,
3867 }, 3907 },
3868 }, 3908 },
3869 [SAA7134_BOARD_BEHOLD_607_9FM] = { 3909 [SAA7134_BOARD_BEHOLD_607_9FM] = {
@@ -3992,6 +4032,221 @@ struct saa7134_board saa7134_boards[] = {
3992 .gpio = 0x6000, 4032 .gpio = 0x6000,
3993 }, 4033 },
3994 }, 4034 },
4035 [SAA7134_BOARD_PHILIPS_SNAKE] = {
4036 .name = "NXP Snake DVB-S reference design",
4037 .audio_clock = 0x00200000,
4038 .tuner_type = TUNER_ABSENT,
4039 .radio_type = UNSET,
4040 .tuner_addr = ADDR_UNSET,
4041 .radio_addr = ADDR_UNSET,
4042 .mpeg = SAA7134_MPEG_DVB,
4043 .inputs = {{
4044 .name = name_comp1,
4045 .vmux = 3,
4046 .amux = LINE1,
4047 }, {
4048 .name = name_svideo,
4049 .vmux = 8,
4050 .amux = LINE1,
4051 } },
4052 },
4053 [SAA7134_BOARD_CREATIX_CTX953] = {
4054 .name = "Medion/Creatix CTX953 Hybrid",
4055 .audio_clock = 0x00187de7,
4056 .tuner_type = TUNER_PHILIPS_TDA8290,
4057 .radio_type = UNSET,
4058 .tuner_addr = ADDR_UNSET,
4059 .radio_addr = ADDR_UNSET,
4060 .tuner_config = 0,
4061 .mpeg = SAA7134_MPEG_DVB,
4062 .inputs = {{
4063 .name = name_tv,
4064 .vmux = 1,
4065 .amux = TV,
4066 .tv = 1,
4067 }, {
4068 .name = name_comp1,
4069 .vmux = 0,
4070 .amux = LINE1,
4071 }, {
4072 .name = name_svideo,
4073 .vmux = 8,
4074 .amux = LINE1,
4075 } },
4076 },
4077 [SAA7134_BOARD_MSI_TVANYWHERE_AD11] = {
4078 .name = "MSI TV@nywhere A/D v1.1",
4079 .audio_clock = 0x00187de7,
4080 .tuner_type = TUNER_PHILIPS_TDA8290,
4081 .radio_type = UNSET,
4082 .tuner_addr = ADDR_UNSET,
4083 .radio_addr = ADDR_UNSET,
4084 .tuner_config = 2,
4085 .mpeg = SAA7134_MPEG_DVB,
4086 .gpiomask = 0x0200000,
4087 .inputs = { {
4088 .name = name_tv,
4089 .vmux = 1,
4090 .amux = TV,
4091 .tv = 1,
4092 }, {
4093 .name = name_comp1,
4094 .vmux = 3,
4095 .amux = LINE1,
4096 }, {
4097 .name = name_svideo,
4098 .vmux = 8,
4099 .amux = LINE1,
4100 } },
4101 .radio = {
4102 .name = name_radio,
4103 .amux = TV,
4104 .gpio = 0x0200000,
4105 },
4106 },
4107 [SAA7134_BOARD_AVERMEDIA_CARDBUS_506] = {
4108 .name = "AVerMedia Cardbus TV/Radio (E506R)",
4109 .audio_clock = 0x187de7,
4110 .tuner_type = TUNER_XC2028,
4111 .radio_type = UNSET,
4112 .tuner_addr = ADDR_UNSET,
4113 .radio_addr = ADDR_UNSET,
4114 /*
4115 TODO:
4116 .mpeg = SAA7134_MPEG_DVB,
4117 */
4118
4119 .inputs = {{
4120 .name = name_tv,
4121 .vmux = 1,
4122 .amux = TV,
4123 .tv = 1,
4124 }, {
4125 .name = name_comp1,
4126 .vmux = 3,
4127 .amux = LINE2,
4128 }, {
4129 .name = name_svideo,
4130 .vmux = 8,
4131 .amux = LINE1,
4132 } },
4133 .radio = {
4134 .name = name_radio,
4135 .amux = TV,
4136 },
4137 },
4138 [SAA7134_BOARD_AVERMEDIA_A16D] = {
4139 .name = "AVerMedia Hybrid TV/Radio (A16D)",
4140 .audio_clock = 0x187de7,
4141 .tuner_type = TUNER_XC2028,
4142 .radio_type = UNSET,
4143 .tuner_addr = ADDR_UNSET,
4144 .radio_addr = ADDR_UNSET,
4145 .inputs = {{
4146 .name = name_tv,
4147 .vmux = 1,
4148 .amux = TV,
4149 .tv = 1,
4150 }, {
4151 .name = name_svideo,
4152 .vmux = 8,
4153 .amux = LINE1,
4154 } },
4155 .radio = {
4156 .name = name_radio,
4157 .amux = LINE1,
4158 },
4159 },
4160 [SAA7134_BOARD_AVERMEDIA_M115] = {
4161 .name = "Avermedia M115",
4162 .audio_clock = 0x187de7,
4163 .tuner_type = TUNER_XC2028,
4164 .radio_type = UNSET,
4165 .tuner_addr = ADDR_UNSET,
4166 .radio_addr = ADDR_UNSET,
4167 .inputs = {{
4168 .name = name_tv,
4169 .vmux = 1,
4170 .amux = TV,
4171 .tv = 1,
4172 }, {
4173 .name = name_comp1,
4174 .vmux = 3,
4175 .amux = LINE1,
4176 }, {
4177 .name = name_svideo,
4178 .vmux = 8,
4179 .amux = LINE2,
4180 } },
4181 },
4182 [SAA7134_BOARD_VIDEOMATE_T750] = {
4183 /* John Newbigin <jn@it.swin.edu.au> */
4184 .name = "Compro VideoMate T750",
4185 .audio_clock = 0x00187de7,
4186 .tuner_type = TUNER_XC2028,
4187 .radio_type = UNSET,
4188 .tuner_addr = ADDR_UNSET,
4189 .radio_addr = ADDR_UNSET,
4190 .mpeg = SAA7134_MPEG_DVB,
4191 .inputs = {{
4192 .name = name_tv,
4193 .vmux = 3,
4194 .amux = TV,
4195 .tv = 1,
4196 }, {
4197 .name = name_comp1,
4198 .vmux = 1,
4199 .amux = LINE2,
4200 }, {
4201 .name = name_svideo,
4202 .vmux = 8,
4203 .amux = LINE2,
4204 } },
4205 .radio = {
4206 .name = name_radio,
4207 .amux = TV,
4208 }
4209 },
4210 [SAA7134_BOARD_AVERMEDIA_A700_PRO] = {
4211 /* Matthias Schwarzott <zzam@gentoo.org> */
4212 .name = "Avermedia DVB-S Pro A700",
4213 .audio_clock = 0x00187de7,
4214 .tuner_type = TUNER_ABSENT,
4215 .radio_type = UNSET,
4216 .tuner_addr = ADDR_UNSET,
4217 .radio_addr = ADDR_UNSET,
4218 /* no DVB support for now */
4219 /* .mpeg = SAA7134_MPEG_DVB, */
4220 .inputs = { {
4221 .name = name_comp,
4222 .vmux = 1,
4223 .amux = LINE1,
4224 }, {
4225 .name = name_svideo,
4226 .vmux = 6,
4227 .amux = LINE1,
4228 } },
4229 },
4230 [SAA7134_BOARD_AVERMEDIA_A700_HYBRID] = {
4231 /* Matthias Schwarzott <zzam@gentoo.org> */
4232 .name = "Avermedia DVB-S Hybrid+FM A700",
4233 .audio_clock = 0x00187de7,
4234 .tuner_type = TUNER_ABSENT, /* TUNER_XC2028 */
4235 .radio_type = UNSET,
4236 .tuner_addr = ADDR_UNSET,
4237 .radio_addr = ADDR_UNSET,
4238 /* no DVB support for now */
4239 /* .mpeg = SAA7134_MPEG_DVB, */
4240 .inputs = { {
4241 .name = name_comp,
4242 .vmux = 1,
4243 .amux = LINE1,
4244 }, {
4245 .name = name_svideo,
4246 .vmux = 6,
4247 .amux = LINE1,
4248 } },
4249 },
3995}; 4250};
3996 4251
3997const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards); 4252const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards);
@@ -4224,6 +4479,18 @@ struct pci_device_id saa7134_pci_tbl[] = {
4224 .driver_data = SAA7134_BOARD_MD2819, 4479 .driver_data = SAA7134_BOARD_MD2819,
4225 },{ 4480 },{
4226 .vendor = PCI_VENDOR_ID_PHILIPS, 4481 .vendor = PCI_VENDOR_ID_PHILIPS,
4482 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4483 .subvendor = 0x1461, /* Avermedia Technologies Inc */
4484 .subdevice = 0xa7a1,
4485 .driver_data = SAA7134_BOARD_AVERMEDIA_A700_PRO,
4486 }, {
4487 .vendor = PCI_VENDOR_ID_PHILIPS,
4488 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
4489 .subvendor = 0x1461, /* Avermedia Technologies Inc */
4490 .subdevice = 0xa7a2,
4491 .driver_data = SAA7134_BOARD_AVERMEDIA_A700_HYBRID,
4492 }, {
4493 .vendor = PCI_VENDOR_ID_PHILIPS,
4227 .device = PCI_DEVICE_ID_PHILIPS_SAA7130, 4494 .device = PCI_DEVICE_ID_PHILIPS_SAA7130,
4228 .subvendor = 0x1461, /* Avermedia Technologies Inc */ 4495 .subvendor = 0x1461, /* Avermedia Technologies Inc */
4229 .subdevice = 0x2115, 4496 .subdevice = 0x2115,
@@ -4942,7 +5209,43 @@ struct pci_device_id saa7134_pci_tbl[] = {
4942 .subvendor = 0x1822, /*Twinhan Technology Co. Ltd*/ 5209 .subvendor = 0x1822, /*Twinhan Technology Co. Ltd*/
4943 .subdevice = 0x0022, 5210 .subdevice = 0x0022,
4944 .driver_data = SAA7134_BOARD_TWINHAN_DTV_DVB_3056, 5211 .driver_data = SAA7134_BOARD_TWINHAN_DTV_DVB_3056,
5212 }, {
5213 .vendor = PCI_VENDOR_ID_PHILIPS,
5214 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
5215 .subvendor = 0x16be,
5216 .subdevice = 0x0010, /* Medion version CTX953_V.1.4.3 */
5217 .driver_data = SAA7134_BOARD_CREATIX_CTX953,
5218 }, {
5219 .vendor = PCI_VENDOR_ID_PHILIPS,
5220 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
5221 .subvendor = 0x1462, /* MSI */
5222 .subdevice = 0x8625, /* TV@nywhere A/D v1.1 */
5223 .driver_data = SAA7134_BOARD_MSI_TVANYWHERE_AD11,
4945 },{ 5224 },{
5225 .vendor = PCI_VENDOR_ID_PHILIPS,
5226 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
5227 .subvendor = 0x1461, /* Avermedia Technologies Inc */
5228 .subdevice = 0xf436,
5229 .driver_data = SAA7134_BOARD_AVERMEDIA_CARDBUS_506,
5230 }, {
5231 .vendor = PCI_VENDOR_ID_PHILIPS,
5232 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
5233 .subvendor = 0x1461, /* Avermedia Technologies Inc */
5234 .subdevice = 0xf936,
5235 .driver_data = SAA7134_BOARD_AVERMEDIA_A16D,
5236 }, {
5237 .vendor = PCI_VENDOR_ID_PHILIPS,
5238 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
5239 .subvendor = 0x1461, /* Avermedia Technologies Inc */
5240 .subdevice = 0xa836,
5241 .driver_data = SAA7134_BOARD_AVERMEDIA_M115,
5242 }, {
5243 .vendor = PCI_VENDOR_ID_PHILIPS,
5244 .device = PCI_DEVICE_ID_PHILIPS_SAA7133,
5245 .subvendor = 0x185b,
5246 .subdevice = 0xc900,
5247 .driver_data = SAA7134_BOARD_VIDEOMATE_T750,
5248 }, {
4946 /* --- boards without eeprom + subsystem ID --- */ 5249 /* --- boards without eeprom + subsystem ID --- */
4947 .vendor = PCI_VENDOR_ID_PHILIPS, 5250 .vendor = PCI_VENDOR_ID_PHILIPS,
4948 .device = PCI_DEVICE_ID_PHILIPS_SAA7134, 5251 .device = PCI_DEVICE_ID_PHILIPS_SAA7134,
@@ -4998,6 +5301,77 @@ static void board_flyvideo(struct saa7134_dev *dev)
4998 dev->name, dev->name, dev->name); 5301 dev->name, dev->name, dev->name);
4999} 5302}
5000 5303
5304static int saa7134_xc2028_callback(struct saa7134_dev *dev,
5305 int command, int arg)
5306{
5307 switch (command) {
5308 case XC2028_TUNER_RESET:
5309 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x06e20000, 0x06e20000);
5310 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x06a20000, 0x06a20000);
5311 mdelay(250);
5312 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x06e20000, 0);
5313 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x06a20000, 0);
5314 mdelay(250);
5315 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x06e20000, 0x06e20000);
5316 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x06a20000, 0x06a20000);
5317 mdelay(250);
5318 saa_andorl(SAA7133_ANALOG_IO_SELECT >> 2, 0x02, 0x02);
5319 saa_andorl(SAA7134_ANALOG_IN_CTRL1 >> 2, 0x81, 0x81);
5320 saa_andorl(SAA7134_AUDIO_CLOCK0 >> 2, 0x03187de7, 0x03187de7);
5321 saa_andorl(SAA7134_AUDIO_PLL_CTRL >> 2, 0x03, 0x03);
5322 saa_andorl(SAA7134_AUDIO_CLOCKS_PER_FIELD0 >> 2,
5323 0x0001e000, 0x0001e000);
5324 return 0;
5325 }
5326 return -EINVAL;
5327}
5328
5329
5330static int saa7134_tda8290_callback(struct saa7134_dev *dev,
5331 int command, int arg)
5332{
5333 u8 sync_control;
5334
5335 switch (command) {
5336 case 0: /* switch LNA gain through GPIO 22*/
5337 saa7134_set_gpio(dev, 22, arg) ;
5338 break;
5339 case 1: /* vsync output at GPIO22. 50 / 60Hz */
5340 saa_andorb(SAA7134_VIDEO_PORT_CTRL3, 0x80, 0x80);
5341 saa_andorb(SAA7134_VIDEO_PORT_CTRL6, 0x0f, 0x03);
5342 if (arg == 1)
5343 sync_control = 11;
5344 else
5345 sync_control = 17;
5346 saa_writeb(SAA7134_VGATE_START, sync_control);
5347 saa_writeb(SAA7134_VGATE_STOP, sync_control + 1);
5348 saa_andorb(SAA7134_MISC_VGATE_MSB, 0x03, 0x00);
5349 break;
5350 default:
5351 return -EINVAL;
5352 }
5353
5354 return 0;
5355}
5356
5357int saa7134_tuner_callback(void *priv, int command, int arg)
5358{
5359 struct saa7134_dev *dev = priv;
5360 if (dev != NULL) {
5361 switch (dev->tuner_type) {
5362 case TUNER_PHILIPS_TDA8290:
5363 return saa7134_tda8290_callback(dev, command, arg);
5364 case TUNER_XC2028:
5365 return saa7134_xc2028_callback(dev, command, arg);
5366 }
5367 } else {
5368 printk(KERN_ERR "saa7134: Error - device struct undefined.\n");
5369 return -EINVAL;
5370 }
5371 return -EINVAL;
5372}
5373EXPORT_SYMBOL(saa7134_tuner_callback);
5374
5001/* ----------------------------------------------------------- */ 5375/* ----------------------------------------------------------- */
5002 5376
5003static void hauppauge_eeprom(struct saa7134_dev *dev, u8 *eeprom_data) 5377static void hauppauge_eeprom(struct saa7134_dev *dev, u8 *eeprom_data)
@@ -5067,6 +5441,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
5067 case SAA7134_BOARD_VIDEOMATE_DVBT_300: 5441 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
5068 case SAA7134_BOARD_VIDEOMATE_DVBT_200: 5442 case SAA7134_BOARD_VIDEOMATE_DVBT_200:
5069 case SAA7134_BOARD_VIDEOMATE_DVBT_200A: 5443 case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
5444 case SAA7134_BOARD_VIDEOMATE_T750:
5070 case SAA7134_BOARD_MANLI_MTV001: 5445 case SAA7134_BOARD_MANLI_MTV001:
5071 case SAA7134_BOARD_MANLI_MTV002: 5446 case SAA7134_BOARD_MANLI_MTV002:
5072 case SAA7134_BOARD_BEHOLD_409FM: 5447 case SAA7134_BOARD_BEHOLD_409FM:
@@ -5133,11 +5508,29 @@ int saa7134_board_init1(struct saa7134_dev *dev)
5133 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x08000000, 0x00000000); 5508 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x08000000, 0x00000000);
5134 break; 5509 break;
5135 case SAA7134_BOARD_AVERMEDIA_CARDBUS: 5510 case SAA7134_BOARD_AVERMEDIA_CARDBUS:
5136 case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM: 5511 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
5512 case SAA7134_BOARD_AVERMEDIA_M115:
5513 case SAA7134_BOARD_AVERMEDIA_A16D:
5514 /* power-down tuner chip */
5515 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0xffffffff, 0);
5516 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0xffffffff, 0);
5517 msleep(10);
5137 /* power-up tuner chip */ 5518 /* power-up tuner chip */
5138 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0xffffffff, 0xffffffff); 5519 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0xffffffff, 0xffffffff);
5139 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0xffffffff, 0xffffffff); 5520 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0xffffffff, 0xffffffff);
5140 msleep(1); 5521 msleep(10);
5522 break;
5523 case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM:
5524 /* power-down tuner chip */
5525 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x000A8004, 0x000A8004);
5526 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x000A8004, 0);
5527 msleep(10);
5528 /* power-up tuner chip */
5529 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x000A8004, 0x000A8004);
5530 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x000A8004, 0x000A8004);
5531 msleep(10);
5532 /* remote via GPIO */
5533 dev->has_remote = SAA7134_REMOTE_GPIO;
5141 break; 5534 break;
5142 case SAA7134_BOARD_RTD_VFG7350: 5535 case SAA7134_BOARD_RTD_VFG7350:
5143 5536
@@ -5160,7 +5553,6 @@ int saa7134_board_init1(struct saa7134_dev *dev)
5160 dev->has_remote = SAA7134_REMOTE_I2C; 5553 dev->has_remote = SAA7134_REMOTE_I2C;
5161 break; 5554 break;
5162 case SAA7134_BOARD_AVERMEDIA_A169_B: 5555 case SAA7134_BOARD_AVERMEDIA_A169_B:
5163 case SAA7134_BOARD_MD7134_BRIDGE_2:
5164 printk("%s: %s: dual saa713x broadcast decoders\n" 5556 printk("%s: %s: dual saa713x broadcast decoders\n"
5165 "%s: Sorry, none of the inputs to this chip are supported yet.\n" 5557 "%s: Sorry, none of the inputs to this chip are supported yet.\n"
5166 "%s: Dual decoder functionality is disabled for now, use the other chip.\n", 5558 "%s: Dual decoder functionality is disabled for now, use the other chip.\n",
@@ -5172,6 +5564,15 @@ int saa7134_board_init1(struct saa7134_dev *dev)
5172 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x8c040007, 0x8c040007); 5564 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x8c040007, 0x8c040007);
5173 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x0c0007cd, 0x0c0007cd); 5565 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x0c0007cd, 0x0c0007cd);
5174 break; 5566 break;
5567 case SAA7134_BOARD_AVERMEDIA_A700_PRO:
5568 case SAA7134_BOARD_AVERMEDIA_A700_HYBRID:
5569 /* write windows gpio values */
5570 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, 0x80040100, 0x80040100);
5571 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, 0x80040100, 0x00040100);
5572 printk("%s: %s: hybrid analog/dvb card\n"
5573 "%s: Sorry, only the analog inputs are supported for now.\n",
5574 dev->name, card(dev).name, dev->name);
5575 break;
5175 } 5576 }
5176 return 0; 5577 return 0;
5177} 5578}
@@ -5200,11 +5601,16 @@ int saa7134_board_init2(struct saa7134_dev *dev)
5200 dev->tuner_type = saa7134_boards[dev->board].tuner_type; 5601 dev->tuner_type = saa7134_boards[dev->board].tuner_type;
5201 5602
5202 if (TUNER_ABSENT != dev->tuner_type) { 5603 if (TUNER_ABSENT != dev->tuner_type) {
5203 tun_setup.mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV; 5604 tun_setup.mode_mask = T_RADIO |
5204 tun_setup.type = dev->tuner_type; 5605 T_ANALOG_TV |
5205 tun_setup.addr = ADDR_UNSET; 5606 T_DIGITAL_TV;
5607 tun_setup.type = dev->tuner_type;
5608 tun_setup.addr = ADDR_UNSET;
5609 tun_setup.tuner_callback = saa7134_tuner_callback;
5206 5610
5207 saa7134_i2c_call_clients (dev, TUNER_SET_TYPE_ADDR, &tun_setup); 5611 saa7134_i2c_call_clients(dev,
5612 TUNER_SET_TYPE_ADDR,
5613 &tun_setup);
5208 } 5614 }
5209 break; 5615 break;
5210 case SAA7134_BOARD_MD7134: 5616 case SAA7134_BOARD_MD7134:
@@ -5275,14 +5681,25 @@ int saa7134_board_init2(struct saa7134_dev *dev)
5275 &tda9887_cfg); 5681 &tda9887_cfg);
5276 } 5682 }
5277 5683
5278 tun_setup.mode_mask = T_RADIO | T_ANALOG_TV | T_DIGITAL_TV; 5684 tun_setup.mode_mask = T_RADIO |
5685 T_ANALOG_TV |
5686 T_DIGITAL_TV;
5279 tun_setup.type = dev->tuner_type; 5687 tun_setup.type = dev->tuner_type;
5280 tun_setup.addr = ADDR_UNSET; 5688 tun_setup.addr = ADDR_UNSET;
5281 5689
5282 saa7134_i2c_call_clients (dev, TUNER_SET_TYPE_ADDR,&tun_setup); 5690 saa7134_i2c_call_clients(dev,
5691 TUNER_SET_TYPE_ADDR, &tun_setup);
5283 } 5692 }
5284 break; 5693 break;
5285 case SAA7134_BOARD_PHILIPS_EUROPA: 5694 case SAA7134_BOARD_PHILIPS_EUROPA:
5695 if (dev->autodetected && (dev->eedata[0x41] == 0x1c)) {
5696 /* Reconfigure board as Snake reference design */
5697 dev->board = SAA7134_BOARD_PHILIPS_SNAKE;
5698 dev->tuner_type = saa7134_boards[dev->board].tuner_type;
5699 printk(KERN_INFO "%s: Reconfigured board as %s\n",
5700 dev->name, saa7134_boards[dev->board].name);
5701 break;
5702 }
5286 case SAA7134_BOARD_VIDEOMATE_DVBT_300: 5703 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
5287 case SAA7134_BOARD_ASUS_EUROPA2_HYBRID: 5704 case SAA7134_BOARD_ASUS_EUROPA2_HYBRID:
5288 /* The Philips EUROPA based hybrid boards have the tuner connected through 5705 /* The Philips EUROPA based hybrid boards have the tuner connected through
@@ -5333,6 +5750,7 @@ int saa7134_board_init2(struct saa7134_dev *dev)
5333 case SAA7134_BOARD_MEDION_MD8800_QUADRO: 5750 case SAA7134_BOARD_MEDION_MD8800_QUADRO:
5334 case SAA7134_BOARD_AVERMEDIA_SUPER_007: 5751 case SAA7134_BOARD_AVERMEDIA_SUPER_007:
5335 case SAA7134_BOARD_TWINHAN_DTV_DVB_3056: 5752 case SAA7134_BOARD_TWINHAN_DTV_DVB_3056:
5753 case SAA7134_BOARD_CREATIX_CTX953:
5336 /* this is a hybrid board, initialize to analog mode 5754 /* this is a hybrid board, initialize to analog mode
5337 * and configure firmware eeprom address 5755 * and configure firmware eeprom address
5338 */ 5756 */
@@ -5402,13 +5820,46 @@ int saa7134_board_init2(struct saa7134_dev *dev)
5402 break; 5820 break;
5403 } 5821 }
5404 break; 5822 break;
5823 case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM:
5824 {
5825 struct v4l2_priv_tun_config tea5767_cfg;
5826 struct tea5767_ctrl ctl;
5827
5828 dev->i2c_client.addr = 0xC0;
5829 /* set TEA5767(analog FM) defines */
5830 memset(&ctl, 0, sizeof(ctl));
5831 ctl.xtal_freq = TEA5767_HIGH_LO_13MHz;
5832 tea5767_cfg.tuner = TUNER_TEA5767;
5833 tea5767_cfg.priv = &ctl;
5834 saa7134_i2c_call_clients(dev, TUNER_SET_CONFIG, &tea5767_cfg);
5835 }
5836 break;
5405 } 5837 }
5838
5839 if (dev->tuner_type == TUNER_XC2028) {
5840 struct v4l2_priv_tun_config xc2028_cfg;
5841 struct xc2028_ctrl ctl;
5842
5843 memset(&xc2028_cfg, 0, sizeof(ctl));
5844 memset(&ctl, 0, sizeof(ctl));
5845
5846 ctl.fname = XC2028_DEFAULT_FIRMWARE;
5847 ctl.max_len = 64;
5848
5849 switch (dev->board) {
5850 case SAA7134_BOARD_AVERMEDIA_A16D:
5851 ctl.demod = XC3028_FE_ZARLINK456;
5852 break;
5853 default:
5854 ctl.demod = XC3028_FE_OREN538;
5855 ctl.mts = 1;
5856 }
5857
5858 xc2028_cfg.tuner = TUNER_XC2028;
5859 xc2028_cfg.priv = &ctl;
5860
5861 saa7134_i2c_call_clients(dev, TUNER_SET_CONFIG, &xc2028_cfg);
5862 }
5863
5406 return 0; 5864 return 0;
5407} 5865}
5408
5409/* ----------------------------------------------------------- */
5410/*
5411 * Local variables:
5412 * c-basic-offset: 8
5413 * End:
5414 */
diff --git a/drivers/media/video/saa7134/saa7134-core.c b/drivers/media/video/saa7134/saa7134-core.c
index 58ab163fdbd7..eec127864fe3 100644
--- a/drivers/media/video/saa7134/saa7134-core.c
+++ b/drivers/media/video/saa7134/saa7134-core.c
@@ -42,23 +42,23 @@ MODULE_LICENSE("GPL");
42 42
43/* ------------------------------------------------------------------ */ 43/* ------------------------------------------------------------------ */
44 44
45static unsigned int irq_debug = 0; 45static unsigned int irq_debug;
46module_param(irq_debug, int, 0644); 46module_param(irq_debug, int, 0644);
47MODULE_PARM_DESC(irq_debug,"enable debug messages [IRQ handler]"); 47MODULE_PARM_DESC(irq_debug,"enable debug messages [IRQ handler]");
48 48
49static unsigned int core_debug = 0; 49static unsigned int core_debug;
50module_param(core_debug, int, 0644); 50module_param(core_debug, int, 0644);
51MODULE_PARM_DESC(core_debug,"enable debug messages [core]"); 51MODULE_PARM_DESC(core_debug,"enable debug messages [core]");
52 52
53static unsigned int gpio_tracking = 0; 53static unsigned int gpio_tracking;
54module_param(gpio_tracking, int, 0644); 54module_param(gpio_tracking, int, 0644);
55MODULE_PARM_DESC(gpio_tracking,"enable debug messages [gpio]"); 55MODULE_PARM_DESC(gpio_tracking,"enable debug messages [gpio]");
56 56
57static unsigned int alsa = 0; 57static unsigned int alsa;
58module_param(alsa, int, 0644); 58module_param(alsa, int, 0644);
59MODULE_PARM_DESC(alsa,"enable ALSA DMA sound [dmasound]"); 59MODULE_PARM_DESC(alsa,"enable ALSA DMA sound [dmasound]");
60 60
61static unsigned int oss = 0; 61static unsigned int oss;
62module_param(oss, int, 0644); 62module_param(oss, int, 0644);
63MODULE_PARM_DESC(oss,"enable OSS DMA sound [dmasound]"); 63MODULE_PARM_DESC(oss,"enable OSS DMA sound [dmasound]");
64 64
@@ -142,39 +142,6 @@ void saa7134_set_gpio(struct saa7134_dev *dev, int bit_no, int value)
142 } 142 }
143} 143}
144 144
145int saa7134_tuner_callback(void *ptr, int command, int arg)
146{
147 u8 sync_control;
148 struct saa7134_dev *dev = ptr;
149
150 switch (dev->tuner_type) {
151 case TUNER_PHILIPS_TDA8290:
152 switch (command) {
153 case 0: /* switch LNA gain through GPIO 22*/
154 saa7134_set_gpio(dev, 22, arg) ;
155 break;
156 case 1: /* vsync output at GPIO22. 50 / 60Hz */
157 dprintk("setting GPIO22 to vsync %d\n", arg);
158 saa_andorb(SAA7134_VIDEO_PORT_CTRL3, 0x80, 0x80);
159 saa_andorb(SAA7134_VIDEO_PORT_CTRL6, 0x0f, 0x03);
160 if (arg == 1)
161 sync_control = 11;
162 else
163 sync_control = 17;
164 saa_writeb(SAA7134_VGATE_START, sync_control);
165 saa_writeb(SAA7134_VGATE_STOP, sync_control + 1);
166 saa_andorb(SAA7134_MISC_VGATE_MSB, 0x03, 0x00);
167 break;
168 default:
169 return -EINVAL;
170 }
171 break;
172 default:
173 return -ENODEV;
174 }
175 return 0;
176}
177
178/* ------------------------------------------------------------------ */ 145/* ------------------------------------------------------------------ */
179 146
180 147
@@ -897,6 +864,10 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
897 struct saa7134_dev *dev; 864 struct saa7134_dev *dev;
898 struct saa7134_mpeg_ops *mops; 865 struct saa7134_mpeg_ops *mops;
899 int err; 866 int err;
867 int mask;
868
869 if (saa7134_devcount == SAA7134_MAXBOARDS)
870 return -ENOMEM;
900 871
901 dev = kzalloc(sizeof(*dev),GFP_KERNEL); 872 dev = kzalloc(sizeof(*dev),GFP_KERNEL);
902 if (NULL == dev) 873 if (NULL == dev)
@@ -1094,6 +1065,11 @@ static int __devinit saa7134_initdev(struct pci_dev *pci_dev,
1094 if (TUNER_ABSENT != dev->tuner_type) 1065 if (TUNER_ABSENT != dev->tuner_type)
1095 saa7134_i2c_call_clients(dev, TUNER_SET_STANDBY, NULL); 1066 saa7134_i2c_call_clients(dev, TUNER_SET_STANDBY, NULL);
1096 1067
1068 if (card(dev).gpiomask != 0) {
1069 mask = card(dev).gpiomask;
1070 saa_andorl(SAA7134_GPIO_GPMODE0 >> 2, mask, mask);
1071 saa_andorl(SAA7134_GPIO_GPSTATUS0 >> 2, mask, 0);
1072 }
1097 return 0; 1073 return 0;
1098 1074
1099 fail4: 1075 fail4:
diff --git a/drivers/media/video/saa7134/saa7134-dvb.c b/drivers/media/video/saa7134/saa7134-dvb.c
index ea2be9eceeb8..2d16be2259db 100644
--- a/drivers/media/video/saa7134/saa7134-dvb.c
+++ b/drivers/media/video/saa7134/saa7134-dvb.c
@@ -33,33 +33,40 @@
33#include "saa7134.h" 33#include "saa7134.h"
34#include <media/v4l2-common.h> 34#include <media/v4l2-common.h>
35#include "dvb-pll.h" 35#include "dvb-pll.h"
36#include <dvb_frontend.h>
36 37
37#include "mt352.h" 38#include "mt352.h"
38#include "mt352_priv.h" /* FIXME */ 39#include "mt352_priv.h" /* FIXME */
39#include "tda1004x.h" 40#include "tda1004x.h"
40#include "nxt200x.h" 41#include "nxt200x.h"
42#include "tuner-xc2028.h"
41 43
42#include "tda10086.h" 44#include "tda10086.h"
43#include "tda826x.h" 45#include "tda826x.h"
44#include "tda827x.h" 46#include "tda827x.h"
45#include "isl6421.h" 47#include "isl6421.h"
48#include "isl6405.h"
49#include "lnbp21.h"
50#include "tuner-simple.h"
46 51
47MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]"); 52MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
48MODULE_LICENSE("GPL"); 53MODULE_LICENSE("GPL");
49 54
50static unsigned int antenna_pwr = 0; 55static unsigned int antenna_pwr;
51 56
52module_param(antenna_pwr, int, 0444); 57module_param(antenna_pwr, int, 0444);
53MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)"); 58MODULE_PARM_DESC(antenna_pwr,"enable antenna power (Pinnacle 300i)");
54 59
55static int use_frontend = 0; 60static int use_frontend;
56module_param(use_frontend, int, 0644); 61module_param(use_frontend, int, 0644);
57MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)"); 62MODULE_PARM_DESC(use_frontend,"for cards with multiple frontends (0: terrestrial, 1: satellite)");
58 63
59static int debug = 0; 64static int debug;
60module_param(debug, int, 0644); 65module_param(debug, int, 0644);
61MODULE_PARM_DESC(debug, "Turn on/off module debugging (default:off)."); 66MODULE_PARM_DESC(debug, "Turn on/off module debugging (default:off).");
62 67
68DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
69
63#define dprintk(fmt, arg...) do { if (debug) \ 70#define dprintk(fmt, arg...) do { if (debug) \
64 printk(KERN_DEBUG "%s/dvb: " fmt, dev->name , ## arg); } while(0) 71 printk(KERN_DEBUG "%s/dvb: " fmt, dev->name , ## arg); } while(0)
65 72
@@ -91,7 +98,7 @@ static int pinnacle_antenna_pwr(struct saa7134_dev *dev, int on)
91 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28)); 98 saa_setl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 28));
92 udelay(10); 99 udelay(10);
93 ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27); 100 ok = saa_readl(SAA7134_GPIO_GPSTATUS0) & (1 << 27);
94 dprintk("%s %s\n", __FUNCTION__, ok ? "on" : "off"); 101 dprintk("%s %s\n", __func__, ok ? "on" : "off");
95 102
96 if (!ok) 103 if (!ok)
97 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26)); 104 saa_clearl(SAA7134_GPIO_GPSTATUS0 >> 2, (1 << 26));
@@ -111,7 +118,7 @@ static int mt352_pinnacle_init(struct dvb_frontend* fe)
111 static u8 irq_cfg [] = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 }; 118 static u8 irq_cfg [] = { INTERRUPT_EN_0, 0x00, 0x00, 0x00, 0x00 };
112 struct saa7134_dev *dev= fe->dvb->priv; 119 struct saa7134_dev *dev= fe->dvb->priv;
113 120
114 dprintk("%s called\n", __FUNCTION__); 121 dprintk("%s called\n", __func__);
115 122
116 mt352_write(fe, clock_config, sizeof(clock_config)); 123 mt352_write(fe, clock_config, sizeof(clock_config));
117 udelay(200); 124 udelay(200);
@@ -146,6 +153,26 @@ static int mt352_aver777_init(struct dvb_frontend* fe)
146 return 0; 153 return 0;
147} 154}
148 155
156static int mt352_aver_a16d_init(struct dvb_frontend *fe)
157{
158 static u8 clock_config [] = { CLOCK_CTL, 0x38, 0x2d };
159 static u8 reset [] = { RESET, 0x80 };
160 static u8 adc_ctl_1_cfg [] = { ADC_CTL_1, 0x40 };
161 static u8 agc_cfg [] = { AGC_TARGET, 0x28, 0xa0 };
162 static u8 capt_range_cfg[] = { CAPT_RANGE, 0x33 };
163
164 mt352_write(fe, clock_config, sizeof(clock_config));
165 udelay(200);
166 mt352_write(fe, reset, sizeof(reset));
167 mt352_write(fe, adc_ctl_1_cfg, sizeof(adc_ctl_1_cfg));
168 mt352_write(fe, agc_cfg, sizeof(agc_cfg));
169 mt352_write(fe, capt_range_cfg, sizeof(capt_range_cfg));
170
171 return 0;
172}
173
174
175
149static int mt352_pinnacle_tuner_set_params(struct dvb_frontend* fe, 176static int mt352_pinnacle_tuner_set_params(struct dvb_frontend* fe,
150 struct dvb_frontend_parameters* params) 177 struct dvb_frontend_parameters* params)
151{ 178{
@@ -188,6 +215,16 @@ static struct mt352_config avermedia_777 = {
188 .demod_init = mt352_aver777_init, 215 .demod_init = mt352_aver777_init,
189}; 216};
190 217
218static struct mt352_config avermedia_16d = {
219 .demod_address = 0xf,
220 .demod_init = mt352_aver_a16d_init,
221};
222
223static struct mt352_config avermedia_e506r_mt352_dev = {
224 .demod_address = (0x1e >> 1),
225 .no_tuner = 1,
226};
227
191/* ================================================================== 228/* ==================================================================
192 * tda1004x based DVB-T cards, helper functions 229 * tda1004x based DVB-T cards, helper functions
193 */ 230 */
@@ -430,8 +467,6 @@ static struct tda1004x_config philips_europa_config = {
430 .request_firmware = philips_tda1004x_request_firmware 467 .request_firmware = philips_tda1004x_request_firmware
431}; 468};
432 469
433/* ------------------------------------------------------------------ */
434
435static struct tda1004x_config medion_cardbus = { 470static struct tda1004x_config medion_cardbus = {
436 .demod_address = 0x08, 471 .demod_address = 0x08,
437 .invert = 1, 472 .invert = 1,
@@ -447,47 +482,6 @@ static struct tda1004x_config medion_cardbus = {
447 * tda 1004x based cards with philips silicon tuner 482 * tda 1004x based cards with philips silicon tuner
448 */ 483 */
449 484
450static void philips_tda827x_lna_gain(struct dvb_frontend *fe, int high)
451{
452 struct saa7134_dev *dev = fe->dvb->priv;
453 struct tda1004x_state *state = fe->demodulator_priv;
454 u8 addr = state->config->i2c_gate;
455 u8 config = state->config->tuner_config;
456 u8 GP00_CF[] = {0x20, 0x01};
457 u8 GP00_LEV[] = {0x22, 0x00};
458
459 struct i2c_msg msg = {.addr = addr,.flags = 0,.buf = GP00_CF, .len = 2};
460 if (config) {
461 if (high) {
462 dprintk("setting LNA to high gain\n");
463 } else {
464 dprintk("setting LNA to low gain\n");
465 }
466 }
467 switch (config) {
468 case 0: /* no LNA */
469 break;
470 case 1: /* switch is GPIO 0 of tda8290 */
471 case 2:
472 /* turn Vsync off */
473 saa7134_set_gpio(dev, 22, 0);
474 GP00_LEV[1] = high ? 0 : 1;
475 if (i2c_transfer(&dev->i2c_adap, &msg, 1) != 1) {
476 wprintk("could not access tda8290 at addr: 0x%02x\n",
477 addr << 1);
478 return;
479 }
480 msg.buf = GP00_LEV;
481 if (config == 2)
482 GP00_LEV[1] = high ? 1 : 0;
483 i2c_transfer(&dev->i2c_adap, &msg, 1);
484 break;
485 case 3: /* switch with GPIO of saa713x */
486 saa7134_set_gpio(dev, 22, high);
487 break;
488 }
489}
490
491static int tda8290_i2c_gate_ctrl( struct dvb_frontend* fe, int enable) 485static int tda8290_i2c_gate_ctrl( struct dvb_frontend* fe, int enable)
492{ 486{
493 struct tda1004x_state *state = fe->demodulator_priv; 487 struct tda1004x_state *state = fe->demodulator_priv;
@@ -510,8 +504,6 @@ static int tda8290_i2c_gate_ctrl( struct dvb_frontend* fe, int enable)
510 return 0; 504 return 0;
511} 505}
512 506
513/* ------------------------------------------------------------------ */
514
515static int philips_tda827x_tuner_init(struct dvb_frontend *fe) 507static int philips_tda827x_tuner_init(struct dvb_frontend *fe)
516{ 508{
517 struct saa7134_dev *dev = fe->dvb->priv; 509 struct saa7134_dev *dev = fe->dvb->priv;
@@ -546,28 +538,57 @@ static int philips_tda827x_tuner_sleep(struct dvb_frontend *fe)
546 return 0; 538 return 0;
547} 539}
548 540
549static struct tda827x_config tda827x_cfg = { 541static void configure_tda827x_fe(struct saa7134_dev *dev, struct tda1004x_config *cdec_conf,
550 .lna_gain = philips_tda827x_lna_gain, 542 struct tda827x_config *tuner_conf)
551 .init = philips_tda827x_tuner_init,
552 .sleep = philips_tda827x_tuner_sleep
553};
554
555static void configure_tda827x_fe(struct saa7134_dev *dev, struct tda1004x_config *tda_conf)
556{ 543{
557 dev->dvb.frontend = dvb_attach(tda10046_attach, tda_conf, &dev->i2c_adap); 544 dev->dvb.frontend = dvb_attach(tda10046_attach, cdec_conf, &dev->i2c_adap);
558 if (dev->dvb.frontend) { 545 if (dev->dvb.frontend) {
559 if (tda_conf->i2c_gate) 546 if (cdec_conf->i2c_gate)
560 dev->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl; 547 dev->dvb.frontend->ops.i2c_gate_ctrl = tda8290_i2c_gate_ctrl;
561 if (dvb_attach(tda827x_attach, dev->dvb.frontend, tda_conf->tuner_address, 548 if (dvb_attach(tda827x_attach, dev->dvb.frontend, cdec_conf->tuner_address,
562 &dev->i2c_adap,&tda827x_cfg) == NULL) { 549 &dev->i2c_adap, tuner_conf) == NULL) {
563 wprintk("no tda827x tuner found at addr: %02x\n", 550 wprintk("no tda827x tuner found at addr: %02x\n",
564 tda_conf->tuner_address); 551 cdec_conf->tuner_address);
565 } 552 }
566 } 553 }
567} 554}
568 555
569/* ------------------------------------------------------------------ */ 556/* ------------------------------------------------------------------ */
570 557
558static struct tda827x_config tda827x_cfg_0 = {
559 .tuner_callback = saa7134_tuner_callback,
560 .init = philips_tda827x_tuner_init,
561 .sleep = philips_tda827x_tuner_sleep,
562 .config = 0,
563 .switch_addr = 0
564};
565
566static struct tda827x_config tda827x_cfg_1 = {
567 .tuner_callback = saa7134_tuner_callback,
568 .init = philips_tda827x_tuner_init,
569 .sleep = philips_tda827x_tuner_sleep,
570 .config = 1,
571 .switch_addr = 0x4b
572};
573
574static struct tda827x_config tda827x_cfg_2 = {
575 .tuner_callback = saa7134_tuner_callback,
576 .init = philips_tda827x_tuner_init,
577 .sleep = philips_tda827x_tuner_sleep,
578 .config = 2,
579 .switch_addr = 0x4b
580};
581
582static struct tda827x_config tda827x_cfg_2_sw42 = {
583 .tuner_callback = saa7134_tuner_callback,
584 .init = philips_tda827x_tuner_init,
585 .sleep = philips_tda827x_tuner_sleep,
586 .config = 2,
587 .switch_addr = 0x42
588};
589
590/* ------------------------------------------------------------------ */
591
571static struct tda1004x_config tda827x_lifeview_config = { 592static struct tda1004x_config tda827x_lifeview_config = {
572 .demod_address = 0x08, 593 .demod_address = 0x08,
573 .invert = 1, 594 .invert = 1,
@@ -590,7 +611,6 @@ static struct tda1004x_config philips_tiger_config = {
590 .if_freq = TDA10046_FREQ_045, 611 .if_freq = TDA10046_FREQ_045,
591 .i2c_gate = 0x4b, 612 .i2c_gate = 0x4b,
592 .tuner_address = 0x61, 613 .tuner_address = 0x61,
593 .tuner_config = 0,
594 .antenna_switch= 1, 614 .antenna_switch= 1,
595 .request_firmware = philips_tda1004x_request_firmware 615 .request_firmware = philips_tda1004x_request_firmware
596}; 616};
@@ -605,7 +625,6 @@ static struct tda1004x_config cinergy_ht_config = {
605 .if_freq = TDA10046_FREQ_045, 625 .if_freq = TDA10046_FREQ_045,
606 .i2c_gate = 0x4b, 626 .i2c_gate = 0x4b,
607 .tuner_address = 0x61, 627 .tuner_address = 0x61,
608 .tuner_config = 0,
609 .request_firmware = philips_tda1004x_request_firmware 628 .request_firmware = philips_tda1004x_request_firmware
610}; 629};
611 630
@@ -619,7 +638,6 @@ static struct tda1004x_config cinergy_ht_pci_config = {
619 .if_freq = TDA10046_FREQ_045, 638 .if_freq = TDA10046_FREQ_045,
620 .i2c_gate = 0x4b, 639 .i2c_gate = 0x4b,
621 .tuner_address = 0x60, 640 .tuner_address = 0x60,
622 .tuner_config = 0,
623 .request_firmware = philips_tda1004x_request_firmware 641 .request_firmware = philips_tda1004x_request_firmware
624}; 642};
625 643
@@ -633,7 +651,6 @@ static struct tda1004x_config philips_tiger_s_config = {
633 .if_freq = TDA10046_FREQ_045, 651 .if_freq = TDA10046_FREQ_045,
634 .i2c_gate = 0x4b, 652 .i2c_gate = 0x4b,
635 .tuner_address = 0x61, 653 .tuner_address = 0x61,
636 .tuner_config = 2,
637 .antenna_switch= 1, 654 .antenna_switch= 1,
638 .request_firmware = philips_tda1004x_request_firmware 655 .request_firmware = philips_tda1004x_request_firmware
639}; 656};
@@ -648,7 +665,6 @@ static struct tda1004x_config pinnacle_pctv_310i_config = {
648 .if_freq = TDA10046_FREQ_045, 665 .if_freq = TDA10046_FREQ_045,
649 .i2c_gate = 0x4b, 666 .i2c_gate = 0x4b,
650 .tuner_address = 0x61, 667 .tuner_address = 0x61,
651 .tuner_config = 1,
652 .request_firmware = philips_tda1004x_request_firmware 668 .request_firmware = philips_tda1004x_request_firmware
653}; 669};
654 670
@@ -662,7 +678,6 @@ static struct tda1004x_config hauppauge_hvr_1110_config = {
662 .if_freq = TDA10046_FREQ_045, 678 .if_freq = TDA10046_FREQ_045,
663 .i2c_gate = 0x4b, 679 .i2c_gate = 0x4b,
664 .tuner_address = 0x61, 680 .tuner_address = 0x61,
665 .tuner_config = 1,
666 .request_firmware = philips_tda1004x_request_firmware 681 .request_firmware = philips_tda1004x_request_firmware
667}; 682};
668 683
@@ -676,7 +691,6 @@ static struct tda1004x_config asus_p7131_dual_config = {
676 .if_freq = TDA10046_FREQ_045, 691 .if_freq = TDA10046_FREQ_045,
677 .i2c_gate = 0x4b, 692 .i2c_gate = 0x4b,
678 .tuner_address = 0x61, 693 .tuner_address = 0x61,
679 .tuner_config = 0,
680 .antenna_switch= 2, 694 .antenna_switch= 2,
681 .request_firmware = philips_tda1004x_request_firmware 695 .request_firmware = philips_tda1004x_request_firmware
682}; 696};
@@ -715,7 +729,6 @@ static struct tda1004x_config md8800_dvbt_config = {
715 .if_freq = TDA10046_FREQ_045, 729 .if_freq = TDA10046_FREQ_045,
716 .i2c_gate = 0x4b, 730 .i2c_gate = 0x4b,
717 .tuner_address = 0x60, 731 .tuner_address = 0x60,
718 .tuner_config = 0,
719 .request_firmware = philips_tda1004x_request_firmware 732 .request_firmware = philips_tda1004x_request_firmware
720}; 733};
721 734
@@ -729,7 +742,6 @@ static struct tda1004x_config asus_p7131_4871_config = {
729 .if_freq = TDA10046_FREQ_045, 742 .if_freq = TDA10046_FREQ_045,
730 .i2c_gate = 0x4b, 743 .i2c_gate = 0x4b,
731 .tuner_address = 0x61, 744 .tuner_address = 0x61,
732 .tuner_config = 2,
733 .antenna_switch= 2, 745 .antenna_switch= 2,
734 .request_firmware = philips_tda1004x_request_firmware 746 .request_firmware = philips_tda1004x_request_firmware
735}; 747};
@@ -744,7 +756,6 @@ static struct tda1004x_config asus_p7131_hybrid_lna_config = {
744 .if_freq = TDA10046_FREQ_045, 756 .if_freq = TDA10046_FREQ_045,
745 .i2c_gate = 0x4b, 757 .i2c_gate = 0x4b,
746 .tuner_address = 0x61, 758 .tuner_address = 0x61,
747 .tuner_config = 2,
748 .antenna_switch= 2, 759 .antenna_switch= 2,
749 .request_firmware = philips_tda1004x_request_firmware 760 .request_firmware = philips_tda1004x_request_firmware
750}; 761};
@@ -759,7 +770,6 @@ static struct tda1004x_config kworld_dvb_t_210_config = {
759 .if_freq = TDA10046_FREQ_045, 770 .if_freq = TDA10046_FREQ_045,
760 .i2c_gate = 0x4b, 771 .i2c_gate = 0x4b,
761 .tuner_address = 0x61, 772 .tuner_address = 0x61,
762 .tuner_config = 2,
763 .antenna_switch= 1, 773 .antenna_switch= 1,
764 .request_firmware = philips_tda1004x_request_firmware 774 .request_firmware = philips_tda1004x_request_firmware
765}; 775};
@@ -774,7 +784,6 @@ static struct tda1004x_config avermedia_super_007_config = {
774 .if_freq = TDA10046_FREQ_045, 784 .if_freq = TDA10046_FREQ_045,
775 .i2c_gate = 0x4b, 785 .i2c_gate = 0x4b,
776 .tuner_address = 0x60, 786 .tuner_address = 0x60,
777 .tuner_config = 0,
778 .antenna_switch= 1, 787 .antenna_switch= 1,
779 .request_firmware = philips_tda1004x_request_firmware 788 .request_firmware = philips_tda1004x_request_firmware
780}; 789};
@@ -789,7 +798,6 @@ static struct tda1004x_config twinhan_dtv_dvb_3056_config = {
789 .if_freq = TDA10046_FREQ_045, 798 .if_freq = TDA10046_FREQ_045,
790 .i2c_gate = 0x42, 799 .i2c_gate = 0x42,
791 .tuner_address = 0x61, 800 .tuner_address = 0x61,
792 .tuner_config = 2,
793 .antenna_switch = 1, 801 .antenna_switch = 1,
794 .request_firmware = philips_tda1004x_request_firmware 802 .request_firmware = philips_tda1004x_request_firmware
795}; 803};
@@ -817,9 +825,10 @@ static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
817} 825}
818 826
819static struct tda827x_config ads_duo_cfg = { 827static struct tda827x_config ads_duo_cfg = {
820 .lna_gain = philips_tda827x_lna_gain, 828 .tuner_callback = saa7134_tuner_callback,
821 .init = ads_duo_tuner_init, 829 .init = ads_duo_tuner_init,
822 .sleep = ads_duo_tuner_sleep 830 .sleep = ads_duo_tuner_sleep,
831 .config = 0
823}; 832};
824 833
825static struct tda1004x_config ads_tech_duo_config = { 834static struct tda1004x_config ads_tech_duo_config = {
@@ -842,8 +851,73 @@ static struct tda10086_config flydvbs = {
842 .demod_address = 0x0e, 851 .demod_address = 0x0e,
843 .invert = 0, 852 .invert = 0,
844 .diseqc_tone = 0, 853 .diseqc_tone = 0,
854 .xtal_freq = TDA10086_XTAL_16M,
845}; 855};
846 856
857static struct tda10086_config sd1878_4m = {
858 .demod_address = 0x0e,
859 .invert = 0,
860 .diseqc_tone = 0,
861 .xtal_freq = TDA10086_XTAL_4M,
862};
863
864/* ------------------------------------------------------------------
865 * special case: lnb supply is connected to the gated i2c
866 */
867
868static int md8800_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
869{
870 int res = -EIO;
871 struct saa7134_dev *dev = fe->dvb->priv;
872 if (fe->ops.i2c_gate_ctrl) {
873 fe->ops.i2c_gate_ctrl(fe, 1);
874 if (dev->original_set_voltage)
875 res = dev->original_set_voltage(fe, voltage);
876 fe->ops.i2c_gate_ctrl(fe, 0);
877 }
878 return res;
879};
880
881static int md8800_set_high_voltage(struct dvb_frontend *fe, long arg)
882{
883 int res = -EIO;
884 struct saa7134_dev *dev = fe->dvb->priv;
885 if (fe->ops.i2c_gate_ctrl) {
886 fe->ops.i2c_gate_ctrl(fe, 1);
887 if (dev->original_set_high_voltage)
888 res = dev->original_set_high_voltage(fe, arg);
889 fe->ops.i2c_gate_ctrl(fe, 0);
890 }
891 return res;
892};
893
894static int md8800_set_voltage2(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
895{
896 struct saa7134_dev *dev = fe->dvb->priv;
897 u8 wbuf[2] = { 0x1f, 00 };
898 u8 rbuf;
899 struct i2c_msg msg[] = { { .addr = 0x08, .flags = 0, .buf = wbuf, .len = 1 },
900 { .addr = 0x08, .flags = I2C_M_RD, .buf = &rbuf, .len = 1 } };
901
902 if (i2c_transfer(&dev->i2c_adap, msg, 2) != 2)
903 return -EIO;
904 /* NOTE: this assumes that gpo1 is used, it might be bit 5 (gpo2) */
905 if (voltage == SEC_VOLTAGE_18)
906 wbuf[1] = rbuf | 0x10;
907 else
908 wbuf[1] = rbuf & 0xef;
909 msg[0].len = 2;
910 i2c_transfer(&dev->i2c_adap, msg, 1);
911 return 0;
912}
913
914static int md8800_set_high_voltage2(struct dvb_frontend *fe, long arg)
915{
916 struct saa7134_dev *dev = fe->dvb->priv;
917 wprintk("%s: sorry can't set high LNB supply voltage from here\n", __func__);
918 return -EIO;
919}
920
847/* ================================================================== 921/* ==================================================================
848 * nxt200x based ATSC cards, helper functions 922 * nxt200x based ATSC cards, helper functions
849 */ 923 */
@@ -863,12 +937,14 @@ static struct nxt200x_config kworldatsc110 = {
863static int dvb_init(struct saa7134_dev *dev) 937static int dvb_init(struct saa7134_dev *dev)
864{ 938{
865 int ret; 939 int ret;
940 int attach_xc3028 = 0;
941
866 /* init struct videobuf_dvb */ 942 /* init struct videobuf_dvb */
867 dev->ts.nr_bufs = 32; 943 dev->ts.nr_bufs = 32;
868 dev->ts.nr_packets = 32*4; 944 dev->ts.nr_packets = 32*4;
869 dev->dvb.name = dev->name; 945 dev->dvb.name = dev->name;
870 videobuf_queue_pci_init(&dev->dvb.dvbq, &saa7134_ts_qops, 946 videobuf_queue_sg_init(&dev->dvb.dvbq, &saa7134_ts_qops,
871 dev->pci, &dev->slock, 947 &dev->pci->dev, &dev->slock,
872 V4L2_BUF_TYPE_VIDEO_CAPTURE, 948 V4L2_BUF_TYPE_VIDEO_CAPTURE,
873 V4L2_FIELD_ALTERNATE, 949 V4L2_FIELD_ALTERNATE,
874 sizeof(struct saa7134_buf), 950 sizeof(struct saa7134_buf),
@@ -889,17 +965,25 @@ static int dvb_init(struct saa7134_dev *dev)
889 dev->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777, 965 dev->dvb.frontend = dvb_attach(mt352_attach, &avermedia_777,
890 &dev->i2c_adap); 966 &dev->i2c_adap);
891 if (dev->dvb.frontend) { 967 if (dev->dvb.frontend) {
892 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61, 968 dvb_attach(simple_tuner_attach, dev->dvb.frontend,
893 NULL, DVB_PLL_PHILIPS_TD1316); 969 &dev->i2c_adap, 0x61,
970 TUNER_PHILIPS_TD1316);
894 } 971 }
895 break; 972 break;
973 case SAA7134_BOARD_AVERMEDIA_A16D:
974 dprintk("avertv A16D dvb setup\n");
975 dev->dvb.frontend = dvb_attach(mt352_attach, &avermedia_16d,
976 &dev->i2c_adap);
977 attach_xc3028 = 1;
978 break;
896 case SAA7134_BOARD_MD7134: 979 case SAA7134_BOARD_MD7134:
897 dev->dvb.frontend = dvb_attach(tda10046_attach, 980 dev->dvb.frontend = dvb_attach(tda10046_attach,
898 &medion_cardbus, 981 &medion_cardbus,
899 &dev->i2c_adap); 982 &dev->i2c_adap);
900 if (dev->dvb.frontend) { 983 if (dev->dvb.frontend) {
901 dvb_attach(dvb_pll_attach, dev->dvb.frontend, medion_cardbus.tuner_address, 984 dvb_attach(simple_tuner_attach, dev->dvb.frontend,
902 &dev->i2c_adap, DVB_PLL_FMD1216ME); 985 &dev->i2c_adap, medion_cardbus.tuner_address,
986 TUNER_PHILIPS_FMD1216ME_MK3);
903 } 987 }
904 break; 988 break;
905 case SAA7134_BOARD_PHILIPS_TOUGH: 989 case SAA7134_BOARD_PHILIPS_TOUGH:
@@ -913,7 +997,7 @@ static int dvb_init(struct saa7134_dev *dev)
913 break; 997 break;
914 case SAA7134_BOARD_FLYDVBTDUO: 998 case SAA7134_BOARD_FLYDVBTDUO:
915 case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS: 999 case SAA7134_BOARD_FLYDVBT_DUO_CARDBUS:
916 configure_tda827x_fe(dev, &tda827x_lifeview_config); 1000 configure_tda827x_fe(dev, &tda827x_lifeview_config, &tda827x_cfg_0);
917 break; 1001 break;
918 case SAA7134_BOARD_PHILIPS_EUROPA: 1002 case SAA7134_BOARD_PHILIPS_EUROPA:
919 case SAA7134_BOARD_VIDEOMATE_DVBT_300: 1003 case SAA7134_BOARD_VIDEOMATE_DVBT_300:
@@ -938,36 +1022,36 @@ static int dvb_init(struct saa7134_dev *dev)
938 } 1022 }
939 break; 1023 break;
940 case SAA7134_BOARD_KWORLD_DVBT_210: 1024 case SAA7134_BOARD_KWORLD_DVBT_210:
941 configure_tda827x_fe(dev, &kworld_dvb_t_210_config); 1025 configure_tda827x_fe(dev, &kworld_dvb_t_210_config, &tda827x_cfg_2);
942 break; 1026 break;
943 case SAA7134_BOARD_PHILIPS_TIGER: 1027 case SAA7134_BOARD_PHILIPS_TIGER:
944 configure_tda827x_fe(dev, &philips_tiger_config); 1028 configure_tda827x_fe(dev, &philips_tiger_config, &tda827x_cfg_0);
945 break; 1029 break;
946 case SAA7134_BOARD_PINNACLE_PCTV_310i: 1030 case SAA7134_BOARD_PINNACLE_PCTV_310i:
947 configure_tda827x_fe(dev, &pinnacle_pctv_310i_config); 1031 configure_tda827x_fe(dev, &pinnacle_pctv_310i_config, &tda827x_cfg_1);
948 break; 1032 break;
949 case SAA7134_BOARD_HAUPPAUGE_HVR1110: 1033 case SAA7134_BOARD_HAUPPAUGE_HVR1110:
950 configure_tda827x_fe(dev, &hauppauge_hvr_1110_config); 1034 configure_tda827x_fe(dev, &hauppauge_hvr_1110_config, &tda827x_cfg_1);
951 break; 1035 break;
952 case SAA7134_BOARD_ASUSTeK_P7131_DUAL: 1036 case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
953 configure_tda827x_fe(dev, &asus_p7131_dual_config); 1037 configure_tda827x_fe(dev, &asus_p7131_dual_config, &tda827x_cfg_0);
954 break; 1038 break;
955 case SAA7134_BOARD_FLYDVBT_LR301: 1039 case SAA7134_BOARD_FLYDVBT_LR301:
956 configure_tda827x_fe(dev, &tda827x_lifeview_config); 1040 configure_tda827x_fe(dev, &tda827x_lifeview_config, &tda827x_cfg_0);
957 break; 1041 break;
958 case SAA7134_BOARD_FLYDVB_TRIO: 1042 case SAA7134_BOARD_FLYDVB_TRIO:
959 if(! use_frontend) { /* terrestrial */ 1043 if(! use_frontend) { /* terrestrial */
960 configure_tda827x_fe(dev, &lifeview_trio_config); 1044 configure_tda827x_fe(dev, &lifeview_trio_config, &tda827x_cfg_0);
961 } else { /* satellite */ 1045 } else { /* satellite */
962 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap); 1046 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs, &dev->i2c_adap);
963 if (dev->dvb.frontend) { 1047 if (dev->dvb.frontend) {
964 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x63, 1048 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x63,
965 &dev->i2c_adap, 0) == NULL) { 1049 &dev->i2c_adap, 0) == NULL) {
966 wprintk("%s: Lifeview Trio, No tda826x found!\n", __FUNCTION__); 1050 wprintk("%s: Lifeview Trio, No tda826x found!\n", __func__);
967 } 1051 }
968 if (dvb_attach(isl6421_attach, dev->dvb.frontend, &dev->i2c_adap, 1052 if (dvb_attach(isl6421_attach, dev->dvb.frontend, &dev->i2c_adap,
969 0x08, 0, 0) == NULL) { 1053 0x08, 0, 0) == NULL) {
970 wprintk("%s: Lifeview Trio, No ISL6421 found!\n", __FUNCTION__); 1054 wprintk("%s: Lifeview Trio, No ISL6421 found!\n", __func__);
971 } 1055 }
972 } 1056 }
973 } 1057 }
@@ -979,18 +1063,56 @@ static int dvb_init(struct saa7134_dev *dev)
979 &dev->i2c_adap); 1063 &dev->i2c_adap);
980 if (dev->dvb.frontend) { 1064 if (dev->dvb.frontend) {
981 if (dvb_attach(tda827x_attach,dev->dvb.frontend, 1065 if (dvb_attach(tda827x_attach,dev->dvb.frontend,
982 ads_tech_duo_config.tuner_address, 1066 ads_tech_duo_config.tuner_address, &dev->i2c_adap,
983 &dev->i2c_adap,&ads_duo_cfg) == NULL) { 1067 &ads_duo_cfg) == NULL) {
984 wprintk("no tda827x tuner found at addr: %02x\n", 1068 wprintk("no tda827x tuner found at addr: %02x\n",
985 ads_tech_duo_config.tuner_address); 1069 ads_tech_duo_config.tuner_address);
986 } 1070 }
987 } 1071 }
988 break; 1072 break;
989 case SAA7134_BOARD_TEVION_DVBT_220RF: 1073 case SAA7134_BOARD_TEVION_DVBT_220RF:
990 configure_tda827x_fe(dev, &tevion_dvbt220rf_config); 1074 configure_tda827x_fe(dev, &tevion_dvbt220rf_config, &tda827x_cfg_0);
991 break; 1075 break;
992 case SAA7134_BOARD_MEDION_MD8800_QUADRO: 1076 case SAA7134_BOARD_MEDION_MD8800_QUADRO:
993 configure_tda827x_fe(dev, &md8800_dvbt_config); 1077 if (!use_frontend) { /* terrestrial */
1078 configure_tda827x_fe(dev, &md8800_dvbt_config, &tda827x_cfg_0);
1079 } else { /* satellite */
1080 dev->dvb.frontend = dvb_attach(tda10086_attach,
1081 &flydvbs, &dev->i2c_adap);
1082 if (dev->dvb.frontend) {
1083 struct dvb_frontend *fe = dev->dvb.frontend;
1084 u8 dev_id = dev->eedata[2];
1085 u8 data = 0xc4;
1086 struct i2c_msg msg = {.addr = 0x08, .flags = 0, .len = 1};
1087
1088 if (dvb_attach(tda826x_attach, dev->dvb.frontend,
1089 0x60, &dev->i2c_adap, 0) == NULL)
1090 wprintk("%s: Medion Quadro, no tda826x "
1091 "found !\n", __func__);
1092 if (dev_id != 0x08) {
1093 /* we need to open the i2c gate (we know it exists) */
1094 fe->ops.i2c_gate_ctrl(fe, 1);
1095 if (dvb_attach(isl6405_attach, fe,
1096 &dev->i2c_adap, 0x08, 0, 0) == NULL)
1097 wprintk("%s: Medion Quadro, no ISL6405 "
1098 "found !\n", __func__);
1099 if (dev_id == 0x07) {
1100 /* fire up the 2nd section of the LNB supply since
1101 we can't do this from the other section */
1102 msg.buf = &data;
1103 i2c_transfer(&dev->i2c_adap, &msg, 1);
1104 }
1105 fe->ops.i2c_gate_ctrl(fe, 0);
1106 dev->original_set_voltage = fe->ops.set_voltage;
1107 fe->ops.set_voltage = md8800_set_voltage;
1108 dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
1109 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
1110 } else {
1111 fe->ops.set_voltage = md8800_set_voltage2;
1112 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage2;
1113 }
1114 }
1115 }
994 break; 1116 break;
995 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180: 1117 case SAA7134_BOARD_AVERMEDIA_AVERTVHD_A180:
996 dev->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180, 1118 dev->dvb.frontend = dvb_attach(nxt200x_attach, &avertvhda180,
@@ -1004,8 +1126,9 @@ static int dvb_init(struct saa7134_dev *dev)
1004 dev->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110, 1126 dev->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
1005 &dev->i2c_adap); 1127 &dev->i2c_adap);
1006 if (dev->dvb.frontend) { 1128 if (dev->dvb.frontend) {
1007 dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61, 1129 dvb_attach(simple_tuner_attach, dev->dvb.frontend,
1008 NULL, DVB_PLL_TUV1236D); 1130 &dev->i2c_adap, 0x61,
1131 TUNER_PHILIPS_TUV1236D);
1009 } 1132 }
1010 break; 1133 break;
1011 case SAA7134_BOARD_FLYDVBS_LR300: 1134 case SAA7134_BOARD_FLYDVBS_LR300:
@@ -1014,11 +1137,11 @@ static int dvb_init(struct saa7134_dev *dev)
1014 if (dev->dvb.frontend) { 1137 if (dev->dvb.frontend) {
1015 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60, 1138 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60,
1016 &dev->i2c_adap, 0) == NULL) { 1139 &dev->i2c_adap, 0) == NULL) {
1017 wprintk("%s: No tda826x found!\n", __FUNCTION__); 1140 wprintk("%s: No tda826x found!\n", __func__);
1018 } 1141 }
1019 if (dvb_attach(isl6421_attach, dev->dvb.frontend, 1142 if (dvb_attach(isl6421_attach, dev->dvb.frontend,
1020 &dev->i2c_adap, 0x08, 0, 0) == NULL) { 1143 &dev->i2c_adap, 0x08, 0, 0) == NULL) {
1021 wprintk("%s: No ISL6421 found!\n", __FUNCTION__); 1144 wprintk("%s: No ISL6421 found!\n", __func__);
1022 } 1145 }
1023 } 1146 }
1024 break; 1147 break;
@@ -1030,8 +1153,9 @@ static int dvb_init(struct saa7134_dev *dev)
1030 dev->original_demod_sleep = dev->dvb.frontend->ops.sleep; 1153 dev->original_demod_sleep = dev->dvb.frontend->ops.sleep;
1031 dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep; 1154 dev->dvb.frontend->ops.sleep = philips_europa_demod_sleep;
1032 1155
1033 dvb_attach(dvb_pll_attach, dev->dvb.frontend, medion_cardbus.tuner_address, 1156 dvb_attach(simple_tuner_attach, dev->dvb.frontend,
1034 &dev->i2c_adap, DVB_PLL_FMD1216ME); 1157 &dev->i2c_adap, medion_cardbus.tuner_address,
1158 TUNER_PHILIPS_FMD1216ME_MK3);
1035 } 1159 }
1036 break; 1160 break;
1037 case SAA7134_BOARD_VIDEOMATE_DVBT_200A: 1161 case SAA7134_BOARD_VIDEOMATE_DVBT_200A:
@@ -1044,38 +1168,107 @@ static int dvb_init(struct saa7134_dev *dev)
1044 } 1168 }
1045 break; 1169 break;
1046 case SAA7134_BOARD_CINERGY_HT_PCMCIA: 1170 case SAA7134_BOARD_CINERGY_HT_PCMCIA:
1047 configure_tda827x_fe(dev, &cinergy_ht_config); 1171 configure_tda827x_fe(dev, &cinergy_ht_config, &tda827x_cfg_0);
1048 break; 1172 break;
1049 case SAA7134_BOARD_CINERGY_HT_PCI: 1173 case SAA7134_BOARD_CINERGY_HT_PCI:
1050 configure_tda827x_fe(dev, &cinergy_ht_pci_config); 1174 configure_tda827x_fe(dev, &cinergy_ht_pci_config, &tda827x_cfg_0);
1051 break; 1175 break;
1052 case SAA7134_BOARD_PHILIPS_TIGER_S: 1176 case SAA7134_BOARD_PHILIPS_TIGER_S:
1053 configure_tda827x_fe(dev, &philips_tiger_s_config); 1177 configure_tda827x_fe(dev, &philips_tiger_s_config, &tda827x_cfg_2);
1054 break; 1178 break;
1055 case SAA7134_BOARD_ASUS_P7131_4871: 1179 case SAA7134_BOARD_ASUS_P7131_4871:
1056 configure_tda827x_fe(dev, &asus_p7131_4871_config); 1180 configure_tda827x_fe(dev, &asus_p7131_4871_config, &tda827x_cfg_2);
1057 break; 1181 break;
1058 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA: 1182 case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
1059 configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config); 1183 configure_tda827x_fe(dev, &asus_p7131_hybrid_lna_config, &tda827x_cfg_2);
1060 break; 1184 break;
1061 case SAA7134_BOARD_AVERMEDIA_SUPER_007: 1185 case SAA7134_BOARD_AVERMEDIA_SUPER_007:
1062 configure_tda827x_fe(dev, &avermedia_super_007_config); 1186 configure_tda827x_fe(dev, &avermedia_super_007_config, &tda827x_cfg_0);
1063 break; 1187 break;
1064 case SAA7134_BOARD_TWINHAN_DTV_DVB_3056: 1188 case SAA7134_BOARD_TWINHAN_DTV_DVB_3056:
1065 configure_tda827x_fe(dev, &twinhan_dtv_dvb_3056_config); 1189 configure_tda827x_fe(dev, &twinhan_dtv_dvb_3056_config, &tda827x_cfg_2_sw42);
1190 break;
1191 case SAA7134_BOARD_PHILIPS_SNAKE:
1192 dev->dvb.frontend = dvb_attach(tda10086_attach, &flydvbs,
1193 &dev->i2c_adap);
1194 if (dev->dvb.frontend) {
1195 if (dvb_attach(tda826x_attach, dev->dvb.frontend, 0x60,
1196 &dev->i2c_adap, 0) == NULL)
1197 wprintk("%s: No tda826x found!\n", __func__);
1198 if (dvb_attach(lnbp21_attach, dev->dvb.frontend,
1199 &dev->i2c_adap, 0, 0) == NULL)
1200 wprintk("%s: No lnbp21 found!\n", __func__);
1201 }
1202 break;
1203 case SAA7134_BOARD_CREATIX_CTX953:
1204 configure_tda827x_fe(dev, &md8800_dvbt_config, &tda827x_cfg_0);
1205 break;
1206 case SAA7134_BOARD_MSI_TVANYWHERE_AD11:
1207 configure_tda827x_fe(dev, &philips_tiger_s_config, &tda827x_cfg_2);
1208 break;
1209 case SAA7134_BOARD_AVERMEDIA_CARDBUS_506:
1210 dev->dvb.frontend = dvb_attach(mt352_attach,
1211 &avermedia_e506r_mt352_dev,
1212 &dev->i2c_adap);
1213 attach_xc3028 = 1;
1214 break;
1215 case SAA7134_BOARD_MD7134_BRIDGE_2:
1216 dev->dvb.frontend = dvb_attach(tda10086_attach,
1217 &sd1878_4m, &dev->i2c_adap);
1218 if (dev->dvb.frontend) {
1219 struct dvb_frontend *fe;
1220 if (dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x60,
1221 &dev->i2c_adap, DVB_PLL_PHILIPS_SD1878_TDA8261) == NULL)
1222 wprintk("%s: MD7134 DVB-S, no SD1878 "
1223 "found !\n", __func__);
1224 /* we need to open the i2c gate (we know it exists) */
1225 fe = dev->dvb.frontend;
1226 fe->ops.i2c_gate_ctrl(fe, 1);
1227 if (dvb_attach(isl6405_attach, fe,
1228 &dev->i2c_adap, 0x08, 0, 0) == NULL)
1229 wprintk("%s: MD7134 DVB-S, no ISL6405 "
1230 "found !\n", __func__);
1231 fe->ops.i2c_gate_ctrl(fe, 0);
1232 dev->original_set_voltage = fe->ops.set_voltage;
1233 fe->ops.set_voltage = md8800_set_voltage;
1234 dev->original_set_high_voltage = fe->ops.enable_high_lnb_voltage;
1235 fe->ops.enable_high_lnb_voltage = md8800_set_high_voltage;
1236 }
1066 break; 1237 break;
1067 default: 1238 default:
1068 wprintk("Huh? unknown DVB card?\n"); 1239 wprintk("Huh? unknown DVB card?\n");
1069 break; 1240 break;
1070 } 1241 }
1071 1242
1243 if (attach_xc3028) {
1244 struct dvb_frontend *fe;
1245 struct xc2028_config cfg = {
1246 .i2c_adap = &dev->i2c_adap,
1247 .i2c_addr = 0x61,
1248 };
1249
1250 if (!dev->dvb.frontend)
1251 return -1;
1252
1253 fe = dvb_attach(xc2028_attach, dev->dvb.frontend, &cfg);
1254 if (!fe) {
1255 printk(KERN_ERR "%s/2: xc3028 attach failed\n",
1256 dev->name);
1257 dvb_frontend_detach(dev->dvb.frontend);
1258 dvb_unregister_frontend(dev->dvb.frontend);
1259 dev->dvb.frontend = NULL;
1260 return -1;
1261 }
1262 }
1263
1072 if (NULL == dev->dvb.frontend) { 1264 if (NULL == dev->dvb.frontend) {
1073 printk(KERN_ERR "%s/dvb: frontend initialization failed\n", dev->name); 1265 printk(KERN_ERR "%s/dvb: frontend initialization failed\n", dev->name);
1074 return -1; 1266 return -1;
1075 } 1267 }
1076 1268
1077 /* register everything else */ 1269 /* register everything else */
1078 ret = videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev); 1270 ret = videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev,
1271 adapter_nr);
1079 1272
1080 /* this sequence is necessary to make the tda1004x load its firmware 1273 /* this sequence is necessary to make the tda1004x load its firmware
1081 * and to enter analog mode of hybrid boards 1274 * and to enter analog mode of hybrid boards
@@ -1106,9 +1299,22 @@ static int dvb_fini(struct saa7134_dev *dev)
1106 1299
1107 /* otherwise we don't detect the tuner on next insmod */ 1300 /* otherwise we don't detect the tuner on next insmod */
1108 saa7134_i2c_call_clients(dev, TUNER_SET_CONFIG, &tda9887_cfg); 1301 saa7134_i2c_call_clients(dev, TUNER_SET_CONFIG, &tda9887_cfg);
1302 } else if (dev->board == SAA7134_BOARD_MEDION_MD8800_QUADRO) {
1303 if ((dev->eedata[2] == 0x07) && use_frontend) {
1304 /* turn off the 2nd lnb supply */
1305 u8 data = 0x80;
1306 struct i2c_msg msg = {.addr = 0x08, .buf = &data, .flags = 0, .len = 1};
1307 struct dvb_frontend *fe;
1308 fe = dev->dvb.frontend;
1309 if (fe->ops.i2c_gate_ctrl) {
1310 fe->ops.i2c_gate_ctrl(fe, 1);
1311 i2c_transfer(&dev->i2c_adap, &msg, 1);
1312 fe->ops.i2c_gate_ctrl(fe, 0);
1313 }
1314 }
1109 } 1315 }
1110 1316 if (dev->dvb.frontend)
1111 videobuf_dvb_unregister(&dev->dvb); 1317 videobuf_dvb_unregister(&dev->dvb);
1112 return 0; 1318 return 0;
1113} 1319}
1114 1320
diff --git a/drivers/media/video/saa7134/saa7134-empress.c b/drivers/media/video/saa7134/saa7134-empress.c
index 3d2ec30de227..1314522a8130 100644
--- a/drivers/media/video/saa7134/saa7134-empress.c
+++ b/drivers/media/video/saa7134/saa7134-empress.c
@@ -40,7 +40,7 @@ static unsigned int empress_nr[] = {[0 ... (SAA7134_MAXBOARDS - 1)] = UNSET };
40module_param_array(empress_nr, int, NULL, 0444); 40module_param_array(empress_nr, int, NULL, 0444);
41MODULE_PARM_DESC(empress_nr,"ts device number"); 41MODULE_PARM_DESC(empress_nr,"ts device number");
42 42
43static unsigned int debug = 0; 43static unsigned int debug;
44module_param(debug, int, 0644); 44module_param(debug, int, 0644);
45MODULE_PARM_DESC(debug,"enable debug messages"); 45MODULE_PARM_DESC(debug,"enable debug messages");
46 46
@@ -402,7 +402,7 @@ static int empress_init(struct saa7134_dev *dev)
402{ 402{
403 int err; 403 int err;
404 404
405 dprintk("%s: %s\n",dev->name,__FUNCTION__); 405 dprintk("%s: %s\n",dev->name,__func__);
406 dev->empress_dev = video_device_alloc(); 406 dev->empress_dev = video_device_alloc();
407 if (NULL == dev->empress_dev) 407 if (NULL == dev->empress_dev)
408 return -ENOMEM; 408 return -ENOMEM;
@@ -427,8 +427,8 @@ static int empress_init(struct saa7134_dev *dev)
427 printk(KERN_INFO "%s: registered device video%d [mpeg]\n", 427 printk(KERN_INFO "%s: registered device video%d [mpeg]\n",
428 dev->name,dev->empress_dev->minor & 0x1f); 428 dev->name,dev->empress_dev->minor & 0x1f);
429 429
430 videobuf_queue_pci_init(&dev->empress_tsq, &saa7134_ts_qops, 430 videobuf_queue_sg_init(&dev->empress_tsq, &saa7134_ts_qops,
431 dev->pci, &dev->slock, 431 &dev->pci->dev, &dev->slock,
432 V4L2_BUF_TYPE_VIDEO_CAPTURE, 432 V4L2_BUF_TYPE_VIDEO_CAPTURE,
433 V4L2_FIELD_ALTERNATE, 433 V4L2_FIELD_ALTERNATE,
434 sizeof(struct saa7134_buf), 434 sizeof(struct saa7134_buf),
@@ -440,7 +440,7 @@ static int empress_init(struct saa7134_dev *dev)
440 440
441static int empress_fini(struct saa7134_dev *dev) 441static int empress_fini(struct saa7134_dev *dev)
442{ 442{
443 dprintk("%s: %s\n",dev->name,__FUNCTION__); 443 dprintk("%s: %s\n",dev->name,__func__);
444 444
445 if (NULL == dev->empress_dev) 445 if (NULL == dev->empress_dev)
446 return 0; 446 return 0;
diff --git a/drivers/media/video/saa7134/saa7134-i2c.c b/drivers/media/video/saa7134/saa7134-i2c.c
index d3322c3018f2..2ccfaba0c490 100644
--- a/drivers/media/video/saa7134/saa7134-i2c.c
+++ b/drivers/media/video/saa7134/saa7134-i2c.c
@@ -33,11 +33,11 @@
33 33
34/* ----------------------------------------------------------- */ 34/* ----------------------------------------------------------- */
35 35
36static unsigned int i2c_debug = 0; 36static unsigned int i2c_debug;
37module_param(i2c_debug, int, 0644); 37module_param(i2c_debug, int, 0644);
38MODULE_PARM_DESC(i2c_debug,"enable debug messages [i2c]"); 38MODULE_PARM_DESC(i2c_debug,"enable debug messages [i2c]");
39 39
40static unsigned int i2c_scan = 0; 40static unsigned int i2c_scan;
41module_param(i2c_scan, int, 0444); 41module_param(i2c_scan, int, 0444);
42MODULE_PARM_DESC(i2c_scan,"scan i2c bus at insmod time"); 42MODULE_PARM_DESC(i2c_scan,"scan i2c bus at insmod time");
43 43
@@ -140,6 +140,8 @@ static inline int i2c_is_busy(enum i2c_status status)
140{ 140{
141 switch (status) { 141 switch (status) {
142 case BUSY: 142 case BUSY:
143 case TO_SCL:
144 case TO_ARB:
143 return true; 145 return true;
144 default: 146 default:
145 return false; 147 return false;
diff --git a/drivers/media/video/saa7134/saa7134-input.c b/drivers/media/video/saa7134/saa7134-input.c
index b4188819782f..767ff30832f2 100644
--- a/drivers/media/video/saa7134/saa7134-input.c
+++ b/drivers/media/video/saa7134/saa7134-input.c
@@ -27,15 +27,15 @@
27#include "saa7134-reg.h" 27#include "saa7134-reg.h"
28#include "saa7134.h" 28#include "saa7134.h"
29 29
30static unsigned int disable_ir = 0; 30static unsigned int disable_ir;
31module_param(disable_ir, int, 0444); 31module_param(disable_ir, int, 0444);
32MODULE_PARM_DESC(disable_ir,"disable infrared remote support"); 32MODULE_PARM_DESC(disable_ir,"disable infrared remote support");
33 33
34static unsigned int ir_debug = 0; 34static unsigned int ir_debug;
35module_param(ir_debug, int, 0644); 35module_param(ir_debug, int, 0644);
36MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]"); 36MODULE_PARM_DESC(ir_debug,"enable debug messages [IR]");
37 37
38static int pinnacle_remote = 0; 38static int pinnacle_remote;
39module_param(pinnacle_remote, int, 0644); /* Choose Pinnacle PCTV remote */ 39module_param(pinnacle_remote, int, 0644); /* Choose Pinnacle PCTV remote */
40MODULE_PARM_DESC(pinnacle_remote, "Specify Pinnacle PCTV remote: 0=coloured, 1=grey (defaults to 0)"); 40MODULE_PARM_DESC(pinnacle_remote, "Specify Pinnacle PCTV remote: 0=coloured, 1=grey (defaults to 0)");
41 41
@@ -331,6 +331,11 @@ int saa7134_input_init1(struct saa7134_dev *dev)
331 break; 331 break;
332 case SAA7134_BOARD_MANLI_MTV001: 332 case SAA7134_BOARD_MANLI_MTV001:
333 case SAA7134_BOARD_MANLI_MTV002: 333 case SAA7134_BOARD_MANLI_MTV002:
334 ir_codes = ir_codes_manli;
335 mask_keycode = 0x001f00;
336 mask_keyup = 0x004000;
337 polling = 50; /* ms */
338 break;
334 case SAA7134_BOARD_BEHOLD_409FM: 339 case SAA7134_BOARD_BEHOLD_409FM:
335 case SAA7134_BOARD_BEHOLD_401: 340 case SAA7134_BOARD_BEHOLD_401:
336 case SAA7134_BOARD_BEHOLD_403: 341 case SAA7134_BOARD_BEHOLD_403:
@@ -343,7 +348,13 @@ int saa7134_input_init1(struct saa7134_dev *dev)
343 case SAA7134_BOARD_BEHOLD_505FM: 348 case SAA7134_BOARD_BEHOLD_505FM:
344 case SAA7134_BOARD_BEHOLD_507_9FM: 349 case SAA7134_BOARD_BEHOLD_507_9FM:
345 ir_codes = ir_codes_manli; 350 ir_codes = ir_codes_manli;
346 mask_keycode = 0x001f00; 351 mask_keycode = 0x003f00;
352 mask_keyup = 0x004000;
353 polling = 50; /* ms */
354 break;
355 case SAA7134_BOARD_BEHOLD_COLUMBUS_TVFM:
356 ir_codes = ir_codes_behold_columbus;
357 mask_keycode = 0x003f00;
347 mask_keyup = 0x004000; 358 mask_keyup = 0x004000;
348 polling = 50; // ms 359 polling = 50; // ms
349 break; 360 break;
diff --git a/drivers/media/video/saa7134/saa7134-reg.h b/drivers/media/video/saa7134/saa7134-reg.h
index ac6431ba4fc3..86f5eefdb0f6 100644
--- a/drivers/media/video/saa7134/saa7134-reg.h
+++ b/drivers/media/video/saa7134/saa7134-reg.h
@@ -365,6 +365,9 @@
365#define SAA7135_DSP_RWSTATE_RDB (1 << 1) 365#define SAA7135_DSP_RWSTATE_RDB (1 << 1)
366#define SAA7135_DSP_RWSTATE_WRR (1 << 0) 366#define SAA7135_DSP_RWSTATE_WRR (1 << 0)
367 367
368#define SAA7135_DSP_RWCLEAR 0x586
369#define SAA7135_DSP_RWCLEAR_RERR 1
370
368/* ------------------------------------------------------------------ */ 371/* ------------------------------------------------------------------ */
369/* 372/*
370 * Local variables: 373 * Local variables:
diff --git a/drivers/media/video/saa7134/saa7134-ts.c b/drivers/media/video/saa7134/saa7134-ts.c
index f1b8fcaeb43a..eae72fd60cec 100644
--- a/drivers/media/video/saa7134/saa7134-ts.c
+++ b/drivers/media/video/saa7134/saa7134-ts.c
@@ -32,7 +32,7 @@
32 32
33/* ------------------------------------------------------------------ */ 33/* ------------------------------------------------------------------ */
34 34
35static unsigned int ts_debug = 0; 35static unsigned int ts_debug;
36module_param(ts_debug, int, 0644); 36module_param(ts_debug, int, 0644);
37MODULE_PARM_DESC(ts_debug,"enable debug messages [ts]"); 37MODULE_PARM_DESC(ts_debug,"enable debug messages [ts]");
38 38
diff --git a/drivers/media/video/saa7134/saa7134-tvaudio.c b/drivers/media/video/saa7134/saa7134-tvaudio.c
index 4e9810469ae3..232af598d947 100644
--- a/drivers/media/video/saa7134/saa7134-tvaudio.c
+++ b/drivers/media/video/saa7134/saa7134-tvaudio.c
@@ -35,18 +35,18 @@
35 35
36/* ------------------------------------------------------------------ */ 36/* ------------------------------------------------------------------ */
37 37
38static unsigned int audio_debug = 0; 38static unsigned int audio_debug;
39module_param(audio_debug, int, 0644); 39module_param(audio_debug, int, 0644);
40MODULE_PARM_DESC(audio_debug,"enable debug messages [tv audio]"); 40MODULE_PARM_DESC(audio_debug,"enable debug messages [tv audio]");
41 41
42static unsigned int audio_ddep = 0; 42static unsigned int audio_ddep;
43module_param(audio_ddep, int, 0644); 43module_param(audio_ddep, int, 0644);
44MODULE_PARM_DESC(audio_ddep,"audio ddep overwrite"); 44MODULE_PARM_DESC(audio_ddep,"audio ddep overwrite");
45 45
46static int audio_clock_override = UNSET; 46static int audio_clock_override = UNSET;
47module_param(audio_clock_override, int, 0644); 47module_param(audio_clock_override, int, 0644);
48 48
49static int audio_clock_tweak = 0; 49static int audio_clock_tweak;
50module_param(audio_clock_tweak, int, 0644); 50module_param(audio_clock_tweak, int, 0644);
51MODULE_PARM_DESC(audio_clock_tweak, "Audio clock tick fine tuning for cards with audio crystal that's slightly off (range [-1024 .. 1024])"); 51MODULE_PARM_DESC(audio_clock_tweak, "Audio clock tick fine tuning for cards with audio crystal that's slightly off (range [-1024 .. 1024])");
52 52
@@ -653,6 +653,17 @@ static char *stdres[0x20] = {
653 653
654#define DSP_RETRY 32 654#define DSP_RETRY 32
655#define DSP_DELAY 16 655#define DSP_DELAY 16
656#define SAA7135_DSP_RWCLEAR_RERR 1
657
658static inline int saa_dsp_reset_error_bit(struct saa7134_dev *dev)
659{
660 int state = saa_readb(SAA7135_DSP_RWSTATE);
661 if (unlikely(state & SAA7135_DSP_RWSTATE_ERR)) {
662 d2printk("%s: resetting error bit\n", dev->name);
663 saa_writeb(SAA7135_DSP_RWCLEAR, SAA7135_DSP_RWCLEAR_RERR);
664 }
665 return 0;
666}
656 667
657static inline int saa_dsp_wait_bit(struct saa7134_dev *dev, int bit) 668static inline int saa_dsp_wait_bit(struct saa7134_dev *dev, int bit)
658{ 669{
@@ -660,8 +671,8 @@ static inline int saa_dsp_wait_bit(struct saa7134_dev *dev, int bit)
660 671
661 state = saa_readb(SAA7135_DSP_RWSTATE); 672 state = saa_readb(SAA7135_DSP_RWSTATE);
662 if (unlikely(state & SAA7135_DSP_RWSTATE_ERR)) { 673 if (unlikely(state & SAA7135_DSP_RWSTATE_ERR)) {
663 printk("%s: dsp access error\n",dev->name); 674 printk(KERN_WARNING "%s: dsp access error\n", dev->name);
664 /* FIXME: send ack ... */ 675 saa_dsp_reset_error_bit(dev);
665 return -EIO; 676 return -EIO;
666 } 677 }
667 while (0 == (state & bit)) { 678 while (0 == (state & bit)) {
diff --git a/drivers/media/video/saa7134/saa7134-vbi.c b/drivers/media/video/saa7134/saa7134-vbi.c
index f0d5ed9c2b06..cb0304298a96 100644
--- a/drivers/media/video/saa7134/saa7134-vbi.c
+++ b/drivers/media/video/saa7134/saa7134-vbi.c
@@ -31,7 +31,7 @@
31 31
32/* ------------------------------------------------------------------ */ 32/* ------------------------------------------------------------------ */
33 33
34static unsigned int vbi_debug = 0; 34static unsigned int vbi_debug;
35module_param(vbi_debug, int, 0644); 35module_param(vbi_debug, int, 0644);
36MODULE_PARM_DESC(vbi_debug,"enable debug messages [vbi]"); 36MODULE_PARM_DESC(vbi_debug,"enable debug messages [vbi]");
37 37
diff --git a/drivers/media/video/saa7134/saa7134-video.c b/drivers/media/video/saa7134/saa7134-video.c
index 39c41ad97d0e..a0baf2d0ba7f 100644
--- a/drivers/media/video/saa7134/saa7134-video.c
+++ b/drivers/media/video/saa7134/saa7134-video.c
@@ -40,7 +40,7 @@
40 40
41unsigned int video_debug; 41unsigned int video_debug;
42static unsigned int gbuffers = 8; 42static unsigned int gbuffers = 8;
43static unsigned int noninterlaced = 0; 43static unsigned int noninterlaced; /* 0 */
44static unsigned int gbufsize = 720*576*4; 44static unsigned int gbufsize = 720*576*4;
45static unsigned int gbufsize_max = 720*576*4; 45static unsigned int gbufsize_max = 720*576*4;
46static char secam[] = "--"; 46static char secam[] = "--";
@@ -626,13 +626,8 @@ void saa7134_set_tvnorm_hw(struct saa7134_dev *dev)
626{ 626{
627 saa7134_set_decoder(dev); 627 saa7134_set_decoder(dev);
628 628
629 if (card_in(dev, dev->ctl_input).tv) { 629 if (card_in(dev, dev->ctl_input).tv)
630 if ((card(dev).tuner_type == TUNER_PHILIPS_TDA8290)
631 && ((card(dev).tuner_config == 1)
632 || (card(dev).tuner_config == 2)))
633 saa7134_set_gpio(dev, 22, 5);
634 saa7134_i2c_call_clients(dev, VIDIOC_S_STD, &dev->tvnorm->id); 630 saa7134_i2c_call_clients(dev, VIDIOC_S_STD, &dev->tvnorm->id);
635 }
636} 631}
637 632
638static void set_h_prescale(struct saa7134_dev *dev, int task, int prescale) 633static void set_h_prescale(struct saa7134_dev *dev, int task, int prescale)
@@ -1350,14 +1345,14 @@ static int video_open(struct inode *inode, struct file *file)
1350 fh->height = 576; 1345 fh->height = 576;
1351 v4l2_prio_open(&dev->prio,&fh->prio); 1346 v4l2_prio_open(&dev->prio,&fh->prio);
1352 1347
1353 videobuf_queue_pci_init(&fh->cap, &video_qops, 1348 videobuf_queue_sg_init(&fh->cap, &video_qops,
1354 dev->pci, &dev->slock, 1349 &dev->pci->dev, &dev->slock,
1355 V4L2_BUF_TYPE_VIDEO_CAPTURE, 1350 V4L2_BUF_TYPE_VIDEO_CAPTURE,
1356 V4L2_FIELD_INTERLACED, 1351 V4L2_FIELD_INTERLACED,
1357 sizeof(struct saa7134_buf), 1352 sizeof(struct saa7134_buf),
1358 fh); 1353 fh);
1359 videobuf_queue_pci_init(&fh->vbi, &saa7134_vbi_qops, 1354 videobuf_queue_sg_init(&fh->vbi, &saa7134_vbi_qops,
1360 dev->pci, &dev->slock, 1355 &dev->pci->dev, &dev->slock,
1361 V4L2_BUF_TYPE_VBI_CAPTURE, 1356 V4L2_BUF_TYPE_VBI_CAPTURE,
1362 V4L2_FIELD_SEQ_TB, 1357 V4L2_FIELD_SEQ_TB,
1363 sizeof(struct saa7134_buf), 1358 sizeof(struct saa7134_buf),
diff --git a/drivers/media/video/saa7134/saa7134.h b/drivers/media/video/saa7134/saa7134.h
index f940d0254798..924ffd13637e 100644
--- a/drivers/media/video/saa7134/saa7134.h
+++ b/drivers/media/video/saa7134/saa7134.h
@@ -253,7 +253,17 @@ struct saa7134_format {
253#define SAA7134_BOARD_BEHOLD_607_9FM 129 253#define SAA7134_BOARD_BEHOLD_607_9FM 129
254#define SAA7134_BOARD_BEHOLD_M6 130 254#define SAA7134_BOARD_BEHOLD_M6 130
255#define SAA7134_BOARD_TWINHAN_DTV_DVB_3056 131 255#define SAA7134_BOARD_TWINHAN_DTV_DVB_3056 131
256#define SAA7134_BOARD_GENIUS_TVGO_A11MCE 132 256#define SAA7134_BOARD_GENIUS_TVGO_A11MCE 132
257#define SAA7134_BOARD_PHILIPS_SNAKE 133
258#define SAA7134_BOARD_CREATIX_CTX953 134
259#define SAA7134_BOARD_MSI_TVANYWHERE_AD11 135
260#define SAA7134_BOARD_AVERMEDIA_CARDBUS_506 136
261#define SAA7134_BOARD_AVERMEDIA_A16D 137
262#define SAA7134_BOARD_AVERMEDIA_M115 138
263#define SAA7134_BOARD_VIDEOMATE_T750 139
264#define SAA7134_BOARD_AVERMEDIA_A700_PRO 140
265#define SAA7134_BOARD_AVERMEDIA_A700_HYBRID 141
266
257 267
258#define SAA7134_MAXBOARDS 8 268#define SAA7134_MAXBOARDS 8
259#define SAA7134_INPUT_MAX 8 269#define SAA7134_INPUT_MAX 8
@@ -380,9 +390,7 @@ struct saa7134_fh {
380 unsigned int radio; 390 unsigned int radio;
381 enum v4l2_buf_type type; 391 enum v4l2_buf_type type;
382 unsigned int resources; 392 unsigned int resources;
383#ifdef VIDIOC_G_PRIORITY
384 enum v4l2_priority prio; 393 enum v4l2_priority prio;
385#endif
386 394
387 /* video overlay */ 395 /* video overlay */
388 struct v4l2_window win; 396 struct v4l2_window win;
@@ -454,9 +462,7 @@ struct saa7134_dev {
454 struct list_head devlist; 462 struct list_head devlist;
455 struct mutex lock; 463 struct mutex lock;
456 spinlock_t slock; 464 spinlock_t slock;
457#ifdef VIDIOC_G_PRIORITY
458 struct v4l2_prio_state prio; 465 struct v4l2_prio_state prio;
459#endif
460 /* workstruct for loading modules */ 466 /* workstruct for loading modules */
461 struct work_struct request_module_wk; 467 struct work_struct request_module_wk;
462 468
@@ -556,7 +562,9 @@ struct saa7134_dev {
556#if defined(CONFIG_VIDEO_SAA7134_DVB) || defined(CONFIG_VIDEO_SAA7134_DVB_MODULE) 562#if defined(CONFIG_VIDEO_SAA7134_DVB) || defined(CONFIG_VIDEO_SAA7134_DVB_MODULE)
557 /* SAA7134_MPEG_DVB only */ 563 /* SAA7134_MPEG_DVB only */
558 struct videobuf_dvb dvb; 564 struct videobuf_dvb dvb;
559 int (*original_demod_sleep)(struct dvb_frontend* fe); 565 int (*original_demod_sleep)(struct dvb_frontend *fe);
566 int (*original_set_voltage)(struct dvb_frontend *fe, fe_sec_voltage_t voltage);
567 int (*original_set_high_voltage)(struct dvb_frontend *fe, long arg);
560#endif 568#endif
561}; 569};
562 570
@@ -594,7 +602,6 @@ extern int saa7134_no_overlay;
594 602
595void saa7134_track_gpio(struct saa7134_dev *dev, char *msg); 603void saa7134_track_gpio(struct saa7134_dev *dev, char *msg);
596void saa7134_set_gpio(struct saa7134_dev *dev, int bit_no, int value); 604void saa7134_set_gpio(struct saa7134_dev *dev, int bit_no, int value);
597int saa7134_tuner_callback(void *ptr, int command, int arg);
598 605
599#define SAA7134_PGTABLE_SIZE 4096 606#define SAA7134_PGTABLE_SIZE 4096
600 607
@@ -631,6 +638,7 @@ extern struct pci_device_id __devinitdata saa7134_pci_tbl[];
631 638
632extern int saa7134_board_init1(struct saa7134_dev *dev); 639extern int saa7134_board_init1(struct saa7134_dev *dev);
633extern int saa7134_board_init2(struct saa7134_dev *dev); 640extern int saa7134_board_init2(struct saa7134_dev *dev);
641int saa7134_tuner_callback(void *priv, int command, int arg);
634 642
635 643
636/* ----------------------------------------------------------- */ 644/* ----------------------------------------------------------- */
diff --git a/drivers/media/video/saa717x.c b/drivers/media/video/saa717x.c
new file mode 100644
index 000000000000..53c5edbcf7ea
--- /dev/null
+++ b/drivers/media/video/saa717x.c
@@ -0,0 +1,1516 @@
1/*
2 * saa717x - Philips SAA717xHL video decoder driver
3 *
4 * Based on the saa7115 driver
5 *
6 * Changes by Ohta Kyuma <alpha292@bremen.or.jp>
7 * - Apply to SAA717x,NEC uPD64031,uPD64083. (1/31/2004)
8 *
9 * Changes by T.Adachi (tadachi@tadachi-net.com)
10 * - support audio, video scaler etc, and checked the initialize sequence.
11 *
12 * Cleaned up by Hans Verkuil <hverkuil@xs4all.nl>
13 *
14 * Note: this is a reversed engineered driver based on captures from
15 * the I2C bus under Windows. This chip is very similar to the saa7134,
16 * though. Unfortunately, this driver is currently only working for NTSC.
17 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
31 */
32
33#include <linux/version.h>
34#include <linux/module.h>
35#include <linux/kernel.h>
36#include <linux/sched.h>
37
38#include <linux/videodev.h>
39#include <linux/videodev2.h>
40#include <linux/i2c.h>
41#include <media/v4l2-common.h>
42#include <media/v4l2-i2c-drv.h>
43
44MODULE_DESCRIPTION("Philips SAA717x audio/video decoder driver");
45MODULE_AUTHOR("K. Ohta, T. Adachi, Hans Verkuil");
46MODULE_LICENSE("GPL");
47
48static int debug;
49module_param(debug, int, 0644);
50MODULE_PARM_DESC(debug, "Debug level (0-1)");
51
52/*
53 * Generic i2c probe
54 * concerning the addresses: i2c wants 7 bit (without the r/w bit), so '>>1'
55 */
56
57struct saa717x_state {
58 v4l2_std_id std;
59 int input;
60 int enable;
61 int radio;
62 int bright;
63 int contrast;
64 int hue;
65 int sat;
66 int playback;
67 int audio;
68 int tuner_audio_mode;
69 int audio_main_mute;
70 int audio_main_vol_r;
71 int audio_main_vol_l;
72 u16 audio_main_bass;
73 u16 audio_main_treble;
74 u16 audio_main_volume;
75 u16 audio_main_balance;
76 int audio_input;
77};
78
79/* ----------------------------------------------------------------------- */
80
81/* for audio mode */
82#define TUNER_AUDIO_MONO 0 /* LL */
83#define TUNER_AUDIO_STEREO 1 /* LR */
84#define TUNER_AUDIO_LANG1 2 /* LL */
85#define TUNER_AUDIO_LANG2 3 /* RR */
86
87#define SAA717X_NTSC_WIDTH (704)
88#define SAA717X_NTSC_HEIGHT (480)
89
90/* ----------------------------------------------------------------------- */
91
92static int saa717x_write(struct i2c_client *client, u32 reg, u32 value)
93{
94 struct i2c_adapter *adap = client->adapter;
95 int fw_addr = reg == 0x454 || (reg >= 0x464 && reg <= 0x478) || reg == 0x480 || reg == 0x488;
96 unsigned char mm1[6];
97 struct i2c_msg msg;
98
99 msg.flags = 0;
100 msg.addr = client->addr;
101 mm1[0] = (reg >> 8) & 0xff;
102 mm1[1] = reg & 0xff;
103
104 if (fw_addr) {
105 mm1[4] = (value >> 16) & 0xff;
106 mm1[3] = (value >> 8) & 0xff;
107 mm1[2] = value & 0xff;
108 } else {
109 mm1[2] = value & 0xff;
110 }
111 msg.len = fw_addr ? 5 : 3; /* Long Registers have *only* three bytes! */
112 msg.buf = mm1;
113 v4l_dbg(2, debug, client, "wrote: reg 0x%03x=%08x\n", reg, value);
114 return i2c_transfer(adap, &msg, 1) == 1;
115}
116
117static void saa717x_write_regs(struct i2c_client *client, u32 *data)
118{
119 while (data[0] || data[1]) {
120 saa717x_write(client, data[0], data[1]);
121 data += 2;
122 }
123}
124
125static u32 saa717x_read(struct i2c_client *client, u32 reg)
126{
127 struct i2c_adapter *adap = client->adapter;
128 int fw_addr = (reg >= 0x404 && reg <= 0x4b8) || reg == 0x528;
129 unsigned char mm1[2];
130 unsigned char mm2[4] = { 0, 0, 0, 0 };
131 struct i2c_msg msgs[2];
132 u32 value;
133
134 msgs[0].flags = 0;
135 msgs[1].flags = I2C_M_RD;
136 msgs[0].addr = msgs[1].addr = client->addr;
137 mm1[0] = (reg >> 8) & 0xff;
138 mm1[1] = reg & 0xff;
139 msgs[0].len = 2;
140 msgs[0].buf = mm1;
141 msgs[1].len = fw_addr ? 3 : 1; /* Multibyte Registers contains *only* 3 bytes */
142 msgs[1].buf = mm2;
143 i2c_transfer(adap, msgs, 2);
144
145 if (fw_addr)
146 value = (mm2[2] & 0xff) | ((mm2[1] & 0xff) >> 8) | ((mm2[0] & 0xff) >> 16);
147 else
148 value = mm2[0] & 0xff;
149
150 v4l_dbg(2, debug, client, "read: reg 0x%03x=0x%08x\n", reg, value);
151 return value;
152}
153
154/* ----------------------------------------------------------------------- */
155
156static u32 reg_init_initialize[] =
157{
158 /* from linux driver */
159 0x101, 0x008, /* Increment delay */
160
161 0x103, 0x000, /* Analog input control 2 */
162 0x104, 0x090, /* Analog input control 3 */
163 0x105, 0x090, /* Analog input control 4 */
164 0x106, 0x0eb, /* Horizontal sync start */
165 0x107, 0x0e0, /* Horizontal sync stop */
166 0x109, 0x055, /* Luminance control */
167
168 0x10f, 0x02a, /* Chroma gain control */
169 0x110, 0x000, /* Chroma control 2 */
170
171 0x114, 0x045, /* analog/ADC */
172
173 0x118, 0x040, /* RAW data gain */
174 0x119, 0x080, /* RAW data offset */
175
176 0x044, 0x000, /* VBI horizontal input window start (L) TASK A */
177 0x045, 0x000, /* VBI horizontal input window start (H) TASK A */
178 0x046, 0x0cf, /* VBI horizontal input window stop (L) TASK A */
179 0x047, 0x002, /* VBI horizontal input window stop (H) TASK A */
180
181 0x049, 0x000, /* VBI vertical input window start (H) TASK A */
182
183 0x04c, 0x0d0, /* VBI horizontal output length (L) TASK A */
184 0x04d, 0x002, /* VBI horizontal output length (H) TASK A */
185
186 0x064, 0x080, /* Lumina brightness TASK A */
187 0x065, 0x040, /* Luminance contrast TASK A */
188 0x066, 0x040, /* Chroma saturation TASK A */
189 /* 067H: Reserved */
190 0x068, 0x000, /* VBI horizontal scaling increment (L) TASK A */
191 0x069, 0x004, /* VBI horizontal scaling increment (H) TASK A */
192 0x06a, 0x000, /* VBI phase offset TASK A */
193
194 0x06e, 0x000, /* Horizontal phase offset Luma TASK A */
195 0x06f, 0x000, /* Horizontal phase offset Chroma TASK A */
196
197 0x072, 0x000, /* Vertical filter mode TASK A */
198
199 0x084, 0x000, /* VBI horizontal input window start (L) TAKS B */
200 0x085, 0x000, /* VBI horizontal input window start (H) TAKS B */
201 0x086, 0x0cf, /* VBI horizontal input window stop (L) TAKS B */
202 0x087, 0x002, /* VBI horizontal input window stop (H) TAKS B */
203
204 0x089, 0x000, /* VBI vertical input window start (H) TAKS B */
205
206 0x08c, 0x0d0, /* VBI horizontal output length (L) TASK B */
207 0x08d, 0x002, /* VBI horizontal output length (H) TASK B */
208
209 0x0a4, 0x080, /* Lumina brightness TASK B */
210 0x0a5, 0x040, /* Luminance contrast TASK B */
211 0x0a6, 0x040, /* Chroma saturation TASK B */
212 /* 0A7H reserved */
213 0x0a8, 0x000, /* VBI horizontal scaling increment (L) TASK B */
214 0x0a9, 0x004, /* VBI horizontal scaling increment (H) TASK B */
215 0x0aa, 0x000, /* VBI phase offset TASK B */
216
217 0x0ae, 0x000, /* Horizontal phase offset Luma TASK B */
218 0x0af, 0x000, /*Horizontal phase offset Chroma TASK B */
219
220 0x0b2, 0x000, /* Vertical filter mode TASK B */
221
222 0x00c, 0x000, /* Start point GREEN path */
223 0x00d, 0x000, /* Start point BLUE path */
224 0x00e, 0x000, /* Start point RED path */
225
226 0x010, 0x010, /* GREEN path gamma curve --- */
227 0x011, 0x020,
228 0x012, 0x030,
229 0x013, 0x040,
230 0x014, 0x050,
231 0x015, 0x060,
232 0x016, 0x070,
233 0x017, 0x080,
234 0x018, 0x090,
235 0x019, 0x0a0,
236 0x01a, 0x0b0,
237 0x01b, 0x0c0,
238 0x01c, 0x0d0,
239 0x01d, 0x0e0,
240 0x01e, 0x0f0,
241 0x01f, 0x0ff, /* --- GREEN path gamma curve */
242
243 0x020, 0x010, /* BLUE path gamma curve --- */
244 0x021, 0x020,
245 0x022, 0x030,
246 0x023, 0x040,
247 0x024, 0x050,
248 0x025, 0x060,
249 0x026, 0x070,
250 0x027, 0x080,
251 0x028, 0x090,
252 0x029, 0x0a0,
253 0x02a, 0x0b0,
254 0x02b, 0x0c0,
255 0x02c, 0x0d0,
256 0x02d, 0x0e0,
257 0x02e, 0x0f0,
258 0x02f, 0x0ff, /* --- BLUE path gamma curve */
259
260 0x030, 0x010, /* RED path gamma curve --- */
261 0x031, 0x020,
262 0x032, 0x030,
263 0x033, 0x040,
264 0x034, 0x050,
265 0x035, 0x060,
266 0x036, 0x070,
267 0x037, 0x080,
268 0x038, 0x090,
269 0x039, 0x0a0,
270 0x03a, 0x0b0,
271 0x03b, 0x0c0,
272 0x03c, 0x0d0,
273 0x03d, 0x0e0,
274 0x03e, 0x0f0,
275 0x03f, 0x0ff, /* --- RED path gamma curve */
276
277 0x109, 0x085, /* Luminance control */
278
279 /**** from app start ****/
280 0x584, 0x000, /* AGC gain control */
281 0x585, 0x000, /* Program count */
282 0x586, 0x003, /* Status reset */
283 0x588, 0x0ff, /* Number of audio samples (L) */
284 0x589, 0x00f, /* Number of audio samples (M) */
285 0x58a, 0x000, /* Number of audio samples (H) */
286 0x58b, 0x000, /* Audio select */
287 0x58c, 0x010, /* Audio channel assign1 */
288 0x58d, 0x032, /* Audio channel assign2 */
289 0x58e, 0x054, /* Audio channel assign3 */
290 0x58f, 0x023, /* Audio format */
291 0x590, 0x000, /* SIF control */
292
293 0x595, 0x000, /* ?? */
294 0x596, 0x000, /* ?? */
295 0x597, 0x000, /* ?? */
296
297 0x464, 0x00, /* Digital input crossbar1 */
298
299 0x46c, 0xbbbb10, /* Digital output selection1-3 */
300 0x470, 0x101010, /* Digital output selection4-6 */
301
302 0x478, 0x00, /* Sound feature control */
303
304 0x474, 0x18, /* Softmute control */
305
306 0x454, 0x0425b9, /* Sound Easy programming(reset) */
307 0x454, 0x042539, /* Sound Easy programming(reset) */
308
309
310 /**** common setting( of DVD play, including scaler commands) ****/
311 0x042, 0x003, /* Data path configuration for VBI (TASK A) */
312
313 0x082, 0x003, /* Data path configuration for VBI (TASK B) */
314
315 0x108, 0x0f8, /* Sync control */
316 0x2a9, 0x0fd, /* ??? */
317 0x102, 0x089, /* select video input "mode 9" */
318 0x111, 0x000, /* Mode/delay control */
319
320 0x10e, 0x00a, /* Chroma control 1 */
321
322 0x594, 0x002, /* SIF, analog I/O select */
323
324 0x454, 0x0425b9, /* Sound */
325 0x454, 0x042539,
326
327 0x111, 0x000,
328 0x10e, 0x00a,
329 0x464, 0x000,
330 0x300, 0x000,
331 0x301, 0x006,
332 0x302, 0x000,
333 0x303, 0x006,
334 0x308, 0x040,
335 0x309, 0x000,
336 0x30a, 0x000,
337 0x30b, 0x000,
338 0x000, 0x002,
339 0x001, 0x000,
340 0x002, 0x000,
341 0x003, 0x000,
342 0x004, 0x033,
343 0x040, 0x01d,
344 0x041, 0x001,
345 0x042, 0x004,
346 0x043, 0x000,
347 0x080, 0x01e,
348 0x081, 0x001,
349 0x082, 0x004,
350 0x083, 0x000,
351 0x190, 0x018,
352 0x115, 0x000,
353 0x116, 0x012,
354 0x117, 0x018,
355 0x04a, 0x011,
356 0x08a, 0x011,
357 0x04b, 0x000,
358 0x08b, 0x000,
359 0x048, 0x000,
360 0x088, 0x000,
361 0x04e, 0x012,
362 0x08e, 0x012,
363 0x058, 0x012,
364 0x098, 0x012,
365 0x059, 0x000,
366 0x099, 0x000,
367 0x05a, 0x003,
368 0x09a, 0x003,
369 0x05b, 0x001,
370 0x09b, 0x001,
371 0x054, 0x008,
372 0x094, 0x008,
373 0x055, 0x000,
374 0x095, 0x000,
375 0x056, 0x0c7,
376 0x096, 0x0c7,
377 0x057, 0x002,
378 0x097, 0x002,
379 0x0ff, 0x0ff,
380 0x060, 0x001,
381 0x0a0, 0x001,
382 0x061, 0x000,
383 0x0a1, 0x000,
384 0x062, 0x000,
385 0x0a2, 0x000,
386 0x063, 0x000,
387 0x0a3, 0x000,
388 0x070, 0x000,
389 0x0b0, 0x000,
390 0x071, 0x004,
391 0x0b1, 0x004,
392 0x06c, 0x0e9,
393 0x0ac, 0x0e9,
394 0x06d, 0x003,
395 0x0ad, 0x003,
396 0x05c, 0x0d0,
397 0x09c, 0x0d0,
398 0x05d, 0x002,
399 0x09d, 0x002,
400 0x05e, 0x0f2,
401 0x09e, 0x0f2,
402 0x05f, 0x000,
403 0x09f, 0x000,
404 0x074, 0x000,
405 0x0b4, 0x000,
406 0x075, 0x000,
407 0x0b5, 0x000,
408 0x076, 0x000,
409 0x0b6, 0x000,
410 0x077, 0x000,
411 0x0b7, 0x000,
412 0x195, 0x008,
413 0x0ff, 0x0ff,
414 0x108, 0x0f8,
415 0x111, 0x000,
416 0x10e, 0x00a,
417 0x2a9, 0x0fd,
418 0x464, 0x001,
419 0x454, 0x042135,
420 0x598, 0x0e7,
421 0x599, 0x07d,
422 0x59a, 0x018,
423 0x59c, 0x066,
424 0x59d, 0x090,
425 0x59e, 0x001,
426 0x584, 0x000,
427 0x585, 0x000,
428 0x586, 0x003,
429 0x588, 0x0ff,
430 0x589, 0x00f,
431 0x58a, 0x000,
432 0x58b, 0x000,
433 0x58c, 0x010,
434 0x58d, 0x032,
435 0x58e, 0x054,
436 0x58f, 0x023,
437 0x590, 0x000,
438 0x595, 0x000,
439 0x596, 0x000,
440 0x597, 0x000,
441 0x464, 0x000,
442 0x46c, 0xbbbb10,
443 0x470, 0x101010,
444
445
446 0x478, 0x000,
447 0x474, 0x018,
448 0x454, 0x042135,
449 0x598, 0x0e7,
450 0x599, 0x07d,
451 0x59a, 0x018,
452 0x59c, 0x066,
453 0x59d, 0x090,
454 0x59e, 0x001,
455 0x584, 0x000,
456 0x585, 0x000,
457 0x586, 0x003,
458 0x588, 0x0ff,
459 0x589, 0x00f,
460 0x58a, 0x000,
461 0x58b, 0x000,
462 0x58c, 0x010,
463 0x58d, 0x032,
464 0x58e, 0x054,
465 0x58f, 0x023,
466 0x590, 0x000,
467 0x595, 0x000,
468 0x596, 0x000,
469 0x597, 0x000,
470 0x464, 0x000,
471 0x46c, 0xbbbb10,
472 0x470, 0x101010,
473
474 0x478, 0x000,
475 0x474, 0x018,
476 0x454, 0x042135,
477 0x598, 0x0e7,
478 0x599, 0x07d,
479 0x59a, 0x018,
480 0x59c, 0x066,
481 0x59d, 0x090,
482 0x59e, 0x001,
483 0x584, 0x000,
484 0x585, 0x000,
485 0x586, 0x003,
486 0x588, 0x0ff,
487 0x589, 0x00f,
488 0x58a, 0x000,
489 0x58b, 0x000,
490 0x58c, 0x010,
491 0x58d, 0x032,
492 0x58e, 0x054,
493 0x58f, 0x023,
494 0x590, 0x000,
495 0x595, 0x000,
496 0x596, 0x000,
497 0x597, 0x000,
498 0x464, 0x000,
499 0x46c, 0xbbbb10,
500 0x470, 0x101010,
501 0x478, 0x000,
502 0x474, 0x018,
503 0x454, 0x042135,
504 0x193, 0x000,
505 0x300, 0x000,
506 0x301, 0x006,
507 0x302, 0x000,
508 0x303, 0x006,
509 0x308, 0x040,
510 0x309, 0x000,
511 0x30a, 0x000,
512 0x30b, 0x000,
513 0x000, 0x002,
514 0x001, 0x000,
515 0x002, 0x000,
516 0x003, 0x000,
517 0x004, 0x033,
518 0x040, 0x01d,
519 0x041, 0x001,
520 0x042, 0x004,
521 0x043, 0x000,
522 0x080, 0x01e,
523 0x081, 0x001,
524 0x082, 0x004,
525 0x083, 0x000,
526 0x190, 0x018,
527 0x115, 0x000,
528 0x116, 0x012,
529 0x117, 0x018,
530 0x04a, 0x011,
531 0x08a, 0x011,
532 0x04b, 0x000,
533 0x08b, 0x000,
534 0x048, 0x000,
535 0x088, 0x000,
536 0x04e, 0x012,
537 0x08e, 0x012,
538 0x058, 0x012,
539 0x098, 0x012,
540 0x059, 0x000,
541 0x099, 0x000,
542 0x05a, 0x003,
543 0x09a, 0x003,
544 0x05b, 0x001,
545 0x09b, 0x001,
546 0x054, 0x008,
547 0x094, 0x008,
548 0x055, 0x000,
549 0x095, 0x000,
550 0x056, 0x0c7,
551 0x096, 0x0c7,
552 0x057, 0x002,
553 0x097, 0x002,
554 0x060, 0x001,
555 0x0a0, 0x001,
556 0x061, 0x000,
557 0x0a1, 0x000,
558 0x062, 0x000,
559 0x0a2, 0x000,
560 0x063, 0x000,
561 0x0a3, 0x000,
562 0x070, 0x000,
563 0x0b0, 0x000,
564 0x071, 0x004,
565 0x0b1, 0x004,
566 0x06c, 0x0e9,
567 0x0ac, 0x0e9,
568 0x06d, 0x003,
569 0x0ad, 0x003,
570 0x05c, 0x0d0,
571 0x09c, 0x0d0,
572 0x05d, 0x002,
573 0x09d, 0x002,
574 0x05e, 0x0f2,
575 0x09e, 0x0f2,
576 0x05f, 0x000,
577 0x09f, 0x000,
578 0x074, 0x000,
579 0x0b4, 0x000,
580 0x075, 0x000,
581 0x0b5, 0x000,
582 0x076, 0x000,
583 0x0b6, 0x000,
584 0x077, 0x000,
585 0x0b7, 0x000,
586 0x195, 0x008,
587 0x598, 0x0e7,
588 0x599, 0x07d,
589 0x59a, 0x018,
590 0x59c, 0x066,
591 0x59d, 0x090,
592 0x59e, 0x001,
593 0x584, 0x000,
594 0x585, 0x000,
595 0x586, 0x003,
596 0x588, 0x0ff,
597 0x589, 0x00f,
598 0x58a, 0x000,
599 0x58b, 0x000,
600 0x58c, 0x010,
601 0x58d, 0x032,
602 0x58e, 0x054,
603 0x58f, 0x023,
604 0x590, 0x000,
605 0x595, 0x000,
606 0x596, 0x000,
607 0x597, 0x000,
608 0x464, 0x000,
609 0x46c, 0xbbbb10,
610 0x470, 0x101010,
611 0x478, 0x000,
612 0x474, 0x018,
613 0x454, 0x042135,
614 0x193, 0x0a6,
615 0x108, 0x0f8,
616 0x042, 0x003,
617 0x082, 0x003,
618 0x454, 0x0425b9,
619 0x454, 0x042539,
620 0x193, 0x000,
621 0x193, 0x0a6,
622 0x464, 0x000,
623
624 0, 0
625};
626
627/* Tuner */
628static u32 reg_init_tuner_input[] = {
629 0x108, 0x0f8, /* Sync control */
630 0x111, 0x000, /* Mode/delay control */
631 0x10e, 0x00a, /* Chroma control 1 */
632 0, 0
633};
634
635/* Composite */
636static u32 reg_init_composite_input[] = {
637 0x108, 0x0e8, /* Sync control */
638 0x111, 0x000, /* Mode/delay control */
639 0x10e, 0x04a, /* Chroma control 1 */
640 0, 0
641};
642
643/* S-Video */
644static u32 reg_init_svideo_input[] = {
645 0x108, 0x0e8, /* Sync control */
646 0x111, 0x000, /* Mode/delay control */
647 0x10e, 0x04a, /* Chroma control 1 */
648 0, 0
649};
650
651static u32 reg_set_audio_template[4][2] =
652{
653 { /* for MONO
654 tadachi 6/29 DMA audio output select?
655 Register 0x46c
656 7-4: DMA2, 3-0: DMA1 ch. DMA4, DMA3 DMA2, DMA1
657 0: MAIN left, 1: MAIN right
658 2: AUX1 left, 3: AUX1 right
659 4: AUX2 left, 5: AUX2 right
660 6: DPL left, 7: DPL right
661 8: DPL center, 9: DPL surround
662 A: monitor output, B: digital sense */
663 0xbbbb00,
664
665 /* tadachi 6/29 DAC and I2S output select?
666 Register 0x470
667 7-4:DAC right ch. 3-0:DAC left ch.
668 I2S1 right,left I2S2 right,left */
669 0x00,
670 },
671 { /* for STEREO */
672 0xbbbb10, 0x101010,
673 },
674 { /* for LANG1 */
675 0xbbbb00, 0x00,
676 },
677 { /* for LANG2/SAP */
678 0xbbbb11, 0x111111,
679 }
680};
681
682
683/* Get detected audio flags (from saa7134 driver) */
684static void get_inf_dev_status(struct i2c_client *client,
685 int *dual_flag, int *stereo_flag)
686{
687 u32 reg_data3;
688
689 static char *stdres[0x20] = {
690 [0x00] = "no standard detected",
691 [0x01] = "B/G (in progress)",
692 [0x02] = "D/K (in progress)",
693 [0x03] = "M (in progress)",
694
695 [0x04] = "B/G A2",
696 [0x05] = "B/G NICAM",
697 [0x06] = "D/K A2 (1)",
698 [0x07] = "D/K A2 (2)",
699 [0x08] = "D/K A2 (3)",
700 [0x09] = "D/K NICAM",
701 [0x0a] = "L NICAM",
702 [0x0b] = "I NICAM",
703
704 [0x0c] = "M Korea",
705 [0x0d] = "M BTSC ",
706 [0x0e] = "M EIAJ",
707
708 [0x0f] = "FM radio / IF 10.7 / 50 deemp",
709 [0x10] = "FM radio / IF 10.7 / 75 deemp",
710 [0x11] = "FM radio / IF sel / 50 deemp",
711 [0x12] = "FM radio / IF sel / 75 deemp",
712
713 [0x13 ... 0x1e] = "unknown",
714 [0x1f] = "??? [in progress]",
715 };
716
717
718 *dual_flag = *stereo_flag = 0;
719
720 /* (demdec status: 0x528) */
721
722 /* read current status */
723 reg_data3 = saa717x_read(client, 0x0528);
724
725 v4l_dbg(1, debug, client, "tvaudio thread status: 0x%x [%s%s%s]\n",
726 reg_data3, stdres[reg_data3 & 0x1f],
727 (reg_data3 & 0x000020) ? ",stereo" : "",
728 (reg_data3 & 0x000040) ? ",dual" : "");
729 v4l_dbg(1, debug, client, "detailed status: "
730 "%s#%s#%s#%s#%s#%s#%s#%s#%s#%s#%s#%s#%s#%s\n",
731 (reg_data3 & 0x000080) ? " A2/EIAJ pilot tone " : "",
732 (reg_data3 & 0x000100) ? " A2/EIAJ dual " : "",
733 (reg_data3 & 0x000200) ? " A2/EIAJ stereo " : "",
734 (reg_data3 & 0x000400) ? " A2/EIAJ noise mute " : "",
735
736 (reg_data3 & 0x000800) ? " BTSC/FM radio pilot " : "",
737 (reg_data3 & 0x001000) ? " SAP carrier " : "",
738 (reg_data3 & 0x002000) ? " BTSC stereo noise mute " : "",
739 (reg_data3 & 0x004000) ? " SAP noise mute " : "",
740 (reg_data3 & 0x008000) ? " VDSP " : "",
741
742 (reg_data3 & 0x010000) ? " NICST " : "",
743 (reg_data3 & 0x020000) ? " NICDU " : "",
744 (reg_data3 & 0x040000) ? " NICAM muted " : "",
745 (reg_data3 & 0x080000) ? " NICAM reserve sound " : "",
746
747 (reg_data3 & 0x100000) ? " init done " : "");
748
749 if (reg_data3 & 0x000220) {
750 v4l_dbg(1, debug, client, "ST!!!\n");
751 *stereo_flag = 1;
752 }
753
754 if (reg_data3 & 0x000140) {
755 v4l_dbg(1, debug, client, "DUAL!!!\n");
756 *dual_flag = 1;
757 }
758}
759
760/* regs write to set audio mode */
761static void set_audio_mode(struct i2c_client *client, int audio_mode)
762{
763 v4l_dbg(1, debug, client, "writing registers to set audio mode by set %d\n",
764 audio_mode);
765
766 saa717x_write(client, 0x46c, reg_set_audio_template[audio_mode][0]);
767 saa717x_write(client, 0x470, reg_set_audio_template[audio_mode][1]);
768}
769
770/* write regs to video output level (bright,contrast,hue,sat) */
771static void set_video_output_level_regs(struct i2c_client *client,
772 struct saa717x_state *decoder)
773{
774 /* brightness ffh (bright) - 80h (ITU level) - 00h (dark) */
775 saa717x_write(client, 0x10a, decoder->bright);
776
777 /* contrast 7fh (max: 1.984) - 44h (ITU) - 40h (1.0) -
778 0h (luminance off) 40: i2c dump
779 c0h (-1.0 inverse chrominance)
780 80h (-2.0 inverse chrominance) */
781 saa717x_write(client, 0x10b, decoder->contrast);
782
783 /* saturation? 7fh(max)-40h(ITU)-0h(color off)
784 c0h (-1.0 inverse chrominance)
785 80h (-2.0 inverse chrominance) */
786 saa717x_write(client, 0x10c, decoder->sat);
787
788 /* color hue (phase) control
789 7fh (+178.6) - 0h (0 normal) - 80h (-180.0) */
790 saa717x_write(client, 0x10d, decoder->hue);
791}
792
793/* write regs to set audio volume, bass and treble */
794static int set_audio_regs(struct i2c_client *client,
795 struct saa717x_state *decoder)
796{
797 u8 mute = 0xac; /* -84 dB */
798 u32 val;
799 unsigned int work_l, work_r;
800
801 /* set SIF analog I/O select */
802 saa717x_write(client, 0x0594, decoder->audio_input);
803 v4l_dbg(1, debug, client, "set audio input %d\n",
804 decoder->audio_input);
805
806 /* normalize ( 65535 to 0 -> 24 to -40 (not -84)) */
807 work_l = (min(65536 - decoder->audio_main_balance, 32768) * decoder->audio_main_volume) / 32768;
808 work_r = (min(decoder->audio_main_balance, (u16)32768) * decoder->audio_main_volume) / 32768;
809 decoder->audio_main_vol_l = (long)work_l * (24 - (-40)) / 65535 - 40;
810 decoder->audio_main_vol_r = (long)work_r * (24 - (-40)) / 65535 - 40;
811
812 /* set main volume */
813 /* main volume L[7-0],R[7-0],0x00 24=24dB,-83dB, -84(mute) */
814 /* def:0dB->6dB(MPG600GR) */
815 /* if mute is on, set mute */
816 if (decoder->audio_main_mute) {
817 val = mute | (mute << 8);
818 } else {
819 val = (u8)decoder->audio_main_vol_l |
820 ((u8)decoder->audio_main_vol_r << 8);
821 }
822
823 saa717x_write(client, 0x480, val);
824
825 /* bass and treble; go to another function */
826 /* set bass and treble */
827 val = decoder->audio_main_bass | (decoder->audio_main_treble << 8);
828 saa717x_write(client, 0x488, val);
829 return 0;
830}
831
832/********** scaling staff ***********/
833static void set_h_prescale(struct i2c_client *client,
834 int task, int prescale)
835{
836 static const struct {
837 int xpsc;
838 int xacl;
839 int xc2_1;
840 int xdcg;
841 int vpfy;
842 } vals[] = {
843 /* XPSC XACL XC2_1 XDCG VPFY */
844 { 1, 0, 0, 0, 0 },
845 { 2, 2, 1, 2, 2 },
846 { 3, 4, 1, 3, 2 },
847 { 4, 8, 1, 4, 2 },
848 { 5, 8, 1, 4, 2 },
849 { 6, 8, 1, 4, 3 },
850 { 7, 8, 1, 4, 3 },
851 { 8, 15, 0, 4, 3 },
852 { 9, 15, 0, 4, 3 },
853 { 10, 16, 1, 5, 3 },
854 };
855 static const int count = ARRAY_SIZE(vals);
856 int i, task_shift;
857
858 task_shift = task * 0x40;
859 for (i = 0; i < count; i++)
860 if (vals[i].xpsc == prescale)
861 break;
862 if (i == count)
863 return;
864
865 /* horizonal prescaling */
866 saa717x_write(client, 0x60 + task_shift, vals[i].xpsc);
867 /* accumulation length */
868 saa717x_write(client, 0x61 + task_shift, vals[i].xacl);
869 /* level control */
870 saa717x_write(client, 0x62 + task_shift,
871 (vals[i].xc2_1 << 3) | vals[i].xdcg);
872 /*FIR prefilter control */
873 saa717x_write(client, 0x63 + task_shift,
874 (vals[i].vpfy << 2) | vals[i].vpfy);
875}
876
877/********** scaling staff ***********/
878static void set_v_scale(struct i2c_client *client, int task, int yscale)
879{
880 int task_shift;
881
882 task_shift = task * 0x40;
883 /* Vertical scaling ratio (LOW) */
884 saa717x_write(client, 0x70 + task_shift, yscale & 0xff);
885 /* Vertical scaling ratio (HI) */
886 saa717x_write(client, 0x71 + task_shift, yscale >> 8);
887}
888
889static int saa717x_set_audio_clock_freq(struct i2c_client *client, u32 freq)
890{
891 /* not yet implament, so saa717x_cfg_??hz_??_audio is not defined. */
892 return 0;
893}
894
895static int saa717x_set_v4lctrl(struct i2c_client *client, struct v4l2_control *ctrl)
896{
897 struct saa717x_state *state = i2c_get_clientdata(client);
898
899 switch (ctrl->id) {
900 case V4L2_CID_BRIGHTNESS:
901 if (ctrl->value < 0 || ctrl->value > 255) {
902 v4l_err(client, "invalid brightness setting %d\n", ctrl->value);
903 return -ERANGE;
904 }
905
906 state->bright = ctrl->value;
907 v4l_dbg(1, debug, client, "bright:%d\n", state->bright);
908 saa717x_write(client, 0x10a, state->bright);
909 break;
910
911 case V4L2_CID_CONTRAST:
912 if (ctrl->value < 0 || ctrl->value > 127) {
913 v4l_err(client, "invalid contrast setting %d\n", ctrl->value);
914 return -ERANGE;
915 }
916
917 state->contrast = ctrl->value;
918 v4l_dbg(1, debug, client, "contrast:%d\n", state->contrast);
919 saa717x_write(client, 0x10b, state->contrast);
920 break;
921
922 case V4L2_CID_SATURATION:
923 if (ctrl->value < 0 || ctrl->value > 127) {
924 v4l_err(client, "invalid saturation setting %d\n", ctrl->value);
925 return -ERANGE;
926 }
927
928 state->sat = ctrl->value;
929 v4l_dbg(1, debug, client, "sat:%d\n", state->sat);
930 saa717x_write(client, 0x10c, state->sat);
931 break;
932
933 case V4L2_CID_HUE:
934 if (ctrl->value < -127 || ctrl->value > 127) {
935 v4l_err(client, "invalid hue setting %d\n", ctrl->value);
936 return -ERANGE;
937 }
938
939 state->hue = ctrl->value;
940 v4l_dbg(1, debug, client, "hue:%d\n", state->hue);
941 saa717x_write(client, 0x10d, state->hue);
942 break;
943
944 case V4L2_CID_AUDIO_MUTE:
945 state->audio_main_mute = ctrl->value;
946 set_audio_regs(client, state);
947 break;
948
949 case V4L2_CID_AUDIO_VOLUME:
950 state->audio_main_volume = ctrl->value;
951 set_audio_regs(client, state);
952 break;
953
954 case V4L2_CID_AUDIO_BALANCE:
955 state->audio_main_balance = ctrl->value;
956 set_audio_regs(client, state);
957 break;
958
959 case V4L2_CID_AUDIO_TREBLE:
960 state->audio_main_treble = ctrl->value;
961 set_audio_regs(client, state);
962 break;
963
964 case V4L2_CID_AUDIO_BASS:
965 state->audio_main_bass = ctrl->value;
966 set_audio_regs(client, state);
967 break;
968
969 default:
970 return -EINVAL;
971 }
972
973 return 0;
974}
975
976static int saa717x_get_v4lctrl(struct i2c_client *client, struct v4l2_control *ctrl)
977{
978 struct saa717x_state *state = i2c_get_clientdata(client);
979
980 switch (ctrl->id) {
981 case V4L2_CID_BRIGHTNESS:
982 ctrl->value = state->bright;
983 break;
984
985 case V4L2_CID_CONTRAST:
986 ctrl->value = state->contrast;
987 break;
988
989 case V4L2_CID_SATURATION:
990 ctrl->value = state->sat;
991 break;
992
993 case V4L2_CID_HUE:
994 ctrl->value = state->hue;
995 break;
996
997 case V4L2_CID_AUDIO_MUTE:
998 ctrl->value = state->audio_main_mute;
999 break;
1000
1001 case V4L2_CID_AUDIO_VOLUME:
1002 ctrl->value = state->audio_main_volume;
1003 break;
1004
1005 case V4L2_CID_AUDIO_BALANCE:
1006 ctrl->value = state->audio_main_balance;
1007 break;
1008
1009 case V4L2_CID_AUDIO_TREBLE:
1010 ctrl->value = state->audio_main_treble;
1011 break;
1012
1013 case V4L2_CID_AUDIO_BASS:
1014 ctrl->value = state->audio_main_bass;
1015 break;
1016
1017 default:
1018 return -EINVAL;
1019 }
1020
1021 return 0;
1022}
1023
1024static struct v4l2_queryctrl saa717x_qctrl[] = {
1025 {
1026 .id = V4L2_CID_BRIGHTNESS,
1027 .type = V4L2_CTRL_TYPE_INTEGER,
1028 .name = "Brightness",
1029 .minimum = 0,
1030 .maximum = 255,
1031 .step = 1,
1032 .default_value = 128,
1033 .flags = 0,
1034 }, {
1035 .id = V4L2_CID_CONTRAST,
1036 .type = V4L2_CTRL_TYPE_INTEGER,
1037 .name = "Contrast",
1038 .minimum = 0,
1039 .maximum = 255,
1040 .step = 1,
1041 .default_value = 64,
1042 .flags = 0,
1043 }, {
1044 .id = V4L2_CID_SATURATION,
1045 .type = V4L2_CTRL_TYPE_INTEGER,
1046 .name = "Saturation",
1047 .minimum = 0,
1048 .maximum = 255,
1049 .step = 1,
1050 .default_value = 64,
1051 .flags = 0,
1052 }, {
1053 .id = V4L2_CID_HUE,
1054 .type = V4L2_CTRL_TYPE_INTEGER,
1055 .name = "Hue",
1056 .minimum = -128,
1057 .maximum = 127,
1058 .step = 1,
1059 .default_value = 0,
1060 .flags = 0,
1061 }, {
1062 .id = V4L2_CID_AUDIO_VOLUME,
1063 .type = V4L2_CTRL_TYPE_INTEGER,
1064 .name = "Volume",
1065 .minimum = 0,
1066 .maximum = 65535,
1067 .step = 65535 / 100,
1068 .default_value = 58880,
1069 .flags = 0,
1070 }, {
1071 .id = V4L2_CID_AUDIO_BALANCE,
1072 .type = V4L2_CTRL_TYPE_INTEGER,
1073 .name = "Balance",
1074 .minimum = 0,
1075 .maximum = 65535,
1076 .step = 65535 / 100,
1077 .default_value = 32768,
1078 .flags = 0,
1079 }, {
1080 .id = V4L2_CID_AUDIO_MUTE,
1081 .type = V4L2_CTRL_TYPE_BOOLEAN,
1082 .name = "Mute",
1083 .minimum = 0,
1084 .maximum = 1,
1085 .step = 1,
1086 .default_value = 1,
1087 .flags = 0,
1088 }, {
1089 .id = V4L2_CID_AUDIO_BASS,
1090 .type = V4L2_CTRL_TYPE_INTEGER,
1091 .name = "Bass",
1092 .minimum = 0,
1093 .maximum = 65535,
1094 .step = 65535 / 100,
1095 .default_value = 32768,
1096 }, {
1097 .id = V4L2_CID_AUDIO_TREBLE,
1098 .type = V4L2_CTRL_TYPE_INTEGER,
1099 .name = "Treble",
1100 .minimum = 0,
1101 .maximum = 65535,
1102 .step = 65535 / 100,
1103 .default_value = 32768,
1104 },
1105};
1106
1107static int saa717x_set_video_input(struct i2c_client *client, struct saa717x_state *decoder, int inp)
1108{
1109 int is_tuner = inp & 0x80; /* tuner input flag */
1110
1111 inp &= 0x7f;
1112
1113 v4l_dbg(1, debug, client, "decoder set input (%d)\n", inp);
1114 /* inputs from 0-9 are available*/
1115 /* saa717x have mode0-mode9 but mode5 is reserved. */
1116 if (inp < 0 || inp > 9 || inp == 5)
1117 return -EINVAL;
1118
1119 if (decoder->input != inp) {
1120 int input_line = inp;
1121
1122 decoder->input = input_line;
1123 v4l_dbg(1, debug, client, "now setting %s input %d\n",
1124 input_line >= 6 ? "S-Video" : "Composite",
1125 input_line);
1126
1127 /* select mode */
1128 saa717x_write(client, 0x102,
1129 (saa717x_read(client, 0x102) & 0xf0) |
1130 input_line);
1131
1132 /* bypass chrominance trap for modes 6..9 */
1133 saa717x_write(client, 0x109,
1134 (saa717x_read(client, 0x109) & 0x7f) |
1135 (input_line < 6 ? 0x0 : 0x80));
1136
1137 /* change audio_mode */
1138 if (is_tuner) {
1139 /* tuner */
1140 set_audio_mode(client, decoder->tuner_audio_mode);
1141 } else {
1142 /* Force to STEREO mode if Composite or
1143 * S-Video were chosen */
1144 set_audio_mode(client, TUNER_AUDIO_STEREO);
1145 }
1146 /* change initialize procedure (Composite/S-Video) */
1147 if (is_tuner)
1148 saa717x_write_regs(client, reg_init_tuner_input);
1149 else if (input_line >= 6)
1150 saa717x_write_regs(client, reg_init_svideo_input);
1151 else
1152 saa717x_write_regs(client, reg_init_composite_input);
1153 }
1154
1155 return 0;
1156}
1157
1158static int saa717x_command(struct i2c_client *client, unsigned cmd, void *arg)
1159{
1160 struct saa717x_state *decoder = i2c_get_clientdata(client);
1161
1162 v4l_dbg(1, debug, client, "IOCTL: %08x\n", cmd);
1163
1164 switch (cmd) {
1165 case VIDIOC_INT_AUDIO_CLOCK_FREQ:
1166 return saa717x_set_audio_clock_freq(client, *(u32 *)arg);
1167
1168 case VIDIOC_G_CTRL:
1169 return saa717x_get_v4lctrl(client, (struct v4l2_control *)arg);
1170
1171 case VIDIOC_S_CTRL:
1172 return saa717x_set_v4lctrl(client, (struct v4l2_control *)arg);
1173
1174 case VIDIOC_QUERYCTRL: {
1175 struct v4l2_queryctrl *qc = arg;
1176 int i;
1177
1178 for (i = 0; i < ARRAY_SIZE(saa717x_qctrl); i++)
1179 if (qc->id && qc->id == saa717x_qctrl[i].id) {
1180 memcpy(qc, &saa717x_qctrl[i], sizeof(*qc));
1181 return 0;
1182 }
1183 return -EINVAL;
1184 }
1185
1186#ifdef CONFIG_VIDEO_ADV_DEBUG
1187 case VIDIOC_DBG_G_REGISTER: {
1188 struct v4l2_register *reg = arg;
1189
1190 if (!v4l2_chip_match_i2c_client(client, reg->match_type, reg->match_chip))
1191 return -EINVAL;
1192 if (!capable(CAP_SYS_ADMIN))
1193 return -EPERM;
1194 reg->val = saa717x_read(client, reg->reg);
1195 break;
1196 }
1197
1198 case VIDIOC_DBG_S_REGISTER: {
1199 struct v4l2_register *reg = arg;
1200 u16 addr = reg->reg & 0xffff;
1201 u8 val = reg->val & 0xff;
1202
1203 if (!v4l2_chip_match_i2c_client(client, reg->match_type, reg->match_chip))
1204 return -EINVAL;
1205 if (!capable(CAP_SYS_ADMIN))
1206 return -EPERM;
1207 saa717x_write(client, addr, val);
1208 break;
1209 }
1210#endif
1211
1212 case VIDIOC_S_FMT: {
1213 struct v4l2_format *fmt = (struct v4l2_format *)arg;
1214 struct v4l2_pix_format *pix;
1215 int prescale, h_scale, v_scale;
1216
1217 pix = &fmt->fmt.pix;
1218 v4l_dbg(1, debug, client, "decoder set size\n");
1219
1220 /* FIXME need better bounds checking here */
1221 if (pix->width < 1 || pix->width > 1440)
1222 return -EINVAL;
1223 if (pix->height < 1 || pix->height > 960)
1224 return -EINVAL;
1225
1226 /* scaling setting */
1227 /* NTSC and interlace only */
1228 prescale = SAA717X_NTSC_WIDTH / pix->width;
1229 if (prescale == 0)
1230 prescale = 1;
1231 h_scale = 1024 * SAA717X_NTSC_WIDTH / prescale / pix->width;
1232 /* interlace */
1233 v_scale = 512 * 2 * SAA717X_NTSC_HEIGHT / pix->height;
1234
1235 /* Horizontal prescaling etc */
1236 set_h_prescale(client, 0, prescale);
1237 set_h_prescale(client, 1, prescale);
1238
1239 /* Horizontal scaling increment */
1240 /* TASK A */
1241 saa717x_write(client, 0x6C, (u8)(h_scale & 0xFF));
1242 saa717x_write(client, 0x6D, (u8)((h_scale >> 8) & 0xFF));
1243 /* TASK B */
1244 saa717x_write(client, 0xAC, (u8)(h_scale & 0xFF));
1245 saa717x_write(client, 0xAD, (u8)((h_scale >> 8) & 0xFF));
1246
1247 /* Vertical prescaling etc */
1248 set_v_scale(client, 0, v_scale);
1249 set_v_scale(client, 1, v_scale);
1250
1251 /* set video output size */
1252 /* video number of pixels at output */
1253 /* TASK A */
1254 saa717x_write(client, 0x5C, (u8)(pix->width & 0xFF));
1255 saa717x_write(client, 0x5D, (u8)((pix->width >> 8) & 0xFF));
1256 /* TASK B */
1257 saa717x_write(client, 0x9C, (u8)(pix->width & 0xFF));
1258 saa717x_write(client, 0x9D, (u8)((pix->width >> 8) & 0xFF));
1259
1260 /* video number of lines at output */
1261 /* TASK A */
1262 saa717x_write(client, 0x5E, (u8)(pix->height & 0xFF));
1263 saa717x_write(client, 0x5F, (u8)((pix->height >> 8) & 0xFF));
1264 /* TASK B */
1265 saa717x_write(client, 0x9E, (u8)(pix->height & 0xFF));
1266 saa717x_write(client, 0x9F, (u8)((pix->height >> 8) & 0xFF));
1267 break;
1268 }
1269
1270 case AUDC_SET_RADIO:
1271 decoder->radio = 1;
1272 break;
1273
1274 case VIDIOC_S_STD: {
1275 v4l2_std_id std = *(v4l2_std_id *) arg;
1276
1277 v4l_dbg(1, debug, client, "decoder set norm ");
1278 v4l_dbg(1, debug, client, "(not yet implementd)\n");
1279
1280 decoder->radio = 0;
1281 decoder->std = std;
1282 break;
1283 }
1284
1285 case VIDIOC_INT_G_AUDIO_ROUTING: {
1286 struct v4l2_routing *route = arg;
1287
1288 route->input = decoder->audio_input;
1289 route->output = 0;
1290 break;
1291 }
1292
1293 case VIDIOC_INT_S_AUDIO_ROUTING: {
1294 struct v4l2_routing *route = arg;
1295
1296 if (route->input < 3) { /* FIXME! --tadachi */
1297 decoder->audio_input = route->input;
1298 v4l_dbg(1, debug, client,
1299 "set decoder audio input to %d\n",
1300 decoder->audio_input);
1301 set_audio_regs(client, decoder);
1302 break;
1303 }
1304 return -ERANGE;
1305 }
1306
1307 case VIDIOC_INT_S_VIDEO_ROUTING: {
1308 struct v4l2_routing *route = arg;
1309 int inp = route->input;
1310
1311 return saa717x_set_video_input(client, decoder, inp);
1312 }
1313
1314 case VIDIOC_STREAMON: {
1315 v4l_dbg(1, debug, client, "decoder enable output\n");
1316 decoder->enable = 1;
1317 saa717x_write(client, 0x193, 0xa6);
1318 break;
1319 }
1320
1321 case VIDIOC_STREAMOFF: {
1322 v4l_dbg(1, debug, client, "decoder disable output\n");
1323 decoder->enable = 0;
1324 saa717x_write(client, 0x193, 0x26); /* right? FIXME!--tadachi */
1325 break;
1326 }
1327
1328 /* change audio mode */
1329 case VIDIOC_S_TUNER: {
1330 struct v4l2_tuner *vt = (struct v4l2_tuner *)arg;
1331 int audio_mode;
1332 char *mes[4] = {
1333 "MONO", "STEREO", "LANG1", "LANG2/SAP"
1334 };
1335
1336 audio_mode = V4L2_TUNER_MODE_STEREO;
1337
1338 switch (vt->audmode) {
1339 case V4L2_TUNER_MODE_MONO:
1340 audio_mode = TUNER_AUDIO_MONO;
1341 break;
1342 case V4L2_TUNER_MODE_STEREO:
1343 audio_mode = TUNER_AUDIO_STEREO;
1344 break;
1345 case V4L2_TUNER_MODE_LANG2:
1346 audio_mode = TUNER_AUDIO_LANG2;
1347 break;
1348 case V4L2_TUNER_MODE_LANG1:
1349 audio_mode = TUNER_AUDIO_LANG1;
1350 break;
1351 }
1352
1353 v4l_dbg(1, debug, client, "change audio mode to %s\n",
1354 mes[audio_mode]);
1355 decoder->tuner_audio_mode = audio_mode;
1356 /* The registers are not changed here. */
1357 /* See DECODER_ENABLE_OUTPUT section. */
1358 set_audio_mode(client, decoder->tuner_audio_mode);
1359 break;
1360 }
1361
1362 case VIDIOC_G_TUNER: {
1363 struct v4l2_tuner *vt = (struct v4l2_tuner *)arg;
1364 int dual_f, stereo_f;
1365
1366 if (decoder->radio)
1367 break;
1368 get_inf_dev_status(client, &dual_f, &stereo_f);
1369
1370 v4l_dbg(1, debug, client, "DETECT==st:%d dual:%d\n",
1371 stereo_f, dual_f);
1372
1373 /* mono */
1374 if ((dual_f == 0) && (stereo_f == 0)) {
1375 vt->rxsubchans = V4L2_TUNER_SUB_MONO;
1376 v4l_dbg(1, debug, client, "DETECT==MONO\n");
1377 }
1378
1379 /* stereo */
1380 if (stereo_f == 1) {
1381 if (vt->audmode == V4L2_TUNER_MODE_STEREO ||
1382 vt->audmode == V4L2_TUNER_MODE_LANG1) {
1383 vt->rxsubchans = V4L2_TUNER_SUB_STEREO;
1384 v4l_dbg(1, debug, client, "DETECT==ST(ST)\n");
1385 } else {
1386 vt->rxsubchans = V4L2_TUNER_SUB_MONO;
1387 v4l_dbg(1, debug, client, "DETECT==ST(MONO)\n");
1388 }
1389 }
1390
1391 /* dual */
1392 if (dual_f == 1) {
1393 if (vt->audmode == V4L2_TUNER_MODE_LANG2) {
1394 vt->rxsubchans = V4L2_TUNER_SUB_LANG2 | V4L2_TUNER_SUB_MONO;
1395 v4l_dbg(1, debug, client, "DETECT==DUAL1\n");
1396 } else {
1397 vt->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_MONO;
1398 v4l_dbg(1, debug, client, "DETECT==DUAL2\n");
1399 }
1400 }
1401 break;
1402 }
1403
1404 case VIDIOC_LOG_STATUS:
1405 /* not yet implemented */
1406 break;
1407
1408 default:
1409 return -EINVAL;
1410 }
1411
1412 return 0;
1413}
1414
1415/* ----------------------------------------------------------------------- */
1416
1417
1418/* i2c implementation */
1419
1420/* ----------------------------------------------------------------------- */
1421static int saa717x_probe(struct i2c_client *client)
1422{
1423 struct saa717x_state *decoder;
1424 u8 id = 0;
1425 char *p = "";
1426
1427 /* Check if the adapter supports the needed features */
1428 if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_BYTE_DATA))
1429 return -EIO;
1430
1431 snprintf(client->name, sizeof(client->name) - 1, "saa717x");
1432
1433 if (saa717x_write(client, 0x5a4, 0xfe) &&
1434 saa717x_write(client, 0x5a5, 0x0f) &&
1435 saa717x_write(client, 0x5a6, 0x00) &&
1436 saa717x_write(client, 0x5a7, 0x01))
1437 id = saa717x_read(client, 0x5a0);
1438 if (id != 0xc2 && id != 0x32 && id != 0xf2 && id != 0x6c) {
1439 v4l_dbg(1, debug, client, "saa717x not found (id=%02x)\n", id);
1440 return -ENODEV;
1441 }
1442 if (id == 0xc2)
1443 p = "saa7173";
1444 else if (id == 0x32)
1445 p = "saa7174A";
1446 else if (id == 0x6c)
1447 p = "saa7174HL";
1448 else
1449 p = "saa7171";
1450 v4l_info(client, "%s found @ 0x%x (%s)\n", p,
1451 client->addr << 1, client->adapter->name);
1452
1453 decoder = kzalloc(sizeof(struct saa717x_state), GFP_KERNEL);
1454 i2c_set_clientdata(client, decoder);
1455
1456 if (decoder == NULL)
1457 return -ENOMEM;
1458 decoder->std = V4L2_STD_NTSC;
1459 decoder->input = -1;
1460 decoder->enable = 1;
1461
1462 /* tune these parameters */
1463 decoder->bright = 0x80;
1464 decoder->contrast = 0x44;
1465 decoder->sat = 0x40;
1466 decoder->hue = 0x00;
1467
1468 /* FIXME!! */
1469 decoder->playback = 0; /* initially capture mode used */
1470 decoder->audio = 1; /* DECODER_AUDIO_48_KHZ */
1471
1472 decoder->audio_input = 2; /* FIXME!! */
1473
1474 decoder->tuner_audio_mode = TUNER_AUDIO_STEREO;
1475 /* set volume, bass and treble */
1476 decoder->audio_main_vol_l = 6;
1477 decoder->audio_main_vol_r = 6;
1478 decoder->audio_main_bass = 0;
1479 decoder->audio_main_treble = 0;
1480 decoder->audio_main_mute = 0;
1481 decoder->audio_main_balance = 32768;
1482 /* normalize (24 to -40 (not -84) -> 65535 to 0) */
1483 decoder->audio_main_volume =
1484 (decoder->audio_main_vol_r + 41) * 65535 / (24 - (-40));
1485
1486 v4l_dbg(1, debug, client, "writing init values\n");
1487
1488 /* FIXME!! */
1489 saa717x_write_regs(client, reg_init_initialize);
1490 set_video_output_level_regs(client, decoder);
1491 /* set bass,treble to 0db 20041101 K.Ohta */
1492 decoder->audio_main_bass = 0;
1493 decoder->audio_main_treble = 0;
1494 set_audio_regs(client, decoder);
1495
1496 set_current_state(TASK_INTERRUPTIBLE);
1497 schedule_timeout(2*HZ);
1498 return 0;
1499}
1500
1501static int saa717x_remove(struct i2c_client *client)
1502{
1503 kfree(i2c_get_clientdata(client));
1504 return 0;
1505}
1506
1507/* ----------------------------------------------------------------------- */
1508
1509static struct v4l2_i2c_driver_data v4l2_i2c_data = {
1510 .name = "saa717x",
1511 .driverid = I2C_DRIVERID_SAA717X,
1512 .command = saa717x_command,
1513 .probe = saa717x_probe,
1514 .remove = saa717x_remove,
1515 .legacy_class = I2C_CLASS_TV_ANALOG | I2C_CLASS_TV_DIGITAL,
1516};
diff --git a/drivers/media/video/saa7185.c b/drivers/media/video/saa7185.c
index 41f70440fd3b..02fda4eecea3 100644
--- a/drivers/media/video/saa7185.c
+++ b/drivers/media/video/saa7185.c
@@ -52,7 +52,7 @@ MODULE_LICENSE("GPL");
52#define I2C_NAME(s) (s)->name 52#define I2C_NAME(s) (s)->name
53 53
54 54
55static int debug = 0; 55static int debug;
56module_param(debug, int, 0); 56module_param(debug, int, 0);
57MODULE_PARM_DESC(debug, "Debug level (0-1)"); 57MODULE_PARM_DESC(debug, "Debug level (0-1)");
58 58
diff --git a/drivers/media/video/se401.c b/drivers/media/video/se401.c
index d5d7d6cf734a..1cd629380f71 100644
--- a/drivers/media/video/se401.c
+++ b/drivers/media/video/se401.c
@@ -35,7 +35,7 @@ static const char version[] = "0.24";
35#include <linux/usb.h> 35#include <linux/usb.h>
36#include "se401.h" 36#include "se401.h"
37 37
38static int flickerless=0; 38static int flickerless;
39static int video_nr = -1; 39static int video_nr = -1;
40 40
41static struct usb_device_id device_table [] = { 41static struct usb_device_id device_table [] = {
@@ -300,10 +300,10 @@ static void se401_button_irq(struct urb *urb)
300 case -ENOENT: 300 case -ENOENT:
301 case -ESHUTDOWN: 301 case -ESHUTDOWN:
302 /* this urb is terminated, clean up */ 302 /* this urb is terminated, clean up */
303 dbg("%s - urb shutting down with status: %d", __FUNCTION__, urb->status); 303 dbg("%s - urb shutting down with status: %d", __func__, urb->status);
304 return; 304 return;
305 default: 305 default:
306 dbg("%s - nonzero urb status received: %d", __FUNCTION__, urb->status); 306 dbg("%s - nonzero urb status received: %d", __func__, urb->status);
307 goto exit; 307 goto exit;
308 } 308 }
309 309
@@ -315,7 +315,7 @@ exit:
315 status = usb_submit_urb (urb, GFP_ATOMIC); 315 status = usb_submit_urb (urb, GFP_ATOMIC);
316 if (status) 316 if (status)
317 err ("%s - usb_submit_urb failed with result %d", 317 err ("%s - usb_submit_urb failed with result %d",
318 __FUNCTION__, status); 318 __func__, status);
319} 319}
320 320
321static void se401_video_irq(struct urb *urb) 321static void se401_video_irq(struct urb *urb)
@@ -1224,7 +1224,9 @@ static const struct file_operations se401_fops = {
1224 .read = se401_read, 1224 .read = se401_read,
1225 .mmap = se401_mmap, 1225 .mmap = se401_mmap,
1226 .ioctl = se401_ioctl, 1226 .ioctl = se401_ioctl,
1227#ifdef CONFIG_COMPAT
1227 .compat_ioctl = v4l_compat_ioctl32, 1228 .compat_ioctl = v4l_compat_ioctl32,
1229#endif
1228 .llseek = no_llseek, 1230 .llseek = no_llseek,
1229}; 1231};
1230static struct video_device se401_template = { 1232static struct video_device se401_template = {
@@ -1279,7 +1281,7 @@ static int se401_init(struct usb_se401 *se401, int button)
1279 rc=se401_sndctrl(0, se401, SE401_REQ_GET_HEIGHT, 0, cp, sizeof(cp)); 1281 rc=se401_sndctrl(0, se401, SE401_REQ_GET_HEIGHT, 0, cp, sizeof(cp));
1280 se401->cheight=cp[0]+cp[1]*256; 1282 se401->cheight=cp[0]+cp[1]*256;
1281 1283
1282 if (!cp[2] && SE401_FORMAT_BAYER) { 1284 if (!(cp[2] & SE401_FORMAT_BAYER)) {
1283 err("Bayer format not supported!"); 1285 err("Bayer format not supported!");
1284 return 1; 1286 return 1;
1285 } 1287 }
diff --git a/drivers/media/video/sn9c102/sn9c102.h b/drivers/media/video/sn9c102/sn9c102.h
index 2e3c3de793a7..0c8d87d8d18d 100644
--- a/drivers/media/video/sn9c102/sn9c102.h
+++ b/drivers/media/video/sn9c102/sn9c102.h
@@ -176,7 +176,7 @@ do { \
176 dev_info(&cam->usbdev->dev, fmt "\n", ## args); \ 176 dev_info(&cam->usbdev->dev, fmt "\n", ## args); \
177 else if ((level) >= 3) \ 177 else if ((level) >= 3) \
178 dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \ 178 dev_info(&cam->usbdev->dev, "[%s:%d] " fmt "\n", \
179 __FUNCTION__, __LINE__ , ## args); \ 179 __func__, __LINE__ , ## args); \
180 } \ 180 } \
181} while (0) 181} while (0)
182# define V4LDBG(level, name, cmd) \ 182# define V4LDBG(level, name, cmd) \
@@ -191,7 +191,7 @@ do { \
191 pr_info("sn9c102: " fmt "\n", ## args); \ 191 pr_info("sn9c102: " fmt "\n", ## args); \
192 else if ((level) == 3) \ 192 else if ((level) == 3) \
193 pr_debug("sn9c102: [%s:%d] " fmt "\n", \ 193 pr_debug("sn9c102: [%s:%d] " fmt "\n", \
194 __FUNCTION__, __LINE__ , ## args); \ 194 __func__, __LINE__ , ## args); \
195 } \ 195 } \
196} while (0) 196} while (0)
197#else 197#else
@@ -202,7 +202,7 @@ do { \
202 202
203#undef PDBG 203#undef PDBG
204#define PDBG(fmt, args...) \ 204#define PDBG(fmt, args...) \
205dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n", __FILE__, __FUNCTION__, \ 205dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n", __FILE__, __func__, \
206 __LINE__ , ## args) 206 __LINE__ , ## args)
207 207
208#undef PDBGG 208#undef PDBGG
diff --git a/drivers/media/video/sn9c102/sn9c102_core.c b/drivers/media/video/sn9c102/sn9c102_core.c
index c40ba3adab21..5748b1e1a128 100644
--- a/drivers/media/video/sn9c102/sn9c102_core.c
+++ b/drivers/media/video/sn9c102/sn9c102_core.c
@@ -464,9 +464,9 @@ sn9c102_i2c_try_read(struct sn9c102_device* cam,
464} 464}
465 465
466 466
467int 467static int sn9c102_i2c_try_write(struct sn9c102_device* cam,
468sn9c102_i2c_try_write(struct sn9c102_device* cam, 468 const struct sn9c102_sensor* sensor,
469 const struct sn9c102_sensor* sensor, u8 address, u8 value) 469 u8 address, u8 value)
470{ 470{
471 return sn9c102_i2c_try_raw_write(cam, sensor, 3, 471 return sn9c102_i2c_try_raw_write(cam, sensor, 3,
472 sensor->i2c_slave_id, address, 472 sensor->i2c_slave_id, address,
@@ -528,7 +528,7 @@ sn9c102_find_sof_header(struct sn9c102_device* cam, void* mem, size_t len)
528 528
529 /* Search for the SOF marker (fixed part) in the header */ 529 /* Search for the SOF marker (fixed part) in the header */
530 for (j = 0, b=cam->sof.bytesread; j+b < sizeof(marker); j++) { 530 for (j = 0, b=cam->sof.bytesread; j+b < sizeof(marker); j++) {
531 if (unlikely(i+j) == len) 531 if (unlikely(i+j == len))
532 return NULL; 532 return NULL;
533 if (*(m+i+j) == marker[cam->sof.bytesread]) { 533 if (*(m+i+j) == marker[cam->sof.bytesread]) {
534 cam->sof.header[cam->sof.bytesread] = *(m+i+j); 534 cam->sof.header[cam->sof.bytesread] = *(m+i+j);
@@ -3224,7 +3224,9 @@ static const struct file_operations sn9c102_fops = {
3224 .open = sn9c102_open, 3224 .open = sn9c102_open,
3225 .release = sn9c102_release, 3225 .release = sn9c102_release,
3226 .ioctl = sn9c102_ioctl, 3226 .ioctl = sn9c102_ioctl,
3227#ifdef CONFIG_COMPAT
3227 .compat_ioctl = v4l_compat_ioctl32, 3228 .compat_ioctl = v4l_compat_ioctl32,
3229#endif
3228 .read = sn9c102_read, 3230 .read = sn9c102_read,
3229 .poll = sn9c102_poll, 3231 .poll = sn9c102_poll,
3230 .mmap = sn9c102_mmap, 3232 .mmap = sn9c102_mmap,
@@ -3239,7 +3241,7 @@ sn9c102_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3239{ 3241{
3240 struct usb_device *udev = interface_to_usbdev(intf); 3242 struct usb_device *udev = interface_to_usbdev(intf);
3241 struct sn9c102_device* cam; 3243 struct sn9c102_device* cam;
3242 static unsigned int dev_nr = 0; 3244 static unsigned int dev_nr;
3243 unsigned int i; 3245 unsigned int i;
3244 int err = 0, r; 3246 int err = 0, r;
3245 3247
diff --git a/drivers/media/video/sn9c102/sn9c102_sensor.h b/drivers/media/video/sn9c102/sn9c102_sensor.h
index 2dc7c6869484..4af7382da5c5 100644
--- a/drivers/media/video/sn9c102/sn9c102_sensor.h
+++ b/drivers/media/video/sn9c102/sn9c102_sensor.h
@@ -85,9 +85,6 @@ sn9c102_attach_sensor(struct sn9c102_device* cam,
85*/ 85*/
86 86
87/* The "try" I2C I/O versions are used when probing the sensor */ 87/* The "try" I2C I/O versions are used when probing the sensor */
88extern int sn9c102_i2c_try_write(struct sn9c102_device*,
89 const struct sn9c102_sensor*, u8 address,
90 u8 value);
91extern int sn9c102_i2c_try_read(struct sn9c102_device*, 88extern int sn9c102_i2c_try_read(struct sn9c102_device*,
92 const struct sn9c102_sensor*, u8 address); 89 const struct sn9c102_sensor*, u8 address);
93 90
diff --git a/drivers/media/video/soc_camera.c b/drivers/media/video/soc_camera.c
new file mode 100644
index 000000000000..a1b92446c8b4
--- /dev/null
+++ b/drivers/media/video/soc_camera.c
@@ -0,0 +1,1031 @@
1/*
2 * camera image capture (abstract) bus driver
3 *
4 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
5 *
6 * This driver provides an interface between platform-specific camera
7 * busses and camera devices. It should be used if the camera is
8 * connected not over a "proper" bus like PCI or USB, but over a
9 * special bus, like, for example, the Quick Capture interface on PXA270
10 * SoCs. Later it should also be used for i.MX31 SoCs from Freescale.
11 * It can handle multiple cameras and / or multiple busses, which can
12 * be used, e.g., in stereo-vision applications.
13 *
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License version 2 as
16 * published by the Free Software Foundation.
17 */
18
19#include <linux/module.h>
20#include <linux/init.h>
21#include <linux/device.h>
22#include <linux/list.h>
23#include <linux/err.h>
24#include <linux/mutex.h>
25#include <linux/vmalloc.h>
26
27#include <media/v4l2-common.h>
28#include <media/v4l2-dev.h>
29#include <media/soc_camera.h>
30
31static LIST_HEAD(hosts);
32static LIST_HEAD(devices);
33static DEFINE_MUTEX(list_lock);
34static DEFINE_MUTEX(video_lock);
35
36const static struct soc_camera_data_format*
37format_by_fourcc(struct soc_camera_device *icd, unsigned int fourcc)
38{
39 unsigned int i;
40
41 for (i = 0; i < icd->num_formats; i++)
42 if (icd->formats[i].fourcc == fourcc)
43 return icd->formats + i;
44 return NULL;
45}
46
47static int soc_camera_try_fmt_cap(struct file *file, void *priv,
48 struct v4l2_format *f)
49{
50 struct soc_camera_file *icf = file->private_data;
51 struct soc_camera_device *icd = icf->icd;
52 struct soc_camera_host *ici =
53 to_soc_camera_host(icd->dev.parent);
54 enum v4l2_field field;
55 const struct soc_camera_data_format *fmt;
56 int ret;
57
58 WARN_ON(priv != file->private_data);
59
60 fmt = format_by_fourcc(icd, f->fmt.pix.pixelformat);
61 if (!fmt) {
62 dev_dbg(&icd->dev, "invalid format 0x%08x\n",
63 f->fmt.pix.pixelformat);
64 return -EINVAL;
65 }
66
67 dev_dbg(&icd->dev, "fmt: 0x%08x\n", fmt->fourcc);
68
69 field = f->fmt.pix.field;
70
71 if (field == V4L2_FIELD_ANY) {
72 field = V4L2_FIELD_NONE;
73 } else if (V4L2_FIELD_NONE != field) {
74 dev_err(&icd->dev, "Field type invalid.\n");
75 return -EINVAL;
76 }
77
78 /* test physical bus parameters */
79 ret = ici->ops->try_bus_param(icd, f->fmt.pix.pixelformat);
80 if (ret)
81 return ret;
82
83 /* limit format to hardware capabilities */
84 ret = ici->ops->try_fmt_cap(icd, f);
85
86 /* calculate missing fields */
87 f->fmt.pix.field = field;
88 f->fmt.pix.bytesperline =
89 (f->fmt.pix.width * fmt->depth) >> 3;
90 f->fmt.pix.sizeimage =
91 f->fmt.pix.height * f->fmt.pix.bytesperline;
92
93 return ret;
94}
95
96static int soc_camera_enum_input(struct file *file, void *priv,
97 struct v4l2_input *inp)
98{
99 if (inp->index != 0)
100 return -EINVAL;
101
102 inp->type = V4L2_INPUT_TYPE_CAMERA;
103 inp->std = V4L2_STD_UNKNOWN;
104 strcpy(inp->name, "Camera");
105
106 return 0;
107}
108
109static int soc_camera_g_input(struct file *file, void *priv, unsigned int *i)
110{
111 *i = 0;
112
113 return 0;
114}
115
116static int soc_camera_s_input(struct file *file, void *priv, unsigned int i)
117{
118 if (i > 0)
119 return -EINVAL;
120
121 return 0;
122}
123
124static int soc_camera_s_std(struct file *file, void *priv, v4l2_std_id *a)
125{
126 return 0;
127}
128
129static int soc_camera_reqbufs(struct file *file, void *priv,
130 struct v4l2_requestbuffers *p)
131{
132 int ret;
133 struct soc_camera_file *icf = file->private_data;
134 struct soc_camera_device *icd = icf->icd;
135 struct soc_camera_host *ici =
136 to_soc_camera_host(icd->dev.parent);
137
138 WARN_ON(priv != file->private_data);
139
140 dev_dbg(&icd->dev, "%s: %d\n", __func__, p->memory);
141
142 ret = videobuf_reqbufs(&icf->vb_vidq, p);
143 if (ret < 0)
144 return ret;
145
146 return ici->ops->reqbufs(icf, p);
147}
148
149static int soc_camera_querybuf(struct file *file, void *priv,
150 struct v4l2_buffer *p)
151{
152 struct soc_camera_file *icf = file->private_data;
153
154 WARN_ON(priv != file->private_data);
155
156 return videobuf_querybuf(&icf->vb_vidq, p);
157}
158
159static int soc_camera_qbuf(struct file *file, void *priv,
160 struct v4l2_buffer *p)
161{
162 struct soc_camera_file *icf = file->private_data;
163
164 WARN_ON(priv != file->private_data);
165
166 return videobuf_qbuf(&icf->vb_vidq, p);
167}
168
169static int soc_camera_dqbuf(struct file *file, void *priv,
170 struct v4l2_buffer *p)
171{
172 struct soc_camera_file *icf = file->private_data;
173
174 WARN_ON(priv != file->private_data);
175
176 return videobuf_dqbuf(&icf->vb_vidq, p, file->f_flags & O_NONBLOCK);
177}
178
179static int soc_camera_open(struct inode *inode, struct file *file)
180{
181 struct video_device *vdev;
182 struct soc_camera_device *icd;
183 struct soc_camera_host *ici;
184 struct soc_camera_file *icf;
185 spinlock_t *lock;
186 int ret;
187
188 icf = vmalloc(sizeof(*icf));
189 if (!icf)
190 return -ENOMEM;
191
192 /* Protect against icd->remove() until we module_get() both drivers. */
193 mutex_lock(&video_lock);
194
195 vdev = video_devdata(file);
196 icd = container_of(vdev->dev, struct soc_camera_device, dev);
197 ici = to_soc_camera_host(icd->dev.parent);
198
199 if (!try_module_get(icd->ops->owner)) {
200 dev_err(&icd->dev, "Couldn't lock sensor driver.\n");
201 ret = -EINVAL;
202 goto emgd;
203 }
204
205 if (!try_module_get(ici->ops->owner)) {
206 dev_err(&icd->dev, "Couldn't lock capture bus driver.\n");
207 ret = -EINVAL;
208 goto emgi;
209 }
210
211 icf->icd = icd;
212
213 icf->lock = ici->ops->spinlock_alloc(icf);
214 if (!icf->lock) {
215 ret = -ENOMEM;
216 goto esla;
217 }
218
219 icd->use_count++;
220
221 /* Now we really have to activate the camera */
222 if (icd->use_count == 1) {
223 ret = ici->ops->add(icd);
224 if (ret < 0) {
225 dev_err(&icd->dev, "Couldn't activate the camera: %d\n", ret);
226 icd->use_count--;
227 goto eiciadd;
228 }
229 }
230
231 mutex_unlock(&video_lock);
232
233 file->private_data = icf;
234 dev_dbg(&icd->dev, "camera device open\n");
235
236 /* We must pass NULL as dev pointer, then all pci_* dma operations
237 * transform to normal dma_* ones. */
238 videobuf_queue_sg_init(&icf->vb_vidq, ici->vbq_ops, NULL, icf->lock,
239 V4L2_BUF_TYPE_VIDEO_CAPTURE, V4L2_FIELD_NONE,
240 ici->msize, icd);
241
242 return 0;
243
244 /* All errors are entered with the video_lock held */
245eiciadd:
246 lock = icf->lock;
247 icf->lock = NULL;
248 if (ici->ops->spinlock_free)
249 ici->ops->spinlock_free(lock);
250esla:
251 module_put(ici->ops->owner);
252emgi:
253 module_put(icd->ops->owner);
254emgd:
255 mutex_unlock(&video_lock);
256 vfree(icf);
257 return ret;
258}
259
260static int soc_camera_close(struct inode *inode, struct file *file)
261{
262 struct soc_camera_file *icf = file->private_data;
263 struct soc_camera_device *icd = icf->icd;
264 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
265 struct video_device *vdev = icd->vdev;
266 spinlock_t *lock = icf->lock;
267
268 mutex_lock(&video_lock);
269 icd->use_count--;
270 if (!icd->use_count)
271 ici->ops->remove(icd);
272 icf->lock = NULL;
273 if (ici->ops->spinlock_free)
274 ici->ops->spinlock_free(lock);
275 module_put(icd->ops->owner);
276 module_put(ici->ops->owner);
277 mutex_unlock(&video_lock);
278
279 vfree(icf);
280
281 dev_dbg(vdev->dev, "camera device close\n");
282
283 return 0;
284}
285
286static ssize_t soc_camera_read(struct file *file, char __user *buf,
287 size_t count, loff_t *ppos)
288{
289 struct soc_camera_file *icf = file->private_data;
290 struct soc_camera_device *icd = icf->icd;
291 struct video_device *vdev = icd->vdev;
292 int err = -EINVAL;
293
294 dev_err(vdev->dev, "camera device read not implemented\n");
295
296 return err;
297}
298
299static int soc_camera_mmap(struct file *file, struct vm_area_struct *vma)
300{
301 struct soc_camera_file *icf = file->private_data;
302 struct soc_camera_device *icd = icf->icd;
303 int err;
304
305 dev_dbg(&icd->dev, "mmap called, vma=0x%08lx\n", (unsigned long)vma);
306
307 err = videobuf_mmap_mapper(&icf->vb_vidq, vma);
308
309 dev_dbg(&icd->dev, "vma start=0x%08lx, size=%ld, ret=%d\n",
310 (unsigned long)vma->vm_start,
311 (unsigned long)vma->vm_end - (unsigned long)vma->vm_start,
312 err);
313
314 return err;
315}
316
317static unsigned int soc_camera_poll(struct file *file, poll_table *pt)
318{
319 struct soc_camera_file *icf = file->private_data;
320 struct soc_camera_device *icd = icf->icd;
321 struct soc_camera_host *ici =
322 to_soc_camera_host(icd->dev.parent);
323
324 if (list_empty(&icf->vb_vidq.stream)) {
325 dev_err(&icd->dev, "Trying to poll with no queued buffers!\n");
326 return POLLERR;
327 }
328
329 return ici->ops->poll(file, pt);
330}
331
332
333static struct file_operations soc_camera_fops = {
334 .owner = THIS_MODULE,
335 .open = soc_camera_open,
336 .release = soc_camera_close,
337 .ioctl = video_ioctl2,
338 .read = soc_camera_read,
339 .mmap = soc_camera_mmap,
340 .poll = soc_camera_poll,
341 .llseek = no_llseek,
342};
343
344
345static int soc_camera_s_fmt_cap(struct file *file, void *priv,
346 struct v4l2_format *f)
347{
348 struct soc_camera_file *icf = file->private_data;
349 struct soc_camera_device *icd = icf->icd;
350 struct soc_camera_host *ici =
351 to_soc_camera_host(icd->dev.parent);
352 int ret;
353 struct v4l2_rect rect;
354 const static struct soc_camera_data_format *data_fmt;
355
356 WARN_ON(priv != file->private_data);
357
358 data_fmt = format_by_fourcc(icd, f->fmt.pix.pixelformat);
359 if (!data_fmt)
360 return -EINVAL;
361
362 /* buswidth may be further adjusted by the ici */
363 icd->buswidth = data_fmt->depth;
364
365 ret = soc_camera_try_fmt_cap(file, icf, f);
366 if (ret < 0)
367 return ret;
368
369 rect.left = icd->x_current;
370 rect.top = icd->y_current;
371 rect.width = f->fmt.pix.width;
372 rect.height = f->fmt.pix.height;
373 ret = ici->ops->set_fmt_cap(icd, f->fmt.pix.pixelformat, &rect);
374 if (ret < 0)
375 return ret;
376
377 icd->current_fmt = data_fmt;
378 icd->width = rect.width;
379 icd->height = rect.height;
380 icf->vb_vidq.field = f->fmt.pix.field;
381 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != f->type)
382 dev_warn(&icd->dev, "Attention! Wrong buf-type %d\n",
383 f->type);
384
385 dev_dbg(&icd->dev, "set width: %d height: %d\n",
386 icd->width, icd->height);
387
388 /* set physical bus parameters */
389 return ici->ops->set_bus_param(icd, f->fmt.pix.pixelformat);
390}
391
392static int soc_camera_enum_fmt_cap(struct file *file, void *priv,
393 struct v4l2_fmtdesc *f)
394{
395 struct soc_camera_file *icf = file->private_data;
396 struct soc_camera_device *icd = icf->icd;
397 const struct soc_camera_data_format *format;
398
399 WARN_ON(priv != file->private_data);
400
401 if (f->index >= icd->num_formats)
402 return -EINVAL;
403
404 format = &icd->formats[f->index];
405
406 strlcpy(f->description, format->name, sizeof(f->description));
407 f->pixelformat = format->fourcc;
408 return 0;
409}
410
411static int soc_camera_g_fmt_cap(struct file *file, void *priv,
412 struct v4l2_format *f)
413{
414 struct soc_camera_file *icf = file->private_data;
415 struct soc_camera_device *icd = icf->icd;
416
417 WARN_ON(priv != file->private_data);
418
419 f->fmt.pix.width = icd->width;
420 f->fmt.pix.height = icd->height;
421 f->fmt.pix.field = icf->vb_vidq.field;
422 f->fmt.pix.pixelformat = icd->current_fmt->fourcc;
423 f->fmt.pix.bytesperline =
424 (f->fmt.pix.width * icd->current_fmt->depth) >> 3;
425 f->fmt.pix.sizeimage =
426 f->fmt.pix.height * f->fmt.pix.bytesperline;
427 dev_dbg(&icd->dev, "current_fmt->fourcc: 0x%08x\n",
428 icd->current_fmt->fourcc);
429 return 0;
430}
431
432static int soc_camera_querycap(struct file *file, void *priv,
433 struct v4l2_capability *cap)
434{
435 struct soc_camera_file *icf = file->private_data;
436 struct soc_camera_device *icd = icf->icd;
437 struct soc_camera_host *ici =
438 to_soc_camera_host(icd->dev.parent);
439
440 WARN_ON(priv != file->private_data);
441
442 strlcpy(cap->driver, ici->drv_name, sizeof(cap->driver));
443 return ici->ops->querycap(ici, cap);
444}
445
446static int soc_camera_streamon(struct file *file, void *priv,
447 enum v4l2_buf_type i)
448{
449 struct soc_camera_file *icf = file->private_data;
450 struct soc_camera_device *icd = icf->icd;
451
452 WARN_ON(priv != file->private_data);
453
454 dev_dbg(&icd->dev, "%s\n", __func__);
455
456 if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
457 return -EINVAL;
458
459 icd->ops->start_capture(icd);
460
461 /* This calls buf_queue from host driver's videobuf_queue_ops */
462 return videobuf_streamon(&icf->vb_vidq);
463}
464
465static int soc_camera_streamoff(struct file *file, void *priv,
466 enum v4l2_buf_type i)
467{
468 struct soc_camera_file *icf = file->private_data;
469 struct soc_camera_device *icd = icf->icd;
470
471 WARN_ON(priv != file->private_data);
472
473 dev_dbg(&icd->dev, "%s\n", __func__);
474
475 if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
476 return -EINVAL;
477
478 /* This calls buf_release from host driver's videobuf_queue_ops for all
479 * remaining buffers. When the last buffer is freed, stop capture */
480 videobuf_streamoff(&icf->vb_vidq);
481
482 icd->ops->stop_capture(icd);
483
484 return 0;
485}
486
487static int soc_camera_queryctrl(struct file *file, void *priv,
488 struct v4l2_queryctrl *qc)
489{
490 struct soc_camera_file *icf = file->private_data;
491 struct soc_camera_device *icd = icf->icd;
492 int i;
493
494 WARN_ON(priv != file->private_data);
495
496 if (!qc->id)
497 return -EINVAL;
498
499 for (i = 0; i < icd->ops->num_controls; i++)
500 if (qc->id == icd->ops->controls[i].id) {
501 memcpy(qc, &(icd->ops->controls[i]),
502 sizeof(*qc));
503 return 0;
504 }
505
506 return -EINVAL;
507}
508
509static int soc_camera_g_ctrl(struct file *file, void *priv,
510 struct v4l2_control *ctrl)
511{
512 struct soc_camera_file *icf = file->private_data;
513 struct soc_camera_device *icd = icf->icd;
514
515 WARN_ON(priv != file->private_data);
516
517 switch (ctrl->id) {
518 case V4L2_CID_GAIN:
519 if (icd->gain == (unsigned short)~0)
520 return -EINVAL;
521 ctrl->value = icd->gain;
522 return 0;
523 case V4L2_CID_EXPOSURE:
524 if (icd->exposure == (unsigned short)~0)
525 return -EINVAL;
526 ctrl->value = icd->exposure;
527 return 0;
528 }
529
530 if (icd->ops->get_control)
531 return icd->ops->get_control(icd, ctrl);
532 return -EINVAL;
533}
534
535static int soc_camera_s_ctrl(struct file *file, void *priv,
536 struct v4l2_control *ctrl)
537{
538 struct soc_camera_file *icf = file->private_data;
539 struct soc_camera_device *icd = icf->icd;
540
541 WARN_ON(priv != file->private_data);
542
543 if (icd->ops->set_control)
544 return icd->ops->set_control(icd, ctrl);
545 return -EINVAL;
546}
547
548static int soc_camera_cropcap(struct file *file, void *fh,
549 struct v4l2_cropcap *a)
550{
551 struct soc_camera_file *icf = file->private_data;
552 struct soc_camera_device *icd = icf->icd;
553
554 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
555 a->bounds.left = icd->x_min;
556 a->bounds.top = icd->y_min;
557 a->bounds.width = icd->width_max;
558 a->bounds.height = icd->height_max;
559 a->defrect.left = icd->x_min;
560 a->defrect.top = icd->y_min;
561 a->defrect.width = 640;
562 a->defrect.height = 480;
563 a->pixelaspect.numerator = 1;
564 a->pixelaspect.denominator = 1;
565
566 return 0;
567}
568
569static int soc_camera_g_crop(struct file *file, void *fh,
570 struct v4l2_crop *a)
571{
572 struct soc_camera_file *icf = file->private_data;
573 struct soc_camera_device *icd = icf->icd;
574
575 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
576 a->c.left = icd->x_current;
577 a->c.top = icd->y_current;
578 a->c.width = icd->width;
579 a->c.height = icd->height;
580
581 return 0;
582}
583
584static int soc_camera_s_crop(struct file *file, void *fh,
585 struct v4l2_crop *a)
586{
587 struct soc_camera_file *icf = file->private_data;
588 struct soc_camera_device *icd = icf->icd;
589 struct soc_camera_host *ici =
590 to_soc_camera_host(icd->dev.parent);
591 int ret;
592
593 if (a->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
594 return -EINVAL;
595
596 ret = ici->ops->set_fmt_cap(icd, 0, &a->c);
597 if (!ret) {
598 icd->width = a->c.width;
599 icd->height = a->c.height;
600 icd->x_current = a->c.left;
601 icd->y_current = a->c.top;
602 }
603
604 return ret;
605}
606
607static int soc_camera_g_chip_ident(struct file *file, void *fh,
608 struct v4l2_chip_ident *id)
609{
610 struct soc_camera_file *icf = file->private_data;
611 struct soc_camera_device *icd = icf->icd;
612
613 if (!icd->ops->get_chip_id)
614 return -EINVAL;
615
616 return icd->ops->get_chip_id(icd, id);
617}
618
619#ifdef CONFIG_VIDEO_ADV_DEBUG
620static int soc_camera_g_register(struct file *file, void *fh,
621 struct v4l2_register *reg)
622{
623 struct soc_camera_file *icf = file->private_data;
624 struct soc_camera_device *icd = icf->icd;
625
626 if (!icd->ops->get_register)
627 return -EINVAL;
628
629 return icd->ops->get_register(icd, reg);
630}
631
632static int soc_camera_s_register(struct file *file, void *fh,
633 struct v4l2_register *reg)
634{
635 struct soc_camera_file *icf = file->private_data;
636 struct soc_camera_device *icd = icf->icd;
637
638 if (!icd->ops->set_register)
639 return -EINVAL;
640
641 return icd->ops->set_register(icd, reg);
642}
643#endif
644
645static int device_register_link(struct soc_camera_device *icd)
646{
647 int ret = device_register(&icd->dev);
648
649 if (ret < 0) {
650 /* Prevent calling device_unregister() */
651 icd->dev.parent = NULL;
652 dev_err(&icd->dev, "Cannot register device: %d\n", ret);
653 /* Even if probe() was unsuccessful for all registered drivers,
654 * device_register() returns 0, and we add the link, just to
655 * document this camera's control device */
656 } else if (icd->control)
657 /* Have to sysfs_remove_link() before device_unregister()? */
658 if (sysfs_create_link(&icd->dev.kobj, &icd->control->kobj,
659 "control"))
660 dev_warn(&icd->dev,
661 "Failed creating the control symlink\n");
662 return ret;
663}
664
665/* So far this function cannot fail */
666static void scan_add_host(struct soc_camera_host *ici)
667{
668 struct soc_camera_device *icd;
669
670 mutex_lock(&list_lock);
671
672 list_for_each_entry(icd, &devices, list) {
673 if (icd->iface == ici->nr) {
674 icd->dev.parent = &ici->dev;
675 device_register_link(icd);
676 }
677 }
678
679 mutex_unlock(&list_lock);
680}
681
682/* return: 0 if no match found or a match found and
683 * device_register() successful, error code otherwise */
684static int scan_add_device(struct soc_camera_device *icd)
685{
686 struct soc_camera_host *ici;
687 int ret = 0;
688
689 mutex_lock(&list_lock);
690
691 list_add_tail(&icd->list, &devices);
692
693 /* Watch out for class_for_each_device / class_find_device API by
694 * Dave Young <hidave.darkstar@gmail.com> */
695 list_for_each_entry(ici, &hosts, list) {
696 if (icd->iface == ici->nr) {
697 ret = 1;
698 icd->dev.parent = &ici->dev;
699 break;
700 }
701 }
702
703 mutex_unlock(&list_lock);
704
705 if (ret)
706 ret = device_register_link(icd);
707
708 return ret;
709}
710
711static int soc_camera_probe(struct device *dev)
712{
713 struct soc_camera_device *icd = to_soc_camera_dev(dev);
714 struct soc_camera_host *ici =
715 to_soc_camera_host(icd->dev.parent);
716 int ret;
717
718 if (!icd->ops->probe)
719 return -ENODEV;
720
721 /* We only call ->add() here to activate and probe the camera.
722 * We shall ->remove() and deactivate it immediately afterwards. */
723 ret = ici->ops->add(icd);
724 if (ret < 0)
725 return ret;
726
727 ret = icd->ops->probe(icd);
728 if (ret >= 0) {
729 const struct v4l2_queryctrl *qctrl;
730
731 qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_GAIN);
732 icd->gain = qctrl ? qctrl->default_value : (unsigned short)~0;
733 qctrl = soc_camera_find_qctrl(icd->ops, V4L2_CID_EXPOSURE);
734 icd->exposure = qctrl ? qctrl->default_value :
735 (unsigned short)~0;
736 }
737 ici->ops->remove(icd);
738
739 return ret;
740}
741
742/* This is called on device_unregister, which only means we have to disconnect
743 * from the host, but not remove ourselves from the device list */
744static int soc_camera_remove(struct device *dev)
745{
746 struct soc_camera_device *icd = to_soc_camera_dev(dev);
747
748 if (icd->ops->remove)
749 icd->ops->remove(icd);
750
751 return 0;
752}
753
754static struct bus_type soc_camera_bus_type = {
755 .name = "soc-camera",
756 .probe = soc_camera_probe,
757 .remove = soc_camera_remove,
758};
759
760static struct device_driver ic_drv = {
761 .name = "camera",
762 .bus = &soc_camera_bus_type,
763 .owner = THIS_MODULE,
764};
765
766/*
767 * Image capture host - this is a host device, not a bus device, so,
768 * no bus reference, no probing.
769 */
770static struct class soc_camera_host_class = {
771 .owner = THIS_MODULE,
772 .name = "camera_host",
773};
774
775static void dummy_release(struct device *dev)
776{
777}
778
779static spinlock_t *spinlock_alloc(struct soc_camera_file *icf)
780{
781 spinlock_t *lock = kmalloc(sizeof(spinlock_t), GFP_KERNEL);
782
783 if (lock)
784 spin_lock_init(lock);
785
786 return lock;
787}
788
789static void spinlock_free(spinlock_t *lock)
790{
791 kfree(lock);
792}
793
794int soc_camera_host_register(struct soc_camera_host *ici)
795{
796 int ret;
797 struct soc_camera_host *ix;
798
799 if (!ici->vbq_ops || !ici->ops->add || !ici->ops->remove)
800 return -EINVAL;
801
802 /* Number might be equal to the platform device ID */
803 sprintf(ici->dev.bus_id, "camera_host%d", ici->nr);
804 ici->dev.class = &soc_camera_host_class;
805
806 mutex_lock(&list_lock);
807 list_for_each_entry(ix, &hosts, list) {
808 if (ix->nr == ici->nr) {
809 mutex_unlock(&list_lock);
810 return -EBUSY;
811 }
812 }
813
814 list_add_tail(&ici->list, &hosts);
815 mutex_unlock(&list_lock);
816
817 ici->dev.release = dummy_release;
818
819 ret = device_register(&ici->dev);
820
821 if (ret)
822 goto edevr;
823
824 if (!ici->ops->spinlock_alloc) {
825 ici->ops->spinlock_alloc = spinlock_alloc;
826 ici->ops->spinlock_free = spinlock_free;
827 }
828
829 scan_add_host(ici);
830
831 return 0;
832
833edevr:
834 mutex_lock(&list_lock);
835 list_del(&ici->list);
836 mutex_unlock(&list_lock);
837
838 return ret;
839}
840EXPORT_SYMBOL(soc_camera_host_register);
841
842/* Unregister all clients! */
843void soc_camera_host_unregister(struct soc_camera_host *ici)
844{
845 struct soc_camera_device *icd;
846
847 mutex_lock(&list_lock);
848
849 list_del(&ici->list);
850
851 list_for_each_entry(icd, &devices, list) {
852 if (icd->dev.parent == &ici->dev) {
853 device_unregister(&icd->dev);
854 /* Not before device_unregister(), .remove
855 * needs parent to call ici->ops->remove() */
856 icd->dev.parent = NULL;
857 memset(&icd->dev.kobj, 0, sizeof(icd->dev.kobj));
858 }
859 }
860
861 mutex_unlock(&list_lock);
862
863 device_unregister(&ici->dev);
864}
865EXPORT_SYMBOL(soc_camera_host_unregister);
866
867/* Image capture device */
868int soc_camera_device_register(struct soc_camera_device *icd)
869{
870 struct soc_camera_device *ix;
871 int num = -1, i;
872
873 if (!icd)
874 return -EINVAL;
875
876 for (i = 0; i < 256 && num < 0; i++) {
877 num = i;
878 list_for_each_entry(ix, &devices, list) {
879 if (ix->iface == icd->iface && ix->devnum == i) {
880 num = -1;
881 break;
882 }
883 }
884 }
885
886 if (num < 0)
887 /* ok, we have 256 cameras on this host...
888 * man, stay reasonable... */
889 return -ENOMEM;
890
891 icd->devnum = num;
892 icd->dev.bus = &soc_camera_bus_type;
893 snprintf(icd->dev.bus_id, sizeof(icd->dev.bus_id),
894 "%u-%u", icd->iface, icd->devnum);
895
896 icd->dev.release = dummy_release;
897
898 return scan_add_device(icd);
899}
900EXPORT_SYMBOL(soc_camera_device_register);
901
902void soc_camera_device_unregister(struct soc_camera_device *icd)
903{
904 mutex_lock(&list_lock);
905 list_del(&icd->list);
906
907 /* The bus->remove will be eventually called */
908 if (icd->dev.parent)
909 device_unregister(&icd->dev);
910 mutex_unlock(&list_lock);
911}
912EXPORT_SYMBOL(soc_camera_device_unregister);
913
914int soc_camera_video_start(struct soc_camera_device *icd)
915{
916 struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
917 int err = -ENOMEM;
918 struct video_device *vdev;
919
920 if (!icd->dev.parent)
921 return -ENODEV;
922
923 vdev = video_device_alloc();
924 if (!vdev)
925 goto evidallocd;
926 dev_dbg(&ici->dev, "Allocated video_device %p\n", vdev);
927
928 strlcpy(vdev->name, ici->drv_name, sizeof(vdev->name));
929 /* Maybe better &ici->dev */
930 vdev->dev = &icd->dev;
931 vdev->type = VID_TYPE_CAPTURE;
932 vdev->current_norm = V4L2_STD_UNKNOWN;
933 vdev->fops = &soc_camera_fops;
934 vdev->release = video_device_release;
935 vdev->minor = -1;
936 vdev->tvnorms = V4L2_STD_UNKNOWN,
937 vdev->vidioc_querycap = soc_camera_querycap;
938 vdev->vidioc_g_fmt_cap = soc_camera_g_fmt_cap;
939 vdev->vidioc_enum_fmt_cap = soc_camera_enum_fmt_cap;
940 vdev->vidioc_s_fmt_cap = soc_camera_s_fmt_cap;
941 vdev->vidioc_enum_input = soc_camera_enum_input;
942 vdev->vidioc_g_input = soc_camera_g_input;
943 vdev->vidioc_s_input = soc_camera_s_input;
944 vdev->vidioc_s_std = soc_camera_s_std;
945 vdev->vidioc_reqbufs = soc_camera_reqbufs;
946 vdev->vidioc_try_fmt_cap = soc_camera_try_fmt_cap;
947 vdev->vidioc_querybuf = soc_camera_querybuf;
948 vdev->vidioc_qbuf = soc_camera_qbuf;
949 vdev->vidioc_dqbuf = soc_camera_dqbuf;
950 vdev->vidioc_streamon = soc_camera_streamon;
951 vdev->vidioc_streamoff = soc_camera_streamoff;
952 vdev->vidioc_queryctrl = soc_camera_queryctrl;
953 vdev->vidioc_g_ctrl = soc_camera_g_ctrl;
954 vdev->vidioc_s_ctrl = soc_camera_s_ctrl;
955 vdev->vidioc_cropcap = soc_camera_cropcap;
956 vdev->vidioc_g_crop = soc_camera_g_crop;
957 vdev->vidioc_s_crop = soc_camera_s_crop;
958 vdev->vidioc_g_chip_ident = soc_camera_g_chip_ident;
959#ifdef CONFIG_VIDEO_ADV_DEBUG
960 vdev->vidioc_g_register = soc_camera_g_register;
961 vdev->vidioc_s_register = soc_camera_s_register;
962#endif
963
964 icd->current_fmt = &icd->formats[0];
965
966 err = video_register_device(vdev, VFL_TYPE_GRABBER, vdev->minor);
967 if (err < 0) {
968 dev_err(vdev->dev, "video_register_device failed\n");
969 goto evidregd;
970 }
971 icd->vdev = vdev;
972
973 return 0;
974
975evidregd:
976 video_device_release(vdev);
977evidallocd:
978 return err;
979}
980EXPORT_SYMBOL(soc_camera_video_start);
981
982void soc_camera_video_stop(struct soc_camera_device *icd)
983{
984 struct video_device *vdev = icd->vdev;
985
986 dev_dbg(&icd->dev, "%s\n", __func__);
987
988 if (!icd->dev.parent || !vdev)
989 return;
990
991 mutex_lock(&video_lock);
992 video_unregister_device(vdev);
993 icd->vdev = NULL;
994 mutex_unlock(&video_lock);
995}
996EXPORT_SYMBOL(soc_camera_video_stop);
997
998static int __init soc_camera_init(void)
999{
1000 int ret = bus_register(&soc_camera_bus_type);
1001 if (ret)
1002 return ret;
1003 ret = driver_register(&ic_drv);
1004 if (ret)
1005 goto edrvr;
1006 ret = class_register(&soc_camera_host_class);
1007 if (ret)
1008 goto eclr;
1009
1010 return 0;
1011
1012eclr:
1013 driver_unregister(&ic_drv);
1014edrvr:
1015 bus_unregister(&soc_camera_bus_type);
1016 return ret;
1017}
1018
1019static void __exit soc_camera_exit(void)
1020{
1021 class_unregister(&soc_camera_host_class);
1022 driver_unregister(&ic_drv);
1023 bus_unregister(&soc_camera_bus_type);
1024}
1025
1026module_init(soc_camera_init);
1027module_exit(soc_camera_exit);
1028
1029MODULE_DESCRIPTION("Image capture bus driver");
1030MODULE_AUTHOR("Guennadi Liakhovetski <kernel@pengutronix.de>");
1031MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/stk-webcam.c b/drivers/media/video/stk-webcam.c
index ceba45ad0294..9276ed997388 100644
--- a/drivers/media/video/stk-webcam.c
+++ b/drivers/media/video/stk-webcam.c
@@ -1100,7 +1100,7 @@ static int stk_setup_format(struct stk_camera *dev)
1100 && i < ARRAY_SIZE(stk_sizes)) 1100 && i < ARRAY_SIZE(stk_sizes))
1101 i++; 1101 i++;
1102 if (i == ARRAY_SIZE(stk_sizes)) { 1102 if (i == ARRAY_SIZE(stk_sizes)) {
1103 STK_ERROR("Something is broken in %s\n", __FUNCTION__); 1103 STK_ERROR("Something is broken in %s\n", __func__);
1104 return -EFAULT; 1104 return -EFAULT;
1105 } 1105 }
1106 /* This registers controls some timings, not sure of what. */ 1106 /* This registers controls some timings, not sure of what. */
@@ -1465,7 +1465,7 @@ static void stk_camera_disconnect(struct usb_interface *interface)
1465} 1465}
1466 1466
1467#ifdef CONFIG_PM 1467#ifdef CONFIG_PM
1468int stk_camera_suspend(struct usb_interface *intf, pm_message_t message) 1468static int stk_camera_suspend(struct usb_interface *intf, pm_message_t message)
1469{ 1469{
1470 struct stk_camera *dev = usb_get_intfdata(intf); 1470 struct stk_camera *dev = usb_get_intfdata(intf);
1471 if (is_streaming(dev)) { 1471 if (is_streaming(dev)) {
@@ -1476,7 +1476,7 @@ int stk_camera_suspend(struct usb_interface *intf, pm_message_t message)
1476 return 0; 1476 return 0;
1477} 1477}
1478 1478
1479int stk_camera_resume(struct usb_interface *intf) 1479static int stk_camera_resume(struct usb_interface *intf)
1480{ 1480{
1481 struct stk_camera *dev = usb_get_intfdata(intf); 1481 struct stk_camera *dev = usb_get_intfdata(intf);
1482 if (!is_initialised(dev)) 1482 if (!is_initialised(dev))
diff --git a/drivers/media/video/stradis.c b/drivers/media/video/stradis.c
index 3fb85af5d1f2..c109511f21ea 100644
--- a/drivers/media/video/stradis.c
+++ b/drivers/media/video/stradis.c
@@ -58,7 +58,7 @@
58 58
59static struct saa7146 saa7146s[SAA7146_MAX]; 59static struct saa7146 saa7146s[SAA7146_MAX];
60 60
61static int saa_num = 0; /* number of SAA7146s in use */ 61static int saa_num; /* number of SAA7146s in use */
62 62
63static int video_nr = -1; 63static int video_nr = -1;
64module_param(video_nr, int, 0); 64module_param(video_nr, int, 0);
@@ -248,7 +248,7 @@ static void I2CBusScan(struct saa7146 *saa)
248 attach_inform(saa, i); 248 attach_inform(saa, i);
249} 249}
250 250
251static int debiwait_maxwait = 0; 251static int debiwait_maxwait;
252 252
253static int wait_for_debi_done(struct saa7146 *saa) 253static int wait_for_debi_done(struct saa7146 *saa)
254{ 254{
@@ -1906,7 +1906,9 @@ static const struct file_operations saa_fops = {
1906 .open = saa_open, 1906 .open = saa_open,
1907 .release = saa_release, 1907 .release = saa_release,
1908 .ioctl = saa_ioctl, 1908 .ioctl = saa_ioctl,
1909#ifdef CONFIG_COMPAT
1909 .compat_ioctl = v4l_compat_ioctl32, 1910 .compat_ioctl = v4l_compat_ioctl32,
1911#endif
1910 .read = saa_read, 1912 .read = saa_read,
1911 .llseek = no_llseek, 1913 .llseek = no_llseek,
1912 .write = saa_write, 1914 .write = saa_write,
diff --git a/drivers/media/video/stv680.c b/drivers/media/video/stv680.c
index afc32aa56fde..d7f130bedb5f 100644
--- a/drivers/media/video/stv680.c
+++ b/drivers/media/video/stv680.c
@@ -72,15 +72,18 @@
72#include "stv680.h" 72#include "stv680.h"
73 73
74static int video_nr = -1; 74static int video_nr = -1;
75static int swapRGB = 0; /* default for auto sleect */
76static int swapRGB_on = 0; /* default to allow auto select; -1=swap never, +1= swap always */
77 75
78static unsigned int debug = 0; 76static int swapRGB; /* 0 = default for auto select */
77
78/* 0 = default to allow auto select; -1 = swap never, +1 = swap always */
79static int swapRGB_on;
80
81static unsigned int debug;
79 82
80#define PDEBUG(level, fmt, args...) \ 83#define PDEBUG(level, fmt, args...) \
81 do { \ 84 do { \
82 if (debug >= level) \ 85 if (debug >= level) \
83 info("[%s:%d] " fmt, __FUNCTION__, __LINE__ , ## args); \ 86 info("[%s:%d] " fmt, __func__, __LINE__ , ## args); \
84 } while (0) 87 } while (0)
85 88
86 89
@@ -1391,7 +1394,9 @@ static const struct file_operations stv680_fops = {
1391 .read = stv680_read, 1394 .read = stv680_read,
1392 .mmap = stv680_mmap, 1395 .mmap = stv680_mmap,
1393 .ioctl = stv680_ioctl, 1396 .ioctl = stv680_ioctl,
1397#ifdef CONFIG_COMPAT
1394 .compat_ioctl = v4l_compat_ioctl32, 1398 .compat_ioctl = v4l_compat_ioctl32,
1399#endif
1395 .llseek = no_llseek, 1400 .llseek = no_llseek,
1396}; 1401};
1397static struct video_device stv680_template = { 1402static struct video_device stv680_template = {
diff --git a/drivers/media/video/tcm825x.c b/drivers/media/video/tcm825x.c
index fb895f6684a3..6943b447a1bd 100644
--- a/drivers/media/video/tcm825x.c
+++ b/drivers/media/video/tcm825x.c
@@ -906,7 +906,7 @@ static int __init tcm825x_init(void)
906 rval = i2c_add_driver(&tcm825x_i2c_driver); 906 rval = i2c_add_driver(&tcm825x_i2c_driver);
907 if (rval) 907 if (rval)
908 printk(KERN_INFO "%s: failed registering " TCM825X_NAME "\n", 908 printk(KERN_INFO "%s: failed registering " TCM825X_NAME "\n",
909 __FUNCTION__); 909 __func__);
910 910
911 return rval; 911 return rval;
912} 912}
diff --git a/drivers/media/video/tda8290.c b/drivers/media/video/tda8290.c
index 55bc89a6f069..0ebb5b525e57 100644
--- a/drivers/media/video/tda8290.c
+++ b/drivers/media/video/tda8290.c
@@ -32,8 +32,6 @@ static int debug;
32module_param(debug, int, 0644); 32module_param(debug, int, 0644);
33MODULE_PARM_DESC(debug, "enable verbose debug messages"); 33MODULE_PARM_DESC(debug, "enable verbose debug messages");
34 34
35#define PREFIX "tda8290"
36
37/* ---------------------------------------------------------------------- */ 35/* ---------------------------------------------------------------------- */
38 36
39struct tda8290_priv { 37struct tda8290_priv {
@@ -174,7 +172,7 @@ static void tda8290_set_params(struct dvb_frontend *fe,
174 set_audio(fe, params); 172 set_audio(fe, params);
175 173
176 if (priv->cfg.config) 174 if (priv->cfg.config)
177 tuner_dbg("tda827xa config is 0x%02x\n", *priv->cfg.config); 175 tuner_dbg("tda827xa config is 0x%02x\n", priv->cfg.config);
178 tuner_i2c_xfer_send(&priv->i2c_props, easy_mode, 2); 176 tuner_i2c_xfer_send(&priv->i2c_props, easy_mode, 2);
179 tuner_i2c_xfer_send(&priv->i2c_props, agc_out_on, 2); 177 tuner_i2c_xfer_send(&priv->i2c_props, agc_out_on, 2);
180 tuner_i2c_xfer_send(&priv->i2c_props, soft_reset, 2); 178 tuner_i2c_xfer_send(&priv->i2c_props, soft_reset, 2);
@@ -365,7 +363,7 @@ static void tda8295_set_params(struct dvb_frontend *fe,
365 363
366 set_audio(fe, params); 364 set_audio(fe, params);
367 365
368 tuner_dbg("%s: freq = %d\n", __FUNCTION__, params->frequency); 366 tuner_dbg("%s: freq = %d\n", __func__, params->frequency);
369 367
370 tda8295_power(fe, 1); 368 tda8295_power(fe, 1);
371 tda8295_agc1_out(fe, 1); 369 tda8295_agc1_out(fe, 1);
@@ -444,8 +442,7 @@ static void tda8290_init_if(struct dvb_frontend *fe)
444 unsigned char set_GP00_CF[] = { 0x20, 0x01 }; 442 unsigned char set_GP00_CF[] = { 0x20, 0x01 };
445 unsigned char set_GP01_CF[] = { 0x20, 0x0B }; 443 unsigned char set_GP01_CF[] = { 0x20, 0x0B };
446 444
447 if ((priv->cfg.config) && 445 if ((priv->cfg.config == 1) || (priv->cfg.config == 2))
448 ((*priv->cfg.config == 1) || (*priv->cfg.config == 2)))
449 tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2); 446 tuner_i2c_xfer_send(&priv->i2c_props, set_GP00_CF, 2);
450 else 447 else
451 tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2); 448 tuner_i2c_xfer_send(&priv->i2c_props, set_GP01_CF, 2);
@@ -590,8 +587,8 @@ static int tda829x_find_tuner(struct dvb_frontend *fe)
590 else 587 else
591 priv->ver |= TDA8275A; 588 priv->ver |= TDA8275A;
592 589
593 tda827x_attach(fe, priv->tda827x_addr, 590 tda827x_attach(fe, priv->tda827x_addr, priv->i2c_props.adap, &priv->cfg);
594 priv->i2c_props.adap, &priv->cfg); 591 priv->cfg.switch_addr = priv->i2c_props.addr;
595 } 592 }
596 if (fe->ops.tuner_ops.init) 593 if (fe->ops.tuner_ops.init)
597 fe->ops.tuner_ops.init(fe); 594 fe->ops.tuner_ops.init(fe);
@@ -616,7 +613,7 @@ static int tda8290_probe(struct tuner_i2c_props *i2c_props)
616 if (tda8290_id[1] == TDA8290_ID) { 613 if (tda8290_id[1] == TDA8290_ID) {
617 if (debug) 614 if (debug)
618 printk(KERN_DEBUG "%s: tda8290 detected @ %d-%04x\n", 615 printk(KERN_DEBUG "%s: tda8290 detected @ %d-%04x\n",
619 __FUNCTION__, i2c_adapter_id(i2c_props->adap), 616 __func__, i2c_adapter_id(i2c_props->adap),
620 i2c_props->addr); 617 i2c_props->addr);
621 return 0; 618 return 0;
622 } 619 }
@@ -636,7 +633,7 @@ static int tda8295_probe(struct tuner_i2c_props *i2c_props)
636 if (tda8295_id[1] == TDA8295_ID) { 633 if (tda8295_id[1] == TDA8295_ID) {
637 if (debug) 634 if (debug)
638 printk(KERN_DEBUG "%s: tda8295 detected @ %d-%04x\n", 635 printk(KERN_DEBUG "%s: tda8295 detected @ %d-%04x\n",
639 __FUNCTION__, i2c_adapter_id(i2c_props->adap), 636 __func__, i2c_adapter_id(i2c_props->adap),
640 i2c_props->addr); 637 i2c_props->addr);
641 return 0; 638 return 0;
642 } 639 }
@@ -674,6 +671,7 @@ struct dvb_frontend *tda829x_attach(struct dvb_frontend *fe,
674 671
675 priv->i2c_props.addr = i2c_addr; 672 priv->i2c_props.addr = i2c_addr;
676 priv->i2c_props.adap = i2c_adap; 673 priv->i2c_props.adap = i2c_adap;
674 priv->i2c_props.name = "tda829x";
677 if (cfg) { 675 if (cfg) {
678 priv->cfg.config = cfg->lna_cfg; 676 priv->cfg.config = cfg->lna_cfg;
679 priv->cfg.tuner_callback = cfg->tuner_callback; 677 priv->cfg.tuner_callback = cfg->tuner_callback;
diff --git a/drivers/media/video/tda8290.h b/drivers/media/video/tda8290.h
index dc8ef310b7b2..d3bbf276a469 100644
--- a/drivers/media/video/tda8290.h
+++ b/drivers/media/video/tda8290.h
@@ -21,7 +21,7 @@
21#include "dvb_frontend.h" 21#include "dvb_frontend.h"
22 22
23struct tda829x_config { 23struct tda829x_config {
24 unsigned int *lna_cfg; 24 unsigned int lna_cfg;
25 int (*tuner_callback) (void *dev, int command, int arg); 25 int (*tuner_callback) (void *dev, int command, int arg);
26 26
27 unsigned int probe_tuner:1; 27 unsigned int probe_tuner:1;
@@ -39,7 +39,7 @@ extern struct dvb_frontend *tda829x_attach(struct dvb_frontend *fe,
39#else 39#else
40static inline int tda829x_probe(struct i2c_adapter *i2c_adap, u8 i2c_addr) 40static inline int tda829x_probe(struct i2c_adapter *i2c_adap, u8 i2c_addr)
41{ 41{
42 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 42 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
43 return -EINVAL; 43 return -EINVAL;
44} 44}
45 45
@@ -49,7 +49,7 @@ static inline struct dvb_frontend *tda829x_attach(struct dvb_frontend *fe,
49 struct tda829x_config *cfg) 49 struct tda829x_config *cfg)
50{ 50{
51 printk(KERN_INFO "%s: not probed - driver disabled by Kconfig\n", 51 printk(KERN_INFO "%s: not probed - driver disabled by Kconfig\n",
52 __FUNCTION__); 52 __func__);
53 return NULL; 53 return NULL;
54} 54}
55#endif 55#endif
diff --git a/drivers/media/video/tda9840.c b/drivers/media/video/tda9840.c
index bdca5d278978..0cee00242782 100644
--- a/drivers/media/video/tda9840.c
+++ b/drivers/media/video/tda9840.c
@@ -31,11 +31,11 @@
31 31
32#include "tda9840.h" 32#include "tda9840.h"
33 33
34static int debug = 0; /* insmod parameter */ 34static int debug; /* insmod parameter */
35module_param(debug, int, 0644); 35module_param(debug, int, 0644);
36MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off)."); 36MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off).");
37#define dprintk(args...) \ 37#define dprintk(args...) \
38 do { if (debug) { printk("%s: %s()[%d]: ", KBUILD_MODNAME, __FUNCTION__, __LINE__); printk(args); } } while (0) 38 do { if (debug) { printk("%s: %s()[%d]: ", KBUILD_MODNAME, __func__, __LINE__); printk(args); } } while (0)
39 39
40#define SWITCH 0x00 40#define SWITCH 0x00
41#define LEVEL_ADJUST 0x02 41#define LEVEL_ADJUST 0x02
diff --git a/drivers/media/video/tda9887.c b/drivers/media/video/tda9887.c
index 106c93b8203f..a0545ba957b0 100644
--- a/drivers/media/video/tda9887.c
+++ b/drivers/media/video/tda9887.c
@@ -25,10 +25,12 @@ static int debug;
25module_param(debug, int, 0644); 25module_param(debug, int, 0644);
26MODULE_PARM_DESC(debug, "enable verbose debug messages"); 26MODULE_PARM_DESC(debug, "enable verbose debug messages");
27 27
28#define PREFIX "tda9887" 28static DEFINE_MUTEX(tda9887_list_mutex);
29static LIST_HEAD(hybrid_tuner_instance_list);
29 30
30struct tda9887_priv { 31struct tda9887_priv {
31 struct tuner_i2c_props i2c_props; 32 struct tuner_i2c_props i2c_props;
33 struct list_head hybrid_tuner_instance_list;
32 34
33 unsigned char data[4]; 35 unsigned char data[4];
34 unsigned int config; 36 unsigned int config;
@@ -644,7 +646,15 @@ static int tda9887_set_config(struct dvb_frontend *fe, void *priv_cfg)
644 646
645static void tda9887_release(struct dvb_frontend *fe) 647static void tda9887_release(struct dvb_frontend *fe)
646{ 648{
647 kfree(fe->analog_demod_priv); 649 struct tda9887_priv *priv = fe->analog_demod_priv;
650
651 mutex_lock(&tda9887_list_mutex);
652
653 if (priv)
654 hybrid_tuner_release_state(priv);
655
656 mutex_unlock(&tda9887_list_mutex);
657
648 fe->analog_demod_priv = NULL; 658 fe->analog_demod_priv = NULL;
649} 659}
650 660
@@ -665,17 +675,29 @@ struct dvb_frontend *tda9887_attach(struct dvb_frontend *fe,
665 u8 i2c_addr) 675 u8 i2c_addr)
666{ 676{
667 struct tda9887_priv *priv = NULL; 677 struct tda9887_priv *priv = NULL;
678 int instance;
668 679
669 priv = kzalloc(sizeof(struct tda9887_priv), GFP_KERNEL); 680 mutex_lock(&tda9887_list_mutex);
670 if (priv == NULL)
671 return NULL;
672 fe->analog_demod_priv = priv;
673 681
674 priv->i2c_props.addr = i2c_addr; 682 instance = hybrid_tuner_request_state(struct tda9887_priv, priv,
675 priv->i2c_props.adap = i2c_adap; 683 hybrid_tuner_instance_list,
676 priv->mode = T_STANDBY; 684 i2c_adap, i2c_addr, "tda9887");
685 switch (instance) {
686 case 0:
687 mutex_unlock(&tda9887_list_mutex);
688 return NULL;
689 break;
690 case 1:
691 fe->analog_demod_priv = priv;
692 priv->mode = T_STANDBY;
693 tuner_info("tda988[5/6/7] found\n");
694 break;
695 default:
696 fe->analog_demod_priv = priv;
697 break;
698 }
677 699
678 tuner_info("tda988[5/6/7] found\n"); 700 mutex_unlock(&tda9887_list_mutex);
679 701
680 memcpy(&fe->ops.analog_ops, &tda9887_ops, 702 memcpy(&fe->ops.analog_ops, &tda9887_ops,
681 sizeof(struct analog_demod_ops)); 703 sizeof(struct analog_demod_ops));
diff --git a/drivers/media/video/tda9887.h b/drivers/media/video/tda9887.h
index 8f873a8e6ed2..be49dcbfc70e 100644
--- a/drivers/media/video/tda9887.h
+++ b/drivers/media/video/tda9887.h
@@ -30,7 +30,7 @@ static inline struct dvb_frontend *tda9887_attach(struct dvb_frontend *fe,
30 struct i2c_adapter *i2c_adap, 30 struct i2c_adapter *i2c_adap,
31 u8 i2c_addr) 31 u8 i2c_addr)
32{ 32{
33 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 33 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
34 return NULL; 34 return NULL;
35} 35}
36#endif 36#endif
diff --git a/drivers/media/video/tea5761.c b/drivers/media/video/tea5761.c
index 5326eeceaacd..b93cdef9ac73 100644
--- a/drivers/media/video/tea5761.c
+++ b/drivers/media/video/tea5761.c
@@ -14,12 +14,10 @@
14#include "tuner-i2c.h" 14#include "tuner-i2c.h"
15#include "tea5761.h" 15#include "tea5761.h"
16 16
17static int debug = 0; 17static int debug;
18module_param(debug, int, 0644); 18module_param(debug, int, 0644);
19MODULE_PARM_DESC(debug, "enable verbose debug messages"); 19MODULE_PARM_DESC(debug, "enable verbose debug messages");
20 20
21#define PREFIX "tea5761"
22
23struct tea5761_priv { 21struct tea5761_priv {
24 struct tuner_i2c_props i2c_props; 22 struct tuner_i2c_props i2c_props;
25 23
@@ -131,7 +129,7 @@ static void tea5761_status_dump(unsigned char *buffer)
131 129
132 frq = 1000 * (div * 32768 / 1000 + FREQ_OFFSET + 225) / 4; /* Freq in KHz */ 130 frq = 1000 * (div * 32768 / 1000 + FREQ_OFFSET + 225) / 4; /* Freq in KHz */
133 131
134 printk(PREFIX "Frequency %d.%03d KHz (divider = 0x%04x)\n", 132 printk(KERN_INFO "tea5761: Frequency %d.%03d KHz (divider = 0x%04x)\n",
135 frq / 1000, frq % 1000, div); 133 frq / 1000, frq % 1000, div);
136} 134}
137 135
@@ -249,14 +247,19 @@ int tea5761_autodetection(struct i2c_adapter* i2c_adap, u8 i2c_addr)
249 247
250 if (16 != (rc = tuner_i2c_xfer_recv(&i2c, buffer, 16))) { 248 if (16 != (rc = tuner_i2c_xfer_recv(&i2c, buffer, 16))) {
251 printk(KERN_WARNING "it is not a TEA5761. Received %i chars.\n", rc); 249 printk(KERN_WARNING "it is not a TEA5761. Received %i chars.\n", rc);
252 return EINVAL; 250 return -EINVAL;
253 } 251 }
254 252
255 if (!((buffer[13] != 0x2b) || (buffer[14] != 0x57) || (buffer[15] != 0x061))) { 253 if ((buffer[13] != 0x2b) || (buffer[14] != 0x57) || (buffer[15] != 0x061)) {
256 printk(KERN_WARNING "Manufacturer ID= 0x%02x, Chip ID = %02x%02x. It is not a TEA5761\n",buffer[13],buffer[14],buffer[15]); 254 printk(KERN_WARNING "Manufacturer ID= 0x%02x, Chip ID = %02x%02x."
257 return EINVAL; 255 " It is not a TEA5761\n",
256 buffer[13], buffer[14], buffer[15]);
257 return -EINVAL;
258 } 258 }
259 printk(KERN_WARNING "TEA5761 detected.\n"); 259 printk(KERN_WARNING "tea5761: TEA%02x%02x detected. "
260 "Manufacturer ID= 0x%02x\n",
261 buffer[14], buffer[15], buffer[13]);
262
260 return 0; 263 return 0;
261} 264}
262 265
@@ -302,6 +305,7 @@ struct dvb_frontend *tea5761_attach(struct dvb_frontend *fe,
302 305
303 priv->i2c_props.addr = i2c_addr; 306 priv->i2c_props.addr = i2c_addr;
304 priv->i2c_props.adap = i2c_adap; 307 priv->i2c_props.adap = i2c_adap;
308 priv->i2c_props.name = "tea5761";
305 309
306 memcpy(&fe->ops.tuner_ops, &tea5761_tuner_ops, 310 memcpy(&fe->ops.tuner_ops, &tea5761_tuner_ops,
307 sizeof(struct dvb_tuner_ops)); 311 sizeof(struct dvb_tuner_ops));
diff --git a/drivers/media/video/tea5761.h b/drivers/media/video/tea5761.h
index 73a03b427843..8eb62722b988 100644
--- a/drivers/media/video/tea5761.h
+++ b/drivers/media/video/tea5761.h
@@ -31,7 +31,7 @@ static inline int tea5761_autodetection(struct i2c_adapter* i2c_adap,
31 u8 i2c_addr) 31 u8 i2c_addr)
32{ 32{
33 printk(KERN_INFO "%s: not probed - driver disabled by Kconfig\n", 33 printk(KERN_INFO "%s: not probed - driver disabled by Kconfig\n",
34 __FUNCTION__); 34 __func__);
35 return -EINVAL; 35 return -EINVAL;
36} 36}
37 37
@@ -39,7 +39,7 @@ static inline struct dvb_frontend *tea5761_attach(struct dvb_frontend *fe,
39 struct i2c_adapter* i2c_adap, 39 struct i2c_adapter* i2c_adap,
40 u8 i2c_addr) 40 u8 i2c_addr)
41{ 41{
42 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 42 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
43 return NULL; 43 return NULL;
44} 44}
45#endif 45#endif
diff --git a/drivers/media/video/tea5767.c b/drivers/media/video/tea5767.c
index e1b48d87e7b7..f6e7d7ad8424 100644
--- a/drivers/media/video/tea5767.c
+++ b/drivers/media/video/tea5767.c
@@ -16,12 +16,10 @@
16#include "tuner-i2c.h" 16#include "tuner-i2c.h"
17#include "tea5767.h" 17#include "tea5767.h"
18 18
19static int debug = 0; 19static int debug;
20module_param(debug, int, 0644); 20module_param(debug, int, 0644);
21MODULE_PARM_DESC(debug, "enable verbose debug messages"); 21MODULE_PARM_DESC(debug, "enable verbose debug messages");
22 22
23#define PREFIX "tea5767"
24
25/*****************************************************************************/ 23/*****************************************************************************/
26 24
27struct tea5767_priv { 25struct tea5767_priv {
@@ -137,14 +135,14 @@ static void tea5767_status_dump(struct tea5767_priv *priv,
137 unsigned int div, frq; 135 unsigned int div, frq;
138 136
139 if (TEA5767_READY_FLAG_MASK & buffer[0]) 137 if (TEA5767_READY_FLAG_MASK & buffer[0])
140 printk(PREFIX "Ready Flag ON\n"); 138 tuner_info("Ready Flag ON\n");
141 else 139 else
142 printk(PREFIX "Ready Flag OFF\n"); 140 tuner_info("Ready Flag OFF\n");
143 141
144 if (TEA5767_BAND_LIMIT_MASK & buffer[0]) 142 if (TEA5767_BAND_LIMIT_MASK & buffer[0])
145 printk(PREFIX "Tuner at band limit\n"); 143 tuner_info("Tuner at band limit\n");
146 else 144 else
147 printk(PREFIX "Tuner not at band limit\n"); 145 tuner_info("Tuner not at band limit\n");
148 146
149 div = ((buffer[0] & 0x3f) << 8) | buffer[1]; 147 div = ((buffer[0] & 0x3f) << 8) | buffer[1];
150 148
@@ -166,23 +164,23 @@ static void tea5767_status_dump(struct tea5767_priv *priv,
166 buffer[0] = (div >> 8) & 0x3f; 164 buffer[0] = (div >> 8) & 0x3f;
167 buffer[1] = div & 0xff; 165 buffer[1] = div & 0xff;
168 166
169 printk(PREFIX "Frequency %d.%03d KHz (divider = 0x%04x)\n", 167 tuner_info("Frequency %d.%03d KHz (divider = 0x%04x)\n",
170 frq / 1000, frq % 1000, div); 168 frq / 1000, frq % 1000, div);
171 169
172 if (TEA5767_STEREO_MASK & buffer[2]) 170 if (TEA5767_STEREO_MASK & buffer[2])
173 printk(PREFIX "Stereo\n"); 171 tuner_info("Stereo\n");
174 else 172 else
175 printk(PREFIX "Mono\n"); 173 tuner_info("Mono\n");
176 174
177 printk(PREFIX "IF Counter = %d\n", buffer[2] & TEA5767_IF_CNTR_MASK); 175 tuner_info("IF Counter = %d\n", buffer[2] & TEA5767_IF_CNTR_MASK);
178 176
179 printk(PREFIX "ADC Level = %d\n", 177 tuner_info("ADC Level = %d\n",
180 (buffer[3] & TEA5767_ADC_LEVEL_MASK) >> 4); 178 (buffer[3] & TEA5767_ADC_LEVEL_MASK) >> 4);
181 179
182 printk(PREFIX "Chip ID = %d\n", (buffer[3] & TEA5767_CHIP_ID_MASK)); 180 tuner_info("Chip ID = %d\n", (buffer[3] & TEA5767_CHIP_ID_MASK));
183 181
184 printk(PREFIX "Reserved = 0x%02x\n", 182 tuner_info("Reserved = 0x%02x\n",
185 (buffer[4] & TEA5767_RESERVED_MASK)); 183 (buffer[4] & TEA5767_RESERVED_MASK));
186} 184}
187 185
188/* Freq should be specifyed at 62.5 Hz */ 186/* Freq should be specifyed at 62.5 Hz */
@@ -395,11 +393,6 @@ int tea5767_autodetection(struct i2c_adapter* i2c_adap, u8 i2c_addr)
395 return EINVAL; 393 return EINVAL;
396 } 394 }
397 395
398 /* It seems that tea5767 returns 0xff after the 5th byte */
399 if ((buffer[5] != 0xff) || (buffer[6] != 0xff)) {
400 printk(KERN_WARNING "Returned more than 5 bytes. It is not a TEA5767\n");
401 return EINVAL;
402 }
403 396
404 return 0; 397 return 0;
405} 398}
@@ -456,6 +449,8 @@ struct dvb_frontend *tea5767_attach(struct dvb_frontend *fe,
456 449
457 priv->i2c_props.addr = i2c_addr; 450 priv->i2c_props.addr = i2c_addr;
458 priv->i2c_props.adap = i2c_adap; 451 priv->i2c_props.adap = i2c_adap;
452 priv->i2c_props.name = "tea5767";
453
459 priv->ctrl.xtal_freq = TEA5767_HIGH_LO_32768; 454 priv->ctrl.xtal_freq = TEA5767_HIGH_LO_32768;
460 priv->ctrl.port1 = 1; 455 priv->ctrl.port1 = 1;
461 priv->ctrl.port2 = 1; 456 priv->ctrl.port2 = 1;
diff --git a/drivers/media/video/tea5767.h b/drivers/media/video/tea5767.h
index a44451f61145..7b547c092e25 100644
--- a/drivers/media/video/tea5767.h
+++ b/drivers/media/video/tea5767.h
@@ -50,7 +50,7 @@ static inline int tea5767_autodetection(struct i2c_adapter* i2c_adap,
50 u8 i2c_addr) 50 u8 i2c_addr)
51{ 51{
52 printk(KERN_INFO "%s: not probed - driver disabled by Kconfig\n", 52 printk(KERN_INFO "%s: not probed - driver disabled by Kconfig\n",
53 __FUNCTION__); 53 __func__);
54 return -EINVAL; 54 return -EINVAL;
55} 55}
56 56
@@ -58,7 +58,7 @@ static inline struct dvb_frontend *tea5767_attach(struct dvb_frontend *fe,
58 struct i2c_adapter* i2c_adap, 58 struct i2c_adapter* i2c_adap,
59 u8 i2c_addr) 59 u8 i2c_addr)
60{ 60{
61 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 61 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
62 return NULL; 62 return NULL;
63} 63}
64#endif 64#endif
diff --git a/drivers/media/video/tea6415c.c b/drivers/media/video/tea6415c.c
index df2fad9f391e..9513d8611e87 100644
--- a/drivers/media/video/tea6415c.c
+++ b/drivers/media/video/tea6415c.c
@@ -33,11 +33,11 @@
33 33
34#include "tea6415c.h" 34#include "tea6415c.h"
35 35
36static int debug = 0; /* insmod parameter */ 36static int debug; /* insmod parameter */
37module_param(debug, int, 0644); 37module_param(debug, int, 0644);
38MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off)."); 38MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off).");
39#define dprintk(args...) \ 39#define dprintk(args...) \
40 do { if (debug) { printk("%s: %s()[%d]: ", KBUILD_MODNAME, __FUNCTION__, __LINE__); printk(args); } } while (0) 40 do { if (debug) { printk("%s: %s()[%d]: ", KBUILD_MODNAME, __func__, __LINE__); printk(args); } } while (0)
41 41
42#define TEA6415C_NUM_INPUTS 8 42#define TEA6415C_NUM_INPUTS 8
43#define TEA6415C_NUM_OUTPUTS 6 43#define TEA6415C_NUM_OUTPUTS 6
diff --git a/drivers/media/video/tea6420.c b/drivers/media/video/tea6420.c
index 4ff6c63f7237..7fd53367c07c 100644
--- a/drivers/media/video/tea6420.c
+++ b/drivers/media/video/tea6420.c
@@ -33,11 +33,11 @@
33 33
34#include "tea6420.h" 34#include "tea6420.h"
35 35
36static int debug = 0; /* insmod parameter */ 36static int debug; /* insmod parameter */
37module_param(debug, int, 0644); 37module_param(debug, int, 0644);
38MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off)."); 38MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off).");
39#define dprintk(args...) \ 39#define dprintk(args...) \
40 do { if (debug) { printk("%s: %s()[%d]: ", KBUILD_MODNAME, __FUNCTION__, __LINE__); printk(args); } } while (0) 40 do { if (debug) { printk("%s: %s()[%d]: ", KBUILD_MODNAME, __func__, __LINE__); printk(args); } } while (0)
41 41
42/* addresses to scan, found only at 0x4c and/or 0x4d (7-Bit) */ 42/* addresses to scan, found only at 0x4c and/or 0x4d (7-Bit) */
43static unsigned short normal_i2c[] = { I2C_ADDR_TEA6420_1, I2C_ADDR_TEA6420_2, I2C_CLIENT_END }; 43static unsigned short normal_i2c[] = { I2C_ADDR_TEA6420_1, I2C_ADDR_TEA6420_2, I2C_CLIENT_END };
diff --git a/drivers/media/video/tuner-core.c b/drivers/media/video/tuner-core.c
index 78a09a2a4857..529e00952a8d 100644
--- a/drivers/media/video/tuner-core.c
+++ b/drivers/media/video/tuner-core.c
@@ -68,9 +68,9 @@ static unsigned short normal_i2c[] = {
68I2C_CLIENT_INSMOD; 68I2C_CLIENT_INSMOD;
69 69
70/* insmod options used at init time => read/only */ 70/* insmod options used at init time => read/only */
71static unsigned int addr = 0; 71static unsigned int addr;
72static unsigned int no_autodetect = 0; 72static unsigned int no_autodetect;
73static unsigned int show_i2c = 0; 73static unsigned int show_i2c;
74 74
75/* insmod options used at runtime => read/write */ 75/* insmod options used at runtime => read/write */
76static int tuner_debug; 76static int tuner_debug;
@@ -313,24 +313,14 @@ static void tuner_i2c_address_check(struct tuner *t)
313 tuner_warn("output to v4l-dvb-maintainer@linuxtv.org\n"); 313 tuner_warn("output to v4l-dvb-maintainer@linuxtv.org\n");
314 tuner_warn("Please use subject line: \"obsolete tuner i2c address.\"\n"); 314 tuner_warn("Please use subject line: \"obsolete tuner i2c address.\"\n");
315 tuner_warn("driver: %s, addr: 0x%02x, type: %d (%s)\n", 315 tuner_warn("driver: %s, addr: 0x%02x, type: %d (%s)\n",
316 t->i2c->adapter->name, t->i2c->addr, t->type, 316 t->i2c->adapter->name, t->i2c->addr, t->type, t->i2c->name);
317 tuners[t->type].name);
318 tuner_warn("====================== WARNING! ======================\n"); 317 tuner_warn("====================== WARNING! ======================\n");
319} 318}
320 319
321static void attach_simple_tuner(struct tuner *t)
322{
323 struct simple_tuner_config cfg = {
324 .type = t->type,
325 .tun = &tuners[t->type]
326 };
327 simple_tuner_attach(&t->fe, t->i2c->adapter, t->i2c->addr, &cfg);
328}
329
330static void attach_tda829x(struct tuner *t) 320static void attach_tda829x(struct tuner *t)
331{ 321{
332 struct tda829x_config cfg = { 322 struct tda829x_config cfg = {
333 .lna_cfg = &t->config, 323 .lna_cfg = t->config,
334 .tuner_callback = t->tuner_callback, 324 .tuner_callback = t->tuner_callback,
335 }; 325 };
336 tda829x_attach(&t->fe, t->i2c->adapter, t->i2c->addr, &cfg); 326 tda829x_attach(&t->fe, t->i2c->adapter, t->i2c->addr, &cfg);
@@ -352,11 +342,6 @@ static void set_type(struct i2c_client *c, unsigned int type,
352 return; 342 return;
353 } 343 }
354 344
355 if (type >= tuner_count) {
356 tuner_warn ("tuner 0x%02x: Tuner count greater than %d\n",c->addr,tuner_count);
357 return;
358 }
359
360 t->type = type; 345 t->type = type;
361 t->config = new_config; 346 t->config = new_config;
362 if (tuner_callback != NULL) { 347 if (tuner_callback != NULL) {
@@ -409,7 +394,12 @@ static void set_type(struct i2c_client *c, unsigned int type,
409 buffer[2] = 0x86; 394 buffer[2] = 0x86;
410 buffer[3] = 0x54; 395 buffer[3] = 0x54;
411 i2c_master_send(c, buffer, 4); 396 i2c_master_send(c, buffer, 4);
412 attach_simple_tuner(t); 397 if (simple_tuner_attach(&t->fe, t->i2c->adapter, t->i2c->addr,
398 t->type) == NULL) {
399 t->type = TUNER_ABSENT;
400 t->mode_mask = T_UNINITIALIZED;
401 return;
402 }
413 break; 403 break;
414 case TUNER_PHILIPS_TD1316: 404 case TUNER_PHILIPS_TD1316:
415 buffer[0] = 0x0b; 405 buffer[0] = 0x0b;
@@ -417,14 +407,18 @@ static void set_type(struct i2c_client *c, unsigned int type,
417 buffer[2] = 0x86; 407 buffer[2] = 0x86;
418 buffer[3] = 0xa4; 408 buffer[3] = 0xa4;
419 i2c_master_send(c,buffer,4); 409 i2c_master_send(c,buffer,4);
420 attach_simple_tuner(t); 410 if (simple_tuner_attach(&t->fe, t->i2c->adapter,
411 t->i2c->addr, t->type) == NULL) {
412 t->type = TUNER_ABSENT;
413 t->mode_mask = T_UNINITIALIZED;
414 return;
415 }
421 break; 416 break;
422 case TUNER_XC2028: 417 case TUNER_XC2028:
423 { 418 {
424 struct xc2028_config cfg = { 419 struct xc2028_config cfg = {
425 .i2c_adap = t->i2c->adapter, 420 .i2c_adap = t->i2c->adapter,
426 .i2c_addr = t->i2c->addr, 421 .i2c_addr = t->i2c->addr,
427 .video_dev = c->adapter->algo_data,
428 .callback = t->tuner_callback, 422 .callback = t->tuner_callback,
429 }; 423 };
430 if (!xc2028_attach(&t->fe, &cfg)) { 424 if (!xc2028_attach(&t->fe, &cfg)) {
@@ -455,7 +449,12 @@ static void set_type(struct i2c_client *c, unsigned int type,
455 } 449 }
456 break; 450 break;
457 default: 451 default:
458 attach_simple_tuner(t); 452 if (simple_tuner_attach(&t->fe, t->i2c->adapter,
453 t->i2c->addr, t->type) == NULL) {
454 t->type = TUNER_ABSENT;
455 t->mode_mask = T_UNINITIALIZED;
456 return;
457 }
459 break; 458 break;
460 } 459 }
461 460
@@ -759,7 +758,7 @@ static int tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
759 if (analog_ops->standby) 758 if (analog_ops->standby)
760 analog_ops->standby(&t->fe); 759 analog_ops->standby(&t->fe);
761 break; 760 break;
762#ifdef CONFIG_VIDEO_V4L1 761#ifdef CONFIG_VIDEO_ALLOW_V4L1
763 case VIDIOCSAUDIO: 762 case VIDIOCSAUDIO:
764 if (check_mode(t, "VIDIOCSAUDIO") == EINVAL) 763 if (check_mode(t, "VIDIOCSAUDIO") == EINVAL)
765 return 0; 764 return 0;
@@ -1112,8 +1111,8 @@ static int tuner_probe(struct i2c_client *client)
1112 if (!no_autodetect) { 1111 if (!no_autodetect) {
1113 switch (client->addr) { 1112 switch (client->addr) {
1114 case 0x10: 1113 case 0x10:
1115 if (tea5761_autodetection(t->i2c->adapter, t->i2c->addr) 1114 if (tea5761_autodetection(t->i2c->adapter,
1116 != EINVAL) { 1115 t->i2c->addr) >= 0) {
1117 t->type = TUNER_TEA5761; 1116 t->type = TUNER_TEA5761;
1118 t->mode_mask = T_RADIO; 1117 t->mode_mask = T_RADIO;
1119 t->mode = T_STANDBY; 1118 t->mode = T_STANDBY;
@@ -1125,7 +1124,7 @@ static int tuner_probe(struct i2c_client *client)
1125 1124
1126 goto register_client; 1125 goto register_client;
1127 } 1126 }
1128 break; 1127 return -ENODEV;
1129 case 0x42: 1128 case 0x42:
1130 case 0x43: 1129 case 0x43:
1131 case 0x4a: 1130 case 0x4a:
diff --git a/drivers/media/video/tuner-i2c.h b/drivers/media/video/tuner-i2c.h
index de52e8ffd347..3ad6c8e0b04c 100644
--- a/drivers/media/video/tuner-i2c.h
+++ b/drivers/media/video/tuner-i2c.h
@@ -26,6 +26,10 @@
26struct tuner_i2c_props { 26struct tuner_i2c_props {
27 u8 addr; 27 u8 addr;
28 struct i2c_adapter *adap; 28 struct i2c_adapter *adap;
29
30 /* used for tuner instance management */
31 int count;
32 char *name;
29}; 33};
30 34
31static inline int tuner_i2c_xfer_send(struct tuner_i2c_props *props, char *buf, int len) 35static inline int tuner_i2c_xfer_send(struct tuner_i2c_props *props, char *buf, int len)
@@ -59,29 +63,111 @@ static inline int tuner_i2c_xfer_send_recv(struct tuner_i2c_props *props,
59 return (ret == 2) ? ilen : ret; 63 return (ret == 2) ? ilen : ret;
60} 64}
61 65
62#define tuner_warn(fmt, arg...) do { \ 66/* Callers must declare as a global for the module:
63 printk(KERN_WARNING "%s %d-%04x: " fmt, PREFIX, \ 67 *
64 i2c_adapter_id(priv->i2c_props.adap), \ 68 * static LIST_HEAD(hybrid_tuner_instance_list);
65 priv->i2c_props.addr, ##arg); \ 69 *
70 * hybrid_tuner_instance_list should be the third argument
71 * passed into hybrid_tuner_request_state().
72 *
73 * state structure must contain the following:
74 *
75 * struct list_head hybrid_tuner_instance_list;
76 * struct tuner_i2c_props i2c_props;
77 *
78 * hybrid_tuner_instance_list (both within state structure and globally)
79 * is only required if the driver is using hybrid_tuner_request_state
80 * and hybrid_tuner_release_state to manage state sharing between
81 * multiple instances of hybrid tuners.
82 */
83
84#define tuner_printk(kernlvl, i2cprops, fmt, arg...) do { \
85 printk(kernlvl "%s %d-%04x: " fmt, i2cprops.name, \
86 i2cprops.adap ? \
87 i2c_adapter_id(i2cprops.adap) : -1, \
88 i2cprops.addr, ##arg); \
66 } while (0) 89 } while (0)
67 90
68#define tuner_info(fmt, arg...) do { \ 91/* TO DO: convert all callers of these macros to pass in
69 printk(KERN_INFO "%s %d-%04x: " fmt, PREFIX, \ 92 * struct tuner_i2c_props, then remove the macro wrappers */
70 i2c_adapter_id(priv->i2c_props.adap), \ 93
71 priv->i2c_props.addr , ##arg); \ 94#define __tuner_warn(i2cprops, fmt, arg...) do { \
95 tuner_printk(KERN_WARNING, i2cprops, fmt, ##arg); \
72 } while (0) 96 } while (0)
73 97
74#define tuner_err(fmt, arg...) do { \ 98#define __tuner_info(i2cprops, fmt, arg...) do { \
75 printk(KERN_ERR "%s %d-%04x: " fmt, PREFIX, \ 99 tuner_printk(KERN_INFO, i2cprops, fmt, ##arg); \
76 i2c_adapter_id(priv->i2c_props.adap), \
77 priv->i2c_props.addr , ##arg); \
78 } while (0) 100 } while (0)
79 101
80#define tuner_dbg(fmt, arg...) do { \ 102#define __tuner_err(i2cprops, fmt, arg...) do { \
103 tuner_printk(KERN_ERR, i2cprops, fmt, ##arg); \
104 } while (0)
105
106#define __tuner_dbg(i2cprops, fmt, arg...) do { \
81 if ((debug)) \ 107 if ((debug)) \
82 printk(KERN_DEBUG "%s %d-%04x: " fmt, PREFIX, \ 108 tuner_printk(KERN_DEBUG, i2cprops, fmt, ##arg); \
83 i2c_adapter_id(priv->i2c_props.adap), \
84 priv->i2c_props.addr , ##arg); \
85 } while (0) 109 } while (0)
86 110
111#define tuner_warn(fmt, arg...) __tuner_warn(priv->i2c_props, fmt, ##arg)
112#define tuner_info(fmt, arg...) __tuner_info(priv->i2c_props, fmt, ##arg)
113#define tuner_err(fmt, arg...) __tuner_err(priv->i2c_props, fmt, ##arg)
114#define tuner_dbg(fmt, arg...) __tuner_dbg(priv->i2c_props, fmt, ##arg)
115
116/****************************************************************************/
117
118/* The return value of hybrid_tuner_request_state indicates the number of
119 * instances using this tuner object.
120 *
121 * 0 - no instances, indicates an error - kzalloc must have failed
122 *
123 * 1 - one instance, indicates that the tuner object was created successfully
124 *
125 * 2 (or more) instances, indicates that an existing tuner object was found
126 */
127
128#define hybrid_tuner_request_state(type, state, list, i2cadap, i2caddr, devname)\
129({ \
130 int __ret = 0; \
131 list_for_each_entry(state, &list, hybrid_tuner_instance_list) { \
132 if (((i2cadap) && (state->i2c_props.adap)) && \
133 ((i2c_adapter_id(state->i2c_props.adap) == \
134 i2c_adapter_id(i2cadap)) && \
135 (i2caddr == state->i2c_props.addr))) { \
136 __tuner_info(state->i2c_props, \
137 "attaching existing instance\n"); \
138 state->i2c_props.count++; \
139 __ret = state->i2c_props.count; \
140 break; \
141 } \
142 } \
143 if (0 == __ret) { \
144 state = kzalloc(sizeof(type), GFP_KERNEL); \
145 if (NULL == state) \
146 goto __fail; \
147 state->i2c_props.addr = i2caddr; \
148 state->i2c_props.adap = i2cadap; \
149 state->i2c_props.name = devname; \
150 __tuner_info(state->i2c_props, \
151 "creating new instance\n"); \
152 list_add_tail(&state->hybrid_tuner_instance_list, &list);\
153 state->i2c_props.count++; \
154 __ret = state->i2c_props.count; \
155 } \
156__fail: \
157 __ret; \
158})
159
160#define hybrid_tuner_release_state(state) \
161({ \
162 int __ret; \
163 state->i2c_props.count--; \
164 __ret = state->i2c_props.count; \
165 if (!state->i2c_props.count) { \
166 __tuner_info(state->i2c_props, "destroying instance\n");\
167 list_del(&state->hybrid_tuner_instance_list); \
168 kfree(state); \
169 } \
170 __ret; \
171})
172
87#endif /* __TUNER_I2C_H__ */ 173#endif /* __TUNER_I2C_H__ */
diff --git a/drivers/media/video/tuner-simple.c b/drivers/media/video/tuner-simple.c
index c1db576696c6..be8d903171b7 100644
--- a/drivers/media/video/tuner-simple.c
+++ b/drivers/media/video/tuner-simple.c
@@ -13,15 +13,25 @@
13#include "tuner-i2c.h" 13#include "tuner-i2c.h"
14#include "tuner-simple.h" 14#include "tuner-simple.h"
15 15
16static int debug = 0; 16static int debug;
17module_param(debug, int, 0644); 17module_param(debug, int, 0644);
18MODULE_PARM_DESC(debug, "enable verbose debug messages"); 18MODULE_PARM_DESC(debug, "enable verbose debug messages");
19 19
20#define PREFIX "tuner-simple" 20#define TUNER_SIMPLE_MAX 64
21static unsigned int simple_devcount;
21 22
22static int offset = 0; 23static int offset;
23module_param(offset, int, 0664); 24module_param(offset, int, 0664);
24MODULE_PARM_DESC(offset,"Allows to specify an offset for tuner"); 25MODULE_PARM_DESC(offset, "Allows to specify an offset for tuner");
26
27static unsigned int atv_input[TUNER_SIMPLE_MAX] = \
28 { [0 ... (TUNER_SIMPLE_MAX-1)] = 0 };
29static unsigned int dtv_input[TUNER_SIMPLE_MAX] = \
30 { [0 ... (TUNER_SIMPLE_MAX-1)] = 0 };
31module_param_array(atv_input, int, NULL, 0644);
32module_param_array(dtv_input, int, NULL, 0644);
33MODULE_PARM_DESC(atv_input, "specify atv rf input, 0 for autoselect");
34MODULE_PARM_DESC(dtv_input, "specify dtv rf input, 0 for autoselect");
25 35
26/* ---------------------------------------------------------------------- */ 36/* ---------------------------------------------------------------------- */
27 37
@@ -36,8 +46,8 @@ MODULE_PARM_DESC(offset,"Allows to specify an offset for tuner");
36 */ 46 */
37#define TEMIC_SET_PAL_I 0x05 47#define TEMIC_SET_PAL_I 0x05
38#define TEMIC_SET_PAL_DK 0x09 48#define TEMIC_SET_PAL_DK 0x09
39#define TEMIC_SET_PAL_L 0x0a // SECAM ? 49#define TEMIC_SET_PAL_L 0x0a /* SECAM ? */
40#define TEMIC_SET_PAL_L2 0x0b // change IF ! 50#define TEMIC_SET_PAL_L2 0x0b /* change IF ! */
41#define TEMIC_SET_PAL_BG 0x0c 51#define TEMIC_SET_PAL_BG 0x0c
42 52
43/* tv tuner system standard selection for Philips FQ1216ME 53/* tv tuner system standard selection for Philips FQ1216ME
@@ -90,14 +100,21 @@ MODULE_PARM_DESC(offset,"Allows to specify an offset for tuner");
90#define TUNER_PLL_LOCKED 0x40 100#define TUNER_PLL_LOCKED 0x40
91#define TUNER_STEREO_MK3 0x04 101#define TUNER_STEREO_MK3 0x04
92 102
103static DEFINE_MUTEX(tuner_simple_list_mutex);
104static LIST_HEAD(hybrid_tuner_instance_list);
105
93struct tuner_simple_priv { 106struct tuner_simple_priv {
107 unsigned int nr;
94 u16 last_div; 108 u16 last_div;
109
95 struct tuner_i2c_props i2c_props; 110 struct tuner_i2c_props i2c_props;
111 struct list_head hybrid_tuner_instance_list;
96 112
97 unsigned int type; 113 unsigned int type;
98 struct tunertype *tun; 114 struct tunertype *tun;
99 115
100 u32 frequency; 116 u32 frequency;
117 u32 bandwidth;
101}; 118};
102 119
103/* ---------------------------------------------------------------------- */ 120/* ---------------------------------------------------------------------- */
@@ -107,7 +124,7 @@ static int tuner_read_status(struct dvb_frontend *fe)
107 struct tuner_simple_priv *priv = fe->tuner_priv; 124 struct tuner_simple_priv *priv = fe->tuner_priv;
108 unsigned char byte; 125 unsigned char byte;
109 126
110 if (1 != tuner_i2c_xfer_recv(&priv->i2c_props,&byte,1)) 127 if (1 != tuner_i2c_xfer_recv(&priv->i2c_props, &byte, 1))
111 return 0; 128 return 0;
112 129
113 return byte; 130 return byte;
@@ -121,13 +138,13 @@ static inline int tuner_signal(const int status)
121static inline int tuner_stereo(const int type, const int status) 138static inline int tuner_stereo(const int type, const int status)
122{ 139{
123 switch (type) { 140 switch (type) {
124 case TUNER_PHILIPS_FM1216ME_MK3: 141 case TUNER_PHILIPS_FM1216ME_MK3:
125 case TUNER_PHILIPS_FM1236_MK3: 142 case TUNER_PHILIPS_FM1236_MK3:
126 case TUNER_PHILIPS_FM1256_IH3: 143 case TUNER_PHILIPS_FM1256_IH3:
127 case TUNER_LG_NTSC_TAPE: 144 case TUNER_LG_NTSC_TAPE:
128 return ((status & TUNER_SIGNAL) == TUNER_STEREO_MK3); 145 return ((status & TUNER_SIGNAL) == TUNER_STEREO_MK3);
129 default: 146 default:
130 return status & TUNER_STEREO; 147 return status & TUNER_STEREO;
131 } 148 }
132} 149}
133 150
@@ -145,7 +162,12 @@ static inline int tuner_afcstatus(const int status)
145static int simple_get_status(struct dvb_frontend *fe, u32 *status) 162static int simple_get_status(struct dvb_frontend *fe, u32 *status)
146{ 163{
147 struct tuner_simple_priv *priv = fe->tuner_priv; 164 struct tuner_simple_priv *priv = fe->tuner_priv;
148 int tuner_status = tuner_read_status(fe); 165 int tuner_status;
166
167 if (priv->i2c_props.adap == NULL)
168 return -EINVAL;
169
170 tuner_status = tuner_read_status(fe);
149 171
150 *status = 0; 172 *status = 0;
151 173
@@ -162,7 +184,12 @@ static int simple_get_status(struct dvb_frontend *fe, u32 *status)
162static int simple_get_rf_strength(struct dvb_frontend *fe, u16 *strength) 184static int simple_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
163{ 185{
164 struct tuner_simple_priv *priv = fe->tuner_priv; 186 struct tuner_simple_priv *priv = fe->tuner_priv;
165 int signal = tuner_signal(tuner_read_status(fe)); 187 int signal;
188
189 if (priv->i2c_props.adap == NULL)
190 return -EINVAL;
191
192 signal = tuner_signal(tuner_read_status(fe));
166 193
167 *strength = signal; 194 *strength = signal;
168 195
@@ -173,174 +200,378 @@ static int simple_get_rf_strength(struct dvb_frontend *fe, u16 *strength)
173 200
174/* ---------------------------------------------------------------------- */ 201/* ---------------------------------------------------------------------- */
175 202
176static int simple_set_tv_freq(struct dvb_frontend *fe, 203static inline char *tuner_param_name(enum param_type type)
177 struct analog_parameters *params)
178{ 204{
179 struct tuner_simple_priv *priv = fe->tuner_priv; 205 char *name;
180 u8 config, cb, tuneraddr;
181 u16 div;
182 struct tunertype *tun;
183 u8 buffer[4];
184 int rc, IFPCoff, i, j;
185 enum param_type desired_type;
186 struct tuner_params *t_params;
187 206
188 tun = priv->tun; 207 switch (type) {
208 case TUNER_PARAM_TYPE_RADIO:
209 name = "radio";
210 break;
211 case TUNER_PARAM_TYPE_PAL:
212 name = "pal";
213 break;
214 case TUNER_PARAM_TYPE_SECAM:
215 name = "secam";
216 break;
217 case TUNER_PARAM_TYPE_NTSC:
218 name = "ntsc";
219 break;
220 case TUNER_PARAM_TYPE_DIGITAL:
221 name = "digital";
222 break;
223 default:
224 name = "unknown";
225 break;
226 }
227 return name;
228}
189 229
190 /* IFPCoff = Video Intermediate Frequency - Vif: 230static struct tuner_params *simple_tuner_params(struct dvb_frontend *fe,
191 940 =16*58.75 NTSC/J (Japan) 231 enum param_type desired_type)
192 732 =16*45.75 M/N STD 232{
193 704 =16*44 ATSC (at DVB code) 233 struct tuner_simple_priv *priv = fe->tuner_priv;
194 632 =16*39.50 I U.K. 234 struct tunertype *tun = priv->tun;
195 622.4=16*38.90 B/G D/K I, L STD 235 int i;
196 592 =16*37.00 D China
197 590 =16.36.875 B Australia
198 543.2=16*33.95 L' STD
199 171.2=16*10.70 FM Radio (at set_radio_freq)
200 */
201 236
202 if (params->std == V4L2_STD_NTSC_M_JP) { 237 for (i = 0; i < tun->count; i++)
203 IFPCoff = 940; 238 if (desired_type == tun->params[i].type)
204 desired_type = TUNER_PARAM_TYPE_NTSC; 239 break;
205 } else if ((params->std & V4L2_STD_MN) &&
206 !(params->std & ~V4L2_STD_MN)) {
207 IFPCoff = 732;
208 desired_type = TUNER_PARAM_TYPE_NTSC;
209 } else if (params->std == V4L2_STD_SECAM_LC) {
210 IFPCoff = 543;
211 desired_type = TUNER_PARAM_TYPE_SECAM;
212 } else {
213 IFPCoff = 623;
214 desired_type = TUNER_PARAM_TYPE_PAL;
215 }
216 240
217 for (j = 0; j < tun->count-1; j++) { 241 /* use default tuner params if desired_type not available */
218 if (desired_type != tun->params[j].type) 242 if (i == tun->count) {
219 continue; 243 tuner_dbg("desired params (%s) undefined for tuner %d\n",
220 break; 244 tuner_param_name(desired_type), priv->type);
221 } 245 i = 0;
222 /* use default tuner_t_params if desired_type not available */
223 if (desired_type != tun->params[j].type) {
224 tuner_dbg("IFPCoff = %d: tuner_t_params undefined for tuner %d\n",
225 IFPCoff, priv->type);
226 j = 0;
227 } 246 }
228 t_params = &tun->params[j]; 247
248 tuner_dbg("using tuner params #%d (%s)\n", i,
249 tuner_param_name(tun->params[i].type));
250
251 return &tun->params[i];
252}
253
254static int simple_config_lookup(struct dvb_frontend *fe,
255 struct tuner_params *t_params,
256 int *frequency, u8 *config, u8 *cb)
257{
258 struct tuner_simple_priv *priv = fe->tuner_priv;
259 int i;
229 260
230 for (i = 0; i < t_params->count; i++) { 261 for (i = 0; i < t_params->count; i++) {
231 if (params->frequency > t_params->ranges[i].limit) 262 if (*frequency > t_params->ranges[i].limit)
232 continue; 263 continue;
233 break; 264 break;
234 } 265 }
235 if (i == t_params->count) { 266 if (i == t_params->count) {
236 tuner_dbg("TV frequency out of range (%d > %d)", 267 tuner_dbg("frequency out of range (%d > %d)\n",
237 params->frequency, t_params->ranges[i - 1].limit); 268 *frequency, t_params->ranges[i - 1].limit);
238 params->frequency = t_params->ranges[--i].limit; 269 *frequency = t_params->ranges[--i].limit;
239 } 270 }
240 config = t_params->ranges[i].config; 271 *config = t_params->ranges[i].config;
241 cb = t_params->ranges[i].cb; 272 *cb = t_params->ranges[i].cb;
242 /* i == 0 -> VHF_LO 273
243 * i == 1 -> VHF_HI 274 tuner_dbg("freq = %d.%02d (%d), range = %d, "
244 * i == 2 -> UHF */ 275 "config = 0x%02x, cb = 0x%02x\n",
245 tuner_dbg("tv: param %d, range %d\n",j,i); 276 *frequency / 16, *frequency % 16 * 100 / 16, *frequency,
277 i, *config, *cb);
278
279 return i;
280}
281
282/* ---------------------------------------------------------------------- */
283
284static void simple_set_rf_input(struct dvb_frontend *fe,
285 u8 *config, u8 *cb, unsigned int rf)
286{
287 struct tuner_simple_priv *priv = fe->tuner_priv;
246 288
247 div=params->frequency + IFPCoff + offset; 289 switch (priv->type) {
290 case TUNER_PHILIPS_TUV1236D:
291 switch (rf) {
292 case 1:
293 *cb |= 0x08;
294 break;
295 default:
296 *cb &= ~0x08;
297 break;
298 }
299 break;
300 case TUNER_PHILIPS_FCV1236D:
301 switch (rf) {
302 case 1:
303 *cb |= 0x01;
304 break;
305 default:
306 *cb &= ~0x01;
307 break;
308 }
309 break;
310 default:
311 break;
312 }
313}
248 314
249 tuner_dbg("Freq= %d.%02d MHz, V_IF=%d.%02d MHz, Offset=%d.%02d MHz, div=%0d\n", 315static int simple_std_setup(struct dvb_frontend *fe,
250 params->frequency / 16, params->frequency % 16 * 100 / 16, 316 struct analog_parameters *params,
251 IFPCoff / 16, IFPCoff % 16 * 100 / 16, 317 u8 *config, u8 *cb)
252 offset / 16, offset % 16 * 100 / 16, 318{
253 div); 319 struct tuner_simple_priv *priv = fe->tuner_priv;
320 u8 tuneraddr;
321 int rc;
254 322
255 /* tv norm specific stuff for multi-norm tuners */ 323 /* tv norm specific stuff for multi-norm tuners */
256 switch (priv->type) { 324 switch (priv->type) {
257 case TUNER_PHILIPS_SECAM: // FI1216MF 325 case TUNER_PHILIPS_SECAM: /* FI1216MF */
258 /* 0x01 -> ??? no change ??? */ 326 /* 0x01 -> ??? no change ??? */
259 /* 0x02 -> PAL BDGHI / SECAM L */ 327 /* 0x02 -> PAL BDGHI / SECAM L */
260 /* 0x04 -> ??? PAL others / SECAM others ??? */ 328 /* 0x04 -> ??? PAL others / SECAM others ??? */
261 cb &= ~0x03; 329 *cb &= ~0x03;
262 if (params->std & V4L2_STD_SECAM_L) //also valid for V4L2_STD_SECAM 330 if (params->std & V4L2_STD_SECAM_L)
263 cb |= PHILIPS_MF_SET_STD_L; 331 /* also valid for V4L2_STD_SECAM */
332 *cb |= PHILIPS_MF_SET_STD_L;
264 else if (params->std & V4L2_STD_SECAM_LC) 333 else if (params->std & V4L2_STD_SECAM_LC)
265 cb |= PHILIPS_MF_SET_STD_LC; 334 *cb |= PHILIPS_MF_SET_STD_LC;
266 else /* V4L2_STD_B|V4L2_STD_GH */ 335 else /* V4L2_STD_B|V4L2_STD_GH */
267 cb |= PHILIPS_MF_SET_STD_BG; 336 *cb |= PHILIPS_MF_SET_STD_BG;
268 break; 337 break;
269 338
270 case TUNER_TEMIC_4046FM5: 339 case TUNER_TEMIC_4046FM5:
271 cb &= ~0x0f; 340 *cb &= ~0x0f;
272 341
273 if (params->std & V4L2_STD_PAL_BG) { 342 if (params->std & V4L2_STD_PAL_BG) {
274 cb |= TEMIC_SET_PAL_BG; 343 *cb |= TEMIC_SET_PAL_BG;
275 344
276 } else if (params->std & V4L2_STD_PAL_I) { 345 } else if (params->std & V4L2_STD_PAL_I) {
277 cb |= TEMIC_SET_PAL_I; 346 *cb |= TEMIC_SET_PAL_I;
278 347
279 } else if (params->std & V4L2_STD_PAL_DK) { 348 } else if (params->std & V4L2_STD_PAL_DK) {
280 cb |= TEMIC_SET_PAL_DK; 349 *cb |= TEMIC_SET_PAL_DK;
281 350
282 } else if (params->std & V4L2_STD_SECAM_L) { 351 } else if (params->std & V4L2_STD_SECAM_L) {
283 cb |= TEMIC_SET_PAL_L; 352 *cb |= TEMIC_SET_PAL_L;
284 353
285 } 354 }
286 break; 355 break;
287 356
288 case TUNER_PHILIPS_FQ1216ME: 357 case TUNER_PHILIPS_FQ1216ME:
289 cb &= ~0x0f; 358 *cb &= ~0x0f;
290 359
291 if (params->std & (V4L2_STD_PAL_BG|V4L2_STD_PAL_DK)) { 360 if (params->std & (V4L2_STD_PAL_BG|V4L2_STD_PAL_DK)) {
292 cb |= PHILIPS_SET_PAL_BGDK; 361 *cb |= PHILIPS_SET_PAL_BGDK;
293 362
294 } else if (params->std & V4L2_STD_PAL_I) { 363 } else if (params->std & V4L2_STD_PAL_I) {
295 cb |= PHILIPS_SET_PAL_I; 364 *cb |= PHILIPS_SET_PAL_I;
296 365
297 } else if (params->std & V4L2_STD_SECAM_L) { 366 } else if (params->std & V4L2_STD_SECAM_L) {
298 cb |= PHILIPS_SET_PAL_L; 367 *cb |= PHILIPS_SET_PAL_L;
299 368
300 } 369 }
301 break; 370 break;
302 371
303 case TUNER_PHILIPS_ATSC: 372 case TUNER_PHILIPS_FCV1236D:
304 /* 0x00 -> ATSC antenna input 1 */ 373 /* 0x00 -> ATSC antenna input 1 */
305 /* 0x01 -> ATSC antenna input 2 */ 374 /* 0x01 -> ATSC antenna input 2 */
306 /* 0x02 -> NTSC antenna input 1 */ 375 /* 0x02 -> NTSC antenna input 1 */
307 /* 0x03 -> NTSC antenna input 2 */ 376 /* 0x03 -> NTSC antenna input 2 */
308 cb &= ~0x03; 377 *cb &= ~0x03;
309 if (!(params->std & V4L2_STD_ATSC)) 378 if (!(params->std & V4L2_STD_ATSC))
310 cb |= 2; 379 *cb |= 2;
311 /* FIXME: input */
312 break; 380 break;
313 381
314 case TUNER_MICROTUNE_4042FI5: 382 case TUNER_MICROTUNE_4042FI5:
315 /* Set the charge pump for fast tuning */ 383 /* Set the charge pump for fast tuning */
316 config |= TUNER_CHARGE_PUMP; 384 *config |= TUNER_CHARGE_PUMP;
317 break; 385 break;
318 386
319 case TUNER_PHILIPS_TUV1236D: 387 case TUNER_PHILIPS_TUV1236D:
388 {
320 /* 0x40 -> ATSC antenna input 1 */ 389 /* 0x40 -> ATSC antenna input 1 */
321 /* 0x48 -> ATSC antenna input 2 */ 390 /* 0x48 -> ATSC antenna input 2 */
322 /* 0x00 -> NTSC antenna input 1 */ 391 /* 0x00 -> NTSC antenna input 1 */
323 /* 0x08 -> NTSC antenna input 2 */ 392 /* 0x08 -> NTSC antenna input 2 */
324 buffer[0] = 0x14; 393 u8 buffer[4] = { 0x14, 0x00, 0x17, 0x00};
325 buffer[1] = 0x00; 394 *cb &= ~0x40;
326 buffer[2] = 0x17;
327 buffer[3] = 0x00;
328 cb &= ~0x40;
329 if (params->std & V4L2_STD_ATSC) { 395 if (params->std & V4L2_STD_ATSC) {
330 cb |= 0x40; 396 *cb |= 0x40;
331 buffer[1] = 0x04; 397 buffer[1] = 0x04;
332 } 398 }
333 /* set to the correct mode (analog or digital) */ 399 /* set to the correct mode (analog or digital) */
334 tuneraddr = priv->i2c_props.addr; 400 tuneraddr = priv->i2c_props.addr;
335 priv->i2c_props.addr = 0x0a; 401 priv->i2c_props.addr = 0x0a;
336 if (2 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,&buffer[0],2))) 402 rc = tuner_i2c_xfer_send(&priv->i2c_props, &buffer[0], 2);
337 tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc); 403 if (2 != rc)
338 if (2 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,&buffer[2],2))) 404 tuner_warn("i2c i/o error: rc == %d "
339 tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc); 405 "(should be 2)\n", rc);
406 rc = tuner_i2c_xfer_send(&priv->i2c_props, &buffer[2], 2);
407 if (2 != rc)
408 tuner_warn("i2c i/o error: rc == %d "
409 "(should be 2)\n", rc);
340 priv->i2c_props.addr = tuneraddr; 410 priv->i2c_props.addr = tuneraddr;
341 /* FIXME: input */
342 break; 411 break;
343 } 412 }
413 }
414 if (atv_input[priv->nr])
415 simple_set_rf_input(fe, config, cb, atv_input[priv->nr]);
416
417 return 0;
418}
419
420static int simple_post_tune(struct dvb_frontend *fe, u8 *buffer,
421 u16 div, u8 config, u8 cb)
422{
423 struct tuner_simple_priv *priv = fe->tuner_priv;
424 int rc;
425
426 switch (priv->type) {
427 case TUNER_LG_TDVS_H06XF:
428 /* Set the Auxiliary Byte. */
429 buffer[0] = buffer[2];
430 buffer[0] &= ~0x20;
431 buffer[0] |= 0x18;
432 buffer[1] = 0x20;
433 tuner_dbg("tv 0x%02x 0x%02x\n", buffer[0], buffer[1]);
434
435 rc = tuner_i2c_xfer_send(&priv->i2c_props, buffer, 2);
436 if (2 != rc)
437 tuner_warn("i2c i/o error: rc == %d "
438 "(should be 2)\n", rc);
439 break;
440 case TUNER_MICROTUNE_4042FI5:
441 {
442 /* FIXME - this may also work for other tuners */
443 unsigned long timeout = jiffies + msecs_to_jiffies(1);
444 u8 status_byte = 0;
445
446 /* Wait until the PLL locks */
447 for (;;) {
448 if (time_after(jiffies, timeout))
449 return 0;
450 rc = tuner_i2c_xfer_recv(&priv->i2c_props,
451 &status_byte, 1);
452 if (1 != rc) {
453 tuner_warn("i2c i/o read error: rc == %d "
454 "(should be 1)\n", rc);
455 break;
456 }
457 if (status_byte & TUNER_PLL_LOCKED)
458 break;
459 udelay(10);
460 }
461
462 /* Set the charge pump for optimized phase noise figure */
463 config &= ~TUNER_CHARGE_PUMP;
464 buffer[0] = (div>>8) & 0x7f;
465 buffer[1] = div & 0xff;
466 buffer[2] = config;
467 buffer[3] = cb;
468 tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n",
469 buffer[0], buffer[1], buffer[2], buffer[3]);
470
471 rc = tuner_i2c_xfer_send(&priv->i2c_props, buffer, 4);
472 if (4 != rc)
473 tuner_warn("i2c i/o error: rc == %d "
474 "(should be 4)\n", rc);
475 break;
476 }
477 }
478
479 return 0;
480}
481
482static int simple_radio_bandswitch(struct dvb_frontend *fe, u8 *buffer)
483{
484 struct tuner_simple_priv *priv = fe->tuner_priv;
485
486 switch (priv->type) {
487 case TUNER_TENA_9533_DI:
488 case TUNER_YMEC_TVF_5533MF:
489 tuner_dbg("This tuner doesn't have FM. "
490 "Most cards have a TEA5767 for FM\n");
491 return 0;
492 case TUNER_PHILIPS_FM1216ME_MK3:
493 case TUNER_PHILIPS_FM1236_MK3:
494 case TUNER_PHILIPS_FMD1216ME_MK3:
495 case TUNER_LG_NTSC_TAPE:
496 case TUNER_PHILIPS_FM1256_IH3:
497 buffer[3] = 0x19;
498 break;
499 case TUNER_TNF_5335MF:
500 buffer[3] = 0x11;
501 break;
502 case TUNER_LG_PAL_FM:
503 buffer[3] = 0xa5;
504 break;
505 case TUNER_THOMSON_DTT761X:
506 buffer[3] = 0x39;
507 break;
508 case TUNER_MICROTUNE_4049FM5:
509 default:
510 buffer[3] = 0xa4;
511 break;
512 }
513
514 return 0;
515}
516
517/* ---------------------------------------------------------------------- */
518
519static int simple_set_tv_freq(struct dvb_frontend *fe,
520 struct analog_parameters *params)
521{
522 struct tuner_simple_priv *priv = fe->tuner_priv;
523 u8 config, cb;
524 u16 div;
525 struct tunertype *tun;
526 u8 buffer[4];
527 int rc, IFPCoff, i;
528 enum param_type desired_type;
529 struct tuner_params *t_params;
530
531 tun = priv->tun;
532
533 /* IFPCoff = Video Intermediate Frequency - Vif:
534 940 =16*58.75 NTSC/J (Japan)
535 732 =16*45.75 M/N STD
536 704 =16*44 ATSC (at DVB code)
537 632 =16*39.50 I U.K.
538 622.4=16*38.90 B/G D/K I, L STD
539 592 =16*37.00 D China
540 590 =16.36.875 B Australia
541 543.2=16*33.95 L' STD
542 171.2=16*10.70 FM Radio (at set_radio_freq)
543 */
544
545 if (params->std == V4L2_STD_NTSC_M_JP) {
546 IFPCoff = 940;
547 desired_type = TUNER_PARAM_TYPE_NTSC;
548 } else if ((params->std & V4L2_STD_MN) &&
549 !(params->std & ~V4L2_STD_MN)) {
550 IFPCoff = 732;
551 desired_type = TUNER_PARAM_TYPE_NTSC;
552 } else if (params->std == V4L2_STD_SECAM_LC) {
553 IFPCoff = 543;
554 desired_type = TUNER_PARAM_TYPE_SECAM;
555 } else {
556 IFPCoff = 623;
557 desired_type = TUNER_PARAM_TYPE_PAL;
558 }
559
560 t_params = simple_tuner_params(fe, desired_type);
561
562 i = simple_config_lookup(fe, t_params, &params->frequency,
563 &config, &cb);
564
565 div = params->frequency + IFPCoff + offset;
566
567 tuner_dbg("Freq= %d.%02d MHz, V_IF=%d.%02d MHz, "
568 "Offset=%d.%02d MHz, div=%0d\n",
569 params->frequency / 16, params->frequency % 16 * 100 / 16,
570 IFPCoff / 16, IFPCoff % 16 * 100 / 16,
571 offset / 16, offset % 16 * 100 / 16, div);
572
573 /* tv norm specific stuff for multi-norm tuners */
574 simple_std_setup(fe, params, &config, &cb);
344 575
345 if (t_params->cb_first_if_lower_freq && div < priv->last_div) { 576 if (t_params->cb_first_if_lower_freq && div < priv->last_div) {
346 buffer[0] = config; 577 buffer[0] = config;
@@ -357,8 +588,10 @@ static int simple_set_tv_freq(struct dvb_frontend *fe,
357 if (t_params->has_tda9887) { 588 if (t_params->has_tda9887) {
358 struct v4l2_priv_tun_config tda9887_cfg; 589 struct v4l2_priv_tun_config tda9887_cfg;
359 int config = 0; 590 int config = 0;
360 int is_secam_l = (params->std & (V4L2_STD_SECAM_L | V4L2_STD_SECAM_LC)) && 591 int is_secam_l = (params->std & (V4L2_STD_SECAM_L |
361 !(params->std & ~(V4L2_STD_SECAM_L | V4L2_STD_SECAM_LC)); 592 V4L2_STD_SECAM_LC)) &&
593 !(params->std & ~(V4L2_STD_SECAM_L |
594 V4L2_STD_SECAM_LC));
362 595
363 tda9887_cfg.tuner = TUNER_TDA9887; 596 tda9887_cfg.tuner = TUNER_TDA9887;
364 tda9887_cfg.priv = &config; 597 tda9887_cfg.priv = &config;
@@ -368,8 +601,7 @@ static int simple_set_tv_freq(struct dvb_frontend *fe,
368 config |= TDA9887_PORT1_ACTIVE; 601 config |= TDA9887_PORT1_ACTIVE;
369 if (t_params->port2_active ^ t_params->port2_invert_for_secam_lc) 602 if (t_params->port2_active ^ t_params->port2_invert_for_secam_lc)
370 config |= TDA9887_PORT2_ACTIVE; 603 config |= TDA9887_PORT2_ACTIVE;
371 } 604 } else {
372 else {
373 if (t_params->port1_active) 605 if (t_params->port1_active)
374 config |= TDA9887_PORT1_ACTIVE; 606 config |= TDA9887_PORT1_ACTIVE;
375 if (t_params->port2_active) 607 if (t_params->port2_active)
@@ -384,8 +616,7 @@ static int simple_set_tv_freq(struct dvb_frontend *fe,
384 config |= TDA9887_TOP(t_params->default_top_secam_mid); 616 config |= TDA9887_TOP(t_params->default_top_secam_mid);
385 else if (t_params->default_top_secam_high) 617 else if (t_params->default_top_secam_high)
386 config |= TDA9887_TOP(t_params->default_top_secam_high); 618 config |= TDA9887_TOP(t_params->default_top_secam_high);
387 } 619 } else {
388 else {
389 if (i == 0 && t_params->default_top_low) 620 if (i == 0 && t_params->default_top_low)
390 config |= TDA9887_TOP(t_params->default_top_low); 621 config |= TDA9887_TOP(t_params->default_top_low);
391 else if (i == 1 && t_params->default_top_mid) 622 else if (i == 1 && t_params->default_top_mid)
@@ -399,56 +630,14 @@ static int simple_set_tv_freq(struct dvb_frontend *fe,
399 &tda9887_cfg); 630 &tda9887_cfg);
400 } 631 }
401 tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n", 632 tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n",
402 buffer[0],buffer[1],buffer[2],buffer[3]); 633 buffer[0], buffer[1], buffer[2], buffer[3]);
403
404 if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,4)))
405 tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc);
406
407 switch (priv->type) {
408 case TUNER_LG_TDVS_H06XF:
409 /* Set the Auxiliary Byte. */
410 buffer[0] = buffer[2];
411 buffer[0] &= ~0x20;
412 buffer[0] |= 0x18;
413 buffer[1] = 0x20;
414 tuner_dbg("tv 0x%02x 0x%02x\n",buffer[0],buffer[1]);
415
416 if (2 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,2)))
417 tuner_warn("i2c i/o error: rc == %d (should be 2)\n",rc);
418 break;
419 case TUNER_MICROTUNE_4042FI5:
420 {
421 // FIXME - this may also work for other tuners
422 unsigned long timeout = jiffies + msecs_to_jiffies(1);
423 u8 status_byte = 0;
424 634
425 /* Wait until the PLL locks */ 635 rc = tuner_i2c_xfer_send(&priv->i2c_props, buffer, 4);
426 for (;;) { 636 if (4 != rc)
427 if (time_after(jiffies,timeout)) 637 tuner_warn("i2c i/o error: rc == %d (should be 4)\n", rc);
428 return 0;
429 if (1 != (rc = tuner_i2c_xfer_recv(&priv->i2c_props,&status_byte,1))) {
430 tuner_warn("i2c i/o read error: rc == %d (should be 1)\n",rc);
431 break;
432 }
433 if (status_byte & TUNER_PLL_LOCKED)
434 break;
435 udelay(10);
436 }
437 638
438 /* Set the charge pump for optimized phase noise figure */ 639 simple_post_tune(fe, &buffer[0], div, config, cb);
439 config &= ~TUNER_CHARGE_PUMP;
440 buffer[0] = (div>>8) & 0x7f;
441 buffer[1] = div & 0xff;
442 buffer[2] = config;
443 buffer[3] = cb;
444 tuner_dbg("tv 0x%02x 0x%02x 0x%02x 0x%02x\n",
445 buffer[0],buffer[1],buffer[2],buffer[3]);
446 640
447 if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,4)))
448 tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc);
449 break;
450 }
451 }
452 return 0; 641 return 0;
453} 642}
454 643
@@ -483,37 +672,13 @@ static int simple_set_radio_freq(struct dvb_frontend *fe,
483 freq += (unsigned int)(41.3*16000); 672 freq += (unsigned int)(41.3*16000);
484 break; 673 break;
485 default: 674 default:
486 tuner_warn("Unsupported radio_if value %d\n", t_params->radio_if); 675 tuner_warn("Unsupported radio_if value %d\n",
676 t_params->radio_if);
487 return 0; 677 return 0;
488 } 678 }
489 679
490 /* Bandswitch byte */ 680 /* Bandswitch byte */
491 switch (priv->type) { 681 simple_radio_bandswitch(fe, &buffer[0]);
492 case TUNER_TENA_9533_DI:
493 case TUNER_YMEC_TVF_5533MF:
494 tuner_dbg("This tuner doesn't have FM. Most cards have a TEA5767 for FM\n");
495 return 0;
496 case TUNER_PHILIPS_FM1216ME_MK3:
497 case TUNER_PHILIPS_FM1236_MK3:
498 case TUNER_PHILIPS_FMD1216ME_MK3:
499 case TUNER_LG_NTSC_TAPE:
500 case TUNER_PHILIPS_FM1256_IH3:
501 buffer[3] = 0x19;
502 break;
503 case TUNER_TNF_5335MF:
504 buffer[3] = 0x11;
505 break;
506 case TUNER_LG_PAL_FM:
507 buffer[3] = 0xa5;
508 break;
509 case TUNER_THOMSON_DTT761X:
510 buffer[3] = 0x39;
511 break;
512 case TUNER_MICROTUNE_4049FM5:
513 default:
514 buffer[3] = 0xa4;
515 break;
516 }
517 682
518 buffer[2] = (t_params->ranges[0].config & ~TUNER_RATIO_MASK) | 683 buffer[2] = (t_params->ranges[0].config & ~TUNER_RATIO_MASK) |
519 TUNER_RATIO_SELECT_50; /* 50 kHz step */ 684 TUNER_RATIO_SELECT_50; /* 50 kHz step */
@@ -534,7 +699,7 @@ static int simple_set_radio_freq(struct dvb_frontend *fe,
534 } 699 }
535 700
536 tuner_dbg("radio 0x%02x 0x%02x 0x%02x 0x%02x\n", 701 tuner_dbg("radio 0x%02x 0x%02x 0x%02x 0x%02x\n",
537 buffer[0],buffer[1],buffer[2],buffer[3]); 702 buffer[0], buffer[1], buffer[2], buffer[3]);
538 priv->last_div = div; 703 priv->last_div = div;
539 704
540 if (t_params->has_tda9887) { 705 if (t_params->has_tda9887) {
@@ -544,9 +709,11 @@ static int simple_set_radio_freq(struct dvb_frontend *fe,
544 tda9887_cfg.tuner = TUNER_TDA9887; 709 tda9887_cfg.tuner = TUNER_TDA9887;
545 tda9887_cfg.priv = &config; 710 tda9887_cfg.priv = &config;
546 711
547 if (t_params->port1_active && !t_params->port1_fm_high_sensitivity) 712 if (t_params->port1_active &&
713 !t_params->port1_fm_high_sensitivity)
548 config |= TDA9887_PORT1_ACTIVE; 714 config |= TDA9887_PORT1_ACTIVE;
549 if (t_params->port2_active && !t_params->port2_fm_high_sensitivity) 715 if (t_params->port2_active &&
716 !t_params->port2_fm_high_sensitivity)
550 config |= TDA9887_PORT2_ACTIVE; 717 config |= TDA9887_PORT2_ACTIVE;
551 if (t_params->intercarrier_mode) 718 if (t_params->intercarrier_mode)
552 config |= TDA9887_INTERCARRIER; 719 config |= TDA9887_INTERCARRIER;
@@ -557,10 +724,11 @@ static int simple_set_radio_freq(struct dvb_frontend *fe,
557 if (t_params->radio_if == 2) 724 if (t_params->radio_if == 2)
558 config |= TDA9887_RIF_41_3; 725 config |= TDA9887_RIF_41_3;
559 i2c_clients_command(priv->i2c_props.adap, TUNER_SET_CONFIG, 726 i2c_clients_command(priv->i2c_props.adap, TUNER_SET_CONFIG,
560 &tda9887_cfg); 727 &tda9887_cfg);
561 } 728 }
562 if (4 != (rc = tuner_i2c_xfer_send(&priv->i2c_props,buffer,4))) 729 rc = tuner_i2c_xfer_send(&priv->i2c_props, buffer, 4);
563 tuner_warn("i2c i/o error: rc == %d (should be 4)\n",rc); 730 if (4 != rc)
731 tuner_warn("i2c i/o error: rc == %d (should be 4)\n", rc);
564 732
565 return 0; 733 return 0;
566} 734}
@@ -571,6 +739,9 @@ static int simple_set_params(struct dvb_frontend *fe,
571 struct tuner_simple_priv *priv = fe->tuner_priv; 739 struct tuner_simple_priv *priv = fe->tuner_priv;
572 int ret = -EINVAL; 740 int ret = -EINVAL;
573 741
742 if (priv->i2c_props.adap == NULL)
743 return -EINVAL;
744
574 switch (params->mode) { 745 switch (params->mode) {
575 case V4L2_TUNER_RADIO: 746 case V4L2_TUNER_RADIO:
576 ret = simple_set_radio_freq(fe, params); 747 ret = simple_set_radio_freq(fe, params);
@@ -582,14 +753,210 @@ static int simple_set_params(struct dvb_frontend *fe,
582 priv->frequency = params->frequency * 62500; 753 priv->frequency = params->frequency * 62500;
583 break; 754 break;
584 } 755 }
756 priv->bandwidth = 0;
585 757
586 return ret; 758 return ret;
587} 759}
588 760
761static void simple_set_dvb(struct dvb_frontend *fe, u8 *buf,
762 const struct dvb_frontend_parameters *params)
763{
764 struct tuner_simple_priv *priv = fe->tuner_priv;
765
766 switch (priv->type) {
767 case TUNER_PHILIPS_FMD1216ME_MK3:
768 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ &&
769 params->frequency >= 158870000)
770 buf[3] |= 0x08;
771 break;
772 case TUNER_PHILIPS_TD1316:
773 /* determine band */
774 buf[3] |= (params->frequency < 161000000) ? 1 :
775 (params->frequency < 444000000) ? 2 : 4;
776
777 /* setup PLL filter */
778 if (params->u.ofdm.bandwidth == BANDWIDTH_8_MHZ)
779 buf[3] |= 1 << 3;
780 break;
781 case TUNER_PHILIPS_TUV1236D:
782 case TUNER_PHILIPS_FCV1236D:
783 {
784 unsigned int new_rf;
785
786 if (dtv_input[priv->nr])
787 new_rf = dtv_input[priv->nr];
788 else
789 switch (params->u.vsb.modulation) {
790 case QAM_64:
791 case QAM_256:
792 new_rf = 1;
793 break;
794 case VSB_8:
795 default:
796 new_rf = 0;
797 break;
798 }
799 simple_set_rf_input(fe, &buf[2], &buf[3], new_rf);
800 break;
801 }
802 default:
803 break;
804 }
805}
806
807static u32 simple_dvb_configure(struct dvb_frontend *fe, u8 *buf,
808 const struct dvb_frontend_parameters *params)
809{
810 /* This function returns the tuned frequency on success, 0 on error */
811 struct tuner_simple_priv *priv = fe->tuner_priv;
812 struct tunertype *tun = priv->tun;
813 static struct tuner_params *t_params;
814 u8 config, cb;
815 u32 div;
816 int ret, frequency = params->frequency / 62500;
817
818 t_params = simple_tuner_params(fe, TUNER_PARAM_TYPE_DIGITAL);
819 ret = simple_config_lookup(fe, t_params, &frequency, &config, &cb);
820 if (ret < 0)
821 return 0; /* failure */
822
823 div = ((frequency + t_params->iffreq) * 62500 + offset +
824 tun->stepsize/2) / tun->stepsize;
825
826 buf[0] = div >> 8;
827 buf[1] = div & 0xff;
828 buf[2] = config;
829 buf[3] = cb;
830
831 simple_set_dvb(fe, buf, params);
832
833 tuner_dbg("%s: div=%d | buf=0x%02x,0x%02x,0x%02x,0x%02x\n",
834 tun->name, div, buf[0], buf[1], buf[2], buf[3]);
835
836 /* calculate the frequency we set it to */
837 return (div * tun->stepsize) - t_params->iffreq;
838}
839
840static int simple_dvb_calc_regs(struct dvb_frontend *fe,
841 struct dvb_frontend_parameters *params,
842 u8 *buf, int buf_len)
843{
844 struct tuner_simple_priv *priv = fe->tuner_priv;
845 u32 frequency;
846
847 if (buf_len < 5)
848 return -EINVAL;
849
850 frequency = simple_dvb_configure(fe, buf+1, params);
851 if (frequency == 0)
852 return -EINVAL;
853
854 buf[0] = priv->i2c_props.addr;
855
856 priv->frequency = frequency;
857 priv->bandwidth = (fe->ops.info.type == FE_OFDM) ?
858 params->u.ofdm.bandwidth : 0;
859
860 return 5;
861}
862
863static int simple_dvb_set_params(struct dvb_frontend *fe,
864 struct dvb_frontend_parameters *params)
865{
866 struct tuner_simple_priv *priv = fe->tuner_priv;
867 u32 prev_freq, prev_bw;
868 int ret;
869 u8 buf[5];
870
871 if (priv->i2c_props.adap == NULL)
872 return -EINVAL;
873
874 prev_freq = priv->frequency;
875 prev_bw = priv->bandwidth;
876
877 ret = simple_dvb_calc_regs(fe, params, buf, 5);
878 if (ret != 5)
879 goto fail;
880
881 /* put analog demod in standby when tuning digital */
882 if (fe->ops.analog_ops.standby)
883 fe->ops.analog_ops.standby(fe);
884
885 if (fe->ops.i2c_gate_ctrl)
886 fe->ops.i2c_gate_ctrl(fe, 1);
887
888 /* buf[0] contains the i2c address, but *
889 * we already have it in i2c_props.addr */
890 ret = tuner_i2c_xfer_send(&priv->i2c_props, buf+1, 4);
891 if (ret != 4)
892 goto fail;
893
894 return 0;
895fail:
896 /* calc_regs sets frequency and bandwidth. if we failed, unset them */
897 priv->frequency = prev_freq;
898 priv->bandwidth = prev_bw;
899
900 return ret;
901}
902
903static int simple_init(struct dvb_frontend *fe)
904{
905 struct tuner_simple_priv *priv = fe->tuner_priv;
906
907 if (priv->i2c_props.adap == NULL)
908 return -EINVAL;
909
910 if (priv->tun->initdata) {
911 int ret;
912
913 if (fe->ops.i2c_gate_ctrl)
914 fe->ops.i2c_gate_ctrl(fe, 1);
915
916 ret = tuner_i2c_xfer_send(&priv->i2c_props,
917 priv->tun->initdata + 1,
918 priv->tun->initdata[0]);
919 if (ret != priv->tun->initdata[0])
920 return ret;
921 }
922
923 return 0;
924}
925
926static int simple_sleep(struct dvb_frontend *fe)
927{
928 struct tuner_simple_priv *priv = fe->tuner_priv;
929
930 if (priv->i2c_props.adap == NULL)
931 return -EINVAL;
932
933 if (priv->tun->sleepdata) {
934 int ret;
935
936 if (fe->ops.i2c_gate_ctrl)
937 fe->ops.i2c_gate_ctrl(fe, 1);
938
939 ret = tuner_i2c_xfer_send(&priv->i2c_props,
940 priv->tun->sleepdata + 1,
941 priv->tun->sleepdata[0]);
942 if (ret != priv->tun->sleepdata[0])
943 return ret;
944 }
945
946 return 0;
947}
589 948
590static int simple_release(struct dvb_frontend *fe) 949static int simple_release(struct dvb_frontend *fe)
591{ 950{
592 kfree(fe->tuner_priv); 951 struct tuner_simple_priv *priv = fe->tuner_priv;
952
953 mutex_lock(&tuner_simple_list_mutex);
954
955 if (priv)
956 hybrid_tuner_release_state(priv);
957
958 mutex_unlock(&tuner_simple_list_mutex);
959
593 fe->tuner_priv = NULL; 960 fe->tuner_priv = NULL;
594 961
595 return 0; 962 return 0;
@@ -602,10 +969,22 @@ static int simple_get_frequency(struct dvb_frontend *fe, u32 *frequency)
602 return 0; 969 return 0;
603} 970}
604 971
972static int simple_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
973{
974 struct tuner_simple_priv *priv = fe->tuner_priv;
975 *bandwidth = priv->bandwidth;
976 return 0;
977}
978
605static struct dvb_tuner_ops simple_tuner_ops = { 979static struct dvb_tuner_ops simple_tuner_ops = {
980 .init = simple_init,
981 .sleep = simple_sleep,
606 .set_analog_params = simple_set_params, 982 .set_analog_params = simple_set_params,
983 .set_params = simple_dvb_set_params,
984 .calc_regs = simple_dvb_calc_regs,
607 .release = simple_release, 985 .release = simple_release,
608 .get_frequency = simple_get_frequency, 986 .get_frequency = simple_get_frequency,
987 .get_bandwidth = simple_get_bandwidth,
609 .get_status = simple_get_status, 988 .get_status = simple_get_status,
610 .get_rf_strength = simple_get_rf_strength, 989 .get_rf_strength = simple_get_rf_strength,
611}; 990};
@@ -613,30 +992,92 @@ static struct dvb_tuner_ops simple_tuner_ops = {
613struct dvb_frontend *simple_tuner_attach(struct dvb_frontend *fe, 992struct dvb_frontend *simple_tuner_attach(struct dvb_frontend *fe,
614 struct i2c_adapter *i2c_adap, 993 struct i2c_adapter *i2c_adap,
615 u8 i2c_addr, 994 u8 i2c_addr,
616 struct simple_tuner_config *cfg) 995 unsigned int type)
617{ 996{
618 struct tuner_simple_priv *priv = NULL; 997 struct tuner_simple_priv *priv = NULL;
998 int instance;
619 999
620 priv = kzalloc(sizeof(struct tuner_simple_priv), GFP_KERNEL); 1000 if (type >= tuner_count) {
621 if (priv == NULL) 1001 printk(KERN_WARNING "%s: invalid tuner type: %d (max: %d)\n",
1002 __func__, type, tuner_count-1);
622 return NULL; 1003 return NULL;
623 fe->tuner_priv = priv; 1004 }
624 1005
625 priv->i2c_props.addr = i2c_addr; 1006 /* If i2c_adap is set, check that the tuner is at the correct address.
626 priv->i2c_props.adap = i2c_adap; 1007 * Otherwise, if i2c_adap is NULL, the tuner will be programmed directly
627 priv->type = cfg->type; 1008 * by the digital demod via calc_regs.
628 priv->tun = cfg->tun; 1009 */
1010 if (i2c_adap != NULL) {
1011 u8 b[1];
1012 struct i2c_msg msg = {
1013 .addr = i2c_addr, .flags = I2C_M_RD,
1014 .buf = b, .len = 1,
1015 };
1016
1017 if (fe->ops.i2c_gate_ctrl)
1018 fe->ops.i2c_gate_ctrl(fe, 1);
1019
1020 if (1 != i2c_transfer(i2c_adap, &msg, 1))
1021 tuner_warn("unable to probe %s, proceeding anyway.",
1022 tuners[type].name);
1023
1024 if (fe->ops.i2c_gate_ctrl)
1025 fe->ops.i2c_gate_ctrl(fe, 0);
1026 }
629 1027
630 memcpy(&fe->ops.tuner_ops, &simple_tuner_ops, sizeof(struct dvb_tuner_ops)); 1028 mutex_lock(&tuner_simple_list_mutex);
631 1029
632 tuner_info("type set to %d (%s)\n", cfg->type, cfg->tun->name); 1030 instance = hybrid_tuner_request_state(struct tuner_simple_priv, priv,
1031 hybrid_tuner_instance_list,
1032 i2c_adap, i2c_addr,
1033 "tuner-simple");
1034 switch (instance) {
1035 case 0:
1036 mutex_unlock(&tuner_simple_list_mutex);
1037 return NULL;
1038 break;
1039 case 1:
1040 fe->tuner_priv = priv;
633 1041
634 strlcpy(fe->ops.tuner_ops.info.name, cfg->tun->name, sizeof(fe->ops.tuner_ops.info.name)); 1042 priv->type = type;
1043 priv->tun = &tuners[type];
1044 priv->nr = simple_devcount++;
1045 break;
1046 default:
1047 fe->tuner_priv = priv;
1048 break;
1049 }
635 1050
636 return fe; 1051 mutex_unlock(&tuner_simple_list_mutex);
637} 1052
1053 memcpy(&fe->ops.tuner_ops, &simple_tuner_ops,
1054 sizeof(struct dvb_tuner_ops));
1055
1056 tuner_info("type set to %d (%s)\n", type, priv->tun->name);
1057
1058 if ((debug) || ((atv_input[priv->nr] > 0) ||
1059 (dtv_input[priv->nr] > 0))) {
1060 if (0 == atv_input[priv->nr])
1061 tuner_info("tuner %d atv rf input will be "
1062 "autoselected\n", priv->nr);
1063 else
1064 tuner_info("tuner %d atv rf input will be "
1065 "set to input %d (insmod option)\n",
1066 priv->nr, atv_input[priv->nr]);
1067 if (0 == dtv_input[priv->nr])
1068 tuner_info("tuner %d dtv rf input will be "
1069 "autoselected\n", priv->nr);
1070 else
1071 tuner_info("tuner %d dtv rf input will be "
1072 "set to input %d (insmod option)\n",
1073 priv->nr, dtv_input[priv->nr]);
1074 }
638 1075
1076 strlcpy(fe->ops.tuner_ops.info.name, priv->tun->name,
1077 sizeof(fe->ops.tuner_ops.info.name));
639 1078
1079 return fe;
1080}
640EXPORT_SYMBOL_GPL(simple_tuner_attach); 1081EXPORT_SYMBOL_GPL(simple_tuner_attach);
641 1082
642MODULE_DESCRIPTION("Simple 4-control-bytes style tuner driver"); 1083MODULE_DESCRIPTION("Simple 4-control-bytes style tuner driver");
diff --git a/drivers/media/video/tuner-simple.h b/drivers/media/video/tuner-simple.h
index 9089939a8c02..e46cf0121e03 100644
--- a/drivers/media/video/tuner-simple.h
+++ b/drivers/media/video/tuner-simple.h
@@ -20,25 +20,18 @@
20#include <linux/i2c.h> 20#include <linux/i2c.h>
21#include "dvb_frontend.h" 21#include "dvb_frontend.h"
22 22
23struct simple_tuner_config
24{
25 /* chip type */
26 unsigned int type;
27 struct tunertype *tun;
28};
29
30#if defined(CONFIG_TUNER_SIMPLE) || (defined(CONFIG_TUNER_SIMPLE_MODULE) && defined(MODULE)) 23#if defined(CONFIG_TUNER_SIMPLE) || (defined(CONFIG_TUNER_SIMPLE_MODULE) && defined(MODULE))
31extern struct dvb_frontend *simple_tuner_attach(struct dvb_frontend *fe, 24extern struct dvb_frontend *simple_tuner_attach(struct dvb_frontend *fe,
32 struct i2c_adapter *i2c_adap, 25 struct i2c_adapter *i2c_adap,
33 u8 i2c_addr, 26 u8 i2c_addr,
34 struct simple_tuner_config *cfg); 27 unsigned int type);
35#else 28#else
36static inline struct dvb_frontend *simple_tuner_attach(struct dvb_frontend *fe, 29static inline struct dvb_frontend *simple_tuner_attach(struct dvb_frontend *fe,
37 struct i2c_adapter *i2c_adap, 30 struct i2c_adapter *i2c_adap,
38 u8 i2c_addr, 31 u8 i2c_addr,
39 struct simple_tuner_config *cfg) 32 unsigned int type)
40{ 33{
41 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__); 34 printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
42 return NULL; 35 return NULL;
43} 36}
44#endif 37#endif
diff --git a/drivers/media/video/tuner-types.c b/drivers/media/video/tuner-types.c
index 883047f9c28c..10dddca8b5d1 100644
--- a/drivers/media/video/tuner-types.c
+++ b/drivers/media/video/tuner-types.c
@@ -35,6 +35,27 @@
35 * based on the video standard in use. 35 * based on the video standard in use.
36 */ 36 */
37 37
38/* The following was taken from dvb-pll.c: */
39
40/* Set AGC TOP value to 103 dBuV:
41 * 0x80 = Control Byte
42 * 0x40 = 250 uA charge pump (irrelevant)
43 * 0x18 = Aux Byte to follow
44 * 0x06 = 64.5 kHz divider (irrelevant)
45 * 0x01 = Disable Vt (aka sleep)
46 *
47 * 0x00 = AGC Time constant 2s Iagc = 300 nA (vs 0x80 = 9 nA)
48 * 0x50 = AGC Take over point = 103 dBuV
49 */
50static u8 tua603x_agc103[] = { 2, 0x80|0x40|0x18|0x06|0x01, 0x00|0x50 };
51
52/* 0x04 = 166.67 kHz divider
53 *
54 * 0x80 = AGC Time constant 50ms Iagc = 9 uA
55 * 0x20 = AGC Take over point = 112 dBuV
56 */
57static u8 tua603x_agc112[] = { 2, 0x80|0x40|0x18|0x04|0x01, 0x80|0x20 };
58
38/* 0-9 */ 59/* 0-9 */
39/* ------------ TUNER_TEMIC_PAL - TEMIC PAL ------------ */ 60/* ------------ TUNER_TEMIC_PAL - TEMIC PAL ------------ */
40 61
@@ -594,19 +615,31 @@ static struct tuner_params tuner_philips_pal_mk_params[] = {
594 }, 615 },
595}; 616};
596 617
597/* ---- TUNER_PHILIPS_ATSC - Philips FCV1236D (ATSC/NTSC) ---- */ 618/* ---- TUNER_PHILIPS_FCV1236D - Philips FCV1236D (ATSC/NTSC) ---- */
598 619
599static struct tuner_range tuner_philips_fcv1236d_ranges[] = { 620static struct tuner_range tuner_philips_fcv1236d_ntsc_ranges[] = {
600 { 16 * 157.25 /*MHz*/, 0x8e, 0xa0, }, 621 { 16 * 157.25 /*MHz*/, 0x8e, 0xa2, },
601 { 16 * 451.25 /*MHz*/, 0x8e, 0x90, }, 622 { 16 * 451.25 /*MHz*/, 0x8e, 0x92, },
623 { 16 * 999.99 , 0x8e, 0x32, },
624};
625
626static struct tuner_range tuner_philips_fcv1236d_atsc_ranges[] = {
627 { 16 * 159.00 /*MHz*/, 0x8e, 0xa0, },
628 { 16 * 453.00 /*MHz*/, 0x8e, 0x90, },
602 { 16 * 999.99 , 0x8e, 0x30, }, 629 { 16 * 999.99 , 0x8e, 0x30, },
603}; 630};
604 631
605static struct tuner_params tuner_philips_fcv1236d_params[] = { 632static struct tuner_params tuner_philips_fcv1236d_params[] = {
606 { 633 {
607 .type = TUNER_PARAM_TYPE_NTSC, 634 .type = TUNER_PARAM_TYPE_NTSC,
608 .ranges = tuner_philips_fcv1236d_ranges, 635 .ranges = tuner_philips_fcv1236d_ntsc_ranges,
609 .count = ARRAY_SIZE(tuner_philips_fcv1236d_ranges), 636 .count = ARRAY_SIZE(tuner_philips_fcv1236d_ntsc_ranges),
637 },
638 {
639 .type = TUNER_PARAM_TYPE_DIGITAL,
640 .ranges = tuner_philips_fcv1236d_atsc_ranges,
641 .count = ARRAY_SIZE(tuner_philips_fcv1236d_atsc_ranges),
642 .iffreq = 16 * 44.00,
610 }, 643 },
611}; 644};
612 645
@@ -701,12 +734,24 @@ static struct tuner_range tuner_microtune_4042fi5_ntsc_ranges[] = {
701 { 16 * 999.99 , 0x8e, 0x31, }, 734 { 16 * 999.99 , 0x8e, 0x31, },
702}; 735};
703 736
737static struct tuner_range tuner_microtune_4042fi5_atsc_ranges[] = {
738 { 16 * 162.00 /*MHz*/, 0x8e, 0xa1, },
739 { 16 * 457.00 /*MHz*/, 0x8e, 0x91, },
740 { 16 * 999.99 , 0x8e, 0x31, },
741};
742
704static struct tuner_params tuner_microtune_4042fi5_params[] = { 743static struct tuner_params tuner_microtune_4042fi5_params[] = {
705 { 744 {
706 .type = TUNER_PARAM_TYPE_NTSC, 745 .type = TUNER_PARAM_TYPE_NTSC,
707 .ranges = tuner_microtune_4042fi5_ntsc_ranges, 746 .ranges = tuner_microtune_4042fi5_ntsc_ranges,
708 .count = ARRAY_SIZE(tuner_microtune_4042fi5_ntsc_ranges), 747 .count = ARRAY_SIZE(tuner_microtune_4042fi5_ntsc_ranges),
709 }, 748 },
749 {
750 .type = TUNER_PARAM_TYPE_DIGITAL,
751 .ranges = tuner_microtune_4042fi5_atsc_ranges,
752 .count = ARRAY_SIZE(tuner_microtune_4042fi5_atsc_ranges),
753 .iffreq = 16 * 44.00 /*MHz*/,
754 },
710}; 755};
711 756
712/* 50-59 */ 757/* 50-59 */
@@ -740,6 +785,7 @@ static struct tuner_params tuner_philips_fm1256_ih3_params[] = {
740 785
741/* ------------ TUNER_THOMSON_DTT7610 - THOMSON ATSC ------------ */ 786/* ------------ TUNER_THOMSON_DTT7610 - THOMSON ATSC ------------ */
742 787
788/* single range used for both ntsc and atsc */
743static struct tuner_range tuner_thomson_dtt7610_ntsc_ranges[] = { 789static struct tuner_range tuner_thomson_dtt7610_ntsc_ranges[] = {
744 { 16 * 157.25 /*MHz*/, 0x8e, 0x39, }, 790 { 16 * 157.25 /*MHz*/, 0x8e, 0x39, },
745 { 16 * 454.00 /*MHz*/, 0x8e, 0x3a, }, 791 { 16 * 454.00 /*MHz*/, 0x8e, 0x3a, },
@@ -752,6 +798,12 @@ static struct tuner_params tuner_thomson_dtt7610_params[] = {
752 .ranges = tuner_thomson_dtt7610_ntsc_ranges, 798 .ranges = tuner_thomson_dtt7610_ntsc_ranges,
753 .count = ARRAY_SIZE(tuner_thomson_dtt7610_ntsc_ranges), 799 .count = ARRAY_SIZE(tuner_thomson_dtt7610_ntsc_ranges),
754 }, 800 },
801 {
802 .type = TUNER_PARAM_TYPE_DIGITAL,
803 .ranges = tuner_thomson_dtt7610_ntsc_ranges,
804 .count = ARRAY_SIZE(tuner_thomson_dtt7610_ntsc_ranges),
805 .iffreq = 16 * 44.00 /*MHz*/,
806 },
755}; 807};
756 808
757/* ------------ TUNER_PHILIPS_FQ1286 - Philips NTSC ------------ */ 809/* ------------ TUNER_PHILIPS_FQ1286 - Philips NTSC ------------ */
@@ -855,6 +907,11 @@ static struct tuner_range tuner_thomson_dtt761x_ntsc_ranges[] = {
855 { 16 * 999.99 , 0x8e, 0x3c, }, 907 { 16 * 999.99 , 0x8e, 0x3c, },
856}; 908};
857 909
910static struct tuner_range tuner_thomson_dtt761x_atsc_ranges[] = {
911 { 16 * 147.00 /*MHz*/, 0x8e, 0x39, },
912 { 16 * 417.00 /*MHz*/, 0x8e, 0x3a, },
913 { 16 * 999.99 , 0x8e, 0x3c, },
914};
858 915
859static struct tuner_params tuner_thomson_dtt761x_params[] = { 916static struct tuner_params tuner_thomson_dtt761x_params[] = {
860 { 917 {
@@ -865,6 +922,12 @@ static struct tuner_params tuner_thomson_dtt761x_params[] = {
865 .fm_gain_normal = 1, 922 .fm_gain_normal = 1,
866 .radio_if = 2, /* 41.3 MHz */ 923 .radio_if = 2, /* 41.3 MHz */
867 }, 924 },
925 {
926 .type = TUNER_PARAM_TYPE_DIGITAL,
927 .ranges = tuner_thomson_dtt761x_atsc_ranges,
928 .count = ARRAY_SIZE(tuner_thomson_dtt761x_atsc_ranges),
929 .iffreq = 16 * 44.00, /*MHz*/
930 },
868}; 931};
869 932
870/* ------------ TUNER_TENA_9533_DI - Philips PAL ------------ */ 933/* ------------ TUNER_TENA_9533_DI - Philips PAL ------------ */
@@ -891,6 +954,15 @@ static struct tuner_range tuner_philips_fmd1216me_mk3_pal_ranges[] = {
891 { 16 * 999.99 , 0x86, 0x54, }, 954 { 16 * 999.99 , 0x86, 0x54, },
892}; 955};
893 956
957static struct tuner_range tuner_philips_fmd1216me_mk3_dvb_ranges[] = {
958 { 16 * 143.87 /*MHz*/, 0xbc, 0x41 },
959 { 16 * 158.87 /*MHz*/, 0xf4, 0x41 },
960 { 16 * 329.87 /*MHz*/, 0xbc, 0x42 },
961 { 16 * 441.87 /*MHz*/, 0xf4, 0x42 },
962 { 16 * 625.87 /*MHz*/, 0xbc, 0x44 },
963 { 16 * 803.87 /*MHz*/, 0xf4, 0x44 },
964 { 16 * 999.99 , 0xfc, 0x44 },
965};
894 966
895static struct tuner_params tuner_philips_fmd1216me_mk3_params[] = { 967static struct tuner_params tuner_philips_fmd1216me_mk3_params[] = {
896 { 968 {
@@ -904,6 +976,12 @@ static struct tuner_params tuner_philips_fmd1216me_mk3_params[] = {
904 .port2_invert_for_secam_lc = 1, 976 .port2_invert_for_secam_lc = 1,
905 .port1_set_for_fm_mono = 1, 977 .port1_set_for_fm_mono = 1,
906 }, 978 },
979 {
980 .type = TUNER_PARAM_TYPE_DIGITAL,
981 .ranges = tuner_philips_fmd1216me_mk3_dvb_ranges,
982 .count = ARRAY_SIZE(tuner_philips_fmd1216me_mk3_dvb_ranges),
983 .iffreq = 16 * 36.125, /*MHz*/
984 },
907}; 985};
908 986
909 987
@@ -915,6 +993,11 @@ static struct tuner_range tuner_tua6034_ntsc_ranges[] = {
915 { 16 * 999.99 , 0x8e, 0x04 }, 993 { 16 * 999.99 , 0x8e, 0x04 },
916}; 994};
917 995
996static struct tuner_range tuner_tua6034_atsc_ranges[] = {
997 { 16 * 165.00 /*MHz*/, 0xce, 0x01 },
998 { 16 * 450.00 /*MHz*/, 0xce, 0x02 },
999 { 16 * 999.99 , 0xce, 0x04 },
1000};
918 1001
919static struct tuner_params tuner_lg_tdvs_h06xf_params[] = { 1002static struct tuner_params tuner_lg_tdvs_h06xf_params[] = {
920 { 1003 {
@@ -922,6 +1005,12 @@ static struct tuner_params tuner_lg_tdvs_h06xf_params[] = {
922 .ranges = tuner_tua6034_ntsc_ranges, 1005 .ranges = tuner_tua6034_ntsc_ranges,
923 .count = ARRAY_SIZE(tuner_tua6034_ntsc_ranges), 1006 .count = ARRAY_SIZE(tuner_tua6034_ntsc_ranges),
924 }, 1007 },
1008 {
1009 .type = TUNER_PARAM_TYPE_DIGITAL,
1010 .ranges = tuner_tua6034_atsc_ranges,
1011 .count = ARRAY_SIZE(tuner_tua6034_atsc_ranges),
1012 .iffreq = 16 * 44.00,
1013 },
925}; 1014};
926 1015
927/* ------------ TUNER_YMEC_TVF66T5_B_DFF - Philips PAL ------------ */ 1016/* ------------ TUNER_YMEC_TVF66T5_B_DFF - Philips PAL ------------ */
@@ -974,12 +1063,30 @@ static struct tuner_range tuner_philips_td1316_pal_ranges[] = {
974 { 16 * 999.99 , 0xc8, 0xa4, }, 1063 { 16 * 999.99 , 0xc8, 0xa4, },
975}; 1064};
976 1065
1066static struct tuner_range tuner_philips_td1316_dvb_ranges[] = {
1067 { 16 * 93.834 /*MHz*/, 0xca, 0x60, },
1068 { 16 * 123.834 /*MHz*/, 0xca, 0xa0, },
1069 { 16 * 163.834 /*MHz*/, 0xca, 0xc0, },
1070 { 16 * 253.834 /*MHz*/, 0xca, 0x60, },
1071 { 16 * 383.834 /*MHz*/, 0xca, 0xa0, },
1072 { 16 * 443.834 /*MHz*/, 0xca, 0xc0, },
1073 { 16 * 583.834 /*MHz*/, 0xca, 0x60, },
1074 { 16 * 793.834 /*MHz*/, 0xca, 0xa0, },
1075 { 16 * 999.999 , 0xca, 0xe0, },
1076};
1077
977static struct tuner_params tuner_philips_td1316_params[] = { 1078static struct tuner_params tuner_philips_td1316_params[] = {
978 { 1079 {
979 .type = TUNER_PARAM_TYPE_PAL, 1080 .type = TUNER_PARAM_TYPE_PAL,
980 .ranges = tuner_philips_td1316_pal_ranges, 1081 .ranges = tuner_philips_td1316_pal_ranges,
981 .count = ARRAY_SIZE(tuner_philips_td1316_pal_ranges), 1082 .count = ARRAY_SIZE(tuner_philips_td1316_pal_ranges),
982 }, 1083 },
1084 {
1085 .type = TUNER_PARAM_TYPE_DIGITAL,
1086 .ranges = tuner_philips_td1316_dvb_ranges,
1087 .count = ARRAY_SIZE(tuner_philips_td1316_dvb_ranges),
1088 .iffreq = 16 * 36.166667 /*MHz*/,
1089 },
983}; 1090};
984 1091
985/* ------------ TUNER_PHILIPS_TUV1236D - Philips ATSC ------------ */ 1092/* ------------ TUNER_PHILIPS_TUV1236D - Philips ATSC ------------ */
@@ -990,6 +1097,11 @@ static struct tuner_range tuner_tuv1236d_ntsc_ranges[] = {
990 { 16 * 999.99 , 0xce, 0x04, }, 1097 { 16 * 999.99 , 0xce, 0x04, },
991}; 1098};
992 1099
1100static struct tuner_range tuner_tuv1236d_atsc_ranges[] = {
1101 { 16 * 157.25 /*MHz*/, 0xc6, 0x41, },
1102 { 16 * 454.00 /*MHz*/, 0xc6, 0x42, },
1103 { 16 * 999.99 , 0xc6, 0x44, },
1104};
993 1105
994static struct tuner_params tuner_tuv1236d_params[] = { 1106static struct tuner_params tuner_tuv1236d_params[] = {
995 { 1107 {
@@ -997,6 +1109,12 @@ static struct tuner_params tuner_tuv1236d_params[] = {
997 .ranges = tuner_tuv1236d_ntsc_ranges, 1109 .ranges = tuner_tuv1236d_ntsc_ranges,
998 .count = ARRAY_SIZE(tuner_tuv1236d_ntsc_ranges), 1110 .count = ARRAY_SIZE(tuner_tuv1236d_ntsc_ranges),
999 }, 1111 },
1112 {
1113 .type = TUNER_PARAM_TYPE_DIGITAL,
1114 .ranges = tuner_tuv1236d_atsc_ranges,
1115 .count = ARRAY_SIZE(tuner_tuv1236d_atsc_ranges),
1116 .iffreq = 16 * 44.00,
1117 },
1000}; 1118};
1001 1119
1002/* ------------ TUNER_TNF_xxx5 - Texas Instruments--------- */ 1120/* ------------ TUNER_TNF_xxx5 - Texas Instruments--------- */
@@ -1050,17 +1168,30 @@ static struct tuner_params tuner_samsung_tcpn_2121p30a_params[] = {
1050 1168
1051/* ------------ TUNER_THOMSON_FE6600 - DViCO Hybrid PAL ------------ */ 1169/* ------------ TUNER_THOMSON_FE6600 - DViCO Hybrid PAL ------------ */
1052 1170
1053static struct tuner_range tuner_thomson_fe6600_ranges[] = { 1171static struct tuner_range tuner_thomson_fe6600_pal_ranges[] = {
1054 { 16 * 160.00 /*MHz*/, 0xfe, 0x11, }, 1172 { 16 * 160.00 /*MHz*/, 0xfe, 0x11, },
1055 { 16 * 442.00 /*MHz*/, 0xf6, 0x12, }, 1173 { 16 * 442.00 /*MHz*/, 0xf6, 0x12, },
1056 { 16 * 999.99 , 0xf6, 0x18, }, 1174 { 16 * 999.99 , 0xf6, 0x18, },
1057}; 1175};
1058 1176
1177static struct tuner_range tuner_thomson_fe6600_dvb_ranges[] = {
1178 { 16 * 250.00 /*MHz*/, 0xb4, 0x12, },
1179 { 16 * 455.00 /*MHz*/, 0xfe, 0x11, },
1180 { 16 * 775.50 /*MHz*/, 0xbc, 0x18, },
1181 { 16 * 999.99 , 0xf4, 0x18, },
1182};
1183
1059static struct tuner_params tuner_thomson_fe6600_params[] = { 1184static struct tuner_params tuner_thomson_fe6600_params[] = {
1060 { 1185 {
1061 .type = TUNER_PARAM_TYPE_PAL, 1186 .type = TUNER_PARAM_TYPE_PAL,
1062 .ranges = tuner_thomson_fe6600_ranges, 1187 .ranges = tuner_thomson_fe6600_pal_ranges,
1063 .count = ARRAY_SIZE(tuner_thomson_fe6600_ranges), 1188 .count = ARRAY_SIZE(tuner_thomson_fe6600_pal_ranges),
1189 },
1190 {
1191 .type = TUNER_PARAM_TYPE_DIGITAL,
1192 .ranges = tuner_thomson_fe6600_dvb_ranges,
1193 .count = ARRAY_SIZE(tuner_thomson_fe6600_dvb_ranges),
1194 .iffreq = 16 * 36.125 /*MHz*/,
1064 }, 1195 },
1065}; 1196};
1066 1197
@@ -1303,10 +1434,13 @@ struct tunertype tuners[] = {
1303 .params = tuner_philips_pal_mk_params, 1434 .params = tuner_philips_pal_mk_params,
1304 .count = ARRAY_SIZE(tuner_philips_pal_mk_params), 1435 .count = ARRAY_SIZE(tuner_philips_pal_mk_params),
1305 }, 1436 },
1306 [TUNER_PHILIPS_ATSC] = { /* Philips ATSC */ 1437 [TUNER_PHILIPS_FCV1236D] = { /* Philips ATSC */
1307 .name = "Philips FCV1236D ATSC/NTSC dual in", 1438 .name = "Philips FCV1236D ATSC/NTSC dual in",
1308 .params = tuner_philips_fcv1236d_params, 1439 .params = tuner_philips_fcv1236d_params,
1309 .count = ARRAY_SIZE(tuner_philips_fcv1236d_params), 1440 .count = ARRAY_SIZE(tuner_philips_fcv1236d_params),
1441 .min = 16 * 53.00,
1442 .max = 16 * 803.00,
1443 .stepsize = 62500,
1310 }, 1444 },
1311 [TUNER_PHILIPS_FM1236_MK3] = { /* Philips NTSC */ 1445 [TUNER_PHILIPS_FM1236_MK3] = { /* Philips NTSC */
1312 .name = "Philips NTSC MK3 (FM1236MK3 or FM1236/F)", 1446 .name = "Philips NTSC MK3 (FM1236MK3 or FM1236/F)",
@@ -1342,6 +1476,9 @@ struct tunertype tuners[] = {
1342 .name = "Microtune 4042 FI5 ATSC/NTSC dual in", 1476 .name = "Microtune 4042 FI5 ATSC/NTSC dual in",
1343 .params = tuner_microtune_4042fi5_params, 1477 .params = tuner_microtune_4042fi5_params,
1344 .count = ARRAY_SIZE(tuner_microtune_4042fi5_params), 1478 .count = ARRAY_SIZE(tuner_microtune_4042fi5_params),
1479 .min = 16 * 57.00,
1480 .max = 16 * 858.00,
1481 .stepsize = 62500,
1345 }, 1482 },
1346 1483
1347 /* 50-59 */ 1484 /* 50-59 */
@@ -1359,6 +1496,9 @@ struct tunertype tuners[] = {
1359 .name = "Thomson DTT 7610 (ATSC/NTSC)", 1496 .name = "Thomson DTT 7610 (ATSC/NTSC)",
1360 .params = tuner_thomson_dtt7610_params, 1497 .params = tuner_thomson_dtt7610_params,
1361 .count = ARRAY_SIZE(tuner_thomson_dtt7610_params), 1498 .count = ARRAY_SIZE(tuner_thomson_dtt7610_params),
1499 .min = 16 * 44.00,
1500 .max = 16 * 958.00,
1501 .stepsize = 62500,
1362 }, 1502 },
1363 [TUNER_PHILIPS_FQ1286] = { /* Philips NTSC */ 1503 [TUNER_PHILIPS_FQ1286] = { /* Philips NTSC */
1364 .name = "Philips FQ1286", 1504 .name = "Philips FQ1286",
@@ -1400,6 +1540,10 @@ struct tunertype tuners[] = {
1400 .name = "Thomson DTT 761X (ATSC/NTSC)", 1540 .name = "Thomson DTT 761X (ATSC/NTSC)",
1401 .params = tuner_thomson_dtt761x_params, 1541 .params = tuner_thomson_dtt761x_params,
1402 .count = ARRAY_SIZE(tuner_thomson_dtt761x_params), 1542 .count = ARRAY_SIZE(tuner_thomson_dtt761x_params),
1543 .min = 16 * 57.00,
1544 .max = 16 * 863.00,
1545 .stepsize = 62500,
1546 .initdata = tua603x_agc103,
1403 }, 1547 },
1404 [TUNER_TENA_9533_DI] = { /* Philips PAL */ 1548 [TUNER_TENA_9533_DI] = { /* Philips PAL */
1405 .name = "Tena TNF9533-D/IF/TNF9533-B/DF", 1549 .name = "Tena TNF9533-D/IF/TNF9533-B/DF",
@@ -1414,11 +1558,20 @@ struct tunertype tuners[] = {
1414 .name = "Philips FMD1216ME MK3 Hybrid Tuner", 1558 .name = "Philips FMD1216ME MK3 Hybrid Tuner",
1415 .params = tuner_philips_fmd1216me_mk3_params, 1559 .params = tuner_philips_fmd1216me_mk3_params,
1416 .count = ARRAY_SIZE(tuner_philips_fmd1216me_mk3_params), 1560 .count = ARRAY_SIZE(tuner_philips_fmd1216me_mk3_params),
1561 .min = 16 * 50.87,
1562 .max = 16 * 858.00,
1563 .stepsize = 166667,
1564 .initdata = tua603x_agc112,
1565 .sleepdata = (u8[]){ 4, 0x9c, 0x60, 0x85, 0x54 },
1417 }, 1566 },
1418 [TUNER_LG_TDVS_H06XF] = { /* LGINNOTEK ATSC */ 1567 [TUNER_LG_TDVS_H06XF] = { /* LGINNOTEK ATSC */
1419 .name = "LG TDVS-H06xF", /* H061F, H062F & H064F */ 1568 .name = "LG TDVS-H06xF", /* H061F, H062F & H064F */
1420 .params = tuner_lg_tdvs_h06xf_params, 1569 .params = tuner_lg_tdvs_h06xf_params,
1421 .count = ARRAY_SIZE(tuner_lg_tdvs_h06xf_params), 1570 .count = ARRAY_SIZE(tuner_lg_tdvs_h06xf_params),
1571 .min = 16 * 54.00,
1572 .max = 16 * 863.00,
1573 .stepsize = 62500,
1574 .initdata = tua603x_agc103,
1422 }, 1575 },
1423 [TUNER_YMEC_TVF66T5_B_DFF] = { /* Philips PAL */ 1576 [TUNER_YMEC_TVF66T5_B_DFF] = { /* Philips PAL */
1424 .name = "Ymec TVF66T5-B/DFF", 1577 .name = "Ymec TVF66T5-B/DFF",
@@ -1434,11 +1587,17 @@ struct tunertype tuners[] = {
1434 .name = "Philips TD1316 Hybrid Tuner", 1587 .name = "Philips TD1316 Hybrid Tuner",
1435 .params = tuner_philips_td1316_params, 1588 .params = tuner_philips_td1316_params,
1436 .count = ARRAY_SIZE(tuner_philips_td1316_params), 1589 .count = ARRAY_SIZE(tuner_philips_td1316_params),
1590 .min = 16 * 87.00,
1591 .max = 16 * 895.00,
1592 .stepsize = 166667,
1437 }, 1593 },
1438 [TUNER_PHILIPS_TUV1236D] = { /* Philips ATSC */ 1594 [TUNER_PHILIPS_TUV1236D] = { /* Philips ATSC */
1439 .name = "Philips TUV1236D ATSC/NTSC dual in", 1595 .name = "Philips TUV1236D ATSC/NTSC dual in",
1440 .params = tuner_tuv1236d_params, 1596 .params = tuner_tuv1236d_params,
1441 .count = ARRAY_SIZE(tuner_tuv1236d_params), 1597 .count = ARRAY_SIZE(tuner_tuv1236d_params),
1598 .min = 16 * 54.00,
1599 .max = 16 * 864.00,
1600 .stepsize = 62500,
1442 }, 1601 },
1443 [TUNER_TNF_5335MF] = { /* Tenna PAL/NTSC */ 1602 [TUNER_TNF_5335MF] = { /* Tenna PAL/NTSC */
1444 .name = "Tena TNF 5335 and similar models", 1603 .name = "Tena TNF 5335 and similar models",
@@ -1460,6 +1619,9 @@ struct tunertype tuners[] = {
1460 .name = "Thomson FE6600", 1619 .name = "Thomson FE6600",
1461 .params = tuner_thomson_fe6600_params, 1620 .params = tuner_thomson_fe6600_params,
1462 .count = ARRAY_SIZE(tuner_thomson_fe6600_params), 1621 .count = ARRAY_SIZE(tuner_thomson_fe6600_params),
1622 .min = 16 * 44.25,
1623 .max = 16 * 858.00,
1624 .stepsize = 166667,
1463 }, 1625 },
1464 [TUNER_SAMSUNG_TCPG_6121P30A] = { /* Samsung PAL */ 1626 [TUNER_SAMSUNG_TCPG_6121P30A] = { /* Samsung PAL */
1465 .name = "Samsung TCPG 6121P30A", 1627 .name = "Samsung TCPG 6121P30A",
@@ -1480,5 +1642,11 @@ struct tunertype tuners[] = {
1480 /* see xc5000.c for details */ 1642 /* see xc5000.c for details */
1481 }, 1643 },
1482}; 1644};
1645EXPORT_SYMBOL(tuners);
1483 1646
1484unsigned const int tuner_count = ARRAY_SIZE(tuners); 1647unsigned const int tuner_count = ARRAY_SIZE(tuners);
1648EXPORT_SYMBOL(tuner_count);
1649
1650MODULE_DESCRIPTION("Simple tuner device type database");
1651MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer");
1652MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/tuner-xc2028-types.h b/drivers/media/video/tuner-xc2028-types.h
index d0057fbf0ec7..74dc46a71f64 100644
--- a/drivers/media/video/tuner-xc2028-types.h
+++ b/drivers/media/video/tuner-xc2028-types.h
@@ -1,6 +1,9 @@
1/* tuner-xc2028_types 1/* tuner-xc2028_types
2 * 2 *
3 * Copyright (c) 2007 Mauro Carvalho Chehab (mchehab@infradead.org) 3 * This file includes internal tipes to be used inside tuner-xc2028.
4 * Shouldn't be included outside tuner-xc2028
5 *
6 * Copyright (c) 2007-2008 Mauro Carvalho Chehab (mchehab@infradead.org)
4 * This code is placed under the terms of the GNU General Public License v2 7 * This code is placed under the terms of the GNU General Public License v2
5 */ 8 */
6 9
@@ -54,11 +57,13 @@
54/* LCD firmwares exist only for MTS STD/MN (PAL or NTSC/M) 57/* LCD firmwares exist only for MTS STD/MN (PAL or NTSC/M)
55 and for non-MTS STD/MN (PAL, NTSC/M or NTSC/Kr) 58 and for non-MTS STD/MN (PAL, NTSC/M or NTSC/Kr)
56 There are variants both with and without NOGD 59 There are variants both with and without NOGD
60 Those firmwares produce better result with LCD displays
57 */ 61 */
58#define LCD (1<<12) 62#define LCD (1<<12)
59 63
60/* NOGD firmwares exist only for MTS STD/MN (PAL or NTSC/M) 64/* NOGD firmwares exist only for MTS STD/MN (PAL or NTSC/M)
61 and for non-MTS STD/MN (PAL, NTSC/M or NTSC/Kr) 65 and for non-MTS STD/MN (PAL, NTSC/M or NTSC/Kr)
66 The NOGD firmwares don't have group delay compensation filter
62 */ 67 */
63#define NOGD (1<<13) 68#define NOGD (1<<13)
64 69
@@ -85,11 +90,19 @@
85/* This flag identifies that the scode table has a new format */ 90/* This flag identifies that the scode table has a new format */
86#define HAS_IF (1 << 30) 91#define HAS_IF (1 << 30)
87 92
88#define SCODE_TYPES (MTS|DTV6|QAM|DTV7|DTV78|DTV8|LCD|NOGD|MONO|ATSC|IF| \ 93/* There are different scode tables for MTS and non-MTS.
89 LG60|ATI638|OREN538|OREN36|TOYOTA388|TOYOTA794| \ 94 The MTS firmwares support mono only
90 DIBCOM52|ZARLINK456|CHINA|F6MHZ|SCODE) 95 */
96#define SCODE_TYPES (SCODE | MTS)
97
91 98
92/* Newer types to be moved to videodev2.h */ 99/* Newer types not defined on videodev2.h.
100 The original idea were to move all those types to videodev2.h, but
101 it seemed overkill, since, with the exception of SECAM/K3, the other
102 types seem to be autodetected.
103 It is not clear where secam/k3 is used, nor we have a feedback of this
104 working or being autodetected by the standard secam firmware.
105 */
93 106
94#define V4L2_STD_SECAM_K3 (0x04000000) 107#define V4L2_STD_SECAM_K3 (0x04000000)
95 108
diff --git a/drivers/media/video/tuner-xc2028.c b/drivers/media/video/tuner-xc2028.c
index 50cf876f020f..cc3db7d79a0d 100644
--- a/drivers/media/video/tuner-xc2028.c
+++ b/drivers/media/video/tuner-xc2028.c
@@ -1,6 +1,6 @@
1/* tuner-xc2028 1/* tuner-xc2028
2 * 2 *
3 * Copyright (c) 2007 Mauro Carvalho Chehab (mchehab@infradead.org) 3 * Copyright (c) 2007-2008 Mauro Carvalho Chehab (mchehab@infradead.org)
4 * 4 *
5 * Copyright (c) 2007 Michel Ludwig (michel.ludwig@gmail.com) 5 * Copyright (c) 2007 Michel Ludwig (michel.ludwig@gmail.com)
6 * - frontend interface 6 * - frontend interface
@@ -23,8 +23,6 @@
23#include "dvb_frontend.h" 23#include "dvb_frontend.h"
24 24
25 25
26#define PREFIX "xc2028"
27
28static int debug; 26static int debug;
29module_param(debug, int, 0644); 27module_param(debug, int, 0644);
30MODULE_PARM_DESC(debug, "enable verbose debug messages"); 28MODULE_PARM_DESC(debug, "enable verbose debug messages");
@@ -43,6 +41,11 @@ MODULE_PARM_DESC(audio_std,
43 "NICAM/A\n" 41 "NICAM/A\n"
44 "NICAM/B\n"); 42 "NICAM/B\n");
45 43
44static char firmware_name[FIRMWARE_NAME_MAX];
45module_param_string(firmware_name, firmware_name, sizeof(firmware_name), 0);
46MODULE_PARM_DESC(firmware_name, "Firmware file name. Allows overriding the "
47 "default firmware name\n");
48
46static LIST_HEAD(xc2028_list); 49static LIST_HEAD(xc2028_list);
47static DEFINE_MUTEX(xc2028_list_mutex); 50static DEFINE_MUTEX(xc2028_list_mutex);
48 51
@@ -127,12 +130,12 @@ struct xc2028_data {
127 _rc; \ 130 _rc; \
128}) 131})
129 132
130static unsigned int xc2028_get_reg(struct xc2028_data *priv, u16 reg, u16 *val) 133static int xc2028_get_reg(struct xc2028_data *priv, u16 reg, u16 *val)
131{ 134{
132 unsigned char buf[2]; 135 unsigned char buf[2];
133 unsigned char ibuf[2]; 136 unsigned char ibuf[2];
134 137
135 tuner_dbg("%s %04x called\n", __FUNCTION__, reg); 138 tuner_dbg("%s %04x called\n", __func__, reg);
136 139
137 buf[0] = reg >> 8; 140 buf[0] = reg >> 8;
138 buf[1] = (unsigned char) reg; 141 buf[1] = (unsigned char) reg;
@@ -145,7 +148,7 @@ static unsigned int xc2028_get_reg(struct xc2028_data *priv, u16 reg, u16 *val)
145} 148}
146 149
147#define dump_firm_type(t) dump_firm_type_and_int_freq(t, 0) 150#define dump_firm_type(t) dump_firm_type_and_int_freq(t, 0)
148void dump_firm_type_and_int_freq(unsigned int type, u16 int_freq) 151static void dump_firm_type_and_int_freq(unsigned int type, u16 int_freq)
149{ 152{
150 if (type & BASE) 153 if (type & BASE)
151 printk("BASE "); 154 printk("BASE ");
@@ -232,6 +235,7 @@ static v4l2_std_id parse_audio_std_option(void)
232static void free_firmware(struct xc2028_data *priv) 235static void free_firmware(struct xc2028_data *priv)
233{ 236{
234 int i; 237 int i;
238 tuner_dbg("%s called\n", __func__);
235 239
236 if (!priv->firm) 240 if (!priv->firm)
237 return; 241 return;
@@ -255,19 +259,24 @@ static int load_all_firmwares(struct dvb_frontend *fe)
255 int rc = 0; 259 int rc = 0;
256 int n, n_array; 260 int n, n_array;
257 char name[33]; 261 char name[33];
262 char *fname;
263
264 tuner_dbg("%s called\n", __func__);
258 265
259 tuner_dbg("%s called\n", __FUNCTION__); 266 if (!firmware_name[0])
267 fname = priv->ctrl.fname;
268 else
269 fname = firmware_name;
260 270
261 tuner_dbg("Reading firmware %s\n", priv->ctrl.fname); 271 tuner_dbg("Reading firmware %s\n", fname);
262 rc = request_firmware(&fw, priv->ctrl.fname, 272 rc = request_firmware(&fw, fname, &priv->i2c_props.adap->dev);
263 &priv->i2c_props.adap->dev);
264 if (rc < 0) { 273 if (rc < 0) {
265 if (rc == -ENOENT) 274 if (rc == -ENOENT)
266 tuner_err("Error: firmware %s not found.\n", 275 tuner_err("Error: firmware %s not found.\n",
267 priv->ctrl.fname); 276 fname);
268 else 277 else
269 tuner_err("Error %d while requesting firmware %s \n", 278 tuner_err("Error %d while requesting firmware %s \n",
270 rc, priv->ctrl.fname); 279 rc, fname);
271 280
272 return rc; 281 return rc;
273 } 282 }
@@ -276,7 +285,7 @@ static int load_all_firmwares(struct dvb_frontend *fe)
276 285
277 if (fw->size < sizeof(name) - 1 + 2 + 2) { 286 if (fw->size < sizeof(name) - 1 + 2 + 2) {
278 tuner_err("Error: firmware file %s has invalid size!\n", 287 tuner_err("Error: firmware file %s has invalid size!\n",
279 priv->ctrl.fname); 288 fname);
280 goto corrupt; 289 goto corrupt;
281 } 290 }
282 291
@@ -291,7 +300,7 @@ static int load_all_firmwares(struct dvb_frontend *fe)
291 p += 2; 300 p += 2;
292 301
293 tuner_info("Loading %d firmware images from %s, type: %s, ver %d.%d\n", 302 tuner_info("Loading %d firmware images from %s, type: %s, ver %d.%d\n",
294 n_array, priv->ctrl.fname, name, 303 n_array, fname, name,
295 priv->firm_version >> 8, priv->firm_version & 0xff); 304 priv->firm_version >> 8, priv->firm_version & 0xff);
296 305
297 priv->firm = kzalloc(sizeof(*priv->firm) * n_array, GFP_KERNEL); 306 priv->firm = kzalloc(sizeof(*priv->firm) * n_array, GFP_KERNEL);
@@ -395,9 +404,9 @@ static int seek_firmware(struct dvb_frontend *fe, unsigned int type,
395{ 404{
396 struct xc2028_data *priv = fe->tuner_priv; 405 struct xc2028_data *priv = fe->tuner_priv;
397 int i, best_i = -1, best_nr_matches = 0; 406 int i, best_i = -1, best_nr_matches = 0;
398 unsigned int ign_firm_type_mask = 0; 407 unsigned int type_mask = 0;
399 408
400 tuner_dbg("%s called, want type=", __FUNCTION__); 409 tuner_dbg("%s called, want type=", __func__);
401 if (debug) { 410 if (debug) {
402 dump_firm_type(type); 411 dump_firm_type(type);
403 printk("(%x), id %016llx.\n", type, (unsigned long long)*id); 412 printk("(%x), id %016llx.\n", type, (unsigned long long)*id);
@@ -412,18 +421,23 @@ static int seek_firmware(struct dvb_frontend *fe, unsigned int type,
412 *id = V4L2_STD_PAL; 421 *id = V4L2_STD_PAL;
413 422
414 if (type & BASE) 423 if (type & BASE)
415 type &= BASE_TYPES; 424 type_mask = BASE_TYPES;
416 else if (type & SCODE) { 425 else if (type & SCODE) {
417 type &= SCODE_TYPES; 426 type &= SCODE_TYPES;
418 ign_firm_type_mask = HAS_IF; 427 type_mask = SCODE_TYPES & ~HAS_IF;
419 } else if (type & DTV_TYPES) 428 } else if (type & DTV_TYPES)
420 type &= DTV_TYPES; 429 type_mask = DTV_TYPES;
421 else if (type & STD_SPECIFIC_TYPES) 430 else if (type & STD_SPECIFIC_TYPES)
422 type &= STD_SPECIFIC_TYPES; 431 type_mask = STD_SPECIFIC_TYPES;
432
433 type &= type_mask;
434
435 if (!type & SCODE)
436 type_mask = ~0;
423 437
424 /* Seek for exact match */ 438 /* Seek for exact match */
425 for (i = 0; i < priv->firm_size; i++) { 439 for (i = 0; i < priv->firm_size; i++) {
426 if ((type == (priv->firm[i].type & ~ign_firm_type_mask)) && 440 if ((type == (priv->firm[i].type & type_mask)) &&
427 (*id == priv->firm[i].id)) 441 (*id == priv->firm[i].id))
428 goto found; 442 goto found;
429 } 443 }
@@ -433,7 +447,7 @@ static int seek_firmware(struct dvb_frontend *fe, unsigned int type,
433 v4l2_std_id match_mask; 447 v4l2_std_id match_mask;
434 int nr_matches; 448 int nr_matches;
435 449
436 if (type != (priv->firm[i].type & ~ign_firm_type_mask)) 450 if (type != (priv->firm[i].type & type_mask))
437 continue; 451 continue;
438 452
439 match_mask = *id & priv->firm[i].id; 453 match_mask = *id & priv->firm[i].id;
@@ -483,7 +497,7 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type,
483 int pos, rc; 497 int pos, rc;
484 unsigned char *p, *endp, buf[priv->ctrl.max_len]; 498 unsigned char *p, *endp, buf[priv->ctrl.max_len];
485 499
486 tuner_dbg("%s called\n", __FUNCTION__); 500 tuner_dbg("%s called\n", __func__);
487 501
488 pos = seek_firmware(fe, type, id); 502 pos = seek_firmware(fe, type, id);
489 if (pos < 0) 503 if (pos < 0)
@@ -586,7 +600,7 @@ static int load_scode(struct dvb_frontend *fe, unsigned int type,
586 int pos, rc; 600 int pos, rc;
587 unsigned char *p; 601 unsigned char *p;
588 602
589 tuner_dbg("%s called\n", __FUNCTION__); 603 tuner_dbg("%s called\n", __func__);
590 604
591 if (!int_freq) { 605 if (!int_freq) {
592 pos = seek_firmware(fe, type, id); 606 pos = seek_firmware(fe, type, id);
@@ -650,7 +664,7 @@ static int check_firmware(struct dvb_frontend *fe, unsigned int type,
650 u16 version, hwmodel; 664 u16 version, hwmodel;
651 v4l2_std_id std0; 665 v4l2_std_id std0;
652 666
653 tuner_dbg("%s called\n", __FUNCTION__); 667 tuner_dbg("%s called\n", __func__);
654 668
655 if (!priv->firm) { 669 if (!priv->firm) {
656 if (!priv->ctrl.fname) { 670 if (!priv->ctrl.fname) {
@@ -770,10 +784,10 @@ check_device:
770 goto fail; 784 goto fail;
771 } 785 }
772 786
773 tuner_info("Device is Xceive %d version %d.%d, " 787 tuner_dbg("Device is Xceive %d version %d.%d, "
774 "firmware version %d.%d\n", 788 "firmware version %d.%d\n",
775 hwmodel, (version & 0xf000) >> 12, (version & 0xf00) >> 8, 789 hwmodel, (version & 0xf000) >> 12, (version & 0xf00) >> 8,
776 (version & 0xf0) >> 4, version & 0xf); 790 (version & 0xf0) >> 4, version & 0xf);
777 791
778 /* Check firmware version against what we downloaded. */ 792 /* Check firmware version against what we downloaded. */
779 if (priv->firm_version != ((version & 0xf0) << 4 | (version & 0x0f))) { 793 if (priv->firm_version != ((version & 0xf0) << 4 | (version & 0x0f))) {
@@ -824,27 +838,34 @@ static int xc2028_signal(struct dvb_frontend *fe, u16 *strength)
824 u16 frq_lock, signal = 0; 838 u16 frq_lock, signal = 0;
825 int rc; 839 int rc;
826 840
827 tuner_dbg("%s called\n", __FUNCTION__); 841 tuner_dbg("%s called\n", __func__);
828 842
829 mutex_lock(&priv->lock); 843 mutex_lock(&priv->lock);
830 844
831 /* Sync Lock Indicator */ 845 /* Sync Lock Indicator */
832 rc = xc2028_get_reg(priv, 0x0002, &frq_lock); 846 rc = xc2028_get_reg(priv, 0x0002, &frq_lock);
833 if (rc < 0 || frq_lock == 0) 847 if (rc < 0)
834 goto ret; 848 goto ret;
835 849
836 /* Frequency is locked. Return signal quality */ 850 /* Frequency is locked */
851 if (frq_lock == 1)
852 signal = 32768;
837 853
838 /* Get SNR of the video signal */ 854 /* Get SNR of the video signal */
839 rc = xc2028_get_reg(priv, 0x0040, &signal); 855 rc = xc2028_get_reg(priv, 0x0040, &signal);
840 if (rc < 0) 856 if (rc < 0)
841 signal = -frq_lock; 857 goto ret;
858
859 /* Use both frq_lock and signal to generate the result */
860 signal = signal || ((signal & 0x07) << 12);
842 861
843ret: 862ret:
844 mutex_unlock(&priv->lock); 863 mutex_unlock(&priv->lock);
845 864
846 *strength = signal; 865 *strength = signal;
847 866
867 tuner_dbg("signal strength is %d\n", signal);
868
848 return rc; 869 return rc;
849} 870}
850 871
@@ -861,7 +882,7 @@ static int generic_set_freq(struct dvb_frontend *fe, u32 freq /* in HZ */,
861 unsigned char buf[4]; 882 unsigned char buf[4];
862 u32 div, offset = 0; 883 u32 div, offset = 0;
863 884
864 tuner_dbg("%s called\n", __FUNCTION__); 885 tuner_dbg("%s called\n", __func__);
865 886
866 mutex_lock(&priv->lock); 887 mutex_lock(&priv->lock);
867 888
@@ -906,9 +927,11 @@ static int generic_set_freq(struct dvb_frontend *fe, u32 freq /* in HZ */,
906 if (rc < 0) 927 if (rc < 0)
907 goto ret; 928 goto ret;
908 929
909 rc = priv->tuner_callback(priv->video_dev, XC2028_RESET_CLK, 1); 930 /* Return code shouldn't be checked.
910 if (rc < 0) 931 The reset CLK is needed only with tm6000.
911 goto ret; 932 Driver should work fine even if this fails.
933 */
934 priv->tuner_callback(priv->video_dev, XC2028_RESET_CLK, 1);
912 935
913 msleep(10); 936 msleep(10);
914 937
@@ -942,7 +965,7 @@ static int xc2028_set_analog_freq(struct dvb_frontend *fe,
942 struct xc2028_data *priv = fe->tuner_priv; 965 struct xc2028_data *priv = fe->tuner_priv;
943 unsigned int type=0; 966 unsigned int type=0;
944 967
945 tuner_dbg("%s called\n", __FUNCTION__); 968 tuner_dbg("%s called\n", __func__);
946 969
947 if (p->mode == V4L2_TUNER_RADIO) { 970 if (p->mode == V4L2_TUNER_RADIO) {
948 type |= FM; 971 type |= FM;
@@ -975,7 +998,7 @@ static int xc2028_set_params(struct dvb_frontend *fe,
975 fe_bandwidth_t bw = BANDWIDTH_8_MHZ; 998 fe_bandwidth_t bw = BANDWIDTH_8_MHZ;
976 u16 demod = 0; 999 u16 demod = 0;
977 1000
978 tuner_dbg("%s called\n", __FUNCTION__); 1001 tuner_dbg("%s called\n", __func__);
979 1002
980 if (priv->ctrl.d2633) 1003 if (priv->ctrl.d2633)
981 type |= D2633; 1004 type |= D2633;
@@ -1040,33 +1063,12 @@ static int xc2028_set_params(struct dvb_frontend *fe,
1040 T_DIGITAL_TV, type, 0, demod); 1063 T_DIGITAL_TV, type, 0, demod);
1041} 1064}
1042 1065
1043static int xc2028_sleep(struct dvb_frontend *fe)
1044{
1045 struct xc2028_data *priv = fe->tuner_priv;
1046 int rc = 0;
1047
1048 tuner_dbg("%s called\n", __FUNCTION__);
1049
1050 mutex_lock(&priv->lock);
1051
1052 if (priv->firm_version < 0x0202)
1053 rc = send_seq(priv, {0x00, 0x08, 0x00, 0x00});
1054 else
1055 rc = send_seq(priv, {0x80, 0x08, 0x00, 0x00});
1056
1057 priv->cur_fw.type = 0; /* need firmware reload */
1058
1059 mutex_unlock(&priv->lock);
1060
1061 return rc;
1062}
1063
1064 1066
1065static int xc2028_dvb_release(struct dvb_frontend *fe) 1067static int xc2028_dvb_release(struct dvb_frontend *fe)
1066{ 1068{
1067 struct xc2028_data *priv = fe->tuner_priv; 1069 struct xc2028_data *priv = fe->tuner_priv;
1068 1070
1069 tuner_dbg("%s called\n", __FUNCTION__); 1071 tuner_dbg("%s called\n", __func__);
1070 1072
1071 mutex_lock(&xc2028_list_mutex); 1073 mutex_lock(&xc2028_list_mutex);
1072 1074
@@ -1091,7 +1093,7 @@ static int xc2028_get_frequency(struct dvb_frontend *fe, u32 *frequency)
1091{ 1093{
1092 struct xc2028_data *priv = fe->tuner_priv; 1094 struct xc2028_data *priv = fe->tuner_priv;
1093 1095
1094 tuner_dbg("%s called\n", __FUNCTION__); 1096 tuner_dbg("%s called\n", __func__);
1095 1097
1096 *frequency = priv->frequency; 1098 *frequency = priv->frequency;
1097 1099
@@ -1104,25 +1106,25 @@ static int xc2028_set_config(struct dvb_frontend *fe, void *priv_cfg)
1104 struct xc2028_ctrl *p = priv_cfg; 1106 struct xc2028_ctrl *p = priv_cfg;
1105 int rc = 0; 1107 int rc = 0;
1106 1108
1107 tuner_dbg("%s called\n", __FUNCTION__); 1109 tuner_dbg("%s called\n", __func__);
1108 1110
1109 mutex_lock(&priv->lock); 1111 mutex_lock(&priv->lock);
1110 1112
1111 kfree(priv->ctrl.fname);
1112 free_firmware(priv);
1113
1114 memcpy(&priv->ctrl, p, sizeof(priv->ctrl)); 1113 memcpy(&priv->ctrl, p, sizeof(priv->ctrl));
1115 priv->ctrl.fname = NULL; 1114 if (priv->ctrl.max_len < 9)
1115 priv->ctrl.max_len = 13;
1116 1116
1117 if (p->fname) { 1117 if (p->fname) {
1118 if (priv->ctrl.fname && strcmp(p->fname, priv->ctrl.fname)) {
1119 kfree(priv->ctrl.fname);
1120 free_firmware(priv);
1121 }
1122
1118 priv->ctrl.fname = kstrdup(p->fname, GFP_KERNEL); 1123 priv->ctrl.fname = kstrdup(p->fname, GFP_KERNEL);
1119 if (priv->ctrl.fname == NULL) 1124 if (priv->ctrl.fname == NULL)
1120 rc = -ENOMEM; 1125 rc = -ENOMEM;
1121 } 1126 }
1122 1127
1123 if (priv->ctrl.max_len < 9)
1124 priv->ctrl.max_len = 13;
1125
1126 mutex_unlock(&priv->lock); 1128 mutex_unlock(&priv->lock);
1127 1129
1128 return rc; 1130 return rc;
@@ -1142,8 +1144,6 @@ static const struct dvb_tuner_ops xc2028_dvb_tuner_ops = {
1142 .get_frequency = xc2028_get_frequency, 1144 .get_frequency = xc2028_get_frequency,
1143 .get_rf_strength = xc2028_signal, 1145 .get_rf_strength = xc2028_signal,
1144 .set_params = xc2028_set_params, 1146 .set_params = xc2028_set_params,
1145 .sleep = xc2028_sleep,
1146
1147}; 1147};
1148 1148
1149struct dvb_frontend *xc2028_attach(struct dvb_frontend *fe, 1149struct dvb_frontend *xc2028_attach(struct dvb_frontend *fe,
@@ -1153,23 +1153,29 @@ struct dvb_frontend *xc2028_attach(struct dvb_frontend *fe,
1153 void *video_dev; 1153 void *video_dev;
1154 1154
1155 if (debug) 1155 if (debug)
1156 printk(KERN_DEBUG PREFIX ": Xcv2028/3028 init called!\n"); 1156 printk(KERN_DEBUG "xc2028: Xcv2028/3028 init called!\n");
1157 1157
1158 if (NULL == cfg || NULL == cfg->video_dev) 1158 if (NULL == cfg)
1159 return NULL; 1159 return NULL;
1160 1160
1161 if (!fe) { 1161 if (!fe) {
1162 printk(KERN_ERR PREFIX ": No frontend!\n"); 1162 printk(KERN_ERR "xc2028: No frontend!\n");
1163 return NULL; 1163 return NULL;
1164 } 1164 }
1165 1165
1166 video_dev = cfg->video_dev; 1166 video_dev = cfg->i2c_adap->algo_data;
1167
1168 if (debug)
1169 printk(KERN_DEBUG "xc2028: video_dev =%p\n", video_dev);
1167 1170
1168 mutex_lock(&xc2028_list_mutex); 1171 mutex_lock(&xc2028_list_mutex);
1169 1172
1170 list_for_each_entry(priv, &xc2028_list, xc2028_list) { 1173 list_for_each_entry(priv, &xc2028_list, xc2028_list) {
1171 if (priv->video_dev == cfg->video_dev) { 1174 if (&priv->i2c_props.adap->dev == &cfg->i2c_adap->dev) {
1172 video_dev = NULL; 1175 video_dev = NULL;
1176 if (debug)
1177 printk(KERN_DEBUG "xc2028: reusing device\n");
1178
1173 break; 1179 break;
1174 } 1180 }
1175 } 1181 }
@@ -1183,6 +1189,8 @@ struct dvb_frontend *xc2028_attach(struct dvb_frontend *fe,
1183 1189
1184 priv->i2c_props.addr = cfg->i2c_addr; 1190 priv->i2c_props.addr = cfg->i2c_addr;
1185 priv->i2c_props.adap = cfg->i2c_adap; 1191 priv->i2c_props.adap = cfg->i2c_adap;
1192 priv->i2c_props.name = "xc2028";
1193
1186 priv->video_dev = video_dev; 1194 priv->video_dev = video_dev;
1187 priv->tuner_callback = cfg->callback; 1195 priv->tuner_callback = cfg->callback;
1188 priv->ctrl.max_len = 13; 1196 priv->ctrl.max_len = 13;
@@ -1195,6 +1203,9 @@ struct dvb_frontend *xc2028_attach(struct dvb_frontend *fe,
1195 fe->tuner_priv = priv; 1203 fe->tuner_priv = priv;
1196 priv->count++; 1204 priv->count++;
1197 1205
1206 if (debug)
1207 printk(KERN_DEBUG "xc2028: usage count is %i\n", priv->count);
1208
1198 memcpy(&fe->ops.tuner_ops, &xc2028_dvb_tuner_ops, 1209 memcpy(&fe->ops.tuner_ops, &xc2028_dvb_tuner_ops,
1199 sizeof(xc2028_dvb_tuner_ops)); 1210 sizeof(xc2028_dvb_tuner_ops));
1200 1211
diff --git a/drivers/media/video/tuner-xc2028.h b/drivers/media/video/tuner-xc2028.h
index 3eb8420379a4..fc2f132a5541 100644
--- a/drivers/media/video/tuner-xc2028.h
+++ b/drivers/media/video/tuner-xc2028.h
@@ -1,6 +1,6 @@
1/* tuner-xc2028 1/* tuner-xc2028
2 * 2 *
3 * Copyright (c) 2007 Mauro Carvalho Chehab (mchehab@infradead.org) 3 * Copyright (c) 2007-2008 Mauro Carvalho Chehab (mchehab@infradead.org)
4 * This code is placed under the terms of the GNU General Public License v2 4 * This code is placed under the terms of the GNU General Public License v2
5 */ 5 */
6 6
@@ -12,7 +12,7 @@
12#define XC2028_DEFAULT_FIRMWARE "xc3028-v27.fw" 12#define XC2028_DEFAULT_FIRMWARE "xc3028-v27.fw"
13 13
14/* Dmoduler IF (kHz) */ 14/* Dmoduler IF (kHz) */
15#define XC3028_FE_DEFAULT 0 15#define XC3028_FE_DEFAULT 0 /* Don't load SCODE */
16#define XC3028_FE_LG60 6000 16#define XC3028_FE_LG60 6000
17#define XC3028_FE_ATI638 6380 17#define XC3028_FE_ATI638 6380
18#define XC3028_FE_OREN538 5380 18#define XC3028_FE_OREN538 5380
@@ -55,7 +55,7 @@ static inline struct dvb_frontend *xc2028_attach(struct dvb_frontend *fe,
55 struct xc2028_config *cfg) 55 struct xc2028_config *cfg)
56{ 56{
57 printk(KERN_INFO "%s: not probed - driver disabled by Kconfig\n", 57 printk(KERN_INFO "%s: not probed - driver disabled by Kconfig\n",
58 __FUNCTION__); 58 __func__);
59 return NULL; 59 return NULL;
60} 60}
61#endif 61#endif
diff --git a/drivers/media/video/tvaudio.c b/drivers/media/video/tvaudio.c
index 01ebcec040c4..f29a2cd0f2f2 100644
--- a/drivers/media/video/tvaudio.c
+++ b/drivers/media/video/tvaudio.c
@@ -38,7 +38,7 @@
38/* ---------------------------------------------------------------------- */ 38/* ---------------------------------------------------------------------- */
39/* insmod args */ 39/* insmod args */
40 40
41static int debug = 0; /* insmod parameter */ 41static int debug; /* insmod parameter */
42module_param(debug, int, 0644); 42module_param(debug, int, 0644);
43 43
44MODULE_DESCRIPTION("device driver for various i2c TV sound decoder / audiomux chips"); 44MODULE_DESCRIPTION("device driver for various i2c TV sound decoder / audiomux chips");
@@ -1235,11 +1235,11 @@ static int tda9850 = 1;
1235static int tda9855 = 1; 1235static int tda9855 = 1;
1236static int tda9873 = 1; 1236static int tda9873 = 1;
1237static int tda9874a = 1; 1237static int tda9874a = 1;
1238static int tea6300 = 0; /* address clash with msp34xx */ 1238static int tea6300; /* default 0 - address clash with msp34xx */
1239static int tea6320 = 0; /* address clash with msp34xx */ 1239static int tea6320; /* default 0 - address clash with msp34xx */
1240static int tea6420 = 1; 1240static int tea6420 = 1;
1241static int pic16c54 = 1; 1241static int pic16c54 = 1;
1242static int ta8874z = 0; /* address clash with tda9840 */ 1242static int ta8874z; /* default 0 - address clash with tda9840 */
1243 1243
1244module_param(tda8425, int, 0444); 1244module_param(tda8425, int, 0444);
1245module_param(tda9840, int, 0444); 1245module_param(tda9840, int, 0444);
diff --git a/drivers/media/video/tveeprom.c b/drivers/media/video/tveeprom.c
index dc0da44a5af6..3cf8a8e801e5 100644
--- a/drivers/media/video/tveeprom.c
+++ b/drivers/media/video/tveeprom.c
@@ -745,109 +745,6 @@ int tveeprom_read(struct i2c_client *c, unsigned char *eedata, int len)
745} 745}
746EXPORT_SYMBOL(tveeprom_read); 746EXPORT_SYMBOL(tveeprom_read);
747 747
748/* ----------------------------------------------------------------------- */
749/* needed for ivtv.sf.net at the moment. Should go away in the long */
750/* run, just call the exported tveeprom_* directly, there is no point in */
751/* using the indirect way via i2c_driver->command() */
752
753static unsigned short normal_i2c[] = {
754 0xa0 >> 1,
755 I2C_CLIENT_END,
756};
757
758I2C_CLIENT_INSMOD;
759
760static struct i2c_driver i2c_driver_tveeprom;
761
762static int
763tveeprom_command(struct i2c_client *client,
764 unsigned int cmd,
765 void *arg)
766{
767 struct tveeprom eeprom;
768 u32 *eeprom_props = arg;
769 u8 *buf;
770
771 switch (cmd) {
772 case 0:
773 buf = kzalloc(256, GFP_KERNEL);
774 tveeprom_read(client, buf, 256);
775 tveeprom_hauppauge_analog(client, &eeprom, buf);
776 kfree(buf);
777 eeprom_props[0] = eeprom.tuner_type;
778 eeprom_props[1] = eeprom.tuner_formats;
779 eeprom_props[2] = eeprom.model;
780 eeprom_props[3] = eeprom.revision;
781 eeprom_props[4] = eeprom.has_radio;
782 break;
783 default:
784 return -EINVAL;
785 }
786 return 0;
787}
788
789static int
790tveeprom_detect_client(struct i2c_adapter *adapter,
791 int address,
792 int kind)
793{
794 struct i2c_client *client;
795
796 client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
797 if (NULL == client)
798 return -ENOMEM;
799 client->addr = address;
800 client->adapter = adapter;
801 client->driver = &i2c_driver_tveeprom;
802 snprintf(client->name, sizeof(client->name), "tveeprom");
803 i2c_attach_client(client);
804
805 return 0;
806}
807
808static int
809tveeprom_attach_adapter(struct i2c_adapter *adapter)
810{
811 if (adapter->class & I2C_CLASS_TV_ANALOG)
812 return i2c_probe(adapter, &addr_data, tveeprom_detect_client);
813 return 0;
814}
815
816static int
817tveeprom_detach_client(struct i2c_client *client)
818{
819 int err;
820
821 err = i2c_detach_client(client);
822 if (err < 0)
823 return err;
824 kfree(client);
825 return 0;
826}
827
828static struct i2c_driver i2c_driver_tveeprom = {
829 .driver = {
830 .name = "tveeprom",
831 },
832 .id = I2C_DRIVERID_TVEEPROM,
833 .attach_adapter = tveeprom_attach_adapter,
834 .detach_client = tveeprom_detach_client,
835 .command = tveeprom_command,
836};
837
838static int __init tveeprom_init(void)
839{
840 return i2c_add_driver(&i2c_driver_tveeprom);
841}
842
843static void __exit tveeprom_exit(void)
844{
845 i2c_del_driver(&i2c_driver_tveeprom);
846}
847
848module_init(tveeprom_init);
849module_exit(tveeprom_exit);
850
851/* 748/*
852 * Local variables: 749 * Local variables:
853 * c-basic-offset: 8 750 * c-basic-offset: 8
diff --git a/drivers/media/video/tvp5150.c b/drivers/media/video/tvp5150.c
index b6e24e714a23..6a3af1005f03 100644
--- a/drivers/media/video/tvp5150.c
+++ b/drivers/media/video/tvp5150.c
@@ -27,7 +27,7 @@ static unsigned short normal_i2c[] = {
27 27
28I2C_CLIENT_INSMOD; 28I2C_CLIENT_INSMOD;
29 29
30static int debug = 0; 30static int debug;
31module_param(debug, int, 0); 31module_param(debug, int, 0);
32MODULE_PARM_DESC(debug, "Debug level (0-1)"); 32MODULE_PARM_DESC(debug, "Debug level (0-1)");
33 33
diff --git a/drivers/media/video/usbvideo/ibmcam.c b/drivers/media/video/usbvideo/ibmcam.c
index 14db95e10cfe..59166b760104 100644
--- a/drivers/media/video/usbvideo/ibmcam.c
+++ b/drivers/media/video/usbvideo/ibmcam.c
@@ -121,7 +121,7 @@ static int init_model2_yb = -1;
121 121
122/* 01.01.08 - Added for RCA video in support -LO */ 122/* 01.01.08 - Added for RCA video in support -LO */
123/* Settings for camera model 3 */ 123/* Settings for camera model 3 */
124static int init_model3_input = 0; 124static int init_model3_input;
125 125
126module_param(debug, int, 0); 126module_param(debug, int, 0);
127MODULE_PARM_DESC(debug, "Debug level: 0-9 (default=0)"); 127MODULE_PARM_DESC(debug, "Debug level: 0-9 (default=0)");
@@ -802,6 +802,21 @@ static enum ParseState ibmcam_model2_320x240_parse_lines(
802 return scan_Continue; 802 return scan_Continue;
803} 803}
804 804
805/*
806 * ibmcam_model3_parse_lines()
807 *
808 * | Even lines | Odd Lines |
809 * -----------------------------------|
810 * |YYY........Y|UYVYUYVY.........UYVY|
811 * |YYY........Y|UYVYUYVY.........UYVY|
812 * |............|.....................|
813 * |YYY........Y|UYVYUYVY.........UYVY|
814 * |------------+---------------------|
815 *
816 * There is one (U, V) chroma pair for every four luma (Y) values. This
817 * function reads a pair of lines at a time and obtains missing chroma values
818 * from adjacent pixels.
819 */
805static enum ParseState ibmcam_model3_parse_lines( 820static enum ParseState ibmcam_model3_parse_lines(
806 struct uvd *uvd, 821 struct uvd *uvd,
807 struct usbvideo_frame *frame, 822 struct usbvideo_frame *frame,
@@ -816,6 +831,7 @@ static enum ParseState ibmcam_model3_parse_lines(
816 const int ccm = 128; /* Color correction median - see below */ 831 const int ccm = 128; /* Color correction median - see below */
817 int i, u, v, rw, data_w=0, data_h=0, color_corr; 832 int i, u, v, rw, data_w=0, data_h=0, color_corr;
818 static unsigned char lineBuffer[640*3]; 833 static unsigned char lineBuffer[640*3];
834 int line;
819 835
820 color_corr = (uvd->vpic.colour - 0x8000) >> 8; /* -128..+127 = -ccm..+(ccm-1)*/ 836 color_corr = (uvd->vpic.colour - 0x8000) >> 8; /* -128..+127 = -ccm..+(ccm-1)*/
821 RESTRICT_TO_RANGE(color_corr, -ccm, ccm+1); 837 RESTRICT_TO_RANGE(color_corr, -ccm, ccm+1);
@@ -869,15 +885,15 @@ static enum ParseState ibmcam_model3_parse_lines(
869 return scan_NextFrame; 885 return scan_NextFrame;
870 } 886 }
871 887
872 /* Make sure there's enough data for the entire line */ 888 /* Make sure that lineBuffer can store two lines of data */
873 len = 3 * data_w; /* <y-data> <uv-data> */ 889 len = 3 * data_w; /* <y-data> <uyvy-data> */
874 assert(len <= sizeof(lineBuffer)); 890 assert(len <= sizeof(lineBuffer));
875 891
876 /* Make sure there's enough data for the entire line */ 892 /* Make sure there's enough data for two lines */
877 if (RingQueue_GetLength(&uvd->dp) < len) 893 if (RingQueue_GetLength(&uvd->dp) < len)
878 return scan_Out; 894 return scan_Out;
879 895
880 /* Suck one line out of the ring queue */ 896 /* Suck two lines of data out of the ring queue */
881 RingQueue_Dequeue(&uvd->dp, lineBuffer, len); 897 RingQueue_Dequeue(&uvd->dp, lineBuffer, len);
882 898
883 data = lineBuffer; 899 data = lineBuffer;
@@ -887,15 +903,23 @@ static enum ParseState ibmcam_model3_parse_lines(
887 rw = (int)VIDEOSIZE_Y(frame->request) - (int)(frame->curline) - 1; 903 rw = (int)VIDEOSIZE_Y(frame->request) - (int)(frame->curline) - 1;
888 RESTRICT_TO_RANGE(rw, 0, VIDEOSIZE_Y(frame->request)-1); 904 RESTRICT_TO_RANGE(rw, 0, VIDEOSIZE_Y(frame->request)-1);
889 905
890 for (i = 0; i < VIDEOSIZE_X(frame->request); i++) { 906 /* Iterate over two lines. */
891 int y, rv, gv, bv; /* RGB components */ 907 for (line = 0; line < 2; line++) {
908 for (i = 0; i < VIDEOSIZE_X(frame->request); i++) {
909 int y;
910 int rv, gv, bv; /* RGB components */
892 911
893 if (i < data_w) { 912 if (i >= data_w) {
894 y = data[i]; /* Luminosity is the first line */ 913 RGB24_PUTPIXEL(frame, i, rw, 0, 0, 0);
914 continue;
915 }
916
917 /* first line is YYY...Y; second is UYVY...UYVY */
918 y = data[(line == 0) ? i : (i*2 + 1)];
895 919
896 /* Apply static color correction */ 920 /* Apply static color correction */
897 u = color[i*2] + hue_corr; 921 u = color[(i/2)*4] + hue_corr;
898 v = color[i*2 + 1] + hue2_corr; 922 v = color[(i/2)*4 + 2] + hue2_corr;
899 923
900 /* Apply color correction */ 924 /* Apply color correction */
901 if (color_corr != 0) { 925 if (color_corr != 0) {
@@ -903,13 +927,21 @@ static enum ParseState ibmcam_model3_parse_lines(
903 u = 128 + ((ccm + color_corr) * (u - 128)) / ccm; 927 u = 128 + ((ccm + color_corr) * (u - 128)) / ccm;
904 v = 128 + ((ccm + color_corr) * (v - 128)) / ccm; 928 v = 128 + ((ccm + color_corr) * (v - 128)) / ccm;
905 } 929 }
906 } else
907 y = 0, u = v = 128;
908 930
909 YUV_TO_RGB_BY_THE_BOOK(y, u, v, rv, gv, bv); 931
910 RGB24_PUTPIXEL(frame, i, rw, rv, gv, bv); /* Done by deinterlacing now */ 932 YUV_TO_RGB_BY_THE_BOOK(y, u, v, rv, gv, bv);
933 RGB24_PUTPIXEL(frame, i, rw, rv, gv, bv); /* No deinterlacing */
934 }
935
936 /* Check for the end of requested data */
937 if (rw == 0)
938 break;
939
940 /* Prepare for the second line */
941 rw--;
942 data = lineBuffer + data_w;
911 } 943 }
912 frame->deinterlace = Deinterlace_FillEvenLines; 944 frame->deinterlace = Deinterlace_None;
913 945
914 /* 946 /*
915 * Account for number of bytes that we wrote into output V4L frame. 947 * Account for number of bytes that we wrote into output V4L frame.
diff --git a/drivers/media/video/usbvideo/konicawc.c b/drivers/media/video/usbvideo/konicawc.c
index 719b17ce83f8..1c180284ec6c 100644
--- a/drivers/media/video/usbvideo/konicawc.c
+++ b/drivers/media/video/usbvideo/konicawc.c
@@ -57,11 +57,11 @@ static struct usbvideo *cams;
57static int debug; 57static int debug;
58#define DEBUG(n, format, arg...) \ 58#define DEBUG(n, format, arg...) \
59 if (n <= debug) { \ 59 if (n <= debug) { \
60 printk(KERN_DEBUG __FILE__ ":%s(): " format "\n", __FUNCTION__ , ## arg); \ 60 printk(KERN_DEBUG __FILE__ ":%s(): " format "\n", __func__ , ## arg); \
61 } 61 }
62#else 62#else
63#define DEBUG(n, arg...) 63#define DEBUG(n, arg...)
64static const int debug = 0; 64static const int debug;
65#endif 65#endif
66 66
67 67
diff --git a/drivers/media/video/usbvideo/quickcam_messenger.c b/drivers/media/video/usbvideo/quickcam_messenger.c
index a2acba0bcc47..32e536edf09d 100644
--- a/drivers/media/video/usbvideo/quickcam_messenger.c
+++ b/drivers/media/video/usbvideo/quickcam_messenger.c
@@ -46,11 +46,11 @@
46static int debug; 46static int debug;
47#define DEBUG(n, format, arg...) \ 47#define DEBUG(n, format, arg...) \
48 if (n <= debug) { \ 48 if (n <= debug) { \
49 printk(KERN_DEBUG __FILE__ ":%s(): " format "\n", __FUNCTION__ , ## arg); \ 49 printk(KERN_DEBUG __FILE__ ":%s(): " format "\n", __func__ , ## arg); \
50 } 50 }
51#else 51#else
52#define DEBUG(n, arg...) 52#define DEBUG(n, arg...)
53static const int debug = 0; 53static const int debug;
54#endif 54#endif
55 55
56#define DRIVER_VERSION "v0.01" 56#define DRIVER_VERSION "v0.01"
diff --git a/drivers/media/video/usbvideo/ultracam.c b/drivers/media/video/usbvideo/ultracam.c
index 95453c108d40..9544e644bf0d 100644
--- a/drivers/media/video/usbvideo/ultracam.c
+++ b/drivers/media/video/usbvideo/ultracam.c
@@ -28,9 +28,9 @@ typedef struct {
28 28
29static struct usbvideo *cams = NULL; 29static struct usbvideo *cams = NULL;
30 30
31static int debug = 0; 31static int debug;
32 32
33static int flags = 0; /* FLAGS_DISPLAY_HINTS | FLAGS_OVERLAY_STATS; */ 33static int flags; /* FLAGS_DISPLAY_HINTS | FLAGS_OVERLAY_STATS; */
34 34
35static const int min_canvasWidth = 8; 35static const int min_canvasWidth = 8;
36static const int min_canvasHeight = 4; 36static const int min_canvasHeight = 4;
diff --git a/drivers/media/video/usbvideo/usbvideo.c b/drivers/media/video/usbvideo/usbvideo.c
index 5d363be7bc73..4128ee20b64e 100644
--- a/drivers/media/video/usbvideo/usbvideo.c
+++ b/drivers/media/video/usbvideo/usbvideo.c
@@ -522,14 +522,14 @@ void usbvideo_TestPattern(struct uvd *uvd, int fullframe, int pmode)
522 struct usbvideo_frame *frame; 522 struct usbvideo_frame *frame;
523 int num_cell = 0; 523 int num_cell = 0;
524 int scan_length = 0; 524 int scan_length = 0;
525 static int num_pass = 0; 525 static int num_pass;
526 526
527 if (uvd == NULL) { 527 if (uvd == NULL) {
528 err("%s: uvd == NULL", __FUNCTION__); 528 err("%s: uvd == NULL", __func__);
529 return; 529 return;
530 } 530 }
531 if ((uvd->curframe < 0) || (uvd->curframe >= USBVIDEO_NUMFRAMES)) { 531 if ((uvd->curframe < 0) || (uvd->curframe >= USBVIDEO_NUMFRAMES)) {
532 err("%s: uvd->curframe=%d.", __FUNCTION__, uvd->curframe); 532 err("%s: uvd->curframe=%d.", __func__, uvd->curframe);
533 return; 533 return;
534 } 534 }
535 535
@@ -630,15 +630,15 @@ EXPORT_SYMBOL(usbvideo_HexDump);
630static int usbvideo_ClientIncModCount(struct uvd *uvd) 630static int usbvideo_ClientIncModCount(struct uvd *uvd)
631{ 631{
632 if (uvd == NULL) { 632 if (uvd == NULL) {
633 err("%s: uvd == NULL", __FUNCTION__); 633 err("%s: uvd == NULL", __func__);
634 return -EINVAL; 634 return -EINVAL;
635 } 635 }
636 if (uvd->handle == NULL) { 636 if (uvd->handle == NULL) {
637 err("%s: uvd->handle == NULL", __FUNCTION__); 637 err("%s: uvd->handle == NULL", __func__);
638 return -EINVAL; 638 return -EINVAL;
639 } 639 }
640 if (!try_module_get(uvd->handle->md_module)) { 640 if (!try_module_get(uvd->handle->md_module)) {
641 err("%s: try_module_get() == 0", __FUNCTION__); 641 err("%s: try_module_get() == 0", __func__);
642 return -ENODEV; 642 return -ENODEV;
643 } 643 }
644 return 0; 644 return 0;
@@ -647,15 +647,15 @@ static int usbvideo_ClientIncModCount(struct uvd *uvd)
647static void usbvideo_ClientDecModCount(struct uvd *uvd) 647static void usbvideo_ClientDecModCount(struct uvd *uvd)
648{ 648{
649 if (uvd == NULL) { 649 if (uvd == NULL) {
650 err("%s: uvd == NULL", __FUNCTION__); 650 err("%s: uvd == NULL", __func__);
651 return; 651 return;
652 } 652 }
653 if (uvd->handle == NULL) { 653 if (uvd->handle == NULL) {
654 err("%s: uvd->handle == NULL", __FUNCTION__); 654 err("%s: uvd->handle == NULL", __func__);
655 return; 655 return;
656 } 656 }
657 if (uvd->handle->md_module == NULL) { 657 if (uvd->handle->md_module == NULL) {
658 err("%s: uvd->handle->md_module == NULL", __FUNCTION__); 658 err("%s: uvd->handle->md_module == NULL", __func__);
659 return; 659 return;
660 } 660 }
661 module_put(uvd->handle->md_module); 661 module_put(uvd->handle->md_module);
@@ -675,13 +675,13 @@ int usbvideo_register(
675 675
676 /* Check parameters for sanity */ 676 /* Check parameters for sanity */
677 if ((num_cams <= 0) || (pCams == NULL) || (cbTbl == NULL)) { 677 if ((num_cams <= 0) || (pCams == NULL) || (cbTbl == NULL)) {
678 err("%s: Illegal call", __FUNCTION__); 678 err("%s: Illegal call", __func__);
679 return -EINVAL; 679 return -EINVAL;
680 } 680 }
681 681
682 /* Check registration callback - must be set! */ 682 /* Check registration callback - must be set! */
683 if (cbTbl->probe == NULL) { 683 if (cbTbl->probe == NULL) {
684 err("%s: probe() is required!", __FUNCTION__); 684 err("%s: probe() is required!", __func__);
685 return -EINVAL; 685 return -EINVAL;
686 } 686 }
687 687
@@ -692,7 +692,7 @@ int usbvideo_register(
692 return -ENOMEM; 692 return -ENOMEM;
693 } 693 }
694 dbg("%s: Allocated $%p (%d. bytes) for %d. cameras", 694 dbg("%s: Allocated $%p (%d. bytes) for %d. cameras",
695 __FUNCTION__, cams, base_size, num_cams); 695 __func__, cams, base_size, num_cams);
696 696
697 /* Copy callbacks, apply defaults for those that are not set */ 697 /* Copy callbacks, apply defaults for those that are not set */
698 memmove(&cams->cb, cbTbl, sizeof(cams->cb)); 698 memmove(&cams->cb, cbTbl, sizeof(cams->cb));
@@ -721,7 +721,7 @@ int usbvideo_register(
721 up->user_data = kmalloc(up->user_size, GFP_KERNEL); 721 up->user_data = kmalloc(up->user_size, GFP_KERNEL);
722 if (up->user_data == NULL) { 722 if (up->user_data == NULL) {
723 err("%s: Failed to allocate user_data (%d. bytes)", 723 err("%s: Failed to allocate user_data (%d. bytes)",
724 __FUNCTION__, up->user_size); 724 __func__, up->user_size);
725 while (i) { 725 while (i) {
726 up = &cams->cam[--i]; 726 up = &cams->cam[--i];
727 kfree(up->user_data); 727 kfree(up->user_data);
@@ -730,7 +730,7 @@ int usbvideo_register(
730 return -ENOMEM; 730 return -ENOMEM;
731 } 731 }
732 dbg("%s: Allocated cams[%d].user_data=$%p (%d. bytes)", 732 dbg("%s: Allocated cams[%d].user_data=$%p (%d. bytes)",
733 __FUNCTION__, i, up->user_data, up->user_size); 733 __func__, i, up->user_data, up->user_size);
734 } 734 }
735 } 735 }
736 736
@@ -776,19 +776,19 @@ void usbvideo_Deregister(struct usbvideo **pCams)
776 int i; 776 int i;
777 777
778 if (pCams == NULL) { 778 if (pCams == NULL) {
779 err("%s: pCams == NULL", __FUNCTION__); 779 err("%s: pCams == NULL", __func__);
780 return; 780 return;
781 } 781 }
782 cams = *pCams; 782 cams = *pCams;
783 if (cams == NULL) { 783 if (cams == NULL) {
784 err("%s: cams == NULL", __FUNCTION__); 784 err("%s: cams == NULL", __func__);
785 return; 785 return;
786 } 786 }
787 787
788 dbg("%s: Deregistering %s driver.", __FUNCTION__, cams->drvName); 788 dbg("%s: Deregistering %s driver.", __func__, cams->drvName);
789 usb_deregister(&cams->usbdrv); 789 usb_deregister(&cams->usbdrv);
790 790
791 dbg("%s: Deallocating cams=$%p (%d. cameras)", __FUNCTION__, cams, cams->num_cameras); 791 dbg("%s: Deallocating cams=$%p (%d. cameras)", __func__, cams, cams->num_cameras);
792 for (i=0; i < cams->num_cameras; i++) { 792 for (i=0; i < cams->num_cameras; i++) {
793 struct uvd *up = &cams->cam[i]; 793 struct uvd *up = &cams->cam[i];
794 int warning = 0; 794 int warning = 0;
@@ -802,16 +802,16 @@ void usbvideo_Deregister(struct usbvideo **pCams)
802 } 802 }
803 if (warning) { 803 if (warning) {
804 err("%s: Warning: user_data=$%p user_size=%d.", 804 err("%s: Warning: user_data=$%p user_size=%d.",
805 __FUNCTION__, up->user_data, up->user_size); 805 __func__, up->user_data, up->user_size);
806 } else { 806 } else {
807 dbg("%s: Freeing %d. $%p->user_data=$%p", 807 dbg("%s: Freeing %d. $%p->user_data=$%p",
808 __FUNCTION__, i, up, up->user_data); 808 __func__, i, up, up->user_data);
809 kfree(up->user_data); 809 kfree(up->user_data);
810 } 810 }
811 } 811 }
812 /* Whole array was allocated in one chunk */ 812 /* Whole array was allocated in one chunk */
813 dbg("%s: Freed %d uvd structures", 813 dbg("%s: Freed %d uvd structures",
814 __FUNCTION__, cams->num_cameras); 814 __func__, cams->num_cameras);
815 kfree(cams); 815 kfree(cams);
816 *pCams = NULL; 816 *pCams = NULL;
817} 817}
@@ -846,7 +846,7 @@ static void usbvideo_Disconnect(struct usb_interface *intf)
846 int i; 846 int i;
847 847
848 if (uvd == NULL) { 848 if (uvd == NULL) {
849 err("%s($%p): Illegal call.", __FUNCTION__, intf); 849 err("%s($%p): Illegal call.", __func__, intf);
850 return; 850 return;
851 } 851 }
852 852
@@ -854,7 +854,7 @@ static void usbvideo_Disconnect(struct usb_interface *intf)
854 854
855 usbvideo_ClientIncModCount(uvd); 855 usbvideo_ClientIncModCount(uvd);
856 if (uvd->debug > 0) 856 if (uvd->debug > 0)
857 info("%s(%p.)", __FUNCTION__, intf); 857 info("%s(%p.)", __func__, intf);
858 858
859 mutex_lock(&uvd->lock); 859 mutex_lock(&uvd->lock);
860 uvd->remove_pending = 1; /* Now all ISO data will be ignored */ 860 uvd->remove_pending = 1; /* Now all ISO data will be ignored */
@@ -870,10 +870,10 @@ static void usbvideo_Disconnect(struct usb_interface *intf)
870 870
871 video_unregister_device(&uvd->vdev); 871 video_unregister_device(&uvd->vdev);
872 if (uvd->debug > 0) 872 if (uvd->debug > 0)
873 info("%s: Video unregistered.", __FUNCTION__); 873 info("%s: Video unregistered.", __func__);
874 874
875 if (uvd->user) 875 if (uvd->user)
876 info("%s: In use, disconnect pending.", __FUNCTION__); 876 info("%s: In use, disconnect pending.", __func__);
877 else 877 else
878 usbvideo_CameraRelease(uvd); 878 usbvideo_CameraRelease(uvd);
879 mutex_unlock(&uvd->lock); 879 mutex_unlock(&uvd->lock);
@@ -895,7 +895,7 @@ static void usbvideo_Disconnect(struct usb_interface *intf)
895static void usbvideo_CameraRelease(struct uvd *uvd) 895static void usbvideo_CameraRelease(struct uvd *uvd)
896{ 896{
897 if (uvd == NULL) { 897 if (uvd == NULL) {
898 err("%s: Illegal call", __FUNCTION__); 898 err("%s: Illegal call", __func__);
899 return; 899 return;
900 } 900 }
901 901
@@ -946,7 +946,9 @@ static const struct file_operations usbvideo_fops = {
946 .read = usbvideo_v4l_read, 946 .read = usbvideo_v4l_read,
947 .mmap = usbvideo_v4l_mmap, 947 .mmap = usbvideo_v4l_mmap,
948 .ioctl = usbvideo_v4l_ioctl, 948 .ioctl = usbvideo_v4l_ioctl,
949#ifdef CONFIG_COMPAT
949 .compat_ioctl = v4l_compat_ioctl32, 950 .compat_ioctl = v4l_compat_ioctl32,
951#endif
950 .llseek = no_llseek, 952 .llseek = no_llseek,
951}; 953};
952static const struct video_device usbvideo_template = { 954static const struct video_device usbvideo_template = {
@@ -1011,18 +1013,18 @@ int usbvideo_RegisterVideoDevice(struct uvd *uvd)
1011 char tmp1[20], tmp2[20]; /* Buffers for printing */ 1013 char tmp1[20], tmp2[20]; /* Buffers for printing */
1012 1014
1013 if (uvd == NULL) { 1015 if (uvd == NULL) {
1014 err("%s: Illegal call.", __FUNCTION__); 1016 err("%s: Illegal call.", __func__);
1015 return -EINVAL; 1017 return -EINVAL;
1016 } 1018 }
1017 if (uvd->video_endp == 0) { 1019 if (uvd->video_endp == 0) {
1018 info("%s: No video endpoint specified; data pump disabled.", __FUNCTION__); 1020 info("%s: No video endpoint specified; data pump disabled.", __func__);
1019 } 1021 }
1020 if (uvd->paletteBits == 0) { 1022 if (uvd->paletteBits == 0) {
1021 err("%s: No palettes specified!", __FUNCTION__); 1023 err("%s: No palettes specified!", __func__);
1022 return -EINVAL; 1024 return -EINVAL;
1023 } 1025 }
1024 if (uvd->defaultPalette == 0) { 1026 if (uvd->defaultPalette == 0) {
1025 info("%s: No default palette!", __FUNCTION__); 1027 info("%s: No default palette!", __func__);
1026 } 1028 }
1027 1029
1028 uvd->max_frame_size = VIDEOSIZE_X(uvd->canvas) * 1030 uvd->max_frame_size = VIDEOSIZE_X(uvd->canvas) *
@@ -1032,19 +1034,19 @@ int usbvideo_RegisterVideoDevice(struct uvd *uvd)
1032 1034
1033 if (uvd->debug > 0) { 1035 if (uvd->debug > 0) {
1034 info("%s: iface=%d. endpoint=$%02x paletteBits=$%08lx", 1036 info("%s: iface=%d. endpoint=$%02x paletteBits=$%08lx",
1035 __FUNCTION__, uvd->iface, uvd->video_endp, uvd->paletteBits); 1037 __func__, uvd->iface, uvd->video_endp, uvd->paletteBits);
1036 } 1038 }
1037 if (uvd->dev == NULL) { 1039 if (uvd->dev == NULL) {
1038 err("%s: uvd->dev == NULL", __FUNCTION__); 1040 err("%s: uvd->dev == NULL", __func__);
1039 return -EINVAL; 1041 return -EINVAL;
1040 } 1042 }
1041 uvd->vdev.dev=&(uvd->dev->dev); 1043 uvd->vdev.dev = &uvd->dev->dev;
1042 if (video_register_device(&uvd->vdev, VFL_TYPE_GRABBER, video_nr) == -1) { 1044 if (video_register_device(&uvd->vdev, VFL_TYPE_GRABBER, video_nr) == -1) {
1043 err("%s: video_register_device failed", __FUNCTION__); 1045 err("%s: video_register_device failed", __func__);
1044 return -EPIPE; 1046 return -EPIPE;
1045 } 1047 }
1046 if (uvd->debug > 1) { 1048 if (uvd->debug > 1) {
1047 info("%s: video_register_device() successful", __FUNCTION__); 1049 info("%s: video_register_device() successful", __func__);
1048 } 1050 }
1049 1051
1050 info("%s on /dev/video%d: canvas=%s videosize=%s", 1052 info("%s on /dev/video%d: canvas=%s videosize=%s",
@@ -1111,14 +1113,14 @@ static int usbvideo_v4l_open(struct inode *inode, struct file *file)
1111 int i, errCode = 0; 1113 int i, errCode = 0;
1112 1114
1113 if (uvd->debug > 1) 1115 if (uvd->debug > 1)
1114 info("%s($%p)", __FUNCTION__, dev); 1116 info("%s($%p)", __func__, dev);
1115 1117
1116 if (0 < usbvideo_ClientIncModCount(uvd)) 1118 if (0 < usbvideo_ClientIncModCount(uvd))
1117 return -ENODEV; 1119 return -ENODEV;
1118 mutex_lock(&uvd->lock); 1120 mutex_lock(&uvd->lock);
1119 1121
1120 if (uvd->user) { 1122 if (uvd->user) {
1121 err("%s: Someone tried to open an already opened device!", __FUNCTION__); 1123 err("%s: Someone tried to open an already opened device!", __func__);
1122 errCode = -EBUSY; 1124 errCode = -EBUSY;
1123 } else { 1125 } else {
1124 /* Clear statistics */ 1126 /* Clear statistics */
@@ -1134,7 +1136,7 @@ static int usbvideo_v4l_open(struct inode *inode, struct file *file)
1134 RingQueue_Allocate(&uvd->dp, RING_QUEUE_SIZE); 1136 RingQueue_Allocate(&uvd->dp, RING_QUEUE_SIZE);
1135 if ((uvd->fbuf == NULL) || 1137 if ((uvd->fbuf == NULL) ||
1136 (!RingQueue_IsAllocated(&uvd->dp))) { 1138 (!RingQueue_IsAllocated(&uvd->dp))) {
1137 err("%s: Failed to allocate fbuf or dp", __FUNCTION__); 1139 err("%s: Failed to allocate fbuf or dp", __func__);
1138 errCode = -ENOMEM; 1140 errCode = -ENOMEM;
1139 } else { 1141 } else {
1140 /* Allocate all buffers */ 1142 /* Allocate all buffers */
@@ -1178,19 +1180,19 @@ static int usbvideo_v4l_open(struct inode *inode, struct file *file)
1178 if (errCode == 0) { 1180 if (errCode == 0) {
1179 if (VALID_CALLBACK(uvd, setupOnOpen)) { 1181 if (VALID_CALLBACK(uvd, setupOnOpen)) {
1180 if (uvd->debug > 1) 1182 if (uvd->debug > 1)
1181 info("%s: setupOnOpen callback", __FUNCTION__); 1183 info("%s: setupOnOpen callback", __func__);
1182 errCode = GET_CALLBACK(uvd, setupOnOpen)(uvd); 1184 errCode = GET_CALLBACK(uvd, setupOnOpen)(uvd);
1183 if (errCode < 0) { 1185 if (errCode < 0) {
1184 err("%s: setupOnOpen callback failed (%d.).", 1186 err("%s: setupOnOpen callback failed (%d.).",
1185 __FUNCTION__, errCode); 1187 __func__, errCode);
1186 } else if (uvd->debug > 1) { 1188 } else if (uvd->debug > 1) {
1187 info("%s: setupOnOpen callback successful", __FUNCTION__); 1189 info("%s: setupOnOpen callback successful", __func__);
1188 } 1190 }
1189 } 1191 }
1190 if (errCode == 0) { 1192 if (errCode == 0) {
1191 uvd->settingsAdjusted = 0; 1193 uvd->settingsAdjusted = 0;
1192 if (uvd->debug > 1) 1194 if (uvd->debug > 1)
1193 info("%s: Open succeeded.", __FUNCTION__); 1195 info("%s: Open succeeded.", __func__);
1194 uvd->user++; 1196 uvd->user++;
1195 file->private_data = uvd; 1197 file->private_data = uvd;
1196 } 1198 }
@@ -1200,7 +1202,7 @@ static int usbvideo_v4l_open(struct inode *inode, struct file *file)
1200 if (errCode != 0) 1202 if (errCode != 0)
1201 usbvideo_ClientDecModCount(uvd); 1203 usbvideo_ClientDecModCount(uvd);
1202 if (uvd->debug > 0) 1204 if (uvd->debug > 0)
1203 info("%s: Returning %d.", __FUNCTION__, errCode); 1205 info("%s: Returning %d.", __func__, errCode);
1204 return errCode; 1206 return errCode;
1205} 1207}
1206 1208
@@ -1223,7 +1225,7 @@ static int usbvideo_v4l_close(struct inode *inode, struct file *file)
1223 int i; 1225 int i;
1224 1226
1225 if (uvd->debug > 1) 1227 if (uvd->debug > 1)
1226 info("%s($%p)", __FUNCTION__, dev); 1228 info("%s($%p)", __func__, dev);
1227 1229
1228 mutex_lock(&uvd->lock); 1230 mutex_lock(&uvd->lock);
1229 GET_CALLBACK(uvd, stopDataPump)(uvd); 1231 GET_CALLBACK(uvd, stopDataPump)(uvd);
@@ -1250,7 +1252,7 @@ static int usbvideo_v4l_close(struct inode *inode, struct file *file)
1250 usbvideo_ClientDecModCount(uvd); 1252 usbvideo_ClientDecModCount(uvd);
1251 1253
1252 if (uvd->debug > 1) 1254 if (uvd->debug > 1)
1253 info("%s: Completed.", __FUNCTION__); 1255 info("%s: Completed.", __func__);
1254 file->private_data = NULL; 1256 file->private_data = NULL;
1255 return 0; 1257 return 0;
1256} 1258}
@@ -1504,7 +1506,7 @@ static ssize_t usbvideo_v4l_read(struct file *file, char __user *buf,
1504 return -EFAULT; 1506 return -EFAULT;
1505 1507
1506 if (uvd->debug >= 1) 1508 if (uvd->debug >= 1)
1507 info("%s: %Zd. bytes, noblock=%d.", __FUNCTION__, count, noblock); 1509 info("%s: %Zd. bytes, noblock=%d.", __func__, count, noblock);
1508 1510
1509 mutex_lock(&uvd->lock); 1511 mutex_lock(&uvd->lock);
1510 1512
@@ -1551,7 +1553,7 @@ static ssize_t usbvideo_v4l_read(struct file *file, char __user *buf,
1551 */ 1553 */
1552 if (frmx == -1) { 1554 if (frmx == -1) {
1553 if (uvd->defaultPalette == 0) { 1555 if (uvd->defaultPalette == 0) {
1554 err("%s: No default palette; don't know what to do!", __FUNCTION__); 1556 err("%s: No default palette; don't know what to do!", __func__);
1555 count = -EFAULT; 1557 count = -EFAULT;
1556 goto read_done; 1558 goto read_done;
1557 } 1559 }
@@ -1623,7 +1625,7 @@ static ssize_t usbvideo_v4l_read(struct file *file, char __user *buf,
1623 frame->seqRead_Index += count; 1625 frame->seqRead_Index += count;
1624 if (uvd->debug >= 1) { 1626 if (uvd->debug >= 1) {
1625 err("%s: {copy} count used=%Zd, new seqRead_Index=%ld", 1627 err("%s: {copy} count used=%Zd, new seqRead_Index=%ld",
1626 __FUNCTION__, count, frame->seqRead_Index); 1628 __func__, count, frame->seqRead_Index);
1627 } 1629 }
1628 1630
1629 /* Finally check if the frame is done with and "release" it */ 1631 /* Finally check if the frame is done with and "release" it */
@@ -1634,7 +1636,7 @@ static ssize_t usbvideo_v4l_read(struct file *file, char __user *buf,
1634 /* Mark it as available to be used again. */ 1636 /* Mark it as available to be used again. */
1635 uvd->frame[frmx].frameState = FrameState_Unused; 1637 uvd->frame[frmx].frameState = FrameState_Unused;
1636 if (usbvideo_NewFrame(uvd, (frmx + 1) % USBVIDEO_NUMFRAMES)) { 1638 if (usbvideo_NewFrame(uvd, (frmx + 1) % USBVIDEO_NUMFRAMES)) {
1637 err("%s: usbvideo_NewFrame failed.", __FUNCTION__); 1639 err("%s: usbvideo_NewFrame failed.", __func__);
1638 } 1640 }
1639 } 1641 }
1640read_done: 1642read_done:
@@ -1741,10 +1743,10 @@ static int usbvideo_StartDataPump(struct uvd *uvd)
1741 int i, errFlag; 1743 int i, errFlag;
1742 1744
1743 if (uvd->debug > 1) 1745 if (uvd->debug > 1)
1744 info("%s($%p)", __FUNCTION__, uvd); 1746 info("%s($%p)", __func__, uvd);
1745 1747
1746 if (!CAMERA_IS_OPERATIONAL(uvd)) { 1748 if (!CAMERA_IS_OPERATIONAL(uvd)) {
1747 err("%s: Camera is not operational", __FUNCTION__); 1749 err("%s: Camera is not operational", __func__);
1748 return -EFAULT; 1750 return -EFAULT;
1749 } 1751 }
1750 uvd->curframe = -1; 1752 uvd->curframe = -1;
@@ -1752,14 +1754,14 @@ static int usbvideo_StartDataPump(struct uvd *uvd)
1752 /* Alternate interface 1 is is the biggest frame size */ 1754 /* Alternate interface 1 is is the biggest frame size */
1753 i = usb_set_interface(dev, uvd->iface, uvd->ifaceAltActive); 1755 i = usb_set_interface(dev, uvd->iface, uvd->ifaceAltActive);
1754 if (i < 0) { 1756 if (i < 0) {
1755 err("%s: usb_set_interface error", __FUNCTION__); 1757 err("%s: usb_set_interface error", __func__);
1756 uvd->last_error = i; 1758 uvd->last_error = i;
1757 return -EBUSY; 1759 return -EBUSY;
1758 } 1760 }
1759 if (VALID_CALLBACK(uvd, videoStart)) 1761 if (VALID_CALLBACK(uvd, videoStart))
1760 GET_CALLBACK(uvd, videoStart)(uvd); 1762 GET_CALLBACK(uvd, videoStart)(uvd);
1761 else 1763 else
1762 err("%s: videoStart not set", __FUNCTION__); 1764 err("%s: videoStart not set", __func__);
1763 1765
1764 /* We double buffer the Iso lists */ 1766 /* We double buffer the Iso lists */
1765 for (i=0; i < USBVIDEO_NUMSBUF; i++) { 1767 for (i=0; i < USBVIDEO_NUMSBUF; i++) {
@@ -1784,12 +1786,12 @@ static int usbvideo_StartDataPump(struct uvd *uvd)
1784 for (i=0; i < USBVIDEO_NUMSBUF; i++) { 1786 for (i=0; i < USBVIDEO_NUMSBUF; i++) {
1785 errFlag = usb_submit_urb(uvd->sbuf[i].urb, GFP_KERNEL); 1787 errFlag = usb_submit_urb(uvd->sbuf[i].urb, GFP_KERNEL);
1786 if (errFlag) 1788 if (errFlag)
1787 err("%s: usb_submit_isoc(%d) ret %d", __FUNCTION__, i, errFlag); 1789 err("%s: usb_submit_isoc(%d) ret %d", __func__, i, errFlag);
1788 } 1790 }
1789 1791
1790 uvd->streaming = 1; 1792 uvd->streaming = 1;
1791 if (uvd->debug > 1) 1793 if (uvd->debug > 1)
1792 info("%s: streaming=1 video_endp=$%02x", __FUNCTION__, uvd->video_endp); 1794 info("%s: streaming=1 video_endp=$%02x", __func__, uvd->video_endp);
1793 return 0; 1795 return 0;
1794} 1796}
1795 1797
@@ -1811,14 +1813,14 @@ static void usbvideo_StopDataPump(struct uvd *uvd)
1811 return; 1813 return;
1812 1814
1813 if (uvd->debug > 1) 1815 if (uvd->debug > 1)
1814 info("%s($%p)", __FUNCTION__, uvd); 1816 info("%s($%p)", __func__, uvd);
1815 1817
1816 /* Unschedule all of the iso td's */ 1818 /* Unschedule all of the iso td's */
1817 for (i=0; i < USBVIDEO_NUMSBUF; i++) { 1819 for (i=0; i < USBVIDEO_NUMSBUF; i++) {
1818 usb_kill_urb(uvd->sbuf[i].urb); 1820 usb_kill_urb(uvd->sbuf[i].urb);
1819 } 1821 }
1820 if (uvd->debug > 1) 1822 if (uvd->debug > 1)
1821 info("%s: streaming=0", __FUNCTION__); 1823 info("%s: streaming=0", __func__);
1822 uvd->streaming = 0; 1824 uvd->streaming = 0;
1823 1825
1824 if (!uvd->remove_pending) { 1826 if (!uvd->remove_pending) {
@@ -1826,12 +1828,12 @@ static void usbvideo_StopDataPump(struct uvd *uvd)
1826 if (VALID_CALLBACK(uvd, videoStop)) 1828 if (VALID_CALLBACK(uvd, videoStop))
1827 GET_CALLBACK(uvd, videoStop)(uvd); 1829 GET_CALLBACK(uvd, videoStop)(uvd);
1828 else 1830 else
1829 err("%s: videoStop not set", __FUNCTION__); 1831 err("%s: videoStop not set", __func__);
1830 1832
1831 /* Set packet size to 0 */ 1833 /* Set packet size to 0 */
1832 j = usb_set_interface(uvd->dev, uvd->iface, uvd->ifaceAltInactive); 1834 j = usb_set_interface(uvd->dev, uvd->iface, uvd->ifaceAltInactive);
1833 if (j < 0) { 1835 if (j < 0) {
1834 err("%s: usb_set_interface() error %d.", __FUNCTION__, j); 1836 err("%s: usb_set_interface() error %d.", __func__, j);
1835 uvd->last_error = j; 1837 uvd->last_error = j;
1836 } 1838 }
1837 } 1839 }
@@ -1955,12 +1957,12 @@ static int usbvideo_GetFrame(struct uvd *uvd, int frameNum)
1955 struct usbvideo_frame *frame = &uvd->frame[frameNum]; 1957 struct usbvideo_frame *frame = &uvd->frame[frameNum];
1956 1958
1957 if (uvd->debug >= 2) 1959 if (uvd->debug >= 2)
1958 info("%s($%p,%d.)", __FUNCTION__, uvd, frameNum); 1960 info("%s($%p,%d.)", __func__, uvd, frameNum);
1959 1961
1960 switch (frame->frameState) { 1962 switch (frame->frameState) {
1961 case FrameState_Unused: 1963 case FrameState_Unused:
1962 if (uvd->debug >= 2) 1964 if (uvd->debug >= 2)
1963 info("%s: FrameState_Unused", __FUNCTION__); 1965 info("%s: FrameState_Unused", __func__);
1964 return -EINVAL; 1966 return -EINVAL;
1965 case FrameState_Ready: 1967 case FrameState_Ready:
1966 case FrameState_Grabbing: 1968 case FrameState_Grabbing:
@@ -1970,7 +1972,7 @@ static int usbvideo_GetFrame(struct uvd *uvd, int frameNum)
1970 redo: 1972 redo:
1971 if (!CAMERA_IS_OPERATIONAL(uvd)) { 1973 if (!CAMERA_IS_OPERATIONAL(uvd)) {
1972 if (uvd->debug >= 2) 1974 if (uvd->debug >= 2)
1973 info("%s: Camera is not operational (1)", __FUNCTION__); 1975 info("%s: Camera is not operational (1)", __func__);
1974 return -EIO; 1976 return -EIO;
1975 } 1977 }
1976 ntries = 0; 1978 ntries = 0;
@@ -1979,24 +1981,24 @@ static int usbvideo_GetFrame(struct uvd *uvd, int frameNum)
1979 signalPending = signal_pending(current); 1981 signalPending = signal_pending(current);
1980 if (!CAMERA_IS_OPERATIONAL(uvd)) { 1982 if (!CAMERA_IS_OPERATIONAL(uvd)) {
1981 if (uvd->debug >= 2) 1983 if (uvd->debug >= 2)
1982 info("%s: Camera is not operational (2)", __FUNCTION__); 1984 info("%s: Camera is not operational (2)", __func__);
1983 return -EIO; 1985 return -EIO;
1984 } 1986 }
1985 assert(uvd->fbuf != NULL); 1987 assert(uvd->fbuf != NULL);
1986 if (signalPending) { 1988 if (signalPending) {
1987 if (uvd->debug >= 2) 1989 if (uvd->debug >= 2)
1988 info("%s: Signal=$%08x", __FUNCTION__, signalPending); 1990 info("%s: Signal=$%08x", __func__, signalPending);
1989 if (uvd->flags & FLAGS_RETRY_VIDIOCSYNC) { 1991 if (uvd->flags & FLAGS_RETRY_VIDIOCSYNC) {
1990 usbvideo_TestPattern(uvd, 1, 0); 1992 usbvideo_TestPattern(uvd, 1, 0);
1991 uvd->curframe = -1; 1993 uvd->curframe = -1;
1992 uvd->stats.frame_num++; 1994 uvd->stats.frame_num++;
1993 if (uvd->debug >= 2) 1995 if (uvd->debug >= 2)
1994 info("%s: Forced test pattern screen", __FUNCTION__); 1996 info("%s: Forced test pattern screen", __func__);
1995 return 0; 1997 return 0;
1996 } else { 1998 } else {
1997 /* Standard answer: Interrupted! */ 1999 /* Standard answer: Interrupted! */
1998 if (uvd->debug >= 2) 2000 if (uvd->debug >= 2)
1999 info("%s: Interrupted!", __FUNCTION__); 2001 info("%s: Interrupted!", __func__);
2000 return -EINTR; 2002 return -EINTR;
2001 } 2003 }
2002 } else { 2004 } else {
@@ -2006,17 +2008,17 @@ static int usbvideo_GetFrame(struct uvd *uvd, int frameNum)
2006 else if (VALID_CALLBACK(uvd, processData)) 2008 else if (VALID_CALLBACK(uvd, processData))
2007 GET_CALLBACK(uvd, processData)(uvd, frame); 2009 GET_CALLBACK(uvd, processData)(uvd, frame);
2008 else 2010 else
2009 err("%s: processData not set", __FUNCTION__); 2011 err("%s: processData not set", __func__);
2010 } 2012 }
2011 } while (frame->frameState == FrameState_Grabbing); 2013 } while (frame->frameState == FrameState_Grabbing);
2012 if (uvd->debug >= 2) { 2014 if (uvd->debug >= 2) {
2013 info("%s: Grabbing done; state=%d. (%lu. bytes)", 2015 info("%s: Grabbing done; state=%d. (%lu. bytes)",
2014 __FUNCTION__, frame->frameState, frame->seqRead_Length); 2016 __func__, frame->frameState, frame->seqRead_Length);
2015 } 2017 }
2016 if (frame->frameState == FrameState_Error) { 2018 if (frame->frameState == FrameState_Error) {
2017 int ret = usbvideo_NewFrame(uvd, frameNum); 2019 int ret = usbvideo_NewFrame(uvd, frameNum);
2018 if (ret < 0) { 2020 if (ret < 0) {
2019 err("%s: usbvideo_NewFrame() failed (%d.)", __FUNCTION__, ret); 2021 err("%s: usbvideo_NewFrame() failed (%d.)", __func__, ret);
2020 return ret; 2022 return ret;
2021 } 2023 }
2022 goto redo; 2024 goto redo;
@@ -2048,7 +2050,7 @@ static int usbvideo_GetFrame(struct uvd *uvd, int frameNum)
2048 } 2050 }
2049 frame->frameState = FrameState_Done_Hold; 2051 frame->frameState = FrameState_Done_Hold;
2050 if (uvd->debug >= 2) 2052 if (uvd->debug >= 2)
2051 info("%s: Entered FrameState_Done_Hold state.", __FUNCTION__); 2053 info("%s: Entered FrameState_Done_Hold state.", __func__);
2052 return 0; 2054 return 0;
2053 2055
2054 case FrameState_Done_Hold: 2056 case FrameState_Done_Hold:
@@ -2059,12 +2061,12 @@ static int usbvideo_GetFrame(struct uvd *uvd, int frameNum)
2059 * it will be released back into the wild to roam freely. 2061 * it will be released back into the wild to roam freely.
2060 */ 2062 */
2061 if (uvd->debug >= 2) 2063 if (uvd->debug >= 2)
2062 info("%s: FrameState_Done_Hold state.", __FUNCTION__); 2064 info("%s: FrameState_Done_Hold state.", __func__);
2063 return 0; 2065 return 0;
2064 } 2066 }
2065 2067
2066 /* Catch-all for other cases. We shall not be here. */ 2068 /* Catch-all for other cases. We shall not be here. */
2067 err("%s: Invalid state %d.", __FUNCTION__, frame->frameState); 2069 err("%s: Invalid state %d.", __func__, frame->frameState);
2068 frame->frameState = FrameState_Unused; 2070 frame->frameState = FrameState_Unused;
2069 return 0; 2071 return 0;
2070} 2072}
@@ -2160,7 +2162,7 @@ static void usbvideo_SoftwareContrastAdjustment(struct uvd *uvd,
2160 const int ccm = 128; /* Color correction median - see below */ 2162 const int ccm = 128; /* Color correction median - see below */
2161 2163
2162 if ((uvd == NULL) || (frame == NULL)) { 2164 if ((uvd == NULL) || (frame == NULL)) {
2163 err("%s: Illegal call.", __FUNCTION__); 2165 err("%s: Illegal call.", __func__);
2164 return; 2166 return;
2165 } 2167 }
2166 adj = (uvd->vpic.contrast - 0x8000) >> 8; /* -128..+127 = -ccm..+(ccm-1)*/ 2168 adj = (uvd->vpic.contrast - 0x8000) >> 8; /* -128..+127 = -ccm..+(ccm-1)*/
diff --git a/drivers/media/video/usbvideo/vicam.c b/drivers/media/video/usbvideo/vicam.c
index da1ba0211108..64819353276a 100644
--- a/drivers/media/video/usbvideo/vicam.c
+++ b/drivers/media/video/usbvideo/vicam.c
@@ -48,7 +48,7 @@
48// #define VICAM_DEBUG 48// #define VICAM_DEBUG
49 49
50#ifdef VICAM_DEBUG 50#ifdef VICAM_DEBUG
51#define ADBG(lineno,fmt,args...) printk(fmt, jiffies, __FUNCTION__, lineno, ##args) 51#define ADBG(lineno,fmt,args...) printk(fmt, jiffies, __func__, lineno, ##args)
52#define DBG(fmt,args...) ADBG((__LINE__),KERN_DEBUG __FILE__"(%ld):%s (%d):"fmt,##args) 52#define DBG(fmt,args...) ADBG((__LINE__),KERN_DEBUG __FILE__"(%ld):%s (%d):"fmt,##args)
53#else 53#else
54#define DBG(fmn,args...) do {} while(0) 54#define DBG(fmn,args...) do {} while(0)
@@ -1066,7 +1066,9 @@ static const struct file_operations vicam_fops = {
1066 .read = vicam_read, 1066 .read = vicam_read,
1067 .mmap = vicam_mmap, 1067 .mmap = vicam_mmap,
1068 .ioctl = vicam_ioctl, 1068 .ioctl = vicam_ioctl,
1069#ifdef CONFIG_COMPAT
1069 .compat_ioctl = v4l_compat_ioctl32, 1070 .compat_ioctl = v4l_compat_ioctl32,
1071#endif
1070 .llseek = no_llseek, 1072 .llseek = no_llseek,
1071}; 1073};
1072 1074
diff --git a/drivers/media/video/usbvision/usbvision-core.c b/drivers/media/video/usbvision/usbvision-core.c
index 56775ab8b75d..a9c5e5adba3a 100644
--- a/drivers/media/video/usbvision/usbvision-core.c
+++ b/drivers/media/video/usbvision/usbvision-core.c
@@ -53,19 +53,21 @@
53 53
54#include "usbvision.h" 54#include "usbvision.h"
55 55
56static unsigned int core_debug = 0; 56static unsigned int core_debug;
57module_param(core_debug,int,0644); 57module_param(core_debug,int,0644);
58MODULE_PARM_DESC(core_debug,"enable debug messages [core]"); 58MODULE_PARM_DESC(core_debug,"enable debug messages [core]");
59 59
60static unsigned int force_testpattern = 0; 60static unsigned int force_testpattern;
61module_param(force_testpattern,int,0644); 61module_param(force_testpattern,int,0644);
62MODULE_PARM_DESC(force_testpattern,"enable test pattern display [core]"); 62MODULE_PARM_DESC(force_testpattern,"enable test pattern display [core]");
63 63
64static int adjustCompression = 1; // Set the compression to be adaptive 64static int adjustCompression = 1; /* Set the compression to be adaptive */
65module_param(adjustCompression, int, 0444); 65module_param(adjustCompression, int, 0444);
66MODULE_PARM_DESC(adjustCompression, " Set the ADPCM compression for the device. Default: 1 (On)"); 66MODULE_PARM_DESC(adjustCompression, " Set the ADPCM compression for the device. Default: 1 (On)");
67 67
68static int SwitchSVideoInput = 0; // To help people with Black and White output with using s-video input. Some cables and input device are wired differently. 68/* To help people with Black and White output with using s-video input.
69 * Some cables and input device are wired differently. */
70static int SwitchSVideoInput;
69module_param(SwitchSVideoInput, int, 0444); 71module_param(SwitchSVideoInput, int, 0444);
70MODULE_PARM_DESC(SwitchSVideoInput, " Set the S-Video input. Some cables and input device are wired differently. Default: 0 (Off)"); 72MODULE_PARM_DESC(SwitchSVideoInput, " Set the S-Video input. Some cables and input device are wired differently. Default: 0 (Off)");
71 73
@@ -82,8 +84,10 @@ MODULE_PARM_DESC(adjust_Y_Offset, "adjust Y offset display [core]");
82 84
83 85
84#ifdef USBVISION_DEBUG 86#ifdef USBVISION_DEBUG
85 #define PDEBUG(level, fmt, args...) \ 87 #define PDEBUG(level, fmt, args...) { \
86 if (core_debug & (level)) info("[%s:%d] " fmt, __PRETTY_FUNCTION__, __LINE__ , ## args) 88 if (core_debug & (level)) \
89 info("[%s:%d] " fmt, __func__, __LINE__ , ## args); \
90 }
87#else 91#else
88 #define PDEBUG(level, fmt, args...) do {} while(0) 92 #define PDEBUG(level, fmt, args...) do {} while(0)
89#endif 93#endif
@@ -384,7 +388,7 @@ int usbvision_scratch_alloc(struct usb_usbvision *usbvision)
384 scratch_reset(usbvision); 388 scratch_reset(usbvision);
385 if(usbvision->scratch == NULL) { 389 if(usbvision->scratch == NULL) {
386 err("%s: unable to allocate %d bytes for scratch", 390 err("%s: unable to allocate %d bytes for scratch",
387 __FUNCTION__, scratch_buf_size); 391 __func__, scratch_buf_size);
388 return -ENOMEM; 392 return -ENOMEM;
389 } 393 }
390 return 0; 394 return 0;
@@ -418,7 +422,7 @@ static void usbvision_testpattern(struct usb_usbvision *usbvision,
418 unsigned char *f; 422 unsigned char *f;
419 int num_cell = 0; 423 int num_cell = 0;
420 int scan_length = 0; 424 int scan_length = 0;
421 static int num_pass = 0; 425 static int num_pass;
422 426
423 if (usbvision == NULL) { 427 if (usbvision == NULL) {
424 printk(KERN_ERR "%s: usbvision == NULL\n", proc); 428 printk(KERN_ERR "%s: usbvision == NULL\n", proc);
@@ -493,7 +497,8 @@ int usbvision_decompress_alloc(struct usb_usbvision *usbvision)
493 int IFB_size = MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * 3 / 2; 497 int IFB_size = MAX_FRAME_WIDTH * MAX_FRAME_HEIGHT * 3 / 2;
494 usbvision->IntraFrameBuffer = vmalloc_32(IFB_size); 498 usbvision->IntraFrameBuffer = vmalloc_32(IFB_size);
495 if (usbvision->IntraFrameBuffer == NULL) { 499 if (usbvision->IntraFrameBuffer == NULL) {
496 err("%s: unable to allocate %d for compr. frame buffer", __FUNCTION__, IFB_size); 500 err("%s: unable to allocate %d for compr. frame buffer",
501 __func__, IFB_size);
497 return -ENOMEM; 502 return -ENOMEM;
498 } 503 }
499 return 0; 504 return 0;
@@ -1430,7 +1435,7 @@ static int usbvision_compress_isochronous(struct usb_usbvision *usbvision,
1430 } 1435 }
1431#if ENABLE_HEXDUMP 1436#if ENABLE_HEXDUMP
1432 if (totlen > 0) { 1437 if (totlen > 0) {
1433 static int foo = 0; 1438 static int foo;
1434 if (foo < 1) { 1439 if (foo < 1) {
1435 printk(KERN_DEBUG "+%d.\n", usbvision->scratchlen); 1440 printk(KERN_DEBUG "+%d.\n", usbvision->scratchlen);
1436 usbvision_hexdump(data0, (totlen > 64) ? 64 : totlen); 1441 usbvision_hexdump(data0, (totlen > 64) ? 64 : totlen);
@@ -1516,7 +1521,7 @@ static void usbvision_isocIrq(struct urb *urb)
1516 1521
1517 if(errCode) { 1522 if(errCode) {
1518 err("%s: usb_submit_urb failed: error %d", 1523 err("%s: usb_submit_urb failed: error %d",
1519 __FUNCTION__, errCode); 1524 __func__, errCode);
1520 } 1525 }
1521 1526
1522 return; 1527 return;
@@ -1547,7 +1552,7 @@ int usbvision_read_reg(struct usb_usbvision *usbvision, unsigned char reg)
1547 0, (__u16) reg, buffer, 1, HZ); 1552 0, (__u16) reg, buffer, 1, HZ);
1548 1553
1549 if (errCode < 0) { 1554 if (errCode < 0) {
1550 err("%s: failed: error %d", __FUNCTION__, errCode); 1555 err("%s: failed: error %d", __func__, errCode);
1551 return errCode; 1556 return errCode;
1552 } 1557 }
1553 return buffer[0]; 1558 return buffer[0];
@@ -1575,7 +1580,7 @@ int usbvision_write_reg(struct usb_usbvision *usbvision, unsigned char reg,
1575 USB_RECIP_ENDPOINT, 0, (__u16) reg, &value, 1, HZ); 1580 USB_RECIP_ENDPOINT, 0, (__u16) reg, &value, 1, HZ);
1576 1581
1577 if (errCode < 0) { 1582 if (errCode < 0) {
1578 err("%s: failed: error %d", __FUNCTION__, errCode); 1583 err("%s: failed: error %d", __func__, errCode);
1579 } 1584 }
1580 return errCode; 1585 return errCode;
1581} 1586}
@@ -1851,7 +1856,7 @@ int usbvision_set_output(struct usb_usbvision *usbvision, int width,
1851 0, (__u16) USBVISION_LXSIZE_O, value, 4, HZ); 1856 0, (__u16) USBVISION_LXSIZE_O, value, 4, HZ);
1852 1857
1853 if (errCode < 0) { 1858 if (errCode < 0) {
1854 err("%s failed: error %d", __FUNCTION__, errCode); 1859 err("%s failed: error %d", __func__, errCode);
1855 return errCode; 1860 return errCode;
1856 } 1861 }
1857 usbvision->curwidth = usbvision->stretch_width * UsbWidth; 1862 usbvision->curwidth = usbvision->stretch_width * UsbWidth;
@@ -2237,7 +2242,7 @@ static int usbvision_set_dram_settings(struct usb_usbvision *usbvision)
2237 (__u16) USBVISION_DRM_PRM1, value, 8, HZ); 2242 (__u16) USBVISION_DRM_PRM1, value, 8, HZ);
2238 2243
2239 if (rc < 0) { 2244 if (rc < 0) {
2240 err("%sERROR=%d", __FUNCTION__, rc); 2245 err("%sERROR=%d", __func__, rc);
2241 return rc; 2246 return rc;
2242 } 2247 }
2243 2248
@@ -2486,7 +2491,7 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
2486 2491
2487 urb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL); 2492 urb = usb_alloc_urb(USBVISION_URB_FRAMES, GFP_KERNEL);
2488 if (urb == NULL) { 2493 if (urb == NULL) {
2489 err("%s: usb_alloc_urb() failed", __FUNCTION__); 2494 err("%s: usb_alloc_urb() failed", __func__);
2490 return -ENOMEM; 2495 return -ENOMEM;
2491 } 2496 }
2492 usbvision->sbuf[bufIdx].urb = urb; 2497 usbvision->sbuf[bufIdx].urb = urb;
@@ -2520,13 +2525,13 @@ int usbvision_init_isoc(struct usb_usbvision *usbvision)
2520 GFP_KERNEL); 2525 GFP_KERNEL);
2521 if (errCode) { 2526 if (errCode) {
2522 err("%s: usb_submit_urb(%d) failed: error %d", 2527 err("%s: usb_submit_urb(%d) failed: error %d",
2523 __FUNCTION__, bufIdx, errCode); 2528 __func__, bufIdx, errCode);
2524 } 2529 }
2525 } 2530 }
2526 2531
2527 usbvision->streaming = Stream_Idle; 2532 usbvision->streaming = Stream_Idle;
2528 PDEBUG(DBG_ISOC, "%s: streaming=1 usbvision->video_endp=$%02x", 2533 PDEBUG(DBG_ISOC, "%s: streaming=1 usbvision->video_endp=$%02x",
2529 __FUNCTION__, 2534 __func__,
2530 usbvision->video_endp); 2535 usbvision->video_endp);
2531 return 0; 2536 return 0;
2532} 2537}
@@ -2560,7 +2565,7 @@ void usbvision_stop_isoc(struct usb_usbvision *usbvision)
2560 } 2565 }
2561 2566
2562 2567
2563 PDEBUG(DBG_ISOC, "%s: streaming=Stream_Off\n", __FUNCTION__); 2568 PDEBUG(DBG_ISOC, "%s: streaming=Stream_Off\n", __func__);
2564 usbvision->streaming = Stream_Off; 2569 usbvision->streaming = Stream_Off;
2565 2570
2566 if (!usbvision->remove_pending) { 2571 if (!usbvision->remove_pending) {
@@ -2571,7 +2576,7 @@ void usbvision_stop_isoc(struct usb_usbvision *usbvision)
2571 usbvision->ifaceAlt); 2576 usbvision->ifaceAlt);
2572 if (errCode < 0) { 2577 if (errCode < 0) {
2573 err("%s: usb_set_interface() failed: error %d", 2578 err("%s: usb_set_interface() failed: error %d",
2574 __FUNCTION__, errCode); 2579 __func__, errCode);
2575 usbvision->last_error = errCode; 2580 usbvision->last_error = errCode;
2576 } 2581 }
2577 regValue = (16-usbvision_read_reg(usbvision, USBVISION_ALTER_REG)) & 0x0F; 2582 regValue = (16-usbvision_read_reg(usbvision, USBVISION_ALTER_REG)) & 0x0F;
diff --git a/drivers/media/video/usbvision/usbvision-i2c.c b/drivers/media/video/usbvision/usbvision-i2c.c
index aabc42cae9c7..e2274d77ea29 100644
--- a/drivers/media/video/usbvision/usbvision-i2c.c
+++ b/drivers/media/video/usbvision/usbvision-i2c.c
@@ -40,13 +40,15 @@
40 40
41#define DBG_I2C 1<<0 41#define DBG_I2C 1<<0
42 42
43static int i2c_debug = 0; 43static int i2c_debug;
44 44
45module_param (i2c_debug, int, 0644); // debug_i2c_usb mode of the device driver 45module_param (i2c_debug, int, 0644); // debug_i2c_usb mode of the device driver
46MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]"); 46MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
47 47
48#define PDEBUG(level, fmt, args...) \ 48#define PDEBUG(level, fmt, args...) { \
49 if (i2c_debug & (level)) info("[%s:%d] " fmt, __PRETTY_FUNCTION__, __LINE__ , ## args) 49 if (i2c_debug & (level)) \
50 info("[%s:%d] " fmt, __func__, __LINE__ , ## args); \
51 }
50 52
51static int usbvision_i2c_write(struct usb_usbvision *usbvision, unsigned char addr, char *buf, 53static int usbvision_i2c_write(struct usb_usbvision *usbvision, unsigned char addr, char *buf,
52 short len); 54 short len);
diff --git a/drivers/media/video/usbvision/usbvision-video.c b/drivers/media/video/usbvision/usbvision-video.c
index df52f8a60215..d97261ab430f 100644
--- a/drivers/media/video/usbvision/usbvision-video.c
+++ b/drivers/media/video/usbvision/usbvision-video.c
@@ -97,10 +97,10 @@ USBVISION_DRIVER_VERSION_PATCHLEVEL)
97 97
98 98
99#ifdef USBVISION_DEBUG 99#ifdef USBVISION_DEBUG
100 #define PDEBUG(level, fmt, args...) \ 100 #define PDEBUG(level, fmt, args...) { \
101 if (video_debug & (level)) \ 101 if (video_debug & (level)) \
102 info("[%s:%d] " fmt, __PRETTY_FUNCTION__, __LINE__ ,\ 102 info("[%s:%d] " fmt, __func__, __LINE__ , ## args); \
103 ## args) 103 }
104#else 104#else
105 #define PDEBUG(level, fmt, args...) do {} while(0) 105 #define PDEBUG(level, fmt, args...) do {} while(0)
106#endif 106#endif
@@ -115,7 +115,7 @@ USBVISION_DRIVER_VERSION_PATCHLEVEL)
115 115
116 116
117/* sequential number of usbvision device */ 117/* sequential number of usbvision device */
118static int usbvision_nr = 0; 118static int usbvision_nr;
119 119
120static struct usbvision_v4l2_format_st usbvision_v4l2_format[] = { 120static struct usbvision_v4l2_format_st usbvision_v4l2_format[] = {
121 { 1, 1, 8, V4L2_PIX_FMT_GREY , "GREY" }, 121 { 1, 1, 8, V4L2_PIX_FMT_GREY , "GREY" },
@@ -135,7 +135,7 @@ static void usbvision_release(struct usb_usbvision *usbvision);
135/* Set the default format for ISOC endpoint */ 135/* Set the default format for ISOC endpoint */
136static int isocMode = ISOC_MODE_COMPRESS; 136static int isocMode = ISOC_MODE_COMPRESS;
137/* Set the default Debug Mode of the device driver */ 137/* Set the default Debug Mode of the device driver */
138static int video_debug = 0; 138static int video_debug;
139/* Set the default device to power on at startup */ 139/* Set the default device to power on at startup */
140static int PowerOnAtOpen = 1; 140static int PowerOnAtOpen = 1;
141/* Sequential Number of Video Device */ 141/* Sequential Number of Video Device */
@@ -343,7 +343,7 @@ static void usbvision_create_sysfs(struct video_device *vdev)
343 return; 343 return;
344 } while (0); 344 } while (0);
345 345
346 err("%s error: %d\n", __FUNCTION__, res); 346 err("%s error: %d\n", __func__, res);
347} 347}
348 348
349static void usbvision_remove_sysfs(struct video_device *vdev) 349static void usbvision_remove_sysfs(struct video_device *vdev)
@@ -490,7 +490,7 @@ static int usbvision_v4l2_close(struct inode *inode, struct file *file)
490 mutex_unlock(&usbvision->lock); 490 mutex_unlock(&usbvision->lock);
491 491
492 if (usbvision->remove_pending) { 492 if (usbvision->remove_pending) {
493 printk(KERN_INFO "%s: Final disconnect\n", __FUNCTION__); 493 printk(KERN_INFO "%s: Final disconnect\n", __func__);
494 usbvision_release(usbvision); 494 usbvision_release(usbvision);
495 } 495 }
496 496
@@ -522,7 +522,7 @@ static int vidioc_g_register (struct file *file, void *priv,
522 errCode = usbvision_read_reg(usbvision, reg->reg&0xff); 522 errCode = usbvision_read_reg(usbvision, reg->reg&0xff);
523 if (errCode < 0) { 523 if (errCode < 0) {
524 err("%s: VIDIOC_DBG_G_REGISTER failed: error %d", 524 err("%s: VIDIOC_DBG_G_REGISTER failed: error %d",
525 __FUNCTION__, errCode); 525 __func__, errCode);
526 return errCode; 526 return errCode;
527 } 527 }
528 reg->val = errCode; 528 reg->val = errCode;
@@ -543,7 +543,7 @@ static int vidioc_s_register (struct file *file, void *priv,
543 errCode = usbvision_write_reg(usbvision, reg->reg&0xff, reg->val); 543 errCode = usbvision_write_reg(usbvision, reg->reg&0xff, reg->val);
544 if (errCode < 0) { 544 if (errCode < 0) {
545 err("%s: VIDIOC_DBG_S_REGISTER failed: error %d", 545 err("%s: VIDIOC_DBG_S_REGISTER failed: error %d",
546 __FUNCTION__, errCode); 546 __func__, errCode);
547 return errCode; 547 return errCode;
548 } 548 }
549 return 0; 549 return 0;
@@ -1102,7 +1102,7 @@ static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
1102 int ret,i; 1102 int ret,i;
1103 struct usbvision_frame *frame; 1103 struct usbvision_frame *frame;
1104 1104
1105 PDEBUG(DBG_IO, "%s: %ld bytes, noblock=%d", __FUNCTION__, 1105 PDEBUG(DBG_IO, "%s: %ld bytes, noblock=%d", __func__,
1106 (unsigned long)count, noblock); 1106 (unsigned long)count, noblock);
1107 1107
1108 if (!USBVISION_IS_OPERATIONAL(usbvision) || (buf == NULL)) 1108 if (!USBVISION_IS_OPERATIONAL(usbvision) || (buf == NULL))
@@ -1171,7 +1171,7 @@ static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
1171 } 1171 }
1172 1172
1173 PDEBUG(DBG_IO, "%s: frmx=%d, bytes_read=%ld, scanlength=%ld", 1173 PDEBUG(DBG_IO, "%s: frmx=%d, bytes_read=%ld, scanlength=%ld",
1174 __FUNCTION__, 1174 __func__,
1175 frame->index, frame->bytes_read, frame->scanlength); 1175 frame->index, frame->bytes_read, frame->scanlength);
1176 1176
1177 /* copy bytes to user space; we allow for partials reads */ 1177 /* copy bytes to user space; we allow for partials reads */
@@ -1184,7 +1184,7 @@ static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
1184 1184
1185 frame->bytes_read += count; 1185 frame->bytes_read += count;
1186 PDEBUG(DBG_IO, "%s: {copy} count used=%ld, new bytes_read=%ld", 1186 PDEBUG(DBG_IO, "%s: {copy} count used=%ld, new bytes_read=%ld",
1187 __FUNCTION__, 1187 __func__,
1188 (unsigned long)count, frame->bytes_read); 1188 (unsigned long)count, frame->bytes_read);
1189 1189
1190 /* For now, forget the frame if it has not been read in one shot. */ 1190 /* For now, forget the frame if it has not been read in one shot. */
@@ -1269,12 +1269,12 @@ static int usbvision_radio_open(struct inode *inode, struct file *file)
1269 (struct usb_usbvision *) video_get_drvdata(dev); 1269 (struct usb_usbvision *) video_get_drvdata(dev);
1270 int errCode = 0; 1270 int errCode = 0;
1271 1271
1272 PDEBUG(DBG_IO, "%s:", __FUNCTION__); 1272 PDEBUG(DBG_IO, "%s:", __func__);
1273 1273
1274 mutex_lock(&usbvision->lock); 1274 mutex_lock(&usbvision->lock);
1275 1275
1276 if (usbvision->user) { 1276 if (usbvision->user) {
1277 err("%s: Someone tried to open an already opened USBVision Radio!", __FUNCTION__); 1277 err("%s: Someone tried to open an already opened USBVision Radio!", __func__);
1278 errCode = -EBUSY; 1278 errCode = -EBUSY;
1279 } 1279 }
1280 else { 1280 else {
@@ -1342,7 +1342,7 @@ static int usbvision_radio_close(struct inode *inode, struct file *file)
1342 mutex_unlock(&usbvision->lock); 1342 mutex_unlock(&usbvision->lock);
1343 1343
1344 if (usbvision->remove_pending) { 1344 if (usbvision->remove_pending) {
1345 printk(KERN_INFO "%s: Final disconnect\n", __FUNCTION__); 1345 printk(KERN_INFO "%s: Final disconnect\n", __func__);
1346 usbvision_release(usbvision); 1346 usbvision_release(usbvision);
1347 } 1347 }
1348 1348
@@ -1507,7 +1507,7 @@ static struct video_device *usbvision_vdev_init(struct usb_usbvision *usbvision,
1507 struct video_device *vdev; 1507 struct video_device *vdev;
1508 1508
1509 if (usb_dev == NULL) { 1509 if (usb_dev == NULL) {
1510 err("%s: usbvision->dev is not set", __FUNCTION__); 1510 err("%s: usbvision->dev is not set", __func__);
1511 return NULL; 1511 return NULL;
1512 } 1512 }
1513 1513
@@ -1759,7 +1759,7 @@ static int __devinit usbvision_probe(struct usb_interface *intf,
1759 PDEBUG(DBG_PROBE, "model out of bounds %d",model); 1759 PDEBUG(DBG_PROBE, "model out of bounds %d",model);
1760 return -ENODEV; 1760 return -ENODEV;
1761 } 1761 }
1762 printk(KERN_INFO "%s: %s found\n", __FUNCTION__, 1762 printk(KERN_INFO "%s: %s found\n", __func__,
1763 usbvision_device_data[model].ModelString); 1763 usbvision_device_data[model].ModelString);
1764 1764
1765 if (usbvision_device_data[model].Interface >= 0) { 1765 if (usbvision_device_data[model].Interface >= 0) {
@@ -1771,20 +1771,20 @@ static int __devinit usbvision_probe(struct usb_interface *intf,
1771 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) != 1771 if ((endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) !=
1772 USB_ENDPOINT_XFER_ISOC) { 1772 USB_ENDPOINT_XFER_ISOC) {
1773 err("%s: interface %d. has non-ISO endpoint!", 1773 err("%s: interface %d. has non-ISO endpoint!",
1774 __FUNCTION__, ifnum); 1774 __func__, ifnum);
1775 err("%s: Endpoint attributes %d", 1775 err("%s: Endpoint attributes %d",
1776 __FUNCTION__, endpoint->bmAttributes); 1776 __func__, endpoint->bmAttributes);
1777 return -ENODEV; 1777 return -ENODEV;
1778 } 1778 }
1779 if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) == 1779 if ((endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) ==
1780 USB_DIR_OUT) { 1780 USB_DIR_OUT) {
1781 err("%s: interface %d. has ISO OUT endpoint!", 1781 err("%s: interface %d. has ISO OUT endpoint!",
1782 __FUNCTION__, ifnum); 1782 __func__, ifnum);
1783 return -ENODEV; 1783 return -ENODEV;
1784 } 1784 }
1785 1785
1786 if ((usbvision = usbvision_alloc(dev)) == NULL) { 1786 if ((usbvision = usbvision_alloc(dev)) == NULL) {
1787 err("%s: couldn't allocate USBVision struct", __FUNCTION__); 1787 err("%s: couldn't allocate USBVision struct", __func__);
1788 return -ENOMEM; 1788 return -ENOMEM;
1789 } 1789 }
1790 1790
@@ -1868,7 +1868,7 @@ static void __devexit usbvision_disconnect(struct usb_interface *intf)
1868 PDEBUG(DBG_PROBE, ""); 1868 PDEBUG(DBG_PROBE, "");
1869 1869
1870 if (usbvision == NULL) { 1870 if (usbvision == NULL) {
1871 err("%s: usb_get_intfdata() failed", __FUNCTION__); 1871 err("%s: usb_get_intfdata() failed", __func__);
1872 return; 1872 return;
1873 } 1873 }
1874 usb_set_intfdata (intf, NULL); 1874 usb_set_intfdata (intf, NULL);
@@ -1891,7 +1891,7 @@ static void __devexit usbvision_disconnect(struct usb_interface *intf)
1891 1891
1892 if (usbvision->user) { 1892 if (usbvision->user) {
1893 printk(KERN_INFO "%s: In use, disconnect pending\n", 1893 printk(KERN_INFO "%s: In use, disconnect pending\n",
1894 __FUNCTION__); 1894 __func__);
1895 wake_up_interruptible(&usbvision->wait_frame); 1895 wake_up_interruptible(&usbvision->wait_frame);
1896 wake_up_interruptible(&usbvision->wait_stream); 1896 wake_up_interruptible(&usbvision->wait_stream);
1897 } else { 1897 } else {
diff --git a/drivers/media/video/v4l1-compat.c b/drivers/media/video/v4l1-compat.c
index e3ac5e686075..a0f6c60279ec 100644
--- a/drivers/media/video/v4l1-compat.c
+++ b/drivers/media/video/v4l1-compat.c
@@ -39,15 +39,18 @@
39#include <linux/kmod.h> 39#include <linux/kmod.h>
40#endif 40#endif
41 41
42static unsigned int debug = 0; 42static unsigned int debug;
43module_param(debug, int, 0644); 43module_param(debug, int, 0644);
44MODULE_PARM_DESC(debug,"enable debug messages"); 44MODULE_PARM_DESC(debug, "enable debug messages");
45MODULE_AUTHOR("Bill Dirks"); 45MODULE_AUTHOR("Bill Dirks");
46MODULE_DESCRIPTION("v4l(1) compatibility layer for v4l2 drivers."); 46MODULE_DESCRIPTION("v4l(1) compatibility layer for v4l2 drivers.");
47MODULE_LICENSE("GPL"); 47MODULE_LICENSE("GPL");
48 48
49#define dprintk(fmt, arg...) if (debug) \ 49#define dprintk(fmt, arg...) \
50 printk(KERN_DEBUG "v4l1-compat: " fmt , ## arg) 50 do { \
51 if (debug) \
52 printk(KERN_DEBUG "v4l1-compat: " fmt , ## arg);\
53 } while (0)
51 54
52/* 55/*
53 * I O C T L T R A N S L A T I O N 56 * I O C T L T R A N S L A T I O N
@@ -69,14 +72,12 @@ get_v4l_control(struct inode *inode,
69 qctrl2.id = cid; 72 qctrl2.id = cid;
70 err = drv(inode, file, VIDIOC_QUERYCTRL, &qctrl2); 73 err = drv(inode, file, VIDIOC_QUERYCTRL, &qctrl2);
71 if (err < 0) 74 if (err < 0)
72 dprintk("VIDIOC_QUERYCTRL: %d\n",err); 75 dprintk("VIDIOC_QUERYCTRL: %d\n", err);
73 if (err == 0 && 76 if (err == 0 && !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED)) {
74 !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED))
75 {
76 ctrl2.id = qctrl2.id; 77 ctrl2.id = qctrl2.id;
77 err = drv(inode, file, VIDIOC_G_CTRL, &ctrl2); 78 err = drv(inode, file, VIDIOC_G_CTRL, &ctrl2);
78 if (err < 0) { 79 if (err < 0) {
79 dprintk("VIDIOC_G_CTRL: %d\n",err); 80 dprintk("VIDIOC_G_CTRL: %d\n", err);
80 return 0; 81 return 0;
81 } 82 }
82 return ((ctrl2.value - qctrl2.minimum) * 65535 83 return ((ctrl2.value - qctrl2.minimum) * 65535
@@ -100,11 +101,10 @@ set_v4l_control(struct inode *inode,
100 qctrl2.id = cid; 101 qctrl2.id = cid;
101 err = drv(inode, file, VIDIOC_QUERYCTRL, &qctrl2); 102 err = drv(inode, file, VIDIOC_QUERYCTRL, &qctrl2);
102 if (err < 0) 103 if (err < 0)
103 dprintk("VIDIOC_QUERYCTRL: %d\n",err); 104 dprintk("VIDIOC_QUERYCTRL: %d\n", err);
104 if (err == 0 && 105 if (err == 0 &&
105 !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED) && 106 !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED) &&
106 !(qctrl2.flags & V4L2_CTRL_FLAG_GRABBED)) 107 !(qctrl2.flags & V4L2_CTRL_FLAG_GRABBED)) {
107 {
108 if (value < 0) 108 if (value < 0)
109 value = 0; 109 value = 0;
110 if (value > 65535) 110 if (value > 65535)
@@ -119,7 +119,7 @@ set_v4l_control(struct inode *inode,
119 ctrl2.value += qctrl2.minimum; 119 ctrl2.value += qctrl2.minimum;
120 err = drv(inode, file, VIDIOC_S_CTRL, &ctrl2); 120 err = drv(inode, file, VIDIOC_S_CTRL, &ctrl2);
121 if (err < 0) 121 if (err < 0)
122 dprintk("VIDIOC_S_CTRL: %d\n",err); 122 dprintk("VIDIOC_S_CTRL: %d\n", err);
123 } 123 }
124 return 0; 124 return 0;
125} 125}
@@ -157,8 +157,7 @@ static unsigned int __attribute_const__
157pixelformat_to_palette(unsigned int pixelformat) 157pixelformat_to_palette(unsigned int pixelformat)
158{ 158{
159 int palette = 0; 159 int palette = 0;
160 switch (pixelformat) 160 switch (pixelformat) {
161 {
162 case V4L2_PIX_FMT_GREY: 161 case V4L2_PIX_FMT_GREY:
163 palette = VIDEO_PALETTE_GREY; 162 palette = VIDEO_PALETTE_GREY;
164 break; 163 break;
@@ -200,14 +199,13 @@ pixelformat_to_palette(unsigned int pixelformat)
200 199
201/* ----------------------------------------------------------------- */ 200/* ----------------------------------------------------------------- */
202 201
203static int poll_one(struct file *file) 202static int poll_one(struct file *file, struct poll_wqueues *pwq)
204{ 203{
205 int retval = 1; 204 int retval = 1;
206 poll_table *table; 205 poll_table *table;
207 struct poll_wqueues pwq;
208 206
209 poll_initwait(&pwq); 207 poll_initwait(pwq);
210 table = &pwq.pt; 208 table = &pwq->pt;
211 for (;;) { 209 for (;;) {
212 int mask; 210 int mask;
213 set_current_state(TASK_INTERRUPTIBLE); 211 set_current_state(TASK_INTERRUPTIBLE);
@@ -222,878 +220,1073 @@ static int poll_one(struct file *file)
222 schedule(); 220 schedule();
223 } 221 }
224 set_current_state(TASK_RUNNING); 222 set_current_state(TASK_RUNNING);
225 poll_freewait(&pwq); 223 poll_freewait(pwq);
226 return retval; 224 return retval;
227} 225}
228 226
229static int count_inputs(struct inode *inode, 227static int count_inputs(
230 struct file *file, 228 struct inode *inode,
231 v4l2_kioctl drv) 229 struct file *file,
230 v4l2_kioctl drv)
232{ 231{
233 struct v4l2_input input2; 232 struct v4l2_input input2;
234 int i; 233 int i;
235 234
236 for (i = 0;; i++) { 235 for (i = 0;; i++) {
237 memset(&input2,0,sizeof(input2)); 236 memset(&input2, 0, sizeof(input2));
238 input2.index = i; 237 input2.index = i;
239 if (0 != drv(inode,file,VIDIOC_ENUMINPUT, &input2)) 238 if (0 != drv(inode, file, VIDIOC_ENUMINPUT, &input2))
240 break; 239 break;
241 } 240 }
242 return i; 241 return i;
243} 242}
244 243
245static int check_size(struct inode *inode, 244static int check_size(
246 struct file *file, 245 struct inode *inode,
247 v4l2_kioctl drv, 246 struct file *file,
248 int *maxw, int *maxh) 247 v4l2_kioctl drv,
248 int *maxw,
249 int *maxh)
249{ 250{
250 struct v4l2_fmtdesc desc2; 251 struct v4l2_fmtdesc desc2;
251 struct v4l2_format fmt2; 252 struct v4l2_format fmt2;
252 253
253 memset(&desc2,0,sizeof(desc2)); 254 memset(&desc2, 0, sizeof(desc2));
254 memset(&fmt2,0,sizeof(fmt2)); 255 memset(&fmt2, 0, sizeof(fmt2));
255 256
256 desc2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 257 desc2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
257 if (0 != drv(inode,file,VIDIOC_ENUM_FMT, &desc2)) 258 if (0 != drv(inode, file, VIDIOC_ENUM_FMT, &desc2))
258 goto done; 259 goto done;
259 260
260 fmt2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 261 fmt2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
261 fmt2.fmt.pix.width = 10000; 262 fmt2.fmt.pix.width = 10000;
262 fmt2.fmt.pix.height = 10000; 263 fmt2.fmt.pix.height = 10000;
263 fmt2.fmt.pix.pixelformat = desc2.pixelformat; 264 fmt2.fmt.pix.pixelformat = desc2.pixelformat;
264 if (0 != drv(inode,file,VIDIOC_TRY_FMT, &fmt2)) 265 if (0 != drv(inode, file, VIDIOC_TRY_FMT, &fmt2))
265 goto done; 266 goto done;
266 267
267 *maxw = fmt2.fmt.pix.width; 268 *maxw = fmt2.fmt.pix.width;
268 *maxh = fmt2.fmt.pix.height; 269 *maxh = fmt2.fmt.pix.height;
269 270
270 done: 271done:
271 return 0; 272 return 0;
272} 273}
273 274
274/* ----------------------------------------------------------------- */ 275/* ----------------------------------------------------------------- */
275 276
276/* 277static noinline int v4l1_compat_get_capabilities(
277 * This function is exported. 278 struct video_capability *cap,
278 */ 279 struct inode *inode,
279int 280 struct file *file,
280v4l_compat_translate_ioctl(struct inode *inode, 281 v4l2_kioctl drv)
281 struct file *file,
282 int cmd,
283 void *arg,
284 v4l2_kioctl drv)
285{ 282{
286 struct v4l2_capability *cap2 = NULL; 283 int err;
287 struct v4l2_format *fmt2 = NULL; 284 struct v4l2_framebuffer fbuf;
288 enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE; 285 struct v4l2_capability *cap2;
289 286
290 struct v4l2_framebuffer fbuf2; 287 cap2 = kzalloc(sizeof(*cap2), GFP_KERNEL);
291 struct v4l2_input input2; 288 if (!cap2) {
292 struct v4l2_tuner tun2; 289 err = -ENOMEM;
293 struct v4l2_standard std2; 290 return err;
294 struct v4l2_frequency freq2; 291 }
295 struct v4l2_audio aud2; 292 memset(cap, 0, sizeof(*cap));
296 struct v4l2_queryctrl qctrl2; 293 memset(&fbuf, 0, sizeof(fbuf));
297 struct v4l2_buffer buf2;
298 v4l2_std_id sid;
299 int i, err = 0;
300
301 switch (cmd) {
302 case VIDIOCGCAP: /* capability */
303 {
304 struct video_capability *cap = arg;
305
306 cap2 = kzalloc(sizeof(*cap2), GFP_KERNEL);
307 if (!cap2) {
308 err = -ENOMEM;
309 break;
310 }
311 memset(cap, 0, sizeof(*cap));
312 memset(&fbuf2, 0, sizeof(fbuf2));
313 294
314 err = drv(inode, file, VIDIOC_QUERYCAP, cap2); 295 err = drv(inode, file, VIDIOC_QUERYCAP, cap2);
296 if (err < 0) {
297 dprintk("VIDIOCGCAP / VIDIOC_QUERYCAP: %d\n", err);
298 goto done;
299 }
300 if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY) {
301 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf);
315 if (err < 0) { 302 if (err < 0) {
316 dprintk("VIDIOCGCAP / VIDIOC_QUERYCAP: %d\n",err); 303 dprintk("VIDIOCGCAP / VIDIOC_G_FBUF: %d\n", err);
317 break; 304 memset(&fbuf, 0, sizeof(fbuf));
318 } 305 }
319 if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY) { 306 err = 0;
320 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf2);
321 if (err < 0) {
322 dprintk("VIDIOCGCAP / VIDIOC_G_FBUF: %d\n",err);
323 memset(&fbuf2, 0, sizeof(fbuf2));
324 }
325 err = 0;
326 }
327
328 memcpy(cap->name, cap2->card,
329 min(sizeof(cap->name), sizeof(cap2->card)));
330 cap->name[sizeof(cap->name) - 1] = 0;
331 if (cap2->capabilities & V4L2_CAP_VIDEO_CAPTURE)
332 cap->type |= VID_TYPE_CAPTURE;
333 if (cap2->capabilities & V4L2_CAP_TUNER)
334 cap->type |= VID_TYPE_TUNER;
335 if (cap2->capabilities & V4L2_CAP_VBI_CAPTURE)
336 cap->type |= VID_TYPE_TELETEXT;
337 if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY)
338 cap->type |= VID_TYPE_OVERLAY;
339 if (fbuf2.capability & V4L2_FBUF_CAP_LIST_CLIPPING)
340 cap->type |= VID_TYPE_CLIPPING;
341
342 cap->channels = count_inputs(inode,file,drv);
343 check_size(inode,file,drv,
344 &cap->maxwidth,&cap->maxheight);
345 cap->audios = 0; /* FIXME */
346 cap->minwidth = 48; /* FIXME */
347 cap->minheight = 32; /* FIXME */
348 break;
349 } 307 }
350 case VIDIOCGFBUF: /* get frame buffer */
351 {
352 struct video_buffer *buffer = arg;
353 308
354 memset(buffer, 0, sizeof(*buffer)); 309 memcpy(cap->name, cap2->card,
355 memset(&fbuf2, 0, sizeof(fbuf2)); 310 min(sizeof(cap->name), sizeof(cap2->card)));
311 cap->name[sizeof(cap->name) - 1] = 0;
312 if (cap2->capabilities & V4L2_CAP_VIDEO_CAPTURE)
313 cap->type |= VID_TYPE_CAPTURE;
314 if (cap2->capabilities & V4L2_CAP_TUNER)
315 cap->type |= VID_TYPE_TUNER;
316 if (cap2->capabilities & V4L2_CAP_VBI_CAPTURE)
317 cap->type |= VID_TYPE_TELETEXT;
318 if (cap2->capabilities & V4L2_CAP_VIDEO_OVERLAY)
319 cap->type |= VID_TYPE_OVERLAY;
320 if (fbuf.capability & V4L2_FBUF_CAP_LIST_CLIPPING)
321 cap->type |= VID_TYPE_CLIPPING;
322
323 cap->channels = count_inputs(inode, file, drv);
324 check_size(inode, file, drv,
325 &cap->maxwidth, &cap->maxheight);
326 cap->audios = 0; /* FIXME */
327 cap->minwidth = 48; /* FIXME */
328 cap->minheight = 32; /* FIXME */
329
330done:
331 kfree(cap2);
332 return err;
333}
356 334
357 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf2); 335static noinline int v4l1_compat_get_frame_buffer(
358 if (err < 0) { 336 struct video_buffer *buffer,
359 dprintk("VIDIOCGFBUF / VIDIOC_G_FBUF: %d\n",err); 337 struct inode *inode,
360 break; 338 struct file *file,
361 } 339 v4l2_kioctl drv)
362 buffer->base = fbuf2.base; 340{
363 buffer->height = fbuf2.fmt.height; 341 int err;
364 buffer->width = fbuf2.fmt.width; 342 struct v4l2_framebuffer fbuf;
365 343
366 switch (fbuf2.fmt.pixelformat) { 344 memset(buffer, 0, sizeof(*buffer));
367 case V4L2_PIX_FMT_RGB332: 345 memset(&fbuf, 0, sizeof(fbuf));
368 buffer->depth = 8; 346
369 break; 347 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf);
370 case V4L2_PIX_FMT_RGB555: 348 if (err < 0) {
371 buffer->depth = 15; 349 dprintk("VIDIOCGFBUF / VIDIOC_G_FBUF: %d\n", err);
372 break; 350 goto done;
373 case V4L2_PIX_FMT_RGB565: 351 }
374 buffer->depth = 16; 352 buffer->base = fbuf.base;
375 break; 353 buffer->height = fbuf.fmt.height;
376 case V4L2_PIX_FMT_BGR24: 354 buffer->width = fbuf.fmt.width;
377 buffer->depth = 24; 355
378 break; 356 switch (fbuf.fmt.pixelformat) {
379 case V4L2_PIX_FMT_BGR32: 357 case V4L2_PIX_FMT_RGB332:
380 buffer->depth = 32; 358 buffer->depth = 8;
381 break; 359 break;
382 default: 360 case V4L2_PIX_FMT_RGB555:
383 buffer->depth = 0; 361 buffer->depth = 15;
384 } 362 break;
385 if (fbuf2.fmt.bytesperline) { 363 case V4L2_PIX_FMT_RGB565:
386 buffer->bytesperline = fbuf2.fmt.bytesperline; 364 buffer->depth = 16;
387 if (!buffer->depth && buffer->width) 365 break;
388 buffer->depth = ((fbuf2.fmt.bytesperline<<3) 366 case V4L2_PIX_FMT_BGR24:
389 + (buffer->width-1) ) 367 buffer->depth = 24;
390 /buffer->width; 368 break;
391 } else { 369 case V4L2_PIX_FMT_BGR32:
392 buffer->bytesperline = 370 buffer->depth = 32;
393 (buffer->width * buffer->depth + 7) & 7;
394 buffer->bytesperline >>= 3;
395 }
396 break; 371 break;
372 default:
373 buffer->depth = 0;
397 } 374 }
398 case VIDIOCSFBUF: /* set frame buffer */ 375 if (fbuf.fmt.bytesperline) {
399 { 376 buffer->bytesperline = fbuf.fmt.bytesperline;
400 struct video_buffer *buffer = arg; 377 if (!buffer->depth && buffer->width)
401 378 buffer->depth = ((fbuf.fmt.bytesperline<<3)
402 memset(&fbuf2, 0, sizeof(fbuf2)); 379 + (buffer->width-1))
403 fbuf2.base = buffer->base; 380 / buffer->width;
404 fbuf2.fmt.height = buffer->height; 381 } else {
405 fbuf2.fmt.width = buffer->width; 382 buffer->bytesperline =
406 switch (buffer->depth) { 383 (buffer->width * buffer->depth + 7) & 7;
407 case 8: 384 buffer->bytesperline >>= 3;
408 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_RGB332; 385 }
409 break; 386done:
410 case 15: 387 return err;
411 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_RGB555; 388}
412 break; 389
413 case 16: 390static noinline int v4l1_compat_set_frame_buffer(
414 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_RGB565; 391 struct video_buffer *buffer,
415 break; 392 struct inode *inode,
416 case 24: 393 struct file *file,
417 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_BGR24; 394 v4l2_kioctl drv)
418 break; 395{
419 case 32: 396 int err;
420 fbuf2.fmt.pixelformat = V4L2_PIX_FMT_BGR32; 397 struct v4l2_framebuffer fbuf;
421 break; 398
422 } 399 memset(&fbuf, 0, sizeof(fbuf));
423 fbuf2.fmt.bytesperline = buffer->bytesperline; 400 fbuf.base = buffer->base;
424 err = drv(inode, file, VIDIOC_S_FBUF, &fbuf2); 401 fbuf.fmt.height = buffer->height;
425 if (err < 0) 402 fbuf.fmt.width = buffer->width;
426 dprintk("VIDIOCSFBUF / VIDIOC_S_FBUF: %d\n",err); 403 switch (buffer->depth) {
404 case 8:
405 fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB332;
406 break;
407 case 15:
408 fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB555;
409 break;
410 case 16:
411 fbuf.fmt.pixelformat = V4L2_PIX_FMT_RGB565;
412 break;
413 case 24:
414 fbuf.fmt.pixelformat = V4L2_PIX_FMT_BGR24;
415 break;
416 case 32:
417 fbuf.fmt.pixelformat = V4L2_PIX_FMT_BGR32;
427 break; 418 break;
428 } 419 }
429 case VIDIOCGWIN: /* get window or capture dimensions */ 420 fbuf.fmt.bytesperline = buffer->bytesperline;
430 { 421 err = drv(inode, file, VIDIOC_S_FBUF, &fbuf);
431 struct video_window *win = arg; 422 if (err < 0)
423 dprintk("VIDIOCSFBUF / VIDIOC_S_FBUF: %d\n", err);
424 return err;
425}
432 426
433 fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL); 427static noinline int v4l1_compat_get_win_cap_dimensions(
434 if (!fmt2) { 428 struct video_window *win,
435 err = -ENOMEM; 429 struct inode *inode,
436 break; 430 struct file *file,
437 } 431 v4l2_kioctl drv)
438 memset(win,0,sizeof(*win)); 432{
433 int err;
434 struct v4l2_format *fmt;
439 435
440 fmt2->type = V4L2_BUF_TYPE_VIDEO_OVERLAY; 436 fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
441 err = drv(inode, file, VIDIOC_G_FMT, fmt2); 437 if (!fmt) {
442 if (err < 0) 438 err = -ENOMEM;
443 dprintk("VIDIOCGWIN / VIDIOC_G_WIN: %d\n",err); 439 return err;
444 if (err == 0) { 440 }
445 win->x = fmt2->fmt.win.w.left; 441 memset(win, 0, sizeof(*win));
446 win->y = fmt2->fmt.win.w.top;
447 win->width = fmt2->fmt.win.w.width;
448 win->height = fmt2->fmt.win.w.height;
449 win->chromakey = fmt2->fmt.win.chromakey;
450 win->clips = NULL;
451 win->clipcount = 0;
452 break;
453 }
454 442
455 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 443 fmt->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
456 err = drv(inode, file, VIDIOC_G_FMT, fmt2); 444 err = drv(inode, file, VIDIOC_G_FMT, fmt);
457 if (err < 0) { 445 if (err < 0)
458 dprintk("VIDIOCGWIN / VIDIOC_G_FMT: %d\n",err); 446 dprintk("VIDIOCGWIN / VIDIOC_G_WIN: %d\n", err);
459 break; 447 if (err == 0) {
460 } 448 win->x = fmt->fmt.win.w.left;
461 win->x = 0; 449 win->y = fmt->fmt.win.w.top;
462 win->y = 0; 450 win->width = fmt->fmt.win.w.width;
463 win->width = fmt2->fmt.pix.width; 451 win->height = fmt->fmt.win.w.height;
464 win->height = fmt2->fmt.pix.height; 452 win->chromakey = fmt->fmt.win.chromakey;
465 win->chromakey = 0;
466 win->clips = NULL; 453 win->clips = NULL;
467 win->clipcount = 0; 454 win->clipcount = 0;
468 break; 455 goto done;
469 } 456 }
470 case VIDIOCSWIN: /* set window and/or capture dimensions */
471 {
472 struct video_window *win = arg;
473 int err1,err2;
474 457
475 fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL); 458 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
476 if (!fmt2) { 459 err = drv(inode, file, VIDIOC_G_FMT, fmt);
477 err = -ENOMEM; 460 if (err < 0) {
478 break; 461 dprintk("VIDIOCGWIN / VIDIOC_G_FMT: %d\n", err);
479 } 462 goto done;
480 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 463 }
481 drv(inode, file, VIDIOC_STREAMOFF, &fmt2->type); 464 win->x = 0;
482 err1 = drv(inode, file, VIDIOC_G_FMT, fmt2); 465 win->y = 0;
483 if (err1 < 0) 466 win->width = fmt->fmt.pix.width;
484 dprintk("VIDIOCSWIN / VIDIOC_G_FMT: %d\n",err); 467 win->height = fmt->fmt.pix.height;
485 if (err1 == 0) { 468 win->chromakey = 0;
486 fmt2->fmt.pix.width = win->width; 469 win->clips = NULL;
487 fmt2->fmt.pix.height = win->height; 470 win->clipcount = 0;
488 fmt2->fmt.pix.field = V4L2_FIELD_ANY; 471done:
489 fmt2->fmt.pix.bytesperline = 0; 472 kfree(fmt);
490 err = drv(inode, file, VIDIOC_S_FMT, fmt2); 473 return err;
491 if (err < 0) 474}
492 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #1: %d\n",
493 err);
494 win->width = fmt2->fmt.pix.width;
495 win->height = fmt2->fmt.pix.height;
496 }
497 475
498 memset(fmt2,0,sizeof(*fmt2)); 476static noinline int v4l1_compat_set_win_cap_dimensions(
499 fmt2->type = V4L2_BUF_TYPE_VIDEO_OVERLAY; 477 struct video_window *win,
500 fmt2->fmt.win.w.left = win->x; 478 struct inode *inode,
501 fmt2->fmt.win.w.top = win->y; 479 struct file *file,
502 fmt2->fmt.win.w.width = win->width; 480 v4l2_kioctl drv)
503 fmt2->fmt.win.w.height = win->height; 481{
504 fmt2->fmt.win.chromakey = win->chromakey; 482 int err, err1, err2;
505 fmt2->fmt.win.clips = (void __user *)win->clips; 483 struct v4l2_format *fmt;
506 fmt2->fmt.win.clipcount = win->clipcount; 484
507 err2 = drv(inode, file, VIDIOC_S_FMT, fmt2); 485 fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
508 if (err2 < 0) 486 if (!fmt) {
509 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #2: %d\n",err); 487 err = -ENOMEM;
510 488 return err;
511 if (err1 != 0 && err2 != 0)
512 err = err1;
513 break;
514 } 489 }
515 case VIDIOCCAPTURE: /* turn on/off preview */ 490 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
516 { 491 drv(inode, file, VIDIOC_STREAMOFF, &fmt->type);
517 int *on = arg; 492 err1 = drv(inode, file, VIDIOC_G_FMT, fmt);
518 493 if (err1 < 0)
519 if (0 == *on) { 494 dprintk("VIDIOCSWIN / VIDIOC_G_FMT: %d\n", err1);
520 /* dirty hack time. But v4l1 has no STREAMOFF 495 if (err1 == 0) {
521 * equivalent in the API, and this one at 496 fmt->fmt.pix.width = win->width;
522 * least comes close ... */ 497 fmt->fmt.pix.height = win->height;
523 drv(inode, file, VIDIOC_STREAMOFF, &captype); 498 fmt->fmt.pix.field = V4L2_FIELD_ANY;
524 } 499 fmt->fmt.pix.bytesperline = 0;
525 err = drv(inode, file, VIDIOC_OVERLAY, arg); 500 err = drv(inode, file, VIDIOC_S_FMT, fmt);
526 if (err < 0) 501 if (err < 0)
527 dprintk("VIDIOCCAPTURE / VIDIOC_PREVIEW: %d\n",err); 502 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #1: %d\n",
528 break; 503 err);
504 win->width = fmt->fmt.pix.width;
505 win->height = fmt->fmt.pix.height;
529 } 506 }
530 case VIDIOCGCHAN: /* get input information */
531 {
532 struct video_channel *chan = arg;
533 507
534 memset(&input2,0,sizeof(input2)); 508 memset(fmt, 0, sizeof(*fmt));
535 input2.index = chan->channel; 509 fmt->type = V4L2_BUF_TYPE_VIDEO_OVERLAY;
536 err = drv(inode, file, VIDIOC_ENUMINPUT, &input2); 510 fmt->fmt.win.w.left = win->x;
537 if (err < 0) { 511 fmt->fmt.win.w.top = win->y;
538 dprintk("VIDIOCGCHAN / VIDIOC_ENUMINPUT: " 512 fmt->fmt.win.w.width = win->width;
539 "channel=%d err=%d\n",chan->channel,err); 513 fmt->fmt.win.w.height = win->height;
540 break; 514 fmt->fmt.win.chromakey = win->chromakey;
541 } 515 fmt->fmt.win.clips = (void __user *)win->clips;
542 chan->channel = input2.index; 516 fmt->fmt.win.clipcount = win->clipcount;
543 memcpy(chan->name, input2.name, 517 err2 = drv(inode, file, VIDIOC_S_FMT, fmt);
544 min(sizeof(chan->name), sizeof(input2.name))); 518 if (err2 < 0)
545 chan->name[sizeof(chan->name) - 1] = 0; 519 dprintk("VIDIOCSWIN / VIDIOC_S_FMT #2: %d\n", err2);
546 chan->tuners = (input2.type == V4L2_INPUT_TYPE_TUNER) ? 1 : 0; 520
547 chan->flags = (chan->tuners) ? VIDEO_VC_TUNER : 0; 521 if (err1 != 0 && err2 != 0)
548 switch (input2.type) { 522 err = err1;
549 case V4L2_INPUT_TYPE_TUNER: 523 else
550 chan->type = VIDEO_TYPE_TV; 524 err = 0;
551 break; 525 kfree(fmt);
552 default: 526 return err;
553 case V4L2_INPUT_TYPE_CAMERA: 527}
554 chan->type = VIDEO_TYPE_CAMERA;
555 break;
556 }
557 chan->norm = 0;
558 err = drv(inode, file, VIDIOC_G_STD, &sid);
559 if (err < 0)
560 dprintk("VIDIOCGCHAN / VIDIOC_G_STD: %d\n",err);
561 if (err == 0) {
562 if (sid & V4L2_STD_PAL)
563 chan->norm = VIDEO_MODE_PAL;
564 if (sid & V4L2_STD_NTSC)
565 chan->norm = VIDEO_MODE_NTSC;
566 if (sid & V4L2_STD_SECAM)
567 chan->norm = VIDEO_MODE_SECAM;
568 }
569 break;
570 }
571 case VIDIOCSCHAN: /* set input */
572 {
573 struct video_channel *chan = arg;
574 528
575 sid = 0; 529static noinline int v4l1_compat_turn_preview_on_off(
576 err = drv(inode, file, VIDIOC_S_INPUT, &chan->channel); 530 int *on,
577 if (err < 0) 531 struct inode *inode,
578 dprintk("VIDIOCSCHAN / VIDIOC_S_INPUT: %d\n",err); 532 struct file *file,
579 switch (chan->norm) { 533 v4l2_kioctl drv)
580 case VIDEO_MODE_PAL: 534{
581 sid = V4L2_STD_PAL; 535 int err;
582 break; 536 enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
583 case VIDEO_MODE_NTSC: 537
584 sid = V4L2_STD_NTSC; 538 if (0 == *on) {
585 break; 539 /* dirty hack time. But v4l1 has no STREAMOFF
586 case VIDEO_MODE_SECAM: 540 * equivalent in the API, and this one at
587 sid = V4L2_STD_SECAM; 541 * least comes close ... */
588 break; 542 drv(inode, file, VIDIOC_STREAMOFF, &captype);
589 }
590 if (0 != sid) {
591 err = drv(inode, file, VIDIOC_S_STD, &sid);
592 if (err < 0)
593 dprintk("VIDIOCSCHAN / VIDIOC_S_STD: %d\n",err);
594 }
595 break;
596 } 543 }
597 case VIDIOCGPICT: /* get tone controls & partial capture format */ 544 err = drv(inode, file, VIDIOC_OVERLAY, on);
598 { 545 if (err < 0)
599 struct video_picture *pict = arg; 546 dprintk("VIDIOCCAPTURE / VIDIOC_PREVIEW: %d\n", err);
600 547 return err;
601 fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL); 548}
602 if (!fmt2) {
603 err = -ENOMEM;
604 break;
605 }
606 549
607 pict->brightness = get_v4l_control(inode, file, 550static noinline int v4l1_compat_get_input_info(
608 V4L2_CID_BRIGHTNESS,drv); 551 struct video_channel *chan,
609 pict->hue = get_v4l_control(inode, file, 552 struct inode *inode,
610 V4L2_CID_HUE, drv); 553 struct file *file,
611 pict->contrast = get_v4l_control(inode, file, 554 v4l2_kioctl drv)
612 V4L2_CID_CONTRAST, drv); 555{
613 pict->colour = get_v4l_control(inode, file, 556 int err;
614 V4L2_CID_SATURATION, drv); 557 struct v4l2_input input2;
615 pict->whiteness = get_v4l_control(inode, file, 558 v4l2_std_id sid;
616 V4L2_CID_WHITENESS, drv);
617
618 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
619 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
620 if (err < 0) {
621 dprintk("VIDIOCGPICT / VIDIOC_G_FMT: %d\n",err);
622 break;
623 }
624 559
625 pict->depth = ((fmt2->fmt.pix.bytesperline<<3) 560 memset(&input2, 0, sizeof(input2));
626 + (fmt2->fmt.pix.width-1) ) 561 input2.index = chan->channel;
627 /fmt2->fmt.pix.width; 562 err = drv(inode, file, VIDIOC_ENUMINPUT, &input2);
628 pict->palette = pixelformat_to_palette( 563 if (err < 0) {
629 fmt2->fmt.pix.pixelformat); 564 dprintk("VIDIOCGCHAN / VIDIOC_ENUMINPUT: "
565 "channel=%d err=%d\n", chan->channel, err);
566 goto done;
567 }
568 chan->channel = input2.index;
569 memcpy(chan->name, input2.name,
570 min(sizeof(chan->name), sizeof(input2.name)));
571 chan->name[sizeof(chan->name) - 1] = 0;
572 chan->tuners = (input2.type == V4L2_INPUT_TYPE_TUNER) ? 1 : 0;
573 chan->flags = (chan->tuners) ? VIDEO_VC_TUNER : 0;
574 switch (input2.type) {
575 case V4L2_INPUT_TYPE_TUNER:
576 chan->type = VIDEO_TYPE_TV;
577 break;
578 default:
579 case V4L2_INPUT_TYPE_CAMERA:
580 chan->type = VIDEO_TYPE_CAMERA;
630 break; 581 break;
631 } 582 }
632 case VIDIOCSPICT: /* set tone controls & partial capture format */ 583 chan->norm = 0;
633 { 584 err = drv(inode, file, VIDIOC_G_STD, &sid);
634 struct video_picture *pict = arg; 585 if (err < 0)
635 int mem_err = 0, ovl_err = 0; 586 dprintk("VIDIOCGCHAN / VIDIOC_G_STD: %d\n", err);
587 if (err == 0) {
588 if (sid & V4L2_STD_PAL)
589 chan->norm = VIDEO_MODE_PAL;
590 if (sid & V4L2_STD_NTSC)
591 chan->norm = VIDEO_MODE_NTSC;
592 if (sid & V4L2_STD_SECAM)
593 chan->norm = VIDEO_MODE_SECAM;
594 }
595done:
596 return err;
597}
636 598
637 fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL); 599static noinline int v4l1_compat_set_input(
638 if (!fmt2) { 600 struct video_channel *chan,
639 err = -ENOMEM; 601 struct inode *inode,
640 break; 602 struct file *file,
641 } 603 v4l2_kioctl drv)
642 memset(&fbuf2, 0, sizeof(fbuf2)); 604{
643 605 int err;
644 set_v4l_control(inode, file, 606 v4l2_std_id sid = 0;
645 V4L2_CID_BRIGHTNESS, pict->brightness, drv);
646 set_v4l_control(inode, file,
647 V4L2_CID_HUE, pict->hue, drv);
648 set_v4l_control(inode, file,
649 V4L2_CID_CONTRAST, pict->contrast, drv);
650 set_v4l_control(inode, file,
651 V4L2_CID_SATURATION, pict->colour, drv);
652 set_v4l_control(inode, file,
653 V4L2_CID_WHITENESS, pict->whiteness, drv);
654 /*
655 * V4L1 uses this ioctl to set both memory capture and overlay
656 * pixel format, while V4L2 has two different ioctls for this.
657 * Some cards may not support one or the other, and may support
658 * different pixel formats for memory vs overlay.
659 */
660
661 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
662 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
663 /* If VIDIOC_G_FMT failed, then the driver likely doesn't
664 support memory capture. Trying to set the memory capture
665 parameters would be pointless. */
666 if (err < 0) {
667 dprintk("VIDIOCSPICT / VIDIOC_G_FMT: %d\n",err);
668 mem_err = -1000; /* didn't even try */
669 } else if (fmt2->fmt.pix.pixelformat !=
670 palette_to_pixelformat(pict->palette)) {
671 fmt2->fmt.pix.pixelformat = palette_to_pixelformat(
672 pict->palette);
673 mem_err = drv(inode, file, VIDIOC_S_FMT, fmt2);
674 if (mem_err < 0)
675 dprintk("VIDIOCSPICT / VIDIOC_S_FMT: %d\n",
676 mem_err);
677 }
678 607
679 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf2); 608 err = drv(inode, file, VIDIOC_S_INPUT, &chan->channel);
680 /* If VIDIOC_G_FBUF failed, then the driver likely doesn't 609 if (err < 0)
681 support overlay. Trying to set the overlay parameters 610 dprintk("VIDIOCSCHAN / VIDIOC_S_INPUT: %d\n", err);
682 would be quite pointless. */ 611 switch (chan->norm) {
683 if (err < 0) { 612 case VIDEO_MODE_PAL:
684 dprintk("VIDIOCSPICT / VIDIOC_G_FBUF: %d\n",err); 613 sid = V4L2_STD_PAL;
685 ovl_err = -1000; /* didn't even try */ 614 break;
686 } else if (fbuf2.fmt.pixelformat != 615 case VIDEO_MODE_NTSC:
687 palette_to_pixelformat(pict->palette)) { 616 sid = V4L2_STD_NTSC;
688 fbuf2.fmt.pixelformat = palette_to_pixelformat( 617 break;
689 pict->palette); 618 case VIDEO_MODE_SECAM:
690 ovl_err = drv(inode, file, VIDIOC_S_FBUF, &fbuf2); 619 sid = V4L2_STD_SECAM;
691 if (ovl_err < 0)
692 dprintk("VIDIOCSPICT / VIDIOC_S_FBUF: %d\n",
693 ovl_err);
694 }
695 if (ovl_err < 0 && mem_err < 0)
696 /* ioctl failed, couldn't set either parameter */
697 if (mem_err != -1000) {
698 err = mem_err;
699 } else if (ovl_err == -EPERM) {
700 err = 0;
701 } else {
702 err = ovl_err;
703 }
704 else
705 err = 0;
706 break; 620 break;
707 } 621 }
708 case VIDIOCGTUNER: /* get tuner information */ 622 if (0 != sid) {
709 { 623 err = drv(inode, file, VIDIOC_S_STD, &sid);
710 struct video_tuner *tun = arg;
711
712 memset(&tun2,0,sizeof(tun2));
713 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
714 if (err < 0) {
715 dprintk("VIDIOCGTUNER / VIDIOC_G_TUNER: %d\n",err);
716 break;
717 }
718 memcpy(tun->name, tun2.name,
719 min(sizeof(tun->name), sizeof(tun2.name)));
720 tun->name[sizeof(tun->name) - 1] = 0;
721 tun->rangelow = tun2.rangelow;
722 tun->rangehigh = tun2.rangehigh;
723 tun->flags = 0;
724 tun->mode = VIDEO_MODE_AUTO;
725
726 for (i = 0; i < 64; i++) {
727 memset(&std2,0,sizeof(std2));
728 std2.index = i;
729 if (0 != drv(inode, file, VIDIOC_ENUMSTD, &std2))
730 break;
731 if (std2.id & V4L2_STD_PAL)
732 tun->flags |= VIDEO_TUNER_PAL;
733 if (std2.id & V4L2_STD_NTSC)
734 tun->flags |= VIDEO_TUNER_NTSC;
735 if (std2.id & V4L2_STD_SECAM)
736 tun->flags |= VIDEO_TUNER_SECAM;
737 }
738
739 err = drv(inode, file, VIDIOC_G_STD, &sid);
740 if (err < 0) 624 if (err < 0)
741 dprintk("VIDIOCGTUNER / VIDIOC_G_STD: %d\n",err); 625 dprintk("VIDIOCSCHAN / VIDIOC_S_STD: %d\n", err);
742 if (err == 0) {
743 if (sid & V4L2_STD_PAL)
744 tun->mode = VIDEO_MODE_PAL;
745 if (sid & V4L2_STD_NTSC)
746 tun->mode = VIDEO_MODE_NTSC;
747 if (sid & V4L2_STD_SECAM)
748 tun->mode = VIDEO_MODE_SECAM;
749 }
750
751 if (tun2.capability & V4L2_TUNER_CAP_LOW)
752 tun->flags |= VIDEO_TUNER_LOW;
753 if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
754 tun->flags |= VIDEO_TUNER_STEREO_ON;
755 tun->signal = tun2.signal;
756 break;
757 } 626 }
758 case VIDIOCSTUNER: /* select a tuner input */ 627 return err;
759 { 628}
760 struct video_tuner *tun = arg;
761 struct v4l2_tuner t;
762 memset(&t,0,sizeof(t));
763
764 t.index=tun->tuner;
765 629
766 err = drv(inode, file, VIDIOC_S_INPUT, &t); 630static noinline int v4l1_compat_get_picture(
767 if (err < 0) 631 struct video_picture *pict,
768 dprintk("VIDIOCSTUNER / VIDIOC_S_INPUT: %d\n",err); 632 struct inode *inode,
633 struct file *file,
634 v4l2_kioctl drv)
635{
636 int err;
637 struct v4l2_format *fmt;
769 638
770 break; 639 fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
640 if (!fmt) {
641 err = -ENOMEM;
642 return err;
771 } 643 }
772 case VIDIOCGFREQ: /* get frequency */
773 {
774 unsigned long *freq = arg;
775 memset(&freq2,0,sizeof(freq2));
776 644
777 freq2.tuner = 0; 645 pict->brightness = get_v4l_control(inode, file,
778 err = drv(inode, file, VIDIOC_G_FREQUENCY, &freq2); 646 V4L2_CID_BRIGHTNESS, drv);
779 if (err < 0) 647 pict->hue = get_v4l_control(inode, file,
780 dprintk("VIDIOCGFREQ / VIDIOC_G_FREQUENCY: %d\n",err); 648 V4L2_CID_HUE, drv);
781 if (0 == err) 649 pict->contrast = get_v4l_control(inode, file,
782 *freq = freq2.frequency; 650 V4L2_CID_CONTRAST, drv);
783 break; 651 pict->colour = get_v4l_control(inode, file,
652 V4L2_CID_SATURATION, drv);
653 pict->whiteness = get_v4l_control(inode, file,
654 V4L2_CID_WHITENESS, drv);
655
656 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
657 err = drv(inode, file, VIDIOC_G_FMT, fmt);
658 if (err < 0) {
659 dprintk("VIDIOCGPICT / VIDIOC_G_FMT: %d\n", err);
660 goto done;
784 } 661 }
785 case VIDIOCSFREQ: /* set frequency */
786 {
787 unsigned long *freq = arg;
788 memset(&freq2,0,sizeof(freq2));
789 662
790 drv(inode, file, VIDIOC_G_FREQUENCY, &freq2); 663 pict->depth = ((fmt->fmt.pix.bytesperline << 3)
791 freq2.frequency = *freq; 664 + (fmt->fmt.pix.width - 1))
792 err = drv(inode, file, VIDIOC_S_FREQUENCY, &freq2); 665 / fmt->fmt.pix.width;
793 if (err < 0) 666 pict->palette = pixelformat_to_palette(
794 dprintk("VIDIOCSFREQ / VIDIOC_S_FREQUENCY: %d\n",err); 667 fmt->fmt.pix.pixelformat);
795 break; 668done:
669 kfree(fmt);
670 return err;
671}
672
673static noinline int v4l1_compat_set_picture(
674 struct video_picture *pict,
675 struct inode *inode,
676 struct file *file,
677 v4l2_kioctl drv)
678{
679 int err;
680 struct v4l2_framebuffer fbuf;
681 int mem_err = 0, ovl_err = 0;
682 struct v4l2_format *fmt;
683
684 fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
685 if (!fmt) {
686 err = -ENOMEM;
687 return err;
688 }
689 memset(&fbuf, 0, sizeof(fbuf));
690
691 set_v4l_control(inode, file,
692 V4L2_CID_BRIGHTNESS, pict->brightness, drv);
693 set_v4l_control(inode, file,
694 V4L2_CID_HUE, pict->hue, drv);
695 set_v4l_control(inode, file,
696 V4L2_CID_CONTRAST, pict->contrast, drv);
697 set_v4l_control(inode, file,
698 V4L2_CID_SATURATION, pict->colour, drv);
699 set_v4l_control(inode, file,
700 V4L2_CID_WHITENESS, pict->whiteness, drv);
701 /*
702 * V4L1 uses this ioctl to set both memory capture and overlay
703 * pixel format, while V4L2 has two different ioctls for this.
704 * Some cards may not support one or the other, and may support
705 * different pixel formats for memory vs overlay.
706 */
707
708 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
709 err = drv(inode, file, VIDIOC_G_FMT, fmt);
710 /* If VIDIOC_G_FMT failed, then the driver likely doesn't
711 support memory capture. Trying to set the memory capture
712 parameters would be pointless. */
713 if (err < 0) {
714 dprintk("VIDIOCSPICT / VIDIOC_G_FMT: %d\n", err);
715 mem_err = -1000; /* didn't even try */
716 } else if (fmt->fmt.pix.pixelformat !=
717 palette_to_pixelformat(pict->palette)) {
718 fmt->fmt.pix.pixelformat = palette_to_pixelformat(
719 pict->palette);
720 mem_err = drv(inode, file, VIDIOC_S_FMT, fmt);
721 if (mem_err < 0)
722 dprintk("VIDIOCSPICT / VIDIOC_S_FMT: %d\n",
723 mem_err);
796 } 724 }
797 case VIDIOCGAUDIO: /* get audio properties/controls */
798 {
799 struct video_audio *aud = arg;
800 memset(&aud2,0,sizeof(aud2));
801 725
802 err = drv(inode, file, VIDIOC_G_AUDIO, &aud2); 726 err = drv(inode, file, VIDIOC_G_FBUF, &fbuf);
803 if (err < 0) { 727 /* If VIDIOC_G_FBUF failed, then the driver likely doesn't
804 dprintk("VIDIOCGAUDIO / VIDIOC_G_AUDIO: %d\n",err); 728 support overlay. Trying to set the overlay parameters
805 break; 729 would be quite pointless. */
806 } 730 if (err < 0) {
807 memcpy(aud->name, aud2.name, 731 dprintk("VIDIOCSPICT / VIDIOC_G_FBUF: %d\n", err);
808 min(sizeof(aud->name), sizeof(aud2.name))); 732 ovl_err = -1000; /* didn't even try */
809 aud->name[sizeof(aud->name) - 1] = 0; 733 } else if (fbuf.fmt.pixelformat !=
810 aud->audio = aud2.index; 734 palette_to_pixelformat(pict->palette)) {
811 aud->flags = 0; 735 fbuf.fmt.pixelformat = palette_to_pixelformat(
812 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_VOLUME, drv); 736 pict->palette);
813 if (i >= 0) { 737 ovl_err = drv(inode, file, VIDIOC_S_FBUF, &fbuf);
814 aud->volume = i; 738 if (ovl_err < 0)
815 aud->flags |= VIDEO_AUDIO_VOLUME; 739 dprintk("VIDIOCSPICT / VIDIOC_S_FBUF: %d\n",
816 } 740 ovl_err);
817 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_BASS, drv); 741 }
818 if (i >= 0) { 742 if (ovl_err < 0 && mem_err < 0) {
819 aud->bass = i; 743 /* ioctl failed, couldn't set either parameter */
820 aud->flags |= VIDEO_AUDIO_BASS; 744 if (mem_err != -1000)
821 } 745 err = mem_err;
822 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_TREBLE, drv); 746 else if (ovl_err == -EPERM)
823 if (i >= 0) {
824 aud->treble = i;
825 aud->flags |= VIDEO_AUDIO_TREBLE;
826 }
827 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_BALANCE, drv);
828 if (i >= 0) {
829 aud->balance = i;
830 aud->flags |= VIDEO_AUDIO_BALANCE;
831 }
832 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_MUTE, drv);
833 if (i >= 0) {
834 if (i)
835 aud->flags |= VIDEO_AUDIO_MUTE;
836 aud->flags |= VIDEO_AUDIO_MUTABLE;
837 }
838 aud->step = 1;
839 qctrl2.id = V4L2_CID_AUDIO_VOLUME;
840 if (drv(inode, file, VIDIOC_QUERYCTRL, &qctrl2) == 0 &&
841 !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED))
842 aud->step = qctrl2.step;
843 aud->mode = 0;
844
845 memset(&tun2,0,sizeof(tun2));
846 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
847 if (err < 0) {
848 dprintk("VIDIOCGAUDIO / VIDIOC_G_TUNER: %d\n",err);
849 err = 0; 747 err = 0;
748 else
749 err = ovl_err;
750 } else
751 err = 0;
752 kfree(fmt);
753 return err;
754}
755
756static noinline int v4l1_compat_get_tuner(
757 struct video_tuner *tun,
758 struct inode *inode,
759 struct file *file,
760 v4l2_kioctl drv)
761{
762 int err, i;
763 struct v4l2_tuner tun2;
764 struct v4l2_standard std2;
765 v4l2_std_id sid;
766
767 memset(&tun2, 0, sizeof(tun2));
768 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
769 if (err < 0) {
770 dprintk("VIDIOCGTUNER / VIDIOC_G_TUNER: %d\n", err);
771 goto done;
772 }
773 memcpy(tun->name, tun2.name,
774 min(sizeof(tun->name), sizeof(tun2.name)));
775 tun->name[sizeof(tun->name) - 1] = 0;
776 tun->rangelow = tun2.rangelow;
777 tun->rangehigh = tun2.rangehigh;
778 tun->flags = 0;
779 tun->mode = VIDEO_MODE_AUTO;
780
781 for (i = 0; i < 64; i++) {
782 memset(&std2, 0, sizeof(std2));
783 std2.index = i;
784 if (0 != drv(inode, file, VIDIOC_ENUMSTD, &std2))
850 break; 785 break;
851 } 786 if (std2.id & V4L2_STD_PAL)
787 tun->flags |= VIDEO_TUNER_PAL;
788 if (std2.id & V4L2_STD_NTSC)
789 tun->flags |= VIDEO_TUNER_NTSC;
790 if (std2.id & V4L2_STD_SECAM)
791 tun->flags |= VIDEO_TUNER_SECAM;
792 }
852 793
853 if (tun2.rxsubchans & V4L2_TUNER_SUB_LANG2) 794 err = drv(inode, file, VIDIOC_G_STD, &sid);
854 aud->mode = VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2; 795 if (err < 0)
855 else if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO) 796 dprintk("VIDIOCGTUNER / VIDIOC_G_STD: %d\n", err);
856 aud->mode = VIDEO_SOUND_STEREO; 797 if (err == 0) {
857 else if (tun2.rxsubchans & V4L2_TUNER_SUB_MONO) 798 if (sid & V4L2_STD_PAL)
858 aud->mode = VIDEO_SOUND_MONO; 799 tun->mode = VIDEO_MODE_PAL;
859 break; 800 if (sid & V4L2_STD_NTSC)
801 tun->mode = VIDEO_MODE_NTSC;
802 if (sid & V4L2_STD_SECAM)
803 tun->mode = VIDEO_MODE_SECAM;
860 } 804 }
861 case VIDIOCSAUDIO: /* set audio controls */
862 {
863 struct video_audio *aud = arg;
864 805
865 memset(&aud2,0,sizeof(aud2)); 806 if (tun2.capability & V4L2_TUNER_CAP_LOW)
866 memset(&tun2,0,sizeof(tun2)); 807 tun->flags |= VIDEO_TUNER_LOW;
808 if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
809 tun->flags |= VIDEO_TUNER_STEREO_ON;
810 tun->signal = tun2.signal;
811done:
812 return err;
813}
867 814
868 aud2.index = aud->audio; 815static noinline int v4l1_compat_select_tuner(
869 err = drv(inode, file, VIDIOC_S_AUDIO, &aud2); 816 struct video_tuner *tun,
870 if (err < 0) { 817 struct inode *inode,
871 dprintk("VIDIOCSAUDIO / VIDIOC_S_AUDIO: %d\n",err); 818 struct file *file,
872 break; 819 v4l2_kioctl drv)
873 } 820{
821 int err;
822 struct v4l2_tuner t;/*84 bytes on x86_64*/
823 memset(&t, 0, sizeof(t));
874 824
875 set_v4l_control(inode, file, V4L2_CID_AUDIO_VOLUME, 825 t.index = tun->tuner;
876 aud->volume, drv); 826
877 set_v4l_control(inode, file, V4L2_CID_AUDIO_BASS, 827 err = drv(inode, file, VIDIOC_S_INPUT, &t);
878 aud->bass, drv); 828 if (err < 0)
879 set_v4l_control(inode, file, V4L2_CID_AUDIO_TREBLE, 829 dprintk("VIDIOCSTUNER / VIDIOC_S_INPUT: %d\n", err);
880 aud->treble, drv); 830 return err;
881 set_v4l_control(inode, file, V4L2_CID_AUDIO_BALANCE, 831}
882 aud->balance, drv); 832
883 set_v4l_control(inode, file, V4L2_CID_AUDIO_MUTE, 833static noinline int v4l1_compat_get_frequency(
884 !!(aud->flags & VIDEO_AUDIO_MUTE), drv); 834 unsigned long *freq,
885 835 struct inode *inode,
886 err = drv(inode, file, VIDIOC_G_TUNER, &tun2); 836 struct file *file,
887 if (err < 0) 837 v4l2_kioctl drv)
888 dprintk("VIDIOCSAUDIO / VIDIOC_G_TUNER: %d\n",err); 838{
889 if (err == 0) { 839 int err;
890 switch (aud->mode) { 840 struct v4l2_frequency freq2;
891 default: 841 memset(&freq2, 0, sizeof(freq2));
892 case VIDEO_SOUND_MONO: 842
893 case VIDEO_SOUND_LANG1: 843 freq2.tuner = 0;
894 tun2.audmode = V4L2_TUNER_MODE_MONO; 844 err = drv(inode, file, VIDIOC_G_FREQUENCY, &freq2);
895 break; 845 if (err < 0)
896 case VIDEO_SOUND_STEREO: 846 dprintk("VIDIOCGFREQ / VIDIOC_G_FREQUENCY: %d\n", err);
897 tun2.audmode = V4L2_TUNER_MODE_STEREO; 847 if (0 == err)
898 break; 848 *freq = freq2.frequency;
899 case VIDEO_SOUND_LANG2: 849 return err;
900 tun2.audmode = V4L2_TUNER_MODE_LANG2; 850}
901 break; 851
902 } 852static noinline int v4l1_compat_set_frequency(
903 err = drv(inode, file, VIDIOC_S_TUNER, &tun2); 853 unsigned long *freq,
904 if (err < 0) 854 struct inode *inode,
905 dprintk("VIDIOCSAUDIO / VIDIOC_S_TUNER: %d\n",err); 855 struct file *file,
906 } 856 v4l2_kioctl drv)
857{
858 int err;
859 struct v4l2_frequency freq2;
860 memset(&freq2, 0, sizeof(freq2));
861
862 drv(inode, file, VIDIOC_G_FREQUENCY, &freq2);
863 freq2.frequency = *freq;
864 err = drv(inode, file, VIDIOC_S_FREQUENCY, &freq2);
865 if (err < 0)
866 dprintk("VIDIOCSFREQ / VIDIOC_S_FREQUENCY: %d\n", err);
867 return err;
868}
869
870static noinline int v4l1_compat_get_audio(
871 struct video_audio *aud,
872 struct inode *inode,
873 struct file *file,
874 v4l2_kioctl drv)
875{
876 int err, i;
877 struct v4l2_queryctrl qctrl2;
878 struct v4l2_audio aud2;
879 struct v4l2_tuner tun2;
880 memset(&aud2, 0, sizeof(aud2));
881
882 err = drv(inode, file, VIDIOC_G_AUDIO, &aud2);
883 if (err < 0) {
884 dprintk("VIDIOCGAUDIO / VIDIOC_G_AUDIO: %d\n", err);
885 goto done;
886 }
887 memcpy(aud->name, aud2.name,
888 min(sizeof(aud->name), sizeof(aud2.name)));
889 aud->name[sizeof(aud->name) - 1] = 0;
890 aud->audio = aud2.index;
891 aud->flags = 0;
892 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_VOLUME, drv);
893 if (i >= 0) {
894 aud->volume = i;
895 aud->flags |= VIDEO_AUDIO_VOLUME;
896 }
897 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_BASS, drv);
898 if (i >= 0) {
899 aud->bass = i;
900 aud->flags |= VIDEO_AUDIO_BASS;
901 }
902 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_TREBLE, drv);
903 if (i >= 0) {
904 aud->treble = i;
905 aud->flags |= VIDEO_AUDIO_TREBLE;
906 }
907 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_BALANCE, drv);
908 if (i >= 0) {
909 aud->balance = i;
910 aud->flags |= VIDEO_AUDIO_BALANCE;
911 }
912 i = get_v4l_control(inode, file, V4L2_CID_AUDIO_MUTE, drv);
913 if (i >= 0) {
914 if (i)
915 aud->flags |= VIDEO_AUDIO_MUTE;
916 aud->flags |= VIDEO_AUDIO_MUTABLE;
917 }
918 aud->step = 1;
919 qctrl2.id = V4L2_CID_AUDIO_VOLUME;
920 if (drv(inode, file, VIDIOC_QUERYCTRL, &qctrl2) == 0 &&
921 !(qctrl2.flags & V4L2_CTRL_FLAG_DISABLED))
922 aud->step = qctrl2.step;
923 aud->mode = 0;
924
925 memset(&tun2, 0, sizeof(tun2));
926 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
927 if (err < 0) {
928 dprintk("VIDIOCGAUDIO / VIDIOC_G_TUNER: %d\n", err);
907 err = 0; 929 err = 0;
908 break; 930 goto done;
909 } 931 }
910 case VIDIOCMCAPTURE: /* capture a frame */
911 {
912 struct video_mmap *mm = arg;
913 932
914 fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL); 933 if (tun2.rxsubchans & V4L2_TUNER_SUB_LANG2)
915 if (!fmt2) { 934 aud->mode = VIDEO_SOUND_LANG1 | VIDEO_SOUND_LANG2;
916 err = -ENOMEM; 935 else if (tun2.rxsubchans & V4L2_TUNER_SUB_STEREO)
917 break; 936 aud->mode = VIDEO_SOUND_STEREO;
918 } 937 else if (tun2.rxsubchans & V4L2_TUNER_SUB_MONO)
919 memset(&buf2,0,sizeof(buf2)); 938 aud->mode = VIDEO_SOUND_MONO;
939done:
940 return err;
941}
920 942
921 fmt2->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 943static noinline int v4l1_compat_set_audio(
922 err = drv(inode, file, VIDIOC_G_FMT, fmt2); 944 struct video_audio *aud,
923 if (err < 0) { 945 struct inode *inode,
924 dprintk("VIDIOCMCAPTURE / VIDIOC_G_FMT: %d\n",err); 946 struct file *file,
947 v4l2_kioctl drv)
948{
949 int err;
950 struct v4l2_audio aud2;
951 struct v4l2_tuner tun2;
952
953 memset(&aud2, 0, sizeof(aud2));
954 memset(&tun2, 0, sizeof(tun2));
955
956 aud2.index = aud->audio;
957 err = drv(inode, file, VIDIOC_S_AUDIO, &aud2);
958 if (err < 0) {
959 dprintk("VIDIOCSAUDIO / VIDIOC_S_AUDIO: %d\n", err);
960 goto done;
961 }
962
963 set_v4l_control(inode, file, V4L2_CID_AUDIO_VOLUME,
964 aud->volume, drv);
965 set_v4l_control(inode, file, V4L2_CID_AUDIO_BASS,
966 aud->bass, drv);
967 set_v4l_control(inode, file, V4L2_CID_AUDIO_TREBLE,
968 aud->treble, drv);
969 set_v4l_control(inode, file, V4L2_CID_AUDIO_BALANCE,
970 aud->balance, drv);
971 set_v4l_control(inode, file, V4L2_CID_AUDIO_MUTE,
972 !!(aud->flags & VIDEO_AUDIO_MUTE), drv);
973
974 err = drv(inode, file, VIDIOC_G_TUNER, &tun2);
975 if (err < 0)
976 dprintk("VIDIOCSAUDIO / VIDIOC_G_TUNER: %d\n", err);
977 if (err == 0) {
978 switch (aud->mode) {
979 default:
980 case VIDEO_SOUND_MONO:
981 case VIDEO_SOUND_LANG1:
982 tun2.audmode = V4L2_TUNER_MODE_MONO;
925 break; 983 break;
926 } 984 case VIDEO_SOUND_STEREO:
927 if (mm->width != fmt2->fmt.pix.width || 985 tun2.audmode = V4L2_TUNER_MODE_STEREO;
928 mm->height != fmt2->fmt.pix.height ||
929 palette_to_pixelformat(mm->format) !=
930 fmt2->fmt.pix.pixelformat)
931 {/* New capture format... */
932 fmt2->fmt.pix.width = mm->width;
933 fmt2->fmt.pix.height = mm->height;
934 fmt2->fmt.pix.pixelformat =
935 palette_to_pixelformat(mm->format);
936 fmt2->fmt.pix.field = V4L2_FIELD_ANY;
937 fmt2->fmt.pix.bytesperline = 0;
938 err = drv(inode, file, VIDIOC_S_FMT, fmt2);
939 if (err < 0) {
940 dprintk("VIDIOCMCAPTURE / VIDIOC_S_FMT: %d\n",err);
941 break;
942 }
943 }
944 buf2.index = mm->frame;
945 buf2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
946 err = drv(inode, file, VIDIOC_QUERYBUF, &buf2);
947 if (err < 0) {
948 dprintk("VIDIOCMCAPTURE / VIDIOC_QUERYBUF: %d\n",err);
949 break; 986 break;
950 } 987 case VIDEO_SOUND_LANG2:
951 err = drv(inode, file, VIDIOC_QBUF, &buf2); 988 tun2.audmode = V4L2_TUNER_MODE_LANG2;
952 if (err < 0) {
953 dprintk("VIDIOCMCAPTURE / VIDIOC_QBUF: %d\n",err);
954 break; 989 break;
955 } 990 }
956 err = drv(inode, file, VIDIOC_STREAMON, &captype); 991 err = drv(inode, file, VIDIOC_S_TUNER, &tun2);
957 if (err < 0) 992 if (err < 0)
958 dprintk("VIDIOCMCAPTURE / VIDIOC_STREAMON: %d\n",err); 993 dprintk("VIDIOCSAUDIO / VIDIOC_S_TUNER: %d\n", err);
959 break;
960 } 994 }
961 case VIDIOCSYNC: /* wait for a frame */ 995 err = 0;
962 { 996done:
963 int *i = arg; 997 return err;
998}
964 999
965 memset(&buf2,0,sizeof(buf2)); 1000static noinline int v4l1_compat_capture_frame(
966 buf2.index = *i; 1001 struct video_mmap *mm,
967 buf2.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1002 struct inode *inode,
968 err = drv(inode, file, VIDIOC_QUERYBUF, &buf2); 1003 struct file *file,
969 if (err < 0) { 1004 v4l2_kioctl drv)
970 /* No such buffer */ 1005{
971 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n",err); 1006 int err;
972 break; 1007 enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
973 } 1008 struct v4l2_buffer buf;
974 if (!(buf2.flags & V4L2_BUF_FLAG_MAPPED)) { 1009 struct v4l2_format *fmt;
975 /* Buffer is not mapped */ 1010
976 err = -EINVAL; 1011 fmt = kzalloc(sizeof(*fmt), GFP_KERNEL);
977 break; 1012 if (!fmt) {
978 } 1013 err = -ENOMEM;
1014 return err;
1015 }
1016 memset(&buf, 0, sizeof(buf));
979 1017
980 /* make sure capture actually runs so we don't block forever */ 1018 fmt->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
981 err = drv(inode, file, VIDIOC_STREAMON, &captype); 1019 err = drv(inode, file, VIDIOC_G_FMT, fmt);
1020 if (err < 0) {
1021 dprintk("VIDIOCMCAPTURE / VIDIOC_G_FMT: %d\n", err);
1022 goto done;
1023 }
1024 if (mm->width != fmt->fmt.pix.width ||
1025 mm->height != fmt->fmt.pix.height ||
1026 palette_to_pixelformat(mm->format) !=
1027 fmt->fmt.pix.pixelformat) {
1028 /* New capture format... */
1029 fmt->fmt.pix.width = mm->width;
1030 fmt->fmt.pix.height = mm->height;
1031 fmt->fmt.pix.pixelformat =
1032 palette_to_pixelformat(mm->format);
1033 fmt->fmt.pix.field = V4L2_FIELD_ANY;
1034 fmt->fmt.pix.bytesperline = 0;
1035 err = drv(inode, file, VIDIOC_S_FMT, fmt);
982 if (err < 0) { 1036 if (err < 0) {
983 dprintk("VIDIOCSYNC / VIDIOC_STREAMON: %d\n",err); 1037 dprintk("VIDIOCMCAPTURE / VIDIOC_S_FMT: %d\n", err);
984 break; 1038 goto done;
985 } 1039 }
1040 }
1041 buf.index = mm->frame;
1042 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1043 err = drv(inode, file, VIDIOC_QUERYBUF, &buf);
1044 if (err < 0) {
1045 dprintk("VIDIOCMCAPTURE / VIDIOC_QUERYBUF: %d\n", err);
1046 goto done;
1047 }
1048 err = drv(inode, file, VIDIOC_QBUF, &buf);
1049 if (err < 0) {
1050 dprintk("VIDIOCMCAPTURE / VIDIOC_QBUF: %d\n", err);
1051 goto done;
1052 }
1053 err = drv(inode, file, VIDIOC_STREAMON, &captype);
1054 if (err < 0)
1055 dprintk("VIDIOCMCAPTURE / VIDIOC_STREAMON: %d\n", err);
1056done:
1057 kfree(fmt);
1058 return err;
1059}
986 1060
987 /* Loop as long as the buffer is queued, but not done */ 1061static noinline int v4l1_compat_sync(
988 while ((buf2.flags & 1062 int *i,
989 (V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE)) 1063 struct inode *inode,
990 == V4L2_BUF_FLAG_QUEUED) 1064 struct file *file,
991 { 1065 v4l2_kioctl drv)
992 err = poll_one(file); 1066{
993 if (err < 0 || /* error or sleep was interrupted */ 1067 int err;
994 err == 0) /* timeout? Shouldn't occur. */ 1068 enum v4l2_buf_type captype = V4L2_BUF_TYPE_VIDEO_CAPTURE;
995 break; 1069 struct v4l2_buffer buf;
996 err = drv(inode, file, VIDIOC_QUERYBUF, &buf2); 1070 struct poll_wqueues *pwq;
997 if (err < 0) 1071
998 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n",err); 1072 memset(&buf, 0, sizeof(buf));
999 } 1073 buf.index = *i;
1000 if (!(buf2.flags & V4L2_BUF_FLAG_DONE)) /* not done */ 1074 buf.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1001 break; 1075 err = drv(inode, file, VIDIOC_QUERYBUF, &buf);
1002 do { 1076 if (err < 0) {
1003 err = drv(inode, file, VIDIOC_DQBUF, &buf2); 1077 /* No such buffer */
1004 if (err < 0) 1078 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n", err);
1005 dprintk("VIDIOCSYNC / VIDIOC_DQBUF: %d\n",err); 1079 goto done;
1006 } while (err == 0 && buf2.index != *i); 1080 }
1007 break; 1081 if (!(buf.flags & V4L2_BUF_FLAG_MAPPED)) {
1082 /* Buffer is not mapped */
1083 err = -EINVAL;
1084 goto done;
1008 } 1085 }
1009 1086
1010 case VIDIOCGVBIFMT: /* query VBI data capture format */ 1087 /* make sure capture actually runs so we don't block forever */
1011 { 1088 err = drv(inode, file, VIDIOC_STREAMON, &captype);
1012 struct vbi_format *fmt = arg; 1089 if (err < 0) {
1090 dprintk("VIDIOCSYNC / VIDIOC_STREAMON: %d\n", err);
1091 goto done;
1092 }
1013 1093
1014 fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL); 1094 pwq = kmalloc(sizeof(*pwq), GFP_KERNEL);
1015 if (!fmt2) { 1095 /* Loop as long as the buffer is queued, but not done */
1016 err = -ENOMEM; 1096 while ((buf.flags & (V4L2_BUF_FLAG_QUEUED | V4L2_BUF_FLAG_DONE))
1097 == V4L2_BUF_FLAG_QUEUED) {
1098 err = poll_one(file, pwq);
1099 if (err < 0 || /* error or sleep was interrupted */
1100 err == 0) /* timeout? Shouldn't occur. */
1017 break; 1101 break;
1018 } 1102 err = drv(inode, file, VIDIOC_QUERYBUF, &buf);
1019 fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE; 1103 if (err < 0)
1104 dprintk("VIDIOCSYNC / VIDIOC_QUERYBUF: %d\n", err);
1105 }
1106 kfree(pwq);
1107 if (!(buf.flags & V4L2_BUF_FLAG_DONE)) /* not done */
1108 goto done;
1109 do {
1110 err = drv(inode, file, VIDIOC_DQBUF, &buf);
1111 if (err < 0)
1112 dprintk("VIDIOCSYNC / VIDIOC_DQBUF: %d\n", err);
1113 } while (err == 0 && buf.index != *i);
1114done:
1115 return err;
1116}
1020 1117
1021 err = drv(inode, file, VIDIOC_G_FMT, fmt2); 1118static noinline int v4l1_compat_get_vbi_format(
1022 if (err < 0) { 1119 struct vbi_format *fmt,
1023 dprintk("VIDIOCGVBIFMT / VIDIOC_G_FMT: %d\n", err); 1120 struct inode *inode,
1024 break; 1121 struct file *file,
1025 } 1122 v4l2_kioctl drv)
1026 if (fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY) { 1123{
1027 err = -EINVAL; 1124 int err;
1028 break; 1125 struct v4l2_format *fmt2;
1029 } 1126
1030 memset(fmt, 0, sizeof(*fmt)); 1127 fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL);
1031 fmt->samples_per_line = fmt2->fmt.vbi.samples_per_line; 1128 if (!fmt2) {
1032 fmt->sampling_rate = fmt2->fmt.vbi.sampling_rate; 1129 err = -ENOMEM;
1033 fmt->sample_format = VIDEO_PALETTE_RAW; 1130 return err;
1034 fmt->start[0] = fmt2->fmt.vbi.start[0];
1035 fmt->count[0] = fmt2->fmt.vbi.count[0];
1036 fmt->start[1] = fmt2->fmt.vbi.start[1];
1037 fmt->count[1] = fmt2->fmt.vbi.count[1];
1038 fmt->flags = fmt2->fmt.vbi.flags & 0x03;
1039 break;
1040 } 1131 }
1041 case VIDIOCSVBIFMT: 1132 fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
1042 {
1043 struct vbi_format *fmt = arg;
1044 1133
1045 if (VIDEO_PALETTE_RAW != fmt->sample_format) { 1134 err = drv(inode, file, VIDIOC_G_FMT, fmt2);
1046 err = -EINVAL; 1135 if (err < 0) {
1047 break; 1136 dprintk("VIDIOCGVBIFMT / VIDIOC_G_FMT: %d\n", err);
1048 } 1137 goto done;
1138 }
1139 if (fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY) {
1140 err = -EINVAL;
1141 goto done;
1142 }
1143 memset(fmt, 0, sizeof(*fmt));
1144 fmt->samples_per_line = fmt2->fmt.vbi.samples_per_line;
1145 fmt->sampling_rate = fmt2->fmt.vbi.sampling_rate;
1146 fmt->sample_format = VIDEO_PALETTE_RAW;
1147 fmt->start[0] = fmt2->fmt.vbi.start[0];
1148 fmt->count[0] = fmt2->fmt.vbi.count[0];
1149 fmt->start[1] = fmt2->fmt.vbi.start[1];
1150 fmt->count[1] = fmt2->fmt.vbi.count[1];
1151 fmt->flags = fmt2->fmt.vbi.flags & 0x03;
1152done:
1153 kfree(fmt2);
1154 return err;
1155}
1049 1156
1050 fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL); 1157static noinline int v4l1_compat_set_vbi_format(
1051 if (!fmt2) { 1158 struct vbi_format *fmt,
1052 err = -ENOMEM; 1159 struct inode *inode,
1053 break; 1160 struct file *file,
1054 } 1161 v4l2_kioctl drv)
1055 fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE; 1162{
1056 fmt2->fmt.vbi.samples_per_line = fmt->samples_per_line; 1163 int err;
1057 fmt2->fmt.vbi.sampling_rate = fmt->sampling_rate; 1164 struct v4l2_format *fmt2 = NULL;
1058 fmt2->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
1059 fmt2->fmt.vbi.start[0] = fmt->start[0];
1060 fmt2->fmt.vbi.count[0] = fmt->count[0];
1061 fmt2->fmt.vbi.start[1] = fmt->start[1];
1062 fmt2->fmt.vbi.count[1] = fmt->count[1];
1063 fmt2->fmt.vbi.flags = fmt->flags;
1064 err = drv(inode, file, VIDIOC_TRY_FMT, fmt2);
1065 if (err < 0) {
1066 dprintk("VIDIOCSVBIFMT / VIDIOC_TRY_FMT: %d\n", err);
1067 break;
1068 }
1069 1165
1070 if (fmt2->fmt.vbi.samples_per_line != fmt->samples_per_line || 1166 if (VIDEO_PALETTE_RAW != fmt->sample_format) {
1071 fmt2->fmt.vbi.sampling_rate != fmt->sampling_rate || 1167 err = -EINVAL;
1072 fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY || 1168 return err;
1073 fmt2->fmt.vbi.start[0] != fmt->start[0] ||
1074 fmt2->fmt.vbi.count[0] != fmt->count[0] ||
1075 fmt2->fmt.vbi.start[1] != fmt->start[1] ||
1076 fmt2->fmt.vbi.count[1] != fmt->count[1] ||
1077 fmt2->fmt.vbi.flags != fmt->flags) {
1078 err = -EINVAL;
1079 break;
1080 }
1081 err = drv(inode, file, VIDIOC_S_FMT, fmt2);
1082 if (err < 0)
1083 dprintk("VIDIOCSVBIFMT / VIDIOC_S_FMT: %d\n", err);
1084 break;
1085 } 1169 }
1086 1170
1171 fmt2 = kzalloc(sizeof(*fmt2), GFP_KERNEL);
1172 if (!fmt2) {
1173 err = -ENOMEM;
1174 return err;
1175 }
1176 fmt2->type = V4L2_BUF_TYPE_VBI_CAPTURE;
1177 fmt2->fmt.vbi.samples_per_line = fmt->samples_per_line;
1178 fmt2->fmt.vbi.sampling_rate = fmt->sampling_rate;
1179 fmt2->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
1180 fmt2->fmt.vbi.start[0] = fmt->start[0];
1181 fmt2->fmt.vbi.count[0] = fmt->count[0];
1182 fmt2->fmt.vbi.start[1] = fmt->start[1];
1183 fmt2->fmt.vbi.count[1] = fmt->count[1];
1184 fmt2->fmt.vbi.flags = fmt->flags;
1185 err = drv(inode, file, VIDIOC_TRY_FMT, fmt2);
1186 if (err < 0) {
1187 dprintk("VIDIOCSVBIFMT / VIDIOC_TRY_FMT: %d\n", err);
1188 goto done;
1189 }
1190
1191 if (fmt2->fmt.vbi.samples_per_line != fmt->samples_per_line ||
1192 fmt2->fmt.vbi.sampling_rate != fmt->sampling_rate ||
1193 fmt2->fmt.vbi.sample_format != V4L2_PIX_FMT_GREY ||
1194 fmt2->fmt.vbi.start[0] != fmt->start[0] ||
1195 fmt2->fmt.vbi.count[0] != fmt->count[0] ||
1196 fmt2->fmt.vbi.start[1] != fmt->start[1] ||
1197 fmt2->fmt.vbi.count[1] != fmt->count[1] ||
1198 fmt2->fmt.vbi.flags != fmt->flags) {
1199 err = -EINVAL;
1200 goto done;
1201 }
1202 err = drv(inode, file, VIDIOC_S_FMT, fmt2);
1203 if (err < 0)
1204 dprintk("VIDIOCSVBIFMT / VIDIOC_S_FMT: %d\n", err);
1205done:
1206 kfree(fmt2);
1207 return err;
1208}
1209
1210/*
1211 * This function is exported.
1212 */
1213int
1214v4l_compat_translate_ioctl(struct inode *inode,
1215 struct file *file,
1216 int cmd,
1217 void *arg,
1218 v4l2_kioctl drv)
1219{
1220 int err;
1221
1222 switch (cmd) {
1223 case VIDIOCGCAP: /* capability */
1224 err = v4l1_compat_get_capabilities(arg, inode, file, drv);
1225 break;
1226 case VIDIOCGFBUF: /* get frame buffer */
1227 err = v4l1_compat_get_frame_buffer(arg, inode, file, drv);
1228 break;
1229 case VIDIOCSFBUF: /* set frame buffer */
1230 err = v4l1_compat_set_frame_buffer(arg, inode, file, drv);
1231 break;
1232 case VIDIOCGWIN: /* get window or capture dimensions */
1233 err = v4l1_compat_get_win_cap_dimensions(arg, inode, file, drv);
1234 break;
1235 case VIDIOCSWIN: /* set window and/or capture dimensions */
1236 err = v4l1_compat_set_win_cap_dimensions(arg, inode, file, drv);
1237 break;
1238 case VIDIOCCAPTURE: /* turn on/off preview */
1239 err = v4l1_compat_turn_preview_on_off(arg, inode, file, drv);
1240 break;
1241 case VIDIOCGCHAN: /* get input information */
1242 err = v4l1_compat_get_input_info(arg, inode, file, drv);
1243 break;
1244 case VIDIOCSCHAN: /* set input */
1245 err = v4l1_compat_set_input(arg, inode, file, drv);
1246 break;
1247 case VIDIOCGPICT: /* get tone controls & partial capture format */
1248 err = v4l1_compat_get_picture(arg, inode, file, drv);
1249 break;
1250 case VIDIOCSPICT: /* set tone controls & partial capture format */
1251 err = v4l1_compat_set_picture(arg, inode, file, drv);
1252 break;
1253 case VIDIOCGTUNER: /* get tuner information */
1254 err = v4l1_compat_get_tuner(arg, inode, file, drv);
1255 break;
1256 case VIDIOCSTUNER: /* select a tuner input */
1257 err = v4l1_compat_select_tuner(arg, inode, file, drv);
1258 break;
1259 case VIDIOCGFREQ: /* get frequency */
1260 err = v4l1_compat_get_frequency(arg, inode, file, drv);
1261 break;
1262 case VIDIOCSFREQ: /* set frequency */
1263 err = v4l1_compat_set_frequency(arg, inode, file, drv);
1264 break;
1265 case VIDIOCGAUDIO: /* get audio properties/controls */
1266 err = v4l1_compat_get_audio(arg, inode, file, drv);
1267 break;
1268 case VIDIOCSAUDIO: /* set audio controls */
1269 err = v4l1_compat_set_audio(arg, inode, file, drv);
1270 break;
1271 case VIDIOCMCAPTURE: /* capture a frame */
1272 err = v4l1_compat_capture_frame(arg, inode, file, drv);
1273 break;
1274 case VIDIOCSYNC: /* wait for a frame */
1275 err = v4l1_compat_sync(arg, inode, file, drv);
1276 break;
1277 case VIDIOCGVBIFMT: /* query VBI data capture format */
1278 err = v4l1_compat_get_vbi_format(arg, inode, file, drv);
1279 break;
1280 case VIDIOCSVBIFMT:
1281 err = v4l1_compat_set_vbi_format(arg, inode, file, drv);
1282 break;
1087 default: 1283 default:
1088 err = -ENOIOCTLCMD; 1284 err = -ENOIOCTLCMD;
1089 break; 1285 break;
1090 } 1286 }
1091 1287
1092 kfree(cap2);
1093 kfree(fmt2);
1094 return err; 1288 return err;
1095} 1289}
1096
1097EXPORT_SYMBOL(v4l_compat_translate_ioctl); 1290EXPORT_SYMBOL(v4l_compat_translate_ioctl);
1098 1291
1099/* 1292/*
diff --git a/drivers/media/video/videobuf-core.c b/drivers/media/video/videobuf-core.c
index eab79ffdf56a..fc51e4918bbf 100644
--- a/drivers/media/video/videobuf-core.c
+++ b/drivers/media/video/videobuf-core.c
@@ -64,32 +64,25 @@ void *videobuf_alloc(struct videobuf_queue *q)
64 return vb; 64 return vb;
65} 65}
66 66
67#define WAITON_CONDITION (vb->state != VIDEOBUF_ACTIVE &&\
68 vb->state != VIDEOBUF_QUEUED)
67int videobuf_waiton(struct videobuf_buffer *vb, int non_blocking, int intr) 69int videobuf_waiton(struct videobuf_buffer *vb, int non_blocking, int intr)
68{ 70{
69 int retval = 0;
70 DECLARE_WAITQUEUE(wait, current);
71
72 MAGIC_CHECK(vb->magic, MAGIC_BUFFER); 71 MAGIC_CHECK(vb->magic, MAGIC_BUFFER);
73 add_wait_queue(&vb->done, &wait); 72
74 while (vb->state == VIDEOBUF_ACTIVE || vb->state == VIDEOBUF_QUEUED) { 73 if (non_blocking) {
75 if (non_blocking) { 74 if (WAITON_CONDITION)
76 retval = -EAGAIN; 75 return 0;
77 break; 76 else
78 } 77 return -EAGAIN;
79 set_current_state(intr ? TASK_INTERRUPTIBLE
80 : TASK_UNINTERRUPTIBLE);
81 if (vb->state == VIDEOBUF_ACTIVE ||
82 vb->state == VIDEOBUF_QUEUED)
83 schedule();
84 set_current_state(TASK_RUNNING);
85 if (intr && signal_pending(current)) {
86 dprintk(1, "buffer waiton: -EINTR\n");
87 retval = -EINTR;
88 break;
89 }
90 } 78 }
91 remove_wait_queue(&vb->done, &wait); 79
92 return retval; 80 if (intr)
81 return wait_event_interruptible(vb->done, WAITON_CONDITION);
82 else
83 wait_event(vb->done, WAITON_CONDITION);
84
85 return 0;
93} 86}
94 87
95int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb, 88int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb,
@@ -98,29 +91,22 @@ int videobuf_iolock(struct videobuf_queue *q, struct videobuf_buffer *vb,
98 MAGIC_CHECK(vb->magic, MAGIC_BUFFER); 91 MAGIC_CHECK(vb->magic, MAGIC_BUFFER);
99 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS); 92 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
100 93
101 /* This is required to avoid OOPS on some cases,
102 since mmap_mapper() method should be called before _iolock.
103 On some cases, the mmap_mapper() is called only after scheduling.
104 */
105 if (vb->memory == V4L2_MEMORY_MMAP) {
106 wait_event_timeout(vb->done, q->is_mmapped,
107 msecs_to_jiffies(100));
108 if (!q->is_mmapped) {
109 printk(KERN_ERR
110 "Error: mmap_mapper() never called!\n");
111 return -EINVAL;
112 }
113 }
114
115 return CALL(q, iolock, q, vb, fbuf); 94 return CALL(q, iolock, q, vb, fbuf);
116} 95}
117 96
97void *videobuf_queue_to_vmalloc (struct videobuf_queue *q,
98 struct videobuf_buffer *buf)
99{
100 return CALL(q, vmalloc, buf);
101}
102EXPORT_SYMBOL_GPL(videobuf_queue_to_vmalloc);
103
118/* --------------------------------------------------------------------- */ 104/* --------------------------------------------------------------------- */
119 105
120 106
121void videobuf_queue_core_init(struct videobuf_queue *q, 107void videobuf_queue_core_init(struct videobuf_queue *q,
122 struct videobuf_queue_ops *ops, 108 struct videobuf_queue_ops *ops,
123 void *dev, 109 struct device *dev,
124 spinlock_t *irqlock, 110 spinlock_t *irqlock,
125 enum v4l2_buf_type type, 111 enum v4l2_buf_type type,
126 enum v4l2_field field, 112 enum v4l2_field field,
@@ -144,10 +130,14 @@ void videobuf_queue_core_init(struct videobuf_queue *q,
144 BUG_ON(!q->ops->buf_queue); 130 BUG_ON(!q->ops->buf_queue);
145 BUG_ON(!q->ops->buf_release); 131 BUG_ON(!q->ops->buf_release);
146 132
133 /* Lock is mandatory for queue_cancel to work */
134 BUG_ON(!irqlock);
135
147 /* Having implementations for abstract methods are mandatory */ 136 /* Having implementations for abstract methods are mandatory */
148 BUG_ON(!q->int_ops); 137 BUG_ON(!q->int_ops);
149 138
150 mutex_init(&q->vb_lock); 139 mutex_init(&q->vb_lock);
140 init_waitqueue_head(&q->wait);
151 INIT_LIST_HEAD(&q->stream); 141 INIT_LIST_HEAD(&q->stream);
152} 142}
153 143
@@ -195,19 +185,22 @@ void videobuf_queue_cancel(struct videobuf_queue *q)
195 unsigned long flags = 0; 185 unsigned long flags = 0;
196 int i; 186 int i;
197 187
188 q->streaming = 0;
189 q->reading = 0;
190 wake_up_interruptible_sync(&q->wait);
191
198 /* remove queued buffers from list */ 192 /* remove queued buffers from list */
199 if (q->irqlock) 193 spin_lock_irqsave(q->irqlock, flags);
200 spin_lock_irqsave(q->irqlock, flags);
201 for (i = 0; i < VIDEO_MAX_FRAME; i++) { 194 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
202 if (NULL == q->bufs[i]) 195 if (NULL == q->bufs[i])
203 continue; 196 continue;
204 if (q->bufs[i]->state == VIDEOBUF_QUEUED) { 197 if (q->bufs[i]->state == VIDEOBUF_QUEUED) {
205 list_del(&q->bufs[i]->queue); 198 list_del(&q->bufs[i]->queue);
206 q->bufs[i]->state = VIDEOBUF_ERROR; 199 q->bufs[i]->state = VIDEOBUF_ERROR;
200 wake_up_all(&q->bufs[i]->done);
207 } 201 }
208 } 202 }
209 if (q->irqlock) 203 spin_unlock_irqrestore(q->irqlock, flags);
210 spin_unlock_irqrestore(q->irqlock, flags);
211 204
212 /* free all buffers + clear queue */ 205 /* free all buffers + clear queue */
213 for (i = 0; i < VIDEO_MAX_FRAME; i++) { 206 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
@@ -563,14 +556,13 @@ int videobuf_qbuf(struct videobuf_queue *q,
563 556
564 list_add_tail(&buf->stream, &q->stream); 557 list_add_tail(&buf->stream, &q->stream);
565 if (q->streaming) { 558 if (q->streaming) {
566 if (q->irqlock) 559 spin_lock_irqsave(q->irqlock, flags);
567 spin_lock_irqsave(q->irqlock, flags);
568 q->ops->buf_queue(q, buf); 560 q->ops->buf_queue(q, buf);
569 if (q->irqlock) 561 spin_unlock_irqrestore(q->irqlock, flags);
570 spin_unlock_irqrestore(q->irqlock, flags);
571 } 562 }
572 dprintk(1, "qbuf: succeded\n"); 563 dprintk(1, "qbuf: succeded\n");
573 retval = 0; 564 retval = 0;
565 wake_up_interruptible_sync(&q->wait);
574 566
575 done: 567 done:
576 mutex_unlock(&q->vb_lock); 568 mutex_unlock(&q->vb_lock);
@@ -581,35 +573,88 @@ int videobuf_qbuf(struct videobuf_queue *q,
581 return retval; 573 return retval;
582} 574}
583 575
584int videobuf_dqbuf(struct videobuf_queue *q, 576
585 struct v4l2_buffer *b, int nonblocking) 577/* Locking: Caller holds q->vb_lock */
578static int stream_next_buffer_check_queue(struct videobuf_queue *q, int noblock)
586{ 579{
587 struct videobuf_buffer *buf;
588 int retval; 580 int retval;
589 581
590 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS); 582checks:
591 583 if (!q->streaming) {
592 mutex_lock(&q->vb_lock); 584 dprintk(1, "next_buffer: Not streaming\n");
593 retval = -EBUSY; 585 retval = -EINVAL;
594 if (q->reading) {
595 dprintk(1, "dqbuf: Reading running...\n");
596 goto done;
597 }
598 retval = -EINVAL;
599 if (b->type != q->type) {
600 dprintk(1, "dqbuf: Wrong type.\n");
601 goto done; 586 goto done;
602 } 587 }
588
603 if (list_empty(&q->stream)) { 589 if (list_empty(&q->stream)) {
604 dprintk(1, "dqbuf: stream running\n"); 590 if (noblock) {
605 goto done; 591 retval = -EAGAIN;
592 dprintk(2, "next_buffer: no buffers to dequeue\n");
593 goto done;
594 } else {
595 dprintk(2, "next_buffer: waiting on buffer\n");
596
597 /* Drop lock to avoid deadlock with qbuf */
598 mutex_unlock(&q->vb_lock);
599
600 /* Checking list_empty and streaming is safe without
601 * locks because we goto checks to validate while
602 * holding locks before proceeding */
603 retval = wait_event_interruptible(q->wait,
604 !list_empty(&q->stream) || !q->streaming);
605 mutex_lock(&q->vb_lock);
606
607 if (retval)
608 goto done;
609
610 goto checks;
611 }
606 } 612 }
613
614 retval = 0;
615
616done:
617 return retval;
618}
619
620
621/* Locking: Caller holds q->vb_lock */
622static int stream_next_buffer(struct videobuf_queue *q,
623 struct videobuf_buffer **vb, int nonblocking)
624{
625 int retval;
626 struct videobuf_buffer *buf = NULL;
627
628 retval = stream_next_buffer_check_queue(q, nonblocking);
629 if (retval)
630 goto done;
631
607 buf = list_entry(q->stream.next, struct videobuf_buffer, stream); 632 buf = list_entry(q->stream.next, struct videobuf_buffer, stream);
608 retval = videobuf_waiton(buf, nonblocking, 1); 633 retval = videobuf_waiton(buf, nonblocking, 1);
634 if (retval < 0)
635 goto done;
636
637 *vb = buf;
638done:
639 return retval;
640}
641
642int videobuf_dqbuf(struct videobuf_queue *q,
643 struct v4l2_buffer *b, int nonblocking)
644{
645 struct videobuf_buffer *buf = NULL;
646 int retval;
647
648 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
649
650 mutex_lock(&q->vb_lock);
651
652 retval = stream_next_buffer(q, &buf, nonblocking);
609 if (retval < 0) { 653 if (retval < 0) {
610 dprintk(1, "dqbuf: waiton returned %d\n", retval); 654 dprintk(1, "dqbuf: next_buffer error: %i\n", retval);
611 goto done; 655 goto done;
612 } 656 }
657
613 switch (buf->state) { 658 switch (buf->state) {
614 case VIDEOBUF_ERROR: 659 case VIDEOBUF_ERROR:
615 dprintk(1, "dqbuf: state is error\n"); 660 dprintk(1, "dqbuf: state is error\n");
@@ -650,14 +695,13 @@ int videobuf_streamon(struct videobuf_queue *q)
650 if (q->streaming) 695 if (q->streaming)
651 goto done; 696 goto done;
652 q->streaming = 1; 697 q->streaming = 1;
653 if (q->irqlock) 698 spin_lock_irqsave(q->irqlock, flags);
654 spin_lock_irqsave(q->irqlock, flags);
655 list_for_each_entry(buf, &q->stream, stream) 699 list_for_each_entry(buf, &q->stream, stream)
656 if (buf->state == VIDEOBUF_PREPARED) 700 if (buf->state == VIDEOBUF_PREPARED)
657 q->ops->buf_queue(q, buf); 701 q->ops->buf_queue(q, buf);
658 if (q->irqlock) 702 spin_unlock_irqrestore(q->irqlock, flags);
659 spin_unlock_irqrestore(q->irqlock, flags);
660 703
704 wake_up_interruptible_sync(&q->wait);
661 done: 705 done:
662 mutex_unlock(&q->vb_lock); 706 mutex_unlock(&q->vb_lock);
663 return retval; 707 return retval;
@@ -670,7 +714,6 @@ static int __videobuf_streamoff(struct videobuf_queue *q)
670 return -EINVAL; 714 return -EINVAL;
671 715
672 videobuf_queue_cancel(q); 716 videobuf_queue_cancel(q);
673 q->streaming = 0;
674 717
675 return 0; 718 return 0;
676} 719}
@@ -712,11 +755,9 @@ static ssize_t videobuf_read_zerocopy(struct videobuf_queue *q,
712 goto done; 755 goto done;
713 756
714 /* start capture & wait */ 757 /* start capture & wait */
715 if (q->irqlock) 758 spin_lock_irqsave(q->irqlock, flags);
716 spin_lock_irqsave(q->irqlock, flags);
717 q->ops->buf_queue(q, q->read_buf); 759 q->ops->buf_queue(q, q->read_buf);
718 if (q->irqlock) 760 spin_unlock_irqrestore(q->irqlock, flags);
719 spin_unlock_irqrestore(q->irqlock, flags);
720 retval = videobuf_waiton(q->read_buf, 0, 0); 761 retval = videobuf_waiton(q->read_buf, 0, 0);
721 if (0 == retval) { 762 if (0 == retval) {
722 CALL(q, sync, q, q->read_buf); 763 CALL(q, sync, q, q->read_buf);
@@ -740,14 +781,13 @@ ssize_t videobuf_read_one(struct videobuf_queue *q,
740{ 781{
741 enum v4l2_field field; 782 enum v4l2_field field;
742 unsigned long flags = 0; 783 unsigned long flags = 0;
743 unsigned size, nbufs; 784 unsigned size = 0, nbufs = 1;
744 int retval; 785 int retval;
745 786
746 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS); 787 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
747 788
748 mutex_lock(&q->vb_lock); 789 mutex_lock(&q->vb_lock);
749 790
750 nbufs = 1; size = 0;
751 q->ops->buf_setup(q, &nbufs, &size); 791 q->ops->buf_setup(q, &nbufs, &size);
752 792
753 if (NULL == q->read_buf && 793 if (NULL == q->read_buf &&
@@ -778,12 +818,11 @@ ssize_t videobuf_read_one(struct videobuf_queue *q,
778 q->read_buf = NULL; 818 q->read_buf = NULL;
779 goto done; 819 goto done;
780 } 820 }
781 if (q->irqlock)
782 spin_lock_irqsave(q->irqlock, flags);
783 821
822 spin_lock_irqsave(q->irqlock, flags);
784 q->ops->buf_queue(q, q->read_buf); 823 q->ops->buf_queue(q, q->read_buf);
785 if (q->irqlock) 824 spin_unlock_irqrestore(q->irqlock, flags);
786 spin_unlock_irqrestore(q->irqlock, flags); 825
787 q->read_off = 0; 826 q->read_off = 0;
788 } 827 }
789 828
@@ -849,12 +888,10 @@ static int __videobuf_read_start(struct videobuf_queue *q)
849 return err; 888 return err;
850 list_add_tail(&q->bufs[i]->stream, &q->stream); 889 list_add_tail(&q->bufs[i]->stream, &q->stream);
851 } 890 }
852 if (q->irqlock) 891 spin_lock_irqsave(q->irqlock, flags);
853 spin_lock_irqsave(q->irqlock, flags);
854 for (i = 0; i < count; i++) 892 for (i = 0; i < count; i++)
855 q->ops->buf_queue(q, q->bufs[i]); 893 q->ops->buf_queue(q, q->bufs[i]);
856 if (q->irqlock) 894 spin_unlock_irqrestore(q->irqlock, flags);
857 spin_unlock_irqrestore(q->irqlock, flags);
858 q->reading = 1; 895 q->reading = 1;
859 return 0; 896 return 0;
860} 897}
@@ -863,7 +900,6 @@ static void __videobuf_read_stop(struct videobuf_queue *q)
863{ 900{
864 int i; 901 int i;
865 902
866
867 videobuf_queue_cancel(q); 903 videobuf_queue_cancel(q);
868 __videobuf_mmap_free(q); 904 __videobuf_mmap_free(q);
869 INIT_LIST_HEAD(&q->stream); 905 INIT_LIST_HEAD(&q->stream);
@@ -874,7 +910,6 @@ static void __videobuf_read_stop(struct videobuf_queue *q)
874 q->bufs[i] = NULL; 910 q->bufs[i] = NULL;
875 } 911 }
876 q->read_buf = NULL; 912 q->read_buf = NULL;
877 q->reading = 0;
878 913
879} 914}
880 915
@@ -919,7 +954,7 @@ ssize_t videobuf_read_stream(struct videobuf_queue *q,
919 954
920 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS); 955 MAGIC_CHECK(q->int_ops->magic, MAGIC_QTYPE_OPS);
921 956
922 dprintk(2, "%s\n", __FUNCTION__); 957 dprintk(2, "%s\n", __func__);
923 mutex_lock(&q->vb_lock); 958 mutex_lock(&q->vb_lock);
924 retval = -EBUSY; 959 retval = -EBUSY;
925 if (q->streaming) 960 if (q->streaming)
@@ -968,11 +1003,9 @@ ssize_t videobuf_read_stream(struct videobuf_queue *q,
968 if (q->read_off == q->read_buf->size) { 1003 if (q->read_off == q->read_buf->size) {
969 list_add_tail(&q->read_buf->stream, 1004 list_add_tail(&q->read_buf->stream,
970 &q->stream); 1005 &q->stream);
971 if (q->irqlock) 1006 spin_lock_irqsave(q->irqlock, flags);
972 spin_lock_irqsave(q->irqlock, flags);
973 q->ops->buf_queue(q, q->read_buf); 1007 q->ops->buf_queue(q, q->read_buf);
974 if (q->irqlock) 1008 spin_unlock_irqrestore(q->irqlock, flags);
975 spin_unlock_irqrestore(q->irqlock, flags);
976 q->read_buf = NULL; 1009 q->read_buf = NULL;
977 } 1010 }
978 if (retval < 0) 1011 if (retval < 0)
diff --git a/drivers/media/video/videobuf-dma-sg.c b/drivers/media/video/videobuf-dma-sg.c
index 53fed4b74ce9..03a7b946bd54 100644
--- a/drivers/media/video/videobuf-dma-sg.c
+++ b/drivers/media/video/videobuf-dma-sg.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * helper functions for PCI DMA video4linux capture buffers 2 * helper functions for SG DMA video4linux capture buffers
3 * 3 *
4 * The functions expect the hardware being able to scatter gatter 4 * The functions expect the hardware being able to scatter gatter
5 * (i.e. the buffers are not linear in physical memory, but fragmented 5 * (i.e. the buffers are not linear in physical memory, but fragmented
@@ -24,7 +24,7 @@
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/interrupt.h> 25#include <linux/interrupt.h>
26 26
27#include <linux/pci.h> 27#include <linux/dma-mapping.h>
28#include <linux/vmalloc.h> 28#include <linux/vmalloc.h>
29#include <linux/pagemap.h> 29#include <linux/pagemap.h>
30#include <linux/scatterlist.h> 30#include <linux/scatterlist.h>
@@ -39,10 +39,10 @@
39#define MAGIC_CHECK(is,should) if (unlikely((is) != (should))) \ 39#define MAGIC_CHECK(is,should) if (unlikely((is) != (should))) \
40 { printk(KERN_ERR "magic mismatch: %x (expected %x)\n",is,should); BUG(); } 40 { printk(KERN_ERR "magic mismatch: %x (expected %x)\n",is,should); BUG(); }
41 41
42static int debug = 0; 42static int debug;
43module_param(debug, int, 0644); 43module_param(debug, int, 0644);
44 44
45MODULE_DESCRIPTION("helper module to manage video4linux pci dma sg buffers"); 45MODULE_DESCRIPTION("helper module to manage video4linux dma sg buffers");
46MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>"); 46MODULE_AUTHOR("Mauro Carvalho Chehab <mchehab@infradead.org>");
47MODULE_LICENSE("GPL"); 47MODULE_LICENSE("GPL");
48 48
@@ -119,10 +119,10 @@ videobuf_pages_to_sg(struct page **pages, int nr_pages, int offset)
119 119
120struct videobuf_dmabuf *videobuf_to_dma (struct videobuf_buffer *buf) 120struct videobuf_dmabuf *videobuf_to_dma (struct videobuf_buffer *buf)
121{ 121{
122 struct videbuf_pci_sg_memory *mem=buf->priv; 122 struct videobuf_dma_sg_memory *mem = buf->priv;
123 BUG_ON (!mem); 123 BUG_ON(!mem);
124 124
125 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM); 125 MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
126 126
127 return &mem->dma; 127 return &mem->dma;
128} 128}
@@ -141,9 +141,14 @@ static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
141 141
142 dma->direction = direction; 142 dma->direction = direction;
143 switch (dma->direction) { 143 switch (dma->direction) {
144 case PCI_DMA_FROMDEVICE: rw = READ; break; 144 case DMA_FROM_DEVICE:
145 case PCI_DMA_TODEVICE: rw = WRITE; break; 145 rw = READ;
146 default: BUG(); 146 break;
147 case DMA_TO_DEVICE:
148 rw = WRITE;
149 break;
150 default:
151 BUG();
147 } 152 }
148 153
149 first = (data & PAGE_MASK) >> PAGE_SHIFT; 154 first = (data & PAGE_MASK) >> PAGE_SHIFT;
@@ -157,9 +162,6 @@ static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
157 dprintk(1,"init user [0x%lx+0x%lx => %d pages]\n", 162 dprintk(1,"init user [0x%lx+0x%lx => %d pages]\n",
158 data,size,dma->nr_pages); 163 data,size,dma->nr_pages);
159 164
160 dma->varea = (void *) data;
161
162
163 err = get_user_pages(current,current->mm, 165 err = get_user_pages(current,current->mm,
164 data & PAGE_MASK, dma->nr_pages, 166 data & PAGE_MASK, dma->nr_pages,
165 rw == READ, 1, /* force */ 167 rw == READ, 1, /* force */
@@ -216,10 +218,8 @@ int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
216 return 0; 218 return 0;
217} 219}
218 220
219int videobuf_dma_map(struct videobuf_queue* q,struct videobuf_dmabuf *dma) 221int videobuf_dma_map(struct videobuf_queue* q, struct videobuf_dmabuf *dma)
220{ 222{
221 void *dev=q->dev;
222
223 MAGIC_CHECK(dma->magic,MAGIC_DMABUF); 223 MAGIC_CHECK(dma->magic,MAGIC_DMABUF);
224 BUG_ON(0 == dma->nr_pages); 224 BUG_ON(0 == dma->nr_pages);
225 225
@@ -245,11 +245,11 @@ int videobuf_dma_map(struct videobuf_queue* q,struct videobuf_dmabuf *dma)
245 return -ENOMEM; 245 return -ENOMEM;
246 } 246 }
247 if (!dma->bus_addr) { 247 if (!dma->bus_addr) {
248 dma->sglen = pci_map_sg(dev,dma->sglist, 248 dma->sglen = dma_map_sg(q->dev, dma->sglist,
249 dma->nr_pages, dma->direction); 249 dma->nr_pages, dma->direction);
250 if (0 == dma->sglen) { 250 if (0 == dma->sglen) {
251 printk(KERN_WARNING 251 printk(KERN_WARNING
252 "%s: videobuf_map_sg failed\n",__FUNCTION__); 252 "%s: videobuf_map_sg failed\n",__func__);
253 kfree(dma->sglist); 253 kfree(dma->sglist);
254 dma->sglist = NULL; 254 dma->sglist = NULL;
255 dma->sglen = 0; 255 dma->sglen = 0;
@@ -259,26 +259,22 @@ int videobuf_dma_map(struct videobuf_queue* q,struct videobuf_dmabuf *dma)
259 return 0; 259 return 0;
260} 260}
261 261
262int videobuf_dma_sync(struct videobuf_queue *q,struct videobuf_dmabuf *dma) 262int videobuf_dma_sync(struct videobuf_queue *q, struct videobuf_dmabuf *dma)
263{ 263{
264 void *dev=q->dev; 264 MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
265
266 MAGIC_CHECK(dma->magic,MAGIC_DMABUF);
267 BUG_ON(!dma->sglen); 265 BUG_ON(!dma->sglen);
268 266
269 pci_dma_sync_sg_for_cpu (dev,dma->sglist,dma->nr_pages,dma->direction); 267 dma_sync_sg_for_cpu(q->dev, dma->sglist, dma->nr_pages, dma->direction);
270 return 0; 268 return 0;
271} 269}
272 270
273int videobuf_dma_unmap(struct videobuf_queue* q,struct videobuf_dmabuf *dma) 271int videobuf_dma_unmap(struct videobuf_queue* q,struct videobuf_dmabuf *dma)
274{ 272{
275 void *dev=q->dev; 273 MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
276
277 MAGIC_CHECK(dma->magic,MAGIC_DMABUF);
278 if (!dma->sglen) 274 if (!dma->sglen)
279 return 0; 275 return 0;
280 276
281 pci_unmap_sg (dev,dma->sglist,dma->nr_pages,dma->direction); 277 dma_unmap_sg(q->dev, dma->sglist, dma->nr_pages, dma->direction);
282 278
283 kfree(dma->sglist); 279 kfree(dma->sglist);
284 dma->sglist = NULL; 280 dma->sglist = NULL;
@@ -301,33 +297,32 @@ int videobuf_dma_free(struct videobuf_dmabuf *dma)
301 297
302 vfree(dma->vmalloc); 298 vfree(dma->vmalloc);
303 dma->vmalloc = NULL; 299 dma->vmalloc = NULL;
304 dma->varea = NULL;
305 300
306 if (dma->bus_addr) { 301 if (dma->bus_addr) {
307 dma->bus_addr = 0; 302 dma->bus_addr = 0;
308 } 303 }
309 dma->direction = PCI_DMA_NONE; 304 dma->direction = DMA_NONE;
310 return 0; 305 return 0;
311} 306}
312 307
313/* --------------------------------------------------------------------- */ 308/* --------------------------------------------------------------------- */
314 309
315int videobuf_pci_dma_map(struct pci_dev *pci,struct videobuf_dmabuf *dma) 310int videobuf_sg_dma_map(struct device *dev, struct videobuf_dmabuf *dma)
316{ 311{
317 struct videobuf_queue q; 312 struct videobuf_queue q;
318 313
319 q.dev=pci; 314 q.dev = dev;
320 315
321 return (videobuf_dma_map(&q,dma)); 316 return videobuf_dma_map(&q, dma);
322} 317}
323 318
324int videobuf_pci_dma_unmap(struct pci_dev *pci,struct videobuf_dmabuf *dma) 319int videobuf_sg_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma)
325{ 320{
326 struct videobuf_queue q; 321 struct videobuf_queue q;
327 322
328 q.dev=pci; 323 q.dev = dev;
329 324
330 return (videobuf_dma_unmap(&q,dma)); 325 return videobuf_dma_unmap(&q, dma);
331} 326}
332 327
333/* --------------------------------------------------------------------- */ 328/* --------------------------------------------------------------------- */
@@ -347,7 +342,7 @@ videobuf_vm_close(struct vm_area_struct *vma)
347{ 342{
348 struct videobuf_mapping *map = vma->vm_private_data; 343 struct videobuf_mapping *map = vma->vm_private_data;
349 struct videobuf_queue *q = map->q; 344 struct videobuf_queue *q = map->q;
350 struct videbuf_pci_sg_memory *mem; 345 struct videobuf_dma_sg_memory *mem;
351 int i; 346 int i;
352 347
353 dprintk(2,"vm_close %p [count=%d,vma=%08lx-%08lx]\n",map, 348 dprintk(2,"vm_close %p [count=%d,vma=%08lx-%08lx]\n",map,
@@ -409,18 +404,18 @@ static struct vm_operations_struct videobuf_vm_ops =
409}; 404};
410 405
411/* --------------------------------------------------------------------- 406/* ---------------------------------------------------------------------
412 * PCI handlers for the generic methods 407 * SG handlers for the generic methods
413 */ 408 */
414 409
415/* Allocated area consists on 3 parts: 410/* Allocated area consists on 3 parts:
416 struct video_buffer 411 struct video_buffer
417 struct <driver>_buffer (cx88_buffer, saa7134_buf, ...) 412 struct <driver>_buffer (cx88_buffer, saa7134_buf, ...)
418 struct videobuf_pci_sg_memory 413 struct videobuf_dma_sg_memory
419 */ 414 */
420 415
421static void *__videobuf_alloc(size_t size) 416static void *__videobuf_alloc(size_t size)
422{ 417{
423 struct videbuf_pci_sg_memory *mem; 418 struct videobuf_dma_sg_memory *mem;
424 struct videobuf_buffer *vb; 419 struct videobuf_buffer *vb;
425 420
426 vb = kzalloc(size+sizeof(*mem),GFP_KERNEL); 421 vb = kzalloc(size+sizeof(*mem),GFP_KERNEL);
@@ -431,22 +426,32 @@ static void *__videobuf_alloc(size_t size)
431 videobuf_dma_init(&mem->dma); 426 videobuf_dma_init(&mem->dma);
432 427
433 dprintk(1,"%s: allocated at %p(%ld+%ld) & %p(%ld)\n", 428 dprintk(1,"%s: allocated at %p(%ld+%ld) & %p(%ld)\n",
434 __FUNCTION__,vb,(long)sizeof(*vb),(long)size-sizeof(*vb), 429 __func__,vb,(long)sizeof(*vb),(long)size-sizeof(*vb),
435 mem,(long)sizeof(*mem)); 430 mem,(long)sizeof(*mem));
436 431
437 return vb; 432 return vb;
438} 433}
439 434
435static void *__videobuf_to_vmalloc (struct videobuf_buffer *buf)
436{
437 struct videobuf_dma_sg_memory *mem = buf->priv;
438 BUG_ON(!mem);
439
440 MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
441
442 return mem->dma.vmalloc;
443}
444
440static int __videobuf_iolock (struct videobuf_queue* q, 445static int __videobuf_iolock (struct videobuf_queue* q,
441 struct videobuf_buffer *vb, 446 struct videobuf_buffer *vb,
442 struct v4l2_framebuffer *fbuf) 447 struct v4l2_framebuffer *fbuf)
443{ 448{
444 int err,pages; 449 int err,pages;
445 dma_addr_t bus; 450 dma_addr_t bus;
446 struct videbuf_pci_sg_memory *mem=vb->priv; 451 struct videobuf_dma_sg_memory *mem = vb->priv;
447 BUG_ON(!mem); 452 BUG_ON(!mem);
448 453
449 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM); 454 MAGIC_CHECK(mem->magic, MAGIC_SG_MEM);
450 455
451 switch (vb->memory) { 456 switch (vb->memory) {
452 case V4L2_MEMORY_MMAP: 457 case V4L2_MEMORY_MMAP:
@@ -455,14 +460,14 @@ static int __videobuf_iolock (struct videobuf_queue* q,
455 /* no userspace addr -- kernel bounce buffer */ 460 /* no userspace addr -- kernel bounce buffer */
456 pages = PAGE_ALIGN(vb->size) >> PAGE_SHIFT; 461 pages = PAGE_ALIGN(vb->size) >> PAGE_SHIFT;
457 err = videobuf_dma_init_kernel( &mem->dma, 462 err = videobuf_dma_init_kernel( &mem->dma,
458 PCI_DMA_FROMDEVICE, 463 DMA_FROM_DEVICE,
459 pages ); 464 pages );
460 if (0 != err) 465 if (0 != err)
461 return err; 466 return err;
462 } else if (vb->memory == V4L2_MEMORY_USERPTR) { 467 } else if (vb->memory == V4L2_MEMORY_USERPTR) {
463 /* dma directly to userspace */ 468 /* dma directly to userspace */
464 err = videobuf_dma_init_user( &mem->dma, 469 err = videobuf_dma_init_user( &mem->dma,
465 PCI_DMA_FROMDEVICE, 470 DMA_FROM_DEVICE,
466 vb->baddr,vb->bsize ); 471 vb->baddr,vb->bsize );
467 if (0 != err) 472 if (0 != err)
468 return err; 473 return err;
@@ -473,7 +478,7 @@ static int __videobuf_iolock (struct videobuf_queue* q,
473 locking inversion, so don't take it here */ 478 locking inversion, so don't take it here */
474 479
475 err = videobuf_dma_init_user_locked(&mem->dma, 480 err = videobuf_dma_init_user_locked(&mem->dma,
476 PCI_DMA_FROMDEVICE, 481 DMA_FROM_DEVICE,
477 vb->baddr, vb->bsize); 482 vb->baddr, vb->bsize);
478 if (0 != err) 483 if (0 != err)
479 return err; 484 return err;
@@ -490,7 +495,7 @@ static int __videobuf_iolock (struct videobuf_queue* q,
490 */ 495 */
491 bus = (dma_addr_t)(unsigned long)fbuf->base + vb->boff; 496 bus = (dma_addr_t)(unsigned long)fbuf->base + vb->boff;
492 pages = PAGE_ALIGN(vb->size) >> PAGE_SHIFT; 497 pages = PAGE_ALIGN(vb->size) >> PAGE_SHIFT;
493 err = videobuf_dma_init_overlay(&mem->dma,PCI_DMA_FROMDEVICE, 498 err = videobuf_dma_init_overlay(&mem->dma, DMA_FROM_DEVICE,
494 bus, pages); 499 bus, pages);
495 if (0 != err) 500 if (0 != err)
496 return err; 501 return err;
@@ -498,7 +503,7 @@ static int __videobuf_iolock (struct videobuf_queue* q,
498 default: 503 default:
499 BUG(); 504 BUG();
500 } 505 }
501 err = videobuf_dma_map(q,&mem->dma); 506 err = videobuf_dma_map(q, &mem->dma);
502 if (0 != err) 507 if (0 != err)
503 return err; 508 return err;
504 509
@@ -508,8 +513,8 @@ static int __videobuf_iolock (struct videobuf_queue* q,
508static int __videobuf_sync(struct videobuf_queue *q, 513static int __videobuf_sync(struct videobuf_queue *q,
509 struct videobuf_buffer *buf) 514 struct videobuf_buffer *buf)
510{ 515{
511 struct videbuf_pci_sg_memory *mem=buf->priv; 516 struct videobuf_dma_sg_memory *mem = buf->priv;
512 BUG_ON (!mem); 517 BUG_ON(!mem);
513 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM); 518 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
514 519
515 return videobuf_dma_sync(q,&mem->dma); 520 return videobuf_dma_sync(q,&mem->dma);
@@ -532,7 +537,7 @@ static int __videobuf_mmap_free(struct videobuf_queue *q)
532static int __videobuf_mmap_mapper(struct videobuf_queue *q, 537static int __videobuf_mmap_mapper(struct videobuf_queue *q,
533 struct vm_area_struct *vma) 538 struct vm_area_struct *vma)
534{ 539{
535 struct videbuf_pci_sg_memory *mem; 540 struct videobuf_dma_sg_memory *mem;
536 struct videobuf_mapping *map; 541 struct videobuf_mapping *map;
537 unsigned int first,last,size,i; 542 unsigned int first,last,size,i;
538 int retval; 543 int retval;
@@ -547,12 +552,20 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
547 goto done; 552 goto done;
548 } 553 }
549 554
555 /* This function maintains backwards compatibility with V4L1 and will
556 * map more than one buffer if the vma length is equal to the combined
557 * size of multiple buffers than it will map them together. See
558 * VIDIOCGMBUF in the v4l spec
559 *
560 * TODO: Allow drivers to specify if they support this mode
561 */
562
550 /* look for first buffer to map */ 563 /* look for first buffer to map */
551 for (first = 0; first < VIDEO_MAX_FRAME; first++) { 564 for (first = 0; first < VIDEO_MAX_FRAME; first++) {
552 if (NULL == q->bufs[first]) 565 if (NULL == q->bufs[first])
553 continue; 566 continue;
554 mem=q->bufs[first]->priv; 567 mem=q->bufs[first]->priv;
555 BUG_ON (!mem); 568 BUG_ON(!mem);
556 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM); 569 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
557 570
558 if (V4L2_MEMORY_MMAP != q->bufs[first]->memory) 571 if (V4L2_MEMORY_MMAP != q->bufs[first]->memory)
@@ -591,10 +604,16 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
591 map = kmalloc(sizeof(struct videobuf_mapping),GFP_KERNEL); 604 map = kmalloc(sizeof(struct videobuf_mapping),GFP_KERNEL);
592 if (NULL == map) 605 if (NULL == map)
593 goto done; 606 goto done;
594 for (size = 0, i = first; i <= last; size += q->bufs[i++]->bsize) { 607
608 size = 0;
609 for (i = first; i <= last; i++) {
610 if (NULL == q->bufs[i])
611 continue;
595 q->bufs[i]->map = map; 612 q->bufs[i]->map = map;
596 q->bufs[i]->baddr = vma->vm_start + size; 613 q->bufs[i]->baddr = vma->vm_start + size;
614 size += q->bufs[i]->bsize;
597 } 615 }
616
598 map->count = 1; 617 map->count = 1;
599 map->start = vma->vm_start; 618 map->start = vma->vm_start;
600 map->end = vma->vm_end; 619 map->end = vma->vm_end;
@@ -615,8 +634,8 @@ static int __videobuf_copy_to_user ( struct videobuf_queue *q,
615 char __user *data, size_t count, 634 char __user *data, size_t count,
616 int nonblocking ) 635 int nonblocking )
617{ 636{
618 struct videbuf_pci_sg_memory *mem=q->read_buf->priv; 637 struct videobuf_dma_sg_memory *mem = q->read_buf->priv;
619 BUG_ON (!mem); 638 BUG_ON(!mem);
620 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM); 639 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
621 640
622 /* copy to userspace */ 641 /* copy to userspace */
@@ -634,8 +653,8 @@ static int __videobuf_copy_stream ( struct videobuf_queue *q,
634 int vbihack, int nonblocking ) 653 int vbihack, int nonblocking )
635{ 654{
636 unsigned int *fc; 655 unsigned int *fc;
637 struct videbuf_pci_sg_memory *mem=q->read_buf->priv; 656 struct videobuf_dma_sg_memory *mem = q->read_buf->priv;
638 BUG_ON (!mem); 657 BUG_ON(!mem);
639 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM); 658 MAGIC_CHECK(mem->magic,MAGIC_SG_MEM);
640 659
641 if (vbihack) { 660 if (vbihack) {
@@ -658,7 +677,7 @@ static int __videobuf_copy_stream ( struct videobuf_queue *q,
658 return count; 677 return count;
659} 678}
660 679
661static struct videobuf_qtype_ops pci_ops = { 680static struct videobuf_qtype_ops sg_ops = {
662 .magic = MAGIC_QTYPE_OPS, 681 .magic = MAGIC_QTYPE_OPS,
663 682
664 .alloc = __videobuf_alloc, 683 .alloc = __videobuf_alloc,
@@ -668,23 +687,24 @@ static struct videobuf_qtype_ops pci_ops = {
668 .mmap_mapper = __videobuf_mmap_mapper, 687 .mmap_mapper = __videobuf_mmap_mapper,
669 .video_copy_to_user = __videobuf_copy_to_user, 688 .video_copy_to_user = __videobuf_copy_to_user,
670 .copy_stream = __videobuf_copy_stream, 689 .copy_stream = __videobuf_copy_stream,
690 .vmalloc = __videobuf_to_vmalloc,
671}; 691};
672 692
673void *videobuf_pci_alloc (size_t size) 693void *videobuf_sg_alloc(size_t size)
674{ 694{
675 struct videobuf_queue q; 695 struct videobuf_queue q;
676 696
677 /* Required to make generic handler to call __videobuf_alloc */ 697 /* Required to make generic handler to call __videobuf_alloc */
678 q.int_ops=&pci_ops; 698 q.int_ops = &sg_ops;
679 699
680 q.msize=size; 700 q.msize = size;
681 701
682 return videobuf_alloc (&q); 702 return videobuf_alloc(&q);
683} 703}
684 704
685void videobuf_queue_pci_init(struct videobuf_queue* q, 705void videobuf_queue_sg_init(struct videobuf_queue* q,
686 struct videobuf_queue_ops *ops, 706 struct videobuf_queue_ops *ops,
687 void *dev, 707 struct device *dev,
688 spinlock_t *irqlock, 708 spinlock_t *irqlock,
689 enum v4l2_buf_type type, 709 enum v4l2_buf_type type,
690 enum v4l2_field field, 710 enum v4l2_field field,
@@ -692,7 +712,7 @@ void videobuf_queue_pci_init(struct videobuf_queue* q,
692 void *priv) 712 void *priv)
693{ 713{
694 videobuf_queue_core_init(q, ops, dev, irqlock, type, field, msize, 714 videobuf_queue_core_init(q, ops, dev, irqlock, type, field, msize,
695 priv, &pci_ops); 715 priv, &sg_ops);
696} 716}
697 717
698/* --------------------------------------------------------------------- */ 718/* --------------------------------------------------------------------- */
@@ -709,11 +729,11 @@ EXPORT_SYMBOL_GPL(videobuf_dma_sync);
709EXPORT_SYMBOL_GPL(videobuf_dma_unmap); 729EXPORT_SYMBOL_GPL(videobuf_dma_unmap);
710EXPORT_SYMBOL_GPL(videobuf_dma_free); 730EXPORT_SYMBOL_GPL(videobuf_dma_free);
711 731
712EXPORT_SYMBOL_GPL(videobuf_pci_dma_map); 732EXPORT_SYMBOL_GPL(videobuf_sg_dma_map);
713EXPORT_SYMBOL_GPL(videobuf_pci_dma_unmap); 733EXPORT_SYMBOL_GPL(videobuf_sg_dma_unmap);
714EXPORT_SYMBOL_GPL(videobuf_pci_alloc); 734EXPORT_SYMBOL_GPL(videobuf_sg_alloc);
715 735
716EXPORT_SYMBOL_GPL(videobuf_queue_pci_init); 736EXPORT_SYMBOL_GPL(videobuf_queue_sg_init);
717 737
718/* 738/*
719 * Local variables: 739 * Local variables:
diff --git a/drivers/media/video/videobuf-dvb.c b/drivers/media/video/videobuf-dvb.c
index b73aba65d21d..6e4d73ec6855 100644
--- a/drivers/media/video/videobuf-dvb.c
+++ b/drivers/media/video/videobuf-dvb.c
@@ -20,9 +20,10 @@
20#include <linux/fs.h> 20#include <linux/fs.h>
21#include <linux/kthread.h> 21#include <linux/kthread.h>
22#include <linux/file.h> 22#include <linux/file.h>
23
23#include <linux/freezer.h> 24#include <linux/freezer.h>
24 25
25#include <media/videobuf-dma-sg.h> 26#include <media/videobuf-core.h>
26#include <media/videobuf-dvb.h> 27#include <media/videobuf-dvb.h>
27 28
28/* ------------------------------------------------------------------ */ 29/* ------------------------------------------------------------------ */
@@ -30,7 +31,7 @@
30MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]"); 31MODULE_AUTHOR("Gerd Knorr <kraxel@bytesex.org> [SuSE Labs]");
31MODULE_LICENSE("GPL"); 32MODULE_LICENSE("GPL");
32 33
33static unsigned int debug = 0; 34static unsigned int debug;
34module_param(debug, int, 0644); 35module_param(debug, int, 0644);
35MODULE_PARM_DESC(debug,"enable debug messages"); 36MODULE_PARM_DESC(debug,"enable debug messages");
36 37
@@ -45,7 +46,7 @@ static int videobuf_dvb_thread(void *data)
45 struct videobuf_buffer *buf; 46 struct videobuf_buffer *buf;
46 unsigned long flags; 47 unsigned long flags;
47 int err; 48 int err;
48 struct videobuf_dmabuf *dma; 49 void *outp;
49 50
50 dprintk("dvb thread started\n"); 51 dprintk("dvb thread started\n");
51 set_freezable(); 52 set_freezable();
@@ -66,9 +67,10 @@ static int videobuf_dvb_thread(void *data)
66 try_to_freeze(); 67 try_to_freeze();
67 68
68 /* feed buffer data to demux */ 69 /* feed buffer data to demux */
69 dma=videobuf_to_dma(buf); 70 outp = videobuf_queue_to_vmalloc (&dvb->dvbq, buf);
71
70 if (buf->state == VIDEOBUF_DONE) 72 if (buf->state == VIDEOBUF_DONE)
71 dvb_dmx_swfilter(&dvb->demux, dma->vmalloc, 73 dvb_dmx_swfilter(&dvb->demux, outp,
72 buf->size); 74 buf->size);
73 75
74 /* requeue buffer */ 76 /* requeue buffer */
@@ -138,14 +140,16 @@ static int videobuf_dvb_stop_feed(struct dvb_demux_feed *feed)
138int videobuf_dvb_register(struct videobuf_dvb *dvb, 140int videobuf_dvb_register(struct videobuf_dvb *dvb,
139 struct module *module, 141 struct module *module,
140 void *adapter_priv, 142 void *adapter_priv,
141 struct device *device) 143 struct device *device,
144 short *adapter_nr)
142{ 145{
143 int result; 146 int result;
144 147
145 mutex_init(&dvb->lock); 148 mutex_init(&dvb->lock);
146 149
147 /* register adapter */ 150 /* register adapter */
148 result = dvb_register_adapter(&dvb->adapter, dvb->name, module, device); 151 result = dvb_register_adapter(&dvb->adapter, dvb->name, module, device,
152 adapter_nr);
149 if (result < 0) { 153 if (result < 0) {
150 printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n", 154 printk(KERN_WARNING "%s: dvb_register_adapter failed (errno = %d)\n",
151 dvb->name, result); 155 dvb->name, result);
diff --git a/drivers/media/video/videobuf-vmalloc.c b/drivers/media/video/videobuf-vmalloc.c
index 5266ecc91dab..c91e1d8e3802 100644
--- a/drivers/media/video/videobuf-vmalloc.c
+++ b/drivers/media/video/videobuf-vmalloc.c
@@ -33,7 +33,7 @@
33#define MAGIC_CHECK(is,should) if (unlikely((is) != (should))) \ 33#define MAGIC_CHECK(is,should) if (unlikely((is) != (should))) \
34 { printk(KERN_ERR "magic mismatch: %x (expected %x)\n",is,should); BUG(); } 34 { printk(KERN_ERR "magic mismatch: %x (expected %x)\n",is,should); BUG(); }
35 35
36static int debug = 0; 36static int debug;
37module_param(debug, int, 0644); 37module_param(debug, int, 0644);
38 38
39MODULE_DESCRIPTION("helper module to manage video4linux vmalloc buffers"); 39MODULE_DESCRIPTION("helper module to manage video4linux vmalloc buffers");
@@ -57,20 +57,26 @@ videobuf_vm_open(struct vm_area_struct *vma)
57 map->count++; 57 map->count++;
58} 58}
59 59
60static void 60static void videobuf_vm_close(struct vm_area_struct *vma)
61videobuf_vm_close(struct vm_area_struct *vma)
62{ 61{
63 struct videobuf_mapping *map = vma->vm_private_data; 62 struct videobuf_mapping *map = vma->vm_private_data;
64 struct videobuf_queue *q = map->q; 63 struct videobuf_queue *q = map->q;
65 int i; 64 int i;
66 65
67 dprintk(2,"vm_close %p [count=%u,vma=%08lx-%08lx]\n",map, 66 dprintk(2,"vm_close %p [count=%u,vma=%08lx-%08lx]\n", map,
68 map->count,vma->vm_start,vma->vm_end); 67 map->count, vma->vm_start, vma->vm_end);
69 68
70 map->count--; 69 map->count--;
71 if (0 == map->count) { 70 if (0 == map->count) {
72 dprintk(1,"munmap %p q=%p\n",map,q); 71 struct videobuf_vmalloc_memory *mem;
72
73 dprintk(1, "munmap %p q=%p\n", map, q);
73 mutex_lock(&q->vb_lock); 74 mutex_lock(&q->vb_lock);
75
76 /* We need first to cancel streams, before unmapping */
77 if (q->streaming)
78 videobuf_queue_cancel(q);
79
74 for (i = 0; i < VIDEO_MAX_FRAME; i++) { 80 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
75 if (NULL == q->bufs[i]) 81 if (NULL == q->bufs[i])
76 continue; 82 continue;
@@ -78,14 +84,35 @@ videobuf_vm_close(struct vm_area_struct *vma)
78 if (q->bufs[i]->map != map) 84 if (q->bufs[i]->map != map)
79 continue; 85 continue;
80 86
81 q->ops->buf_release(q,q->bufs[i]); 87 mem = q->bufs[i]->priv;
88 if (mem) {
89 /* This callback is called only if kernel has
90 allocated memory and this memory is mmapped.
91 In this case, memory should be freed,
92 in order to do memory unmap.
93 */
94
95 MAGIC_CHECK(mem->magic, MAGIC_VMAL_MEM);
96
97 /* vfree is not atomic - can't be
98 called with IRQ's disabled
99 */
100 dprintk(1, "%s: buf[%d] freeing (%p)\n",
101 __func__, i, mem->vmalloc);
102
103 vfree(mem->vmalloc);
104 mem->vmalloc = NULL;
105 }
82 106
83 q->bufs[i]->map = NULL; 107 q->bufs[i]->map = NULL;
84 q->bufs[i]->baddr = 0; 108 q->bufs[i]->baddr = 0;
85 } 109 }
86 mutex_unlock(&q->vb_lock); 110
87 kfree(map); 111 kfree(map);
112
113 mutex_unlock(&q->vb_lock);
88 } 114 }
115
89 return; 116 return;
90} 117}
91 118
@@ -102,7 +129,7 @@ static struct vm_operations_struct videobuf_vm_ops =
102/* Allocated area consists on 3 parts: 129/* Allocated area consists on 3 parts:
103 struct video_buffer 130 struct video_buffer
104 struct <driver>_buffer (cx88_buffer, saa7134_buf, ...) 131 struct <driver>_buffer (cx88_buffer, saa7134_buf, ...)
105 struct videobuf_pci_sg_memory 132 struct videobuf_dma_sg_memory
106 */ 133 */
107 134
108static void *__videobuf_alloc(size_t size) 135static void *__videobuf_alloc(size_t size)
@@ -116,7 +143,7 @@ static void *__videobuf_alloc(size_t size)
116 mem->magic=MAGIC_VMAL_MEM; 143 mem->magic=MAGIC_VMAL_MEM;
117 144
118 dprintk(1,"%s: allocated at %p(%ld+%ld) & %p(%ld)\n", 145 dprintk(1,"%s: allocated at %p(%ld+%ld) & %p(%ld)\n",
119 __FUNCTION__,vb,(long)sizeof(*vb),(long)size-sizeof(*vb), 146 __func__,vb,(long)sizeof(*vb),(long)size-sizeof(*vb),
120 mem,(long)sizeof(*mem)); 147 mem,(long)sizeof(*mem));
121 148
122 return vb; 149 return vb;
@@ -126,45 +153,74 @@ static int __videobuf_iolock (struct videobuf_queue* q,
126 struct videobuf_buffer *vb, 153 struct videobuf_buffer *vb,
127 struct v4l2_framebuffer *fbuf) 154 struct v4l2_framebuffer *fbuf)
128{ 155{
156 struct videobuf_vmalloc_memory *mem = vb->priv;
129 int pages; 157 int pages;
130 struct videobuf_vmalloc_memory *mem=vb->priv;
131 158
132 BUG_ON(!mem); 159 BUG_ON(!mem);
133 160
134 MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM); 161 MAGIC_CHECK(mem->magic, MAGIC_VMAL_MEM);
135 162
136 pages = PAGE_ALIGN(vb->size) >> PAGE_SHIFT; 163 switch (vb->memory) {
164 case V4L2_MEMORY_MMAP:
165 dprintk(1, "%s memory method MMAP\n", __func__);
137 166
138 /* Currently, doesn't support V4L2_MEMORY_OVERLAY */ 167 /* All handling should be done by __videobuf_mmap_mapper() */
139 if ((vb->memory != V4L2_MEMORY_MMAP) && 168 if (!mem->vmalloc) {
140 (vb->memory != V4L2_MEMORY_USERPTR) ) { 169 printk(KERN_ERR "memory is not alloced/mmapped.\n");
141 printk(KERN_ERR "Method currently unsupported.\n"); 170 return -EINVAL;
142 return -EINVAL; 171 }
143 } 172 break;
173 case V4L2_MEMORY_USERPTR:
174 pages = PAGE_ALIGN(vb->size);
144 175
145 /* FIXME: should be tested with kernel mmap mem */ 176 dprintk(1, "%s memory method USERPTR\n", __func__);
146 mem->vmalloc=vmalloc_user (PAGE_ALIGN(vb->size));
147 if (NULL == mem->vmalloc) {
148 printk(KERN_ERR "vmalloc (%d pages) failed\n",pages);
149 return -ENOMEM;
150 }
151 177
152 dprintk(1,"vmalloc is at addr 0x%08lx, size=%d\n", 178#if 1
153 (unsigned long)mem->vmalloc, 179 if (vb->baddr) {
154 pages << PAGE_SHIFT); 180 printk(KERN_ERR "USERPTR is currently not supported\n");
181 return -EINVAL;
182 }
183#endif
155 184
156 /* It seems that some kernel versions need to do remap *after* 185 /* The only USERPTR currently supported is the one needed for
157 the mmap() call 186 read() method.
158 */ 187 */
159 if (mem->vma) { 188
160 int retval=remap_vmalloc_range(mem->vma, mem->vmalloc,0); 189 mem->vmalloc = vmalloc_user(pages);
161 kfree(mem->vma); 190 if (!mem->vmalloc) {
162 mem->vma=NULL; 191 printk(KERN_ERR "vmalloc (%d pages) failed\n", pages);
163 if (retval<0) { 192 return -ENOMEM;
164 dprintk(1,"mmap app bug: remap_vmalloc_range area %p error %d\n", 193 }
165 mem->vmalloc,retval); 194 dprintk(1, "vmalloc is at addr %p (%d pages)\n",
166 return retval; 195 mem->vmalloc, pages);
196
197#if 0
198 int rc;
199 /* Kernel userptr is used also by read() method. In this case,
200 there's no need to remap, since data will be copied to user
201 */
202 if (!vb->baddr)
203 return 0;
204
205 /* FIXME: to properly support USERPTR, remap should occur.
206 The code bellow won't work, since mem->vma = NULL
207 */
208 /* Try to remap memory */
209 rc = remap_vmalloc_range(mem->vma, (void *)vb->baddr, 0);
210 if (rc < 0) {
211 printk(KERN_ERR "mmap: remap failed with error %d. ", rc);
212 return -ENOMEM;
167 } 213 }
214#endif
215
216 break;
217 case V4L2_MEMORY_OVERLAY:
218 default:
219 dprintk(1, "%s memory method OVERLAY/unknown\n", __func__);
220
221 /* Currently, doesn't support V4L2_MEMORY_OVERLAY */
222 printk(KERN_ERR "Memory method currently unsupported.\n");
223 return -EINVAL;
168 } 224 }
169 225
170 return 0; 226 return 0;
@@ -180,6 +236,7 @@ static int __videobuf_mmap_free(struct videobuf_queue *q)
180{ 236{
181 unsigned int i; 237 unsigned int i;
182 238
239 dprintk(1, "%s\n", __func__);
183 for (i = 0; i < VIDEO_MAX_FRAME; i++) { 240 for (i = 0; i < VIDEO_MAX_FRAME; i++) {
184 if (q->bufs[i]) { 241 if (q->bufs[i]) {
185 if (q->bufs[i]->map) 242 if (q->bufs[i]->map)
@@ -196,10 +253,11 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
196 struct videobuf_vmalloc_memory *mem; 253 struct videobuf_vmalloc_memory *mem;
197 struct videobuf_mapping *map; 254 struct videobuf_mapping *map;
198 unsigned int first; 255 unsigned int first;
199 int retval; 256 int retval, pages;
200 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT; 257 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
201 258
202 if (! (vma->vm_flags & VM_WRITE) || ! (vma->vm_flags & VM_SHARED)) 259 dprintk(1, "%s\n", __func__);
260 if (!(vma->vm_flags & VM_WRITE) || !(vma->vm_flags & VM_SHARED))
203 return -EINVAL; 261 return -EINVAL;
204 262
205 /* look for first buffer to map */ 263 /* look for first buffer to map */
@@ -219,46 +277,55 @@ static int __videobuf_mmap_mapper(struct videobuf_queue *q,
219 } 277 }
220 278
221 /* create mapping + update buffer list */ 279 /* create mapping + update buffer list */
222 map = q->bufs[first]->map = kzalloc(sizeof(struct videobuf_mapping),GFP_KERNEL); 280 map = kzalloc(sizeof(struct videobuf_mapping), GFP_KERNEL);
223 if (NULL == map) 281 if (NULL == map)
224 return -ENOMEM; 282 return -ENOMEM;
225 283
284 q->bufs[first]->map = map;
226 map->start = vma->vm_start; 285 map->start = vma->vm_start;
227 map->end = vma->vm_end; 286 map->end = vma->vm_end;
228 map->q = q; 287 map->q = q;
229 288
230 q->bufs[first]->baddr = vma->vm_start; 289 q->bufs[first]->baddr = vma->vm_start;
231 290
232 vma->vm_ops = &videobuf_vm_ops; 291 mem = q->bufs[first]->priv;
233 vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED; 292 BUG_ON(!mem);
234 vma->vm_private_data = map; 293 MAGIC_CHECK(mem->magic, MAGIC_VMAL_MEM);
235 294
236 mem=q->bufs[first]->priv; 295 pages = PAGE_ALIGN(vma->vm_end - vma->vm_start);
237 BUG_ON (!mem); 296 mem->vmalloc = vmalloc_user(pages);
238 MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM); 297 if (!mem->vmalloc) {
298 printk(KERN_ERR "vmalloc (%d pages) failed\n", pages);
299 goto error;
300 }
301 dprintk(1, "vmalloc is at addr %p (%d pages)\n",
302 mem->vmalloc, pages);
239 303
240 /* Try to remap memory */ 304 /* Try to remap memory */
241 retval=remap_vmalloc_range(vma, mem->vmalloc,0); 305 retval = remap_vmalloc_range(vma, mem->vmalloc, 0);
242 if (retval<0) { 306 if (retval < 0) {
243 dprintk(1,"mmap: postponing remap_vmalloc_range\n"); 307 printk(KERN_ERR "mmap: remap failed with error %d. ", retval);
244 308 vfree(mem->vmalloc);
245 mem->vma=kmalloc(sizeof(*vma),GFP_KERNEL); 309 goto error;
246 if (!mem->vma) {
247 kfree(map);
248 q->bufs[first]->map=NULL;
249 return -ENOMEM;
250 }
251 memcpy(mem->vma,vma,sizeof(*vma));
252 } 310 }
253 311
312 vma->vm_ops = &videobuf_vm_ops;
313 vma->vm_flags |= VM_DONTEXPAND | VM_RESERVED;
314 vma->vm_private_data = map;
315
254 dprintk(1,"mmap %p: q=%p %08lx-%08lx (%lx) pgoff %08lx buf %d\n", 316 dprintk(1,"mmap %p: q=%p %08lx-%08lx (%lx) pgoff %08lx buf %d\n",
255 map,q,vma->vm_start,vma->vm_end, 317 map, q, vma->vm_start, vma->vm_end,
256 (long int) q->bufs[first]->bsize, 318 (long int) q->bufs[first]->bsize,
257 vma->vm_pgoff,first); 319 vma->vm_pgoff, first);
258 320
259 videobuf_vm_open(vma); 321 videobuf_vm_open(vma);
260 322
261 return (0); 323 return 0;
324
325error:
326 mem = NULL;
327 kfree(map);
328 return -ENOMEM;
262} 329}
263 330
264static int __videobuf_copy_to_user ( struct videobuf_queue *q, 331static int __videobuf_copy_to_user ( struct videobuf_queue *q,
@@ -320,6 +387,7 @@ static struct videobuf_qtype_ops qops = {
320 .mmap_mapper = __videobuf_mmap_mapper, 387 .mmap_mapper = __videobuf_mmap_mapper,
321 .video_copy_to_user = __videobuf_copy_to_user, 388 .video_copy_to_user = __videobuf_copy_to_user,
322 .copy_stream = __videobuf_copy_stream, 389 .copy_stream = __videobuf_copy_stream,
390 .vmalloc = videobuf_to_vmalloc,
323}; 391};
324 392
325void videobuf_queue_vmalloc_init(struct videobuf_queue* q, 393void videobuf_queue_vmalloc_init(struct videobuf_queue* q,
@@ -349,13 +417,24 @@ EXPORT_SYMBOL_GPL(videobuf_to_vmalloc);
349 417
350void videobuf_vmalloc_free (struct videobuf_buffer *buf) 418void videobuf_vmalloc_free (struct videobuf_buffer *buf)
351{ 419{
352 struct videobuf_vmalloc_memory *mem=buf->priv; 420 struct videobuf_vmalloc_memory *mem = buf->priv;
353 BUG_ON (!mem);
354 421
355 MAGIC_CHECK(mem->magic,MAGIC_VMAL_MEM); 422 /* mmapped memory can't be freed here, otherwise mmapped region
423 would be released, while still needed. In this case, the memory
424 release should happen inside videobuf_vm_close().
425 So, it should free memory only if the memory were allocated for
426 read() operation.
427 */
428 if ((buf->memory != V4L2_MEMORY_USERPTR) || (buf->baddr == 0))
429 return;
430
431 if (!mem)
432 return;
433
434 MAGIC_CHECK(mem->magic, MAGIC_VMAL_MEM);
356 435
357 vfree(mem->vmalloc); 436 vfree(mem->vmalloc);
358 mem->vmalloc=NULL; 437 mem->vmalloc = NULL;
359 438
360 return; 439 return;
361} 440}
diff --git a/drivers/media/video/videocodec.c b/drivers/media/video/videocodec.c
index 87951ec8254f..cf24956f3204 100644
--- a/drivers/media/video/videocodec.c
+++ b/drivers/media/video/videocodec.c
@@ -39,12 +39,13 @@
39 39
40#ifdef CONFIG_PROC_FS 40#ifdef CONFIG_PROC_FS
41#include <linux/proc_fs.h> 41#include <linux/proc_fs.h>
42#include <linux/seq_file.h>
42#include <asm/uaccess.h> 43#include <asm/uaccess.h>
43#endif 44#endif
44 45
45#include "videocodec.h" 46#include "videocodec.h"
46 47
47static int debug = 0; 48static int debug;
48module_param(debug, int, 0); 49module_param(debug, int, 0);
49MODULE_PARM_DESC(debug, "Debug level (0-4)"); 50MODULE_PARM_DESC(debug, "Debug level (0-4)");
50 51
@@ -320,56 +321,22 @@ videocodec_unregister (const struct videocodec *codec)
320} 321}
321 322
322#ifdef CONFIG_PROC_FS 323#ifdef CONFIG_PROC_FS
323/* ============ */ 324static int proc_videocodecs_show(struct seq_file *m, void *v)
324/* procfs stuff */
325/* ============ */
326
327static char *videocodec_buf = NULL;
328static int videocodec_bufsize = 0;
329
330static int
331videocodec_build_table (void)
332{ 325{
333 struct codec_list *h = codeclist_top; 326 struct codec_list *h = codeclist_top;
334 struct attached_list *a; 327 struct attached_list *a;
335 int i = 0, size;
336
337 // sum up amount of slaves plus their attached masters
338 while (h) {
339 i += h->attached + 1;
340 h = h->next;
341 }
342#define LINESIZE 100
343 size = LINESIZE * (i + 1);
344 328
345 dprintk(3, "videocodec_build table: %d entries, %d bytes\n", i, 329 seq_printf(m, "<S>lave or attached <M>aster name type flags magic ");
346 size); 330 seq_printf(m, "(connected as)\n");
347
348 kfree(videocodec_buf);
349 videocodec_buf = kmalloc(size, GFP_KERNEL);
350
351 if (!videocodec_buf)
352 return 0;
353
354 i = 0;
355 i += scnprintf(videocodec_buf + i, size - 1,
356 "<S>lave or attached <M>aster name type flags magic ");
357 i += scnprintf(videocodec_buf + i, size -i - 1, "(connected as)\n");
358 331
359 h = codeclist_top; 332 h = codeclist_top;
360 while (h) { 333 while (h) {
361 if (i > (size - LINESIZE)) 334 seq_printf(m, "S %32s %04x %08lx %08lx (TEMPLATE)\n",
362 break; // security check
363 i += scnprintf(videocodec_buf + i, size -i -1,
364 "S %32s %04x %08lx %08lx (TEMPLATE)\n",
365 h->codec->name, h->codec->type, 335 h->codec->name, h->codec->type,
366 h->codec->flags, h->codec->magic); 336 h->codec->flags, h->codec->magic);
367 a = h->list; 337 a = h->list;
368 while (a) { 338 while (a) {
369 if (i > (size - LINESIZE)) 339 seq_printf(m, "M %32s %04x %08lx %08lx (%s)\n",
370 break; // security check
371 i += scnprintf(videocodec_buf + i, size -i -1,
372 "M %32s %04x %08lx %08lx (%s)\n",
373 a->codec->master_data->name, 340 a->codec->master_data->name,
374 a->codec->master_data->type, 341 a->codec->master_data->type,
375 a->codec->master_data->flags, 342 a->codec->master_data->flags,
@@ -380,54 +347,21 @@ videocodec_build_table (void)
380 h = h->next; 347 h = h->next;
381 } 348 }
382 349
383 return i; 350 return 0;
384} 351}
385 352
386//The definition: 353static int proc_videocodecs_open(struct inode *inode, struct file *file)
387//typedef int (read_proc_t)(char *page, char **start, off_t off,
388// int count, int *eof, void *data);
389
390static int
391videocodec_info (char *buffer,
392 char **buffer_location,
393 off_t offset,
394 int buffer_length,
395 int *eof,
396 void *data)
397{ 354{
398 int size; 355 return single_open(file, proc_videocodecs_show, NULL);
399
400 dprintk(3, "videocodec_info: offset: %ld, len %d / size %d\n",
401 offset, buffer_length, videocodec_bufsize);
402
403 if (offset == 0) {
404 videocodec_bufsize = videocodec_build_table();
405 }
406 if ((offset < 0) || (offset >= videocodec_bufsize)) {
407 dprintk(4,
408 "videocodec_info: call delivers no result, return 0\n");
409 *eof = 1;
410 return 0;
411 }
412
413 if (buffer_length < (videocodec_bufsize - offset)) {
414 dprintk(4, "videocodec_info: %ld needed, %d got\n",
415 videocodec_bufsize - offset, buffer_length);
416 size = buffer_length;
417 } else {
418 dprintk(4, "videocodec_info: last reading of %ld bytes\n",
419 videocodec_bufsize - offset);
420 size = videocodec_bufsize - offset;
421 *eof = 1;
422 }
423
424 memcpy(buffer, videocodec_buf + offset, size);
425 /* doesn't work... */
426 /* copy_to_user(buffer, videocodec_buf+offset, size); */
427 /* *buffer_location = videocodec_buf+offset; */
428
429 return size;
430} 356}
357
358static const struct file_operations videocodecs_proc_fops = {
359 .owner = THIS_MODULE,
360 .open = proc_videocodecs_open,
361 .read = seq_read,
362 .llseek = seq_lseek,
363 .release = single_release,
364};
431#endif 365#endif
432 366
433/* ===================== */ 367/* ===================== */
@@ -444,16 +378,8 @@ videocodec_init (void)
444 VIDEOCODEC_VERSION); 378 VIDEOCODEC_VERSION);
445 379
446#ifdef CONFIG_PROC_FS 380#ifdef CONFIG_PROC_FS
447 videocodec_buf = NULL; 381 videocodec_proc_entry = proc_create("videocodecs", 0, NULL, &videocodecs_proc_fops);
448 videocodec_bufsize = 0; 382 if (!videocodec_proc_entry) {
449
450 videocodec_proc_entry = create_proc_entry("videocodecs", 0, NULL);
451 if (videocodec_proc_entry) {
452 videocodec_proc_entry->read_proc = videocodec_info;
453 videocodec_proc_entry->write_proc = NULL;
454 videocodec_proc_entry->data = NULL;
455 videocodec_proc_entry->owner = THIS_MODULE;
456 } else {
457 dprintk(1, KERN_ERR "videocodec: can't init procfs.\n"); 383 dprintk(1, KERN_ERR "videocodec: can't init procfs.\n");
458 } 384 }
459#endif 385#endif
@@ -465,7 +391,6 @@ videocodec_exit (void)
465{ 391{
466#ifdef CONFIG_PROC_FS 392#ifdef CONFIG_PROC_FS
467 remove_proc_entry("videocodecs", NULL); 393 remove_proc_entry("videocodecs", NULL);
468 kfree(videocodec_buf);
469#endif 394#endif
470} 395}
471 396
diff --git a/drivers/media/video/videodev.c b/drivers/media/video/videodev.c
index 0d9b63762a48..31e8af0ba278 100644
--- a/drivers/media/video/videodev.c
+++ b/drivers/media/video/videodev.c
@@ -18,14 +18,14 @@
18 18
19#define dbgarg(cmd, fmt, arg...) \ 19#define dbgarg(cmd, fmt, arg...) \
20 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \ 20 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { \
21 printk (KERN_DEBUG "%s: ", vfd->name); \ 21 printk(KERN_DEBUG "%s: ", vfd->name); \
22 v4l_printk_ioctl(cmd); \ 22 v4l_printk_ioctl(cmd); \
23 printk (KERN_DEBUG "%s: " fmt, vfd->name, ## arg); \ 23 printk(" " fmt, ## arg); \
24 } 24 }
25 25
26#define dbgarg2(fmt, arg...) \ 26#define dbgarg2(fmt, arg...) \
27 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \ 27 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) \
28 printk (KERN_DEBUG "%s: " fmt, vfd->name, ## arg); 28 printk(KERN_DEBUG "%s: " fmt, vfd->name, ## arg);
29 29
30#include <linux/module.h> 30#include <linux/module.h>
31#include <linux/types.h> 31#include <linux/types.h>
@@ -378,38 +378,45 @@ static const char *v4l2_int_ioctls[] = {
378 external ioctl messages as well as internal V4L ioctl */ 378 external ioctl messages as well as internal V4L ioctl */
379void v4l_printk_ioctl(unsigned int cmd) 379void v4l_printk_ioctl(unsigned int cmd)
380{ 380{
381 char *dir; 381 char *dir, *type;
382 382
383 switch (_IOC_DIR(cmd)) {
384 case _IOC_NONE: dir = "--"; break;
385 case _IOC_READ: dir = "r-"; break;
386 case _IOC_WRITE: dir = "-w"; break;
387 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
388 default: dir = "*ERR*"; break;
389 }
390 switch (_IOC_TYPE(cmd)) { 383 switch (_IOC_TYPE(cmd)) {
391 case 'd': 384 case 'd':
392 printk("v4l2_int ioctl %s, dir=%s (0x%08x)\n", 385 if (_IOC_NR(cmd) >= V4L2_INT_IOCTLS) {
393 (_IOC_NR(cmd) < V4L2_INT_IOCTLS) ? 386 type = "v4l2_int";
394 v4l2_int_ioctls[_IOC_NR(cmd)] : "UNKNOWN", dir, cmd); 387 break;
395 break; 388 }
389 printk("%s", v4l2_int_ioctls[_IOC_NR(cmd)]);
390 return;
396#ifdef CONFIG_VIDEO_V4L1_COMPAT 391#ifdef CONFIG_VIDEO_V4L1_COMPAT
397 case 'v': 392 case 'v':
398 printk("v4l1 ioctl %s, dir=%s (0x%08x)\n", 393 if (_IOC_NR(cmd) >= V4L1_IOCTLS) {
399 (_IOC_NR(cmd) < V4L1_IOCTLS) ? 394 type = "v4l1";
400 v4l1_ioctls[_IOC_NR(cmd)] : "UNKNOWN", dir, cmd); 395 break;
401 break; 396 }
397 printk("%s", v4l1_ioctls[_IOC_NR(cmd)]);
398 return;
402#endif 399#endif
403 case 'V': 400 case 'V':
404 printk("v4l2 ioctl %s, dir=%s (0x%08x)\n", 401 if (_IOC_NR(cmd) >= V4L2_IOCTLS) {
405 (_IOC_NR(cmd) < V4L2_IOCTLS) ? 402 type = "v4l2";
406 v4l2_ioctls[_IOC_NR(cmd)] : "UNKNOWN", dir, cmd); 403 break;
407 break; 404 }
408 405 printk("%s", v4l2_ioctls[_IOC_NR(cmd)]);
406 return;
409 default: 407 default:
410 printk("unknown ioctl '%c', dir=%s, #%d (0x%08x)\n", 408 type = "unknown";
411 _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd); 409 }
410
411 switch (_IOC_DIR(cmd)) {
412 case _IOC_NONE: dir = "--"; break;
413 case _IOC_READ: dir = "r-"; break;
414 case _IOC_WRITE: dir = "-w"; break;
415 case _IOC_READ | _IOC_WRITE: dir = "rw"; break;
416 default: dir = "*ERR*"; break;
412 } 417 }
418 printk("%s ioctl '%c', dir=%s, #%d (0x%08x)",
419 type, _IOC_TYPE(cmd), dir, _IOC_NR(cmd), cmd);
413} 420}
414EXPORT_SYMBOL(v4l_printk_ioctl); 421EXPORT_SYMBOL(v4l_printk_ioctl);
415 422
@@ -774,6 +781,7 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
774 if ( (vfd->debug & V4L2_DEBUG_IOCTL) && 781 if ( (vfd->debug & V4L2_DEBUG_IOCTL) &&
775 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) { 782 !(vfd->debug & V4L2_DEBUG_IOCTL_ARG)) {
776 v4l_print_ioctl(vfd->name, cmd); 783 v4l_print_ioctl(vfd->name, cmd);
784 printk("\n");
777 } 785 }
778 786
779#ifdef CONFIG_VIDEO_V4L1_COMPAT 787#ifdef CONFIG_VIDEO_V4L1_COMPAT
@@ -1853,12 +1861,20 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
1853 dbgarg (cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision); 1861 dbgarg (cmd, "chip_ident=%u, revision=0x%x\n", p->ident, p->revision);
1854 break; 1862 break;
1855 } 1863 }
1864 default:
1865 {
1866 if (!vfd->vidioc_default)
1867 break;
1868 ret = vfd->vidioc_default(file, fh, cmd, arg);
1869 break;
1870 }
1856 } /* switch */ 1871 } /* switch */
1857 1872
1858 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) { 1873 if (vfd->debug & V4L2_DEBUG_IOCTL_ARG) {
1859 if (ret<0) { 1874 if (ret<0) {
1860 printk ("%s: err:\n", vfd->name); 1875 printk("%s: err: on ", vfd->name);
1861 v4l_print_ioctl(vfd->name, cmd); 1876 v4l_print_ioctl(vfd->name, cmd);
1877 printk("\n");
1862 } 1878 }
1863 } 1879 }
1864 1880
@@ -2019,7 +2035,7 @@ int video_register_device(struct video_device *vfd, int type, int nr)
2019 break; 2035 break;
2020 default: 2036 default:
2021 printk(KERN_ERR "%s called with unknown type: %d\n", 2037 printk(KERN_ERR "%s called with unknown type: %d\n",
2022 __FUNCTION__, type); 2038 __func__, type);
2023 return -1; 2039 return -1;
2024 } 2040 }
2025 2041
@@ -2057,7 +2073,7 @@ int video_register_device(struct video_device *vfd, int type, int nr)
2057 ret = device_register(&vfd->class_dev); 2073 ret = device_register(&vfd->class_dev);
2058 if (ret < 0) { 2074 if (ret < 0) {
2059 printk(KERN_ERR "%s: device_register failed\n", 2075 printk(KERN_ERR "%s: device_register failed\n",
2060 __FUNCTION__); 2076 __func__);
2061 goto fail_minor; 2077 goto fail_minor;
2062 } 2078 }
2063 2079
diff --git a/drivers/media/video/vino.c b/drivers/media/video/vino.c
index 5bb75294b5aa..d545c98dd5e7 100644
--- a/drivers/media/video/vino.c
+++ b/drivers/media/video/vino.c
@@ -333,7 +333,7 @@ struct vino_settings {
333 * 333 *
334 * Use non-zero value to enable conversion. 334 * Use non-zero value to enable conversion.
335 */ 335 */
336static int vino_pixel_conversion = 0; 336static int vino_pixel_conversion;
337 337
338module_param_named(pixelconv, vino_pixel_conversion, int, 0); 338module_param_named(pixelconv, vino_pixel_conversion, int, 0);
339 339
@@ -4370,8 +4370,8 @@ static int vino_ioctl(struct inode *inode, struct file *file,
4370 4370
4371/* Initialization and cleanup */ 4371/* Initialization and cleanup */
4372 4372
4373// __initdata 4373/* __initdata */
4374static int vino_init_stage = 0; 4374static int vino_init_stage;
4375 4375
4376static const struct file_operations vino_fops = { 4376static const struct file_operations vino_fops = {
4377 .owner = THIS_MODULE, 4377 .owner = THIS_MODULE,
@@ -4385,8 +4385,8 @@ static const struct file_operations vino_fops = {
4385 4385
4386static struct video_device v4l_device_template = { 4386static struct video_device v4l_device_template = {
4387 .name = "NOT SET", 4387 .name = "NOT SET",
4388 //.type = VID_TYPE_CAPTURE | VID_TYPE_SUBCAPTURE | 4388 /*.type = VID_TYPE_CAPTURE | VID_TYPE_SUBCAPTURE | */
4389 // VID_TYPE_CLIPPING | VID_TYPE_SCALES, VID_TYPE_OVERLAY 4389 /* VID_TYPE_CLIPPING | VID_TYPE_SCALES, VID_TYPE_OVERLAY */
4390 .fops = &vino_fops, 4390 .fops = &vino_fops,
4391 .minor = -1, 4391 .minor = -1,
4392}; 4392};
diff --git a/drivers/media/video/vivi.c b/drivers/media/video/vivi.c
index 1db067c02815..b1e9592acb90 100644
--- a/drivers/media/video/vivi.c
+++ b/drivers/media/video/vivi.c
@@ -146,8 +146,6 @@ struct vivi_buffer {
146 146
147struct vivi_dmaqueue { 147struct vivi_dmaqueue {
148 struct list_head active; 148 struct list_head active;
149 struct list_head queued;
150 struct timer_list timeout;
151 149
152 /* thread for generating video stream*/ 150 /* thread for generating video stream*/
153 struct task_struct *kthread; 151 struct task_struct *kthread;
@@ -162,8 +160,8 @@ static LIST_HEAD(vivi_devlist);
162struct vivi_dev { 160struct vivi_dev {
163 struct list_head vivi_devlist; 161 struct list_head vivi_devlist;
164 162
165 struct mutex lock;
166 spinlock_t slock; 163 spinlock_t slock;
164 struct mutex mutex;
167 165
168 int users; 166 int users;
169 167
@@ -322,24 +320,26 @@ static void gen_line(char *basep, int inipos, int wmax,
322end: 320end:
323 return; 321 return;
324} 322}
323
325static void vivi_fillbuff(struct vivi_dev *dev, struct vivi_buffer *buf) 324static void vivi_fillbuff(struct vivi_dev *dev, struct vivi_buffer *buf)
326{ 325{
327 int h , pos = 0; 326 int h , pos = 0;
328 int hmax = buf->vb.height; 327 int hmax = buf->vb.height;
329 int wmax = buf->vb.width; 328 int wmax = buf->vb.width;
330 struct timeval ts; 329 struct timeval ts;
331 char *tmpbuf = kmalloc(wmax * 2, GFP_KERNEL); 330 char *tmpbuf = kmalloc(wmax * 2, GFP_ATOMIC);
332 void *vbuf = videobuf_to_vmalloc(&buf->vb); 331 void *vbuf = videobuf_to_vmalloc(&buf->vb);
333 332
334 if (!tmpbuf) 333 if (!tmpbuf)
335 return; 334 return;
336 335
336 if (!vbuf)
337 return;
338
337 for (h = 0; h < hmax; h++) { 339 for (h = 0; h < hmax; h++) {
338 gen_line(tmpbuf, 0, wmax, hmax, h, dev->mv_count, 340 gen_line(tmpbuf, 0, wmax, hmax, h, dev->mv_count,
339 dev->timestr); 341 dev->timestr);
340 /* FIXME: replacing to __copy_to_user */ 342 memcpy(vbuf + pos, tmpbuf, wmax * 2);
341 if (copy_to_user(vbuf + pos, tmpbuf, wmax * 2) != 0)
342 dprintk(dev, 2, "vivifill copy_to_user failed.\n");
343 pos += wmax*2; 343 pos += wmax*2;
344 } 344 }
345 345
@@ -372,107 +372,71 @@ static void vivi_fillbuff(struct vivi_dev *dev, struct vivi_buffer *buf)
372 dev->timestr, (unsigned long)tmpbuf, pos); 372 dev->timestr, (unsigned long)tmpbuf, pos);
373 373
374 /* Advice that buffer was filled */ 374 /* Advice that buffer was filled */
375 buf->vb.state = VIDEOBUF_DONE;
376 buf->vb.field_count++; 375 buf->vb.field_count++;
377 do_gettimeofday(&ts); 376 do_gettimeofday(&ts);
378 buf->vb.ts = ts; 377 buf->vb.ts = ts;
379 378 buf->vb.state = VIDEOBUF_DONE;
380 list_del(&buf->vb.queue);
381 wake_up(&buf->vb.done);
382} 379}
383 380
384static int restart_video_queue(struct vivi_dmaqueue *dma_q); 381static void vivi_thread_tick(struct vivi_fh *fh)
385
386static void vivi_thread_tick(struct vivi_dmaqueue *dma_q)
387{ 382{
388 struct vivi_buffer *buf; 383 struct vivi_buffer *buf;
389 struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq); 384 struct vivi_dev *dev = fh->dev;
385 struct vivi_dmaqueue *dma_q = &dev->vidq;
390 386
391 int bc; 387 unsigned long flags = 0;
392 388
393 spin_lock(&dev->slock); 389 dprintk(dev, 1, "Thread tick\n");
394 /* Announces videobuf that all went ok */
395 for (bc = 0;; bc++) {
396 if (list_empty(&dma_q->active)) {
397 dprintk(dev, 1, "No active queue to serve\n");
398 break;
399 }
400 390
401 buf = list_entry(dma_q->active.next, 391 spin_lock_irqsave(&dev->slock, flags);
402 struct vivi_buffer, vb.queue); 392 if (list_empty(&dma_q->active)) {
393 dprintk(dev, 1, "No active queue to serve\n");
394 goto unlock;
395 }
403 396
404 /* Nobody is waiting something to be done, just return */ 397 buf = list_entry(dma_q->active.next,
405 if (!waitqueue_active(&buf->vb.done)) { 398 struct vivi_buffer, vb.queue);
406 mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT); 399
407 spin_unlock(&dev->slock); 400 /* Nobody is waiting on this buffer, return */
408 return; 401 if (!waitqueue_active(&buf->vb.done))
409 } 402 goto unlock;
410 403
411 do_gettimeofday(&buf->vb.ts); 404 list_del(&buf->vb.queue);
412 dprintk(dev, 2, "[%p/%d] wakeup\n", buf, buf->vb. i);
413 405
414 /* Fill buffer */ 406 do_gettimeofday(&buf->vb.ts);
415 vivi_fillbuff(dev, buf);
416 407
417 if (list_empty(&dma_q->active)) { 408 /* Fill buffer */
418 del_timer(&dma_q->timeout); 409 vivi_fillbuff(dev, buf);
419 } else { 410 dprintk(dev, 1, "filled buffer %p\n", buf);
420 mod_timer(&dma_q->timeout, jiffies + BUFFER_TIMEOUT); 411
421 } 412 wake_up(&buf->vb.done);
422 } 413 dprintk(dev, 2, "[%p/%d] wakeup\n", buf, buf->vb. i);
423 if (bc != 1) 414unlock:
424 dprintk(dev, 1, "%s: %d buffers handled (should be 1)\n", 415 spin_unlock_irqrestore(&dev->slock, flags);
425 __FUNCTION__, bc); 416 return;
426 spin_unlock(&dev->slock);
427} 417}
428 418
429#define frames_to_ms(frames) \ 419#define frames_to_ms(frames) \
430 ((frames * WAKE_NUMERATOR * 1000) / WAKE_DENOMINATOR) 420 ((frames * WAKE_NUMERATOR * 1000) / WAKE_DENOMINATOR)
431 421
432static void vivi_sleep(struct vivi_dmaqueue *dma_q) 422static void vivi_sleep(struct vivi_fh *fh)
433{ 423{
434 struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq); 424 struct vivi_dev *dev = fh->dev;
435 int timeout, running_time; 425 struct vivi_dmaqueue *dma_q = &dev->vidq;
426 int timeout;
436 DECLARE_WAITQUEUE(wait, current); 427 DECLARE_WAITQUEUE(wait, current);
437 428
438 dprintk(dev, 1, "%s dma_q=0x%08lx\n", __FUNCTION__, 429 dprintk(dev, 1, "%s dma_q=0x%08lx\n", __func__,
439 (unsigned long)dma_q); 430 (unsigned long)dma_q);
440 431
441 add_wait_queue(&dma_q->wq, &wait); 432 add_wait_queue(&dma_q->wq, &wait);
442 if (kthread_should_stop()) 433 if (kthread_should_stop())
443 goto stop_task; 434 goto stop_task;
444 435
445 running_time = jiffies - dma_q->ini_jiffies;
446 dma_q->frame++;
447
448 /* Calculate time to wake up */ 436 /* Calculate time to wake up */
449 timeout = msecs_to_jiffies(frames_to_ms(dma_q->frame)) - running_time; 437 timeout = msecs_to_jiffies(frames_to_ms(1));
450
451 if (timeout > msecs_to_jiffies(frames_to_ms(2)) || timeout <= 0) {
452 int old = dma_q->frame;
453 int nframes;
454
455 dma_q->frame = (jiffies_to_msecs(running_time) /
456 frames_to_ms(1)) + 1;
457
458 timeout = msecs_to_jiffies(frames_to_ms(dma_q->frame))
459 - running_time;
460
461 if (unlikely (timeout <= 0))
462 timeout = 1;
463
464 nframes = (dma_q->frame > old)?
465 dma_q->frame - old : old - dma_q->frame;
466
467 dprintk(dev, 1, "%ld: %s %d frames. "
468 "Current frame is %d. Will sleep for %d jiffies\n",
469 jiffies,
470 (dma_q->frame > old)? "Underrun, losed" : "Overrun of",
471 nframes, dma_q->frame, timeout);
472 } else
473 dprintk(dev, 1, "will sleep for %d jiffies\n", timeout);
474 438
475 vivi_thread_tick(dma_q); 439 vivi_thread_tick(fh);
476 440
477 schedule_timeout_interruptible(timeout); 441 schedule_timeout_interruptible(timeout);
478 442
@@ -483,16 +447,15 @@ stop_task:
483 447
484static int vivi_thread(void *data) 448static int vivi_thread(void *data)
485{ 449{
486 struct vivi_dmaqueue *dma_q = data; 450 struct vivi_fh *fh = data;
487 struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq); 451 struct vivi_dev *dev = fh->dev;
488 452
489 dprintk(dev, 1, "thread started\n"); 453 dprintk(dev, 1, "thread started\n");
490 454
491 mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT);
492 set_freezable(); 455 set_freezable();
493 456
494 for (;;) { 457 for (;;) {
495 vivi_sleep(dma_q); 458 vivi_sleep(fh);
496 459
497 if (kthread_should_stop()) 460 if (kthread_should_stop())
498 break; 461 break;
@@ -501,16 +464,17 @@ static int vivi_thread(void *data)
501 return 0; 464 return 0;
502} 465}
503 466
504static int vivi_start_thread(struct vivi_dmaqueue *dma_q) 467static int vivi_start_thread(struct vivi_fh *fh)
505{ 468{
506 struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq); 469 struct vivi_dev *dev = fh->dev;
470 struct vivi_dmaqueue *dma_q = &dev->vidq;
507 471
508 dma_q->frame = 0; 472 dma_q->frame = 0;
509 dma_q->ini_jiffies = jiffies; 473 dma_q->ini_jiffies = jiffies;
510 474
511 dprintk(dev, 1, "%s\n", __FUNCTION__); 475 dprintk(dev, 1, "%s\n", __func__);
512 476
513 dma_q->kthread = kthread_run(vivi_thread, dma_q, "vivi"); 477 dma_q->kthread = kthread_run(vivi_thread, fh, "vivi");
514 478
515 if (IS_ERR(dma_q->kthread)) { 479 if (IS_ERR(dma_q->kthread)) {
516 printk(KERN_ERR "vivi: kernel_thread() failed\n"); 480 printk(KERN_ERR "vivi: kernel_thread() failed\n");
@@ -519,7 +483,7 @@ static int vivi_start_thread(struct vivi_dmaqueue *dma_q)
519 /* Wakes thread */ 483 /* Wakes thread */
520 wake_up_interruptible(&dma_q->wq); 484 wake_up_interruptible(&dma_q->wq);
521 485
522 dprintk(dev, 1, "returning from %s\n", __FUNCTION__); 486 dprintk(dev, 1, "returning from %s\n", __func__);
523 return 0; 487 return 0;
524} 488}
525 489
@@ -527,7 +491,7 @@ static void vivi_stop_thread(struct vivi_dmaqueue *dma_q)
527{ 491{
528 struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq); 492 struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq);
529 493
530 dprintk(dev, 1, "%s\n", __FUNCTION__); 494 dprintk(dev, 1, "%s\n", __func__);
531 /* shutdown control thread */ 495 /* shutdown control thread */
532 if (dma_q->kthread) { 496 if (dma_q->kthread) {
533 kthread_stop(dma_q->kthread); 497 kthread_stop(dma_q->kthread);
@@ -535,91 +499,6 @@ static void vivi_stop_thread(struct vivi_dmaqueue *dma_q)
535 } 499 }
536} 500}
537 501
538static int restart_video_queue(struct vivi_dmaqueue *dma_q)
539{
540 struct vivi_dev *dev = container_of(dma_q, struct vivi_dev, vidq);
541 struct vivi_buffer *buf, *prev;
542
543 dprintk(dev, 1, "%s dma_q=0x%08lx\n", __FUNCTION__,
544 (unsigned long)dma_q);
545
546 if (!list_empty(&dma_q->active)) {
547 buf = list_entry(dma_q->active.next,
548 struct vivi_buffer, vb.queue);
549 dprintk(dev, 2, "restart_queue [%p/%d]: restart dma\n",
550 buf, buf->vb.i);
551
552 dprintk(dev, 1, "Restarting video dma\n");
553 vivi_stop_thread(dma_q);
554
555 /* cancel all outstanding capture / vbi requests */
556 list_for_each_entry_safe(buf, prev, &dma_q->active, vb.queue) {
557 list_del(&buf->vb.queue);
558 buf->vb.state = VIDEOBUF_ERROR;
559 wake_up(&buf->vb.done);
560 }
561 mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT);
562
563 return 0;
564 }
565
566 prev = NULL;
567 for (;;) {
568 if (list_empty(&dma_q->queued))
569 return 0;
570 buf = list_entry(dma_q->queued.next,
571 struct vivi_buffer, vb.queue);
572 if (NULL == prev) {
573 list_del(&buf->vb.queue);
574 list_add_tail(&buf->vb.queue, &dma_q->active);
575
576 dprintk(dev, 1, "Restarting video dma\n");
577 vivi_stop_thread(dma_q);
578 vivi_start_thread(dma_q);
579
580 buf->vb.state = VIDEOBUF_ACTIVE;
581 mod_timer(&dma_q->timeout, jiffies+BUFFER_TIMEOUT);
582 dprintk(dev, 2,
583 "[%p/%d] restart_queue - first active\n",
584 buf, buf->vb.i);
585
586 } else if (prev->vb.width == buf->vb.width &&
587 prev->vb.height == buf->vb.height &&
588 prev->fmt == buf->fmt) {
589 list_del(&buf->vb.queue);
590 list_add_tail(&buf->vb.queue, &dma_q->active);
591 buf->vb.state = VIDEOBUF_ACTIVE;
592 dprintk(dev, 2,
593 "[%p/%d] restart_queue - move to active\n",
594 buf, buf->vb.i);
595 } else {
596 return 0;
597 }
598 prev = buf;
599 }
600}
601
602static void vivi_vid_timeout(unsigned long data)
603{
604 struct vivi_dev *dev = (struct vivi_dev *)data;
605 struct vivi_dmaqueue *vidq = &dev->vidq;
606 struct vivi_buffer *buf;
607
608 spin_lock(&dev->slock);
609
610 while (!list_empty(&vidq->active)) {
611 buf = list_entry(vidq->active.next,
612 struct vivi_buffer, vb.queue);
613 list_del(&buf->vb.queue);
614 buf->vb.state = VIDEOBUF_ERROR;
615 wake_up(&buf->vb.done);
616 printk(KERN_INFO "vivi/0: [%p/%d] timeout\n", buf, buf->vb.i);
617 }
618 restart_video_queue(vidq);
619
620 spin_unlock(&dev->slock);
621}
622
623/* ------------------------------------------------------------------ 502/* ------------------------------------------------------------------
624 Videobuf operations 503 Videobuf operations
625 ------------------------------------------------------------------*/ 504 ------------------------------------------------------------------*/
@@ -637,7 +516,7 @@ buffer_setup(struct videobuf_queue *vq, unsigned int *count, unsigned int *size)
637 while (*size * *count > vid_limit * 1024 * 1024) 516 while (*size * *count > vid_limit * 1024 * 1024)
638 (*count)--; 517 (*count)--;
639 518
640 dprintk(dev, 1, "%s, count=%d, size=%d\n", __FUNCTION__, 519 dprintk(dev, 1, "%s, count=%d, size=%d\n", __func__,
641 *count, *size); 520 *count, *size);
642 521
643 return 0; 522 return 0;
@@ -648,13 +527,13 @@ static void free_buffer(struct videobuf_queue *vq, struct vivi_buffer *buf)
648 struct vivi_fh *fh = vq->priv_data; 527 struct vivi_fh *fh = vq->priv_data;
649 struct vivi_dev *dev = fh->dev; 528 struct vivi_dev *dev = fh->dev;
650 529
651 dprintk(dev, 1, "%s\n", __FUNCTION__); 530 dprintk(dev, 1, "%s, state: %i\n", __func__, buf->vb.state);
652 531
653 if (in_interrupt()) 532 if (in_interrupt())
654 BUG(); 533 BUG();
655 534
656 videobuf_waiton(&buf->vb, 0, 0);
657 videobuf_vmalloc_free(&buf->vb); 535 videobuf_vmalloc_free(&buf->vb);
536 dprintk(dev, 1, "free_buffer: freed\n");
658 buf->vb.state = VIDEOBUF_NEEDS_INIT; 537 buf->vb.state = VIDEOBUF_NEEDS_INIT;
659} 538}
660 539
@@ -667,28 +546,25 @@ buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb,
667 struct vivi_fh *fh = vq->priv_data; 546 struct vivi_fh *fh = vq->priv_data;
668 struct vivi_dev *dev = fh->dev; 547 struct vivi_dev *dev = fh->dev;
669 struct vivi_buffer *buf = container_of(vb, struct vivi_buffer, vb); 548 struct vivi_buffer *buf = container_of(vb, struct vivi_buffer, vb);
670 int rc, init_buffer = 0; 549 int rc;
671 550
672 dprintk(dev, 1, "%s, field=%d\n", __FUNCTION__, field); 551 dprintk(dev, 1, "%s, field=%d\n", __func__, field);
673 552
674 BUG_ON(NULL == fh->fmt); 553 BUG_ON(NULL == fh->fmt);
554
675 if (fh->width < 48 || fh->width > norm_maxw() || 555 if (fh->width < 48 || fh->width > norm_maxw() ||
676 fh->height < 32 || fh->height > norm_maxh()) 556 fh->height < 32 || fh->height > norm_maxh())
677 return -EINVAL; 557 return -EINVAL;
558
678 buf->vb.size = fh->width*fh->height*2; 559 buf->vb.size = fh->width*fh->height*2;
679 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) 560 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size)
680 return -EINVAL; 561 return -EINVAL;
681 562
682 if (buf->fmt != fh->fmt || 563 /* These properties only change when queue is idle, see s_fmt */
683 buf->vb.width != fh->width || 564 buf->fmt = fh->fmt;
684 buf->vb.height != fh->height || 565 buf->vb.width = fh->width;
685 buf->vb.field != field) { 566 buf->vb.height = fh->height;
686 buf->fmt = fh->fmt; 567 buf->vb.field = field;
687 buf->vb.width = fh->width;
688 buf->vb.height = fh->height;
689 buf->vb.field = field;
690 init_buffer = 1;
691 }
692 568
693 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { 569 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
694 rc = videobuf_iolock(vq, &buf->vb, NULL); 570 rc = videobuf_iolock(vq, &buf->vb, NULL);
@@ -711,45 +587,12 @@ buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
711 struct vivi_buffer *buf = container_of(vb, struct vivi_buffer, vb); 587 struct vivi_buffer *buf = container_of(vb, struct vivi_buffer, vb);
712 struct vivi_fh *fh = vq->priv_data; 588 struct vivi_fh *fh = vq->priv_data;
713 struct vivi_dev *dev = fh->dev; 589 struct vivi_dev *dev = fh->dev;
714 struct vivi_dmaqueue *vidq = &dev->vidq; 590 struct vivi_dmaqueue *vidq = &dev->vidq;
715 struct vivi_buffer *prev; 591
716 592 dprintk(dev, 1, "%s\n", __func__);
717 if (!list_empty(&vidq->queued)) { 593
718 dprintk(dev, 1, "adding vb queue=0x%08lx\n", 594 buf->vb.state = VIDEOBUF_QUEUED;
719 (unsigned long)&buf->vb.queue); 595 list_add_tail(&buf->vb.queue, &vidq->active);
720 list_add_tail(&buf->vb.queue, &vidq->queued);
721 buf->vb.state = VIDEOBUF_QUEUED;
722 dprintk(dev, 2, "[%p/%d] buffer_queue - append to queued\n",
723 buf, buf->vb.i);
724 } else if (list_empty(&vidq->active)) {
725 list_add_tail(&buf->vb.queue, &vidq->active);
726
727 buf->vb.state = VIDEOBUF_ACTIVE;
728 mod_timer(&vidq->timeout, jiffies+BUFFER_TIMEOUT);
729 dprintk(dev, 2, "[%p/%d] buffer_queue - first active\n",
730 buf, buf->vb.i);
731
732 vivi_start_thread(vidq);
733 } else {
734 prev = list_entry(vidq->active.prev,
735 struct vivi_buffer, vb.queue);
736 if (prev->vb.width == buf->vb.width &&
737 prev->vb.height == buf->vb.height &&
738 prev->fmt == buf->fmt) {
739 list_add_tail(&buf->vb.queue, &vidq->active);
740 buf->vb.state = VIDEOBUF_ACTIVE;
741 dprintk(dev, 2,
742 "[%p/%d] buffer_queue - append to active\n",
743 buf, buf->vb.i);
744
745 } else {
746 list_add_tail(&buf->vb.queue, &vidq->queued);
747 buf->vb.state = VIDEOBUF_QUEUED;
748 dprintk(dev, 2,
749 "[%p/%d] buffer_queue - first queued\n",
750 buf, buf->vb.i);
751 }
752 }
753} 596}
754 597
755static void buffer_release(struct videobuf_queue *vq, 598static void buffer_release(struct videobuf_queue *vq,
@@ -758,11 +601,8 @@ static void buffer_release(struct videobuf_queue *vq,
758 struct vivi_buffer *buf = container_of(vb, struct vivi_buffer, vb); 601 struct vivi_buffer *buf = container_of(vb, struct vivi_buffer, vb);
759 struct vivi_fh *fh = vq->priv_data; 602 struct vivi_fh *fh = vq->priv_data;
760 struct vivi_dev *dev = (struct vivi_dev *)fh->dev; 603 struct vivi_dev *dev = (struct vivi_dev *)fh->dev;
761 struct vivi_dmaqueue *vidq = &dev->vidq;
762
763 dprintk(dev, 1, "%s\n", __FUNCTION__);
764 604
765 vivi_stop_thread(vidq); 605 dprintk(dev, 1, "%s\n", __func__);
766 606
767 free_buffer(vq, buf); 607 free_buffer(vq, buf);
768} 608}
@@ -869,17 +709,31 @@ static int vidioc_s_fmt_cap(struct file *file, void *priv,
869 struct v4l2_format *f) 709 struct v4l2_format *f)
870{ 710{
871 struct vivi_fh *fh = priv; 711 struct vivi_fh *fh = priv;
712 struct videobuf_queue *q = &fh->vb_vidq;
713
872 int ret = vidioc_try_fmt_cap(file, fh, f); 714 int ret = vidioc_try_fmt_cap(file, fh, f);
873 if (ret < 0) 715 if (ret < 0)
874 return (ret); 716 return (ret);
875 717
718 mutex_lock(&q->vb_lock);
719
720 if (videobuf_queue_is_busy(&fh->vb_vidq)) {
721 dprintk(fh->dev, 1, "%s queue busy\n", __func__);
722 ret = -EBUSY;
723 goto out;
724 }
725
876 fh->fmt = &format; 726 fh->fmt = &format;
877 fh->width = f->fmt.pix.width; 727 fh->width = f->fmt.pix.width;
878 fh->height = f->fmt.pix.height; 728 fh->height = f->fmt.pix.height;
879 fh->vb_vidq.field = f->fmt.pix.field; 729 fh->vb_vidq.field = f->fmt.pix.field;
880 fh->type = f->type; 730 fh->type = f->type;
881 731
882 return (0); 732 ret = 0;
733out:
734 mutex_unlock(&q->vb_lock);
735
736 return (ret);
883} 737}
884 738
885static int vidioc_reqbufs(struct file *file, void *priv, 739static int vidioc_reqbufs(struct file *file, void *priv,
@@ -1036,6 +890,7 @@ static int vivi_open(struct inode *inode, struct file *file)
1036 struct vivi_dev *dev; 890 struct vivi_dev *dev;
1037 struct vivi_fh *fh; 891 struct vivi_fh *fh;
1038 int i; 892 int i;
893 int retval = 0;
1039 894
1040 printk(KERN_DEBUG "vivi: open called (minor=%d)\n", minor); 895 printk(KERN_DEBUG "vivi: open called (minor=%d)\n", minor);
1041 896
@@ -1045,9 +900,15 @@ static int vivi_open(struct inode *inode, struct file *file)
1045 return -ENODEV; 900 return -ENODEV;
1046 901
1047found: 902found:
1048 /* If more than one user, mutex should be added */ 903 mutex_lock(&dev->mutex);
1049 dev->users++; 904 dev->users++;
1050 905
906 if (dev->users > 1) {
907 dev->users--;
908 retval = -EBUSY;
909 goto unlock;
910 }
911
1051 dprintk(dev, 1, "open minor=%d type=%s users=%d\n", minor, 912 dprintk(dev, 1, "open minor=%d type=%s users=%d\n", minor,
1052 v4l2_type_names[V4L2_BUF_TYPE_VIDEO_CAPTURE], dev->users); 913 v4l2_type_names[V4L2_BUF_TYPE_VIDEO_CAPTURE], dev->users);
1053 914
@@ -1055,8 +916,13 @@ found:
1055 fh = kzalloc(sizeof(*fh), GFP_KERNEL); 916 fh = kzalloc(sizeof(*fh), GFP_KERNEL);
1056 if (NULL == fh) { 917 if (NULL == fh) {
1057 dev->users--; 918 dev->users--;
1058 return -ENOMEM; 919 retval = -ENOMEM;
920 goto unlock;
1059 } 921 }
922unlock:
923 mutex_unlock(&dev->mutex);
924 if (retval)
925 return retval;
1060 926
1061 file->private_data = fh; 927 file->private_data = fh;
1062 fh->dev = dev; 928 fh->dev = dev;
@@ -1084,6 +950,8 @@ found:
1084 NULL, &dev->slock, fh->type, V4L2_FIELD_INTERLACED, 950 NULL, &dev->slock, fh->type, V4L2_FIELD_INTERLACED,
1085 sizeof(struct vivi_buffer), fh); 951 sizeof(struct vivi_buffer), fh);
1086 952
953 vivi_start_thread(fh);
954
1087 return 0; 955 return 0;
1088} 956}
1089 957
@@ -1106,7 +974,7 @@ vivi_poll(struct file *file, struct poll_table_struct *wait)
1106 struct vivi_dev *dev = fh->dev; 974 struct vivi_dev *dev = fh->dev;
1107 struct videobuf_queue *q = &fh->vb_vidq; 975 struct videobuf_queue *q = &fh->vb_vidq;
1108 976
1109 dprintk(dev, 1, "%s\n", __FUNCTION__); 977 dprintk(dev, 1, "%s\n", __func__);
1110 978
1111 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type) 979 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != fh->type)
1112 return POLLERR; 980 return POLLERR;
@@ -1128,7 +996,9 @@ static int vivi_close(struct inode *inode, struct file *file)
1128 996
1129 kfree(fh); 997 kfree(fh);
1130 998
999 mutex_lock(&dev->mutex);
1131 dev->users--; 1000 dev->users--;
1001 mutex_unlock(&dev->mutex);
1132 1002
1133 dprintk(dev, 1, "close called (minor=%d, users=%d)\n", 1003 dprintk(dev, 1, "close called (minor=%d, users=%d)\n",
1134 minor, dev->users); 1004 minor, dev->users);
@@ -1182,6 +1052,7 @@ static const struct file_operations vivi_fops = {
1182 .read = vivi_read, 1052 .read = vivi_read,
1183 .poll = vivi_poll, 1053 .poll = vivi_poll,
1184 .ioctl = video_ioctl2, /* V4L2 ioctl handler */ 1054 .ioctl = video_ioctl2, /* V4L2 ioctl handler */
1055 .compat_ioctl = v4l_compat_ioctl32,
1185 .mmap = vivi_mmap, 1056 .mmap = vivi_mmap,
1186 .llseek = no_llseek, 1057 .llseek = no_llseek,
1187}; 1058};
@@ -1236,16 +1107,11 @@ static int __init vivi_init(void)
1236 1107
1237 /* init video dma queues */ 1108 /* init video dma queues */
1238 INIT_LIST_HEAD(&dev->vidq.active); 1109 INIT_LIST_HEAD(&dev->vidq.active);
1239 INIT_LIST_HEAD(&dev->vidq.queued);
1240 init_waitqueue_head(&dev->vidq.wq); 1110 init_waitqueue_head(&dev->vidq.wq);
1241 1111
1242 /* initialize locks */ 1112 /* initialize locks */
1243 mutex_init(&dev->lock);
1244 spin_lock_init(&dev->slock); 1113 spin_lock_init(&dev->slock);
1245 1114 mutex_init(&dev->mutex);
1246 dev->vidq.timeout.function = vivi_vid_timeout;
1247 dev->vidq.timeout.data = (unsigned long)dev;
1248 init_timer(&dev->vidq.timeout);
1249 1115
1250 vfd = video_device_alloc(); 1116 vfd = video_device_alloc();
1251 if (NULL == vfd) 1117 if (NULL == vfd)
diff --git a/drivers/media/video/vpx3220.c b/drivers/media/video/vpx3220.c
index a9133858e913..35293029da02 100644
--- a/drivers/media/video/vpx3220.c
+++ b/drivers/media/video/vpx3220.c
@@ -40,7 +40,7 @@
40#define I2C_VPX3220 0x86 40#define I2C_VPX3220 0x86
41#define VPX3220_DEBUG KERN_DEBUG "vpx3220: " 41#define VPX3220_DEBUG KERN_DEBUG "vpx3220: "
42 42
43static int debug = 0; 43static int debug;
44module_param(debug, int, 0); 44module_param(debug, int, 0);
45MODULE_PARM_DESC(debug, "Debug level (0-1)"); 45MODULE_PARM_DESC(debug, "Debug level (0-1)");
46 46
diff --git a/drivers/media/video/w9966.c b/drivers/media/video/w9966.c
index 08aaae07c7e0..33f702698a56 100644
--- a/drivers/media/video/w9966.c
+++ b/drivers/media/video/w9966.c
@@ -61,10 +61,10 @@
61#include <media/v4l2-common.h> 61#include <media/v4l2-common.h>
62#include <linux/parport.h> 62#include <linux/parport.h>
63 63
64//#define DEBUG // Undef me for production 64/*#define DEBUG*/ /* Undef me for production */
65 65
66#ifdef DEBUG 66#ifdef DEBUG
67#define DPRINTF(x, a...) printk(KERN_DEBUG "W9966: %s(): "x, __FUNCTION__ , ##a) 67#define DPRINTF(x, a...) printk(KERN_DEBUG "W9966: %s(): "x, __func__ , ##a)
68#else 68#else
69#define DPRINTF(x...) 69#define DPRINTF(x...)
70#endif 70#endif
@@ -134,7 +134,7 @@ MODULE_PARM_DESC(pardev, "pardev: where to search for\n\
134\tEg: >pardev=parport3,aggressive,parport2,parport1< would assign\n\ 134\tEg: >pardev=parport3,aggressive,parport2,parport1< would assign\n\
135\tcam 1 to parport3 and search every parport for cam 2 etc..."); 135\tcam 1 to parport3 and search every parport for cam 2 etc...");
136 136
137static int parmode = 0; 137static int parmode;
138module_param(parmode, int, 0); 138module_param(parmode, int, 0);
139MODULE_PARM_DESC(parmode, "parmode: transfer mode (0=auto, 1=ecp, 2=epp"); 139MODULE_PARM_DESC(parmode, "parmode: transfer mode (0=auto, 1=ecp, 2=epp");
140 140
@@ -188,7 +188,9 @@ static const struct file_operations w9966_fops = {
188 .open = video_exclusive_open, 188 .open = video_exclusive_open,
189 .release = video_exclusive_release, 189 .release = video_exclusive_release,
190 .ioctl = w9966_v4l_ioctl, 190 .ioctl = w9966_v4l_ioctl,
191#ifdef CONFIG_COMPAT
191 .compat_ioctl = v4l_compat_ioctl32, 192 .compat_ioctl = v4l_compat_ioctl32,
193#endif
192 .read = w9966_v4l_read, 194 .read = w9966_v4l_read,
193 .llseek = no_llseek, 195 .llseek = no_llseek,
194}; 196};
diff --git a/drivers/media/video/w9968cf.c b/drivers/media/video/w9968cf.c
index 2ae1430f5f7d..840522442d07 100644
--- a/drivers/media/video/w9968cf.c
+++ b/drivers/media/video/w9968cf.c
@@ -3461,7 +3461,9 @@ static const struct file_operations w9968cf_fops = {
3461 .release = w9968cf_release, 3461 .release = w9968cf_release,
3462 .read = w9968cf_read, 3462 .read = w9968cf_read,
3463 .ioctl = w9968cf_ioctl, 3463 .ioctl = w9968cf_ioctl,
3464#ifdef CONFIG_COMPAT
3464 .compat_ioctl = v4l_compat_ioctl32, 3465 .compat_ioctl = v4l_compat_ioctl32,
3466#endif
3465 .mmap = w9968cf_mmap, 3467 .mmap = w9968cf_mmap,
3466 .llseek = no_llseek, 3468 .llseek = no_llseek,
3467}; 3469};
@@ -3481,7 +3483,7 @@ w9968cf_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
3481 enum w9968cf_model_id mod_id; 3483 enum w9968cf_model_id mod_id;
3482 struct list_head* ptr; 3484 struct list_head* ptr;
3483 u8 sc = 0; /* number of simultaneous cameras */ 3485 u8 sc = 0; /* number of simultaneous cameras */
3484 static unsigned short dev_nr = 0; /* we are handling device number n */ 3486 static unsigned short dev_nr; /* 0 - we are handling device number n */
3485 3487
3486 if (le16_to_cpu(udev->descriptor.idVendor) == winbond_id_table[0].idVendor && 3488 if (le16_to_cpu(udev->descriptor.idVendor) == winbond_id_table[0].idVendor &&
3487 le16_to_cpu(udev->descriptor.idProduct) == winbond_id_table[0].idProduct) 3489 le16_to_cpu(udev->descriptor.idProduct) == winbond_id_table[0].idProduct)
diff --git a/drivers/media/video/w9968cf.h b/drivers/media/video/w9968cf.h
index ec7696e8f1fa..3c95316bc030 100644
--- a/drivers/media/video/w9968cf.h
+++ b/drivers/media/video/w9968cf.h
@@ -298,7 +298,7 @@ struct w9968cf_device {
298 dev_warn(&cam->dev, fmt "\n", ## args); \ 298 dev_warn(&cam->dev, fmt "\n", ## args); \
299 else if ((level) >= 5) \ 299 else if ((level) >= 5) \
300 dev_info(&cam->dev, "[%s:%d] " fmt "\n", \ 300 dev_info(&cam->dev, "[%s:%d] " fmt "\n", \
301 __FUNCTION__, __LINE__ , ## args); \ 301 __func__, __LINE__ , ## args); \
302 } \ 302 } \
303} 303}
304/* For generic kernel (not device specific) messages */ 304/* For generic kernel (not device specific) messages */
@@ -309,7 +309,7 @@ struct w9968cf_device {
309 if ((level) >= 1 && (level) <= 4) \ 309 if ((level) >= 1 && (level) <= 4) \
310 pr_info("w9968cf: " fmt "\n", ## args); \ 310 pr_info("w9968cf: " fmt "\n", ## args); \
311 else if ((level) >= 5) \ 311 else if ((level) >= 5) \
312 pr_debug("w9968cf: [%s:%d] " fmt "\n", __FUNCTION__, \ 312 pr_debug("w9968cf: [%s:%d] " fmt "\n", __func__, \
313 __LINE__ , ## args); \ 313 __LINE__ , ## args); \
314 } \ 314 } \
315} 315}
@@ -321,7 +321,7 @@ struct w9968cf_device {
321 321
322#undef PDBG 322#undef PDBG
323#define PDBG(fmt, args...) \ 323#define PDBG(fmt, args...) \
324dev_info(&cam->dev, "[%s:%d] " fmt "\n", __FUNCTION__, __LINE__ , ## args); 324dev_info(&cam->dev, "[%s:%d] " fmt "\n", __func__, __LINE__ , ## args);
325 325
326#undef PDBGG 326#undef PDBGG
327#define PDBGG(fmt, args...) do {;} while(0); /* nothing: it's a placeholder */ 327#define PDBGG(fmt, args...) do {;} while(0); /* nothing: it's a placeholder */
diff --git a/drivers/media/video/zc0301/zc0301.h b/drivers/media/video/zc0301/zc0301.h
index a2de50efa31a..7bbab541a309 100644
--- a/drivers/media/video/zc0301/zc0301.h
+++ b/drivers/media/video/zc0301/zc0301.h
@@ -160,7 +160,7 @@ do { \
160 dev_info(&cam->usbdev->dev, fmt "\n", ## args); \ 160 dev_info(&cam->usbdev->dev, fmt "\n", ## args); \
161 else if ((level) >= 3) \ 161 else if ((level) >= 3) \
162 dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n", \ 162 dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n", \
163 __FILE__, __FUNCTION__, __LINE__ , ## args); \ 163 __FILE__, __func__, __LINE__ , ## args); \
164 } \ 164 } \
165} while (0) 165} while (0)
166# define KDBG(level, fmt, args...) \ 166# define KDBG(level, fmt, args...) \
@@ -170,7 +170,7 @@ do { \
170 pr_info("zc0301: " fmt "\n", ## args); \ 170 pr_info("zc0301: " fmt "\n", ## args); \
171 else if ((level) == 3) \ 171 else if ((level) == 3) \
172 pr_debug("sn9c102: [%s:%s:%d] " fmt "\n", __FILE__, \ 172 pr_debug("sn9c102: [%s:%s:%d] " fmt "\n", __FILE__, \
173 __FUNCTION__, __LINE__ , ## args); \ 173 __func__, __LINE__ , ## args); \
174 } \ 174 } \
175} while (0) 175} while (0)
176# define V4LDBG(level, name, cmd) \ 176# define V4LDBG(level, name, cmd) \
@@ -186,7 +186,7 @@ do { \
186 186
187#undef PDBG 187#undef PDBG
188#define PDBG(fmt, args...) \ 188#define PDBG(fmt, args...) \
189dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n", __FILE__, __FUNCTION__, \ 189dev_info(&cam->usbdev->dev, "[%s:%s:%d] " fmt "\n", __FILE__, __func__, \
190 __LINE__ , ## args) 190 __LINE__ , ## args)
191 191
192#undef PDBGG 192#undef PDBGG
diff --git a/drivers/media/video/zc0301/zc0301_core.c b/drivers/media/video/zc0301/zc0301_core.c
index 2c5665c82442..363dd2b9475c 100644
--- a/drivers/media/video/zc0301/zc0301_core.c
+++ b/drivers/media/video/zc0301/zc0301_core.c
@@ -1925,7 +1925,9 @@ static const struct file_operations zc0301_fops = {
1925 .open = zc0301_open, 1925 .open = zc0301_open,
1926 .release = zc0301_release, 1926 .release = zc0301_release,
1927 .ioctl = zc0301_ioctl, 1927 .ioctl = zc0301_ioctl,
1928#ifdef CONFIG_COMPAT
1928 .compat_ioctl = v4l_compat_ioctl32, 1929 .compat_ioctl = v4l_compat_ioctl32,
1930#endif
1929 .read = zc0301_read, 1931 .read = zc0301_read,
1930 .poll = zc0301_poll, 1932 .poll = zc0301_poll,
1931 .mmap = zc0301_mmap, 1933 .mmap = zc0301_mmap,
@@ -1939,7 +1941,7 @@ zc0301_usb_probe(struct usb_interface* intf, const struct usb_device_id* id)
1939{ 1941{
1940 struct usb_device *udev = interface_to_usbdev(intf); 1942 struct usb_device *udev = interface_to_usbdev(intf);
1941 struct zc0301_device* cam; 1943 struct zc0301_device* cam;
1942 static unsigned int dev_nr = 0; 1944 static unsigned int dev_nr;
1943 unsigned int i; 1945 unsigned int i;
1944 int err = 0; 1946 int err = 0;
1945 1947
diff --git a/drivers/media/video/zoran.h b/drivers/media/video/zoran.h
index 498a43c1f2b1..81cc3b00a079 100644
--- a/drivers/media/video/zoran.h
+++ b/drivers/media/video/zoran.h
@@ -243,10 +243,8 @@ struct zoran_format {
243#ifdef CONFIG_VIDEO_V4L1_COMPAT 243#ifdef CONFIG_VIDEO_V4L1_COMPAT
244 int palette; 244 int palette;
245#endif 245#endif
246#ifdef CONFIG_VIDEO_V4L2
247 __u32 fourcc; 246 __u32 fourcc;
248 int colorspace; 247 int colorspace;
249#endif
250 int depth; 248 int depth;
251 __u32 flags; 249 __u32 flags;
252 __u32 vfespfr; 250 __u32 vfespfr;
@@ -271,20 +269,6 @@ struct zoran_v4l_settings {
271 const struct zoran_format *format; /* capture format */ 269 const struct zoran_format *format; /* capture format */
272}; 270};
273 271
274/* whoops, this one is undeclared if !v4l2 */
275#ifndef CONFIG_VIDEO_V4L2
276struct v4l2_jpegcompression {
277 int quality;
278 int APPn;
279 int APP_len;
280 char APP_data[60];
281 int COM_len;
282 char COM_data[60];
283 __u32 jpeg_markers;
284 __u8 reserved[116];
285};
286#endif
287
288/* jpg-capture/-playback settings */ 272/* jpg-capture/-playback settings */
289struct zoran_jpg_settings { 273struct zoran_jpg_settings {
290 int decimation; /* this bit is used to set everything to default */ 274 int decimation; /* this bit is used to set everything to default */
diff --git a/drivers/media/video/zoran_card.c b/drivers/media/video/zoran_card.c
index 690281bb59ee..006d48847e24 100644
--- a/drivers/media/video/zoran_card.c
+++ b/drivers/media/video/zoran_card.c
@@ -83,7 +83,7 @@ MODULE_PARM_DESC(decoder, "i2c TV decoder");
83 or set in in a VIDIOCSFBUF ioctl 83 or set in in a VIDIOCSFBUF ioctl
84 */ 84 */
85 85
86static unsigned long vidmem = 0; /* Video memory base address */ 86static unsigned long vidmem; /* default = 0 - Video memory base address */
87module_param(vidmem, ulong, 0444); 87module_param(vidmem, ulong, 0444);
88MODULE_PARM_DESC(vidmem, "Default video memory base address"); 88MODULE_PARM_DESC(vidmem, "Default video memory base address");
89 89
@@ -91,7 +91,7 @@ MODULE_PARM_DESC(vidmem, "Default video memory base address");
91 Default input and video norm at startup of the driver. 91 Default input and video norm at startup of the driver.
92*/ 92*/
93 93
94static unsigned int default_input = 0; /* 0=Composite, 1=S-Video */ 94static unsigned int default_input; /* default 0 = Composite, 1 = S-Video */
95module_param(default_input, uint, 0444); 95module_param(default_input, uint, 0444);
96MODULE_PARM_DESC(default_input, 96MODULE_PARM_DESC(default_input,
97 "Default input (0=Composite, 1=S-Video, 2=Internal)"); 97 "Default input (0=Composite, 1=S-Video, 2=Internal)");
@@ -101,7 +101,7 @@ module_param(default_mux, int, 0644);
101MODULE_PARM_DESC(default_mux, 101MODULE_PARM_DESC(default_mux,
102 "Default 6 Eyes mux setting (Input selection)"); 102 "Default 6 Eyes mux setting (Input selection)");
103 103
104static int default_norm = 0; /* 0=PAL, 1=NTSC 2=SECAM */ 104static int default_norm; /* default 0 = PAL, 1 = NTSC 2 = SECAM */
105module_param(default_norm, int, 0444); 105module_param(default_norm, int, 0444);
106MODULE_PARM_DESC(default_norm, "Default norm (0=PAL, 1=NTSC, 2=SECAM)"); 106MODULE_PARM_DESC(default_norm, "Default norm (0=PAL, 1=NTSC, 2=SECAM)");
107 107
diff --git a/drivers/media/video/zoran_card.h b/drivers/media/video/zoran_card.h
index 8444ca0a5f3f..1b5c4171cf9c 100644
--- a/drivers/media/video/zoran_card.h
+++ b/drivers/media/video/zoran_card.h
@@ -50,4 +50,6 @@ extern int zoran_check_jpg_settings(struct zoran *zr,
50extern void zoran_open_init_params(struct zoran *zr); 50extern void zoran_open_init_params(struct zoran *zr);
51extern void zoran_vdev_release(struct video_device *vdev); 51extern void zoran_vdev_release(struct video_device *vdev);
52 52
53void zr36016_write(struct videocodec *codec, u16 reg, u32 val);
54
53#endif /* __ZORAN_CARD_H__ */ 55#endif /* __ZORAN_CARD_H__ */
diff --git a/drivers/media/video/zoran_device.c b/drivers/media/video/zoran_device.c
index f97c20692057..7b60533efe45 100644
--- a/drivers/media/video/zoran_device.c
+++ b/drivers/media/video/zoran_device.c
@@ -60,7 +60,8 @@
60 60
61extern const struct zoran_format zoran_formats[]; 61extern const struct zoran_format zoran_formats[];
62 62
63static int lml33dpath = 0; /* 1 will use digital path in capture 63static int lml33dpath; /* default = 0
64 * 1 will use digital path in capture
64 * mode instead of analog. It can be 65 * mode instead of analog. It can be
65 * used for picture adjustments using 66 * used for picture adjustments using
66 * tool like xawtv while watching image 67 * tool like xawtv while watching image
@@ -927,11 +928,6 @@ count_reset_interrupt (struct zoran *zr)
927 return isr; 928 return isr;
928} 929}
929 930
930/* hack */
931extern void zr36016_write (struct videocodec *codec,
932 u16 reg,
933 u32 val);
934
935void 931void
936jpeg_start (struct zoran *zr) 932jpeg_start (struct zoran *zr)
937{ 933{
@@ -987,7 +983,7 @@ void
987zr36057_enable_jpg (struct zoran *zr, 983zr36057_enable_jpg (struct zoran *zr,
988 enum zoran_codec_mode mode) 984 enum zoran_codec_mode mode)
989{ 985{
990 static int zero = 0; 986 static int zero;
991 static int one = 1; 987 static int one = 1;
992 struct vfe_settings cap; 988 struct vfe_settings cap;
993 int field_size = 989 int field_size =
@@ -1726,7 +1722,7 @@ decoder_command (struct zoran *zr,
1726 return -EIO; 1722 return -EIO;
1727 1723
1728 if (zr->card.type == LML33 && 1724 if (zr->card.type == LML33 &&
1729 (cmd == DECODER_SET_NORM || DECODER_SET_INPUT)) { 1725 (cmd == DECODER_SET_NORM || cmd == DECODER_SET_INPUT)) {
1730 int res; 1726 int res;
1731 1727
1732 // Bt819 needs to reset its FIFO buffer using #FRST pin and 1728 // Bt819 needs to reset its FIFO buffer using #FRST pin and
diff --git a/drivers/media/video/zoran_driver.c b/drivers/media/video/zoran_driver.c
index fea4946ee713..0134bec1e399 100644
--- a/drivers/media/video/zoran_driver.c
+++ b/drivers/media/video/zoran_driver.c
@@ -85,7 +85,6 @@
85#include "zoran_device.h" 85#include "zoran_device.h"
86#include "zoran_card.h" 86#include "zoran_card.h"
87 87
88#ifdef CONFIG_VIDEO_V4L2
89 /* we declare some card type definitions here, they mean 88 /* we declare some card type definitions here, they mean
90 * the same as the v4l1 ZORAN_VID_TYPE above, except it's v4l2 */ 89 * the same as the v4l1 ZORAN_VID_TYPE above, except it's v4l2 */
91#define ZORAN_V4L2_VID_FLAGS ( \ 90#define ZORAN_V4L2_VID_FLAGS ( \
@@ -94,19 +93,15 @@
94 V4L2_CAP_VIDEO_OUTPUT |\ 93 V4L2_CAP_VIDEO_OUTPUT |\
95 V4L2_CAP_VIDEO_OVERLAY \ 94 V4L2_CAP_VIDEO_OVERLAY \
96 ) 95 )
97#endif
98 96
99#include <asm/byteorder.h> 97#include <asm/byteorder.h>
100 98
101#if defined(CONFIG_VIDEO_V4L2) && defined(CONFIG_VIDEO_V4L1_COMPAT) 99#if defined(CONFIG_VIDEO_V4L1_COMPAT)
102#define ZFMT(pal, fcc, cs) \ 100#define ZFMT(pal, fcc, cs) \
103 .palette = (pal), .fourcc = (fcc), .colorspace = (cs) 101 .palette = (pal), .fourcc = (fcc), .colorspace = (cs)
104#elif defined(CONFIG_VIDEO_V4L2)
105#define ZFMT(pal, fcc, cs) \
106 .fourcc = (fcc), .colorspace = (cs)
107#else 102#else
108#define ZFMT(pal, fcc, cs) \ 103#define ZFMT(pal, fcc, cs) \
109 .palette = (pal) 104 .fourcc = (fcc), .colorspace = (cs)
110#endif 105#endif
111 106
112const struct zoran_format zoran_formats[] = { 107const struct zoran_format zoran_formats[] = {
@@ -205,11 +200,10 @@ extern int jpg_nbufs;
205extern int jpg_bufsize; 200extern int jpg_bufsize;
206extern int pass_through; 201extern int pass_through;
207 202
208static int lock_norm = 0; /* 1=Don't change TV standard (norm) */ 203static int lock_norm; /* 0 = default 1 = Don't change TV standard (norm) */
209module_param(lock_norm, int, 0644); 204module_param(lock_norm, int, 0644);
210MODULE_PARM_DESC(lock_norm, "Prevent norm changes (1 = ignore, >1 = fail)"); 205MODULE_PARM_DESC(lock_norm, "Prevent norm changes (1 = ignore, >1 = fail)");
211 206
212#ifdef CONFIG_VIDEO_V4L2
213 /* small helper function for calculating buffersizes for v4l2 207 /* small helper function for calculating buffersizes for v4l2
214 * we calculate the nearest higher power-of-two, which 208 * we calculate the nearest higher power-of-two, which
215 * will be the recommended buffersize */ 209 * will be the recommended buffersize */
@@ -232,7 +226,6 @@ zoran_v4l2_calc_bufsize (struct zoran_jpg_settings *settings)
232 return 8192; 226 return 8192;
233 return result; 227 return result;
234} 228}
235#endif
236 229
237/* forward references */ 230/* forward references */
238static void v4l_fbuffer_free(struct file *file); 231static void v4l_fbuffer_free(struct file *file);
@@ -1709,7 +1702,6 @@ setup_overlay (struct file *file,
1709 return wait_grab_pending(zr); 1702 return wait_grab_pending(zr);
1710} 1703}
1711 1704
1712#ifdef CONFIG_VIDEO_V4L2
1713 /* get the status of a buffer in the clients buffer queue */ 1705 /* get the status of a buffer in the clients buffer queue */
1714static int 1706static int
1715zoran_v4l2_buffer_status (struct file *file, 1707zoran_v4l2_buffer_status (struct file *file,
@@ -1815,7 +1807,6 @@ zoran_v4l2_buffer_status (struct file *file,
1815 1807
1816 return 0; 1808 return 0;
1817} 1809}
1818#endif
1819 1810
1820static int 1811static int
1821zoran_set_norm (struct zoran *zr, 1812zoran_set_norm (struct zoran *zr,
@@ -2624,8 +2615,6 @@ zoran_do_ioctl (struct inode *inode,
2624 } 2615 }
2625 break; 2616 break;
2626 2617
2627#ifdef CONFIG_VIDEO_V4L2
2628
2629 /* The new video4linux2 capture interface - much nicer than video4linux1, since 2618 /* The new video4linux2 capture interface - much nicer than video4linux1, since
2630 * it allows for integrating the JPEG capturing calls inside standard v4l2 2619 * it allows for integrating the JPEG capturing calls inside standard v4l2
2631 */ 2620 */
@@ -4197,7 +4186,6 @@ zoran_do_ioctl (struct inode *inode,
4197 return 0; 4186 return 0;
4198 } 4187 }
4199 break; 4188 break;
4200#endif
4201 4189
4202 default: 4190 default:
4203 dprintk(1, KERN_DEBUG "%s: UNKNOWN ioctl cmd: 0x%x\n", 4191 dprintk(1, KERN_DEBUG "%s: UNKNOWN ioctl cmd: 0x%x\n",
@@ -4247,7 +4235,7 @@ zoran_poll (struct file *file,
4247 dprintk(3, 4235 dprintk(3,
4248 KERN_DEBUG 4236 KERN_DEBUG
4249 "%s: %s() raw - active=%c, sync_tail=%lu/%c, pend_tail=%lu, pend_head=%lu\n", 4237 "%s: %s() raw - active=%c, sync_tail=%lu/%c, pend_tail=%lu, pend_head=%lu\n",
4250 ZR_DEVNAME(zr), __FUNCTION__, 4238 ZR_DEVNAME(zr), __func__,
4251 "FAL"[fh->v4l_buffers.active], zr->v4l_sync_tail, 4239 "FAL"[fh->v4l_buffers.active], zr->v4l_sync_tail,
4252 "UPMD"[zr->v4l_buffers.buffer[frame].state], 4240 "UPMD"[zr->v4l_buffers.buffer[frame].state],
4253 zr->v4l_pend_tail, zr->v4l_pend_head); 4241 zr->v4l_pend_tail, zr->v4l_pend_head);
@@ -4269,7 +4257,7 @@ zoran_poll (struct file *file,
4269 dprintk(3, 4257 dprintk(3,
4270 KERN_DEBUG 4258 KERN_DEBUG
4271 "%s: %s() jpg - active=%c, que_tail=%lu/%c, que_head=%lu, dma=%lu/%lu\n", 4259 "%s: %s() jpg - active=%c, que_tail=%lu/%c, que_head=%lu, dma=%lu/%lu\n",
4272 ZR_DEVNAME(zr), __FUNCTION__, 4260 ZR_DEVNAME(zr), __func__,
4273 "FAL"[fh->jpg_buffers.active], zr->jpg_que_tail, 4261 "FAL"[fh->jpg_buffers.active], zr->jpg_que_tail,
4274 "UPMD"[zr->jpg_buffers.buffer[frame].state], 4262 "UPMD"[zr->jpg_buffers.buffer[frame].state],
4275 zr->jpg_que_head, zr->jpg_dma_tail, zr->jpg_dma_head); 4263 zr->jpg_que_head, zr->jpg_dma_tail, zr->jpg_dma_head);
@@ -4644,7 +4632,9 @@ static const struct file_operations zoran_fops = {
4644 .open = zoran_open, 4632 .open = zoran_open,
4645 .release = zoran_close, 4633 .release = zoran_close,
4646 .ioctl = zoran_ioctl, 4634 .ioctl = zoran_ioctl,
4635#ifdef CONFIG_COMPAT
4647 .compat_ioctl = v4l_compat_ioctl32, 4636 .compat_ioctl = v4l_compat_ioctl32,
4637#endif
4648 .llseek = no_llseek, 4638 .llseek = no_llseek,
4649 .read = zoran_read, 4639 .read = zoran_read,
4650 .write = zoran_write, 4640 .write = zoran_write,
@@ -4655,9 +4645,7 @@ static const struct file_operations zoran_fops = {
4655struct video_device zoran_template __devinitdata = { 4645struct video_device zoran_template __devinitdata = {
4656 .name = ZORAN_NAME, 4646 .name = ZORAN_NAME,
4657 .type = ZORAN_VID_TYPE, 4647 .type = ZORAN_VID_TYPE,
4658#ifdef CONFIG_VIDEO_V4L2
4659 .type2 = ZORAN_V4L2_VID_FLAGS, 4648 .type2 = ZORAN_V4L2_VID_FLAGS,
4660#endif
4661 .fops = &zoran_fops, 4649 .fops = &zoran_fops,
4662 .release = &zoran_vdev_release, 4650 .release = &zoran_vdev_release,
4663 .minor = -1 4651 .minor = -1
diff --git a/drivers/media/video/zr36016.c b/drivers/media/video/zr36016.c
index dd084555da8f..00d132bcd1e4 100644
--- a/drivers/media/video/zr36016.c
+++ b/drivers/media/video/zr36016.c
@@ -55,11 +55,10 @@
55#define MAX_CODECS 20 55#define MAX_CODECS 20
56 56
57/* amount of chips attached via this driver */ 57/* amount of chips attached via this driver */
58static int zr36016_codecs = 0; 58static int zr36016_codecs;
59 59
60/* debugging is available via module parameter */ 60/* debugging is available via module parameter */
61 61static int debug;
62static int debug = 0;
63module_param(debug, int, 0); 62module_param(debug, int, 0);
64MODULE_PARM_DESC(debug, "Debug level (0-4)"); 63MODULE_PARM_DESC(debug, "Debug level (0-4)");
65 64
diff --git a/drivers/media/video/zr36050.c b/drivers/media/video/zr36050.c
index faae4ec3ea0b..cf8b271a1c8f 100644
--- a/drivers/media/video/zr36050.c
+++ b/drivers/media/video/zr36050.c
@@ -52,11 +52,10 @@
52#define MAX_CODECS 20 52#define MAX_CODECS 20
53 53
54/* amount of chips attached via this driver */ 54/* amount of chips attached via this driver */
55static int zr36050_codecs = 0; 55static int zr36050_codecs;
56 56
57/* debugging is available via module parameter */ 57/* debugging is available via module parameter */
58 58static int debug;
59static int debug = 0;
60module_param(debug, int, 0); 59module_param(debug, int, 0);
61MODULE_PARM_DESC(debug, "Debug level (0-4)"); 60MODULE_PARM_DESC(debug, "Debug level (0-4)");
62 61
diff --git a/drivers/media/video/zr36060.c b/drivers/media/video/zr36060.c
index 7849b65969d0..8e74054d5ef1 100644
--- a/drivers/media/video/zr36060.c
+++ b/drivers/media/video/zr36060.c
@@ -52,14 +52,14 @@
52#define MAX_CODECS 20 52#define MAX_CODECS 20
53 53
54/* amount of chips attached via this driver */ 54/* amount of chips attached via this driver */
55static int zr36060_codecs = 0; 55static int zr36060_codecs;
56 56
57static int low_bitrate = 0; 57static int low_bitrate;
58module_param(low_bitrate, bool, 0); 58module_param(low_bitrate, bool, 0);
59MODULE_PARM_DESC(low_bitrate, "Buz compatibility option, halves bitrate"); 59MODULE_PARM_DESC(low_bitrate, "Buz compatibility option, halves bitrate");
60 60
61/* debugging is available via module parameter */ 61/* debugging is available via module parameter */
62static int debug = 0; 62static int debug;
63module_param(debug, int, 0); 63module_param(debug, int, 0);
64MODULE_PARM_DESC(debug, "Debug level (0-4)"); 64MODULE_PARM_DESC(debug, "Debug level (0-4)");
65 65
diff --git a/drivers/media/video/zr364xx.c b/drivers/media/video/zr364xx.c
index 04949c823654..a0e49dc66301 100644
--- a/drivers/media/video/zr364xx.c
+++ b/drivers/media/video/zr364xx.c
@@ -62,8 +62,8 @@
62 62
63 63
64/* Module parameters */ 64/* Module parameters */
65static int debug = 0; 65static int debug;
66static int mode = 0; 66static int mode;
67 67
68 68
69/* Module parameters interface */ 69/* Module parameters interface */
diff --git a/drivers/mfd/htc-pasic3.c b/drivers/mfd/htc-pasic3.c
index af66f4f28300..4edc120a6359 100644
--- a/drivers/mfd/htc-pasic3.c
+++ b/drivers/mfd/htc-pasic3.c
@@ -19,8 +19,6 @@
19#include <linux/interrupt.h> 19#include <linux/interrupt.h>
20#include <linux/mfd/htc-pasic3.h> 20#include <linux/mfd/htc-pasic3.h>
21 21
22#include <asm/arch/pxa-regs.h>
23
24struct pasic3_data { 22struct pasic3_data {
25 void __iomem *mapping; 23 void __iomem *mapping;
26 unsigned int bus_shift; 24 unsigned int bus_shift;
@@ -30,7 +28,6 @@ struct pasic3_data {
30 28
31#define REG_ADDR 5 29#define REG_ADDR 5
32#define REG_DATA 6 30#define REG_DATA 6
33#define NUM_REGS 7
34 31
35#define READ_MODE 0x80 32#define READ_MODE 0x80
36 33
diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index 2399a3796f6e..015e16325973 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -827,7 +827,7 @@ config ULTRA32
827 827
828config BFIN_MAC 828config BFIN_MAC
829 tristate "Blackfin 527/536/537 on-chip mac support" 829 tristate "Blackfin 527/536/537 on-chip mac support"
830 depends on NET_ETHERNET && (BF527 || BF537 || BF536) && (!BF537_PORT_H) 830 depends on NET_ETHERNET && (BF527 || BF537 || BF536)
831 select CRC32 831 select CRC32
832 select MII 832 select MII
833 select PHYLIB 833 select PHYLIB
diff --git a/drivers/net/ppp_generic.c b/drivers/net/ppp_generic.c
index 4dc5b4b7a561..d3207c0da895 100644
--- a/drivers/net/ppp_generic.c
+++ b/drivers/net/ppp_generic.c
@@ -123,7 +123,6 @@ struct ppp {
123 u32 minseq; /* MP: min of most recent seqnos */ 123 u32 minseq; /* MP: min of most recent seqnos */
124 struct sk_buff_head mrq; /* MP: receive reconstruction queue */ 124 struct sk_buff_head mrq; /* MP: receive reconstruction queue */
125#endif /* CONFIG_PPP_MULTILINK */ 125#endif /* CONFIG_PPP_MULTILINK */
126 struct net_device_stats stats; /* statistics */
127#ifdef CONFIG_PPP_FILTER 126#ifdef CONFIG_PPP_FILTER
128 struct sock_filter *pass_filter; /* filter for packets to pass */ 127 struct sock_filter *pass_filter; /* filter for packets to pass */
129 struct sock_filter *active_filter;/* filter for pkts to reset idle */ 128 struct sock_filter *active_filter;/* filter for pkts to reset idle */
@@ -914,18 +913,10 @@ ppp_start_xmit(struct sk_buff *skb, struct net_device *dev)
914 913
915 outf: 914 outf:
916 kfree_skb(skb); 915 kfree_skb(skb);
917 ++ppp->stats.tx_dropped; 916 ++ppp->dev->stats.tx_dropped;
918 return 0; 917 return 0;
919} 918}
920 919
921static struct net_device_stats *
922ppp_net_stats(struct net_device *dev)
923{
924 struct ppp *ppp = (struct ppp *) dev->priv;
925
926 return &ppp->stats;
927}
928
929static int 920static int
930ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) 921ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
931{ 922{
@@ -1095,8 +1086,8 @@ ppp_send_frame(struct ppp *ppp, struct sk_buff *skb)
1095#endif /* CONFIG_PPP_FILTER */ 1086#endif /* CONFIG_PPP_FILTER */
1096 } 1087 }
1097 1088
1098 ++ppp->stats.tx_packets; 1089 ++ppp->dev->stats.tx_packets;
1099 ppp->stats.tx_bytes += skb->len - 2; 1090 ppp->dev->stats.tx_bytes += skb->len - 2;
1100 1091
1101 switch (proto) { 1092 switch (proto) {
1102 case PPP_IP: 1093 case PPP_IP:
@@ -1171,7 +1162,7 @@ ppp_send_frame(struct ppp *ppp, struct sk_buff *skb)
1171 drop: 1162 drop:
1172 if (skb) 1163 if (skb)
1173 kfree_skb(skb); 1164 kfree_skb(skb);
1174 ++ppp->stats.tx_errors; 1165 ++ppp->dev->stats.tx_errors;
1175} 1166}
1176 1167
1177/* 1168/*
@@ -1409,7 +1400,7 @@ static int ppp_mp_explode(struct ppp *ppp, struct sk_buff *skb)
1409 spin_unlock_bh(&pch->downl); 1400 spin_unlock_bh(&pch->downl);
1410 if (ppp->debug & 1) 1401 if (ppp->debug & 1)
1411 printk(KERN_ERR "PPP: no memory (fragment)\n"); 1402 printk(KERN_ERR "PPP: no memory (fragment)\n");
1412 ++ppp->stats.tx_errors; 1403 ++ppp->dev->stats.tx_errors;
1413 ++ppp->nxseq; 1404 ++ppp->nxseq;
1414 return 1; /* abandon the frame */ 1405 return 1; /* abandon the frame */
1415} 1406}
@@ -1538,7 +1529,7 @@ ppp_receive_frame(struct ppp *ppp, struct sk_buff *skb, struct channel *pch)
1538 1529
1539 if (skb->len > 0) 1530 if (skb->len > 0)
1540 /* note: a 0-length skb is used as an error indication */ 1531 /* note: a 0-length skb is used as an error indication */
1541 ++ppp->stats.rx_length_errors; 1532 ++ppp->dev->stats.rx_length_errors;
1542 1533
1543 kfree_skb(skb); 1534 kfree_skb(skb);
1544 ppp_receive_error(ppp); 1535 ppp_receive_error(ppp);
@@ -1547,7 +1538,7 @@ ppp_receive_frame(struct ppp *ppp, struct sk_buff *skb, struct channel *pch)
1547static void 1538static void
1548ppp_receive_error(struct ppp *ppp) 1539ppp_receive_error(struct ppp *ppp)
1549{ 1540{
1550 ++ppp->stats.rx_errors; 1541 ++ppp->dev->stats.rx_errors;
1551 if (ppp->vj) 1542 if (ppp->vj)
1552 slhc_toss(ppp->vj); 1543 slhc_toss(ppp->vj);
1553} 1544}
@@ -1627,8 +1618,8 @@ ppp_receive_nonmp_frame(struct ppp *ppp, struct sk_buff *skb)
1627 break; 1618 break;
1628 } 1619 }
1629 1620
1630 ++ppp->stats.rx_packets; 1621 ++ppp->dev->stats.rx_packets;
1631 ppp->stats.rx_bytes += skb->len - 2; 1622 ppp->dev->stats.rx_bytes += skb->len - 2;
1632 1623
1633 npi = proto_to_npindex(proto); 1624 npi = proto_to_npindex(proto);
1634 if (npi < 0) { 1625 if (npi < 0) {
@@ -1806,7 +1797,7 @@ ppp_receive_mp_frame(struct ppp *ppp, struct sk_buff *skb, struct channel *pch)
1806 */ 1797 */
1807 if (seq_before(seq, ppp->nextseq)) { 1798 if (seq_before(seq, ppp->nextseq)) {
1808 kfree_skb(skb); 1799 kfree_skb(skb);
1809 ++ppp->stats.rx_dropped; 1800 ++ppp->dev->stats.rx_dropped;
1810 ppp_receive_error(ppp); 1801 ppp_receive_error(ppp);
1811 return; 1802 return;
1812 } 1803 }
@@ -1928,7 +1919,7 @@ ppp_mp_reconstruct(struct ppp *ppp)
1928 /* Got a complete packet yet? */ 1919 /* Got a complete packet yet? */
1929 if (lost == 0 && (p->BEbits & E) && (head->BEbits & B)) { 1920 if (lost == 0 && (p->BEbits & E) && (head->BEbits & B)) {
1930 if (len > ppp->mrru + 2) { 1921 if (len > ppp->mrru + 2) {
1931 ++ppp->stats.rx_length_errors; 1922 ++ppp->dev->stats.rx_length_errors;
1932 printk(KERN_DEBUG "PPP: reconstructed packet" 1923 printk(KERN_DEBUG "PPP: reconstructed packet"
1933 " is too long (%d)\n", len); 1924 " is too long (%d)\n", len);
1934 } else if (p == head) { 1925 } else if (p == head) {
@@ -1937,7 +1928,7 @@ ppp_mp_reconstruct(struct ppp *ppp)
1937 skb = skb_get(p); 1928 skb = skb_get(p);
1938 break; 1929 break;
1939 } else if ((skb = dev_alloc_skb(len)) == NULL) { 1930 } else if ((skb = dev_alloc_skb(len)) == NULL) {
1940 ++ppp->stats.rx_missed_errors; 1931 ++ppp->dev->stats.rx_missed_errors;
1941 printk(KERN_DEBUG "PPP: no memory for " 1932 printk(KERN_DEBUG "PPP: no memory for "
1942 "reconstructed packet"); 1933 "reconstructed packet");
1943 } else { 1934 } else {
@@ -1966,7 +1957,7 @@ ppp_mp_reconstruct(struct ppp *ppp)
1966 if (ppp->debug & 1) 1957 if (ppp->debug & 1)
1967 printk(KERN_DEBUG " missed pkts %u..%u\n", 1958 printk(KERN_DEBUG " missed pkts %u..%u\n",
1968 ppp->nextseq, head->sequence-1); 1959 ppp->nextseq, head->sequence-1);
1969 ++ppp->stats.rx_dropped; 1960 ++ppp->dev->stats.rx_dropped;
1970 ppp_receive_error(ppp); 1961 ppp_receive_error(ppp);
1971 } 1962 }
1972 1963
@@ -2377,12 +2368,12 @@ ppp_get_stats(struct ppp *ppp, struct ppp_stats *st)
2377 struct slcompress *vj = ppp->vj; 2368 struct slcompress *vj = ppp->vj;
2378 2369
2379 memset(st, 0, sizeof(*st)); 2370 memset(st, 0, sizeof(*st));
2380 st->p.ppp_ipackets = ppp->stats.rx_packets; 2371 st->p.ppp_ipackets = ppp->dev->stats.rx_packets;
2381 st->p.ppp_ierrors = ppp->stats.rx_errors; 2372 st->p.ppp_ierrors = ppp->dev->stats.rx_errors;
2382 st->p.ppp_ibytes = ppp->stats.rx_bytes; 2373 st->p.ppp_ibytes = ppp->dev->stats.rx_bytes;
2383 st->p.ppp_opackets = ppp->stats.tx_packets; 2374 st->p.ppp_opackets = ppp->dev->stats.tx_packets;
2384 st->p.ppp_oerrors = ppp->stats.tx_errors; 2375 st->p.ppp_oerrors = ppp->dev->stats.tx_errors;
2385 st->p.ppp_obytes = ppp->stats.tx_bytes; 2376 st->p.ppp_obytes = ppp->dev->stats.tx_bytes;
2386 if (!vj) 2377 if (!vj)
2387 return; 2378 return;
2388 st->vj.vjs_packets = vj->sls_o_compressed + vj->sls_o_uncompressed; 2379 st->vj.vjs_packets = vj->sls_o_compressed + vj->sls_o_uncompressed;
@@ -2436,7 +2427,6 @@ ppp_create_interface(int unit, int *retp)
2436 dev->priv = ppp; 2427 dev->priv = ppp;
2437 2428
2438 dev->hard_start_xmit = ppp_start_xmit; 2429 dev->hard_start_xmit = ppp_start_xmit;
2439 dev->get_stats = ppp_net_stats;
2440 dev->do_ioctl = ppp_net_ioctl; 2430 dev->do_ioctl = ppp_net_ioctl;
2441 2431
2442 ret = -EEXIST; 2432 ret = -EEXIST;
diff --git a/drivers/net/tun.c b/drivers/net/tun.c
index d91856b19f6f..0ce07a339c7e 100644
--- a/drivers/net/tun.c
+++ b/drivers/net/tun.c
@@ -668,16 +668,23 @@ static int tun_chr_ioctl(struct inode *inode, struct file *file,
668 break; 668 break;
669 669
670 case TUNSETLINK: 670 case TUNSETLINK:
671 {
672 int ret;
673
671 /* Only allow setting the type when the interface is down */ 674 /* Only allow setting the type when the interface is down */
675 rtnl_lock();
672 if (tun->dev->flags & IFF_UP) { 676 if (tun->dev->flags & IFF_UP) {
673 DBG(KERN_INFO "%s: Linktype set failed because interface is up\n", 677 DBG(KERN_INFO "%s: Linktype set failed because interface is up\n",
674 tun->dev->name); 678 tun->dev->name);
675 return -EBUSY; 679 ret = -EBUSY;
676 } else { 680 } else {
677 tun->dev->type = (int) arg; 681 tun->dev->type = (int) arg;
678 DBG(KERN_INFO "%s: linktype set to %d\n", tun->dev->name, tun->dev->type); 682 DBG(KERN_INFO "%s: linktype set to %d\n", tun->dev->name, tun->dev->type);
683 ret = 0;
679 } 684 }
680 break; 685 rtnl_unlock();
686 return ret;
687 }
681 688
682#ifdef TUN_DEBUG 689#ifdef TUN_DEBUG
683 case TUNSETDEBUG: 690 case TUNSETDEBUG:
@@ -734,7 +741,12 @@ static int tun_chr_ioctl(struct inode *inode, struct file *file,
734 case SIOCADDMULTI: 741 case SIOCADDMULTI:
735 /** Add the specified group to the character device's multicast filter 742 /** Add the specified group to the character device's multicast filter
736 * list. */ 743 * list. */
744 rtnl_lock();
745 netif_tx_lock_bh(tun->dev);
737 add_multi(tun->chr_filter, ifr.ifr_hwaddr.sa_data); 746 add_multi(tun->chr_filter, ifr.ifr_hwaddr.sa_data);
747 netif_tx_unlock_bh(tun->dev);
748 rtnl_unlock();
749
738 DBG(KERN_DEBUG "%s: add multi: %s\n", 750 DBG(KERN_DEBUG "%s: add multi: %s\n",
739 tun->dev->name, print_mac(mac, ifr.ifr_hwaddr.sa_data)); 751 tun->dev->name, print_mac(mac, ifr.ifr_hwaddr.sa_data));
740 return 0; 752 return 0;
@@ -742,7 +754,12 @@ static int tun_chr_ioctl(struct inode *inode, struct file *file,
742 case SIOCDELMULTI: 754 case SIOCDELMULTI:
743 /** Remove the specified group from the character device's multicast 755 /** Remove the specified group from the character device's multicast
744 * filter list. */ 756 * filter list. */
757 rtnl_lock();
758 netif_tx_lock_bh(tun->dev);
745 del_multi(tun->chr_filter, ifr.ifr_hwaddr.sa_data); 759 del_multi(tun->chr_filter, ifr.ifr_hwaddr.sa_data);
760 netif_tx_unlock_bh(tun->dev);
761 rtnl_unlock();
762
746 DBG(KERN_DEBUG "%s: del multi: %s\n", 763 DBG(KERN_DEBUG "%s: del multi: %s\n",
747 tun->dev->name, print_mac(mac, ifr.ifr_hwaddr.sa_data)); 764 tun->dev->name, print_mac(mac, ifr.ifr_hwaddr.sa_data));
748 return 0; 765 return 0;
diff --git a/drivers/net/wireless/Makefile b/drivers/net/wireless/Makefile
index 70092191fc53..c2642bc1d49b 100644
--- a/drivers/net/wireless/Makefile
+++ b/drivers/net/wireless/Makefile
@@ -56,8 +56,7 @@ obj-$(CONFIG_RTL8187) += rtl8187.o
56 56
57obj-$(CONFIG_ADM8211) += adm8211.o 57obj-$(CONFIG_ADM8211) += adm8211.o
58 58
59obj-$(CONFIG_IWL3945) += iwlwifi/ 59obj-$(CONFIG_IWLCORE) += iwlwifi/
60obj-$(CONFIG_IWL4965) += iwlwifi/
61obj-$(CONFIG_RT2X00) += rt2x00/ 60obj-$(CONFIG_RT2X00) += rt2x00/
62 61
63obj-$(CONFIG_P54_COMMON) += p54/ 62obj-$(CONFIG_P54_COMMON) += p54/
diff --git a/drivers/net/wireless/ath5k/hw.c b/drivers/net/wireless/ath5k/hw.c
index 87e782291a01..5fb1ae6ad3e2 100644
--- a/drivers/net/wireless/ath5k/hw.c
+++ b/drivers/net/wireless/ath5k/hw.c
@@ -304,14 +304,20 @@ struct ath5k_hw *ath5k_hw_attach(struct ath5k_softc *sc, u8 mac_version)
304 ah->ah_radio = AR5K_RF2413; 304 ah->ah_radio = AR5K_RF2413;
305 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A; 305 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
306 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC2) { 306 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_SC2) {
307
308 ah->ah_radio = AR5K_RF5413; 307 ah->ah_radio = AR5K_RF5413;
308 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
309 } else if (ah->ah_radio_5ghz_revision < AR5K_SREV_RAD_5133) {
309 310
310 if (ah->ah_mac_srev <= AR5K_SREV_VER_AR5424 && 311 /* AR5424 */
311 ah->ah_mac_srev >= AR5K_SREV_VER_AR2424) 312 if (srev >= AR5K_SREV_VER_AR5424) {
313 ah->ah_radio = AR5K_RF5413;
312 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5424; 314 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5424;
313 else 315 /* AR2424 */
316 } else {
317 ah->ah_radio = AR5K_RF2413; /* For testing */
314 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A; 318 ah->ah_phy_spending = AR5K_PHY_SPENDING_RF5112A;
319 }
320
315 /* 321 /*
316 * Register returns 0x4 for radio revision 322 * Register returns 0x4 for radio revision
317 * so ath5k_hw_radio_revision doesn't parse the value 323 * so ath5k_hw_radio_revision doesn't parse the value
diff --git a/drivers/net/wireless/b43/dma.c b/drivers/net/wireless/b43/dma.c
index 21c886a9a1d9..6dcbb3c87e72 100644
--- a/drivers/net/wireless/b43/dma.c
+++ b/drivers/net/wireless/b43/dma.c
@@ -980,6 +980,42 @@ void b43_dma_free(struct b43_wldev *dev)
980 destroy_ring(dma, tx_ring_mcast); 980 destroy_ring(dma, tx_ring_mcast);
981} 981}
982 982
983static int b43_dma_set_mask(struct b43_wldev *dev, u64 mask)
984{
985 u64 orig_mask = mask;
986 bool fallback = 0;
987 int err;
988
989 /* Try to set the DMA mask. If it fails, try falling back to a
990 * lower mask, as we can always also support a lower one. */
991 while (1) {
992 err = ssb_dma_set_mask(dev->dev, mask);
993 if (!err)
994 break;
995 if (mask == DMA_64BIT_MASK) {
996 mask = DMA_32BIT_MASK;
997 fallback = 1;
998 continue;
999 }
1000 if (mask == DMA_32BIT_MASK) {
1001 mask = DMA_30BIT_MASK;
1002 fallback = 1;
1003 continue;
1004 }
1005 b43err(dev->wl, "The machine/kernel does not support "
1006 "the required %u-bit DMA mask\n",
1007 (unsigned int)dma_mask_to_engine_type(orig_mask));
1008 return -EOPNOTSUPP;
1009 }
1010 if (fallback) {
1011 b43info(dev->wl, "DMA mask fallback from %u-bit to %u-bit\n",
1012 (unsigned int)dma_mask_to_engine_type(orig_mask),
1013 (unsigned int)dma_mask_to_engine_type(mask));
1014 }
1015
1016 return 0;
1017}
1018
983int b43_dma_init(struct b43_wldev *dev) 1019int b43_dma_init(struct b43_wldev *dev)
984{ 1020{
985 struct b43_dma *dma = &dev->dma; 1021 struct b43_dma *dma = &dev->dma;
@@ -989,14 +1025,9 @@ int b43_dma_init(struct b43_wldev *dev)
989 1025
990 dmamask = supported_dma_mask(dev); 1026 dmamask = supported_dma_mask(dev);
991 type = dma_mask_to_engine_type(dmamask); 1027 type = dma_mask_to_engine_type(dmamask);
992 err = ssb_dma_set_mask(dev->dev, dmamask); 1028 err = b43_dma_set_mask(dev, dmamask);
993 if (err) { 1029 if (err)
994 b43err(dev->wl, "The machine/kernel does not support " 1030 return err;
995 "the required DMA mask (0x%08X%08X)\n",
996 (unsigned int)((dmamask & 0xFFFFFFFF00000000ULL) >> 32),
997 (unsigned int)(dmamask & 0x00000000FFFFFFFFULL));
998 return -EOPNOTSUPP;
999 }
1000 1031
1001 err = -ENOMEM; 1032 err = -ENOMEM;
1002 /* setup TX DMA channels. */ 1033 /* setup TX DMA channels. */
diff --git a/drivers/net/wireless/b43/main.c b/drivers/net/wireless/b43/main.c
index 943cc851c504..4bf8a99099fe 100644
--- a/drivers/net/wireless/b43/main.c
+++ b/drivers/net/wireless/b43/main.c
@@ -84,6 +84,10 @@ int b43_modparam_qos = 1;
84module_param_named(qos, b43_modparam_qos, int, 0444); 84module_param_named(qos, b43_modparam_qos, int, 0444);
85MODULE_PARM_DESC(qos, "Enable QOS support (default on)"); 85MODULE_PARM_DESC(qos, "Enable QOS support (default on)");
86 86
87static int modparam_btcoex = 1;
88module_param_named(btcoex, modparam_btcoex, int, 0444);
89MODULE_PARM_DESC(btcoex, "Enable Bluetooth coexistance (default on)");
90
87 91
88static const struct ssb_device_id b43_ssb_tbl[] = { 92static const struct ssb_device_id b43_ssb_tbl[] = {
89 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 5), 93 SSB_DEVICE(SSB_VENDOR_BROADCOM, SSB_DEV_80211, 5),
@@ -3706,8 +3710,10 @@ static void setup_struct_wldev_for_init(struct b43_wldev *dev)
3706static void b43_bluetooth_coext_enable(struct b43_wldev *dev) 3710static void b43_bluetooth_coext_enable(struct b43_wldev *dev)
3707{ 3711{
3708 struct ssb_sprom *sprom = &dev->dev->bus->sprom; 3712 struct ssb_sprom *sprom = &dev->dev->bus->sprom;
3709 u32 hf; 3713 u64 hf;
3710 3714
3715 if (!modparam_btcoex)
3716 return;
3711 if (!(sprom->boardflags_lo & B43_BFL_BTCOEXIST)) 3717 if (!(sprom->boardflags_lo & B43_BFL_BTCOEXIST))
3712 return; 3718 return;
3713 if (dev->phy.type != B43_PHYTYPE_B && !dev->phy.gmode) 3719 if (dev->phy.type != B43_PHYTYPE_B && !dev->phy.gmode)
@@ -3719,11 +3725,13 @@ static void b43_bluetooth_coext_enable(struct b43_wldev *dev)
3719 else 3725 else
3720 hf |= B43_HF_BTCOEX; 3726 hf |= B43_HF_BTCOEX;
3721 b43_hf_write(dev, hf); 3727 b43_hf_write(dev, hf);
3722 //TODO
3723} 3728}
3724 3729
3725static void b43_bluetooth_coext_disable(struct b43_wldev *dev) 3730static void b43_bluetooth_coext_disable(struct b43_wldev *dev)
3726{ //TODO 3731{
3732 if (!modparam_btcoex)
3733 return;
3734 //TODO
3727} 3735}
3728 3736
3729static void b43_imcfglo_timeouts_workaround(struct b43_wldev *dev) 3737static void b43_imcfglo_timeouts_workaround(struct b43_wldev *dev)
@@ -3852,7 +3860,8 @@ static int b43_wireless_core_init(struct b43_wldev *dev)
3852 struct ssb_sprom *sprom = &bus->sprom; 3860 struct ssb_sprom *sprom = &bus->sprom;
3853 struct b43_phy *phy = &dev->phy; 3861 struct b43_phy *phy = &dev->phy;
3854 int err; 3862 int err;
3855 u32 hf, tmp; 3863 u64 hf;
3864 u32 tmp;
3856 3865
3857 B43_WARN_ON(b43_status(dev) != B43_STAT_UNINIT); 3866 B43_WARN_ON(b43_status(dev) != B43_STAT_UNINIT);
3858 3867
@@ -4414,8 +4423,16 @@ static int b43_one_core_attach(struct ssb_device *dev, struct b43_wl *wl)
4414 return err; 4423 return err;
4415} 4424}
4416 4425
4426#define IS_PDEV(pdev, _vendor, _device, _subvendor, _subdevice) ( \
4427 (pdev->vendor == PCI_VENDOR_ID_##_vendor) && \
4428 (pdev->device == _device) && \
4429 (pdev->subsystem_vendor == PCI_VENDOR_ID_##_subvendor) && \
4430 (pdev->subsystem_device == _subdevice) )
4431
4417static void b43_sprom_fixup(struct ssb_bus *bus) 4432static void b43_sprom_fixup(struct ssb_bus *bus)
4418{ 4433{
4434 struct pci_dev *pdev;
4435
4419 /* boardflags workarounds */ 4436 /* boardflags workarounds */
4420 if (bus->boardinfo.vendor == SSB_BOARDVENDOR_DELL && 4437 if (bus->boardinfo.vendor == SSB_BOARDVENDOR_DELL &&
4421 bus->chip_id == 0x4301 && bus->boardinfo.rev == 0x74) 4438 bus->chip_id == 0x4301 && bus->boardinfo.rev == 0x74)
@@ -4423,6 +4440,13 @@ static void b43_sprom_fixup(struct ssb_bus *bus)
4423 if (bus->boardinfo.vendor == PCI_VENDOR_ID_APPLE && 4440 if (bus->boardinfo.vendor == PCI_VENDOR_ID_APPLE &&
4424 bus->boardinfo.type == 0x4E && bus->boardinfo.rev > 0x40) 4441 bus->boardinfo.type == 0x4E && bus->boardinfo.rev > 0x40)
4425 bus->sprom.boardflags_lo |= B43_BFL_PACTRL; 4442 bus->sprom.boardflags_lo |= B43_BFL_PACTRL;
4443 if (bus->bustype == SSB_BUSTYPE_PCI) {
4444 pdev = bus->host_pci;
4445 if (IS_PDEV(pdev, BROADCOM, 0x4318, ASUSTEK, 0x100F) ||
4446 IS_PDEV(pdev, BROADCOM, 0x4320, LINKSYS, 0x0015) ||
4447 IS_PDEV(pdev, BROADCOM, 0x4320, LINKSYS, 0x0013))
4448 bus->sprom.boardflags_lo &= ~B43_BFL_BTCOEXIST;
4449 }
4426} 4450}
4427 4451
4428static void b43_wireless_exit(struct ssb_device *dev, struct b43_wl *wl) 4452static void b43_wireless_exit(struct ssb_device *dev, struct b43_wl *wl)
diff --git a/drivers/net/wireless/b43/phy.c b/drivers/net/wireless/b43/phy.c
index 575c5436ebdf..de024dc03718 100644
--- a/drivers/net/wireless/b43/phy.c
+++ b/drivers/net/wireless/b43/phy.c
@@ -2043,7 +2043,7 @@ int b43_phy_init(struct b43_wldev *dev)
2043void b43_set_rx_antenna(struct b43_wldev *dev, int antenna) 2043void b43_set_rx_antenna(struct b43_wldev *dev, int antenna)
2044{ 2044{
2045 struct b43_phy *phy = &dev->phy; 2045 struct b43_phy *phy = &dev->phy;
2046 u32 hf; 2046 u64 hf;
2047 u16 tmp; 2047 u16 tmp;
2048 int autodiv = 0; 2048 int autodiv = 0;
2049 2049
diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c
index 1a5678fe4224..a1a0b3c581f1 100644
--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c
@@ -6907,7 +6907,6 @@ static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
6907 6907
6908 if (priv->vif != vif) { 6908 if (priv->vif != vif) {
6909 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); 6909 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
6910 mutex_unlock(&priv->mutex);
6911 return 0; 6910 return 0;
6912 } 6911 }
6913 6912
diff --git a/drivers/net/wireless/iwlwifi/iwl4965-base.c b/drivers/net/wireless/iwlwifi/iwl4965-base.c
index d7e2358a213a..d0bbcaaeb94c 100644
--- a/drivers/net/wireless/iwlwifi/iwl4965-base.c
+++ b/drivers/net/wireless/iwlwifi/iwl4965-base.c
@@ -6473,7 +6473,6 @@ static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
6473 6473
6474 if (priv->vif != vif) { 6474 if (priv->vif != vif) {
6475 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n"); 6475 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
6476 mutex_unlock(&priv->mutex);
6477 return 0; 6476 return 0;
6478 } 6477 }
6479 6478
diff --git a/drivers/net/wireless/prism54/isl_ioctl.c b/drivers/net/wireless/prism54/isl_ioctl.c
index e5b3c282009c..5b375b289036 100644
--- a/drivers/net/wireless/prism54/isl_ioctl.c
+++ b/drivers/net/wireless/prism54/isl_ioctl.c
@@ -1186,7 +1186,7 @@ prism54_get_encode(struct net_device *ndev, struct iw_request_info *info,
1186 rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r); 1186 rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYID, 0, NULL, &r);
1187 devindex = r.u; 1187 devindex = r.u;
1188 /* Now get the key, return it */ 1188 /* Now get the key, return it */
1189 if ((index < 0) || (index > 3)) 1189 if (index == -1 || index > 3)
1190 /* no index provided, use the current one */ 1190 /* no index provided, use the current one */
1191 index = devindex; 1191 index = devindex;
1192 rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYX, index, NULL, &r); 1192 rvalue |= mgt_get_request(priv, DOT11_OID_DEFKEYX, index, NULL, &r);
diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
index 977751f372ff..d0b1fb15c709 100644
--- a/drivers/net/wireless/rndis_wlan.c
+++ b/drivers/net/wireless/rndis_wlan.c
@@ -2402,7 +2402,6 @@ static int bcm4320_early_init(struct usbnet *dev)
2402 priv->param_power_output = modparam_power_output; 2402 priv->param_power_output = modparam_power_output;
2403 priv->param_roamtrigger = modparam_roamtrigger; 2403 priv->param_roamtrigger = modparam_roamtrigger;
2404 priv->param_roamdelta = modparam_roamdelta; 2404 priv->param_roamdelta = modparam_roamdelta;
2405 priv->param_workaround_interval = modparam_workaround_interval;
2406 2405
2407 priv->param_country[0] = toupper(priv->param_country[0]); 2406 priv->param_country[0] = toupper(priv->param_country[0]);
2408 priv->param_country[1] = toupper(priv->param_country[1]); 2407 priv->param_country[1] = toupper(priv->param_country[1]);
@@ -2425,8 +2424,10 @@ static int bcm4320_early_init(struct usbnet *dev)
2425 else if (priv->param_roamdelta > 2) 2424 else if (priv->param_roamdelta > 2)
2426 priv->param_roamdelta = 2; 2425 priv->param_roamdelta = 2;
2427 2426
2428 if (priv->param_workaround_interval < 0) 2427 if (modparam_workaround_interval < 0)
2429 priv->param_workaround_interval = 500; 2428 priv->param_workaround_interval = 500;
2429 else
2430 priv->param_workaround_interval = modparam_workaround_interval;
2430 2431
2431 rndis_set_config_parameter_str(dev, "Country", priv->param_country); 2432 rndis_set_config_parameter_str(dev, "Country", priv->param_country);
2432 rndis_set_config_parameter_str(dev, "FrameBursting", 2433 rndis_set_config_parameter_str(dev, "FrameBursting",
diff --git a/drivers/pcmcia/Kconfig b/drivers/pcmcia/Kconfig
index ed8c06904807..8d8852651fd2 100644
--- a/drivers/pcmcia/Kconfig
+++ b/drivers/pcmcia/Kconfig
@@ -200,7 +200,6 @@ config PCMCIA_AU1X00
200config PCMCIA_SA1100 200config PCMCIA_SA1100
201 tristate "SA1100 support" 201 tristate "SA1100 support"
202 depends on ARM && ARCH_SA1100 && PCMCIA 202 depends on ARM && ARCH_SA1100 && PCMCIA
203 depends on ARCH_LUBBOCK || MACH_MAINSTONE || PXA_SHARPSL || MACH_ARMCORE
204 help 203 help
205 Say Y here to include support for SA11x0-based PCMCIA or CF 204 Say Y here to include support for SA11x0-based PCMCIA or CF
206 sockets, found on HP iPAQs, Yopy, and other StrongARM(R)/ 205 sockets, found on HP iPAQs, Yopy, and other StrongARM(R)/
@@ -221,6 +220,7 @@ config PCMCIA_SA1111
221config PCMCIA_PXA2XX 220config PCMCIA_PXA2XX
222 tristate "PXA2xx support" 221 tristate "PXA2xx support"
223 depends on ARM && ARCH_PXA && PCMCIA 222 depends on ARM && ARCH_PXA && PCMCIA
223 depends on ARCH_LUBBOCK || MACH_MAINSTONE || PXA_SHARPSL || MACH_ARMCORE
224 help 224 help
225 Say Y here to include support for the PXA2xx PCMCIA controller 225 Say Y here to include support for the PXA2xx PCMCIA controller
226 226
diff --git a/drivers/serial/bfin_5xx.c b/drivers/serial/bfin_5xx.c
index 46bb47f37b9a..5f55534a290b 100644
--- a/drivers/serial/bfin_5xx.c
+++ b/drivers/serial/bfin_5xx.c
@@ -151,7 +151,8 @@ void kgdb_put_debug_char(int chr)
151{ 151{
152 struct bfin_serial_port *uart; 152 struct bfin_serial_port *uart;
153 153
154 if (CONFIG_KGDB_UART_PORT<0 || CONFIG_KGDB_UART_PORT>=NR_PORTS) 154 if (CONFIG_KGDB_UART_PORT < 0
155 || CONFIG_KGDB_UART_PORT >= BFIN_UART_NR_PORTS)
155 uart = &bfin_serial_ports[0]; 156 uart = &bfin_serial_ports[0];
156 else 157 else
157 uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT]; 158 uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
@@ -173,7 +174,8 @@ int kgdb_get_debug_char(void)
173 struct bfin_serial_port *uart; 174 struct bfin_serial_port *uart;
174 unsigned char chr; 175 unsigned char chr;
175 176
176 if (CONFIG_KGDB_UART_PORT<0 || CONFIG_KGDB_UART_PORT>=NR_PORTS) 177 if (CONFIG_KGDB_UART_PORT < 0
178 || CONFIG_KGDB_UART_PORT >= BFIN_UART_NR_PORTS)
177 uart = &bfin_serial_ports[0]; 179 uart = &bfin_serial_ports[0];
178 else 180 else
179 uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT]; 181 uart = &bfin_serial_ports[CONFIG_KGDB_UART_PORT];
@@ -192,7 +194,7 @@ int kgdb_get_debug_char(void)
192} 194}
193#endif 195#endif
194 196
195#if ANOMALY_05000230 && defined(CONFIG_SERIAL_BFIN_PIO) 197#if ANOMALY_05000363 && defined(CONFIG_SERIAL_BFIN_PIO)
196# define UART_GET_ANOMALY_THRESHOLD(uart) ((uart)->anomaly_threshold) 198# define UART_GET_ANOMALY_THRESHOLD(uart) ((uart)->anomaly_threshold)
197# define UART_SET_ANOMALY_THRESHOLD(uart, v) ((uart)->anomaly_threshold = (v)) 199# define UART_SET_ANOMALY_THRESHOLD(uart, v) ((uart)->anomaly_threshold = (v))
198#else 200#else
@@ -237,7 +239,7 @@ static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
237 } 239 }
238#endif 240#endif
239 241
240 if (ANOMALY_05000230) { 242 if (ANOMALY_05000363) {
241 /* The BF533 (and BF561) family of processors have a nice anomaly 243 /* The BF533 (and BF561) family of processors have a nice anomaly
242 * where they continuously generate characters for a "single" break. 244 * where they continuously generate characters for a "single" break.
243 * We have to basically ignore this flood until the "next" valid 245 * We have to basically ignore this flood until the "next" valid
@@ -249,9 +251,6 @@ static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
249 * timeout was picked as it must absolutely be larger than 1 251 * timeout was picked as it must absolutely be larger than 1
250 * character time +/- some percent. So 1.5 sounds good. All other 252 * character time +/- some percent. So 1.5 sounds good. All other
251 * Blackfin families operate properly. Woo. 253 * Blackfin families operate properly. Woo.
252 * Note: While Anomaly 05000230 does not directly address this,
253 * the changes that went in for it also fixed this issue.
254 * That anomaly was fixed in 0.5+ silicon. I like bunnies.
255 */ 254 */
256 if (anomaly_start.tv_sec) { 255 if (anomaly_start.tv_sec) {
257 struct timeval curr; 256 struct timeval curr;
@@ -285,7 +284,7 @@ static void bfin_serial_rx_chars(struct bfin_serial_port *uart)
285 } 284 }
286 285
287 if (status & BI) { 286 if (status & BI) {
288 if (ANOMALY_05000230) 287 if (ANOMALY_05000363)
289 if (bfin_revid() < 5) 288 if (bfin_revid() < 5)
290 do_gettimeofday(&anomaly_start); 289 do_gettimeofday(&anomaly_start);
291 uart->port.icount.brk++; 290 uart->port.icount.brk++;
@@ -507,8 +506,7 @@ void bfin_serial_rx_dma_timeout(struct bfin_serial_port *uart)
507 uart->rx_dma_buf.tail = uart->rx_dma_buf.head; 506 uart->rx_dma_buf.tail = uart->rx_dma_buf.head;
508 } 507 }
509 508
510 uart->rx_dma_timer.expires = jiffies + DMA_RX_FLUSH_JIFFIES; 509 mod_timer(&(uart->rx_dma_timer), jiffies + DMA_RX_FLUSH_JIFFIES);
511 add_timer(&(uart->rx_dma_timer));
512} 510}
513 511
514static irqreturn_t bfin_serial_dma_tx_int(int irq, void *dev_id) 512static irqreturn_t bfin_serial_dma_tx_int(int irq, void *dev_id)
@@ -551,9 +549,7 @@ static irqreturn_t bfin_serial_dma_rx_int(int irq, void *dev_id)
551 clear_dma_irqstat(uart->rx_dma_channel); 549 clear_dma_irqstat(uart->rx_dma_channel);
552 spin_unlock(&uart->port.lock); 550 spin_unlock(&uart->port.lock);
553 551
554 del_timer(&(uart->rx_dma_timer)); 552 mod_timer(&(uart->rx_dma_timer), jiffies);
555 uart->rx_dma_timer.expires = jiffies;
556 add_timer(&(uart->rx_dma_timer));
557 553
558 return IRQ_HANDLED; 554 return IRQ_HANDLED;
559} 555}
@@ -749,7 +745,7 @@ bfin_serial_set_termios(struct uart_port *port, struct ktermios *termios,
749 struct bfin_serial_port *uart = (struct bfin_serial_port *)port; 745 struct bfin_serial_port *uart = (struct bfin_serial_port *)port;
750 unsigned long flags; 746 unsigned long flags;
751 unsigned int baud, quot; 747 unsigned int baud, quot;
752 unsigned short val, ier, lsr, lcr = 0; 748 unsigned short val, ier, lcr = 0;
753 749
754 switch (termios->c_cflag & CSIZE) { 750 switch (termios->c_cflag & CSIZE) {
755 case CS8: 751 case CS8:
@@ -806,10 +802,6 @@ bfin_serial_set_termios(struct uart_port *port, struct ktermios *termios,
806 802
807 UART_SET_ANOMALY_THRESHOLD(uart, USEC_PER_SEC / baud * 15); 803 UART_SET_ANOMALY_THRESHOLD(uart, USEC_PER_SEC / baud * 15);
808 804
809 do {
810 lsr = UART_GET_LSR(uart);
811 } while (!(lsr & TEMT));
812
813 /* Disable UART */ 805 /* Disable UART */
814 ier = UART_GET_IER(uart); 806 ier = UART_GET_IER(uart);
815#ifdef CONFIG_BF54x 807#ifdef CONFIG_BF54x
@@ -900,6 +892,31 @@ bfin_serial_verify_port(struct uart_port *port, struct serial_struct *ser)
900 return 0; 892 return 0;
901} 893}
902 894
895/*
896 * Enable the IrDA function if tty->ldisc.num is N_IRDA.
897 * In other cases, disable IrDA function.
898 */
899static void bfin_set_ldisc(struct tty_struct *tty)
900{
901 int line = tty->index;
902 unsigned short val;
903
904 if (line >= tty->driver->num)
905 return;
906
907 switch (tty->ldisc.num) {
908 case N_IRDA:
909 val = UART_GET_GCTL(&bfin_serial_ports[line]);
910 val |= (IREN | RPOLC);
911 UART_PUT_GCTL(&bfin_serial_ports[line], val);
912 break;
913 default:
914 val = UART_GET_GCTL(&bfin_serial_ports[line]);
915 val &= ~(IREN | RPOLC);
916 UART_PUT_GCTL(&bfin_serial_ports[line], val);
917 }
918}
919
903static struct uart_ops bfin_serial_pops = { 920static struct uart_ops bfin_serial_pops = {
904 .tx_empty = bfin_serial_tx_empty, 921 .tx_empty = bfin_serial_tx_empty,
905 .set_mctrl = bfin_serial_set_mctrl, 922 .set_mctrl = bfin_serial_set_mctrl,
@@ -1172,7 +1189,7 @@ static struct uart_driver bfin_serial_reg = {
1172 .dev_name = BFIN_SERIAL_NAME, 1189 .dev_name = BFIN_SERIAL_NAME,
1173 .major = BFIN_SERIAL_MAJOR, 1190 .major = BFIN_SERIAL_MAJOR,
1174 .minor = BFIN_SERIAL_MINOR, 1191 .minor = BFIN_SERIAL_MINOR,
1175 .nr = NR_PORTS, 1192 .nr = BFIN_UART_NR_PORTS,
1176 .cons = BFIN_SERIAL_CONSOLE, 1193 .cons = BFIN_SERIAL_CONSOLE,
1177}; 1194};
1178 1195
@@ -1261,6 +1278,7 @@ static int __init bfin_serial_init(void)
1261 1278
1262 ret = uart_register_driver(&bfin_serial_reg); 1279 ret = uart_register_driver(&bfin_serial_reg);
1263 if (ret == 0) { 1280 if (ret == 0) {
1281 bfin_serial_reg.tty_driver->set_ldisc = bfin_set_ldisc;
1264 ret = platform_driver_register(&bfin_serial_driver); 1282 ret = platform_driver_register(&bfin_serial_driver);
1265 if (ret) { 1283 if (ret) {
1266 pr_debug("uart register failed\n"); 1284 pr_debug("uart register failed\n");
diff --git a/drivers/serial/sunzilog.c b/drivers/serial/sunzilog.c
index cb2e40506379..3271379a36db 100644
--- a/drivers/serial/sunzilog.c
+++ b/drivers/serial/sunzilog.c
@@ -1015,6 +1015,7 @@ static struct uart_ops sunzilog_pops = {
1015 .verify_port = sunzilog_verify_port, 1015 .verify_port = sunzilog_verify_port,
1016}; 1016};
1017 1017
1018static int uart_chip_count;
1018static struct uart_sunzilog_port *sunzilog_port_table; 1019static struct uart_sunzilog_port *sunzilog_port_table;
1019static struct zilog_layout __iomem **sunzilog_chip_regs; 1020static struct zilog_layout __iomem **sunzilog_chip_regs;
1020 1021
@@ -1350,16 +1351,22 @@ static int zilog_irq = -1;
1350 1351
1351static int __devinit zs_probe(struct of_device *op, const struct of_device_id *match) 1352static int __devinit zs_probe(struct of_device *op, const struct of_device_id *match)
1352{ 1353{
1353 static int inst; 1354 static int kbm_inst, uart_inst;
1355 int inst;
1354 struct uart_sunzilog_port *up; 1356 struct uart_sunzilog_port *up;
1355 struct zilog_layout __iomem *rp; 1357 struct zilog_layout __iomem *rp;
1356 int keyboard_mouse; 1358 int keyboard_mouse = 0;
1357 int err; 1359 int err;
1358 1360
1359 keyboard_mouse = 0;
1360 if (of_find_property(op->node, "keyboard", NULL)) 1361 if (of_find_property(op->node, "keyboard", NULL))
1361 keyboard_mouse = 1; 1362 keyboard_mouse = 1;
1362 1363
1364 /* uarts must come before keyboards/mice */
1365 if (keyboard_mouse)
1366 inst = uart_chip_count + kbm_inst;
1367 else
1368 inst = uart_inst;
1369
1363 sunzilog_chip_regs[inst] = of_ioremap(&op->resource[0], 0, 1370 sunzilog_chip_regs[inst] = of_ioremap(&op->resource[0], 0,
1364 sizeof(struct zilog_layout), 1371 sizeof(struct zilog_layout),
1365 "zs"); 1372 "zs");
@@ -1427,6 +1434,7 @@ static int __devinit zs_probe(struct of_device *op, const struct of_device_id *m
1427 rp, sizeof(struct zilog_layout)); 1434 rp, sizeof(struct zilog_layout));
1428 return err; 1435 return err;
1429 } 1436 }
1437 uart_inst++;
1430 } else { 1438 } else {
1431 printk(KERN_INFO "%s: Keyboard at MMIO 0x%llx (irq = %d) " 1439 printk(KERN_INFO "%s: Keyboard at MMIO 0x%llx (irq = %d) "
1432 "is a %s\n", 1440 "is a %s\n",
@@ -1438,12 +1446,11 @@ static int __devinit zs_probe(struct of_device *op, const struct of_device_id *m
1438 op->dev.bus_id, 1446 op->dev.bus_id,
1439 (unsigned long long) up[1].port.mapbase, 1447 (unsigned long long) up[1].port.mapbase,
1440 op->irqs[0], sunzilog_type(&up[1].port)); 1448 op->irqs[0], sunzilog_type(&up[1].port));
1449 kbm_inst++;
1441 } 1450 }
1442 1451
1443 dev_set_drvdata(&op->dev, &up[0]); 1452 dev_set_drvdata(&op->dev, &up[0]);
1444 1453
1445 inst++;
1446
1447 return 0; 1454 return 0;
1448} 1455}
1449 1456
@@ -1491,28 +1498,25 @@ static struct of_platform_driver zs_driver = {
1491static int __init sunzilog_init(void) 1498static int __init sunzilog_init(void)
1492{ 1499{
1493 struct device_node *dp; 1500 struct device_node *dp;
1494 int err, uart_count; 1501 int err;
1495 int num_keybms; 1502 int num_keybms = 0;
1496 int num_sunzilog = 0; 1503 int num_sunzilog = 0;
1497 1504
1498 num_keybms = 0;
1499 for_each_node_by_name(dp, "zs") { 1505 for_each_node_by_name(dp, "zs") {
1500 num_sunzilog++; 1506 num_sunzilog++;
1501 if (of_find_property(dp, "keyboard", NULL)) 1507 if (of_find_property(dp, "keyboard", NULL))
1502 num_keybms++; 1508 num_keybms++;
1503 } 1509 }
1504 1510
1505 uart_count = 0;
1506 if (num_sunzilog) { 1511 if (num_sunzilog) {
1507 int uart_count;
1508
1509 err = sunzilog_alloc_tables(num_sunzilog); 1512 err = sunzilog_alloc_tables(num_sunzilog);
1510 if (err) 1513 if (err)
1511 goto out; 1514 goto out;
1512 1515
1513 uart_count = (num_sunzilog * 2) - (2 * num_keybms); 1516 uart_chip_count = num_sunzilog - num_keybms;
1514 1517
1515 err = sunserial_register_minors(&sunzilog_reg, uart_count); 1518 err = sunserial_register_minors(&sunzilog_reg,
1519 uart_chip_count * 2);
1516 if (err) 1520 if (err)
1517 goto out_free_tables; 1521 goto out_free_tables;
1518 } 1522 }
diff --git a/drivers/ssb/pci.c b/drivers/ssb/pci.c
index 904b1a8d0885..57c4ccfab1ee 100644
--- a/drivers/ssb/pci.c
+++ b/drivers/ssb/pci.c
@@ -484,6 +484,11 @@ static int sprom_extract(struct ssb_bus *bus, struct ssb_sprom *out,
484 goto unsupported; 484 goto unsupported;
485 } 485 }
486 486
487 if (out->boardflags_lo == 0xFFFF)
488 out->boardflags_lo = 0; /* per specs */
489 if (out->boardflags_hi == 0xFFFF)
490 out->boardflags_hi = 0; /* per specs */
491
487 return 0; 492 return 0;
488unsupported: 493unsupported:
489 ssb_printk(KERN_WARNING PFX "Unsupported SPROM revision %d " 494 ssb_printk(KERN_WARNING PFX "Unsupported SPROM revision %d "
diff --git a/fs/Kconfig b/fs/Kconfig
index 8b18a8758677..2e43d46f65d6 100644
--- a/fs/Kconfig
+++ b/fs/Kconfig
@@ -411,7 +411,7 @@ config JFS_STATISTICS
411 to be made available to the user in the /proc/fs/jfs/ directory. 411 to be made available to the user in the /proc/fs/jfs/ directory.
412 412
413config FS_POSIX_ACL 413config FS_POSIX_ACL
414# Posix ACL utility routines (for now, only ext2/ext3/jfs/reiserfs) 414# Posix ACL utility routines (for now, only ext2/ext3/jfs/reiserfs/nfs4)
415# 415#
416# NOTE: you can implement Posix ACLs without these helpers (XFS does). 416# NOTE: you can implement Posix ACLs without these helpers (XFS does).
417# Never use this symbol for ifdefs. 417# Never use this symbol for ifdefs.
@@ -1664,105 +1664,86 @@ config NFS_V4
1664 1664
1665 If unsure, say N. 1665 If unsure, say N.
1666 1666
1667config NFS_DIRECTIO
1668 bool "Allow direct I/O on NFS files"
1669 depends on NFS_FS
1670 help
1671 This option enables applications to perform uncached I/O on files
1672 in NFS file systems using the O_DIRECT open() flag. When O_DIRECT
1673 is set for a file, its data is not cached in the system's page
1674 cache. Data is moved to and from user-level application buffers
1675 directly. Unlike local disk-based file systems, NFS O_DIRECT has
1676 no alignment restrictions.
1677
1678 Unless your program is designed to use O_DIRECT properly, you are
1679 much better off allowing the NFS client to manage data caching for
1680 you. Misusing O_DIRECT can cause poor server performance or network
1681 storms. This kernel build option defaults OFF to avoid exposing
1682 system administrators unwittingly to a potentially hazardous
1683 feature.
1684
1685 For more details on NFS O_DIRECT, see fs/nfs/direct.c.
1686
1687 If unsure, say N. This reduces the size of the NFS client, and
1688 causes open() to return EINVAL if a file residing in NFS is
1689 opened with the O_DIRECT flag.
1690
1691config NFSD 1667config NFSD
1692 tristate "NFS server support" 1668 tristate "NFS server support"
1693 depends on INET 1669 depends on INET
1694 select LOCKD 1670 select LOCKD
1695 select SUNRPC 1671 select SUNRPC
1696 select EXPORTFS 1672 select EXPORTFS
1697 select NFSD_V2_ACL if NFSD_V3_ACL
1698 select NFS_ACL_SUPPORT if NFSD_V2_ACL 1673 select NFS_ACL_SUPPORT if NFSD_V2_ACL
1699 select NFSD_TCP if NFSD_V4 1674 help
1700 select CRYPTO_MD5 if NFSD_V4 1675 Choose Y here if you want to allow other computers to access
1701 select CRYPTO if NFSD_V4 1676 files residing on this system using Sun's Network File System
1702 select FS_POSIX_ACL if NFSD_V4 1677 protocol. To compile the NFS server support as a module,
1703 select PROC_FS if NFSD_V4 1678 choose M here: the module will be called nfsd.
1704 select PROC_FS if SUNRPC_GSS 1679
1705 help 1680 You may choose to use a user-space NFS server instead, in which
1706 If you want your Linux box to act as an NFS *server*, so that other 1681 case you can choose N here.
1707 computers on your local network which support NFS can access certain 1682
1708 directories on your box transparently, you have two options: you can 1683 To export local file systems using NFS, you also need to install
1709 use the self-contained user space program nfsd, in which case you 1684 user space programs which can be found in the Linux nfs-utils
1710 should say N here, or you can say Y and use the kernel based NFS 1685 package, available from http://linux-nfs.org/. More detail about
1711 server. The advantage of the kernel based solution is that it is 1686 the Linux NFS server implementation is available via the
1712 faster. 1687 exports(5) man page.
1713 1688
1714 In either case, you will need support software; the respective 1689 Below you can choose which versions of the NFS protocol are
1715 locations are given in the file <file:Documentation/Changes> in the 1690 available to clients mounting the NFS server on this system.
1716 NFS section. 1691 Support for NFS version 2 (RFC 1094) is always available when
1717 1692 CONFIG_NFSD is selected.
1718 If you say Y here, you will get support for version 2 of the NFS 1693
1719 protocol (NFSv2). If you also want NFSv3, say Y to the next question 1694 If unsure, say N.
1720 as well.
1721
1722 Please read the NFS-HOWTO, available from
1723 <http://www.tldp.org/docs.html#howto>.
1724
1725 To compile the NFS server support as a module, choose M here: the
1726 module will be called nfsd. If unsure, say N.
1727 1695
1728config NFSD_V2_ACL 1696config NFSD_V2_ACL
1729 bool 1697 bool
1730 depends on NFSD 1698 depends on NFSD
1731 1699
1732config NFSD_V3 1700config NFSD_V3
1733 bool "Provide NFSv3 server support" 1701 bool "NFS server support for NFS version 3"
1734 depends on NFSD 1702 depends on NFSD
1735 help 1703 help
1736 If you would like to include the NFSv3 server as well as the NFSv2 1704 This option enables support in your system's NFS server for
1737 server, say Y here. If unsure, say Y. 1705 version 3 of the NFS protocol (RFC 1813).
1706
1707 If unsure, say Y.
1738 1708
1739config NFSD_V3_ACL 1709config NFSD_V3_ACL
1740 bool "Provide server support for the NFSv3 ACL protocol extension" 1710 bool "NFS server support for the NFSv3 ACL protocol extension"
1741 depends on NFSD_V3 1711 depends on NFSD_V3
1712 select NFSD_V2_ACL
1742 help 1713 help
1743 Implement the NFSv3 ACL protocol extension for manipulating POSIX 1714 Solaris NFS servers support an auxiliary NFSv3 ACL protocol that
1744 Access Control Lists on exported file systems. NFS clients should 1715 never became an official part of the NFS version 3 protocol.
1745 be compiled with the NFSv3 ACL protocol extension; see the 1716 This protocol extension allows applications on NFS clients to
1746 CONFIG_NFS_V3_ACL option. If unsure, say N. 1717 manipulate POSIX Access Control Lists on files residing on NFS
1718 servers. NFS servers enforce POSIX ACLs on local files whether
1719 this protocol is available or not.
1720
1721 This option enables support in your system's NFS server for the
1722 NFSv3 ACL protocol extension allowing NFS clients to manipulate
1723 POSIX ACLs on files exported by your system's NFS server. NFS
1724 clients which support the Solaris NFSv3 ACL protocol can then
1725 access and modify ACLs on your NFS server.
1726
1727 To store ACLs on your NFS server, you also need to enable ACL-
1728 related CONFIG options for your local file systems of choice.
1729
1730 If unsure, say N.
1747 1731
1748config NFSD_V4 1732config NFSD_V4
1749 bool "Provide NFSv4 server support (EXPERIMENTAL)" 1733 bool "NFS server support for NFS version 4 (EXPERIMENTAL)"
1750 depends on NFSD && NFSD_V3 && EXPERIMENTAL 1734 depends on NFSD && PROC_FS && EXPERIMENTAL
1735 select NFSD_V3
1736 select FS_POSIX_ACL
1751 select RPCSEC_GSS_KRB5 1737 select RPCSEC_GSS_KRB5
1752 help 1738 help
1753 If you would like to include the NFSv4 server as well as the NFSv2 1739 This option enables support in your system's NFS server for
1754 and NFSv3 servers, say Y here. This feature is experimental, and 1740 version 4 of the NFS protocol (RFC 3530).
1755 should only be used if you are interested in helping to test NFSv4.
1756 If unsure, say N.
1757 1741
1758config NFSD_TCP 1742 To export files using NFSv4, you need to install additional user
1759 bool "Provide NFS server over TCP support" 1743 space programs which can be found in the Linux nfs-utils package,
1760 depends on NFSD 1744 available from http://linux-nfs.org/.
1761 default y 1745
1762 help 1746 If unsure, say N.
1763 If you want your NFS server to support TCP connections, say Y here.
1764 TCP connections usually perform better than the default UDP when
1765 the network is lossy or congested. If unsure, say Y.
1766 1747
1767config ROOT_NFS 1748config ROOT_NFS
1768 bool "Root file system on NFS" 1749 bool "Root file system on NFS"
@@ -1808,15 +1789,33 @@ config SUNRPC_XPRT_RDMA
1808 tristate 1789 tristate
1809 depends on SUNRPC && INFINIBAND && EXPERIMENTAL 1790 depends on SUNRPC && INFINIBAND && EXPERIMENTAL
1810 default SUNRPC && INFINIBAND 1791 default SUNRPC && INFINIBAND
1792 help
1793 This option enables an RPC client transport capability that
1794 allows the NFS client to mount servers via an RDMA-enabled
1795 transport.
1796
1797 To compile RPC client RDMA transport support as a module,
1798 choose M here: the module will be called xprtrdma.
1799
1800 If unsure, say N.
1811 1801
1812config SUNRPC_BIND34 1802config SUNRPC_BIND34
1813 bool "Support for rpcbind versions 3 & 4 (EXPERIMENTAL)" 1803 bool "Support for rpcbind versions 3 & 4 (EXPERIMENTAL)"
1814 depends on SUNRPC && EXPERIMENTAL 1804 depends on SUNRPC && EXPERIMENTAL
1805 default n
1815 help 1806 help
1816 Provides kernel support for querying rpcbind servers via versions 3 1807 RPC requests over IPv6 networks require support for larger
1817 and 4 of the rpcbind protocol. The kernel automatically falls back 1808 addresses when performing an RPC bind. Sun added support for
1818 to version 2 if a remote rpcbind service does not support versions 1809 IPv6 addressing by creating two new versions of the rpcbind
1819 3 or 4. 1810 protocol (RFC 1833).
1811
1812 This option enables support in the kernel RPC client for
1813 querying rpcbind servers via versions 3 and 4 of the rpcbind
1814 protocol. The kernel automatically falls back to version 2
1815 if a remote rpcbind service does not support versions 3 or 4.
1816 By themselves, these new versions do not provide support for
1817 RPC over IPv6, but the new protocol versions are necessary to
1818 support it.
1820 1819
1821 If unsure, say N to get traditional behavior (version 2 rpcbind 1820 If unsure, say N to get traditional behavior (version 2 rpcbind
1822 requests only). 1821 requests only).
@@ -1830,12 +1829,13 @@ config RPCSEC_GSS_KRB5
1830 select CRYPTO_DES 1829 select CRYPTO_DES
1831 select CRYPTO_CBC 1830 select CRYPTO_CBC
1832 help 1831 help
1833 Provides for secure RPC calls by means of a gss-api 1832 Choose Y here to enable Secure RPC using the Kerberos version 5
1834 mechanism based on Kerberos V5. This is required for 1833 GSS-API mechanism (RFC 1964).
1835 NFSv4.
1836 1834
1837 Note: Requires an auxiliary userspace daemon which may be found on 1835 Secure RPC calls with Kerberos require an auxiliary user-space
1838 http://www.citi.umich.edu/projects/nfsv4/ 1836 daemon which may be found in the Linux nfs-utils package
1837 available from http://linux-nfs.org/. In addition, user-space
1838 Kerberos support should be installed.
1839 1839
1840 If unsure, say N. 1840 If unsure, say N.
1841 1841
@@ -1849,11 +1849,12 @@ config RPCSEC_GSS_SPKM3
1849 select CRYPTO_CAST5 1849 select CRYPTO_CAST5
1850 select CRYPTO_CBC 1850 select CRYPTO_CBC
1851 help 1851 help
1852 Provides for secure RPC calls by means of a gss-api 1852 Choose Y here to enable Secure RPC using the SPKM3 public key
1853 mechanism based on the SPKM3 public-key mechanism. 1853 GSS-API mechansim (RFC 2025).
1854 1854
1855 Note: Requires an auxiliary userspace daemon which may be found on 1855 Secure RPC calls with SPKM3 require an auxiliary userspace
1856 http://www.citi.umich.edu/projects/nfsv4/ 1856 daemon which may be found in the Linux nfs-utils package
1857 available from http://linux-nfs.org/.
1857 1858
1858 If unsure, say N. 1859 If unsure, say N.
1859 1860
diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
index b6b74a60e1eb..40b16f23e49a 100644
--- a/fs/lockd/clntproc.c
+++ b/fs/lockd/clntproc.c
@@ -155,8 +155,6 @@ static void nlmclnt_release_lockargs(struct nlm_rqst *req)
155int nlmclnt_proc(struct nlm_host *host, int cmd, struct file_lock *fl) 155int nlmclnt_proc(struct nlm_host *host, int cmd, struct file_lock *fl)
156{ 156{
157 struct nlm_rqst *call; 157 struct nlm_rqst *call;
158 sigset_t oldset;
159 unsigned long flags;
160 int status; 158 int status;
161 159
162 nlm_get_host(host); 160 nlm_get_host(host);
@@ -168,22 +166,6 @@ int nlmclnt_proc(struct nlm_host *host, int cmd, struct file_lock *fl)
168 /* Set up the argument struct */ 166 /* Set up the argument struct */
169 nlmclnt_setlockargs(call, fl); 167 nlmclnt_setlockargs(call, fl);
170 168
171 /* Keep the old signal mask */
172 spin_lock_irqsave(&current->sighand->siglock, flags);
173 oldset = current->blocked;
174
175 /* If we're cleaning up locks because the process is exiting,
176 * perform the RPC call asynchronously. */
177 if ((IS_SETLK(cmd) || IS_SETLKW(cmd))
178 && fl->fl_type == F_UNLCK
179 && (current->flags & PF_EXITING)) {
180 sigfillset(&current->blocked); /* Mask all signals */
181 recalc_sigpending();
182
183 call->a_flags = RPC_TASK_ASYNC;
184 }
185 spin_unlock_irqrestore(&current->sighand->siglock, flags);
186
187 if (IS_SETLK(cmd) || IS_SETLKW(cmd)) { 169 if (IS_SETLK(cmd) || IS_SETLKW(cmd)) {
188 if (fl->fl_type != F_UNLCK) { 170 if (fl->fl_type != F_UNLCK) {
189 call->a_args.block = IS_SETLKW(cmd) ? 1 : 0; 171 call->a_args.block = IS_SETLKW(cmd) ? 1 : 0;
@@ -198,11 +180,6 @@ int nlmclnt_proc(struct nlm_host *host, int cmd, struct file_lock *fl)
198 fl->fl_ops->fl_release_private(fl); 180 fl->fl_ops->fl_release_private(fl);
199 fl->fl_ops = NULL; 181 fl->fl_ops = NULL;
200 182
201 spin_lock_irqsave(&current->sighand->siglock, flags);
202 current->blocked = oldset;
203 recalc_sigpending();
204 spin_unlock_irqrestore(&current->sighand->siglock, flags);
205
206 dprintk("lockd: clnt proc returns %d\n", status); 183 dprintk("lockd: clnt proc returns %d\n", status);
207 return status; 184 return status;
208} 185}
@@ -221,6 +198,7 @@ struct nlm_rqst *nlm_alloc_call(struct nlm_host *host)
221 for(;;) { 198 for(;;) {
222 call = kzalloc(sizeof(*call), GFP_KERNEL); 199 call = kzalloc(sizeof(*call), GFP_KERNEL);
223 if (call != NULL) { 200 if (call != NULL) {
201 atomic_set(&call->a_count, 1);
224 locks_init_lock(&call->a_args.lock.fl); 202 locks_init_lock(&call->a_args.lock.fl);
225 locks_init_lock(&call->a_res.lock.fl); 203 locks_init_lock(&call->a_res.lock.fl);
226 call->a_host = host; 204 call->a_host = host;
@@ -237,6 +215,8 @@ struct nlm_rqst *nlm_alloc_call(struct nlm_host *host)
237 215
238void nlm_release_call(struct nlm_rqst *call) 216void nlm_release_call(struct nlm_rqst *call)
239{ 217{
218 if (!atomic_dec_and_test(&call->a_count))
219 return;
240 nlm_release_host(call->a_host); 220 nlm_release_host(call->a_host);
241 nlmclnt_release_lockargs(call); 221 nlmclnt_release_lockargs(call);
242 kfree(call); 222 kfree(call);
@@ -267,7 +247,7 @@ static int nlm_wait_on_grace(wait_queue_head_t *queue)
267 * Generic NLM call 247 * Generic NLM call
268 */ 248 */
269static int 249static int
270nlmclnt_call(struct nlm_rqst *req, u32 proc) 250nlmclnt_call(struct rpc_cred *cred, struct nlm_rqst *req, u32 proc)
271{ 251{
272 struct nlm_host *host = req->a_host; 252 struct nlm_host *host = req->a_host;
273 struct rpc_clnt *clnt; 253 struct rpc_clnt *clnt;
@@ -276,6 +256,7 @@ nlmclnt_call(struct nlm_rqst *req, u32 proc)
276 struct rpc_message msg = { 256 struct rpc_message msg = {
277 .rpc_argp = argp, 257 .rpc_argp = argp,
278 .rpc_resp = resp, 258 .rpc_resp = resp,
259 .rpc_cred = cred,
279 }; 260 };
280 int status; 261 int status;
281 262
@@ -343,10 +324,16 @@ in_grace_period:
343/* 324/*
344 * Generic NLM call, async version. 325 * Generic NLM call, async version.
345 */ 326 */
346static int __nlm_async_call(struct nlm_rqst *req, u32 proc, struct rpc_message *msg, const struct rpc_call_ops *tk_ops) 327static struct rpc_task *__nlm_async_call(struct nlm_rqst *req, u32 proc, struct rpc_message *msg, const struct rpc_call_ops *tk_ops)
347{ 328{
348 struct nlm_host *host = req->a_host; 329 struct nlm_host *host = req->a_host;
349 struct rpc_clnt *clnt; 330 struct rpc_clnt *clnt;
331 struct rpc_task_setup task_setup_data = {
332 .rpc_message = msg,
333 .callback_ops = tk_ops,
334 .callback_data = req,
335 .flags = RPC_TASK_ASYNC,
336 };
350 337
351 dprintk("lockd: call procedure %d on %s (async)\n", 338 dprintk("lockd: call procedure %d on %s (async)\n",
352 (int)proc, host->h_name); 339 (int)proc, host->h_name);
@@ -356,21 +343,36 @@ static int __nlm_async_call(struct nlm_rqst *req, u32 proc, struct rpc_message *
356 if (clnt == NULL) 343 if (clnt == NULL)
357 goto out_err; 344 goto out_err;
358 msg->rpc_proc = &clnt->cl_procinfo[proc]; 345 msg->rpc_proc = &clnt->cl_procinfo[proc];
346 task_setup_data.rpc_client = clnt;
359 347
360 /* bootstrap and kick off the async RPC call */ 348 /* bootstrap and kick off the async RPC call */
361 return rpc_call_async(clnt, msg, RPC_TASK_ASYNC, tk_ops, req); 349 return rpc_run_task(&task_setup_data);
362out_err: 350out_err:
363 tk_ops->rpc_release(req); 351 tk_ops->rpc_release(req);
364 return -ENOLCK; 352 return ERR_PTR(-ENOLCK);
365} 353}
366 354
355static int nlm_do_async_call(struct nlm_rqst *req, u32 proc, struct rpc_message *msg, const struct rpc_call_ops *tk_ops)
356{
357 struct rpc_task *task;
358
359 task = __nlm_async_call(req, proc, msg, tk_ops);
360 if (IS_ERR(task))
361 return PTR_ERR(task);
362 rpc_put_task(task);
363 return 0;
364}
365
366/*
367 * NLM asynchronous call.
368 */
367int nlm_async_call(struct nlm_rqst *req, u32 proc, const struct rpc_call_ops *tk_ops) 369int nlm_async_call(struct nlm_rqst *req, u32 proc, const struct rpc_call_ops *tk_ops)
368{ 370{
369 struct rpc_message msg = { 371 struct rpc_message msg = {
370 .rpc_argp = &req->a_args, 372 .rpc_argp = &req->a_args,
371 .rpc_resp = &req->a_res, 373 .rpc_resp = &req->a_res,
372 }; 374 };
373 return __nlm_async_call(req, proc, &msg, tk_ops); 375 return nlm_do_async_call(req, proc, &msg, tk_ops);
374} 376}
375 377
376int nlm_async_reply(struct nlm_rqst *req, u32 proc, const struct rpc_call_ops *tk_ops) 378int nlm_async_reply(struct nlm_rqst *req, u32 proc, const struct rpc_call_ops *tk_ops)
@@ -378,7 +380,33 @@ int nlm_async_reply(struct nlm_rqst *req, u32 proc, const struct rpc_call_ops *t
378 struct rpc_message msg = { 380 struct rpc_message msg = {
379 .rpc_argp = &req->a_res, 381 .rpc_argp = &req->a_res,
380 }; 382 };
381 return __nlm_async_call(req, proc, &msg, tk_ops); 383 return nlm_do_async_call(req, proc, &msg, tk_ops);
384}
385
386/*
387 * NLM client asynchronous call.
388 *
389 * Note that although the calls are asynchronous, and are therefore
390 * guaranteed to complete, we still always attempt to wait for
391 * completion in order to be able to correctly track the lock
392 * state.
393 */
394static int nlmclnt_async_call(struct rpc_cred *cred, struct nlm_rqst *req, u32 proc, const struct rpc_call_ops *tk_ops)
395{
396 struct rpc_message msg = {
397 .rpc_argp = &req->a_args,
398 .rpc_resp = &req->a_res,
399 .rpc_cred = cred,
400 };
401 struct rpc_task *task;
402 int err;
403
404 task = __nlm_async_call(req, proc, &msg, tk_ops);
405 if (IS_ERR(task))
406 return PTR_ERR(task);
407 err = rpc_wait_for_completion_task(task);
408 rpc_put_task(task);
409 return err;
382} 410}
383 411
384/* 412/*
@@ -389,7 +417,7 @@ nlmclnt_test(struct nlm_rqst *req, struct file_lock *fl)
389{ 417{
390 int status; 418 int status;
391 419
392 status = nlmclnt_call(req, NLMPROC_TEST); 420 status = nlmclnt_call(nfs_file_cred(fl->fl_file), req, NLMPROC_TEST);
393 if (status < 0) 421 if (status < 0)
394 goto out; 422 goto out;
395 423
@@ -480,10 +508,12 @@ static int do_vfs_lock(struct file_lock *fl)
480static int 508static int
481nlmclnt_lock(struct nlm_rqst *req, struct file_lock *fl) 509nlmclnt_lock(struct nlm_rqst *req, struct file_lock *fl)
482{ 510{
511 struct rpc_cred *cred = nfs_file_cred(fl->fl_file);
483 struct nlm_host *host = req->a_host; 512 struct nlm_host *host = req->a_host;
484 struct nlm_res *resp = &req->a_res; 513 struct nlm_res *resp = &req->a_res;
485 struct nlm_wait *block = NULL; 514 struct nlm_wait *block = NULL;
486 unsigned char fl_flags = fl->fl_flags; 515 unsigned char fl_flags = fl->fl_flags;
516 unsigned char fl_type;
487 int status = -ENOLCK; 517 int status = -ENOLCK;
488 518
489 if (nsm_monitor(host) < 0) { 519 if (nsm_monitor(host) < 0) {
@@ -493,18 +523,22 @@ nlmclnt_lock(struct nlm_rqst *req, struct file_lock *fl)
493 } 523 }
494 fl->fl_flags |= FL_ACCESS; 524 fl->fl_flags |= FL_ACCESS;
495 status = do_vfs_lock(fl); 525 status = do_vfs_lock(fl);
526 fl->fl_flags = fl_flags;
496 if (status < 0) 527 if (status < 0)
497 goto out; 528 goto out;
498 529
499 block = nlmclnt_prepare_block(host, fl); 530 block = nlmclnt_prepare_block(host, fl);
500again: 531again:
532 /*
533 * Initialise resp->status to a valid non-zero value,
534 * since 0 == nlm_lck_granted
535 */
536 resp->status = nlm_lck_blocked;
501 for(;;) { 537 for(;;) {
502 /* Reboot protection */ 538 /* Reboot protection */
503 fl->fl_u.nfs_fl.state = host->h_state; 539 fl->fl_u.nfs_fl.state = host->h_state;
504 status = nlmclnt_call(req, NLMPROC_LOCK); 540 status = nlmclnt_call(cred, req, NLMPROC_LOCK);
505 if (status < 0) 541 if (status < 0)
506 goto out_unblock;
507 if (!req->a_args.block)
508 break; 542 break;
509 /* Did a reclaimer thread notify us of a server reboot? */ 543 /* Did a reclaimer thread notify us of a server reboot? */
510 if (resp->status == nlm_lck_denied_grace_period) 544 if (resp->status == nlm_lck_denied_grace_period)
@@ -513,15 +547,22 @@ again:
513 break; 547 break;
514 /* Wait on an NLM blocking lock */ 548 /* Wait on an NLM blocking lock */
515 status = nlmclnt_block(block, req, NLMCLNT_POLL_TIMEOUT); 549 status = nlmclnt_block(block, req, NLMCLNT_POLL_TIMEOUT);
516 /* if we were interrupted. Send a CANCEL request to the server
517 * and exit
518 */
519 if (status < 0) 550 if (status < 0)
520 goto out_unblock; 551 break;
521 if (resp->status != nlm_lck_blocked) 552 if (resp->status != nlm_lck_blocked)
522 break; 553 break;
523 } 554 }
524 555
556 /* if we were interrupted while blocking, then cancel the lock request
557 * and exit
558 */
559 if (resp->status == nlm_lck_blocked) {
560 if (!req->a_args.block)
561 goto out_unlock;
562 if (nlmclnt_cancel(host, req->a_args.block, fl) == 0)
563 goto out_unblock;
564 }
565
525 if (resp->status == nlm_granted) { 566 if (resp->status == nlm_granted) {
526 down_read(&host->h_rwsem); 567 down_read(&host->h_rwsem);
527 /* Check whether or not the server has rebooted */ 568 /* Check whether or not the server has rebooted */
@@ -530,20 +571,34 @@ again:
530 goto again; 571 goto again;
531 } 572 }
532 /* Ensure the resulting lock will get added to granted list */ 573 /* Ensure the resulting lock will get added to granted list */
533 fl->fl_flags = fl_flags | FL_SLEEP; 574 fl->fl_flags |= FL_SLEEP;
534 if (do_vfs_lock(fl) < 0) 575 if (do_vfs_lock(fl) < 0)
535 printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __FUNCTION__); 576 printk(KERN_WARNING "%s: VFS is out of sync with lock manager!\n", __FUNCTION__);
536 up_read(&host->h_rwsem); 577 up_read(&host->h_rwsem);
578 fl->fl_flags = fl_flags;
579 status = 0;
537 } 580 }
581 if (status < 0)
582 goto out_unlock;
538 status = nlm_stat_to_errno(resp->status); 583 status = nlm_stat_to_errno(resp->status);
539out_unblock: 584out_unblock:
540 nlmclnt_finish_block(block); 585 nlmclnt_finish_block(block);
541 /* Cancel the blocked request if it is still pending */
542 if (resp->status == nlm_lck_blocked)
543 nlmclnt_cancel(host, req->a_args.block, fl);
544out: 586out:
545 nlm_release_call(req); 587 nlm_release_call(req);
588 return status;
589out_unlock:
590 /* Fatal error: ensure that we remove the lock altogether */
591 dprintk("lockd: lock attempt ended in fatal error.\n"
592 " Attempting to unlock.\n");
593 nlmclnt_finish_block(block);
594 fl_type = fl->fl_type;
595 fl->fl_type = F_UNLCK;
596 down_read(&host->h_rwsem);
597 do_vfs_lock(fl);
598 up_read(&host->h_rwsem);
599 fl->fl_type = fl_type;
546 fl->fl_flags = fl_flags; 600 fl->fl_flags = fl_flags;
601 nlmclnt_async_call(cred, req, NLMPROC_UNLOCK, &nlmclnt_unlock_ops);
547 return status; 602 return status;
548} 603}
549 604
@@ -567,8 +622,8 @@ nlmclnt_reclaim(struct nlm_host *host, struct file_lock *fl)
567 nlmclnt_setlockargs(req, fl); 622 nlmclnt_setlockargs(req, fl);
568 req->a_args.reclaim = 1; 623 req->a_args.reclaim = 1;
569 624
570 if ((status = nlmclnt_call(req, NLMPROC_LOCK)) >= 0 625 status = nlmclnt_call(nfs_file_cred(fl->fl_file), req, NLMPROC_LOCK);
571 && req->a_res.status == nlm_granted) 626 if (status >= 0 && req->a_res.status == nlm_granted)
572 return 0; 627 return 0;
573 628
574 printk(KERN_WARNING "lockd: failed to reclaim lock for pid %d " 629 printk(KERN_WARNING "lockd: failed to reclaim lock for pid %d "
@@ -598,7 +653,8 @@ nlmclnt_unlock(struct nlm_rqst *req, struct file_lock *fl)
598{ 653{
599 struct nlm_host *host = req->a_host; 654 struct nlm_host *host = req->a_host;
600 struct nlm_res *resp = &req->a_res; 655 struct nlm_res *resp = &req->a_res;
601 int status = 0; 656 int status;
657 unsigned char fl_flags = fl->fl_flags;
602 658
603 /* 659 /*
604 * Note: the server is supposed to either grant us the unlock 660 * Note: the server is supposed to either grant us the unlock
@@ -607,16 +663,17 @@ nlmclnt_unlock(struct nlm_rqst *req, struct file_lock *fl)
607 */ 663 */
608 fl->fl_flags |= FL_EXISTS; 664 fl->fl_flags |= FL_EXISTS;
609 down_read(&host->h_rwsem); 665 down_read(&host->h_rwsem);
610 if (do_vfs_lock(fl) == -ENOENT) { 666 status = do_vfs_lock(fl);
611 up_read(&host->h_rwsem); 667 up_read(&host->h_rwsem);
668 fl->fl_flags = fl_flags;
669 if (status == -ENOENT) {
670 status = 0;
612 goto out; 671 goto out;
613 } 672 }
614 up_read(&host->h_rwsem);
615
616 if (req->a_flags & RPC_TASK_ASYNC)
617 return nlm_async_call(req, NLMPROC_UNLOCK, &nlmclnt_unlock_ops);
618 673
619 status = nlmclnt_call(req, NLMPROC_UNLOCK); 674 atomic_inc(&req->a_count);
675 status = nlmclnt_async_call(nfs_file_cred(fl->fl_file), req,
676 NLMPROC_UNLOCK, &nlmclnt_unlock_ops);
620 if (status < 0) 677 if (status < 0)
621 goto out; 678 goto out;
622 679
@@ -671,16 +728,10 @@ static const struct rpc_call_ops nlmclnt_unlock_ops = {
671static int nlmclnt_cancel(struct nlm_host *host, int block, struct file_lock *fl) 728static int nlmclnt_cancel(struct nlm_host *host, int block, struct file_lock *fl)
672{ 729{
673 struct nlm_rqst *req; 730 struct nlm_rqst *req;
674 unsigned long flags; 731 int status;
675 sigset_t oldset;
676 int status;
677 732
678 /* Block all signals while setting up call */ 733 dprintk("lockd: blocking lock attempt was interrupted by a signal.\n"
679 spin_lock_irqsave(&current->sighand->siglock, flags); 734 " Attempting to cancel lock.\n");
680 oldset = current->blocked;
681 sigfillset(&current->blocked);
682 recalc_sigpending();
683 spin_unlock_irqrestore(&current->sighand->siglock, flags);
684 735
685 req = nlm_alloc_call(nlm_get_host(host)); 736 req = nlm_alloc_call(nlm_get_host(host));
686 if (!req) 737 if (!req)
@@ -690,13 +741,12 @@ static int nlmclnt_cancel(struct nlm_host *host, int block, struct file_lock *fl
690 nlmclnt_setlockargs(req, fl); 741 nlmclnt_setlockargs(req, fl);
691 req->a_args.block = block; 742 req->a_args.block = block;
692 743
693 status = nlm_async_call(req, NLMPROC_CANCEL, &nlmclnt_cancel_ops); 744 atomic_inc(&req->a_count);
694 745 status = nlmclnt_async_call(nfs_file_cred(fl->fl_file), req,
695 spin_lock_irqsave(&current->sighand->siglock, flags); 746 NLMPROC_CANCEL, &nlmclnt_cancel_ops);
696 current->blocked = oldset; 747 if (status == 0 && req->a_res.status == nlm_lck_denied)
697 recalc_sigpending(); 748 status = -ENOLCK;
698 spin_unlock_irqrestore(&current->sighand->siglock, flags); 749 nlm_release_call(req);
699
700 return status; 750 return status;
701} 751}
702 752
diff --git a/fs/lockd/host.c b/fs/lockd/host.c
index f1ef49fff118..a17664c7eacc 100644
--- a/fs/lockd/host.c
+++ b/fs/lockd/host.c
@@ -19,12 +19,11 @@
19 19
20 20
21#define NLMDBG_FACILITY NLMDBG_HOSTCACHE 21#define NLMDBG_FACILITY NLMDBG_HOSTCACHE
22#define NLM_HOST_MAX 64
23#define NLM_HOST_NRHASH 32 22#define NLM_HOST_NRHASH 32
24#define NLM_ADDRHASH(addr) (ntohl(addr) & (NLM_HOST_NRHASH-1)) 23#define NLM_ADDRHASH(addr) (ntohl(addr) & (NLM_HOST_NRHASH-1))
25#define NLM_HOST_REBIND (60 * HZ) 24#define NLM_HOST_REBIND (60 * HZ)
26#define NLM_HOST_EXPIRE ((nrhosts > NLM_HOST_MAX)? 300 * HZ : 120 * HZ) 25#define NLM_HOST_EXPIRE (300 * HZ)
27#define NLM_HOST_COLLECT ((nrhosts > NLM_HOST_MAX)? 120 * HZ : 60 * HZ) 26#define NLM_HOST_COLLECT (120 * HZ)
28 27
29static struct hlist_head nlm_hosts[NLM_HOST_NRHASH]; 28static struct hlist_head nlm_hosts[NLM_HOST_NRHASH];
30static unsigned long next_gc; 29static unsigned long next_gc;
@@ -42,11 +41,12 @@ static struct nsm_handle * nsm_find(const struct sockaddr_in *sin,
42/* 41/*
43 * Common host lookup routine for server & client 42 * Common host lookup routine for server & client
44 */ 43 */
45static struct nlm_host * 44static struct nlm_host *nlm_lookup_host(int server,
46nlm_lookup_host(int server, const struct sockaddr_in *sin, 45 const struct sockaddr_in *sin,
47 int proto, int version, const char *hostname, 46 int proto, u32 version,
48 unsigned int hostname_len, 47 const char *hostname,
49 const struct sockaddr_in *ssin) 48 unsigned int hostname_len,
49 const struct sockaddr_in *ssin)
50{ 50{
51 struct hlist_head *chain; 51 struct hlist_head *chain;
52 struct hlist_node *pos; 52 struct hlist_node *pos;
@@ -55,7 +55,7 @@ nlm_lookup_host(int server, const struct sockaddr_in *sin,
55 int hash; 55 int hash;
56 56
57 dprintk("lockd: nlm_lookup_host("NIPQUAD_FMT"->"NIPQUAD_FMT 57 dprintk("lockd: nlm_lookup_host("NIPQUAD_FMT"->"NIPQUAD_FMT
58 ", p=%d, v=%d, my role=%s, name=%.*s)\n", 58 ", p=%d, v=%u, my role=%s, name=%.*s)\n",
59 NIPQUAD(ssin->sin_addr.s_addr), 59 NIPQUAD(ssin->sin_addr.s_addr),
60 NIPQUAD(sin->sin_addr.s_addr), proto, version, 60 NIPQUAD(sin->sin_addr.s_addr), proto, version,
61 server? "server" : "client", 61 server? "server" : "client",
@@ -142,9 +142,7 @@ nlm_lookup_host(int server, const struct sockaddr_in *sin,
142 INIT_LIST_HEAD(&host->h_granted); 142 INIT_LIST_HEAD(&host->h_granted);
143 INIT_LIST_HEAD(&host->h_reclaim); 143 INIT_LIST_HEAD(&host->h_reclaim);
144 144
145 if (++nrhosts > NLM_HOST_MAX) 145 nrhosts++;
146 next_gc = 0;
147
148out: 146out:
149 mutex_unlock(&nlm_host_mutex); 147 mutex_unlock(&nlm_host_mutex);
150 return host; 148 return host;
@@ -175,9 +173,10 @@ nlm_destroy_host(struct nlm_host *host)
175/* 173/*
176 * Find an NLM server handle in the cache. If there is none, create it. 174 * Find an NLM server handle in the cache. If there is none, create it.
177 */ 175 */
178struct nlm_host * 176struct nlm_host *nlmclnt_lookup_host(const struct sockaddr_in *sin,
179nlmclnt_lookup_host(const struct sockaddr_in *sin, int proto, int version, 177 int proto, u32 version,
180 const char *hostname, unsigned int hostname_len) 178 const char *hostname,
179 unsigned int hostname_len)
181{ 180{
182 struct sockaddr_in ssin = {0}; 181 struct sockaddr_in ssin = {0};
183 182
@@ -460,7 +459,7 @@ nlm_gc_hosts(void)
460 * Manage NSM handles 459 * Manage NSM handles
461 */ 460 */
462static LIST_HEAD(nsm_handles); 461static LIST_HEAD(nsm_handles);
463static DEFINE_MUTEX(nsm_mutex); 462static DEFINE_SPINLOCK(nsm_lock);
464 463
465static struct nsm_handle * 464static struct nsm_handle *
466__nsm_find(const struct sockaddr_in *sin, 465__nsm_find(const struct sockaddr_in *sin,
@@ -468,7 +467,7 @@ __nsm_find(const struct sockaddr_in *sin,
468 int create) 467 int create)
469{ 468{
470 struct nsm_handle *nsm = NULL; 469 struct nsm_handle *nsm = NULL;
471 struct list_head *pos; 470 struct nsm_handle *pos;
472 471
473 if (!sin) 472 if (!sin)
474 return NULL; 473 return NULL;
@@ -482,38 +481,43 @@ __nsm_find(const struct sockaddr_in *sin,
482 return NULL; 481 return NULL;
483 } 482 }
484 483
485 mutex_lock(&nsm_mutex); 484retry:
486 list_for_each(pos, &nsm_handles) { 485 spin_lock(&nsm_lock);
487 nsm = list_entry(pos, struct nsm_handle, sm_link); 486 list_for_each_entry(pos, &nsm_handles, sm_link) {
488 487
489 if (hostname && nsm_use_hostnames) { 488 if (hostname && nsm_use_hostnames) {
490 if (strlen(nsm->sm_name) != hostname_len 489 if (strlen(pos->sm_name) != hostname_len
491 || memcmp(nsm->sm_name, hostname, hostname_len)) 490 || memcmp(pos->sm_name, hostname, hostname_len))
492 continue; 491 continue;
493 } else if (!nlm_cmp_addr(&nsm->sm_addr, sin)) 492 } else if (!nlm_cmp_addr(&pos->sm_addr, sin))
494 continue; 493 continue;
495 atomic_inc(&nsm->sm_count); 494 atomic_inc(&pos->sm_count);
496 goto out; 495 kfree(nsm);
496 nsm = pos;
497 goto found;
497 } 498 }
498 499 if (nsm) {
499 if (!create) { 500 list_add(&nsm->sm_link, &nsm_handles);
500 nsm = NULL; 501 goto found;
501 goto out;
502 } 502 }
503 spin_unlock(&nsm_lock);
504
505 if (!create)
506 return NULL;
503 507
504 nsm = kzalloc(sizeof(*nsm) + hostname_len + 1, GFP_KERNEL); 508 nsm = kzalloc(sizeof(*nsm) + hostname_len + 1, GFP_KERNEL);
505 if (nsm != NULL) { 509 if (nsm == NULL)
506 nsm->sm_addr = *sin; 510 return NULL;
507 nsm->sm_name = (char *) (nsm + 1);
508 memcpy(nsm->sm_name, hostname, hostname_len);
509 nsm->sm_name[hostname_len] = '\0';
510 atomic_set(&nsm->sm_count, 1);
511 511
512 list_add(&nsm->sm_link, &nsm_handles); 512 nsm->sm_addr = *sin;
513 } 513 nsm->sm_name = (char *) (nsm + 1);
514 memcpy(nsm->sm_name, hostname, hostname_len);
515 nsm->sm_name[hostname_len] = '\0';
516 atomic_set(&nsm->sm_count, 1);
517 goto retry;
514 518
515out: 519found:
516 mutex_unlock(&nsm_mutex); 520 spin_unlock(&nsm_lock);
517 return nsm; 521 return nsm;
518} 522}
519 523
@@ -532,12 +536,9 @@ nsm_release(struct nsm_handle *nsm)
532{ 536{
533 if (!nsm) 537 if (!nsm)
534 return; 538 return;
535 if (atomic_dec_and_test(&nsm->sm_count)) { 539 if (atomic_dec_and_lock(&nsm->sm_count, &nsm_lock)) {
536 mutex_lock(&nsm_mutex); 540 list_del(&nsm->sm_link);
537 if (atomic_read(&nsm->sm_count) == 0) { 541 spin_unlock(&nsm_lock);
538 list_del(&nsm->sm_link); 542 kfree(nsm);
539 kfree(nsm);
540 }
541 mutex_unlock(&nsm_mutex);
542 } 543 }
543} 544}
diff --git a/fs/lockd/mon.c b/fs/lockd/mon.c
index 908b23fadd05..e4d563543b11 100644
--- a/fs/lockd/mon.c
+++ b/fs/lockd/mon.c
@@ -18,6 +18,8 @@
18 18
19#define NLMDBG_FACILITY NLMDBG_MONITOR 19#define NLMDBG_FACILITY NLMDBG_MONITOR
20 20
21#define XDR_ADDRBUF_LEN (20)
22
21static struct rpc_clnt * nsm_create(void); 23static struct rpc_clnt * nsm_create(void);
22 24
23static struct rpc_program nsm_program; 25static struct rpc_program nsm_program;
@@ -147,28 +149,55 @@ nsm_create(void)
147 149
148/* 150/*
149 * XDR functions for NSM. 151 * XDR functions for NSM.
152 *
153 * See http://www.opengroup.org/ for details on the Network
154 * Status Monitor wire protocol.
150 */ 155 */
151 156
152static __be32 * 157static __be32 *xdr_encode_nsm_string(__be32 *p, char *string)
153xdr_encode_common(struct rpc_rqst *rqstp, __be32 *p, struct nsm_args *argp)
154{ 158{
155 char buffer[20], *name; 159 size_t len = strlen(string);
156 160
157 /* 161 if (len > SM_MAXSTRLEN)
158 * Use the dotted-quad IP address of the remote host as 162 len = SM_MAXSTRLEN;
159 * identifier. Linux statd always looks up the canonical 163 return xdr_encode_opaque(p, string, len);
160 * hostname first for whatever remote hostname it receives, 164}
161 * so this works alright. 165
162 */ 166/*
163 if (nsm_use_hostnames) { 167 * "mon_name" specifies the host to be monitored.
164 name = argp->mon_name; 168 *
165 } else { 169 * Linux uses a text version of the IP address of the remote
166 sprintf(buffer, "%u.%u.%u.%u", NIPQUAD(argp->addr)); 170 * host as the host identifier (the "mon_name" argument).
171 *
172 * Linux statd always looks up the canonical hostname first for
173 * whatever remote hostname it receives, so this works alright.
174 */
175static __be32 *xdr_encode_mon_name(__be32 *p, struct nsm_args *argp)
176{
177 char buffer[XDR_ADDRBUF_LEN + 1];
178 char *name = argp->mon_name;
179
180 if (!nsm_use_hostnames) {
181 snprintf(buffer, XDR_ADDRBUF_LEN,
182 NIPQUAD_FMT, NIPQUAD(argp->addr));
167 name = buffer; 183 name = buffer;
168 } 184 }
169 if (!(p = xdr_encode_string(p, name)) 185
170 || !(p = xdr_encode_string(p, utsname()->nodename))) 186 return xdr_encode_nsm_string(p, name);
187}
188
189/*
190 * The "my_id" argument specifies the hostname and RPC procedure
191 * to be called when the status manager receives notification
192 * (via the SM_NOTIFY call) that the state of host "mon_name"
193 * has changed.
194 */
195static __be32 *xdr_encode_my_id(__be32 *p, struct nsm_args *argp)
196{
197 p = xdr_encode_nsm_string(p, utsname()->nodename);
198 if (!p)
171 return ERR_PTR(-EIO); 199 return ERR_PTR(-EIO);
200
172 *p++ = htonl(argp->prog); 201 *p++ = htonl(argp->prog);
173 *p++ = htonl(argp->vers); 202 *p++ = htonl(argp->vers);
174 *p++ = htonl(argp->proc); 203 *p++ = htonl(argp->proc);
@@ -176,18 +205,48 @@ xdr_encode_common(struct rpc_rqst *rqstp, __be32 *p, struct nsm_args *argp)
176 return p; 205 return p;
177} 206}
178 207
179static int 208/*
180xdr_encode_mon(struct rpc_rqst *rqstp, __be32 *p, struct nsm_args *argp) 209 * The "mon_id" argument specifies the non-private arguments
210 * of an SM_MON or SM_UNMON call.
211 */
212static __be32 *xdr_encode_mon_id(__be32 *p, struct nsm_args *argp)
181{ 213{
182 p = xdr_encode_common(rqstp, p, argp); 214 p = xdr_encode_mon_name(p, argp);
183 if (IS_ERR(p)) 215 if (!p)
184 return PTR_ERR(p); 216 return ERR_PTR(-EIO);
185 217
186 /* Surprise - there may even be room for an IPv6 address now */ 218 return xdr_encode_my_id(p, argp);
219}
220
221/*
222 * The "priv" argument may contain private information required
223 * by the SM_MON call. This information will be supplied in the
224 * SM_NOTIFY call.
225 *
226 * Linux provides the raw IP address of the monitored host,
227 * left in network byte order.
228 */
229static __be32 *xdr_encode_priv(__be32 *p, struct nsm_args *argp)
230{
187 *p++ = argp->addr; 231 *p++ = argp->addr;
188 *p++ = 0; 232 *p++ = 0;
189 *p++ = 0; 233 *p++ = 0;
190 *p++ = 0; 234 *p++ = 0;
235
236 return p;
237}
238
239static int
240xdr_encode_mon(struct rpc_rqst *rqstp, __be32 *p, struct nsm_args *argp)
241{
242 p = xdr_encode_mon_id(p, argp);
243 if (IS_ERR(p))
244 return PTR_ERR(p);
245
246 p = xdr_encode_priv(p, argp);
247 if (IS_ERR(p))
248 return PTR_ERR(p);
249
191 rqstp->rq_slen = xdr_adjust_iovec(rqstp->rq_svec, p); 250 rqstp->rq_slen = xdr_adjust_iovec(rqstp->rq_svec, p);
192 return 0; 251 return 0;
193} 252}
@@ -195,7 +254,7 @@ xdr_encode_mon(struct rpc_rqst *rqstp, __be32 *p, struct nsm_args *argp)
195static int 254static int
196xdr_encode_unmon(struct rpc_rqst *rqstp, __be32 *p, struct nsm_args *argp) 255xdr_encode_unmon(struct rpc_rqst *rqstp, __be32 *p, struct nsm_args *argp)
197{ 256{
198 p = xdr_encode_common(rqstp, p, argp); 257 p = xdr_encode_mon_id(p, argp);
199 if (IS_ERR(p)) 258 if (IS_ERR(p))
200 return PTR_ERR(p); 259 return PTR_ERR(p);
201 rqstp->rq_slen = xdr_adjust_iovec(rqstp->rq_svec, p); 260 rqstp->rq_slen = xdr_adjust_iovec(rqstp->rq_svec, p);
@@ -220,9 +279,11 @@ xdr_decode_stat(struct rpc_rqst *rqstp, __be32 *p, struct nsm_res *resp)
220} 279}
221 280
222#define SM_my_name_sz (1+XDR_QUADLEN(SM_MAXSTRLEN)) 281#define SM_my_name_sz (1+XDR_QUADLEN(SM_MAXSTRLEN))
223#define SM_my_id_sz (3+1+SM_my_name_sz) 282#define SM_my_id_sz (SM_my_name_sz+3)
224#define SM_mon_id_sz (1+XDR_QUADLEN(20)+SM_my_id_sz) 283#define SM_mon_name_sz (1+XDR_QUADLEN(SM_MAXSTRLEN))
225#define SM_mon_sz (SM_mon_id_sz+4) 284#define SM_mon_id_sz (SM_mon_name_sz+SM_my_id_sz)
285#define SM_priv_sz (XDR_QUADLEN(SM_PRIV_SIZE))
286#define SM_mon_sz (SM_mon_id_sz+SM_priv_sz)
226#define SM_monres_sz 2 287#define SM_monres_sz 2
227#define SM_unmonres_sz 1 288#define SM_unmonres_sz 1
228 289
diff --git a/fs/lockd/svc.c b/fs/lockd/svc.c
index 1ed8bd4de941..2169af4d5455 100644
--- a/fs/lockd/svc.c
+++ b/fs/lockd/svc.c
@@ -25,6 +25,7 @@
25#include <linux/smp.h> 25#include <linux/smp.h>
26#include <linux/smp_lock.h> 26#include <linux/smp_lock.h>
27#include <linux/mutex.h> 27#include <linux/mutex.h>
28#include <linux/kthread.h>
28#include <linux/freezer.h> 29#include <linux/freezer.h>
29 30
30#include <linux/sunrpc/types.h> 31#include <linux/sunrpc/types.h>
@@ -48,14 +49,11 @@ EXPORT_SYMBOL(nlmsvc_ops);
48 49
49static DEFINE_MUTEX(nlmsvc_mutex); 50static DEFINE_MUTEX(nlmsvc_mutex);
50static unsigned int nlmsvc_users; 51static unsigned int nlmsvc_users;
51static pid_t nlmsvc_pid; 52static struct task_struct *nlmsvc_task;
52static struct svc_serv *nlmsvc_serv; 53static struct svc_serv *nlmsvc_serv;
53int nlmsvc_grace_period; 54int nlmsvc_grace_period;
54unsigned long nlmsvc_timeout; 55unsigned long nlmsvc_timeout;
55 56
56static DECLARE_COMPLETION(lockd_start_done);
57static DECLARE_WAIT_QUEUE_HEAD(lockd_exit);
58
59/* 57/*
60 * These can be set at insmod time (useful for NFS as root filesystem), 58 * These can be set at insmod time (useful for NFS as root filesystem),
61 * and also changed through the sysctl interface. -- Jamie Lokier, Aug 2003 59 * and also changed through the sysctl interface. -- Jamie Lokier, Aug 2003
@@ -74,7 +72,9 @@ static const unsigned long nlm_timeout_min = 3;
74static const unsigned long nlm_timeout_max = 20; 72static const unsigned long nlm_timeout_max = 20;
75static const int nlm_port_min = 0, nlm_port_max = 65535; 73static const int nlm_port_min = 0, nlm_port_max = 65535;
76 74
75#ifdef CONFIG_SYSCTL
77static struct ctl_table_header * nlm_sysctl_table; 76static struct ctl_table_header * nlm_sysctl_table;
77#endif
78 78
79static unsigned long get_lockd_grace_period(void) 79static unsigned long get_lockd_grace_period(void)
80{ 80{
@@ -111,35 +111,30 @@ static inline void clear_grace_period(void)
111/* 111/*
112 * This is the lockd kernel thread 112 * This is the lockd kernel thread
113 */ 113 */
114static void 114static int
115lockd(struct svc_rqst *rqstp) 115lockd(void *vrqstp)
116{ 116{
117 int err = 0; 117 int err = 0, preverr = 0;
118 struct svc_rqst *rqstp = vrqstp;
118 unsigned long grace_period_expire; 119 unsigned long grace_period_expire;
119 120
120 /* Lock module and set up kernel thread */ 121 /* try_to_freeze() is called from svc_recv() */
121 /* lockd_up is waiting for us to startup, so will
122 * be holding a reference to this module, so it
123 * is safe to just claim another reference
124 */
125 __module_get(THIS_MODULE);
126 lock_kernel();
127
128 /*
129 * Let our maker know we're running.
130 */
131 nlmsvc_pid = current->pid;
132 nlmsvc_serv = rqstp->rq_server;
133 complete(&lockd_start_done);
134
135 daemonize("lockd");
136 set_freezable(); 122 set_freezable();
137 123
138 /* Process request with signals blocked, but allow SIGKILL. */ 124 /* Allow SIGKILL to tell lockd to drop all of its locks */
139 allow_signal(SIGKILL); 125 allow_signal(SIGKILL);
140 126
141 dprintk("NFS locking service started (ver " LOCKD_VERSION ").\n"); 127 dprintk("NFS locking service started (ver " LOCKD_VERSION ").\n");
142 128
129 /*
130 * FIXME: it would be nice if lockd didn't spend its entire life
131 * running under the BKL. At the very least, it would be good to
132 * have someone clarify what it's intended to protect here. I've
133 * seen some handwavy posts about posix locking needing to be
134 * done under the BKL, but it's far from clear.
135 */
136 lock_kernel();
137
143 if (!nlm_timeout) 138 if (!nlm_timeout)
144 nlm_timeout = LOCKD_DFLT_TIMEO; 139 nlm_timeout = LOCKD_DFLT_TIMEO;
145 nlmsvc_timeout = nlm_timeout * HZ; 140 nlmsvc_timeout = nlm_timeout * HZ;
@@ -148,10 +143,9 @@ lockd(struct svc_rqst *rqstp)
148 143
149 /* 144 /*
150 * The main request loop. We don't terminate until the last 145 * The main request loop. We don't terminate until the last
151 * NFS mount or NFS daemon has gone away, and we've been sent a 146 * NFS mount or NFS daemon has gone away.
152 * signal, or else another process has taken over our job.
153 */ 147 */
154 while ((nlmsvc_users || !signalled()) && nlmsvc_pid == current->pid) { 148 while (!kthread_should_stop()) {
155 long timeout = MAX_SCHEDULE_TIMEOUT; 149 long timeout = MAX_SCHEDULE_TIMEOUT;
156 RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]); 150 RPC_IFDEBUG(char buf[RPC_MAX_ADDRBUFLEN]);
157 151
@@ -161,6 +155,7 @@ lockd(struct svc_rqst *rqstp)
161 nlmsvc_invalidate_all(); 155 nlmsvc_invalidate_all();
162 grace_period_expire = set_grace_period(); 156 grace_period_expire = set_grace_period();
163 } 157 }
158 continue;
164 } 159 }
165 160
166 /* 161 /*
@@ -179,14 +174,20 @@ lockd(struct svc_rqst *rqstp)
179 * recvfrom routine. 174 * recvfrom routine.
180 */ 175 */
181 err = svc_recv(rqstp, timeout); 176 err = svc_recv(rqstp, timeout);
182 if (err == -EAGAIN || err == -EINTR) 177 if (err == -EAGAIN || err == -EINTR) {
178 preverr = err;
183 continue; 179 continue;
180 }
184 if (err < 0) { 181 if (err < 0) {
185 printk(KERN_WARNING 182 if (err != preverr) {
186 "lockd: terminating on error %d\n", 183 printk(KERN_WARNING "%s: unexpected error "
187 -err); 184 "from svc_recv (%d)\n", __func__, err);
188 break; 185 preverr = err;
186 }
187 schedule_timeout_interruptible(HZ);
188 continue;
189 } 189 }
190 preverr = err;
190 191
191 dprintk("lockd: request from %s\n", 192 dprintk("lockd: request from %s\n",
192 svc_print_addr(rqstp, buf, sizeof(buf))); 193 svc_print_addr(rqstp, buf, sizeof(buf)));
@@ -195,28 +196,19 @@ lockd(struct svc_rqst *rqstp)
195 } 196 }
196 197
197 flush_signals(current); 198 flush_signals(current);
199 if (nlmsvc_ops)
200 nlmsvc_invalidate_all();
201 nlm_shutdown_hosts();
198 202
199 /* 203 unlock_kernel();
200 * Check whether there's a new lockd process before 204
201 * shutting down the hosts and clearing the slot. 205 nlmsvc_task = NULL;
202 */ 206 nlmsvc_serv = NULL;
203 if (!nlmsvc_pid || current->pid == nlmsvc_pid) {
204 if (nlmsvc_ops)
205 nlmsvc_invalidate_all();
206 nlm_shutdown_hosts();
207 nlmsvc_pid = 0;
208 nlmsvc_serv = NULL;
209 } else
210 printk(KERN_DEBUG
211 "lockd: new process, skipping host shutdown\n");
212 wake_up(&lockd_exit);
213 207
214 /* Exit the RPC thread */ 208 /* Exit the RPC thread */
215 svc_exit_thread(rqstp); 209 svc_exit_thread(rqstp);
216 210
217 /* Release module */ 211 return 0;
218 unlock_kernel();
219 module_put_and_exit(0);
220} 212}
221 213
222/* 214/*
@@ -261,14 +253,15 @@ static int make_socks(struct svc_serv *serv, int proto)
261int 253int
262lockd_up(int proto) /* Maybe add a 'family' option when IPv6 is supported ?? */ 254lockd_up(int proto) /* Maybe add a 'family' option when IPv6 is supported ?? */
263{ 255{
264 struct svc_serv * serv; 256 struct svc_serv *serv;
265 int error = 0; 257 struct svc_rqst *rqstp;
258 int error = 0;
266 259
267 mutex_lock(&nlmsvc_mutex); 260 mutex_lock(&nlmsvc_mutex);
268 /* 261 /*
269 * Check whether we're already up and running. 262 * Check whether we're already up and running.
270 */ 263 */
271 if (nlmsvc_pid) { 264 if (nlmsvc_serv) {
272 if (proto) 265 if (proto)
273 error = make_socks(nlmsvc_serv, proto); 266 error = make_socks(nlmsvc_serv, proto);
274 goto out; 267 goto out;
@@ -295,13 +288,28 @@ lockd_up(int proto) /* Maybe add a 'family' option when IPv6 is supported ?? */
295 /* 288 /*
296 * Create the kernel thread and wait for it to start. 289 * Create the kernel thread and wait for it to start.
297 */ 290 */
298 error = svc_create_thread(lockd, serv); 291 rqstp = svc_prepare_thread(serv, &serv->sv_pools[0]);
299 if (error) { 292 if (IS_ERR(rqstp)) {
293 error = PTR_ERR(rqstp);
294 printk(KERN_WARNING
295 "lockd_up: svc_rqst allocation failed, error=%d\n",
296 error);
297 goto destroy_and_out;
298 }
299
300 svc_sock_update_bufs(serv);
301 nlmsvc_serv = rqstp->rq_server;
302
303 nlmsvc_task = kthread_run(lockd, rqstp, serv->sv_name);
304 if (IS_ERR(nlmsvc_task)) {
305 error = PTR_ERR(nlmsvc_task);
306 nlmsvc_task = NULL;
307 nlmsvc_serv = NULL;
300 printk(KERN_WARNING 308 printk(KERN_WARNING
301 "lockd_up: create thread failed, error=%d\n", error); 309 "lockd_up: kthread_run failed, error=%d\n", error);
310 svc_exit_thread(rqstp);
302 goto destroy_and_out; 311 goto destroy_and_out;
303 } 312 }
304 wait_for_completion(&lockd_start_done);
305 313
306 /* 314 /*
307 * Note: svc_serv structures have an initial use count of 1, 315 * Note: svc_serv structures have an initial use count of 1,
@@ -323,42 +331,28 @@ EXPORT_SYMBOL(lockd_up);
323void 331void
324lockd_down(void) 332lockd_down(void)
325{ 333{
326 static int warned;
327
328 mutex_lock(&nlmsvc_mutex); 334 mutex_lock(&nlmsvc_mutex);
329 if (nlmsvc_users) { 335 if (nlmsvc_users) {
330 if (--nlmsvc_users) 336 if (--nlmsvc_users)
331 goto out; 337 goto out;
332 } else 338 } else {
333 printk(KERN_WARNING "lockd_down: no users! pid=%d\n", nlmsvc_pid); 339 printk(KERN_ERR "lockd_down: no users! task=%p\n",
334 340 nlmsvc_task);
335 if (!nlmsvc_pid) { 341 BUG();
336 if (warned++ == 0)
337 printk(KERN_WARNING "lockd_down: no lockd running.\n");
338 goto out;
339 } 342 }
340 warned = 0;
341 343
342 kill_proc(nlmsvc_pid, SIGKILL, 1); 344 if (!nlmsvc_task) {
343 /* 345 printk(KERN_ERR "lockd_down: no lockd running.\n");
344 * Wait for the lockd process to exit, but since we're holding 346 BUG();
345 * the lockd semaphore, we can't wait around forever ...
346 */
347 clear_thread_flag(TIF_SIGPENDING);
348 interruptible_sleep_on_timeout(&lockd_exit, HZ);
349 if (nlmsvc_pid) {
350 printk(KERN_WARNING
351 "lockd_down: lockd failed to exit, clearing pid\n");
352 nlmsvc_pid = 0;
353 } 347 }
354 spin_lock_irq(&current->sighand->siglock); 348 kthread_stop(nlmsvc_task);
355 recalc_sigpending();
356 spin_unlock_irq(&current->sighand->siglock);
357out: 349out:
358 mutex_unlock(&nlmsvc_mutex); 350 mutex_unlock(&nlmsvc_mutex);
359} 351}
360EXPORT_SYMBOL(lockd_down); 352EXPORT_SYMBOL(lockd_down);
361 353
354#ifdef CONFIG_SYSCTL
355
362/* 356/*
363 * Sysctl parameters (same as module parameters, different interface). 357 * Sysctl parameters (same as module parameters, different interface).
364 */ 358 */
@@ -443,6 +437,8 @@ static ctl_table nlm_sysctl_root[] = {
443 { .ctl_name = 0 } 437 { .ctl_name = 0 }
444}; 438};
445 439
440#endif /* CONFIG_SYSCTL */
441
446/* 442/*
447 * Module (and sysfs) parameters. 443 * Module (and sysfs) parameters.
448 */ 444 */
@@ -516,15 +512,21 @@ module_param(nsm_use_hostnames, bool, 0644);
516 512
517static int __init init_nlm(void) 513static int __init init_nlm(void)
518{ 514{
515#ifdef CONFIG_SYSCTL
519 nlm_sysctl_table = register_sysctl_table(nlm_sysctl_root); 516 nlm_sysctl_table = register_sysctl_table(nlm_sysctl_root);
520 return nlm_sysctl_table ? 0 : -ENOMEM; 517 return nlm_sysctl_table ? 0 : -ENOMEM;
518#else
519 return 0;
520#endif
521} 521}
522 522
523static void __exit exit_nlm(void) 523static void __exit exit_nlm(void)
524{ 524{
525 /* FIXME: delete all NLM clients */ 525 /* FIXME: delete all NLM clients */
526 nlm_shutdown_hosts(); 526 nlm_shutdown_hosts();
527#ifdef CONFIG_SYSCTL
527 unregister_sysctl_table(nlm_sysctl_table); 528 unregister_sysctl_table(nlm_sysctl_table);
529#endif
528} 530}
529 531
530module_init(init_nlm); 532module_init(init_nlm);
diff --git a/fs/lockd/svclock.c b/fs/lockd/svclock.c
index fe9bdb4a220c..1f122c1940af 100644
--- a/fs/lockd/svclock.c
+++ b/fs/lockd/svclock.c
@@ -29,6 +29,7 @@
29#include <linux/sunrpc/svc.h> 29#include <linux/sunrpc/svc.h>
30#include <linux/lockd/nlm.h> 30#include <linux/lockd/nlm.h>
31#include <linux/lockd/lockd.h> 31#include <linux/lockd/lockd.h>
32#include <linux/kthread.h>
32 33
33#define NLMDBG_FACILITY NLMDBG_SVCLOCK 34#define NLMDBG_FACILITY NLMDBG_SVCLOCK
34 35
@@ -226,8 +227,7 @@ failed:
226} 227}
227 228
228/* 229/*
229 * Delete a block. If the lock was cancelled or the grant callback 230 * Delete a block.
230 * failed, unlock is set to 1.
231 * It is the caller's responsibility to check whether the file 231 * It is the caller's responsibility to check whether the file
232 * can be closed hereafter. 232 * can be closed hereafter.
233 */ 233 */
@@ -887,7 +887,7 @@ nlmsvc_retry_blocked(void)
887 unsigned long timeout = MAX_SCHEDULE_TIMEOUT; 887 unsigned long timeout = MAX_SCHEDULE_TIMEOUT;
888 struct nlm_block *block; 888 struct nlm_block *block;
889 889
890 while (!list_empty(&nlm_blocked)) { 890 while (!list_empty(&nlm_blocked) && !kthread_should_stop()) {
891 block = list_entry(nlm_blocked.next, struct nlm_block, b_list); 891 block = list_entry(nlm_blocked.next, struct nlm_block, b_list);
892 892
893 if (block->b_when == NLM_NEVER) 893 if (block->b_when == NLM_NEVER)
diff --git a/fs/lockd/svcshare.c b/fs/lockd/svcshare.c
index 068886de4dda..b0ae07008700 100644
--- a/fs/lockd/svcshare.c
+++ b/fs/lockd/svcshare.c
@@ -71,7 +71,8 @@ nlmsvc_unshare_file(struct nlm_host *host, struct nlm_file *file,
71 struct nlm_share *share, **shpp; 71 struct nlm_share *share, **shpp;
72 struct xdr_netobj *oh = &argp->lock.oh; 72 struct xdr_netobj *oh = &argp->lock.oh;
73 73
74 for (shpp = &file->f_shares; (share = *shpp) != 0; shpp = &share->s_next) { 74 for (shpp = &file->f_shares; (share = *shpp) != NULL;
75 shpp = &share->s_next) {
75 if (share->s_host == host && nlm_cmp_owner(share, oh)) { 76 if (share->s_host == host && nlm_cmp_owner(share, oh)) {
76 *shpp = share->s_next; 77 *shpp = share->s_next;
77 kfree(share); 78 kfree(share);
diff --git a/fs/nfs/Makefile b/fs/nfs/Makefile
index df0f41e09885..ac6170c594a3 100644
--- a/fs/nfs/Makefile
+++ b/fs/nfs/Makefile
@@ -5,7 +5,7 @@
5obj-$(CONFIG_NFS_FS) += nfs.o 5obj-$(CONFIG_NFS_FS) += nfs.o
6 6
7nfs-y := client.o dir.o file.o getroot.o inode.o super.o nfs2xdr.o \ 7nfs-y := client.o dir.o file.o getroot.o inode.o super.o nfs2xdr.o \
8 pagelist.o proc.o read.o symlink.o unlink.o \ 8 direct.o pagelist.o proc.o read.o symlink.o unlink.o \
9 write.o namespace.o mount_clnt.o 9 write.o namespace.o mount_clnt.o
10nfs-$(CONFIG_ROOT_NFS) += nfsroot.o 10nfs-$(CONFIG_ROOT_NFS) += nfsroot.o
11nfs-$(CONFIG_NFS_V3) += nfs3proc.o nfs3xdr.o 11nfs-$(CONFIG_NFS_V3) += nfs3proc.o nfs3xdr.o
@@ -14,5 +14,4 @@ nfs-$(CONFIG_NFS_V4) += nfs4proc.o nfs4xdr.o nfs4state.o nfs4renewd.o \
14 delegation.o idmap.o \ 14 delegation.o idmap.o \
15 callback.o callback_xdr.o callback_proc.o \ 15 callback.o callback_xdr.o callback_proc.o \
16 nfs4namespace.o 16 nfs4namespace.o
17nfs-$(CONFIG_NFS_DIRECTIO) += direct.o
18nfs-$(CONFIG_SYSCTL) += sysctl.o 17nfs-$(CONFIG_SYSCTL) += sysctl.o
diff --git a/fs/nfs/callback.c b/fs/nfs/callback.c
index 66648dd92d97..5606ae3d72d3 100644
--- a/fs/nfs/callback.c
+++ b/fs/nfs/callback.c
@@ -15,6 +15,7 @@
15#include <linux/nfs_fs.h> 15#include <linux/nfs_fs.h>
16#include <linux/mutex.h> 16#include <linux/mutex.h>
17#include <linux/freezer.h> 17#include <linux/freezer.h>
18#include <linux/kthread.h>
18 19
19#include <net/inet_sock.h> 20#include <net/inet_sock.h>
20 21
@@ -27,9 +28,7 @@
27struct nfs_callback_data { 28struct nfs_callback_data {
28 unsigned int users; 29 unsigned int users;
29 struct svc_serv *serv; 30 struct svc_serv *serv;
30 pid_t pid; 31 struct task_struct *task;
31 struct completion started;
32 struct completion stopped;
33}; 32};
34 33
35static struct nfs_callback_data nfs_callback_info; 34static struct nfs_callback_data nfs_callback_info;
@@ -57,48 +56,44 @@ module_param_call(callback_tcpport, param_set_port, param_get_int,
57/* 56/*
58 * This is the callback kernel thread. 57 * This is the callback kernel thread.
59 */ 58 */
60static void nfs_callback_svc(struct svc_rqst *rqstp) 59static int
60nfs_callback_svc(void *vrqstp)
61{ 61{
62 int err; 62 int err, preverr = 0;
63 struct svc_rqst *rqstp = vrqstp;
63 64
64 __module_get(THIS_MODULE);
65 lock_kernel();
66
67 nfs_callback_info.pid = current->pid;
68 daemonize("nfsv4-svc");
69 /* Process request with signals blocked, but allow SIGKILL. */
70 allow_signal(SIGKILL);
71 set_freezable(); 65 set_freezable();
72 66
73 complete(&nfs_callback_info.started); 67 /*
74 68 * FIXME: do we really need to run this under the BKL? If so, please
75 for(;;) { 69 * add a comment about what it's intended to protect.
76 if (signalled()) { 70 */
77 if (nfs_callback_info.users == 0) 71 lock_kernel();
78 break; 72 while (!kthread_should_stop()) {
79 flush_signals(current);
80 }
81 /* 73 /*
82 * Listen for a request on the socket 74 * Listen for a request on the socket
83 */ 75 */
84 err = svc_recv(rqstp, MAX_SCHEDULE_TIMEOUT); 76 err = svc_recv(rqstp, MAX_SCHEDULE_TIMEOUT);
85 if (err == -EAGAIN || err == -EINTR) 77 if (err == -EAGAIN || err == -EINTR) {
78 preverr = err;
86 continue; 79 continue;
80 }
87 if (err < 0) { 81 if (err < 0) {
88 printk(KERN_WARNING 82 if (err != preverr) {
89 "%s: terminating on error %d\n", 83 printk(KERN_WARNING "%s: unexpected error "
90 __FUNCTION__, -err); 84 "from svc_recv (%d)\n", __func__, err);
91 break; 85 preverr = err;
86 }
87 schedule_timeout_uninterruptible(HZ);
88 continue;
92 } 89 }
90 preverr = err;
93 svc_process(rqstp); 91 svc_process(rqstp);
94 } 92 }
95
96 flush_signals(current);
97 svc_exit_thread(rqstp);
98 nfs_callback_info.pid = 0;
99 complete(&nfs_callback_info.stopped);
100 unlock_kernel(); 93 unlock_kernel();
101 module_put_and_exit(0); 94 nfs_callback_info.task = NULL;
95 svc_exit_thread(rqstp);
96 return 0;
102} 97}
103 98
104/* 99/*
@@ -107,14 +102,13 @@ static void nfs_callback_svc(struct svc_rqst *rqstp)
107int nfs_callback_up(void) 102int nfs_callback_up(void)
108{ 103{
109 struct svc_serv *serv = NULL; 104 struct svc_serv *serv = NULL;
105 struct svc_rqst *rqstp;
110 int ret = 0; 106 int ret = 0;
111 107
112 lock_kernel(); 108 lock_kernel();
113 mutex_lock(&nfs_callback_mutex); 109 mutex_lock(&nfs_callback_mutex);
114 if (nfs_callback_info.users++ || nfs_callback_info.pid != 0) 110 if (nfs_callback_info.users++ || nfs_callback_info.task != NULL)
115 goto out; 111 goto out;
116 init_completion(&nfs_callback_info.started);
117 init_completion(&nfs_callback_info.stopped);
118 serv = svc_create(&nfs4_callback_program, NFS4_CALLBACK_BUFSIZE, NULL); 112 serv = svc_create(&nfs4_callback_program, NFS4_CALLBACK_BUFSIZE, NULL);
119 ret = -ENOMEM; 113 ret = -ENOMEM;
120 if (!serv) 114 if (!serv)
@@ -127,15 +121,28 @@ int nfs_callback_up(void)
127 nfs_callback_tcpport = ret; 121 nfs_callback_tcpport = ret;
128 dprintk("Callback port = 0x%x\n", nfs_callback_tcpport); 122 dprintk("Callback port = 0x%x\n", nfs_callback_tcpport);
129 123
130 ret = svc_create_thread(nfs_callback_svc, serv); 124 rqstp = svc_prepare_thread(serv, &serv->sv_pools[0]);
131 if (ret < 0) 125 if (IS_ERR(rqstp)) {
126 ret = PTR_ERR(rqstp);
132 goto out_err; 127 goto out_err;
128 }
129
130 svc_sock_update_bufs(serv);
133 nfs_callback_info.serv = serv; 131 nfs_callback_info.serv = serv;
134 wait_for_completion(&nfs_callback_info.started); 132
133 nfs_callback_info.task = kthread_run(nfs_callback_svc, rqstp,
134 "nfsv4-svc");
135 if (IS_ERR(nfs_callback_info.task)) {
136 ret = PTR_ERR(nfs_callback_info.task);
137 nfs_callback_info.serv = NULL;
138 nfs_callback_info.task = NULL;
139 svc_exit_thread(rqstp);
140 goto out_err;
141 }
135out: 142out:
136 /* 143 /*
137 * svc_create creates the svc_serv with sv_nrthreads == 1, and then 144 * svc_create creates the svc_serv with sv_nrthreads == 1, and then
138 * svc_create_thread increments that. So we need to call svc_destroy 145 * svc_prepare_thread increments that. So we need to call svc_destroy
139 * on both success and failure so that the refcount is 1 when the 146 * on both success and failure so that the refcount is 1 when the
140 * thread exits. 147 * thread exits.
141 */ 148 */
@@ -152,19 +159,15 @@ out_err:
152} 159}
153 160
154/* 161/*
155 * Kill the server process if it is not already up. 162 * Kill the server process if it is not already down.
156 */ 163 */
157void nfs_callback_down(void) 164void nfs_callback_down(void)
158{ 165{
159 lock_kernel(); 166 lock_kernel();
160 mutex_lock(&nfs_callback_mutex); 167 mutex_lock(&nfs_callback_mutex);
161 nfs_callback_info.users--; 168 nfs_callback_info.users--;
162 do { 169 if (nfs_callback_info.users == 0 && nfs_callback_info.task != NULL)
163 if (nfs_callback_info.users != 0 || nfs_callback_info.pid == 0) 170 kthread_stop(nfs_callback_info.task);
164 break;
165 if (kill_proc(nfs_callback_info.pid, SIGKILL, 1) < 0)
166 break;
167 } while (wait_for_completion_timeout(&nfs_callback_info.stopped, 5*HZ) == 0);
168 mutex_unlock(&nfs_callback_mutex); 171 mutex_unlock(&nfs_callback_mutex);
169 unlock_kernel(); 172 unlock_kernel();
170} 173}
diff --git a/fs/nfs/client.c b/fs/nfs/client.c
index c5c0175898f6..f2f3b284e6dd 100644
--- a/fs/nfs/client.c
+++ b/fs/nfs/client.c
@@ -112,6 +112,7 @@ struct nfs_client_initdata {
112static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init) 112static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_init)
113{ 113{
114 struct nfs_client *clp; 114 struct nfs_client *clp;
115 struct rpc_cred *cred;
115 116
116 if ((clp = kzalloc(sizeof(*clp), GFP_KERNEL)) == NULL) 117 if ((clp = kzalloc(sizeof(*clp), GFP_KERNEL)) == NULL)
117 goto error_0; 118 goto error_0;
@@ -150,6 +151,9 @@ static struct nfs_client *nfs_alloc_client(const struct nfs_client_initdata *cl_
150 clp->cl_boot_time = CURRENT_TIME; 151 clp->cl_boot_time = CURRENT_TIME;
151 clp->cl_state = 1 << NFS4CLNT_LEASE_EXPIRED; 152 clp->cl_state = 1 << NFS4CLNT_LEASE_EXPIRED;
152#endif 153#endif
154 cred = rpc_lookup_machine_cred();
155 if (!IS_ERR(cred))
156 clp->cl_machine_cred = cred;
153 157
154 return clp; 158 return clp;
155 159
@@ -170,6 +174,8 @@ static void nfs4_shutdown_client(struct nfs_client *clp)
170 BUG_ON(!RB_EMPTY_ROOT(&clp->cl_state_owners)); 174 BUG_ON(!RB_EMPTY_ROOT(&clp->cl_state_owners));
171 if (__test_and_clear_bit(NFS_CS_IDMAP, &clp->cl_res_state)) 175 if (__test_and_clear_bit(NFS_CS_IDMAP, &clp->cl_res_state))
172 nfs_idmap_delete(clp); 176 nfs_idmap_delete(clp);
177
178 rpc_destroy_wait_queue(&clp->cl_rpcwaitq);
173#endif 179#endif
174} 180}
175 181
@@ -189,6 +195,9 @@ static void nfs_free_client(struct nfs_client *clp)
189 if (__test_and_clear_bit(NFS_CS_CALLBACK, &clp->cl_res_state)) 195 if (__test_and_clear_bit(NFS_CS_CALLBACK, &clp->cl_res_state))
190 nfs_callback_down(); 196 nfs_callback_down();
191 197
198 if (clp->cl_machine_cred != NULL)
199 put_rpccred(clp->cl_machine_cred);
200
192 kfree(clp->cl_hostname); 201 kfree(clp->cl_hostname);
193 kfree(clp); 202 kfree(clp);
194 203
@@ -680,10 +689,22 @@ static int nfs_init_server(struct nfs_server *server,
680 if (error < 0) 689 if (error < 0)
681 goto error; 690 goto error;
682 691
692 server->port = data->nfs_server.port;
693
683 error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]); 694 error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]);
684 if (error < 0) 695 if (error < 0)
685 goto error; 696 goto error;
686 697
698 /* Preserve the values of mount_server-related mount options */
699 if (data->mount_server.addrlen) {
700 memcpy(&server->mountd_address, &data->mount_server.address,
701 data->mount_server.addrlen);
702 server->mountd_addrlen = data->mount_server.addrlen;
703 }
704 server->mountd_version = data->mount_server.version;
705 server->mountd_port = data->mount_server.port;
706 server->mountd_protocol = data->mount_server.protocol;
707
687 server->namelen = data->namlen; 708 server->namelen = data->namlen;
688 /* Create a client RPC handle for the NFSv3 ACL management interface */ 709 /* Create a client RPC handle for the NFSv3 ACL management interface */
689 nfs_init_server_aclclient(server); 710 nfs_init_server_aclclient(server);
@@ -1062,6 +1083,8 @@ static int nfs4_init_server(struct nfs_server *server,
1062 server->acdirmin = data->acdirmin * HZ; 1083 server->acdirmin = data->acdirmin * HZ;
1063 server->acdirmax = data->acdirmax * HZ; 1084 server->acdirmax = data->acdirmax * HZ;
1064 1085
1086 server->port = data->nfs_server.port;
1087
1065 error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]); 1088 error = nfs_init_server_rpcclient(server, &timeparms, data->auth_flavors[0]);
1066 1089
1067error: 1090error:
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c
index d9e30ac2798d..f288b3ecab4a 100644
--- a/fs/nfs/dir.c
+++ b/fs/nfs/dir.c
@@ -1967,7 +1967,7 @@ force_lookup:
1967 if (!NFS_PROTO(inode)->access) 1967 if (!NFS_PROTO(inode)->access)
1968 goto out_notsup; 1968 goto out_notsup;
1969 1969
1970 cred = rpcauth_lookupcred(NFS_CLIENT(inode)->cl_auth, 0); 1970 cred = rpc_lookup_cred();
1971 if (!IS_ERR(cred)) { 1971 if (!IS_ERR(cred)) {
1972 res = nfs_do_access(inode, cred, mask); 1972 res = nfs_do_access(inode, cred, mask);
1973 put_rpccred(cred); 1973 put_rpccred(cred);
diff --git a/fs/nfs/direct.c b/fs/nfs/direct.c
index 16844f98f50e..4757a2b326a1 100644
--- a/fs/nfs/direct.c
+++ b/fs/nfs/direct.c
@@ -229,14 +229,20 @@ static void nfs_direct_complete(struct nfs_direct_req *dreq)
229static void nfs_direct_read_result(struct rpc_task *task, void *calldata) 229static void nfs_direct_read_result(struct rpc_task *task, void *calldata)
230{ 230{
231 struct nfs_read_data *data = calldata; 231 struct nfs_read_data *data = calldata;
232 struct nfs_direct_req *dreq = (struct nfs_direct_req *) data->req;
233 232
234 if (nfs_readpage_result(task, data) != 0) 233 nfs_readpage_result(task, data);
235 return; 234}
235
236static void nfs_direct_read_release(void *calldata)
237{
238
239 struct nfs_read_data *data = calldata;
240 struct nfs_direct_req *dreq = (struct nfs_direct_req *) data->req;
241 int status = data->task.tk_status;
236 242
237 spin_lock(&dreq->lock); 243 spin_lock(&dreq->lock);
238 if (unlikely(task->tk_status < 0)) { 244 if (unlikely(status < 0)) {
239 dreq->error = task->tk_status; 245 dreq->error = status;
240 spin_unlock(&dreq->lock); 246 spin_unlock(&dreq->lock);
241 } else { 247 } else {
242 dreq->count += data->res.count; 248 dreq->count += data->res.count;
@@ -249,11 +255,12 @@ static void nfs_direct_read_result(struct rpc_task *task, void *calldata)
249 255
250 if (put_dreq(dreq)) 256 if (put_dreq(dreq))
251 nfs_direct_complete(dreq); 257 nfs_direct_complete(dreq);
258 nfs_readdata_release(calldata);
252} 259}
253 260
254static const struct rpc_call_ops nfs_read_direct_ops = { 261static const struct rpc_call_ops nfs_read_direct_ops = {
255 .rpc_call_done = nfs_direct_read_result, 262 .rpc_call_done = nfs_direct_read_result,
256 .rpc_release = nfs_readdata_release, 263 .rpc_release = nfs_direct_read_release,
257}; 264};
258 265
259/* 266/*
@@ -280,6 +287,7 @@ static ssize_t nfs_direct_read_schedule_segment(struct nfs_direct_req *dreq,
280 .rpc_client = NFS_CLIENT(inode), 287 .rpc_client = NFS_CLIENT(inode),
281 .rpc_message = &msg, 288 .rpc_message = &msg,
282 .callback_ops = &nfs_read_direct_ops, 289 .callback_ops = &nfs_read_direct_ops,
290 .workqueue = nfsiod_workqueue,
283 .flags = RPC_TASK_ASYNC, 291 .flags = RPC_TASK_ASYNC,
284 }; 292 };
285 unsigned int pgbase; 293 unsigned int pgbase;
@@ -323,7 +331,7 @@ static ssize_t nfs_direct_read_schedule_segment(struct nfs_direct_req *dreq,
323 data->inode = inode; 331 data->inode = inode;
324 data->cred = msg.rpc_cred; 332 data->cred = msg.rpc_cred;
325 data->args.fh = NFS_FH(inode); 333 data->args.fh = NFS_FH(inode);
326 data->args.context = ctx; 334 data->args.context = get_nfs_open_context(ctx);
327 data->args.offset = pos; 335 data->args.offset = pos;
328 data->args.pgbase = pgbase; 336 data->args.pgbase = pgbase;
329 data->args.pages = data->pagevec; 337 data->args.pages = data->pagevec;
@@ -339,8 +347,9 @@ static ssize_t nfs_direct_read_schedule_segment(struct nfs_direct_req *dreq,
339 NFS_PROTO(inode)->read_setup(data, &msg); 347 NFS_PROTO(inode)->read_setup(data, &msg);
340 348
341 task = rpc_run_task(&task_setup_data); 349 task = rpc_run_task(&task_setup_data);
342 if (!IS_ERR(task)) 350 if (IS_ERR(task))
343 rpc_put_task(task); 351 break;
352 rpc_put_task(task);
344 353
345 dprintk("NFS: %5u initiated direct read call " 354 dprintk("NFS: %5u initiated direct read call "
346 "(req %s/%Ld, %zu bytes @ offset %Lu)\n", 355 "(req %s/%Ld, %zu bytes @ offset %Lu)\n",
@@ -446,6 +455,7 @@ static void nfs_direct_write_reschedule(struct nfs_direct_req *dreq)
446 struct rpc_task_setup task_setup_data = { 455 struct rpc_task_setup task_setup_data = {
447 .rpc_client = NFS_CLIENT(inode), 456 .rpc_client = NFS_CLIENT(inode),
448 .callback_ops = &nfs_write_direct_ops, 457 .callback_ops = &nfs_write_direct_ops,
458 .workqueue = nfsiod_workqueue,
449 .flags = RPC_TASK_ASYNC, 459 .flags = RPC_TASK_ASYNC,
450 }; 460 };
451 461
@@ -499,27 +509,34 @@ static void nfs_direct_write_reschedule(struct nfs_direct_req *dreq)
499static void nfs_direct_commit_result(struct rpc_task *task, void *calldata) 509static void nfs_direct_commit_result(struct rpc_task *task, void *calldata)
500{ 510{
501 struct nfs_write_data *data = calldata; 511 struct nfs_write_data *data = calldata;
502 struct nfs_direct_req *dreq = (struct nfs_direct_req *) data->req;
503 512
504 /* Call the NFS version-specific code */ 513 /* Call the NFS version-specific code */
505 if (NFS_PROTO(data->inode)->commit_done(task, data) != 0) 514 NFS_PROTO(data->inode)->commit_done(task, data);
506 return; 515}
507 if (unlikely(task->tk_status < 0)) { 516
517static void nfs_direct_commit_release(void *calldata)
518{
519 struct nfs_write_data *data = calldata;
520 struct nfs_direct_req *dreq = (struct nfs_direct_req *) data->req;
521 int status = data->task.tk_status;
522
523 if (status < 0) {
508 dprintk("NFS: %5u commit failed with error %d.\n", 524 dprintk("NFS: %5u commit failed with error %d.\n",
509 task->tk_pid, task->tk_status); 525 data->task.tk_pid, status);
510 dreq->flags = NFS_ODIRECT_RESCHED_WRITES; 526 dreq->flags = NFS_ODIRECT_RESCHED_WRITES;
511 } else if (memcmp(&dreq->verf, &data->verf, sizeof(data->verf))) { 527 } else if (memcmp(&dreq->verf, &data->verf, sizeof(data->verf))) {
512 dprintk("NFS: %5u commit verify failed\n", task->tk_pid); 528 dprintk("NFS: %5u commit verify failed\n", data->task.tk_pid);
513 dreq->flags = NFS_ODIRECT_RESCHED_WRITES; 529 dreq->flags = NFS_ODIRECT_RESCHED_WRITES;
514 } 530 }
515 531
516 dprintk("NFS: %5u commit returned %d\n", task->tk_pid, task->tk_status); 532 dprintk("NFS: %5u commit returned %d\n", data->task.tk_pid, status);
517 nfs_direct_write_complete(dreq, data->inode); 533 nfs_direct_write_complete(dreq, data->inode);
534 nfs_commitdata_release(calldata);
518} 535}
519 536
520static const struct rpc_call_ops nfs_commit_direct_ops = { 537static const struct rpc_call_ops nfs_commit_direct_ops = {
521 .rpc_call_done = nfs_direct_commit_result, 538 .rpc_call_done = nfs_direct_commit_result,
522 .rpc_release = nfs_commit_release, 539 .rpc_release = nfs_direct_commit_release,
523}; 540};
524 541
525static void nfs_direct_commit_schedule(struct nfs_direct_req *dreq) 542static void nfs_direct_commit_schedule(struct nfs_direct_req *dreq)
@@ -537,6 +554,7 @@ static void nfs_direct_commit_schedule(struct nfs_direct_req *dreq)
537 .rpc_message = &msg, 554 .rpc_message = &msg,
538 .callback_ops = &nfs_commit_direct_ops, 555 .callback_ops = &nfs_commit_direct_ops,
539 .callback_data = data, 556 .callback_data = data,
557 .workqueue = nfsiod_workqueue,
540 .flags = RPC_TASK_ASYNC, 558 .flags = RPC_TASK_ASYNC,
541 }; 559 };
542 560
@@ -546,6 +564,7 @@ static void nfs_direct_commit_schedule(struct nfs_direct_req *dreq)
546 data->args.fh = NFS_FH(data->inode); 564 data->args.fh = NFS_FH(data->inode);
547 data->args.offset = 0; 565 data->args.offset = 0;
548 data->args.count = 0; 566 data->args.count = 0;
567 data->args.context = get_nfs_open_context(dreq->ctx);
549 data->res.count = 0; 568 data->res.count = 0;
550 data->res.fattr = &data->fattr; 569 data->res.fattr = &data->fattr;
551 data->res.verf = &data->verf; 570 data->res.verf = &data->verf;
@@ -585,7 +604,7 @@ static void nfs_direct_write_complete(struct nfs_direct_req *dreq, struct inode
585 604
586static void nfs_alloc_commit_data(struct nfs_direct_req *dreq) 605static void nfs_alloc_commit_data(struct nfs_direct_req *dreq)
587{ 606{
588 dreq->commit_data = nfs_commit_alloc(); 607 dreq->commit_data = nfs_commitdata_alloc();
589 if (dreq->commit_data != NULL) 608 if (dreq->commit_data != NULL)
590 dreq->commit_data->req = (struct nfs_page *) dreq; 609 dreq->commit_data->req = (struct nfs_page *) dreq;
591} 610}
@@ -606,11 +625,20 @@ static void nfs_direct_write_complete(struct nfs_direct_req *dreq, struct inode
606static void nfs_direct_write_result(struct rpc_task *task, void *calldata) 625static void nfs_direct_write_result(struct rpc_task *task, void *calldata)
607{ 626{
608 struct nfs_write_data *data = calldata; 627 struct nfs_write_data *data = calldata;
609 struct nfs_direct_req *dreq = (struct nfs_direct_req *) data->req;
610 int status = task->tk_status;
611 628
612 if (nfs_writeback_done(task, data) != 0) 629 if (nfs_writeback_done(task, data) != 0)
613 return; 630 return;
631}
632
633/*
634 * NB: Return the value of the first error return code. Subsequent
635 * errors after the first one are ignored.
636 */
637static void nfs_direct_write_release(void *calldata)
638{
639 struct nfs_write_data *data = calldata;
640 struct nfs_direct_req *dreq = (struct nfs_direct_req *) data->req;
641 int status = data->task.tk_status;
614 642
615 spin_lock(&dreq->lock); 643 spin_lock(&dreq->lock);
616 644
@@ -632,23 +660,13 @@ static void nfs_direct_write_result(struct rpc_task *task, void *calldata)
632 break; 660 break;
633 case NFS_ODIRECT_DO_COMMIT: 661 case NFS_ODIRECT_DO_COMMIT:
634 if (memcmp(&dreq->verf, &data->verf, sizeof(dreq->verf))) { 662 if (memcmp(&dreq->verf, &data->verf, sizeof(dreq->verf))) {
635 dprintk("NFS: %5u write verify failed\n", task->tk_pid); 663 dprintk("NFS: %5u write verify failed\n", data->task.tk_pid);
636 dreq->flags = NFS_ODIRECT_RESCHED_WRITES; 664 dreq->flags = NFS_ODIRECT_RESCHED_WRITES;
637 } 665 }
638 } 666 }
639 } 667 }
640out_unlock: 668out_unlock:
641 spin_unlock(&dreq->lock); 669 spin_unlock(&dreq->lock);
642}
643
644/*
645 * NB: Return the value of the first error return code. Subsequent
646 * errors after the first one are ignored.
647 */
648static void nfs_direct_write_release(void *calldata)
649{
650 struct nfs_write_data *data = calldata;
651 struct nfs_direct_req *dreq = (struct nfs_direct_req *) data->req;
652 670
653 if (put_dreq(dreq)) 671 if (put_dreq(dreq))
654 nfs_direct_write_complete(dreq, data->inode); 672 nfs_direct_write_complete(dreq, data->inode);
@@ -682,6 +700,7 @@ static ssize_t nfs_direct_write_schedule_segment(struct nfs_direct_req *dreq,
682 .rpc_client = NFS_CLIENT(inode), 700 .rpc_client = NFS_CLIENT(inode),
683 .rpc_message = &msg, 701 .rpc_message = &msg,
684 .callback_ops = &nfs_write_direct_ops, 702 .callback_ops = &nfs_write_direct_ops,
703 .workqueue = nfsiod_workqueue,
685 .flags = RPC_TASK_ASYNC, 704 .flags = RPC_TASK_ASYNC,
686 }; 705 };
687 size_t wsize = NFS_SERVER(inode)->wsize; 706 size_t wsize = NFS_SERVER(inode)->wsize;
@@ -728,7 +747,7 @@ static ssize_t nfs_direct_write_schedule_segment(struct nfs_direct_req *dreq,
728 data->inode = inode; 747 data->inode = inode;
729 data->cred = msg.rpc_cred; 748 data->cred = msg.rpc_cred;
730 data->args.fh = NFS_FH(inode); 749 data->args.fh = NFS_FH(inode);
731 data->args.context = ctx; 750 data->args.context = get_nfs_open_context(ctx);
732 data->args.offset = pos; 751 data->args.offset = pos;
733 data->args.pgbase = pgbase; 752 data->args.pgbase = pgbase;
734 data->args.pages = data->pagevec; 753 data->args.pages = data->pagevec;
@@ -745,8 +764,9 @@ static ssize_t nfs_direct_write_schedule_segment(struct nfs_direct_req *dreq,
745 NFS_PROTO(inode)->write_setup(data, &msg); 764 NFS_PROTO(inode)->write_setup(data, &msg);
746 765
747 task = rpc_run_task(&task_setup_data); 766 task = rpc_run_task(&task_setup_data);
748 if (!IS_ERR(task)) 767 if (IS_ERR(task))
749 rpc_put_task(task); 768 break;
769 rpc_put_task(task);
750 770
751 dprintk("NFS: %5u initiated direct write call " 771 dprintk("NFS: %5u initiated direct write call "
752 "(req %s/%Ld, %zu bytes @ offset %Lu)\n", 772 "(req %s/%Ld, %zu bytes @ offset %Lu)\n",
diff --git a/fs/nfs/file.c b/fs/nfs/file.c
index 5d2e9d9a4e28..3536b01164f9 100644
--- a/fs/nfs/file.c
+++ b/fs/nfs/file.c
@@ -238,10 +238,8 @@ nfs_file_read(struct kiocb *iocb, const struct iovec *iov,
238 ssize_t result; 238 ssize_t result;
239 size_t count = iov_length(iov, nr_segs); 239 size_t count = iov_length(iov, nr_segs);
240 240
241#ifdef CONFIG_NFS_DIRECTIO
242 if (iocb->ki_filp->f_flags & O_DIRECT) 241 if (iocb->ki_filp->f_flags & O_DIRECT)
243 return nfs_file_direct_read(iocb, iov, nr_segs, pos); 242 return nfs_file_direct_read(iocb, iov, nr_segs, pos);
244#endif
245 243
246 dfprintk(VFS, "nfs: read(%s/%s, %lu@%lu)\n", 244 dfprintk(VFS, "nfs: read(%s/%s, %lu@%lu)\n",
247 dentry->d_parent->d_name.name, dentry->d_name.name, 245 dentry->d_parent->d_name.name, dentry->d_name.name,
@@ -387,9 +385,7 @@ const struct address_space_operations nfs_file_aops = {
387 .write_end = nfs_write_end, 385 .write_end = nfs_write_end,
388 .invalidatepage = nfs_invalidate_page, 386 .invalidatepage = nfs_invalidate_page,
389 .releasepage = nfs_release_page, 387 .releasepage = nfs_release_page,
390#ifdef CONFIG_NFS_DIRECTIO
391 .direct_IO = nfs_direct_IO, 388 .direct_IO = nfs_direct_IO,
392#endif
393 .launder_page = nfs_launder_page, 389 .launder_page = nfs_launder_page,
394}; 390};
395 391
@@ -447,10 +443,8 @@ static ssize_t nfs_file_write(struct kiocb *iocb, const struct iovec *iov,
447 ssize_t result; 443 ssize_t result;
448 size_t count = iov_length(iov, nr_segs); 444 size_t count = iov_length(iov, nr_segs);
449 445
450#ifdef CONFIG_NFS_DIRECTIO
451 if (iocb->ki_filp->f_flags & O_DIRECT) 446 if (iocb->ki_filp->f_flags & O_DIRECT)
452 return nfs_file_direct_write(iocb, iov, nr_segs, pos); 447 return nfs_file_direct_write(iocb, iov, nr_segs, pos);
453#endif
454 448
455 dfprintk(VFS, "nfs: write(%s/%s(%ld), %lu@%Ld)\n", 449 dfprintk(VFS, "nfs: write(%s/%s(%ld), %lu@%Ld)\n",
456 dentry->d_parent->d_name.name, dentry->d_name.name, 450 dentry->d_parent->d_name.name, dentry->d_name.name,
@@ -576,17 +570,9 @@ static int do_setlk(struct file *filp, int cmd, struct file_lock *fl)
576 570
577 lock_kernel(); 571 lock_kernel();
578 /* Use local locking if mounted with "-onolock" */ 572 /* Use local locking if mounted with "-onolock" */
579 if (!(NFS_SERVER(inode)->flags & NFS_MOUNT_NONLM)) { 573 if (!(NFS_SERVER(inode)->flags & NFS_MOUNT_NONLM))
580 status = NFS_PROTO(inode)->lock(filp, cmd, fl); 574 status = NFS_PROTO(inode)->lock(filp, cmd, fl);
581 /* If we were signalled we still need to ensure that 575 else
582 * we clean up any state on the server. We therefore
583 * record the lock call as having succeeded in order to
584 * ensure that locks_remove_posix() cleans it out when
585 * the process exits.
586 */
587 if (status == -EINTR || status == -ERESTARTSYS)
588 do_vfs_lock(filp, fl);
589 } else
590 status = do_vfs_lock(filp, fl); 576 status = do_vfs_lock(filp, fl);
591 unlock_kernel(); 577 unlock_kernel();
592 if (status < 0) 578 if (status < 0)
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
index 6f88d7c77ac9..5cb3345eb694 100644
--- a/fs/nfs/inode.c
+++ b/fs/nfs/inode.c
@@ -523,8 +523,12 @@ struct nfs_open_context *get_nfs_open_context(struct nfs_open_context *ctx)
523 523
524static void __put_nfs_open_context(struct nfs_open_context *ctx, int wait) 524static void __put_nfs_open_context(struct nfs_open_context *ctx, int wait)
525{ 525{
526 struct inode *inode = ctx->path.dentry->d_inode; 526 struct inode *inode;
527 527
528 if (ctx == NULL)
529 return;
530
531 inode = ctx->path.dentry->d_inode;
528 if (!atomic_dec_and_lock(&ctx->count, &inode->i_lock)) 532 if (!atomic_dec_and_lock(&ctx->count, &inode->i_lock))
529 return; 533 return;
530 list_del(&ctx->list); 534 list_del(&ctx->list);
@@ -610,7 +614,7 @@ int nfs_open(struct inode *inode, struct file *filp)
610 struct nfs_open_context *ctx; 614 struct nfs_open_context *ctx;
611 struct rpc_cred *cred; 615 struct rpc_cred *cred;
612 616
613 cred = rpcauth_lookupcred(NFS_CLIENT(inode)->cl_auth, 0); 617 cred = rpc_lookup_cred();
614 if (IS_ERR(cred)) 618 if (IS_ERR(cred))
615 return PTR_ERR(cred); 619 return PTR_ERR(cred);
616 ctx = alloc_nfs_open_context(filp->f_path.mnt, filp->f_path.dentry, cred); 620 ctx = alloc_nfs_open_context(filp->f_path.mnt, filp->f_path.dentry, cred);
@@ -1218,6 +1222,36 @@ static void nfs_destroy_inodecache(void)
1218 kmem_cache_destroy(nfs_inode_cachep); 1222 kmem_cache_destroy(nfs_inode_cachep);
1219} 1223}
1220 1224
1225struct workqueue_struct *nfsiod_workqueue;
1226
1227/*
1228 * start up the nfsiod workqueue
1229 */
1230static int nfsiod_start(void)
1231{
1232 struct workqueue_struct *wq;
1233 dprintk("RPC: creating workqueue nfsiod\n");
1234 wq = create_singlethread_workqueue("nfsiod");
1235 if (wq == NULL)
1236 return -ENOMEM;
1237 nfsiod_workqueue = wq;
1238 return 0;
1239}
1240
1241/*
1242 * Destroy the nfsiod workqueue
1243 */
1244static void nfsiod_stop(void)
1245{
1246 struct workqueue_struct *wq;
1247
1248 wq = nfsiod_workqueue;
1249 if (wq == NULL)
1250 return;
1251 nfsiod_workqueue = NULL;
1252 destroy_workqueue(wq);
1253}
1254
1221/* 1255/*
1222 * Initialize NFS 1256 * Initialize NFS
1223 */ 1257 */
@@ -1225,6 +1259,10 @@ static int __init init_nfs_fs(void)
1225{ 1259{
1226 int err; 1260 int err;
1227 1261
1262 err = nfsiod_start();
1263 if (err)
1264 goto out6;
1265
1228 err = nfs_fs_proc_init(); 1266 err = nfs_fs_proc_init();
1229 if (err) 1267 if (err)
1230 goto out5; 1268 goto out5;
@@ -1271,6 +1309,8 @@ out3:
1271out4: 1309out4:
1272 nfs_fs_proc_exit(); 1310 nfs_fs_proc_exit();
1273out5: 1311out5:
1312 nfsiod_stop();
1313out6:
1274 return err; 1314 return err;
1275} 1315}
1276 1316
@@ -1286,6 +1326,7 @@ static void __exit exit_nfs_fs(void)
1286#endif 1326#endif
1287 unregister_nfs_fs(); 1327 unregister_nfs_fs();
1288 nfs_fs_proc_exit(); 1328 nfs_fs_proc_exit();
1329 nfsiod_stop();
1289} 1330}
1290 1331
1291/* Not quite true; I just maintain it */ 1332/* Not quite true; I just maintain it */
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h
index 931992763e68..04ae867dddba 100644
--- a/fs/nfs/internal.h
+++ b/fs/nfs/internal.h
@@ -46,9 +46,9 @@ struct nfs_parsed_mount_data {
46 struct sockaddr_storage address; 46 struct sockaddr_storage address;
47 size_t addrlen; 47 size_t addrlen;
48 char *hostname; 48 char *hostname;
49 unsigned int version; 49 u32 version;
50 unsigned short port; 50 unsigned short port;
51 int protocol; 51 unsigned short protocol;
52 } mount_server; 52 } mount_server;
53 53
54 struct { 54 struct {
@@ -56,7 +56,8 @@ struct nfs_parsed_mount_data {
56 size_t addrlen; 56 size_t addrlen;
57 char *hostname; 57 char *hostname;
58 char *export_path; 58 char *export_path;
59 int protocol; 59 unsigned short port;
60 unsigned short protocol;
60 } nfs_server; 61 } nfs_server;
61 62
62 struct security_mnt_opts lsm_opts; 63 struct security_mnt_opts lsm_opts;
@@ -115,13 +116,8 @@ extern void nfs_destroy_readpagecache(void);
115extern int __init nfs_init_writepagecache(void); 116extern int __init nfs_init_writepagecache(void);
116extern void nfs_destroy_writepagecache(void); 117extern void nfs_destroy_writepagecache(void);
117 118
118#ifdef CONFIG_NFS_DIRECTIO
119extern int __init nfs_init_directcache(void); 119extern int __init nfs_init_directcache(void);
120extern void nfs_destroy_directcache(void); 120extern void nfs_destroy_directcache(void);
121#else
122#define nfs_init_directcache() (0)
123#define nfs_destroy_directcache() do {} while(0)
124#endif
125 121
126/* nfs2xdr.c */ 122/* nfs2xdr.c */
127extern int nfs_stat_to_errno(int); 123extern int nfs_stat_to_errno(int);
@@ -146,6 +142,7 @@ extern struct rpc_procinfo nfs4_procedures[];
146extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask); 142extern int nfs_access_cache_shrinker(int nr_to_scan, gfp_t gfp_mask);
147 143
148/* inode.c */ 144/* inode.c */
145extern struct workqueue_struct *nfsiod_workqueue;
149extern struct inode *nfs_alloc_inode(struct super_block *sb); 146extern struct inode *nfs_alloc_inode(struct super_block *sb);
150extern void nfs_destroy_inode(struct inode *); 147extern void nfs_destroy_inode(struct inode *);
151extern int nfs_write_inode(struct inode *,int); 148extern int nfs_write_inode(struct inode *,int);
diff --git a/fs/nfs/namespace.c b/fs/nfs/namespace.c
index 607f6eb9cdb5..af4d0f1e402c 100644
--- a/fs/nfs/namespace.c
+++ b/fs/nfs/namespace.c
@@ -20,7 +20,7 @@
20 20
21static void nfs_expire_automounts(struct work_struct *work); 21static void nfs_expire_automounts(struct work_struct *work);
22 22
23LIST_HEAD(nfs_automount_list); 23static LIST_HEAD(nfs_automount_list);
24static DECLARE_DELAYED_WORK(nfs_automount_task, nfs_expire_automounts); 24static DECLARE_DELAYED_WORK(nfs_automount_task, nfs_expire_automounts);
25int nfs_mountpoint_expiry_timeout = 500 * HZ; 25int nfs_mountpoint_expiry_timeout = 500 * HZ;
26 26
diff --git a/fs/nfs/nfs2xdr.c b/fs/nfs/nfs2xdr.c
index 1f7ea675e0c5..28bab67d1519 100644
--- a/fs/nfs/nfs2xdr.c
+++ b/fs/nfs/nfs2xdr.c
@@ -267,7 +267,7 @@ nfs_xdr_readres(struct rpc_rqst *req, __be32 *p, struct nfs_readres *res)
267 int status; 267 int status;
268 268
269 if ((status = ntohl(*p++))) 269 if ((status = ntohl(*p++)))
270 return -nfs_stat_to_errno(status); 270 return nfs_stat_to_errno(status);
271 p = xdr_decode_fattr(p, res->fattr); 271 p = xdr_decode_fattr(p, res->fattr);
272 272
273 count = ntohl(*p++); 273 count = ntohl(*p++);
@@ -428,11 +428,11 @@ nfs_xdr_readdirres(struct rpc_rqst *req, __be32 *p, void *dummy)
428 size_t hdrlen; 428 size_t hdrlen;
429 unsigned int pglen, recvd; 429 unsigned int pglen, recvd;
430 u32 len; 430 u32 len;
431 int status, nr; 431 int status, nr = 0;
432 __be32 *end, *entry, *kaddr; 432 __be32 *end, *entry, *kaddr;
433 433
434 if ((status = ntohl(*p++))) 434 if ((status = ntohl(*p++)))
435 return -nfs_stat_to_errno(status); 435 return nfs_stat_to_errno(status);
436 436
437 hdrlen = (u8 *) p - (u8 *) iov->iov_base; 437 hdrlen = (u8 *) p - (u8 *) iov->iov_base;
438 if (iov->iov_len < hdrlen) { 438 if (iov->iov_len < hdrlen) {
@@ -452,7 +452,12 @@ nfs_xdr_readdirres(struct rpc_rqst *req, __be32 *p, void *dummy)
452 kaddr = p = kmap_atomic(*page, KM_USER0); 452 kaddr = p = kmap_atomic(*page, KM_USER0);
453 end = (__be32 *)((char *)p + pglen); 453 end = (__be32 *)((char *)p + pglen);
454 entry = p; 454 entry = p;
455 for (nr = 0; *p++; nr++) { 455
456 /* Make sure the packet actually has a value_follows and EOF entry */
457 if ((entry + 1) > end)
458 goto short_pkt;
459
460 for (; *p++; nr++) {
456 if (p + 2 > end) 461 if (p + 2 > end)
457 goto short_pkt; 462 goto short_pkt;
458 p++; /* fileid */ 463 p++; /* fileid */
@@ -467,18 +472,32 @@ nfs_xdr_readdirres(struct rpc_rqst *req, __be32 *p, void *dummy)
467 goto short_pkt; 472 goto short_pkt;
468 entry = p; 473 entry = p;
469 } 474 }
470 if (!nr && (entry[0] != 0 || entry[1] == 0)) 475
471 goto short_pkt; 476 /*
477 * Apparently some server sends responses that are a valid size, but
478 * contain no entries, and have value_follows==0 and EOF==0. For
479 * those, just set the EOF marker.
480 */
481 if (!nr && entry[1] == 0) {
482 dprintk("NFS: readdir reply truncated!\n");
483 entry[1] = 1;
484 }
472 out: 485 out:
473 kunmap_atomic(kaddr, KM_USER0); 486 kunmap_atomic(kaddr, KM_USER0);
474 return nr; 487 return nr;
475 short_pkt: 488 short_pkt:
489 /*
490 * When we get a short packet there are 2 possibilities. We can
491 * return an error, or fix up the response to look like a valid
492 * response and return what we have so far. If there are no
493 * entries and the packet was short, then return -EIO. If there
494 * are valid entries in the response, return them and pretend that
495 * the call was successful, but incomplete. The caller can retry the
496 * readdir starting at the last cookie.
497 */
476 entry[0] = entry[1] = 0; 498 entry[0] = entry[1] = 0;
477 /* truncate listing ? */ 499 if (!nr)
478 if (!nr) { 500 nr = -errno_NFSERR_IO;
479 dprintk("NFS: readdir reply truncated!\n");
480 entry[1] = 1;
481 }
482 goto out; 501 goto out;
483err_unmap: 502err_unmap:
484 nr = -errno_NFSERR_IO; 503 nr = -errno_NFSERR_IO;
@@ -518,7 +537,7 @@ nfs_xdr_stat(struct rpc_rqst *req, __be32 *p, void *dummy)
518 int status; 537 int status;
519 538
520 if ((status = ntohl(*p++)) != 0) 539 if ((status = ntohl(*p++)) != 0)
521 status = -nfs_stat_to_errno(status); 540 status = nfs_stat_to_errno(status);
522 return status; 541 return status;
523} 542}
524 543
@@ -532,7 +551,7 @@ nfs_xdr_attrstat(struct rpc_rqst *req, __be32 *p, struct nfs_fattr *fattr)
532 int status; 551 int status;
533 552
534 if ((status = ntohl(*p++))) 553 if ((status = ntohl(*p++)))
535 return -nfs_stat_to_errno(status); 554 return nfs_stat_to_errno(status);
536 xdr_decode_fattr(p, fattr); 555 xdr_decode_fattr(p, fattr);
537 return 0; 556 return 0;
538} 557}
@@ -547,7 +566,7 @@ nfs_xdr_diropres(struct rpc_rqst *req, __be32 *p, struct nfs_diropok *res)
547 int status; 566 int status;
548 567
549 if ((status = ntohl(*p++))) 568 if ((status = ntohl(*p++)))
550 return -nfs_stat_to_errno(status); 569 return nfs_stat_to_errno(status);
551 p = xdr_decode_fhandle(p, res->fh); 570 p = xdr_decode_fhandle(p, res->fh);
552 xdr_decode_fattr(p, res->fattr); 571 xdr_decode_fattr(p, res->fattr);
553 return 0; 572 return 0;
@@ -585,7 +604,7 @@ nfs_xdr_readlinkres(struct rpc_rqst *req, __be32 *p, void *dummy)
585 int status; 604 int status;
586 605
587 if ((status = ntohl(*p++))) 606 if ((status = ntohl(*p++)))
588 return -nfs_stat_to_errno(status); 607 return nfs_stat_to_errno(status);
589 /* Convert length of symlink */ 608 /* Convert length of symlink */
590 len = ntohl(*p++); 609 len = ntohl(*p++);
591 if (len >= rcvbuf->page_len) { 610 if (len >= rcvbuf->page_len) {
@@ -634,7 +653,7 @@ nfs_xdr_statfsres(struct rpc_rqst *req, __be32 *p, struct nfs2_fsstat *res)
634 int status; 653 int status;
635 654
636 if ((status = ntohl(*p++))) 655 if ((status = ntohl(*p++)))
637 return -nfs_stat_to_errno(status); 656 return nfs_stat_to_errno(status);
638 657
639 res->tsize = ntohl(*p++); 658 res->tsize = ntohl(*p++);
640 res->bsize = ntohl(*p++); 659 res->bsize = ntohl(*p++);
@@ -653,39 +672,39 @@ static struct {
653 int errno; 672 int errno;
654} nfs_errtbl[] = { 673} nfs_errtbl[] = {
655 { NFS_OK, 0 }, 674 { NFS_OK, 0 },
656 { NFSERR_PERM, EPERM }, 675 { NFSERR_PERM, -EPERM },
657 { NFSERR_NOENT, ENOENT }, 676 { NFSERR_NOENT, -ENOENT },
658 { NFSERR_IO, errno_NFSERR_IO }, 677 { NFSERR_IO, -errno_NFSERR_IO},
659 { NFSERR_NXIO, ENXIO }, 678 { NFSERR_NXIO, -ENXIO },
660/* { NFSERR_EAGAIN, EAGAIN }, */ 679/* { NFSERR_EAGAIN, -EAGAIN }, */
661 { NFSERR_ACCES, EACCES }, 680 { NFSERR_ACCES, -EACCES },
662 { NFSERR_EXIST, EEXIST }, 681 { NFSERR_EXIST, -EEXIST },
663 { NFSERR_XDEV, EXDEV }, 682 { NFSERR_XDEV, -EXDEV },
664 { NFSERR_NODEV, ENODEV }, 683 { NFSERR_NODEV, -ENODEV },
665 { NFSERR_NOTDIR, ENOTDIR }, 684 { NFSERR_NOTDIR, -ENOTDIR },
666 { NFSERR_ISDIR, EISDIR }, 685 { NFSERR_ISDIR, -EISDIR },
667 { NFSERR_INVAL, EINVAL }, 686 { NFSERR_INVAL, -EINVAL },
668 { NFSERR_FBIG, EFBIG }, 687 { NFSERR_FBIG, -EFBIG },
669 { NFSERR_NOSPC, ENOSPC }, 688 { NFSERR_NOSPC, -ENOSPC },
670 { NFSERR_ROFS, EROFS }, 689 { NFSERR_ROFS, -EROFS },
671 { NFSERR_MLINK, EMLINK }, 690 { NFSERR_MLINK, -EMLINK },
672 { NFSERR_NAMETOOLONG, ENAMETOOLONG }, 691 { NFSERR_NAMETOOLONG, -ENAMETOOLONG },
673 { NFSERR_NOTEMPTY, ENOTEMPTY }, 692 { NFSERR_NOTEMPTY, -ENOTEMPTY },
674 { NFSERR_DQUOT, EDQUOT }, 693 { NFSERR_DQUOT, -EDQUOT },
675 { NFSERR_STALE, ESTALE }, 694 { NFSERR_STALE, -ESTALE },
676 { NFSERR_REMOTE, EREMOTE }, 695 { NFSERR_REMOTE, -EREMOTE },
677#ifdef EWFLUSH 696#ifdef EWFLUSH
678 { NFSERR_WFLUSH, EWFLUSH }, 697 { NFSERR_WFLUSH, -EWFLUSH },
679#endif 698#endif
680 { NFSERR_BADHANDLE, EBADHANDLE }, 699 { NFSERR_BADHANDLE, -EBADHANDLE },
681 { NFSERR_NOT_SYNC, ENOTSYNC }, 700 { NFSERR_NOT_SYNC, -ENOTSYNC },
682 { NFSERR_BAD_COOKIE, EBADCOOKIE }, 701 { NFSERR_BAD_COOKIE, -EBADCOOKIE },
683 { NFSERR_NOTSUPP, ENOTSUPP }, 702 { NFSERR_NOTSUPP, -ENOTSUPP },
684 { NFSERR_TOOSMALL, ETOOSMALL }, 703 { NFSERR_TOOSMALL, -ETOOSMALL },
685 { NFSERR_SERVERFAULT, ESERVERFAULT }, 704 { NFSERR_SERVERFAULT, -ESERVERFAULT },
686 { NFSERR_BADTYPE, EBADTYPE }, 705 { NFSERR_BADTYPE, -EBADTYPE },
687 { NFSERR_JUKEBOX, EJUKEBOX }, 706 { NFSERR_JUKEBOX, -EJUKEBOX },
688 { -1, EIO } 707 { -1, -EIO }
689}; 708};
690 709
691/* 710/*
diff --git a/fs/nfs/nfs3xdr.c b/fs/nfs/nfs3xdr.c
index 3917e2fa4e40..11cdddec1432 100644
--- a/fs/nfs/nfs3xdr.c
+++ b/fs/nfs/nfs3xdr.c
@@ -508,14 +508,14 @@ nfs3_xdr_readdirres(struct rpc_rqst *req, __be32 *p, struct nfs3_readdirres *res
508 struct page **page; 508 struct page **page;
509 size_t hdrlen; 509 size_t hdrlen;
510 u32 len, recvd, pglen; 510 u32 len, recvd, pglen;
511 int status, nr; 511 int status, nr = 0;
512 __be32 *entry, *end, *kaddr; 512 __be32 *entry, *end, *kaddr;
513 513
514 status = ntohl(*p++); 514 status = ntohl(*p++);
515 /* Decode post_op_attrs */ 515 /* Decode post_op_attrs */
516 p = xdr_decode_post_op_attr(p, res->dir_attr); 516 p = xdr_decode_post_op_attr(p, res->dir_attr);
517 if (status) 517 if (status)
518 return -nfs_stat_to_errno(status); 518 return nfs_stat_to_errno(status);
519 /* Decode verifier cookie */ 519 /* Decode verifier cookie */
520 if (res->verf) { 520 if (res->verf) {
521 res->verf[0] = *p++; 521 res->verf[0] = *p++;
@@ -542,7 +542,12 @@ nfs3_xdr_readdirres(struct rpc_rqst *req, __be32 *p, struct nfs3_readdirres *res
542 kaddr = p = kmap_atomic(*page, KM_USER0); 542 kaddr = p = kmap_atomic(*page, KM_USER0);
543 end = (__be32 *)((char *)p + pglen); 543 end = (__be32 *)((char *)p + pglen);
544 entry = p; 544 entry = p;
545 for (nr = 0; *p++; nr++) { 545
546 /* Make sure the packet actually has a value_follows and EOF entry */
547 if ((entry + 1) > end)
548 goto short_pkt;
549
550 for (; *p++; nr++) {
546 if (p + 3 > end) 551 if (p + 3 > end)
547 goto short_pkt; 552 goto short_pkt;
548 p += 2; /* inode # */ 553 p += 2; /* inode # */
@@ -581,18 +586,32 @@ nfs3_xdr_readdirres(struct rpc_rqst *req, __be32 *p, struct nfs3_readdirres *res
581 goto short_pkt; 586 goto short_pkt;
582 entry = p; 587 entry = p;
583 } 588 }
584 if (!nr && (entry[0] != 0 || entry[1] == 0)) 589
585 goto short_pkt; 590 /*
591 * Apparently some server sends responses that are a valid size, but
592 * contain no entries, and have value_follows==0 and EOF==0. For
593 * those, just set the EOF marker.
594 */
595 if (!nr && entry[1] == 0) {
596 dprintk("NFS: readdir reply truncated!\n");
597 entry[1] = 1;
598 }
586 out: 599 out:
587 kunmap_atomic(kaddr, KM_USER0); 600 kunmap_atomic(kaddr, KM_USER0);
588 return nr; 601 return nr;
589 short_pkt: 602 short_pkt:
603 /*
604 * When we get a short packet there are 2 possibilities. We can
605 * return an error, or fix up the response to look like a valid
606 * response and return what we have so far. If there are no
607 * entries and the packet was short, then return -EIO. If there
608 * are valid entries in the response, return them and pretend that
609 * the call was successful, but incomplete. The caller can retry the
610 * readdir starting at the last cookie.
611 */
590 entry[0] = entry[1] = 0; 612 entry[0] = entry[1] = 0;
591 /* truncate listing ? */ 613 if (!nr)
592 if (!nr) { 614 nr = -errno_NFSERR_IO;
593 dprintk("NFS: readdir reply truncated!\n");
594 entry[1] = 1;
595 }
596 goto out; 615 goto out;
597err_unmap: 616err_unmap:
598 nr = -errno_NFSERR_IO; 617 nr = -errno_NFSERR_IO;
@@ -732,7 +751,7 @@ nfs3_xdr_attrstat(struct rpc_rqst *req, __be32 *p, struct nfs_fattr *fattr)
732 int status; 751 int status;
733 752
734 if ((status = ntohl(*p++))) 753 if ((status = ntohl(*p++)))
735 return -nfs_stat_to_errno(status); 754 return nfs_stat_to_errno(status);
736 xdr_decode_fattr(p, fattr); 755 xdr_decode_fattr(p, fattr);
737 return 0; 756 return 0;
738} 757}
@@ -747,7 +766,7 @@ nfs3_xdr_wccstat(struct rpc_rqst *req, __be32 *p, struct nfs_fattr *fattr)
747 int status; 766 int status;
748 767
749 if ((status = ntohl(*p++))) 768 if ((status = ntohl(*p++)))
750 status = -nfs_stat_to_errno(status); 769 status = nfs_stat_to_errno(status);
751 xdr_decode_wcc_data(p, fattr); 770 xdr_decode_wcc_data(p, fattr);
752 return status; 771 return status;
753} 772}
@@ -767,7 +786,7 @@ nfs3_xdr_lookupres(struct rpc_rqst *req, __be32 *p, struct nfs3_diropres *res)
767 int status; 786 int status;
768 787
769 if ((status = ntohl(*p++))) { 788 if ((status = ntohl(*p++))) {
770 status = -nfs_stat_to_errno(status); 789 status = nfs_stat_to_errno(status);
771 } else { 790 } else {
772 if (!(p = xdr_decode_fhandle(p, res->fh))) 791 if (!(p = xdr_decode_fhandle(p, res->fh)))
773 return -errno_NFSERR_IO; 792 return -errno_NFSERR_IO;
@@ -787,7 +806,7 @@ nfs3_xdr_accessres(struct rpc_rqst *req, __be32 *p, struct nfs3_accessres *res)
787 806
788 p = xdr_decode_post_op_attr(p, res->fattr); 807 p = xdr_decode_post_op_attr(p, res->fattr);
789 if (status) 808 if (status)
790 return -nfs_stat_to_errno(status); 809 return nfs_stat_to_errno(status);
791 res->access = ntohl(*p++); 810 res->access = ntohl(*p++);
792 return 0; 811 return 0;
793} 812}
@@ -824,7 +843,7 @@ nfs3_xdr_readlinkres(struct rpc_rqst *req, __be32 *p, struct nfs_fattr *fattr)
824 p = xdr_decode_post_op_attr(p, fattr); 843 p = xdr_decode_post_op_attr(p, fattr);
825 844
826 if (status != 0) 845 if (status != 0)
827 return -nfs_stat_to_errno(status); 846 return nfs_stat_to_errno(status);
828 847
829 /* Convert length of symlink */ 848 /* Convert length of symlink */
830 len = ntohl(*p++); 849 len = ntohl(*p++);
@@ -872,7 +891,7 @@ nfs3_xdr_readres(struct rpc_rqst *req, __be32 *p, struct nfs_readres *res)
872 p = xdr_decode_post_op_attr(p, res->fattr); 891 p = xdr_decode_post_op_attr(p, res->fattr);
873 892
874 if (status != 0) 893 if (status != 0)
875 return -nfs_stat_to_errno(status); 894 return nfs_stat_to_errno(status);
876 895
877 /* Decode reply count and EOF flag. NFSv3 is somewhat redundant 896 /* Decode reply count and EOF flag. NFSv3 is somewhat redundant
878 * in that it puts the count both in the res struct and in the 897 * in that it puts the count both in the res struct and in the
@@ -922,7 +941,7 @@ nfs3_xdr_writeres(struct rpc_rqst *req, __be32 *p, struct nfs_writeres *res)
922 p = xdr_decode_wcc_data(p, res->fattr); 941 p = xdr_decode_wcc_data(p, res->fattr);
923 942
924 if (status != 0) 943 if (status != 0)
925 return -nfs_stat_to_errno(status); 944 return nfs_stat_to_errno(status);
926 945
927 res->count = ntohl(*p++); 946 res->count = ntohl(*p++);
928 res->verf->committed = (enum nfs3_stable_how)ntohl(*p++); 947 res->verf->committed = (enum nfs3_stable_how)ntohl(*p++);
@@ -953,7 +972,7 @@ nfs3_xdr_createres(struct rpc_rqst *req, __be32 *p, struct nfs3_diropres *res)
953 res->fattr->valid = 0; 972 res->fattr->valid = 0;
954 } 973 }
955 } else { 974 } else {
956 status = -nfs_stat_to_errno(status); 975 status = nfs_stat_to_errno(status);
957 } 976 }
958 p = xdr_decode_wcc_data(p, res->dir_attr); 977 p = xdr_decode_wcc_data(p, res->dir_attr);
959 return status; 978 return status;
@@ -968,7 +987,7 @@ nfs3_xdr_renameres(struct rpc_rqst *req, __be32 *p, struct nfs3_renameres *res)
968 int status; 987 int status;
969 988
970 if ((status = ntohl(*p++)) != 0) 989 if ((status = ntohl(*p++)) != 0)
971 status = -nfs_stat_to_errno(status); 990 status = nfs_stat_to_errno(status);
972 p = xdr_decode_wcc_data(p, res->fromattr); 991 p = xdr_decode_wcc_data(p, res->fromattr);
973 p = xdr_decode_wcc_data(p, res->toattr); 992 p = xdr_decode_wcc_data(p, res->toattr);
974 return status; 993 return status;
@@ -983,7 +1002,7 @@ nfs3_xdr_linkres(struct rpc_rqst *req, __be32 *p, struct nfs3_linkres *res)
983 int status; 1002 int status;
984 1003
985 if ((status = ntohl(*p++)) != 0) 1004 if ((status = ntohl(*p++)) != 0)
986 status = -nfs_stat_to_errno(status); 1005 status = nfs_stat_to_errno(status);
987 p = xdr_decode_post_op_attr(p, res->fattr); 1006 p = xdr_decode_post_op_attr(p, res->fattr);
988 p = xdr_decode_wcc_data(p, res->dir_attr); 1007 p = xdr_decode_wcc_data(p, res->dir_attr);
989 return status; 1008 return status;
@@ -1001,7 +1020,7 @@ nfs3_xdr_fsstatres(struct rpc_rqst *req, __be32 *p, struct nfs_fsstat *res)
1001 1020
1002 p = xdr_decode_post_op_attr(p, res->fattr); 1021 p = xdr_decode_post_op_attr(p, res->fattr);
1003 if (status != 0) 1022 if (status != 0)
1004 return -nfs_stat_to_errno(status); 1023 return nfs_stat_to_errno(status);
1005 1024
1006 p = xdr_decode_hyper(p, &res->tbytes); 1025 p = xdr_decode_hyper(p, &res->tbytes);
1007 p = xdr_decode_hyper(p, &res->fbytes); 1026 p = xdr_decode_hyper(p, &res->fbytes);
@@ -1026,7 +1045,7 @@ nfs3_xdr_fsinfores(struct rpc_rqst *req, __be32 *p, struct nfs_fsinfo *res)
1026 1045
1027 p = xdr_decode_post_op_attr(p, res->fattr); 1046 p = xdr_decode_post_op_attr(p, res->fattr);
1028 if (status != 0) 1047 if (status != 0)
1029 return -nfs_stat_to_errno(status); 1048 return nfs_stat_to_errno(status);
1030 1049
1031 res->rtmax = ntohl(*p++); 1050 res->rtmax = ntohl(*p++);
1032 res->rtpref = ntohl(*p++); 1051 res->rtpref = ntohl(*p++);
@@ -1054,7 +1073,7 @@ nfs3_xdr_pathconfres(struct rpc_rqst *req, __be32 *p, struct nfs_pathconf *res)
1054 1073
1055 p = xdr_decode_post_op_attr(p, res->fattr); 1074 p = xdr_decode_post_op_attr(p, res->fattr);
1056 if (status != 0) 1075 if (status != 0)
1057 return -nfs_stat_to_errno(status); 1076 return nfs_stat_to_errno(status);
1058 res->max_link = ntohl(*p++); 1077 res->max_link = ntohl(*p++);
1059 res->max_namelen = ntohl(*p++); 1078 res->max_namelen = ntohl(*p++);
1060 1079
@@ -1073,7 +1092,7 @@ nfs3_xdr_commitres(struct rpc_rqst *req, __be32 *p, struct nfs_writeres *res)
1073 status = ntohl(*p++); 1092 status = ntohl(*p++);
1074 p = xdr_decode_wcc_data(p, res->fattr); 1093 p = xdr_decode_wcc_data(p, res->fattr);
1075 if (status != 0) 1094 if (status != 0)
1076 return -nfs_stat_to_errno(status); 1095 return nfs_stat_to_errno(status);
1077 1096
1078 res->verf->verifier[0] = *p++; 1097 res->verf->verifier[0] = *p++;
1079 res->verf->verifier[1] = *p++; 1098 res->verf->verifier[1] = *p++;
@@ -1095,7 +1114,7 @@ nfs3_xdr_getaclres(struct rpc_rqst *req, __be32 *p,
1095 int err, base; 1114 int err, base;
1096 1115
1097 if (status != 0) 1116 if (status != 0)
1098 return -nfs_stat_to_errno(status); 1117 return nfs_stat_to_errno(status);
1099 p = xdr_decode_post_op_attr(p, res->fattr); 1118 p = xdr_decode_post_op_attr(p, res->fattr);
1100 res->mask = ntohl(*p++); 1119 res->mask = ntohl(*p++);
1101 if (res->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT)) 1120 if (res->mask & ~(NFS_ACL|NFS_ACLCNT|NFS_DFACL|NFS_DFACLCNT))
@@ -1122,7 +1141,7 @@ nfs3_xdr_setaclres(struct rpc_rqst *req, __be32 *p, struct nfs_fattr *fattr)
1122 int status = ntohl(*p++); 1141 int status = ntohl(*p++);
1123 1142
1124 if (status) 1143 if (status)
1125 return -nfs_stat_to_errno(status); 1144 return nfs_stat_to_errno(status);
1126 xdr_decode_post_op_attr(p, fattr); 1145 xdr_decode_post_op_attr(p, fattr);
1127 return 0; 1146 return 0;
1128} 1147}
diff --git a/fs/nfs/nfs4proc.c b/fs/nfs/nfs4proc.c
index 7ce07862c2fb..dbc09271af02 100644
--- a/fs/nfs/nfs4proc.c
+++ b/fs/nfs/nfs4proc.c
@@ -51,6 +51,7 @@
51 51
52#include "nfs4_fs.h" 52#include "nfs4_fs.h"
53#include "delegation.h" 53#include "delegation.h"
54#include "internal.h"
54#include "iostat.h" 55#include "iostat.h"
55 56
56#define NFSDBG_FACILITY NFSDBG_PROC 57#define NFSDBG_FACILITY NFSDBG_PROC
@@ -239,6 +240,8 @@ static void nfs4_init_opendata_res(struct nfs4_opendata *p)
239{ 240{
240 p->o_res.f_attr = &p->f_attr; 241 p->o_res.f_attr = &p->f_attr;
241 p->o_res.dir_attr = &p->dir_attr; 242 p->o_res.dir_attr = &p->dir_attr;
243 p->o_res.seqid = p->o_arg.seqid;
244 p->c_res.seqid = p->c_arg.seqid;
242 p->o_res.server = p->o_arg.server; 245 p->o_res.server = p->o_arg.server;
243 nfs_fattr_init(&p->f_attr); 246 nfs_fattr_init(&p->f_attr);
244 nfs_fattr_init(&p->dir_attr); 247 nfs_fattr_init(&p->dir_attr);
@@ -729,7 +732,6 @@ static void nfs4_open_confirm_done(struct rpc_task *task, void *calldata)
729 renew_lease(data->o_res.server, data->timestamp); 732 renew_lease(data->o_res.server, data->timestamp);
730 data->rpc_done = 1; 733 data->rpc_done = 1;
731 } 734 }
732 nfs_increment_open_seqid(data->rpc_status, data->c_arg.seqid);
733} 735}
734 736
735static void nfs4_open_confirm_release(void *calldata) 737static void nfs4_open_confirm_release(void *calldata)
@@ -773,6 +775,7 @@ static int _nfs4_proc_open_confirm(struct nfs4_opendata *data)
773 .rpc_message = &msg, 775 .rpc_message = &msg,
774 .callback_ops = &nfs4_open_confirm_ops, 776 .callback_ops = &nfs4_open_confirm_ops,
775 .callback_data = data, 777 .callback_data = data,
778 .workqueue = nfsiod_workqueue,
776 .flags = RPC_TASK_ASYNC, 779 .flags = RPC_TASK_ASYNC,
777 }; 780 };
778 int status; 781 int status;
@@ -858,7 +861,6 @@ static void nfs4_open_done(struct rpc_task *task, void *calldata)
858 if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM)) 861 if (!(data->o_res.rflags & NFS4_OPEN_RESULT_CONFIRM))
859 nfs_confirm_seqid(&data->owner->so_seqid, 0); 862 nfs_confirm_seqid(&data->owner->so_seqid, 0);
860 } 863 }
861 nfs_increment_open_seqid(data->rpc_status, data->o_arg.seqid);
862 data->rpc_done = 1; 864 data->rpc_done = 1;
863} 865}
864 866
@@ -910,6 +912,7 @@ static int _nfs4_proc_open(struct nfs4_opendata *data)
910 .rpc_message = &msg, 912 .rpc_message = &msg,
911 .callback_ops = &nfs4_open_ops, 913 .callback_ops = &nfs4_open_ops,
912 .callback_data = data, 914 .callback_data = data,
915 .workqueue = nfsiod_workqueue,
913 .flags = RPC_TASK_ASYNC, 916 .flags = RPC_TASK_ASYNC,
914 }; 917 };
915 int status; 918 int status;
@@ -979,11 +982,8 @@ static int _nfs4_open_expired(struct nfs_open_context *ctx, struct nfs4_state *s
979 if (IS_ERR(opendata)) 982 if (IS_ERR(opendata))
980 return PTR_ERR(opendata); 983 return PTR_ERR(opendata);
981 ret = nfs4_open_recover(opendata, state); 984 ret = nfs4_open_recover(opendata, state);
982 if (ret == -ESTALE) { 985 if (ret == -ESTALE)
983 /* Invalidate the state owner so we don't ever use it again */
984 nfs4_drop_state_owner(state->owner);
985 d_drop(ctx->path.dentry); 986 d_drop(ctx->path.dentry);
986 }
987 nfs4_opendata_put(opendata); 987 nfs4_opendata_put(opendata);
988 return ret; 988 return ret;
989} 989}
@@ -1226,7 +1226,6 @@ static void nfs4_close_done(struct rpc_task *task, void *data)
1226 /* hmm. we are done with the inode, and in the process of freeing 1226 /* hmm. we are done with the inode, and in the process of freeing
1227 * the state_owner. we keep this around to process errors 1227 * the state_owner. we keep this around to process errors
1228 */ 1228 */
1229 nfs_increment_open_seqid(task->tk_status, calldata->arg.seqid);
1230 switch (task->tk_status) { 1229 switch (task->tk_status) {
1231 case 0: 1230 case 0:
1232 nfs_set_open_stateid(state, &calldata->res.stateid, 0); 1231 nfs_set_open_stateid(state, &calldata->res.stateid, 0);
@@ -1315,6 +1314,7 @@ int nfs4_do_close(struct path *path, struct nfs4_state *state, int wait)
1315 .rpc_client = server->client, 1314 .rpc_client = server->client,
1316 .rpc_message = &msg, 1315 .rpc_message = &msg,
1317 .callback_ops = &nfs4_close_ops, 1316 .callback_ops = &nfs4_close_ops,
1317 .workqueue = nfsiod_workqueue,
1318 .flags = RPC_TASK_ASYNC, 1318 .flags = RPC_TASK_ASYNC,
1319 }; 1319 };
1320 int status = -ENOMEM; 1320 int status = -ENOMEM;
@@ -1332,6 +1332,7 @@ int nfs4_do_close(struct path *path, struct nfs4_state *state, int wait)
1332 goto out_free_calldata; 1332 goto out_free_calldata;
1333 calldata->arg.bitmask = server->attr_bitmask; 1333 calldata->arg.bitmask = server->attr_bitmask;
1334 calldata->res.fattr = &calldata->fattr; 1334 calldata->res.fattr = &calldata->fattr;
1335 calldata->res.seqid = calldata->arg.seqid;
1335 calldata->res.server = server; 1336 calldata->res.server = server;
1336 calldata->path.mnt = mntget(path->mnt); 1337 calldata->path.mnt = mntget(path->mnt);
1337 calldata->path.dentry = dget(path->dentry); 1338 calldata->path.dentry = dget(path->dentry);
@@ -1404,7 +1405,7 @@ nfs4_atomic_open(struct inode *dir, struct dentry *dentry, struct nameidata *nd)
1404 BUG_ON(nd->intent.open.flags & O_CREAT); 1405 BUG_ON(nd->intent.open.flags & O_CREAT);
1405 } 1406 }
1406 1407
1407 cred = rpcauth_lookupcred(NFS_CLIENT(dir)->cl_auth, 0); 1408 cred = rpc_lookup_cred();
1408 if (IS_ERR(cred)) 1409 if (IS_ERR(cred))
1409 return (struct dentry *)cred; 1410 return (struct dentry *)cred;
1410 parent = dentry->d_parent; 1411 parent = dentry->d_parent;
@@ -1439,7 +1440,7 @@ nfs4_open_revalidate(struct inode *dir, struct dentry *dentry, int openflags, st
1439 struct rpc_cred *cred; 1440 struct rpc_cred *cred;
1440 struct nfs4_state *state; 1441 struct nfs4_state *state;
1441 1442
1442 cred = rpcauth_lookupcred(NFS_CLIENT(dir)->cl_auth, 0); 1443 cred = rpc_lookup_cred();
1443 if (IS_ERR(cred)) 1444 if (IS_ERR(cred))
1444 return PTR_ERR(cred); 1445 return PTR_ERR(cred);
1445 state = nfs4_do_open(dir, &path, openflags, NULL, cred); 1446 state = nfs4_do_open(dir, &path, openflags, NULL, cred);
@@ -1656,7 +1657,7 @@ nfs4_proc_setattr(struct dentry *dentry, struct nfs_fattr *fattr,
1656 1657
1657 nfs_fattr_init(fattr); 1658 nfs_fattr_init(fattr);
1658 1659
1659 cred = rpcauth_lookupcred(NFS_CLIENT(inode)->cl_auth, 0); 1660 cred = rpc_lookup_cred();
1660 if (IS_ERR(cred)) 1661 if (IS_ERR(cred))
1661 return PTR_ERR(cred); 1662 return PTR_ERR(cred);
1662 1663
@@ -1892,7 +1893,7 @@ nfs4_proc_create(struct inode *dir, struct dentry *dentry, struct iattr *sattr,
1892 struct rpc_cred *cred; 1893 struct rpc_cred *cred;
1893 int status = 0; 1894 int status = 0;
1894 1895
1895 cred = rpcauth_lookupcred(NFS_CLIENT(dir)->cl_auth, 0); 1896 cred = rpc_lookup_cred();
1896 if (IS_ERR(cred)) { 1897 if (IS_ERR(cred)) {
1897 status = PTR_ERR(cred); 1898 status = PTR_ERR(cred);
1898 goto out; 1899 goto out;
@@ -2761,10 +2762,10 @@ nfs4_async_handle_error(struct rpc_task *task, const struct nfs_server *server)
2761 case -NFS4ERR_STALE_CLIENTID: 2762 case -NFS4ERR_STALE_CLIENTID:
2762 case -NFS4ERR_STALE_STATEID: 2763 case -NFS4ERR_STALE_STATEID:
2763 case -NFS4ERR_EXPIRED: 2764 case -NFS4ERR_EXPIRED:
2764 rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL, NULL); 2765 rpc_sleep_on(&clp->cl_rpcwaitq, task, NULL);
2765 nfs4_schedule_state_recovery(clp); 2766 nfs4_schedule_state_recovery(clp);
2766 if (test_bit(NFS4CLNT_STATE_RECOVER, &clp->cl_state) == 0) 2767 if (test_bit(NFS4CLNT_STATE_RECOVER, &clp->cl_state) == 0)
2767 rpc_wake_up_task(task); 2768 rpc_wake_up_queued_task(&clp->cl_rpcwaitq, task);
2768 task->tk_status = 0; 2769 task->tk_status = 0;
2769 return -EAGAIN; 2770 return -EAGAIN;
2770 case -NFS4ERR_DELAY: 2771 case -NFS4ERR_DELAY:
@@ -2884,7 +2885,7 @@ int nfs4_proc_setclientid(struct nfs_client *clp, u32 program, unsigned short po
2884 RPC_DISPLAY_ADDR), 2885 RPC_DISPLAY_ADDR),
2885 rpc_peeraddr2str(clp->cl_rpcclient, 2886 rpc_peeraddr2str(clp->cl_rpcclient,
2886 RPC_DISPLAY_PROTO), 2887 RPC_DISPLAY_PROTO),
2887 cred->cr_ops->cr_name, 2888 clp->cl_rpcclient->cl_auth->au_ops->au_name,
2888 clp->cl_id_uniquifier); 2889 clp->cl_id_uniquifier);
2889 setclientid.sc_netid_len = scnprintf(setclientid.sc_netid, 2890 setclientid.sc_netid_len = scnprintf(setclientid.sc_netid,
2890 sizeof(setclientid.sc_netid), 2891 sizeof(setclientid.sc_netid),
@@ -3158,6 +3159,7 @@ static struct nfs4_unlockdata *nfs4_alloc_unlockdata(struct file_lock *fl,
3158 p->arg.fh = NFS_FH(inode); 3159 p->arg.fh = NFS_FH(inode);
3159 p->arg.fl = &p->fl; 3160 p->arg.fl = &p->fl;
3160 p->arg.seqid = seqid; 3161 p->arg.seqid = seqid;
3162 p->res.seqid = seqid;
3161 p->arg.stateid = &lsp->ls_stateid; 3163 p->arg.stateid = &lsp->ls_stateid;
3162 p->lsp = lsp; 3164 p->lsp = lsp;
3163 atomic_inc(&lsp->ls_count); 3165 atomic_inc(&lsp->ls_count);
@@ -3183,7 +3185,6 @@ static void nfs4_locku_done(struct rpc_task *task, void *data)
3183 3185
3184 if (RPC_ASSASSINATED(task)) 3186 if (RPC_ASSASSINATED(task))
3185 return; 3187 return;
3186 nfs_increment_lock_seqid(task->tk_status, calldata->arg.seqid);
3187 switch (task->tk_status) { 3188 switch (task->tk_status) {
3188 case 0: 3189 case 0:
3189 memcpy(calldata->lsp->ls_stateid.data, 3190 memcpy(calldata->lsp->ls_stateid.data,
@@ -3235,6 +3236,7 @@ static struct rpc_task *nfs4_do_unlck(struct file_lock *fl,
3235 .rpc_client = NFS_CLIENT(lsp->ls_state->inode), 3236 .rpc_client = NFS_CLIENT(lsp->ls_state->inode),
3236 .rpc_message = &msg, 3237 .rpc_message = &msg,
3237 .callback_ops = &nfs4_locku_ops, 3238 .callback_ops = &nfs4_locku_ops,
3239 .workqueue = nfsiod_workqueue,
3238 .flags = RPC_TASK_ASYNC, 3240 .flags = RPC_TASK_ASYNC,
3239 }; 3241 };
3240 3242
@@ -3261,6 +3263,7 @@ static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *
3261 struct nfs4_lock_state *lsp; 3263 struct nfs4_lock_state *lsp;
3262 struct rpc_task *task; 3264 struct rpc_task *task;
3263 int status = 0; 3265 int status = 0;
3266 unsigned char fl_flags = request->fl_flags;
3264 3267
3265 status = nfs4_set_lock_state(state, request); 3268 status = nfs4_set_lock_state(state, request);
3266 /* Unlock _before_ we do the RPC call */ 3269 /* Unlock _before_ we do the RPC call */
@@ -3284,6 +3287,7 @@ static int nfs4_proc_unlck(struct nfs4_state *state, int cmd, struct file_lock *
3284 status = nfs4_wait_for_completion_rpc_task(task); 3287 status = nfs4_wait_for_completion_rpc_task(task);
3285 rpc_put_task(task); 3288 rpc_put_task(task);
3286out: 3289out:
3290 request->fl_flags = fl_flags;
3287 return status; 3291 return status;
3288} 3292}
3289 3293
@@ -3320,6 +3324,7 @@ static struct nfs4_lockdata *nfs4_alloc_lockdata(struct file_lock *fl,
3320 p->arg.lock_stateid = &lsp->ls_stateid; 3324 p->arg.lock_stateid = &lsp->ls_stateid;
3321 p->arg.lock_owner.clientid = server->nfs_client->cl_clientid; 3325 p->arg.lock_owner.clientid = server->nfs_client->cl_clientid;
3322 p->arg.lock_owner.id = lsp->ls_id.id; 3326 p->arg.lock_owner.id = lsp->ls_id.id;
3327 p->res.lock_seqid = p->arg.lock_seqid;
3323 p->lsp = lsp; 3328 p->lsp = lsp;
3324 atomic_inc(&lsp->ls_count); 3329 atomic_inc(&lsp->ls_count);
3325 p->ctx = get_nfs_open_context(ctx); 3330 p->ctx = get_nfs_open_context(ctx);
@@ -3346,6 +3351,7 @@ static void nfs4_lock_prepare(struct rpc_task *task, void *calldata)
3346 return; 3351 return;
3347 data->arg.open_stateid = &state->stateid; 3352 data->arg.open_stateid = &state->stateid;
3348 data->arg.new_lock_owner = 1; 3353 data->arg.new_lock_owner = 1;
3354 data->res.open_seqid = data->arg.open_seqid;
3349 } else 3355 } else
3350 data->arg.new_lock_owner = 0; 3356 data->arg.new_lock_owner = 0;
3351 data->timestamp = jiffies; 3357 data->timestamp = jiffies;
@@ -3363,7 +3369,6 @@ static void nfs4_lock_done(struct rpc_task *task, void *calldata)
3363 if (RPC_ASSASSINATED(task)) 3369 if (RPC_ASSASSINATED(task))
3364 goto out; 3370 goto out;
3365 if (data->arg.new_lock_owner != 0) { 3371 if (data->arg.new_lock_owner != 0) {
3366 nfs_increment_open_seqid(data->rpc_status, data->arg.open_seqid);
3367 if (data->rpc_status == 0) 3372 if (data->rpc_status == 0)
3368 nfs_confirm_seqid(&data->lsp->ls_seqid, 0); 3373 nfs_confirm_seqid(&data->lsp->ls_seqid, 0);
3369 else 3374 else
@@ -3375,7 +3380,6 @@ static void nfs4_lock_done(struct rpc_task *task, void *calldata)
3375 data->lsp->ls_flags |= NFS_LOCK_INITIALIZED; 3380 data->lsp->ls_flags |= NFS_LOCK_INITIALIZED;
3376 renew_lease(NFS_SERVER(data->ctx->path.dentry->d_inode), data->timestamp); 3381 renew_lease(NFS_SERVER(data->ctx->path.dentry->d_inode), data->timestamp);
3377 } 3382 }
3378 nfs_increment_lock_seqid(data->rpc_status, data->arg.lock_seqid);
3379out: 3383out:
3380 dprintk("%s: done, ret = %d!\n", __FUNCTION__, data->rpc_status); 3384 dprintk("%s: done, ret = %d!\n", __FUNCTION__, data->rpc_status);
3381} 3385}
@@ -3419,6 +3423,7 @@ static int _nfs4_do_setlk(struct nfs4_state *state, int cmd, struct file_lock *f
3419 .rpc_client = NFS_CLIENT(state->inode), 3423 .rpc_client = NFS_CLIENT(state->inode),
3420 .rpc_message = &msg, 3424 .rpc_message = &msg,
3421 .callback_ops = &nfs4_lock_ops, 3425 .callback_ops = &nfs4_lock_ops,
3426 .workqueue = nfsiod_workqueue,
3422 .flags = RPC_TASK_ASYNC, 3427 .flags = RPC_TASK_ASYNC,
3423 }; 3428 };
3424 int ret; 3429 int ret;
diff --git a/fs/nfs/nfs4state.c b/fs/nfs/nfs4state.c
index b962397004c1..46eb624e4f16 100644
--- a/fs/nfs/nfs4state.c
+++ b/fs/nfs/nfs4state.c
@@ -71,6 +71,29 @@ static int nfs4_init_client(struct nfs_client *clp, struct rpc_cred *cred)
71 return status; 71 return status;
72} 72}
73 73
74static struct rpc_cred *nfs4_get_machine_cred(struct nfs_client *clp)
75{
76 struct rpc_cred *cred = NULL;
77
78 spin_lock(&clp->cl_lock);
79 if (clp->cl_machine_cred != NULL)
80 cred = get_rpccred(clp->cl_machine_cred);
81 spin_unlock(&clp->cl_lock);
82 return cred;
83}
84
85static void nfs4_clear_machine_cred(struct nfs_client *clp)
86{
87 struct rpc_cred *cred;
88
89 spin_lock(&clp->cl_lock);
90 cred = clp->cl_machine_cred;
91 clp->cl_machine_cred = NULL;
92 spin_unlock(&clp->cl_lock);
93 if (cred != NULL)
94 put_rpccred(cred);
95}
96
74struct rpc_cred *nfs4_get_renew_cred(struct nfs_client *clp) 97struct rpc_cred *nfs4_get_renew_cred(struct nfs_client *clp)
75{ 98{
76 struct nfs4_state_owner *sp; 99 struct nfs4_state_owner *sp;
@@ -91,13 +114,18 @@ static struct rpc_cred *nfs4_get_setclientid_cred(struct nfs_client *clp)
91{ 114{
92 struct nfs4_state_owner *sp; 115 struct nfs4_state_owner *sp;
93 struct rb_node *pos; 116 struct rb_node *pos;
117 struct rpc_cred *cred;
94 118
119 cred = nfs4_get_machine_cred(clp);
120 if (cred != NULL)
121 goto out;
95 pos = rb_first(&clp->cl_state_owners); 122 pos = rb_first(&clp->cl_state_owners);
96 if (pos != NULL) { 123 if (pos != NULL) {
97 sp = rb_entry(pos, struct nfs4_state_owner, so_client_node); 124 sp = rb_entry(pos, struct nfs4_state_owner, so_client_node);
98 return get_rpccred(sp->so_cred); 125 cred = get_rpccred(sp->so_cred);
99 } 126 }
100 return NULL; 127out:
128 return cred;
101} 129}
102 130
103static void nfs_alloc_unique_id(struct rb_root *root, struct nfs_unique_id *new, 131static void nfs_alloc_unique_id(struct rb_root *root, struct nfs_unique_id *new,
@@ -292,8 +320,10 @@ struct nfs4_state_owner *nfs4_get_state_owner(struct nfs_server *server, struct
292 spin_unlock(&clp->cl_lock); 320 spin_unlock(&clp->cl_lock);
293 if (sp == new) 321 if (sp == new)
294 get_rpccred(cred); 322 get_rpccred(cred);
295 else 323 else {
324 rpc_destroy_wait_queue(&new->so_sequence.wait);
296 kfree(new); 325 kfree(new);
326 }
297 return sp; 327 return sp;
298} 328}
299 329
@@ -310,6 +340,7 @@ void nfs4_put_state_owner(struct nfs4_state_owner *sp)
310 return; 340 return;
311 nfs4_remove_state_owner(clp, sp); 341 nfs4_remove_state_owner(clp, sp);
312 spin_unlock(&clp->cl_lock); 342 spin_unlock(&clp->cl_lock);
343 rpc_destroy_wait_queue(&sp->so_sequence.wait);
313 put_rpccred(cred); 344 put_rpccred(cred);
314 kfree(sp); 345 kfree(sp);
315} 346}
@@ -529,6 +560,7 @@ static void nfs4_free_lock_state(struct nfs4_lock_state *lsp)
529 spin_lock(&clp->cl_lock); 560 spin_lock(&clp->cl_lock);
530 nfs_free_unique_id(&clp->cl_lockowner_id, &lsp->ls_id); 561 nfs_free_unique_id(&clp->cl_lockowner_id, &lsp->ls_id);
531 spin_unlock(&clp->cl_lock); 562 spin_unlock(&clp->cl_lock);
563 rpc_destroy_wait_queue(&lsp->ls_sequence.wait);
532 kfree(lsp); 564 kfree(lsp);
533} 565}
534 566
@@ -731,7 +763,7 @@ int nfs_wait_on_sequence(struct nfs_seqid *seqid, struct rpc_task *task)
731 list_add_tail(&seqid->list, &sequence->list); 763 list_add_tail(&seqid->list, &sequence->list);
732 if (list_first_entry(&sequence->list, struct nfs_seqid, list) == seqid) 764 if (list_first_entry(&sequence->list, struct nfs_seqid, list) == seqid)
733 goto unlock; 765 goto unlock;
734 rpc_sleep_on(&sequence->wait, task, NULL, NULL); 766 rpc_sleep_on(&sequence->wait, task, NULL);
735 status = -EAGAIN; 767 status = -EAGAIN;
736unlock: 768unlock:
737 spin_unlock(&sequence->lock); 769 spin_unlock(&sequence->lock);
@@ -920,10 +952,10 @@ restart_loop:
920 if (cred != NULL) { 952 if (cred != NULL) {
921 /* Yes there are: try to renew the old lease */ 953 /* Yes there are: try to renew the old lease */
922 status = nfs4_proc_renew(clp, cred); 954 status = nfs4_proc_renew(clp, cred);
955 put_rpccred(cred);
923 switch (status) { 956 switch (status) {
924 case 0: 957 case 0:
925 case -NFS4ERR_CB_PATH_DOWN: 958 case -NFS4ERR_CB_PATH_DOWN:
926 put_rpccred(cred);
927 goto out; 959 goto out;
928 case -NFS4ERR_STALE_CLIENTID: 960 case -NFS4ERR_STALE_CLIENTID:
929 case -NFS4ERR_LEASE_MOVED: 961 case -NFS4ERR_LEASE_MOVED:
@@ -932,14 +964,19 @@ restart_loop:
932 } else { 964 } else {
933 /* "reboot" to ensure we clear all state on the server */ 965 /* "reboot" to ensure we clear all state on the server */
934 clp->cl_boot_time = CURRENT_TIME; 966 clp->cl_boot_time = CURRENT_TIME;
935 cred = nfs4_get_setclientid_cred(clp);
936 } 967 }
937 /* We're going to have to re-establish a clientid */ 968 /* We're going to have to re-establish a clientid */
938 nfs4_state_mark_reclaim(clp); 969 nfs4_state_mark_reclaim(clp);
939 status = -ENOENT; 970 status = -ENOENT;
971 cred = nfs4_get_setclientid_cred(clp);
940 if (cred != NULL) { 972 if (cred != NULL) {
941 status = nfs4_init_client(clp, cred); 973 status = nfs4_init_client(clp, cred);
942 put_rpccred(cred); 974 put_rpccred(cred);
975 /* Handle case where the user hasn't set up machine creds */
976 if (status == -EACCES && cred == clp->cl_machine_cred) {
977 nfs4_clear_machine_cred(clp);
978 goto restart_loop;
979 }
943 } 980 }
944 if (status) 981 if (status)
945 goto out_error; 982 goto out_error;
diff --git a/fs/nfs/nfs4xdr.c b/fs/nfs/nfs4xdr.c
index db1ed9c46ede..5a2d64927b35 100644
--- a/fs/nfs/nfs4xdr.c
+++ b/fs/nfs/nfs4xdr.c
@@ -110,7 +110,7 @@ static int nfs4_stat_to_errno(int);
110#define decode_savefh_maxsz (op_decode_hdr_maxsz) 110#define decode_savefh_maxsz (op_decode_hdr_maxsz)
111#define encode_restorefh_maxsz (op_encode_hdr_maxsz) 111#define encode_restorefh_maxsz (op_encode_hdr_maxsz)
112#define decode_restorefh_maxsz (op_decode_hdr_maxsz) 112#define decode_restorefh_maxsz (op_decode_hdr_maxsz)
113#define encode_fsinfo_maxsz (op_encode_hdr_maxsz + 2) 113#define encode_fsinfo_maxsz (encode_getattr_maxsz)
114#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11) 114#define decode_fsinfo_maxsz (op_decode_hdr_maxsz + 11)
115#define encode_renew_maxsz (op_encode_hdr_maxsz + 3) 115#define encode_renew_maxsz (op_encode_hdr_maxsz + 3)
116#define decode_renew_maxsz (op_decode_hdr_maxsz) 116#define decode_renew_maxsz (op_decode_hdr_maxsz)
@@ -1191,8 +1191,8 @@ static int encode_readdir(struct xdr_stream *xdr, const struct nfs4_readdir_arg
1191 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID; 1191 attrs[1] &= ~FATTR4_WORD1_MOUNTED_ON_FILEID;
1192 WRITE32(attrs[0] & readdir->bitmask[0]); 1192 WRITE32(attrs[0] & readdir->bitmask[0]);
1193 WRITE32(attrs[1] & readdir->bitmask[1]); 1193 WRITE32(attrs[1] & readdir->bitmask[1]);
1194 dprintk("%s: cookie = %Lu, verifier = 0x%x%x, bitmap = 0x%x%x\n", 1194 dprintk("%s: cookie = %Lu, verifier = %08x:%08x, bitmap = %08x:%08x\n",
1195 __FUNCTION__, 1195 __func__,
1196 (unsigned long long)readdir->cookie, 1196 (unsigned long long)readdir->cookie,
1197 ((u32 *)readdir->verifier.data)[0], 1197 ((u32 *)readdir->verifier.data)[0],
1198 ((u32 *)readdir->verifier.data)[1], 1198 ((u32 *)readdir->verifier.data)[1],
@@ -2241,7 +2241,7 @@ static int decode_op_hdr(struct xdr_stream *xdr, enum nfs_opnum4 expected)
2241 } 2241 }
2242 READ32(nfserr); 2242 READ32(nfserr);
2243 if (nfserr != NFS_OK) 2243 if (nfserr != NFS_OK)
2244 return -nfs4_stat_to_errno(nfserr); 2244 return nfs4_stat_to_errno(nfserr);
2245 return 0; 2245 return 0;
2246} 2246}
2247 2247
@@ -2291,7 +2291,7 @@ static int decode_attr_supported(struct xdr_stream *xdr, uint32_t *bitmap, uint3
2291 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS; 2291 bitmap[0] &= ~FATTR4_WORD0_SUPPORTED_ATTRS;
2292 } else 2292 } else
2293 bitmask[0] = bitmask[1] = 0; 2293 bitmask[0] = bitmask[1] = 0;
2294 dprintk("%s: bitmask=0x%x%x\n", __FUNCTION__, bitmask[0], bitmask[1]); 2294 dprintk("%s: bitmask=%08x:%08x\n", __func__, bitmask[0], bitmask[1]);
2295 return 0; 2295 return 0;
2296} 2296}
2297 2297
@@ -3005,6 +3005,8 @@ static int decode_close(struct xdr_stream *xdr, struct nfs_closeres *res)
3005 int status; 3005 int status;
3006 3006
3007 status = decode_op_hdr(xdr, OP_CLOSE); 3007 status = decode_op_hdr(xdr, OP_CLOSE);
3008 if (status != -EIO)
3009 nfs_increment_open_seqid(status, res->seqid);
3008 if (status) 3010 if (status)
3009 return status; 3011 return status;
3010 READ_BUF(NFS4_STATEID_SIZE); 3012 READ_BUF(NFS4_STATEID_SIZE);
@@ -3296,11 +3298,17 @@ static int decode_lock(struct xdr_stream *xdr, struct nfs_lock_res *res)
3296 int status; 3298 int status;
3297 3299
3298 status = decode_op_hdr(xdr, OP_LOCK); 3300 status = decode_op_hdr(xdr, OP_LOCK);
3301 if (status == -EIO)
3302 goto out;
3299 if (status == 0) { 3303 if (status == 0) {
3300 READ_BUF(NFS4_STATEID_SIZE); 3304 READ_BUF(NFS4_STATEID_SIZE);
3301 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE); 3305 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
3302 } else if (status == -NFS4ERR_DENIED) 3306 } else if (status == -NFS4ERR_DENIED)
3303 return decode_lock_denied(xdr, NULL); 3307 status = decode_lock_denied(xdr, NULL);
3308 if (res->open_seqid != NULL)
3309 nfs_increment_open_seqid(status, res->open_seqid);
3310 nfs_increment_lock_seqid(status, res->lock_seqid);
3311out:
3304 return status; 3312 return status;
3305} 3313}
3306 3314
@@ -3319,6 +3327,8 @@ static int decode_locku(struct xdr_stream *xdr, struct nfs_locku_res *res)
3319 int status; 3327 int status;
3320 3328
3321 status = decode_op_hdr(xdr, OP_LOCKU); 3329 status = decode_op_hdr(xdr, OP_LOCKU);
3330 if (status != -EIO)
3331 nfs_increment_lock_seqid(status, res->seqid);
3322 if (status == 0) { 3332 if (status == 0) {
3323 READ_BUF(NFS4_STATEID_SIZE); 3333 READ_BUF(NFS4_STATEID_SIZE);
3324 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE); 3334 COPYMEM(res->stateid.data, NFS4_STATEID_SIZE);
@@ -3384,6 +3394,8 @@ static int decode_open(struct xdr_stream *xdr, struct nfs_openres *res)
3384 int status; 3394 int status;
3385 3395
3386 status = decode_op_hdr(xdr, OP_OPEN); 3396 status = decode_op_hdr(xdr, OP_OPEN);
3397 if (status != -EIO)
3398 nfs_increment_open_seqid(status, res->seqid);
3387 if (status) 3399 if (status)
3388 return status; 3400 return status;
3389 READ_BUF(NFS4_STATEID_SIZE); 3401 READ_BUF(NFS4_STATEID_SIZE);
@@ -3416,6 +3428,8 @@ static int decode_open_confirm(struct xdr_stream *xdr, struct nfs_open_confirmre
3416 int status; 3428 int status;
3417 3429
3418 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM); 3430 status = decode_op_hdr(xdr, OP_OPEN_CONFIRM);
3431 if (status != -EIO)
3432 nfs_increment_open_seqid(status, res->seqid);
3419 if (status) 3433 if (status)
3420 return status; 3434 return status;
3421 READ_BUF(NFS4_STATEID_SIZE); 3435 READ_BUF(NFS4_STATEID_SIZE);
@@ -3429,6 +3443,8 @@ static int decode_open_downgrade(struct xdr_stream *xdr, struct nfs_closeres *re
3429 int status; 3443 int status;
3430 3444
3431 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE); 3445 status = decode_op_hdr(xdr, OP_OPEN_DOWNGRADE);
3446 if (status != -EIO)
3447 nfs_increment_open_seqid(status, res->seqid);
3432 if (status) 3448 if (status)
3433 return status; 3449 return status;
3434 READ_BUF(NFS4_STATEID_SIZE); 3450 READ_BUF(NFS4_STATEID_SIZE);
@@ -3481,7 +3497,7 @@ static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct n
3481 size_t hdrlen; 3497 size_t hdrlen;
3482 u32 recvd, pglen = rcvbuf->page_len; 3498 u32 recvd, pglen = rcvbuf->page_len;
3483 __be32 *end, *entry, *p, *kaddr; 3499 __be32 *end, *entry, *p, *kaddr;
3484 unsigned int nr; 3500 unsigned int nr = 0;
3485 int status; 3501 int status;
3486 3502
3487 status = decode_op_hdr(xdr, OP_READDIR); 3503 status = decode_op_hdr(xdr, OP_READDIR);
@@ -3489,8 +3505,8 @@ static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct n
3489 return status; 3505 return status;
3490 READ_BUF(8); 3506 READ_BUF(8);
3491 COPYMEM(readdir->verifier.data, 8); 3507 COPYMEM(readdir->verifier.data, 8);
3492 dprintk("%s: verifier = 0x%x%x\n", 3508 dprintk("%s: verifier = %08x:%08x\n",
3493 __FUNCTION__, 3509 __func__,
3494 ((u32 *)readdir->verifier.data)[0], 3510 ((u32 *)readdir->verifier.data)[0],
3495 ((u32 *)readdir->verifier.data)[1]); 3511 ((u32 *)readdir->verifier.data)[1]);
3496 3512
@@ -3505,7 +3521,12 @@ static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct n
3505 kaddr = p = kmap_atomic(page, KM_USER0); 3521 kaddr = p = kmap_atomic(page, KM_USER0);
3506 end = p + ((pglen + readdir->pgbase) >> 2); 3522 end = p + ((pglen + readdir->pgbase) >> 2);
3507 entry = p; 3523 entry = p;
3508 for (nr = 0; *p++; nr++) { 3524
3525 /* Make sure the packet actually has a value_follows and EOF entry */
3526 if ((entry + 1) > end)
3527 goto short_pkt;
3528
3529 for (; *p++; nr++) {
3509 u32 len, attrlen, xlen; 3530 u32 len, attrlen, xlen;
3510 if (end - p < 3) 3531 if (end - p < 3)
3511 goto short_pkt; 3532 goto short_pkt;
@@ -3532,20 +3553,32 @@ static int decode_readdir(struct xdr_stream *xdr, struct rpc_rqst *req, struct n
3532 p += attrlen; /* attributes */ 3553 p += attrlen; /* attributes */
3533 entry = p; 3554 entry = p;
3534 } 3555 }
3535 if (!nr && (entry[0] != 0 || entry[1] == 0)) 3556 /*
3536 goto short_pkt; 3557 * Apparently some server sends responses that are a valid size, but
3558 * contain no entries, and have value_follows==0 and EOF==0. For
3559 * those, just set the EOF marker.
3560 */
3561 if (!nr && entry[1] == 0) {
3562 dprintk("NFS: readdir reply truncated!\n");
3563 entry[1] = 1;
3564 }
3537out: 3565out:
3538 kunmap_atomic(kaddr, KM_USER0); 3566 kunmap_atomic(kaddr, KM_USER0);
3539 return 0; 3567 return 0;
3540short_pkt: 3568short_pkt:
3569 /*
3570 * When we get a short packet there are 2 possibilities. We can
3571 * return an error, or fix up the response to look like a valid
3572 * response and return what we have so far. If there are no
3573 * entries and the packet was short, then return -EIO. If there
3574 * are valid entries in the response, return them and pretend that
3575 * the call was successful, but incomplete. The caller can retry the
3576 * readdir starting at the last cookie.
3577 */
3541 dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr); 3578 dprintk("%s: short packet at entry %d\n", __FUNCTION__, nr);
3542 entry[0] = entry[1] = 0; 3579 entry[0] = entry[1] = 0;
3543 /* truncate listing ? */ 3580 if (nr)
3544 if (!nr) { 3581 goto out;
3545 dprintk("NFS: readdir reply truncated!\n");
3546 entry[1] = 1;
3547 }
3548 goto out;
3549err_unmap: 3582err_unmap:
3550 kunmap_atomic(kaddr, KM_USER0); 3583 kunmap_atomic(kaddr, KM_USER0);
3551 return -errno_NFSERR_IO; 3584 return -errno_NFSERR_IO;
@@ -3727,7 +3760,7 @@ static int decode_setclientid(struct xdr_stream *xdr, struct nfs_client *clp)
3727 READ_BUF(len); 3760 READ_BUF(len);
3728 return -NFSERR_CLID_INUSE; 3761 return -NFSERR_CLID_INUSE;
3729 } else 3762 } else
3730 return -nfs4_stat_to_errno(nfserr); 3763 return nfs4_stat_to_errno(nfserr);
3731 3764
3732 return 0; 3765 return 0;
3733} 3766}
@@ -4389,7 +4422,7 @@ static int nfs4_xdr_dec_fsinfo(struct rpc_rqst *req, __be32 *p, struct nfs_fsinf
4389 if (!status) 4422 if (!status)
4390 status = decode_fsinfo(&xdr, fsinfo); 4423 status = decode_fsinfo(&xdr, fsinfo);
4391 if (!status) 4424 if (!status)
4392 status = -nfs4_stat_to_errno(hdr.status); 4425 status = nfs4_stat_to_errno(hdr.status);
4393 return status; 4426 return status;
4394} 4427}
4395 4428
@@ -4479,7 +4512,7 @@ static int nfs4_xdr_dec_setclientid(struct rpc_rqst *req, __be32 *p,
4479 if (!status) 4512 if (!status)
4480 status = decode_setclientid(&xdr, clp); 4513 status = decode_setclientid(&xdr, clp);
4481 if (!status) 4514 if (!status)
4482 status = -nfs4_stat_to_errno(hdr.status); 4515 status = nfs4_stat_to_errno(hdr.status);
4483 return status; 4516 return status;
4484} 4517}
4485 4518
@@ -4501,7 +4534,7 @@ static int nfs4_xdr_dec_setclientid_confirm(struct rpc_rqst *req, __be32 *p, str
4501 if (!status) 4534 if (!status)
4502 status = decode_fsinfo(&xdr, fsinfo); 4535 status = decode_fsinfo(&xdr, fsinfo);
4503 if (!status) 4536 if (!status)
4504 status = -nfs4_stat_to_errno(hdr.status); 4537 status = nfs4_stat_to_errno(hdr.status);
4505 return status; 4538 return status;
4506} 4539}
4507 4540
@@ -4611,42 +4644,42 @@ static struct {
4611 int errno; 4644 int errno;
4612} nfs_errtbl[] = { 4645} nfs_errtbl[] = {
4613 { NFS4_OK, 0 }, 4646 { NFS4_OK, 0 },
4614 { NFS4ERR_PERM, EPERM }, 4647 { NFS4ERR_PERM, -EPERM },
4615 { NFS4ERR_NOENT, ENOENT }, 4648 { NFS4ERR_NOENT, -ENOENT },
4616 { NFS4ERR_IO, errno_NFSERR_IO }, 4649 { NFS4ERR_IO, -errno_NFSERR_IO},
4617 { NFS4ERR_NXIO, ENXIO }, 4650 { NFS4ERR_NXIO, -ENXIO },
4618 { NFS4ERR_ACCESS, EACCES }, 4651 { NFS4ERR_ACCESS, -EACCES },
4619 { NFS4ERR_EXIST, EEXIST }, 4652 { NFS4ERR_EXIST, -EEXIST },
4620 { NFS4ERR_XDEV, EXDEV }, 4653 { NFS4ERR_XDEV, -EXDEV },
4621 { NFS4ERR_NOTDIR, ENOTDIR }, 4654 { NFS4ERR_NOTDIR, -ENOTDIR },
4622 { NFS4ERR_ISDIR, EISDIR }, 4655 { NFS4ERR_ISDIR, -EISDIR },
4623 { NFS4ERR_INVAL, EINVAL }, 4656 { NFS4ERR_INVAL, -EINVAL },
4624 { NFS4ERR_FBIG, EFBIG }, 4657 { NFS4ERR_FBIG, -EFBIG },
4625 { NFS4ERR_NOSPC, ENOSPC }, 4658 { NFS4ERR_NOSPC, -ENOSPC },
4626 { NFS4ERR_ROFS, EROFS }, 4659 { NFS4ERR_ROFS, -EROFS },
4627 { NFS4ERR_MLINK, EMLINK }, 4660 { NFS4ERR_MLINK, -EMLINK },
4628 { NFS4ERR_NAMETOOLONG, ENAMETOOLONG }, 4661 { NFS4ERR_NAMETOOLONG, -ENAMETOOLONG },
4629 { NFS4ERR_NOTEMPTY, ENOTEMPTY }, 4662 { NFS4ERR_NOTEMPTY, -ENOTEMPTY },
4630 { NFS4ERR_DQUOT, EDQUOT }, 4663 { NFS4ERR_DQUOT, -EDQUOT },
4631 { NFS4ERR_STALE, ESTALE }, 4664 { NFS4ERR_STALE, -ESTALE },
4632 { NFS4ERR_BADHANDLE, EBADHANDLE }, 4665 { NFS4ERR_BADHANDLE, -EBADHANDLE },
4633 { NFS4ERR_BADOWNER, EINVAL }, 4666 { NFS4ERR_BADOWNER, -EINVAL },
4634 { NFS4ERR_BADNAME, EINVAL }, 4667 { NFS4ERR_BADNAME, -EINVAL },
4635 { NFS4ERR_BAD_COOKIE, EBADCOOKIE }, 4668 { NFS4ERR_BAD_COOKIE, -EBADCOOKIE },
4636 { NFS4ERR_NOTSUPP, ENOTSUPP }, 4669 { NFS4ERR_NOTSUPP, -ENOTSUPP },
4637 { NFS4ERR_TOOSMALL, ETOOSMALL }, 4670 { NFS4ERR_TOOSMALL, -ETOOSMALL },
4638 { NFS4ERR_SERVERFAULT, ESERVERFAULT }, 4671 { NFS4ERR_SERVERFAULT, -ESERVERFAULT },
4639 { NFS4ERR_BADTYPE, EBADTYPE }, 4672 { NFS4ERR_BADTYPE, -EBADTYPE },
4640 { NFS4ERR_LOCKED, EAGAIN }, 4673 { NFS4ERR_LOCKED, -EAGAIN },
4641 { NFS4ERR_RESOURCE, EREMOTEIO }, 4674 { NFS4ERR_RESOURCE, -EREMOTEIO },
4642 { NFS4ERR_SYMLINK, ELOOP }, 4675 { NFS4ERR_SYMLINK, -ELOOP },
4643 { NFS4ERR_OP_ILLEGAL, EOPNOTSUPP }, 4676 { NFS4ERR_OP_ILLEGAL, -EOPNOTSUPP },
4644 { NFS4ERR_DEADLOCK, EDEADLK }, 4677 { NFS4ERR_DEADLOCK, -EDEADLK },
4645 { NFS4ERR_WRONGSEC, EPERM }, /* FIXME: this needs 4678 { NFS4ERR_WRONGSEC, -EPERM }, /* FIXME: this needs
4646 * to be handled by a 4679 * to be handled by a
4647 * middle-layer. 4680 * middle-layer.
4648 */ 4681 */
4649 { -1, EIO } 4682 { -1, -EIO }
4650}; 4683};
4651 4684
4652/* 4685/*
@@ -4663,14 +4696,14 @@ nfs4_stat_to_errno(int stat)
4663 } 4696 }
4664 if (stat <= 10000 || stat > 10100) { 4697 if (stat <= 10000 || stat > 10100) {
4665 /* The server is looney tunes. */ 4698 /* The server is looney tunes. */
4666 return ESERVERFAULT; 4699 return -ESERVERFAULT;
4667 } 4700 }
4668 /* If we cannot translate the error, the recovery routines should 4701 /* If we cannot translate the error, the recovery routines should
4669 * handle it. 4702 * handle it.
4670 * Note: remaining NFSv4 error codes have values > 10000, so should 4703 * Note: remaining NFSv4 error codes have values > 10000, so should
4671 * not conflict with native Linux error codes. 4704 * not conflict with native Linux error codes.
4672 */ 4705 */
4673 return stat; 4706 return -stat;
4674} 4707}
4675 4708
4676#define PROC(proc, argtype, restype) \ 4709#define PROC(proc, argtype, restype) \
diff --git a/fs/nfs/read.c b/fs/nfs/read.c
index 5a70be589bbe..16f57e0af999 100644
--- a/fs/nfs/read.c
+++ b/fs/nfs/read.c
@@ -58,22 +58,19 @@ struct nfs_read_data *nfs_readdata_alloc(unsigned int pagecount)
58 return p; 58 return p;
59} 59}
60 60
61static void nfs_readdata_rcu_free(struct rcu_head *head) 61static void nfs_readdata_free(struct nfs_read_data *p)
62{ 62{
63 struct nfs_read_data *p = container_of(head, struct nfs_read_data, task.u.tk_rcu);
64 if (p && (p->pagevec != &p->page_array[0])) 63 if (p && (p->pagevec != &p->page_array[0]))
65 kfree(p->pagevec); 64 kfree(p->pagevec);
66 mempool_free(p, nfs_rdata_mempool); 65 mempool_free(p, nfs_rdata_mempool);
67} 66}
68 67
69static void nfs_readdata_free(struct nfs_read_data *rdata)
70{
71 call_rcu_bh(&rdata->task.u.tk_rcu, nfs_readdata_rcu_free);
72}
73
74void nfs_readdata_release(void *data) 68void nfs_readdata_release(void *data)
75{ 69{
76 nfs_readdata_free(data); 70 struct nfs_read_data *rdata = data;
71
72 put_nfs_open_context(rdata->args.context);
73 nfs_readdata_free(rdata);
77} 74}
78 75
79static 76static
@@ -156,7 +153,7 @@ static void nfs_readpage_release(struct nfs_page *req)
156/* 153/*
157 * Set up the NFS read request struct 154 * Set up the NFS read request struct
158 */ 155 */
159static void nfs_read_rpcsetup(struct nfs_page *req, struct nfs_read_data *data, 156static int nfs_read_rpcsetup(struct nfs_page *req, struct nfs_read_data *data,
160 const struct rpc_call_ops *call_ops, 157 const struct rpc_call_ops *call_ops,
161 unsigned int count, unsigned int offset) 158 unsigned int count, unsigned int offset)
162{ 159{
@@ -174,6 +171,7 @@ static void nfs_read_rpcsetup(struct nfs_page *req, struct nfs_read_data *data,
174 .rpc_message = &msg, 171 .rpc_message = &msg,
175 .callback_ops = call_ops, 172 .callback_ops = call_ops,
176 .callback_data = data, 173 .callback_data = data,
174 .workqueue = nfsiod_workqueue,
177 .flags = RPC_TASK_ASYNC | swap_flags, 175 .flags = RPC_TASK_ASYNC | swap_flags,
178 }; 176 };
179 177
@@ -186,7 +184,7 @@ static void nfs_read_rpcsetup(struct nfs_page *req, struct nfs_read_data *data,
186 data->args.pgbase = req->wb_pgbase + offset; 184 data->args.pgbase = req->wb_pgbase + offset;
187 data->args.pages = data->pagevec; 185 data->args.pages = data->pagevec;
188 data->args.count = count; 186 data->args.count = count;
189 data->args.context = req->wb_context; 187 data->args.context = get_nfs_open_context(req->wb_context);
190 188
191 data->res.fattr = &data->fattr; 189 data->res.fattr = &data->fattr;
192 data->res.count = count; 190 data->res.count = count;
@@ -204,8 +202,10 @@ static void nfs_read_rpcsetup(struct nfs_page *req, struct nfs_read_data *data,
204 (unsigned long long)data->args.offset); 202 (unsigned long long)data->args.offset);
205 203
206 task = rpc_run_task(&task_setup_data); 204 task = rpc_run_task(&task_setup_data);
207 if (!IS_ERR(task)) 205 if (IS_ERR(task))
208 rpc_put_task(task); 206 return PTR_ERR(task);
207 rpc_put_task(task);
208 return 0;
209} 209}
210 210
211static void 211static void
@@ -242,6 +242,7 @@ static int nfs_pagein_multi(struct inode *inode, struct list_head *head, unsigne
242 size_t rsize = NFS_SERVER(inode)->rsize, nbytes; 242 size_t rsize = NFS_SERVER(inode)->rsize, nbytes;
243 unsigned int offset; 243 unsigned int offset;
244 int requests = 0; 244 int requests = 0;
245 int ret = 0;
245 LIST_HEAD(list); 246 LIST_HEAD(list);
246 247
247 nfs_list_remove_request(req); 248 nfs_list_remove_request(req);
@@ -253,7 +254,6 @@ static int nfs_pagein_multi(struct inode *inode, struct list_head *head, unsigne
253 data = nfs_readdata_alloc(1); 254 data = nfs_readdata_alloc(1);
254 if (!data) 255 if (!data)
255 goto out_bad; 256 goto out_bad;
256 INIT_LIST_HEAD(&data->pages);
257 list_add(&data->pages, &list); 257 list_add(&data->pages, &list);
258 requests++; 258 requests++;
259 nbytes -= len; 259 nbytes -= len;
@@ -264,6 +264,8 @@ static int nfs_pagein_multi(struct inode *inode, struct list_head *head, unsigne
264 offset = 0; 264 offset = 0;
265 nbytes = count; 265 nbytes = count;
266 do { 266 do {
267 int ret2;
268
267 data = list_entry(list.next, struct nfs_read_data, pages); 269 data = list_entry(list.next, struct nfs_read_data, pages);
268 list_del_init(&data->pages); 270 list_del_init(&data->pages);
269 271
@@ -271,13 +273,15 @@ static int nfs_pagein_multi(struct inode *inode, struct list_head *head, unsigne
271 273
272 if (nbytes < rsize) 274 if (nbytes < rsize)
273 rsize = nbytes; 275 rsize = nbytes;
274 nfs_read_rpcsetup(req, data, &nfs_read_partial_ops, 276 ret2 = nfs_read_rpcsetup(req, data, &nfs_read_partial_ops,
275 rsize, offset); 277 rsize, offset);
278 if (ret == 0)
279 ret = ret2;
276 offset += rsize; 280 offset += rsize;
277 nbytes -= rsize; 281 nbytes -= rsize;
278 } while (nbytes != 0); 282 } while (nbytes != 0);
279 283
280 return 0; 284 return ret;
281 285
282out_bad: 286out_bad:
283 while (!list_empty(&list)) { 287 while (!list_empty(&list)) {
@@ -295,12 +299,12 @@ static int nfs_pagein_one(struct inode *inode, struct list_head *head, unsigned
295 struct nfs_page *req; 299 struct nfs_page *req;
296 struct page **pages; 300 struct page **pages;
297 struct nfs_read_data *data; 301 struct nfs_read_data *data;
302 int ret = -ENOMEM;
298 303
299 data = nfs_readdata_alloc(npages); 304 data = nfs_readdata_alloc(npages);
300 if (!data) 305 if (!data)
301 goto out_bad; 306 goto out_bad;
302 307
303 INIT_LIST_HEAD(&data->pages);
304 pages = data->pagevec; 308 pages = data->pagevec;
305 while (!list_empty(head)) { 309 while (!list_empty(head)) {
306 req = nfs_list_entry(head->next); 310 req = nfs_list_entry(head->next);
@@ -311,11 +315,10 @@ static int nfs_pagein_one(struct inode *inode, struct list_head *head, unsigned
311 } 315 }
312 req = nfs_list_entry(data->pages.next); 316 req = nfs_list_entry(data->pages.next);
313 317
314 nfs_read_rpcsetup(req, data, &nfs_read_full_ops, count, 0); 318 return nfs_read_rpcsetup(req, data, &nfs_read_full_ops, count, 0);
315 return 0;
316out_bad: 319out_bad:
317 nfs_async_read_error(head); 320 nfs_async_read_error(head);
318 return -ENOMEM; 321 return ret;
319} 322}
320 323
321/* 324/*
@@ -342,26 +345,25 @@ int nfs_readpage_result(struct rpc_task *task, struct nfs_read_data *data)
342 return 0; 345 return 0;
343} 346}
344 347
345static int nfs_readpage_retry(struct rpc_task *task, struct nfs_read_data *data) 348static void nfs_readpage_retry(struct rpc_task *task, struct nfs_read_data *data)
346{ 349{
347 struct nfs_readargs *argp = &data->args; 350 struct nfs_readargs *argp = &data->args;
348 struct nfs_readres *resp = &data->res; 351 struct nfs_readres *resp = &data->res;
349 352
350 if (resp->eof || resp->count == argp->count) 353 if (resp->eof || resp->count == argp->count)
351 return 0; 354 return;
352 355
353 /* This is a short read! */ 356 /* This is a short read! */
354 nfs_inc_stats(data->inode, NFSIOS_SHORTREAD); 357 nfs_inc_stats(data->inode, NFSIOS_SHORTREAD);
355 /* Has the server at least made some progress? */ 358 /* Has the server at least made some progress? */
356 if (resp->count == 0) 359 if (resp->count == 0)
357 return 0; 360 return;
358 361
359 /* Yes, so retry the read at the end of the data */ 362 /* Yes, so retry the read at the end of the data */
360 argp->offset += resp->count; 363 argp->offset += resp->count;
361 argp->pgbase += resp->count; 364 argp->pgbase += resp->count;
362 argp->count -= resp->count; 365 argp->count -= resp->count;
363 rpc_restart_call(task); 366 rpc_restart_call(task);
364 return -EAGAIN;
365} 367}
366 368
367/* 369/*
@@ -370,29 +372,37 @@ static int nfs_readpage_retry(struct rpc_task *task, struct nfs_read_data *data)
370static void nfs_readpage_result_partial(struct rpc_task *task, void *calldata) 372static void nfs_readpage_result_partial(struct rpc_task *task, void *calldata)
371{ 373{
372 struct nfs_read_data *data = calldata; 374 struct nfs_read_data *data = calldata;
373 struct nfs_page *req = data->req;
374 struct page *page = req->wb_page;
375 375
376 if (nfs_readpage_result(task, data) != 0) 376 if (nfs_readpage_result(task, data) != 0)
377 return; 377 return;
378 if (task->tk_status < 0)
379 return;
378 380
379 if (likely(task->tk_status >= 0)) { 381 nfs_readpage_truncate_uninitialised_page(data);
380 nfs_readpage_truncate_uninitialised_page(data); 382 nfs_readpage_retry(task, data);
381 if (nfs_readpage_retry(task, data) != 0) 383}
382 return; 384
383 } 385static void nfs_readpage_release_partial(void *calldata)
384 if (unlikely(task->tk_status < 0)) 386{
387 struct nfs_read_data *data = calldata;
388 struct nfs_page *req = data->req;
389 struct page *page = req->wb_page;
390 int status = data->task.tk_status;
391
392 if (status < 0)
385 SetPageError(page); 393 SetPageError(page);
394
386 if (atomic_dec_and_test(&req->wb_complete)) { 395 if (atomic_dec_and_test(&req->wb_complete)) {
387 if (!PageError(page)) 396 if (!PageError(page))
388 SetPageUptodate(page); 397 SetPageUptodate(page);
389 nfs_readpage_release(req); 398 nfs_readpage_release(req);
390 } 399 }
400 nfs_readdata_release(calldata);
391} 401}
392 402
393static const struct rpc_call_ops nfs_read_partial_ops = { 403static const struct rpc_call_ops nfs_read_partial_ops = {
394 .rpc_call_done = nfs_readpage_result_partial, 404 .rpc_call_done = nfs_readpage_result_partial,
395 .rpc_release = nfs_readdata_release, 405 .rpc_release = nfs_readpage_release_partial,
396}; 406};
397 407
398static void nfs_readpage_set_pages_uptodate(struct nfs_read_data *data) 408static void nfs_readpage_set_pages_uptodate(struct nfs_read_data *data)
@@ -427,29 +437,35 @@ static void nfs_readpage_result_full(struct rpc_task *task, void *calldata)
427 437
428 if (nfs_readpage_result(task, data) != 0) 438 if (nfs_readpage_result(task, data) != 0)
429 return; 439 return;
440 if (task->tk_status < 0)
441 return;
430 /* 442 /*
431 * Note: nfs_readpage_retry may change the values of 443 * Note: nfs_readpage_retry may change the values of
432 * data->args. In the multi-page case, we therefore need 444 * data->args. In the multi-page case, we therefore need
433 * to ensure that we call nfs_readpage_set_pages_uptodate() 445 * to ensure that we call nfs_readpage_set_pages_uptodate()
434 * first. 446 * first.
435 */ 447 */
436 if (likely(task->tk_status >= 0)) { 448 nfs_readpage_truncate_uninitialised_page(data);
437 nfs_readpage_truncate_uninitialised_page(data); 449 nfs_readpage_set_pages_uptodate(data);
438 nfs_readpage_set_pages_uptodate(data); 450 nfs_readpage_retry(task, data);
439 if (nfs_readpage_retry(task, data) != 0) 451}
440 return; 452
441 } 453static void nfs_readpage_release_full(void *calldata)
454{
455 struct nfs_read_data *data = calldata;
456
442 while (!list_empty(&data->pages)) { 457 while (!list_empty(&data->pages)) {
443 struct nfs_page *req = nfs_list_entry(data->pages.next); 458 struct nfs_page *req = nfs_list_entry(data->pages.next);
444 459
445 nfs_list_remove_request(req); 460 nfs_list_remove_request(req);
446 nfs_readpage_release(req); 461 nfs_readpage_release(req);
447 } 462 }
463 nfs_readdata_release(calldata);
448} 464}
449 465
450static const struct rpc_call_ops nfs_read_full_ops = { 466static const struct rpc_call_ops nfs_read_full_ops = {
451 .rpc_call_done = nfs_readpage_result_full, 467 .rpc_call_done = nfs_readpage_result_full,
452 .rpc_release = nfs_readdata_release, 468 .rpc_release = nfs_readpage_release_full,
453}; 469};
454 470
455/* 471/*
diff --git a/fs/nfs/super.c b/fs/nfs/super.c
index f9219024f31a..20a1cb1810fe 100644
--- a/fs/nfs/super.c
+++ b/fs/nfs/super.c
@@ -441,10 +441,52 @@ static const char *nfs_pseudoflavour_to_name(rpc_authflavor_t flavour)
441 return sec_flavours[i].str; 441 return sec_flavours[i].str;
442} 442}
443 443
444static void nfs_show_mountd_options(struct seq_file *m, struct nfs_server *nfss,
445 int showdefaults)
446{
447 struct sockaddr *sap = (struct sockaddr *)&nfss->mountd_address;
448
449 switch (sap->sa_family) {
450 case AF_INET: {
451 struct sockaddr_in *sin = (struct sockaddr_in *)sap;
452 seq_printf(m, ",mountaddr=" NIPQUAD_FMT,
453 NIPQUAD(sin->sin_addr.s_addr));
454 break;
455 }
456 case AF_INET6: {
457 struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
458 seq_printf(m, ",mountaddr=" NIP6_FMT,
459 NIP6(sin6->sin6_addr));
460 break;
461 }
462 default:
463 if (showdefaults)
464 seq_printf(m, ",mountaddr=unspecified");
465 }
466
467 if (nfss->mountd_version || showdefaults)
468 seq_printf(m, ",mountvers=%u", nfss->mountd_version);
469 if (nfss->mountd_port || showdefaults)
470 seq_printf(m, ",mountport=%u", nfss->mountd_port);
471
472 switch (nfss->mountd_protocol) {
473 case IPPROTO_UDP:
474 seq_printf(m, ",mountproto=udp");
475 break;
476 case IPPROTO_TCP:
477 seq_printf(m, ",mountproto=tcp");
478 break;
479 default:
480 if (showdefaults)
481 seq_printf(m, ",mountproto=auto");
482 }
483}
484
444/* 485/*
445 * Describe the mount options in force on this server representation 486 * Describe the mount options in force on this server representation
446 */ 487 */
447static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss, int showdefaults) 488static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
489 int showdefaults)
448{ 490{
449 static const struct proc_nfs_info { 491 static const struct proc_nfs_info {
450 int flag; 492 int flag;
@@ -452,6 +494,8 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
452 const char *nostr; 494 const char *nostr;
453 } nfs_info[] = { 495 } nfs_info[] = {
454 { NFS_MOUNT_SOFT, ",soft", ",hard" }, 496 { NFS_MOUNT_SOFT, ",soft", ",hard" },
497 { NFS_MOUNT_INTR, ",intr", ",nointr" },
498 { NFS_MOUNT_POSIX, ",posix", "" },
455 { NFS_MOUNT_NOCTO, ",nocto", "" }, 499 { NFS_MOUNT_NOCTO, ",nocto", "" },
456 { NFS_MOUNT_NOAC, ",noac", "" }, 500 { NFS_MOUNT_NOAC, ",noac", "" },
457 { NFS_MOUNT_NONLM, ",nolock", "" }, 501 { NFS_MOUNT_NONLM, ",nolock", "" },
@@ -462,18 +506,22 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
462 }; 506 };
463 const struct proc_nfs_info *nfs_infop; 507 const struct proc_nfs_info *nfs_infop;
464 struct nfs_client *clp = nfss->nfs_client; 508 struct nfs_client *clp = nfss->nfs_client;
465 509 u32 version = clp->rpc_ops->version;
466 seq_printf(m, ",vers=%d", clp->rpc_ops->version); 510
467 seq_printf(m, ",rsize=%d", nfss->rsize); 511 seq_printf(m, ",vers=%u", version);
468 seq_printf(m, ",wsize=%d", nfss->wsize); 512 seq_printf(m, ",rsize=%u", nfss->rsize);
513 seq_printf(m, ",wsize=%u", nfss->wsize);
514 if (nfss->bsize != 0)
515 seq_printf(m, ",bsize=%u", nfss->bsize);
516 seq_printf(m, ",namlen=%u", nfss->namelen);
469 if (nfss->acregmin != 3*HZ || showdefaults) 517 if (nfss->acregmin != 3*HZ || showdefaults)
470 seq_printf(m, ",acregmin=%d", nfss->acregmin/HZ); 518 seq_printf(m, ",acregmin=%u", nfss->acregmin/HZ);
471 if (nfss->acregmax != 60*HZ || showdefaults) 519 if (nfss->acregmax != 60*HZ || showdefaults)
472 seq_printf(m, ",acregmax=%d", nfss->acregmax/HZ); 520 seq_printf(m, ",acregmax=%u", nfss->acregmax/HZ);
473 if (nfss->acdirmin != 30*HZ || showdefaults) 521 if (nfss->acdirmin != 30*HZ || showdefaults)
474 seq_printf(m, ",acdirmin=%d", nfss->acdirmin/HZ); 522 seq_printf(m, ",acdirmin=%u", nfss->acdirmin/HZ);
475 if (nfss->acdirmax != 60*HZ || showdefaults) 523 if (nfss->acdirmax != 60*HZ || showdefaults)
476 seq_printf(m, ",acdirmax=%d", nfss->acdirmax/HZ); 524 seq_printf(m, ",acdirmax=%u", nfss->acdirmax/HZ);
477 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) { 525 for (nfs_infop = nfs_info; nfs_infop->flag; nfs_infop++) {
478 if (nfss->flags & nfs_infop->flag) 526 if (nfss->flags & nfs_infop->flag)
479 seq_puts(m, nfs_infop->str); 527 seq_puts(m, nfs_infop->str);
@@ -482,9 +530,24 @@ static void nfs_show_mount_options(struct seq_file *m, struct nfs_server *nfss,
482 } 530 }
483 seq_printf(m, ",proto=%s", 531 seq_printf(m, ",proto=%s",
484 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO)); 532 rpc_peeraddr2str(nfss->client, RPC_DISPLAY_PROTO));
533 if (version == 4) {
534 if (nfss->port != NFS_PORT)
535 seq_printf(m, ",port=%u", nfss->port);
536 } else
537 if (nfss->port)
538 seq_printf(m, ",port=%u", nfss->port);
539
485 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ); 540 seq_printf(m, ",timeo=%lu", 10U * nfss->client->cl_timeout->to_initval / HZ);
486 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries); 541 seq_printf(m, ",retrans=%u", nfss->client->cl_timeout->to_retries);
487 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor)); 542 seq_printf(m, ",sec=%s", nfs_pseudoflavour_to_name(nfss->client->cl_auth->au_flavor));
543
544 if (version != 4)
545 nfs_show_mountd_options(m, nfss, showdefaults);
546
547#ifdef CONFIG_NFS_V4
548 if (clp->rpc_ops->version == 4)
549 seq_printf(m, ",clientaddr=%s", clp->cl_ipaddr);
550#endif
488} 551}
489 552
490/* 553/*
@@ -529,10 +592,10 @@ static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
529 592
530 seq_printf(m, "\n\tcaps:\t"); 593 seq_printf(m, "\n\tcaps:\t");
531 seq_printf(m, "caps=0x%x", nfss->caps); 594 seq_printf(m, "caps=0x%x", nfss->caps);
532 seq_printf(m, ",wtmult=%d", nfss->wtmult); 595 seq_printf(m, ",wtmult=%u", nfss->wtmult);
533 seq_printf(m, ",dtsize=%d", nfss->dtsize); 596 seq_printf(m, ",dtsize=%u", nfss->dtsize);
534 seq_printf(m, ",bsize=%d", nfss->bsize); 597 seq_printf(m, ",bsize=%u", nfss->bsize);
535 seq_printf(m, ",namelen=%d", nfss->namelen); 598 seq_printf(m, ",namlen=%u", nfss->namelen);
536 599
537#ifdef CONFIG_NFS_V4 600#ifdef CONFIG_NFS_V4
538 if (nfss->nfs_client->rpc_ops->version == 4) { 601 if (nfss->nfs_client->rpc_ops->version == 4) {
@@ -546,9 +609,9 @@ static int nfs_show_stats(struct seq_file *m, struct vfsmount *mnt)
546 /* 609 /*
547 * Display security flavor in effect for this mount 610 * Display security flavor in effect for this mount
548 */ 611 */
549 seq_printf(m, "\n\tsec:\tflavor=%d", auth->au_ops->au_flavor); 612 seq_printf(m, "\n\tsec:\tflavor=%u", auth->au_ops->au_flavor);
550 if (auth->au_flavor) 613 if (auth->au_flavor)
551 seq_printf(m, ",pseudoflavor=%d", auth->au_flavor); 614 seq_printf(m, ",pseudoflavor=%u", auth->au_flavor);
552 615
553 /* 616 /*
554 * Display superblock I/O counters 617 * Display superblock I/O counters
@@ -683,7 +746,6 @@ static int nfs_parse_mount_options(char *raw,
683 struct nfs_parsed_mount_data *mnt) 746 struct nfs_parsed_mount_data *mnt)
684{ 747{
685 char *p, *string, *secdata; 748 char *p, *string, *secdata;
686 unsigned short port = 0;
687 int rc; 749 int rc;
688 750
689 if (!raw) { 751 if (!raw) {
@@ -798,7 +860,7 @@ static int nfs_parse_mount_options(char *raw,
798 return 0; 860 return 0;
799 if (option < 0 || option > 65535) 861 if (option < 0 || option > 65535)
800 return 0; 862 return 0;
801 port = option; 863 mnt->nfs_server.port = option;
802 break; 864 break;
803 case Opt_rsize: 865 case Opt_rsize:
804 if (match_int(args, &mnt->rsize)) 866 if (match_int(args, &mnt->rsize))
@@ -1048,7 +1110,8 @@ static int nfs_parse_mount_options(char *raw,
1048 } 1110 }
1049 } 1111 }
1050 1112
1051 nfs_set_port((struct sockaddr *)&mnt->nfs_server.address, port); 1113 nfs_set_port((struct sockaddr *)&mnt->nfs_server.address,
1114 mnt->nfs_server.port);
1052 1115
1053 return 1; 1116 return 1;
1054 1117
@@ -1169,7 +1232,9 @@ static int nfs_validate_mount_data(void *options,
1169 args->acregmax = 60; 1232 args->acregmax = 60;
1170 args->acdirmin = 30; 1233 args->acdirmin = 30;
1171 args->acdirmax = 60; 1234 args->acdirmax = 60;
1235 args->mount_server.port = 0; /* autobind unless user sets port */
1172 args->mount_server.protocol = XPRT_TRANSPORT_UDP; 1236 args->mount_server.protocol = XPRT_TRANSPORT_UDP;
1237 args->nfs_server.port = 0; /* autobind unless user sets port */
1173 args->nfs_server.protocol = XPRT_TRANSPORT_TCP; 1238 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1174 1239
1175 switch (data->version) { 1240 switch (data->version) {
@@ -1208,7 +1273,6 @@ static int nfs_validate_mount_data(void *options,
1208 args->flags = data->flags; 1273 args->flags = data->flags;
1209 args->rsize = data->rsize; 1274 args->rsize = data->rsize;
1210 args->wsize = data->wsize; 1275 args->wsize = data->wsize;
1211 args->flags = data->flags;
1212 args->timeo = data->timeo; 1276 args->timeo = data->timeo;
1213 args->retrans = data->retrans; 1277 args->retrans = data->retrans;
1214 args->acregmin = data->acregmin; 1278 args->acregmin = data->acregmin;
@@ -1230,6 +1294,8 @@ static int nfs_validate_mount_data(void *options,
1230 args->namlen = data->namlen; 1294 args->namlen = data->namlen;
1231 args->bsize = data->bsize; 1295 args->bsize = data->bsize;
1232 args->auth_flavors[0] = data->pseudoflavor; 1296 args->auth_flavors[0] = data->pseudoflavor;
1297 if (!args->nfs_server.hostname)
1298 goto out_nomem;
1233 1299
1234 /* 1300 /*
1235 * The legacy version 6 binary mount data from userspace has a 1301 * The legacy version 6 binary mount data from userspace has a
@@ -1276,6 +1342,8 @@ static int nfs_validate_mount_data(void *options,
1276 len = c - dev_name; 1342 len = c - dev_name;
1277 /* N.B. caller will free nfs_server.hostname in all cases */ 1343 /* N.B. caller will free nfs_server.hostname in all cases */
1278 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL); 1344 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
1345 if (!args->nfs_server.hostname)
1346 goto out_nomem;
1279 1347
1280 c++; 1348 c++;
1281 if (strlen(c) > NFS_MAXPATHLEN) 1349 if (strlen(c) > NFS_MAXPATHLEN)
@@ -1319,6 +1387,10 @@ out_v3_not_compiled:
1319 return -EPROTONOSUPPORT; 1387 return -EPROTONOSUPPORT;
1320#endif /* !CONFIG_NFS_V3 */ 1388#endif /* !CONFIG_NFS_V3 */
1321 1389
1390out_nomem:
1391 dfprintk(MOUNT, "NFS: not enough memory to handle mount options\n");
1392 return -ENOMEM;
1393
1322out_no_address: 1394out_no_address:
1323 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n"); 1395 dfprintk(MOUNT, "NFS: mount program didn't pass remote address\n");
1324 return -EINVAL; 1396 return -EINVAL;
@@ -1706,28 +1778,6 @@ static void nfs4_fill_super(struct super_block *sb)
1706} 1778}
1707 1779
1708/* 1780/*
1709 * If the user didn't specify a port, set the port number to
1710 * the NFS version 4 default port.
1711 */
1712static void nfs4_default_port(struct sockaddr *sap)
1713{
1714 switch (sap->sa_family) {
1715 case AF_INET: {
1716 struct sockaddr_in *ap = (struct sockaddr_in *)sap;
1717 if (ap->sin_port == 0)
1718 ap->sin_port = htons(NFS_PORT);
1719 break;
1720 }
1721 case AF_INET6: {
1722 struct sockaddr_in6 *ap = (struct sockaddr_in6 *)sap;
1723 if (ap->sin6_port == 0)
1724 ap->sin6_port = htons(NFS_PORT);
1725 break;
1726 }
1727 }
1728}
1729
1730/*
1731 * Validate NFSv4 mount options 1781 * Validate NFSv4 mount options
1732 */ 1782 */
1733static int nfs4_validate_mount_data(void *options, 1783static int nfs4_validate_mount_data(void *options,
@@ -1751,6 +1801,7 @@ static int nfs4_validate_mount_data(void *options,
1751 args->acregmax = 60; 1801 args->acregmax = 60;
1752 args->acdirmin = 30; 1802 args->acdirmin = 30;
1753 args->acdirmax = 60; 1803 args->acdirmax = 60;
1804 args->nfs_server.port = NFS_PORT; /* 2049 unless user set port= */
1754 args->nfs_server.protocol = XPRT_TRANSPORT_TCP; 1805 args->nfs_server.protocol = XPRT_TRANSPORT_TCP;
1755 1806
1756 switch (data->version) { 1807 switch (data->version) {
@@ -1767,9 +1818,6 @@ static int nfs4_validate_mount_data(void *options,
1767 &args->nfs_server.address)) 1818 &args->nfs_server.address))
1768 goto out_no_address; 1819 goto out_no_address;
1769 1820
1770 nfs4_default_port((struct sockaddr *)
1771 &args->nfs_server.address);
1772
1773 switch (data->auth_flavourlen) { 1821 switch (data->auth_flavourlen) {
1774 case 0: 1822 case 0:
1775 args->auth_flavors[0] = RPC_AUTH_UNIX; 1823 args->auth_flavors[0] = RPC_AUTH_UNIX;
@@ -1827,9 +1875,6 @@ static int nfs4_validate_mount_data(void *options,
1827 &args->nfs_server.address)) 1875 &args->nfs_server.address))
1828 return -EINVAL; 1876 return -EINVAL;
1829 1877
1830 nfs4_default_port((struct sockaddr *)
1831 &args->nfs_server.address);
1832
1833 switch (args->auth_flavor_len) { 1878 switch (args->auth_flavor_len) {
1834 case 0: 1879 case 0:
1835 args->auth_flavors[0] = RPC_AUTH_UNIX; 1880 args->auth_flavors[0] = RPC_AUTH_UNIX;
@@ -1852,12 +1897,16 @@ static int nfs4_validate_mount_data(void *options,
1852 return -ENAMETOOLONG; 1897 return -ENAMETOOLONG;
1853 /* N.B. caller will free nfs_server.hostname in all cases */ 1898 /* N.B. caller will free nfs_server.hostname in all cases */
1854 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL); 1899 args->nfs_server.hostname = kstrndup(dev_name, len, GFP_KERNEL);
1900 if (!args->nfs_server.hostname)
1901 goto out_nomem;
1855 1902
1856 c++; /* step over the ':' */ 1903 c++; /* step over the ':' */
1857 len = strlen(c); 1904 len = strlen(c);
1858 if (len > NFS4_MAXPATHLEN) 1905 if (len > NFS4_MAXPATHLEN)
1859 return -ENAMETOOLONG; 1906 return -ENAMETOOLONG;
1860 args->nfs_server.export_path = kstrndup(c, len, GFP_KERNEL); 1907 args->nfs_server.export_path = kstrndup(c, len, GFP_KERNEL);
1908 if (!args->nfs_server.export_path)
1909 goto out_nomem;
1861 1910
1862 dprintk("NFS: MNTPATH: '%s'\n", args->nfs_server.export_path); 1911 dprintk("NFS: MNTPATH: '%s'\n", args->nfs_server.export_path);
1863 1912
@@ -1879,6 +1928,10 @@ out_inval_auth:
1879 data->auth_flavourlen); 1928 data->auth_flavourlen);
1880 return -EINVAL; 1929 return -EINVAL;
1881 1930
1931out_nomem:
1932 dfprintk(MOUNT, "NFS4: not enough memory to handle mount options\n");
1933 return -ENOMEM;
1934
1882out_no_address: 1935out_no_address:
1883 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n"); 1936 dfprintk(MOUNT, "NFS4: mount program didn't pass remote address\n");
1884 return -EINVAL; 1937 return -EINVAL;
diff --git a/fs/nfs/symlink.c b/fs/nfs/symlink.c
index 83e865a16ad1..412738dbfbc7 100644
--- a/fs/nfs/symlink.c
+++ b/fs/nfs/symlink.c
@@ -10,7 +10,6 @@
10 * nfs symlink handling code 10 * nfs symlink handling code
11 */ 11 */
12 12
13#define NFS_NEED_XDR_TYPES
14#include <linux/time.h> 13#include <linux/time.h>
15#include <linux/errno.h> 14#include <linux/errno.h>
16#include <linux/sunrpc/clnt.h> 15#include <linux/sunrpc/clnt.h>
diff --git a/fs/nfs/unlink.c b/fs/nfs/unlink.c
index 757415363422..3adf8b266461 100644
--- a/fs/nfs/unlink.c
+++ b/fs/nfs/unlink.c
@@ -234,7 +234,7 @@ nfs_async_unlink(struct inode *dir, struct dentry *dentry)
234 if (data == NULL) 234 if (data == NULL)
235 goto out; 235 goto out;
236 236
237 data->cred = rpcauth_lookupcred(NFS_CLIENT(dir)->cl_auth, 0); 237 data->cred = rpc_lookup_cred();
238 if (IS_ERR(data->cred)) { 238 if (IS_ERR(data->cred)) {
239 status = PTR_ERR(data->cred); 239 status = PTR_ERR(data->cred);
240 goto out_free; 240 goto out_free;
diff --git a/fs/nfs/write.c b/fs/nfs/write.c
index bed63416a55b..1ade11d1ba07 100644
--- a/fs/nfs/write.c
+++ b/fs/nfs/write.c
@@ -48,7 +48,7 @@ static struct kmem_cache *nfs_wdata_cachep;
48static mempool_t *nfs_wdata_mempool; 48static mempool_t *nfs_wdata_mempool;
49static mempool_t *nfs_commit_mempool; 49static mempool_t *nfs_commit_mempool;
50 50
51struct nfs_write_data *nfs_commit_alloc(void) 51struct nfs_write_data *nfs_commitdata_alloc(void)
52{ 52{
53 struct nfs_write_data *p = mempool_alloc(nfs_commit_mempool, GFP_NOFS); 53 struct nfs_write_data *p = mempool_alloc(nfs_commit_mempool, GFP_NOFS);
54 54
@@ -59,19 +59,13 @@ struct nfs_write_data *nfs_commit_alloc(void)
59 return p; 59 return p;
60} 60}
61 61
62static void nfs_commit_rcu_free(struct rcu_head *head) 62void nfs_commit_free(struct nfs_write_data *p)
63{ 63{
64 struct nfs_write_data *p = container_of(head, struct nfs_write_data, task.u.tk_rcu);
65 if (p && (p->pagevec != &p->page_array[0])) 64 if (p && (p->pagevec != &p->page_array[0]))
66 kfree(p->pagevec); 65 kfree(p->pagevec);
67 mempool_free(p, nfs_commit_mempool); 66 mempool_free(p, nfs_commit_mempool);
68} 67}
69 68
70void nfs_commit_free(struct nfs_write_data *wdata)
71{
72 call_rcu_bh(&wdata->task.u.tk_rcu, nfs_commit_rcu_free);
73}
74
75struct nfs_write_data *nfs_writedata_alloc(unsigned int pagecount) 69struct nfs_write_data *nfs_writedata_alloc(unsigned int pagecount)
76{ 70{
77 struct nfs_write_data *p = mempool_alloc(nfs_wdata_mempool, GFP_NOFS); 71 struct nfs_write_data *p = mempool_alloc(nfs_wdata_mempool, GFP_NOFS);
@@ -93,21 +87,18 @@ struct nfs_write_data *nfs_writedata_alloc(unsigned int pagecount)
93 return p; 87 return p;
94} 88}
95 89
96static void nfs_writedata_rcu_free(struct rcu_head *head) 90static void nfs_writedata_free(struct nfs_write_data *p)
97{ 91{
98 struct nfs_write_data *p = container_of(head, struct nfs_write_data, task.u.tk_rcu);
99 if (p && (p->pagevec != &p->page_array[0])) 92 if (p && (p->pagevec != &p->page_array[0]))
100 kfree(p->pagevec); 93 kfree(p->pagevec);
101 mempool_free(p, nfs_wdata_mempool); 94 mempool_free(p, nfs_wdata_mempool);
102} 95}
103 96
104static void nfs_writedata_free(struct nfs_write_data *wdata) 97void nfs_writedata_release(void *data)
105{ 98{
106 call_rcu_bh(&wdata->task.u.tk_rcu, nfs_writedata_rcu_free); 99 struct nfs_write_data *wdata = data;
107}
108 100
109void nfs_writedata_release(void *wdata) 101 put_nfs_open_context(wdata->args.context);
110{
111 nfs_writedata_free(wdata); 102 nfs_writedata_free(wdata);
112} 103}
113 104
@@ -291,8 +282,6 @@ static int nfs_page_async_flush(struct nfs_pageio_descriptor *pgio,
291 spin_unlock(&inode->i_lock); 282 spin_unlock(&inode->i_lock);
292 if (!nfs_pageio_add_request(pgio, req)) { 283 if (!nfs_pageio_add_request(pgio, req)) {
293 nfs_redirty_request(req); 284 nfs_redirty_request(req);
294 nfs_end_page_writeback(page);
295 nfs_clear_page_tag_locked(req);
296 return pgio->pg_error; 285 return pgio->pg_error;
297 } 286 }
298 return 0; 287 return 0;
@@ -366,15 +355,13 @@ int nfs_writepages(struct address_space *mapping, struct writeback_control *wbc)
366/* 355/*
367 * Insert a write request into an inode 356 * Insert a write request into an inode
368 */ 357 */
369static int nfs_inode_add_request(struct inode *inode, struct nfs_page *req) 358static void nfs_inode_add_request(struct inode *inode, struct nfs_page *req)
370{ 359{
371 struct nfs_inode *nfsi = NFS_I(inode); 360 struct nfs_inode *nfsi = NFS_I(inode);
372 int error; 361 int error;
373 362
374 error = radix_tree_insert(&nfsi->nfs_page_tree, req->wb_index, req); 363 error = radix_tree_insert(&nfsi->nfs_page_tree, req->wb_index, req);
375 BUG_ON(error == -EEXIST); 364 BUG_ON(error);
376 if (error)
377 return error;
378 if (!nfsi->npages) { 365 if (!nfsi->npages) {
379 igrab(inode); 366 igrab(inode);
380 if (nfs_have_delegation(inode, FMODE_WRITE)) 367 if (nfs_have_delegation(inode, FMODE_WRITE))
@@ -384,8 +371,8 @@ static int nfs_inode_add_request(struct inode *inode, struct nfs_page *req)
384 set_page_private(req->wb_page, (unsigned long)req); 371 set_page_private(req->wb_page, (unsigned long)req);
385 nfsi->npages++; 372 nfsi->npages++;
386 kref_get(&req->wb_kref); 373 kref_get(&req->wb_kref);
387 radix_tree_tag_set(&nfsi->nfs_page_tree, req->wb_index, NFS_PAGE_TAG_LOCKED); 374 radix_tree_tag_set(&nfsi->nfs_page_tree, req->wb_index,
388 return 0; 375 NFS_PAGE_TAG_LOCKED);
389} 376}
390 377
391/* 378/*
@@ -413,7 +400,7 @@ static void nfs_inode_remove_request(struct nfs_page *req)
413} 400}
414 401
415static void 402static void
416nfs_redirty_request(struct nfs_page *req) 403nfs_mark_request_dirty(struct nfs_page *req)
417{ 404{
418 __set_page_dirty_nobuffers(req->wb_page); 405 __set_page_dirty_nobuffers(req->wb_page);
419} 406}
@@ -467,7 +454,7 @@ int nfs_reschedule_unstable_write(struct nfs_page *req)
467 return 1; 454 return 1;
468 } 455 }
469 if (test_and_clear_bit(PG_NEED_RESCHED, &req->wb_flags)) { 456 if (test_and_clear_bit(PG_NEED_RESCHED, &req->wb_flags)) {
470 nfs_redirty_request(req); 457 nfs_mark_request_dirty(req);
471 return 1; 458 return 1;
472 } 459 }
473 return 0; 460 return 0;
@@ -597,6 +584,13 @@ static struct nfs_page * nfs_update_request(struct nfs_open_context* ctx,
597 /* Loop over all inode entries and see if we find 584 /* Loop over all inode entries and see if we find
598 * A request for the page we wish to update 585 * A request for the page we wish to update
599 */ 586 */
587 if (new) {
588 if (radix_tree_preload(GFP_NOFS)) {
589 nfs_release_request(new);
590 return ERR_PTR(-ENOMEM);
591 }
592 }
593
600 spin_lock(&inode->i_lock); 594 spin_lock(&inode->i_lock);
601 req = nfs_page_find_request_locked(page); 595 req = nfs_page_find_request_locked(page);
602 if (req) { 596 if (req) {
@@ -607,28 +601,27 @@ static struct nfs_page * nfs_update_request(struct nfs_open_context* ctx,
607 error = nfs_wait_on_request(req); 601 error = nfs_wait_on_request(req);
608 nfs_release_request(req); 602 nfs_release_request(req);
609 if (error < 0) { 603 if (error < 0) {
610 if (new) 604 if (new) {
605 radix_tree_preload_end();
611 nfs_release_request(new); 606 nfs_release_request(new);
607 }
612 return ERR_PTR(error); 608 return ERR_PTR(error);
613 } 609 }
614 continue; 610 continue;
615 } 611 }
616 spin_unlock(&inode->i_lock); 612 spin_unlock(&inode->i_lock);
617 if (new) 613 if (new) {
614 radix_tree_preload_end();
618 nfs_release_request(new); 615 nfs_release_request(new);
616 }
619 break; 617 break;
620 } 618 }
621 619
622 if (new) { 620 if (new) {
623 int error;
624 nfs_lock_request_dontget(new); 621 nfs_lock_request_dontget(new);
625 error = nfs_inode_add_request(inode, new); 622 nfs_inode_add_request(inode, new);
626 if (error) {
627 spin_unlock(&inode->i_lock);
628 nfs_unlock_request(new);
629 return ERR_PTR(error);
630 }
631 spin_unlock(&inode->i_lock); 623 spin_unlock(&inode->i_lock);
624 radix_tree_preload_end();
632 req = new; 625 req = new;
633 goto zero_page; 626 goto zero_page;
634 } 627 }
@@ -785,7 +778,7 @@ static int flush_task_priority(int how)
785/* 778/*
786 * Set up the argument/result storage required for the RPC call. 779 * Set up the argument/result storage required for the RPC call.
787 */ 780 */
788static void nfs_write_rpcsetup(struct nfs_page *req, 781static int nfs_write_rpcsetup(struct nfs_page *req,
789 struct nfs_write_data *data, 782 struct nfs_write_data *data,
790 const struct rpc_call_ops *call_ops, 783 const struct rpc_call_ops *call_ops,
791 unsigned int count, unsigned int offset, 784 unsigned int count, unsigned int offset,
@@ -806,6 +799,7 @@ static void nfs_write_rpcsetup(struct nfs_page *req,
806 .rpc_message = &msg, 799 .rpc_message = &msg,
807 .callback_ops = call_ops, 800 .callback_ops = call_ops,
808 .callback_data = data, 801 .callback_data = data,
802 .workqueue = nfsiod_workqueue,
809 .flags = flags, 803 .flags = flags,
810 .priority = priority, 804 .priority = priority,
811 }; 805 };
@@ -822,7 +816,7 @@ static void nfs_write_rpcsetup(struct nfs_page *req,
822 data->args.pgbase = req->wb_pgbase + offset; 816 data->args.pgbase = req->wb_pgbase + offset;
823 data->args.pages = data->pagevec; 817 data->args.pages = data->pagevec;
824 data->args.count = count; 818 data->args.count = count;
825 data->args.context = req->wb_context; 819 data->args.context = get_nfs_open_context(req->wb_context);
826 data->args.stable = NFS_UNSTABLE; 820 data->args.stable = NFS_UNSTABLE;
827 if (how & FLUSH_STABLE) { 821 if (how & FLUSH_STABLE) {
828 data->args.stable = NFS_DATA_SYNC; 822 data->args.stable = NFS_DATA_SYNC;
@@ -847,8 +841,21 @@ static void nfs_write_rpcsetup(struct nfs_page *req,
847 (unsigned long long)data->args.offset); 841 (unsigned long long)data->args.offset);
848 842
849 task = rpc_run_task(&task_setup_data); 843 task = rpc_run_task(&task_setup_data);
850 if (!IS_ERR(task)) 844 if (IS_ERR(task))
851 rpc_put_task(task); 845 return PTR_ERR(task);
846 rpc_put_task(task);
847 return 0;
848}
849
850/* If a nfs_flush_* function fails, it should remove reqs from @head and
851 * call this on each, which will prepare them to be retried on next
852 * writeback using standard nfs.
853 */
854static void nfs_redirty_request(struct nfs_page *req)
855{
856 nfs_mark_request_dirty(req);
857 nfs_end_page_writeback(req->wb_page);
858 nfs_clear_page_tag_locked(req);
852} 859}
853 860
854/* 861/*
@@ -863,6 +870,7 @@ static int nfs_flush_multi(struct inode *inode, struct list_head *head, unsigned
863 size_t wsize = NFS_SERVER(inode)->wsize, nbytes; 870 size_t wsize = NFS_SERVER(inode)->wsize, nbytes;
864 unsigned int offset; 871 unsigned int offset;
865 int requests = 0; 872 int requests = 0;
873 int ret = 0;
866 LIST_HEAD(list); 874 LIST_HEAD(list);
867 875
868 nfs_list_remove_request(req); 876 nfs_list_remove_request(req);
@@ -884,6 +892,8 @@ static int nfs_flush_multi(struct inode *inode, struct list_head *head, unsigned
884 offset = 0; 892 offset = 0;
885 nbytes = count; 893 nbytes = count;
886 do { 894 do {
895 int ret2;
896
887 data = list_entry(list.next, struct nfs_write_data, pages); 897 data = list_entry(list.next, struct nfs_write_data, pages);
888 list_del_init(&data->pages); 898 list_del_init(&data->pages);
889 899
@@ -891,13 +901,15 @@ static int nfs_flush_multi(struct inode *inode, struct list_head *head, unsigned
891 901
892 if (nbytes < wsize) 902 if (nbytes < wsize)
893 wsize = nbytes; 903 wsize = nbytes;
894 nfs_write_rpcsetup(req, data, &nfs_write_partial_ops, 904 ret2 = nfs_write_rpcsetup(req, data, &nfs_write_partial_ops,
895 wsize, offset, how); 905 wsize, offset, how);
906 if (ret == 0)
907 ret = ret2;
896 offset += wsize; 908 offset += wsize;
897 nbytes -= wsize; 909 nbytes -= wsize;
898 } while (nbytes != 0); 910 } while (nbytes != 0);
899 911
900 return 0; 912 return ret;
901 913
902out_bad: 914out_bad:
903 while (!list_empty(&list)) { 915 while (!list_empty(&list)) {
@@ -906,8 +918,6 @@ out_bad:
906 nfs_writedata_release(data); 918 nfs_writedata_release(data);
907 } 919 }
908 nfs_redirty_request(req); 920 nfs_redirty_request(req);
909 nfs_end_page_writeback(req->wb_page);
910 nfs_clear_page_tag_locked(req);
911 return -ENOMEM; 921 return -ENOMEM;
912} 922}
913 923
@@ -940,16 +950,12 @@ static int nfs_flush_one(struct inode *inode, struct list_head *head, unsigned i
940 req = nfs_list_entry(data->pages.next); 950 req = nfs_list_entry(data->pages.next);
941 951
942 /* Set up the argument struct */ 952 /* Set up the argument struct */
943 nfs_write_rpcsetup(req, data, &nfs_write_full_ops, count, 0, how); 953 return nfs_write_rpcsetup(req, data, &nfs_write_full_ops, count, 0, how);
944
945 return 0;
946 out_bad: 954 out_bad:
947 while (!list_empty(head)) { 955 while (!list_empty(head)) {
948 req = nfs_list_entry(head->next); 956 req = nfs_list_entry(head->next);
949 nfs_list_remove_request(req); 957 nfs_list_remove_request(req);
950 nfs_redirty_request(req); 958 nfs_redirty_request(req);
951 nfs_end_page_writeback(req->wb_page);
952 nfs_clear_page_tag_locked(req);
953 } 959 }
954 return -ENOMEM; 960 return -ENOMEM;
955} 961}
@@ -972,7 +978,6 @@ static void nfs_writeback_done_partial(struct rpc_task *task, void *calldata)
972{ 978{
973 struct nfs_write_data *data = calldata; 979 struct nfs_write_data *data = calldata;
974 struct nfs_page *req = data->req; 980 struct nfs_page *req = data->req;
975 struct page *page = req->wb_page;
976 981
977 dprintk("NFS: write (%s/%Ld %d@%Ld)", 982 dprintk("NFS: write (%s/%Ld %d@%Ld)",
978 req->wb_context->path.dentry->d_inode->i_sb->s_id, 983 req->wb_context->path.dentry->d_inode->i_sb->s_id,
@@ -980,13 +985,20 @@ static void nfs_writeback_done_partial(struct rpc_task *task, void *calldata)
980 req->wb_bytes, 985 req->wb_bytes,
981 (long long)req_offset(req)); 986 (long long)req_offset(req));
982 987
983 if (nfs_writeback_done(task, data) != 0) 988 nfs_writeback_done(task, data);
984 return; 989}
985 990
986 if (task->tk_status < 0) { 991static void nfs_writeback_release_partial(void *calldata)
992{
993 struct nfs_write_data *data = calldata;
994 struct nfs_page *req = data->req;
995 struct page *page = req->wb_page;
996 int status = data->task.tk_status;
997
998 if (status < 0) {
987 nfs_set_pageerror(page); 999 nfs_set_pageerror(page);
988 nfs_context_set_write_error(req->wb_context, task->tk_status); 1000 nfs_context_set_write_error(req->wb_context, status);
989 dprintk(", error = %d\n", task->tk_status); 1001 dprintk(", error = %d\n", status);
990 goto out; 1002 goto out;
991 } 1003 }
992 1004
@@ -1011,11 +1023,12 @@ static void nfs_writeback_done_partial(struct rpc_task *task, void *calldata)
1011out: 1023out:
1012 if (atomic_dec_and_test(&req->wb_complete)) 1024 if (atomic_dec_and_test(&req->wb_complete))
1013 nfs_writepage_release(req); 1025 nfs_writepage_release(req);
1026 nfs_writedata_release(calldata);
1014} 1027}
1015 1028
1016static const struct rpc_call_ops nfs_write_partial_ops = { 1029static const struct rpc_call_ops nfs_write_partial_ops = {
1017 .rpc_call_done = nfs_writeback_done_partial, 1030 .rpc_call_done = nfs_writeback_done_partial,
1018 .rpc_release = nfs_writedata_release, 1031 .rpc_release = nfs_writeback_release_partial,
1019}; 1032};
1020 1033
1021/* 1034/*
@@ -1028,17 +1041,21 @@ static const struct rpc_call_ops nfs_write_partial_ops = {
1028static void nfs_writeback_done_full(struct rpc_task *task, void *calldata) 1041static void nfs_writeback_done_full(struct rpc_task *task, void *calldata)
1029{ 1042{
1030 struct nfs_write_data *data = calldata; 1043 struct nfs_write_data *data = calldata;
1031 struct nfs_page *req;
1032 struct page *page;
1033 1044
1034 if (nfs_writeback_done(task, data) != 0) 1045 nfs_writeback_done(task, data);
1035 return; 1046}
1047
1048static void nfs_writeback_release_full(void *calldata)
1049{
1050 struct nfs_write_data *data = calldata;
1051 int status = data->task.tk_status;
1036 1052
1037 /* Update attributes as result of writeback. */ 1053 /* Update attributes as result of writeback. */
1038 while (!list_empty(&data->pages)) { 1054 while (!list_empty(&data->pages)) {
1039 req = nfs_list_entry(data->pages.next); 1055 struct nfs_page *req = nfs_list_entry(data->pages.next);
1056 struct page *page = req->wb_page;
1057
1040 nfs_list_remove_request(req); 1058 nfs_list_remove_request(req);
1041 page = req->wb_page;
1042 1059
1043 dprintk("NFS: write (%s/%Ld %d@%Ld)", 1060 dprintk("NFS: write (%s/%Ld %d@%Ld)",
1044 req->wb_context->path.dentry->d_inode->i_sb->s_id, 1061 req->wb_context->path.dentry->d_inode->i_sb->s_id,
@@ -1046,10 +1063,10 @@ static void nfs_writeback_done_full(struct rpc_task *task, void *calldata)
1046 req->wb_bytes, 1063 req->wb_bytes,
1047 (long long)req_offset(req)); 1064 (long long)req_offset(req));
1048 1065
1049 if (task->tk_status < 0) { 1066 if (status < 0) {
1050 nfs_set_pageerror(page); 1067 nfs_set_pageerror(page);
1051 nfs_context_set_write_error(req->wb_context, task->tk_status); 1068 nfs_context_set_write_error(req->wb_context, status);
1052 dprintk(", error = %d\n", task->tk_status); 1069 dprintk(", error = %d\n", status);
1053 goto remove_request; 1070 goto remove_request;
1054 } 1071 }
1055 1072
@@ -1069,11 +1086,12 @@ remove_request:
1069 next: 1086 next:
1070 nfs_clear_page_tag_locked(req); 1087 nfs_clear_page_tag_locked(req);
1071 } 1088 }
1089 nfs_writedata_release(calldata);
1072} 1090}
1073 1091
1074static const struct rpc_call_ops nfs_write_full_ops = { 1092static const struct rpc_call_ops nfs_write_full_ops = {
1075 .rpc_call_done = nfs_writeback_done_full, 1093 .rpc_call_done = nfs_writeback_done_full,
1076 .rpc_release = nfs_writedata_release, 1094 .rpc_release = nfs_writeback_release_full,
1077}; 1095};
1078 1096
1079 1097
@@ -1159,15 +1177,18 @@ int nfs_writeback_done(struct rpc_task *task, struct nfs_write_data *data)
1159 1177
1160 1178
1161#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4) 1179#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
1162void nfs_commit_release(void *wdata) 1180void nfs_commitdata_release(void *data)
1163{ 1181{
1182 struct nfs_write_data *wdata = data;
1183
1184 put_nfs_open_context(wdata->args.context);
1164 nfs_commit_free(wdata); 1185 nfs_commit_free(wdata);
1165} 1186}
1166 1187
1167/* 1188/*
1168 * Set up the argument/result storage required for the RPC call. 1189 * Set up the argument/result storage required for the RPC call.
1169 */ 1190 */
1170static void nfs_commit_rpcsetup(struct list_head *head, 1191static int nfs_commit_rpcsetup(struct list_head *head,
1171 struct nfs_write_data *data, 1192 struct nfs_write_data *data,
1172 int how) 1193 int how)
1173{ 1194{
@@ -1187,6 +1208,7 @@ static void nfs_commit_rpcsetup(struct list_head *head,
1187 .rpc_message = &msg, 1208 .rpc_message = &msg,
1188 .callback_ops = &nfs_commit_ops, 1209 .callback_ops = &nfs_commit_ops,
1189 .callback_data = data, 1210 .callback_data = data,
1211 .workqueue = nfsiod_workqueue,
1190 .flags = flags, 1212 .flags = flags,
1191 .priority = priority, 1213 .priority = priority,
1192 }; 1214 };
@@ -1203,6 +1225,7 @@ static void nfs_commit_rpcsetup(struct list_head *head,
1203 /* Note: we always request a commit of the entire inode */ 1225 /* Note: we always request a commit of the entire inode */
1204 data->args.offset = 0; 1226 data->args.offset = 0;
1205 data->args.count = 0; 1227 data->args.count = 0;
1228 data->args.context = get_nfs_open_context(first->wb_context);
1206 data->res.count = 0; 1229 data->res.count = 0;
1207 data->res.fattr = &data->fattr; 1230 data->res.fattr = &data->fattr;
1208 data->res.verf = &data->verf; 1231 data->res.verf = &data->verf;
@@ -1214,8 +1237,10 @@ static void nfs_commit_rpcsetup(struct list_head *head,
1214 dprintk("NFS: %5u initiated commit call\n", data->task.tk_pid); 1237 dprintk("NFS: %5u initiated commit call\n", data->task.tk_pid);
1215 1238
1216 task = rpc_run_task(&task_setup_data); 1239 task = rpc_run_task(&task_setup_data);
1217 if (!IS_ERR(task)) 1240 if (IS_ERR(task))
1218 rpc_put_task(task); 1241 return PTR_ERR(task);
1242 rpc_put_task(task);
1243 return 0;
1219} 1244}
1220 1245
1221/* 1246/*
@@ -1227,15 +1252,13 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how)
1227 struct nfs_write_data *data; 1252 struct nfs_write_data *data;
1228 struct nfs_page *req; 1253 struct nfs_page *req;
1229 1254
1230 data = nfs_commit_alloc(); 1255 data = nfs_commitdata_alloc();
1231 1256
1232 if (!data) 1257 if (!data)
1233 goto out_bad; 1258 goto out_bad;
1234 1259
1235 /* Set up the argument struct */ 1260 /* Set up the argument struct */
1236 nfs_commit_rpcsetup(head, data, how); 1261 return nfs_commit_rpcsetup(head, data, how);
1237
1238 return 0;
1239 out_bad: 1262 out_bad:
1240 while (!list_empty(head)) { 1263 while (!list_empty(head)) {
1241 req = nfs_list_entry(head->next); 1264 req = nfs_list_entry(head->next);
@@ -1255,7 +1278,6 @@ nfs_commit_list(struct inode *inode, struct list_head *head, int how)
1255static void nfs_commit_done(struct rpc_task *task, void *calldata) 1278static void nfs_commit_done(struct rpc_task *task, void *calldata)
1256{ 1279{
1257 struct nfs_write_data *data = calldata; 1280 struct nfs_write_data *data = calldata;
1258 struct nfs_page *req;
1259 1281
1260 dprintk("NFS: %5u nfs_commit_done (status %d)\n", 1282 dprintk("NFS: %5u nfs_commit_done (status %d)\n",
1261 task->tk_pid, task->tk_status); 1283 task->tk_pid, task->tk_status);
@@ -1263,6 +1285,13 @@ static void nfs_commit_done(struct rpc_task *task, void *calldata)
1263 /* Call the NFS version-specific code */ 1285 /* Call the NFS version-specific code */
1264 if (NFS_PROTO(data->inode)->commit_done(task, data) != 0) 1286 if (NFS_PROTO(data->inode)->commit_done(task, data) != 0)
1265 return; 1287 return;
1288}
1289
1290static void nfs_commit_release(void *calldata)
1291{
1292 struct nfs_write_data *data = calldata;
1293 struct nfs_page *req;
1294 int status = data->task.tk_status;
1266 1295
1267 while (!list_empty(&data->pages)) { 1296 while (!list_empty(&data->pages)) {
1268 req = nfs_list_entry(data->pages.next); 1297 req = nfs_list_entry(data->pages.next);
@@ -1277,10 +1306,10 @@ static void nfs_commit_done(struct rpc_task *task, void *calldata)
1277 (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode), 1306 (long long)NFS_FILEID(req->wb_context->path.dentry->d_inode),
1278 req->wb_bytes, 1307 req->wb_bytes,
1279 (long long)req_offset(req)); 1308 (long long)req_offset(req));
1280 if (task->tk_status < 0) { 1309 if (status < 0) {
1281 nfs_context_set_write_error(req->wb_context, task->tk_status); 1310 nfs_context_set_write_error(req->wb_context, status);
1282 nfs_inode_remove_request(req); 1311 nfs_inode_remove_request(req);
1283 dprintk(", error = %d\n", task->tk_status); 1312 dprintk(", error = %d\n", status);
1284 goto next; 1313 goto next;
1285 } 1314 }
1286 1315
@@ -1297,10 +1326,11 @@ static void nfs_commit_done(struct rpc_task *task, void *calldata)
1297 } 1326 }
1298 /* We have a mismatch. Write the page again */ 1327 /* We have a mismatch. Write the page again */
1299 dprintk(" mismatch\n"); 1328 dprintk(" mismatch\n");
1300 nfs_redirty_request(req); 1329 nfs_mark_request_dirty(req);
1301 next: 1330 next:
1302 nfs_clear_page_tag_locked(req); 1331 nfs_clear_page_tag_locked(req);
1303 } 1332 }
1333 nfs_commitdata_release(calldata);
1304} 1334}
1305 1335
1306static const struct rpc_call_ops nfs_commit_ops = { 1336static const struct rpc_call_ops nfs_commit_ops = {
@@ -1487,18 +1517,19 @@ static int nfs_wb_page_priority(struct inode *inode, struct page *page,
1487 }; 1517 };
1488 int ret; 1518 int ret;
1489 1519
1490 BUG_ON(!PageLocked(page)); 1520 do {
1491 if (clear_page_dirty_for_io(page)) { 1521 if (clear_page_dirty_for_io(page)) {
1492 ret = nfs_writepage_locked(page, &wbc); 1522 ret = nfs_writepage_locked(page, &wbc);
1523 if (ret < 0)
1524 goto out_error;
1525 } else if (!PagePrivate(page))
1526 break;
1527 ret = nfs_sync_mapping_wait(page->mapping, &wbc, how);
1493 if (ret < 0) 1528 if (ret < 0)
1494 goto out; 1529 goto out_error;
1495 } 1530 } while (PagePrivate(page));
1496 if (!PagePrivate(page)) 1531 return 0;
1497 return 0; 1532out_error:
1498 ret = nfs_sync_mapping_wait(page->mapping, &wbc, how);
1499 if (ret >= 0)
1500 return 0;
1501out:
1502 __mark_inode_dirty(inode, I_DIRTY_PAGES); 1533 __mark_inode_dirty(inode, I_DIRTY_PAGES);
1503 return ret; 1534 return ret;
1504} 1535}
diff --git a/fs/nfsd/auth.c b/fs/nfsd/auth.c
index d13403e33622..294992e9bf69 100644
--- a/fs/nfsd/auth.c
+++ b/fs/nfsd/auth.c
@@ -10,6 +10,7 @@
10#include <linux/sunrpc/svcauth.h> 10#include <linux/sunrpc/svcauth.h>
11#include <linux/nfsd/nfsd.h> 11#include <linux/nfsd/nfsd.h>
12#include <linux/nfsd/export.h> 12#include <linux/nfsd/export.h>
13#include "auth.h"
13 14
14int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp) 15int nfsexp_flags(struct svc_rqst *rqstp, struct svc_export *exp)
15{ 16{
diff --git a/fs/nfsd/export.c b/fs/nfsd/export.c
index 8a6f7c924c75..33bfcf09db46 100644
--- a/fs/nfsd/export.c
+++ b/fs/nfsd/export.c
@@ -35,6 +35,7 @@
35#include <linux/lockd/bind.h> 35#include <linux/lockd/bind.h>
36#include <linux/sunrpc/msg_prot.h> 36#include <linux/sunrpc/msg_prot.h>
37#include <linux/sunrpc/gss_api.h> 37#include <linux/sunrpc/gss_api.h>
38#include <net/ipv6.h>
38 39
39#define NFSDDBG_FACILITY NFSDDBG_EXPORT 40#define NFSDDBG_FACILITY NFSDDBG_EXPORT
40 41
@@ -1548,6 +1549,7 @@ exp_addclient(struct nfsctl_client *ncp)
1548{ 1549{
1549 struct auth_domain *dom; 1550 struct auth_domain *dom;
1550 int i, err; 1551 int i, err;
1552 struct in6_addr addr6;
1551 1553
1552 /* First, consistency check. */ 1554 /* First, consistency check. */
1553 err = -EINVAL; 1555 err = -EINVAL;
@@ -1566,9 +1568,10 @@ exp_addclient(struct nfsctl_client *ncp)
1566 goto out_unlock; 1568 goto out_unlock;
1567 1569
1568 /* Insert client into hashtable. */ 1570 /* Insert client into hashtable. */
1569 for (i = 0; i < ncp->cl_naddr; i++) 1571 for (i = 0; i < ncp->cl_naddr; i++) {
1570 auth_unix_add_addr(ncp->cl_addrlist[i], dom); 1572 ipv6_addr_set_v4mapped(ncp->cl_addrlist[i].s_addr, &addr6);
1571 1573 auth_unix_add_addr(&addr6, dom);
1574 }
1572 auth_unix_forget_old(dom); 1575 auth_unix_forget_old(dom);
1573 auth_domain_put(dom); 1576 auth_domain_put(dom);
1574 1577
diff --git a/fs/nfsd/nfs4callback.c b/fs/nfsd/nfs4callback.c
index aae2b29ae2c9..562abf3380d0 100644
--- a/fs/nfsd/nfs4callback.c
+++ b/fs/nfsd/nfs4callback.c
@@ -344,6 +344,21 @@ static struct rpc_version * nfs_cb_version[] = {
344 &nfs_cb_version4, 344 &nfs_cb_version4,
345}; 345};
346 346
347static struct rpc_program cb_program;
348
349static struct rpc_stat cb_stats = {
350 .program = &cb_program
351};
352
353#define NFS4_CALLBACK 0x40000000
354static struct rpc_program cb_program = {
355 .name = "nfs4_cb",
356 .number = NFS4_CALLBACK,
357 .nrvers = ARRAY_SIZE(nfs_cb_version),
358 .version = nfs_cb_version,
359 .stats = &cb_stats,
360};
361
347/* Reference counting, callback cleanup, etc., all look racy as heck. 362/* Reference counting, callback cleanup, etc., all look racy as heck.
348 * And why is cb_set an atomic? */ 363 * And why is cb_set an atomic? */
349 364
@@ -358,13 +373,12 @@ static int do_probe_callback(void *data)
358 .to_maxval = (NFSD_LEASE_TIME/2) * HZ, 373 .to_maxval = (NFSD_LEASE_TIME/2) * HZ,
359 .to_exponential = 1, 374 .to_exponential = 1,
360 }; 375 };
361 struct rpc_program * program = &cb->cb_program;
362 struct rpc_create_args args = { 376 struct rpc_create_args args = {
363 .protocol = IPPROTO_TCP, 377 .protocol = IPPROTO_TCP,
364 .address = (struct sockaddr *)&addr, 378 .address = (struct sockaddr *)&addr,
365 .addrsize = sizeof(addr), 379 .addrsize = sizeof(addr),
366 .timeout = &timeparms, 380 .timeout = &timeparms,
367 .program = program, 381 .program = &cb_program,
368 .version = nfs_cb_version[1]->number, 382 .version = nfs_cb_version[1]->number,
369 .authflavor = RPC_AUTH_UNIX, /* XXX: need AUTH_GSS... */ 383 .authflavor = RPC_AUTH_UNIX, /* XXX: need AUTH_GSS... */
370 .flags = (RPC_CLNT_CREATE_NOPING), 384 .flags = (RPC_CLNT_CREATE_NOPING),
@@ -382,16 +396,8 @@ static int do_probe_callback(void *data)
382 addr.sin_port = htons(cb->cb_port); 396 addr.sin_port = htons(cb->cb_port);
383 addr.sin_addr.s_addr = htonl(cb->cb_addr); 397 addr.sin_addr.s_addr = htonl(cb->cb_addr);
384 398
385 /* Initialize rpc_program */
386 program->name = "nfs4_cb";
387 program->number = cb->cb_prog;
388 program->nrvers = ARRAY_SIZE(nfs_cb_version);
389 program->version = nfs_cb_version;
390 program->stats = &cb->cb_stat;
391
392 /* Initialize rpc_stat */ 399 /* Initialize rpc_stat */
393 memset(program->stats, 0, sizeof(cb->cb_stat)); 400 memset(args.program->stats, 0, sizeof(struct rpc_stat));
394 program->stats->program = program;
395 401
396 /* Create RPC client */ 402 /* Create RPC client */
397 client = rpc_create(&args); 403 client = rpc_create(&args);
diff --git a/fs/nfsd/nfs4idmap.c b/fs/nfsd/nfs4idmap.c
index 996bd88b75ba..5b398421b051 100644
--- a/fs/nfsd/nfs4idmap.c
+++ b/fs/nfsd/nfs4idmap.c
@@ -202,7 +202,7 @@ static struct cache_detail idtoname_cache = {
202 .alloc = ent_alloc, 202 .alloc = ent_alloc,
203}; 203};
204 204
205int 205static int
206idtoname_parse(struct cache_detail *cd, char *buf, int buflen) 206idtoname_parse(struct cache_detail *cd, char *buf, int buflen)
207{ 207{
208 struct ent ent, *res; 208 struct ent ent, *res;
diff --git a/fs/nfsd/nfs4state.c b/fs/nfsd/nfs4state.c
index 81a75f3081f4..55dfdd71f1b0 100644
--- a/fs/nfsd/nfs4state.c
+++ b/fs/nfsd/nfs4state.c
@@ -1639,6 +1639,7 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_sta
1639 locks_init_lock(&fl); 1639 locks_init_lock(&fl);
1640 fl.fl_lmops = &nfsd_lease_mng_ops; 1640 fl.fl_lmops = &nfsd_lease_mng_ops;
1641 fl.fl_flags = FL_LEASE; 1641 fl.fl_flags = FL_LEASE;
1642 fl.fl_type = flag == NFS4_OPEN_DELEGATE_READ? F_RDLCK: F_WRLCK;
1642 fl.fl_end = OFFSET_MAX; 1643 fl.fl_end = OFFSET_MAX;
1643 fl.fl_owner = (fl_owner_t)dp; 1644 fl.fl_owner = (fl_owner_t)dp;
1644 fl.fl_file = stp->st_vfs_file; 1645 fl.fl_file = stp->st_vfs_file;
@@ -1647,8 +1648,7 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_sta
1647 /* vfs_setlease checks to see if delegation should be handed out. 1648 /* vfs_setlease checks to see if delegation should be handed out.
1648 * the lock_manager callbacks fl_mylease and fl_change are used 1649 * the lock_manager callbacks fl_mylease and fl_change are used
1649 */ 1650 */
1650 if ((status = vfs_setlease(stp->st_vfs_file, 1651 if ((status = vfs_setlease(stp->st_vfs_file, fl.fl_type, &flp))) {
1651 flag == NFS4_OPEN_DELEGATE_READ? F_RDLCK: F_WRLCK, &flp))) {
1652 dprintk("NFSD: setlease failed [%d], no delegation\n", status); 1652 dprintk("NFSD: setlease failed [%d], no delegation\n", status);
1653 unhash_delegation(dp); 1653 unhash_delegation(dp);
1654 flag = NFS4_OPEN_DELEGATE_NONE; 1654 flag = NFS4_OPEN_DELEGATE_NONE;
@@ -1763,10 +1763,6 @@ out:
1763 return status; 1763 return status;
1764} 1764}
1765 1765
1766static struct workqueue_struct *laundry_wq;
1767static void laundromat_main(struct work_struct *);
1768static DECLARE_DELAYED_WORK(laundromat_work, laundromat_main);
1769
1770__be32 1766__be32
1771nfsd4_renew(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate, 1767nfsd4_renew(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
1772 clientid_t *clid) 1768 clientid_t *clid)
@@ -1874,7 +1870,11 @@ nfs4_laundromat(void)
1874 return clientid_val; 1870 return clientid_val;
1875} 1871}
1876 1872
1877void 1873static struct workqueue_struct *laundry_wq;
1874static void laundromat_main(struct work_struct *);
1875static DECLARE_DELAYED_WORK(laundromat_work, laundromat_main);
1876
1877static void
1878laundromat_main(struct work_struct *not_used) 1878laundromat_main(struct work_struct *not_used)
1879{ 1879{
1880 time_t t; 1880 time_t t;
@@ -1975,6 +1975,26 @@ io_during_grace_disallowed(struct inode *inode, int flags)
1975 && mandatory_lock(inode); 1975 && mandatory_lock(inode);
1976} 1976}
1977 1977
1978static int check_stateid_generation(stateid_t *in, stateid_t *ref)
1979{
1980 /* If the client sends us a stateid from the future, it's buggy: */
1981 if (in->si_generation > ref->si_generation)
1982 return nfserr_bad_stateid;
1983 /*
1984 * The following, however, can happen. For example, if the
1985 * client sends an open and some IO at the same time, the open
1986 * may bump si_generation while the IO is still in flight.
1987 * Thanks to hard links and renames, the client never knows what
1988 * file an open will affect. So it could avoid that situation
1989 * only by serializing all opens and IO from the same open
1990 * owner. To recover from the old_stateid error, the client
1991 * will just have to retry the IO:
1992 */
1993 if (in->si_generation < ref->si_generation)
1994 return nfserr_old_stateid;
1995 return nfs_ok;
1996}
1997
1978/* 1998/*
1979* Checks for stateid operations 1999* Checks for stateid operations
1980*/ 2000*/
@@ -2023,12 +2043,8 @@ nfs4_preprocess_stateid_op(struct svc_fh *current_fh, stateid_t *stateid, int fl
2023 goto out; 2043 goto out;
2024 stidp = &stp->st_stateid; 2044 stidp = &stp->st_stateid;
2025 } 2045 }
2026 if (stateid->si_generation > stidp->si_generation) 2046 status = check_stateid_generation(stateid, stidp);
2027 goto out; 2047 if (status)
2028
2029 /* OLD STATEID */
2030 status = nfserr_old_stateid;
2031 if (stateid->si_generation < stidp->si_generation)
2032 goto out; 2048 goto out;
2033 if (stp) { 2049 if (stp) {
2034 if ((status = nfs4_check_openmode(stp,flags))) 2050 if ((status = nfs4_check_openmode(stp,flags)))
@@ -2036,7 +2052,7 @@ nfs4_preprocess_stateid_op(struct svc_fh *current_fh, stateid_t *stateid, int fl
2036 renew_client(stp->st_stateowner->so_client); 2052 renew_client(stp->st_stateowner->so_client);
2037 if (filpp) 2053 if (filpp)
2038 *filpp = stp->st_vfs_file; 2054 *filpp = stp->st_vfs_file;
2039 } else if (dp) { 2055 } else {
2040 if ((status = nfs4_check_delegmode(dp, flags))) 2056 if ((status = nfs4_check_delegmode(dp, flags)))
2041 goto out; 2057 goto out;
2042 renew_client(dp->dl_client); 2058 renew_client(dp->dl_client);
@@ -2065,6 +2081,7 @@ nfs4_preprocess_seqid_op(struct svc_fh *current_fh, u32 seqid, stateid_t *statei
2065{ 2081{
2066 struct nfs4_stateid *stp; 2082 struct nfs4_stateid *stp;
2067 struct nfs4_stateowner *sop; 2083 struct nfs4_stateowner *sop;
2084 __be32 status;
2068 2085
2069 dprintk("NFSD: preprocess_seqid_op: seqid=%d " 2086 dprintk("NFSD: preprocess_seqid_op: seqid=%d "
2070 "stateid = (%08x/%08x/%08x/%08x)\n", seqid, 2087 "stateid = (%08x/%08x/%08x/%08x)\n", seqid,
@@ -2127,7 +2144,7 @@ nfs4_preprocess_seqid_op(struct svc_fh *current_fh, u32 seqid, stateid_t *statei
2127 } 2144 }
2128 } 2145 }
2129 2146
2130 if ((flags & CHECK_FH) && nfs4_check_fh(current_fh, stp)) { 2147 if (nfs4_check_fh(current_fh, stp)) {
2131 dprintk("NFSD: preprocess_seqid_op: fh-stateid mismatch!\n"); 2148 dprintk("NFSD: preprocess_seqid_op: fh-stateid mismatch!\n");
2132 return nfserr_bad_stateid; 2149 return nfserr_bad_stateid;
2133 } 2150 }
@@ -2150,15 +2167,9 @@ nfs4_preprocess_seqid_op(struct svc_fh *current_fh, u32 seqid, stateid_t *statei
2150 " confirmed yet!\n"); 2167 " confirmed yet!\n");
2151 return nfserr_bad_stateid; 2168 return nfserr_bad_stateid;
2152 } 2169 }
2153 if (stateid->si_generation > stp->st_stateid.si_generation) { 2170 status = check_stateid_generation(stateid, &stp->st_stateid);
2154 dprintk("NFSD: preprocess_seqid_op: future stateid?!\n"); 2171 if (status)
2155 return nfserr_bad_stateid; 2172 return status;
2156 }
2157
2158 if (stateid->si_generation < stp->st_stateid.si_generation) {
2159 dprintk("NFSD: preprocess_seqid_op: old stateid!\n");
2160 return nfserr_old_stateid;
2161 }
2162 renew_client(sop->so_client); 2173 renew_client(sop->so_client);
2163 return nfs_ok; 2174 return nfs_ok;
2164 2175
@@ -2194,7 +2205,7 @@ nfsd4_open_confirm(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2194 2205
2195 if ((status = nfs4_preprocess_seqid_op(&cstate->current_fh, 2206 if ((status = nfs4_preprocess_seqid_op(&cstate->current_fh,
2196 oc->oc_seqid, &oc->oc_req_stateid, 2207 oc->oc_seqid, &oc->oc_req_stateid,
2197 CHECK_FH | CONFIRM | OPEN_STATE, 2208 CONFIRM | OPEN_STATE,
2198 &oc->oc_stateowner, &stp, NULL))) 2209 &oc->oc_stateowner, &stp, NULL)))
2199 goto out; 2210 goto out;
2200 2211
@@ -2265,7 +2276,7 @@ nfsd4_open_downgrade(struct svc_rqst *rqstp,
2265 if ((status = nfs4_preprocess_seqid_op(&cstate->current_fh, 2276 if ((status = nfs4_preprocess_seqid_op(&cstate->current_fh,
2266 od->od_seqid, 2277 od->od_seqid,
2267 &od->od_stateid, 2278 &od->od_stateid,
2268 CHECK_FH | OPEN_STATE, 2279 OPEN_STATE,
2269 &od->od_stateowner, &stp, NULL))) 2280 &od->od_stateowner, &stp, NULL)))
2270 goto out; 2281 goto out;
2271 2282
@@ -2318,7 +2329,7 @@ nfsd4_close(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2318 if ((status = nfs4_preprocess_seqid_op(&cstate->current_fh, 2329 if ((status = nfs4_preprocess_seqid_op(&cstate->current_fh,
2319 close->cl_seqid, 2330 close->cl_seqid,
2320 &close->cl_stateid, 2331 &close->cl_stateid,
2321 CHECK_FH | OPEN_STATE | CLOSE_STATE, 2332 OPEN_STATE | CLOSE_STATE,
2322 &close->cl_stateowner, &stp, NULL))) 2333 &close->cl_stateowner, &stp, NULL)))
2323 goto out; 2334 goto out;
2324 status = nfs_ok; 2335 status = nfs_ok;
@@ -2623,7 +2634,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2623 status = nfs4_preprocess_seqid_op(&cstate->current_fh, 2634 status = nfs4_preprocess_seqid_op(&cstate->current_fh,
2624 lock->lk_new_open_seqid, 2635 lock->lk_new_open_seqid,
2625 &lock->lk_new_open_stateid, 2636 &lock->lk_new_open_stateid,
2626 CHECK_FH | OPEN_STATE, 2637 OPEN_STATE,
2627 &lock->lk_replay_owner, &open_stp, 2638 &lock->lk_replay_owner, &open_stp,
2628 lock); 2639 lock);
2629 if (status) 2640 if (status)
@@ -2650,7 +2661,7 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2650 status = nfs4_preprocess_seqid_op(&cstate->current_fh, 2661 status = nfs4_preprocess_seqid_op(&cstate->current_fh,
2651 lock->lk_old_lock_seqid, 2662 lock->lk_old_lock_seqid,
2652 &lock->lk_old_lock_stateid, 2663 &lock->lk_old_lock_stateid,
2653 CHECK_FH | LOCK_STATE, 2664 LOCK_STATE,
2654 &lock->lk_replay_owner, &lock_stp, lock); 2665 &lock->lk_replay_owner, &lock_stp, lock);
2655 if (status) 2666 if (status)
2656 goto out; 2667 goto out;
@@ -2847,7 +2858,7 @@ nfsd4_locku(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
2847 if ((status = nfs4_preprocess_seqid_op(&cstate->current_fh, 2858 if ((status = nfs4_preprocess_seqid_op(&cstate->current_fh,
2848 locku->lu_seqid, 2859 locku->lu_seqid,
2849 &locku->lu_stateid, 2860 &locku->lu_stateid,
2850 CHECK_FH | LOCK_STATE, 2861 LOCK_STATE,
2851 &locku->lu_stateowner, &stp, NULL))) 2862 &locku->lu_stateowner, &stp, NULL)))
2852 goto out; 2863 goto out;
2853 2864
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 0e6a179eccaf..1ba7ad981935 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -1867,6 +1867,15 @@ out_serverfault:
1867 goto out; 1867 goto out;
1868} 1868}
1869 1869
1870static inline int attributes_need_mount(u32 *bmval)
1871{
1872 if (bmval[0] & ~(FATTR4_WORD0_RDATTR_ERROR | FATTR4_WORD0_LEASE_TIME))
1873 return 1;
1874 if (bmval[1] & ~FATTR4_WORD1_MOUNTED_ON_FILEID)
1875 return 1;
1876 return 0;
1877}
1878
1870static __be32 1879static __be32
1871nfsd4_encode_dirent_fattr(struct nfsd4_readdir *cd, 1880nfsd4_encode_dirent_fattr(struct nfsd4_readdir *cd,
1872 const char *name, int namlen, __be32 *p, int *buflen) 1881 const char *name, int namlen, __be32 *p, int *buflen)
@@ -1888,9 +1897,7 @@ nfsd4_encode_dirent_fattr(struct nfsd4_readdir *cd,
1888 * we will not follow the cross mount and will fill the attribtutes 1897 * we will not follow the cross mount and will fill the attribtutes
1889 * directly from the mountpoint dentry. 1898 * directly from the mountpoint dentry.
1890 */ 1899 */
1891 if (d_mountpoint(dentry) && 1900 if (d_mountpoint(dentry) && !attributes_need_mount(cd->rd_bmval))
1892 (cd->rd_bmval[0] & ~FATTR4_WORD0_RDATTR_ERROR) == 0 &&
1893 (cd->rd_bmval[1] & ~FATTR4_WORD1_MOUNTED_ON_FILEID) == 0)
1894 ignore_crossmnt = 1; 1901 ignore_crossmnt = 1;
1895 else if (d_mountpoint(dentry)) { 1902 else if (d_mountpoint(dentry)) {
1896 int err; 1903 int err;
diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c
index 8516137cdbb0..613bcb8171a5 100644
--- a/fs/nfsd/nfsctl.c
+++ b/fs/nfsd/nfsctl.c
@@ -37,6 +37,7 @@
37#include <linux/nfsd/syscall.h> 37#include <linux/nfsd/syscall.h>
38 38
39#include <asm/uaccess.h> 39#include <asm/uaccess.h>
40#include <net/ipv6.h>
40 41
41/* 42/*
42 * We have a single directory with 9 nodes in it. 43 * We have a single directory with 9 nodes in it.
@@ -149,7 +150,6 @@ static const struct file_operations transaction_ops = {
149 .release = simple_transaction_release, 150 .release = simple_transaction_release,
150}; 151};
151 152
152extern struct seq_operations nfs_exports_op;
153static int exports_open(struct inode *inode, struct file *file) 153static int exports_open(struct inode *inode, struct file *file)
154{ 154{
155 return seq_open(file, &nfs_exports_op); 155 return seq_open(file, &nfs_exports_op);
@@ -222,6 +222,7 @@ static ssize_t write_getfs(struct file *file, char *buf, size_t size)
222 struct auth_domain *clp; 222 struct auth_domain *clp;
223 int err = 0; 223 int err = 0;
224 struct knfsd_fh *res; 224 struct knfsd_fh *res;
225 struct in6_addr in6;
225 226
226 if (size < sizeof(*data)) 227 if (size < sizeof(*data))
227 return -EINVAL; 228 return -EINVAL;
@@ -236,7 +237,11 @@ static ssize_t write_getfs(struct file *file, char *buf, size_t size)
236 res = (struct knfsd_fh*)buf; 237 res = (struct knfsd_fh*)buf;
237 238
238 exp_readlock(); 239 exp_readlock();
239 if (!(clp = auth_unix_lookup(sin->sin_addr))) 240
241 ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6);
242
243 clp = auth_unix_lookup(&in6);
244 if (!clp)
240 err = -EPERM; 245 err = -EPERM;
241 else { 246 else {
242 err = exp_rootfh(clp, data->gd_path, res, data->gd_maxlen); 247 err = exp_rootfh(clp, data->gd_path, res, data->gd_maxlen);
@@ -257,6 +262,7 @@ static ssize_t write_getfd(struct file *file, char *buf, size_t size)
257 int err = 0; 262 int err = 0;
258 struct knfsd_fh fh; 263 struct knfsd_fh fh;
259 char *res; 264 char *res;
265 struct in6_addr in6;
260 266
261 if (size < sizeof(*data)) 267 if (size < sizeof(*data))
262 return -EINVAL; 268 return -EINVAL;
@@ -271,7 +277,11 @@ static ssize_t write_getfd(struct file *file, char *buf, size_t size)
271 res = buf; 277 res = buf;
272 sin = (struct sockaddr_in *)&data->gd_addr; 278 sin = (struct sockaddr_in *)&data->gd_addr;
273 exp_readlock(); 279 exp_readlock();
274 if (!(clp = auth_unix_lookup(sin->sin_addr))) 280
281 ipv6_addr_set_v4mapped(sin->sin_addr.s_addr, &in6);
282
283 clp = auth_unix_lookup(&in6);
284 if (!clp)
275 err = -EPERM; 285 err = -EPERM;
276 else { 286 else {
277 err = exp_rootfh(clp, data->gd_path, &fh, NFS_FHSIZE); 287 err = exp_rootfh(clp, data->gd_path, &fh, NFS_FHSIZE);
@@ -347,8 +357,6 @@ static ssize_t write_filehandle(struct file *file, char *buf, size_t size)
347 return mesg - buf; 357 return mesg - buf;
348} 358}
349 359
350extern int nfsd_nrthreads(void);
351
352static ssize_t write_threads(struct file *file, char *buf, size_t size) 360static ssize_t write_threads(struct file *file, char *buf, size_t size)
353{ 361{
354 /* if size > 0, look for a number of threads and call nfsd_svc 362 /* if size > 0, look for a number of threads and call nfsd_svc
@@ -371,10 +379,6 @@ static ssize_t write_threads(struct file *file, char *buf, size_t size)
371 return strlen(buf); 379 return strlen(buf);
372} 380}
373 381
374extern int nfsd_nrpools(void);
375extern int nfsd_get_nrthreads(int n, int *);
376extern int nfsd_set_nrthreads(int n, int *);
377
378static ssize_t write_pool_threads(struct file *file, char *buf, size_t size) 382static ssize_t write_pool_threads(struct file *file, char *buf, size_t size)
379{ 383{
380 /* if size > 0, look for an array of number of threads per node 384 /* if size > 0, look for an array of number of threads per node
diff --git a/fs/nfsd/nfsfh.c b/fs/nfsd/nfsfh.c
index 3e6b3f41ee1f..100ae5641162 100644
--- a/fs/nfsd/nfsfh.c
+++ b/fs/nfsd/nfsfh.c
@@ -113,6 +113,124 @@ static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp,
113} 113}
114 114
115/* 115/*
116 * Use the given filehandle to look up the corresponding export and
117 * dentry. On success, the results are used to set fh_export and
118 * fh_dentry.
119 */
120static __be32 nfsd_set_fh_dentry(struct svc_rqst *rqstp, struct svc_fh *fhp)
121{
122 struct knfsd_fh *fh = &fhp->fh_handle;
123 struct fid *fid = NULL, sfid;
124 struct svc_export *exp;
125 struct dentry *dentry;
126 int fileid_type;
127 int data_left = fh->fh_size/4;
128 __be32 error;
129
130 error = nfserr_stale;
131 if (rqstp->rq_vers > 2)
132 error = nfserr_badhandle;
133 if (rqstp->rq_vers == 4 && fh->fh_size == 0)
134 return nfserr_nofilehandle;
135
136 if (fh->fh_version == 1) {
137 int len;
138
139 if (--data_left < 0)
140 return error;
141 if (fh->fh_auth_type != 0)
142 return error;
143 len = key_len(fh->fh_fsid_type) / 4;
144 if (len == 0)
145 return error;
146 if (fh->fh_fsid_type == FSID_MAJOR_MINOR) {
147 /* deprecated, convert to type 3 */
148 len = key_len(FSID_ENCODE_DEV)/4;
149 fh->fh_fsid_type = FSID_ENCODE_DEV;
150 fh->fh_fsid[0] = new_encode_dev(MKDEV(ntohl(fh->fh_fsid[0]), ntohl(fh->fh_fsid[1])));
151 fh->fh_fsid[1] = fh->fh_fsid[2];
152 }
153 data_left -= len;
154 if (data_left < 0)
155 return error;
156 exp = rqst_exp_find(rqstp, fh->fh_fsid_type, fh->fh_auth);
157 fid = (struct fid *)(fh->fh_auth + len);
158 } else {
159 __u32 tfh[2];
160 dev_t xdev;
161 ino_t xino;
162
163 if (fh->fh_size != NFS_FHSIZE)
164 return error;
165 /* assume old filehandle format */
166 xdev = old_decode_dev(fh->ofh_xdev);
167 xino = u32_to_ino_t(fh->ofh_xino);
168 mk_fsid(FSID_DEV, tfh, xdev, xino, 0, NULL);
169 exp = rqst_exp_find(rqstp, FSID_DEV, tfh);
170 }
171
172 error = nfserr_stale;
173 if (PTR_ERR(exp) == -ENOENT)
174 return error;
175
176 if (IS_ERR(exp))
177 return nfserrno(PTR_ERR(exp));
178
179 error = nfsd_setuser_and_check_port(rqstp, exp);
180 if (error)
181 goto out;
182
183 /*
184 * Look up the dentry using the NFS file handle.
185 */
186 error = nfserr_stale;
187 if (rqstp->rq_vers > 2)
188 error = nfserr_badhandle;
189
190 if (fh->fh_version != 1) {
191 sfid.i32.ino = fh->ofh_ino;
192 sfid.i32.gen = fh->ofh_generation;
193 sfid.i32.parent_ino = fh->ofh_dirino;
194 fid = &sfid;
195 data_left = 3;
196 if (fh->ofh_dirino == 0)
197 fileid_type = FILEID_INO32_GEN;
198 else
199 fileid_type = FILEID_INO32_GEN_PARENT;
200 } else
201 fileid_type = fh->fh_fileid_type;
202
203 if (fileid_type == FILEID_ROOT)
204 dentry = dget(exp->ex_path.dentry);
205 else {
206 dentry = exportfs_decode_fh(exp->ex_path.mnt, fid,
207 data_left, fileid_type,
208 nfsd_acceptable, exp);
209 }
210 if (dentry == NULL)
211 goto out;
212 if (IS_ERR(dentry)) {
213 if (PTR_ERR(dentry) != -EINVAL)
214 error = nfserrno(PTR_ERR(dentry));
215 goto out;
216 }
217
218 if (S_ISDIR(dentry->d_inode->i_mode) &&
219 (dentry->d_flags & DCACHE_DISCONNECTED)) {
220 printk("nfsd: find_fh_dentry returned a DISCONNECTED directory: %s/%s\n",
221 dentry->d_parent->d_name.name, dentry->d_name.name);
222 }
223
224 fhp->fh_dentry = dentry;
225 fhp->fh_export = exp;
226 nfsd_nr_verified++;
227 return 0;
228out:
229 exp_put(exp);
230 return error;
231}
232
233/*
116 * Perform sanity checks on the dentry in a client's file handle. 234 * Perform sanity checks on the dentry in a client's file handle.
117 * 235 *
118 * Note that the file handle dentry may need to be freed even after 236 * Note that the file handle dentry may need to be freed even after
@@ -124,115 +242,18 @@ static __be32 nfsd_setuser_and_check_port(struct svc_rqst *rqstp,
124__be32 242__be32
125fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access) 243fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access)
126{ 244{
127 struct knfsd_fh *fh = &fhp->fh_handle; 245 struct svc_export *exp;
128 struct svc_export *exp = NULL;
129 struct dentry *dentry; 246 struct dentry *dentry;
130 __be32 error = 0; 247 __be32 error;
131 248
132 dprintk("nfsd: fh_verify(%s)\n", SVCFH_fmt(fhp)); 249 dprintk("nfsd: fh_verify(%s)\n", SVCFH_fmt(fhp));
133 250
134 if (!fhp->fh_dentry) { 251 if (!fhp->fh_dentry) {
135 struct fid *fid = NULL, sfid; 252 error = nfsd_set_fh_dentry(rqstp, fhp);
136 int fileid_type;
137 int data_left = fh->fh_size/4;
138
139 error = nfserr_stale;
140 if (rqstp->rq_vers > 2)
141 error = nfserr_badhandle;
142 if (rqstp->rq_vers == 4 && fh->fh_size == 0)
143 return nfserr_nofilehandle;
144
145 if (fh->fh_version == 1) {
146 int len;
147 if (--data_left<0) goto out;
148 switch (fh->fh_auth_type) {
149 case 0: break;
150 default: goto out;
151 }
152 len = key_len(fh->fh_fsid_type) / 4;
153 if (len == 0) goto out;
154 if (fh->fh_fsid_type == FSID_MAJOR_MINOR) {
155 /* deprecated, convert to type 3 */
156 len = key_len(FSID_ENCODE_DEV)/4;
157 fh->fh_fsid_type = FSID_ENCODE_DEV;
158 fh->fh_fsid[0] = new_encode_dev(MKDEV(ntohl(fh->fh_fsid[0]), ntohl(fh->fh_fsid[1])));
159 fh->fh_fsid[1] = fh->fh_fsid[2];
160 }
161 if ((data_left -= len)<0) goto out;
162 exp = rqst_exp_find(rqstp, fh->fh_fsid_type,
163 fh->fh_auth);
164 fid = (struct fid *)(fh->fh_auth + len);
165 } else {
166 __u32 tfh[2];
167 dev_t xdev;
168 ino_t xino;
169 if (fh->fh_size != NFS_FHSIZE)
170 goto out;
171 /* assume old filehandle format */
172 xdev = old_decode_dev(fh->ofh_xdev);
173 xino = u32_to_ino_t(fh->ofh_xino);
174 mk_fsid(FSID_DEV, tfh, xdev, xino, 0, NULL);
175 exp = rqst_exp_find(rqstp, FSID_DEV, tfh);
176 }
177
178 error = nfserr_stale;
179 if (PTR_ERR(exp) == -ENOENT)
180 goto out;
181
182 if (IS_ERR(exp)) {
183 error = nfserrno(PTR_ERR(exp));
184 goto out;
185 }
186
187 error = nfsd_setuser_and_check_port(rqstp, exp);
188 if (error) 253 if (error)
189 goto out; 254 goto out;
190 255 dentry = fhp->fh_dentry;
191 /* 256 exp = fhp->fh_export;
192 * Look up the dentry using the NFS file handle.
193 */
194 error = nfserr_stale;
195 if (rqstp->rq_vers > 2)
196 error = nfserr_badhandle;
197
198 if (fh->fh_version != 1) {
199 sfid.i32.ino = fh->ofh_ino;
200 sfid.i32.gen = fh->ofh_generation;
201 sfid.i32.parent_ino = fh->ofh_dirino;
202 fid = &sfid;
203 data_left = 3;
204 if (fh->ofh_dirino == 0)
205 fileid_type = FILEID_INO32_GEN;
206 else
207 fileid_type = FILEID_INO32_GEN_PARENT;
208 } else
209 fileid_type = fh->fh_fileid_type;
210
211 if (fileid_type == FILEID_ROOT)
212 dentry = dget(exp->ex_path.dentry);
213 else {
214 dentry = exportfs_decode_fh(exp->ex_path.mnt, fid,
215 data_left, fileid_type,
216 nfsd_acceptable, exp);
217 }
218 if (dentry == NULL)
219 goto out;
220 if (IS_ERR(dentry)) {
221 if (PTR_ERR(dentry) != -EINVAL)
222 error = nfserrno(PTR_ERR(dentry));
223 goto out;
224 }
225
226 if (S_ISDIR(dentry->d_inode->i_mode) &&
227 (dentry->d_flags & DCACHE_DISCONNECTED)) {
228 printk("nfsd: find_fh_dentry returned a DISCONNECTED directory: %s/%s\n",
229 dentry->d_parent->d_name.name, dentry->d_name.name);
230 }
231
232 fhp->fh_dentry = dentry;
233 fhp->fh_export = exp;
234 nfsd_nr_verified++;
235 cache_get(&exp->h);
236 } else { 257 } else {
237 /* 258 /*
238 * just rechecking permissions 259 * just rechecking permissions
@@ -242,7 +263,6 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access)
242 dprintk("nfsd: fh_verify - just checking\n"); 263 dprintk("nfsd: fh_verify - just checking\n");
243 dentry = fhp->fh_dentry; 264 dentry = fhp->fh_dentry;
244 exp = fhp->fh_export; 265 exp = fhp->fh_export;
245 cache_get(&exp->h);
246 /* 266 /*
247 * Set user creds for this exportpoint; necessary even 267 * Set user creds for this exportpoint; necessary even
248 * in the "just checking" case because this may be a 268 * in the "just checking" case because this may be a
@@ -281,8 +301,6 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access)
281 access, ntohl(error)); 301 access, ntohl(error));
282 } 302 }
283out: 303out:
284 if (exp && !IS_ERR(exp))
285 exp_put(exp);
286 if (error == nfserr_stale) 304 if (error == nfserr_stale)
287 nfsdstats.fh_stale++; 305 nfsdstats.fh_stale++;
288 return error; 306 return error;
diff --git a/fs/nfsd/nfssvc.c b/fs/nfsd/nfssvc.c
index 9647b0f7bc0c..941041f4b136 100644
--- a/fs/nfsd/nfssvc.c
+++ b/fs/nfsd/nfssvc.c
@@ -244,7 +244,6 @@ static int nfsd_init_socks(int port)
244 if (error < 0) 244 if (error < 0)
245 return error; 245 return error;
246 246
247#ifdef CONFIG_NFSD_TCP
248 error = lockd_up(IPPROTO_TCP); 247 error = lockd_up(IPPROTO_TCP);
249 if (error >= 0) { 248 if (error >= 0) {
250 error = svc_create_xprt(nfsd_serv, "tcp", port, 249 error = svc_create_xprt(nfsd_serv, "tcp", port,
@@ -254,7 +253,6 @@ static int nfsd_init_socks(int port)
254 } 253 }
255 if (error < 0) 254 if (error < 0)
256 return error; 255 return error;
257#endif
258 return 0; 256 return 0;
259} 257}
260 258
diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
index 304bf5f643c9..a3a291f771f4 100644
--- a/fs/nfsd/vfs.c
+++ b/fs/nfsd/vfs.c
@@ -264,7 +264,6 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap,
264 struct inode *inode; 264 struct inode *inode;
265 int accmode = MAY_SATTR; 265 int accmode = MAY_SATTR;
266 int ftype = 0; 266 int ftype = 0;
267 int imode;
268 __be32 err; 267 __be32 err;
269 int host_err; 268 int host_err;
270 int size_change = 0; 269 int size_change = 0;
@@ -360,25 +359,25 @@ nfsd_setattr(struct svc_rqst *rqstp, struct svc_fh *fhp, struct iattr *iap,
360 DQUOT_INIT(inode); 359 DQUOT_INIT(inode);
361 } 360 }
362 361
363 imode = inode->i_mode; 362 /* sanitize the mode change */
364 if (iap->ia_valid & ATTR_MODE) { 363 if (iap->ia_valid & ATTR_MODE) {
365 iap->ia_mode &= S_IALLUGO; 364 iap->ia_mode &= S_IALLUGO;
366 imode = iap->ia_mode |= (imode & ~S_IALLUGO); 365 iap->ia_mode |= (inode->i_mode & ~S_IALLUGO);
367 /* if changing uid/gid revoke setuid/setgid in mode */ 366 }
368 if ((iap->ia_valid & ATTR_UID) && iap->ia_uid != inode->i_uid) { 367
369 iap->ia_valid |= ATTR_KILL_PRIV; 368 /* Revoke setuid/setgid on chown */
369 if (((iap->ia_valid & ATTR_UID) && iap->ia_uid != inode->i_uid) ||
370 ((iap->ia_valid & ATTR_GID) && iap->ia_gid != inode->i_gid)) {
371 iap->ia_valid |= ATTR_KILL_PRIV;
372 if (iap->ia_valid & ATTR_MODE) {
373 /* we're setting mode too, just clear the s*id bits */
370 iap->ia_mode &= ~S_ISUID; 374 iap->ia_mode &= ~S_ISUID;
375 if (iap->ia_mode & S_IXGRP)
376 iap->ia_mode &= ~S_ISGID;
377 } else {
378 /* set ATTR_KILL_* bits and let VFS handle it */
379 iap->ia_valid |= (ATTR_KILL_SUID | ATTR_KILL_SGID);
371 } 380 }
372 if ((iap->ia_valid & ATTR_GID) && iap->ia_gid != inode->i_gid)
373 iap->ia_mode &= ~S_ISGID;
374 } else {
375 /*
376 * Revoke setuid/setgid bit on chown/chgrp
377 */
378 if ((iap->ia_valid & ATTR_UID) && iap->ia_uid != inode->i_uid)
379 iap->ia_valid |= ATTR_KILL_SUID | ATTR_KILL_PRIV;
380 if ((iap->ia_valid & ATTR_GID) && iap->ia_gid != inode->i_gid)
381 iap->ia_valid |= ATTR_KILL_SGID;
382 } 381 }
383 382
384 /* Change the attributes. */ 383 /* Change the attributes. */
@@ -988,7 +987,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
988 * flushing the data to disk is handled separately below. 987 * flushing the data to disk is handled separately below.
989 */ 988 */
990 989
991 if (file->f_op->fsync == 0) {/* COMMIT3 cannot work */ 990 if (!file->f_op->fsync) {/* COMMIT3 cannot work */
992 stable = 2; 991 stable = 2;
993 *stablep = 2; /* FILE_SYNC */ 992 *stablep = 2; /* FILE_SYNC */
994 } 993 }
@@ -1152,7 +1151,7 @@ nfsd_commit(struct svc_rqst *rqstp, struct svc_fh *fhp,
1152} 1151}
1153#endif /* CONFIG_NFSD_V3 */ 1152#endif /* CONFIG_NFSD_V3 */
1154 1153
1155__be32 1154static __be32
1156nfsd_create_setattr(struct svc_rqst *rqstp, struct svc_fh *resfhp, 1155nfsd_create_setattr(struct svc_rqst *rqstp, struct svc_fh *resfhp,
1157 struct iattr *iap) 1156 struct iattr *iap)
1158{ 1157{
diff --git a/include/asm-blackfin/.gitignore b/include/asm-blackfin/.gitignore
new file mode 100644
index 000000000000..7858564a4466
--- /dev/null
+++ b/include/asm-blackfin/.gitignore
@@ -0,0 +1 @@
+mach
diff --git a/include/asm-blackfin/bfin-global.h b/include/asm-blackfin/bfin-global.h
index 5dba3a735596..716df7c85923 100644
--- a/include/asm-blackfin/bfin-global.h
+++ b/include/asm-blackfin/bfin-global.h
@@ -112,20 +112,10 @@ extern void init_leds(void);
112 112
113extern const char bfin_board_name[]; 113extern const char bfin_board_name[];
114extern unsigned long wall_jiffies; 114extern unsigned long wall_jiffies;
115extern unsigned long ipdt_table[];
116extern unsigned long dpdt_table[];
117extern unsigned long icplb_table[];
118extern unsigned long dcplb_table[];
119
120extern unsigned long ipdt_swapcount_table[];
121extern unsigned long dpdt_swapcount_table[];
122
123extern unsigned long table_start, table_end;
124 115
125extern unsigned long bfin_sic_iwr[]; 116extern unsigned long bfin_sic_iwr[];
126extern u16 _bfin_swrst; /* shadow for Software Reset Register (SWRST) */ 117extern u16 _bfin_swrst; /* shadow for Software Reset Register (SWRST) */
127extern struct file_operations dpmc_fops; 118extern struct file_operations dpmc_fops;
128extern char _start;
129extern unsigned long _ramstart, _ramend, _rambase; 119extern unsigned long _ramstart, _ramend, _rambase;
130extern unsigned long memory_start, memory_end, physical_mem_end; 120extern unsigned long memory_start, memory_end, physical_mem_end;
131extern char _stext_l1[], _etext_l1[], _sdata_l1[], _edata_l1[], _sbss_l1[], 121extern char _stext_l1[], _etext_l1[], _sdata_l1[], _edata_l1[], _sbss_l1[],
diff --git a/include/asm-blackfin/bug.h b/include/asm-blackfin/bug.h
index 41e53b29f167..6d3e11b1fc57 100644
--- a/include/asm-blackfin/bug.h
+++ b/include/asm-blackfin/bug.h
@@ -1,4 +1,17 @@
1#ifndef _BLACKFIN_BUG_H 1#ifndef _BLACKFIN_BUG_H
2#define _BLACKFIN_BUG_H 2#define _BLACKFIN_BUG_H
3
4#ifdef CONFIG_BUG
5#define HAVE_ARCH_BUG
6
7#define BUG() do { \
8 dump_bfin_trace_buffer(); \
9 printk(KERN_EMERG "BUG: failure at %s:%d/%s()!\n", __FILE__, __LINE__, __func__); \
10 panic("BUG!"); \
11} while (0)
12
13#endif
14
3#include <asm-generic/bug.h> 15#include <asm-generic/bug.h>
16
4#endif 17#endif
diff --git a/include/asm-blackfin/cplb.h b/include/asm-blackfin/cplb.h
index 654375c2b746..5b0da9a69b67 100644
--- a/include/asm-blackfin/cplb.h
+++ b/include/asm-blackfin/cplb.h
@@ -74,32 +74,6 @@
74#define ASYNC_MEMORY_CPLB_COVERAGE ((ASYNC_BANK0_SIZE + ASYNC_BANK1_SIZE + \ 74#define ASYNC_MEMORY_CPLB_COVERAGE ((ASYNC_BANK0_SIZE + ASYNC_BANK1_SIZE + \
75 ASYNC_BANK2_SIZE + ASYNC_BANK3_SIZE) / SIZE_4M) 75 ASYNC_BANK2_SIZE + ASYNC_BANK3_SIZE) / SIZE_4M)
76 76
77/*
78* Number of required data CPLB switchtable entries
79* MEMSIZE / 4 (we mostly install 4M page size CPLBs
80* approx 16 for smaller 1MB page size CPLBs for allignment purposes
81* 1 for L1 Data Memory
82* possibly 1 for L2 Data Memory
83* 1 for CONFIG_DEBUG_HUNT_FOR_ZERO
84* 1 for ASYNC Memory
85*/
86
87
88#define MAX_SWITCH_D_CPLBS (((CONFIG_MEM_SIZE / 4) + 16 + 1 + 1 + 1 \
89 + ASYNC_MEMORY_CPLB_COVERAGE) * 2)
90
91/*
92* Number of required instruction CPLB switchtable entries
93* MEMSIZE / 4 (we mostly install 4M page size CPLBs
94* approx 12 for smaller 1MB page size CPLBs for allignment purposes
95* 1 for L1 Instruction Memory
96* possibly 1 for L2 Instruction Memory
97* 1 for CONFIG_DEBUG_HUNT_FOR_ZERO
98*/
99
100#define MAX_SWITCH_I_CPLBS (((CONFIG_MEM_SIZE / 4) + 12 + 1 + 1 + 1) * 2)
101
102
103#define CPLB_ENABLE_ICACHE_P 0 77#define CPLB_ENABLE_ICACHE_P 0
104#define CPLB_ENABLE_DCACHE_P 1 78#define CPLB_ENABLE_DCACHE_P 1
105#define CPLB_ENABLE_DCACHE2_P 2 79#define CPLB_ENABLE_DCACHE2_P 2
diff --git a/include/asm-blackfin/dma-mapping.h b/include/asm-blackfin/dma-mapping.h
index 282fabccf6a6..1a13c2fc3667 100644
--- a/include/asm-blackfin/dma-mapping.h
+++ b/include/asm-blackfin/dma-mapping.h
@@ -27,6 +27,14 @@ void dma_free_coherent(struct device *dev, size_t size, void *vaddr,
27extern dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size, 27extern dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
28 enum dma_data_direction direction); 28 enum dma_data_direction direction);
29 29
30static inline dma_addr_t
31dma_map_page(struct device *dev, struct page *page,
32 unsigned long offset, size_t size,
33 enum dma_data_direction dir)
34{
35 return dma_map_single(dev, page_address(page) + offset, size, dir);
36}
37
30/* 38/*
31 * Unmap a single streaming mode DMA translation. The dma_addr and size 39 * Unmap a single streaming mode DMA translation. The dma_addr and size
32 * must match what was provided for in a previous pci_map_single call. All 40 * must match what was provided for in a previous pci_map_single call. All
@@ -38,6 +46,13 @@ extern dma_addr_t dma_map_single(struct device *dev, void *ptr, size_t size,
38extern void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size, 46extern void dma_unmap_single(struct device *dev, dma_addr_t dma_addr, size_t size,
39 enum dma_data_direction direction); 47 enum dma_data_direction direction);
40 48
49static inline void
50dma_unmap_page(struct device *dev, dma_addr_t dma_addr, size_t size,
51 enum dma_data_direction dir)
52{
53 dma_unmap_single(dev, dma_addr, size, dir);
54}
55
41/* 56/*
42 * Map a set of buffers described by scatterlist in streaming 57 * Map a set of buffers described by scatterlist in streaming
43 * mode for DMA. This is the scather-gather version of the 58 * mode for DMA. This is the scather-gather version of the
diff --git a/include/asm-blackfin/dma.h b/include/asm-blackfin/dma.h
index 16d493574ba8..c0d5259e315b 100644
--- a/include/asm-blackfin/dma.h
+++ b/include/asm-blackfin/dma.h
@@ -191,4 +191,7 @@ void clear_dma_irqstat(unsigned int channel);
191void *dma_memcpy(void *dest, const void *src, size_t count); 191void *dma_memcpy(void *dest, const void *src, size_t count);
192void *safe_dma_memcpy(void *dest, const void *src, size_t count); 192void *safe_dma_memcpy(void *dest, const void *src, size_t count);
193 193
194extern int channel2irq(unsigned int channel);
195extern struct dma_register *dma_io_base_addr[MAX_BLACKFIN_DMA_CHANNEL];
196
194#endif 197#endif
diff --git a/include/asm-blackfin/gptimers.h b/include/asm-blackfin/gptimers.h
index 4f318f1fd2d9..0520d2aac8f3 100644
--- a/include/asm-blackfin/gptimers.h
+++ b/include/asm-blackfin/gptimers.h
@@ -22,6 +22,18 @@
22# define TIMER0_GROUP_REG TIMER_ENABLE 22# define TIMER0_GROUP_REG TIMER_ENABLE
23#endif 23#endif
24/* 24/*
25 * BF54x: 11 timers (BF542: 8 timers):
26 */
27#if defined(BF548_FAMILY)
28# ifdef CONFIG_BF542
29# define MAX_BLACKFIN_GPTIMERS 8
30# else
31# define MAX_BLACKFIN_GPTIMERS 11
32# define TIMER8_GROUP_REG TIMER_ENABLE1
33# endif
34# define TIMER0_GROUP_REG TIMER_ENABLE0
35#endif
36/*
25 * BF561: 12 timers: 37 * BF561: 12 timers:
26 */ 38 */
27#if defined(CONFIG_BF561) 39#if defined(CONFIG_BF561)
@@ -44,40 +56,28 @@
44#define TIMER0bit 0x0001 /* 0001b */ 56#define TIMER0bit 0x0001 /* 0001b */
45#define TIMER1bit 0x0002 /* 0010b */ 57#define TIMER1bit 0x0002 /* 0010b */
46#define TIMER2bit 0x0004 /* 0100b */ 58#define TIMER2bit 0x0004 /* 0100b */
47 59#define TIMER3bit 0x0008
48#if (MAX_BLACKFIN_GPTIMERS > 3) 60#define TIMER4bit 0x0010
49# define TIMER3bit 0x0008 61#define TIMER5bit 0x0020
50# define TIMER4bit 0x0010 62#define TIMER6bit 0x0040
51# define TIMER5bit 0x0020 63#define TIMER7bit 0x0080
52# define TIMER6bit 0x0040 64#define TIMER8bit 0x0100
53# define TIMER7bit 0x0080 65#define TIMER9bit 0x0200
54#endif 66#define TIMER10bit 0x0400
55 67#define TIMER11bit 0x0800
56#if (MAX_BLACKFIN_GPTIMERS > 8)
57# define TIMER8bit 0x0100
58# define TIMER9bit 0x0200
59# define TIMER10bit 0x0400
60# define TIMER11bit 0x0800
61#endif
62 68
63#define TIMER0_id 0 69#define TIMER0_id 0
64#define TIMER1_id 1 70#define TIMER1_id 1
65#define TIMER2_id 2 71#define TIMER2_id 2
66 72#define TIMER3_id 3
67#if (MAX_BLACKFIN_GPTIMERS > 3) 73#define TIMER4_id 4
68# define TIMER3_id 3 74#define TIMER5_id 5
69# define TIMER4_id 4 75#define TIMER6_id 6
70# define TIMER5_id 5 76#define TIMER7_id 7
71# define TIMER6_id 6 77#define TIMER8_id 8
72# define TIMER7_id 7 78#define TIMER9_id 9
73#endif 79#define TIMER10_id 10
74 80#define TIMER11_id 11
75#if (MAX_BLACKFIN_GPTIMERS > 8)
76# define TIMER8_id 8
77# define TIMER9_id 9
78# define TIMER10_id 10
79# define TIMER11_id 11
80#endif
81 81
82/* associated timers for ppi framesync: */ 82/* associated timers for ppi framesync: */
83 83
@@ -124,45 +124,31 @@
124/* 124/*
125 * Timer Status Register Bits 125 * Timer Status Register Bits
126 */ 126 */
127#define TIMER_STATUS_TIMIL0 0x0001 127#define TIMER_STATUS_TIMIL0 0x0001
128#define TIMER_STATUS_TIMIL1 0x0002 128#define TIMER_STATUS_TIMIL1 0x0002
129#define TIMER_STATUS_TIMIL2 0x0004 129#define TIMER_STATUS_TIMIL2 0x0004
130#if (MAX_BLACKFIN_GPTIMERS > 3) 130#define TIMER_STATUS_TIMIL3 0x00000008
131# define TIMER_STATUS_TIMIL3 0x00000008 131#define TIMER_STATUS_TIMIL4 0x00010000
132# define TIMER_STATUS_TIMIL4 0x00010000 132#define TIMER_STATUS_TIMIL5 0x00020000
133# define TIMER_STATUS_TIMIL5 0x00020000 133#define TIMER_STATUS_TIMIL6 0x00040000
134# define TIMER_STATUS_TIMIL6 0x00040000 134#define TIMER_STATUS_TIMIL7 0x00080000
135# define TIMER_STATUS_TIMIL7 0x00080000 135#define TIMER_STATUS_TIMIL8 0x0001
136# if (MAX_BLACKFIN_GPTIMERS > 8) 136#define TIMER_STATUS_TIMIL9 0x0002
137# define TIMER_STATUS_TIMIL8 0x0001 137#define TIMER_STATUS_TIMIL10 0x0004
138# define TIMER_STATUS_TIMIL9 0x0002 138#define TIMER_STATUS_TIMIL11 0x0008
139# define TIMER_STATUS_TIMIL10 0x0004 139
140# define TIMER_STATUS_TIMIL11 0x0008 140#define TIMER_STATUS_TOVF0 0x0010 /* timer 0 overflow error */
141# endif 141#define TIMER_STATUS_TOVF1 0x0020
142# define TIMER_STATUS_INTR 0x000F000F 142#define TIMER_STATUS_TOVF2 0x0040
143#else 143#define TIMER_STATUS_TOVF3 0x00000080
144# define TIMER_STATUS_INTR 0x0007 /* any timer interrupt */ 144#define TIMER_STATUS_TOVF4 0x00100000
145#endif 145#define TIMER_STATUS_TOVF5 0x00200000
146 146#define TIMER_STATUS_TOVF6 0x00400000
147#define TIMER_STATUS_TOVF0 0x0010 /* timer 0 overflow error */ 147#define TIMER_STATUS_TOVF7 0x00800000
148#define TIMER_STATUS_TOVF1 0x0020 148#define TIMER_STATUS_TOVF8 0x0010
149#define TIMER_STATUS_TOVF2 0x0040 149#define TIMER_STATUS_TOVF9 0x0020
150#if (MAX_BLACKFIN_GPTIMERS > 3) 150#define TIMER_STATUS_TOVF10 0x0040
151# define TIMER_STATUS_TOVF3 0x00000080 151#define TIMER_STATUS_TOVF11 0x0080
152# define TIMER_STATUS_TOVF4 0x00100000
153# define TIMER_STATUS_TOVF5 0x00200000
154# define TIMER_STATUS_TOVF6 0x00400000
155# define TIMER_STATUS_TOVF7 0x00800000
156# if (MAX_BLACKFIN_GPTIMERS > 8)
157# define TIMER_STATUS_TOVF8 0x0010
158# define TIMER_STATUS_TOVF9 0x0020
159# define TIMER_STATUS_TOVF10 0x0040
160# define TIMER_STATUS_TOVF11 0x0080
161# endif
162# define TIMER_STATUS_OFLOW 0x00F000F0
163#else
164# define TIMER_STATUS_OFLOW 0x0070 /* any timer overflow */
165#endif
166 152
167/* 153/*
168 * Timer Slave Enable Status : write 1 to clear 154 * Timer Slave Enable Status : write 1 to clear
@@ -170,22 +156,16 @@
170#define TIMER_STATUS_TRUN0 0x1000 156#define TIMER_STATUS_TRUN0 0x1000
171#define TIMER_STATUS_TRUN1 0x2000 157#define TIMER_STATUS_TRUN1 0x2000
172#define TIMER_STATUS_TRUN2 0x4000 158#define TIMER_STATUS_TRUN2 0x4000
173#if (MAX_BLACKFIN_GPTIMERS > 3) 159#define TIMER_STATUS_TRUN3 0x00008000
174# define TIMER_STATUS_TRUN3 0x00008000 160#define TIMER_STATUS_TRUN4 0x10000000
175# define TIMER_STATUS_TRUN4 0x10000000 161#define TIMER_STATUS_TRUN5 0x20000000
176# define TIMER_STATUS_TRUN5 0x20000000 162#define TIMER_STATUS_TRUN6 0x40000000
177# define TIMER_STATUS_TRUN6 0x40000000 163#define TIMER_STATUS_TRUN7 0x80000000
178# define TIMER_STATUS_TRUN7 0x80000000 164#define TIMER_STATUS_TRUN 0xF000F000
179# define TIMER_STATUS_TRUN 0xF000F000 165#define TIMER_STATUS_TRUN8 0x1000
180# if (MAX_BLACKFIN_GPTIMERS > 8) 166#define TIMER_STATUS_TRUN9 0x2000
181# define TIMER_STATUS_TRUN8 0x1000 167#define TIMER_STATUS_TRUN10 0x4000
182# define TIMER_STATUS_TRUN9 0x2000 168#define TIMER_STATUS_TRUN11 0x8000
183# define TIMER_STATUS_TRUN10 0x4000
184# define TIMER_STATUS_TRUN11 0x8000
185# endif
186#else
187# define TIMER_STATUS_TRUN 0x7000
188#endif
189 169
190/* The actual gptimer API */ 170/* The actual gptimer API */
191 171
diff --git a/include/asm-blackfin/mach-bf527/anomaly.h b/include/asm-blackfin/mach-bf527/anomaly.h
index a89120445be6..735fa02fafb2 100644
--- a/include/asm-blackfin/mach-bf527/anomaly.h
+++ b/include/asm-blackfin/mach-bf527/anomaly.h
@@ -2,12 +2,12 @@
2 * File: include/asm-blackfin/mach-bf527/anomaly.h 2 * File: include/asm-blackfin/mach-bf527/anomaly.h
3 * Bugs: Enter bugs at http://blackfin.uclinux.org/ 3 * Bugs: Enter bugs at http://blackfin.uclinux.org/
4 * 4 *
5 * Copyright (C) 2004-2007 Analog Devices Inc. 5 * Copyright (C) 2004-2008 Analog Devices Inc.
6 * Licensed under the GPL-2 or later. 6 * Licensed under the GPL-2 or later.
7 */ 7 */
8 8
9/* This file shoule be up to date with: 9/* This file shoule be up to date with:
10 * - Revision A, May 30, 2007; ADSP-BF527 Blackfin Processor Anomaly List 10 * - Revision C, 01/25/2008; ADSP-BF527 Blackfin Processor Anomaly List
11 */ 11 */
12 12
13#ifndef _MACH_ANOMALY_H_ 13#ifndef _MACH_ANOMALY_H_
@@ -15,35 +15,85 @@
15 15
16/* Multi-Issue Instruction with dsp32shiftimm in slot1 and P-reg Store in slot2 Not Supported */ 16/* Multi-Issue Instruction with dsp32shiftimm in slot1 and P-reg Store in slot2 Not Supported */
17#define ANOMALY_05000074 (1) 17#define ANOMALY_05000074 (1)
18/* DMA_RUN Bit Is Not Valid after a Peripheral Receive Channel DMA Stops */
19#define ANOMALY_05000119 (1)
20/* Rx.H Cannot Be Used to Access 16-bit System MMR Registers */ 18/* Rx.H Cannot Be Used to Access 16-bit System MMR Registers */
21#define ANOMALY_05000122 (1) 19#define ANOMALY_05000122 (1)
22/* Spurious Hardware Error from an Access in the Shadow of a Conditional Branch */ 20/* Spurious Hardware Error from an Access in the Shadow of a Conditional Branch */
23#define ANOMALY_05000245 (1) 21#define ANOMALY_05000245 (1)
24/* Sensitivity To Noise with Slow Input Edge Rates on External SPORT TX and RX Clocks */ 22/* Sensitivity To Noise with Slow Input Edge Rates on External SPORT TX and RX Clocks */
25#define ANOMALY_05000265 (1) 23#define ANOMALY_05000265 (1)
26/* Memory-To-Memory DMA Source/Destination Descriptors Must Be in Same Memory Space */
27#define ANOMALY_05000301 (1)
28/* Errors When SSYNC, CSYNC, or Loads to LT, LB and LC Registers Are Interrupted */
29#define ANOMALY_05000312 (1)
30/* Incorrect Access of OTP_STATUS During otp_write() Function */ 24/* Incorrect Access of OTP_STATUS During otp_write() Function */
31#define ANOMALY_05000328 (1) 25#define ANOMALY_05000328 (1)
32/* Disallowed Configuration Prevents Subsequent Allowed Configuration on Host DMA Port */ 26/* Disallowed Configuration Prevents Subsequent Allowed Configuration on Host DMA Port */
33#define ANOMALY_05000337 (1) 27#define ANOMALY_05000337 (1)
34/* TWI Does Not Operate Correctly Under Certain Signal Termination Conditions */ 28/* Ethernet MAC MDIO Reads Do Not Meet IEEE Specification */
29#define ANOMALY_05000341 (1)
30/* TWI May Not Operate Correctly Under Certain Signal Termination Conditions */
35#define ANOMALY_05000342 (1) 31#define ANOMALY_05000342 (1)
36/* Boot ROM Kernel Incorrectly Alters Reset Value of USB Register */ 32/* USB Calibration Value Is Not Initialized */
33#define ANOMALY_05000346 (1)
34/* Preboot Routine Incorrectly Alters Reset Value of USB Register */
37#define ANOMALY_05000347 (1) 35#define ANOMALY_05000347 (1)
36/* Security Features Are Not Functional */
37#define ANOMALY_05000348 (__SILICON_REVISION__ < 1)
38/* Regulator Programming Blocked when Hibernate Wakeup Source Remains Active */
39#define ANOMALY_05000355 (1)
40/* Serial Port (SPORT) Multichannel Transmit Failure when Channel 0 Is Disabled */
41#define ANOMALY_05000357 (1)
42/* Incorrect Revision Number in DSPID Register */
43#define ANOMALY_05000364 (__SILICON_REVISION__ > 0)
44/* PPI Underflow Error Goes Undetected in ITU-R 656 Mode */
45#define ANOMALY_05000366 (1)
46/* New Feature: Higher Default CCLK Rate */
47#define ANOMALY_05000368 (1)
48/* Possible RETS Register Corruption when Subroutine Is under 5 Cycles in Duration */
49#define ANOMALY_05000371 (1)
50/* Authentication Fails To Initiate */
51#define ANOMALY_05000376 (__SILICON_REVISION__ > 0)
52/* Data Read From L3 Memory by USB DMA May be Corrupted */
53#define ANOMALY_05000380 (1)
54/* USB Full-speed Mode not Fully Tested */
55#define ANOMALY_05000381 (1)
56/* New Feature: Boot from OTP Memory */
57#define ANOMALY_05000385 (1)
58/* New Feature: bfrom_SysControl() Routine */
59#define ANOMALY_05000386 (1)
60/* New Feature: Programmable Preboot Settings */
61#define ANOMALY_05000387 (1)
62/* Reset Vector Must Not Be in SDRAM Memory Space */
63#define ANOMALY_05000389 (1)
64/* New Feature: pTempCurrent Added to ADI_BOOT_DATA Structure */
65#define ANOMALY_05000392 (1)
66/* New Feature: dTempByteCount Value Increased in ADI_BOOT_DATA Structure */
67#define ANOMALY_05000393 (1)
68/* New Feature: Log Buffer Functionality */
69#define ANOMALY_05000394 (1)
70/* New Feature: Hook Routine Functionality */
71#define ANOMALY_05000395 (1)
72/* New Feature: Header Indirect Bit */
73#define ANOMALY_05000396 (1)
74/* New Feature: BK_ONES, BK_ZEROS, and BK_DATECODE Constants */
75#define ANOMALY_05000397 (1)
76/* New Feature: SWRESET, DFRESET and WDRESET Bits Added to SYSCR Register */
77#define ANOMALY_05000398 (1)
78/* New Feature: BCODE_NOBOOT Added to BCODE Field of SYSCR Register */
79#define ANOMALY_05000399 (1)
80/* PPI Data Signals D0 and D8 do not Tristate After Disabling PPI */
81#define ANOMALY_05000401 (1)
38 82
39/* Anomalies that don't exist on this proc */ 83/* Anomalies that don't exist on this proc */
40#define ANOMALY_05000323 (0)
41#define ANOMALY_05000244 (0)
42#define ANOMALY_05000198 (0)
43#define ANOMALY_05000125 (0) 84#define ANOMALY_05000125 (0)
44#define ANOMALY_05000158 (0) 85#define ANOMALY_05000158 (0)
45#define ANOMALY_05000273 (0) 86#define ANOMALY_05000183 (0)
87#define ANOMALY_05000198 (0)
88#define ANOMALY_05000230 (0)
89#define ANOMALY_05000244 (0)
90#define ANOMALY_05000261 (0)
46#define ANOMALY_05000263 (0) 91#define ANOMALY_05000263 (0)
92#define ANOMALY_05000266 (0)
93#define ANOMALY_05000273 (0)
47#define ANOMALY_05000311 (0) 94#define ANOMALY_05000311 (0)
48#define ANOMALY_05000230 (0) 95#define ANOMALY_05000312 (0)
96#define ANOMALY_05000323 (0)
97#define ANOMALY_05000363 (0)
98
49#endif 99#endif
diff --git a/include/asm-blackfin/mach-bf527/bfin_serial_5xx.h b/include/asm-blackfin/mach-bf527/bfin_serial_5xx.h
index c0694ecd2ecd..f0ab2736a680 100644
--- a/include/asm-blackfin/mach-bf527/bfin_serial_5xx.h
+++ b/include/asm-blackfin/mach-bf527/bfin_serial_5xx.h
@@ -1,22 +1,38 @@
1/*
2 * file: include/asm-blackfin/mach-bf527/bfin_serial_5xx.h
3 * based on:
4 * author:
5 *
6 * created:
7 * description:
8 * blackfin serial driver head file
9 * rev:
10 *
11 * modified:
12 *
13 *
14 * bugs: enter bugs at http://blackfin.uclinux.org/
15 *
16 * this program is free software; you can redistribute it and/or modify
17 * it under the terms of the gnu general public license as published by
18 * the free software foundation; either version 2, or (at your option)
19 * any later version.
20 *
21 * this program is distributed in the hope that it will be useful,
22 * but without any warranty; without even the implied warranty of
23 * merchantability or fitness for a particular purpose. see the
24 * gnu general public license for more details.
25 *
26 * you should have received a copy of the gnu general public license
27 * along with this program; see the file copying.
28 * if not, write to the free software foundation,
29 * 59 temple place - suite 330, boston, ma 02111-1307, usa.
30 */
31
1#include <linux/serial.h> 32#include <linux/serial.h>
2#include <asm/dma.h> 33#include <asm/dma.h>
3#include <asm/portmux.h> 34#include <asm/portmux.h>
4 35
5#define NR_PORTS 2
6
7#define OFFSET_THR 0x00 /* Transmit Holding register */
8#define OFFSET_RBR 0x00 /* Receive Buffer register */
9#define OFFSET_DLL 0x00 /* Divisor Latch (Low-Byte) */
10#define OFFSET_IER 0x04 /* Interrupt Enable Register */
11#define OFFSET_DLH 0x04 /* Divisor Latch (High-Byte) */
12#define OFFSET_IIR 0x08 /* Interrupt Identification Register */
13#define OFFSET_LCR 0x0C /* Line Control Register */
14#define OFFSET_MCR 0x10 /* Modem Control Register */
15#define OFFSET_LSR 0x14 /* Line Status Register */
16#define OFFSET_MSR 0x18 /* Modem Status Register */
17#define OFFSET_SCR 0x1C /* SCR Scratch Register */
18#define OFFSET_GCTL 0x24 /* Global Control Register */
19
20#define UART_GET_CHAR(uart) bfin_read16(((uart)->port.membase + OFFSET_RBR)) 36#define UART_GET_CHAR(uart) bfin_read16(((uart)->port.membase + OFFSET_RBR))
21#define UART_GET_DLL(uart) bfin_read16(((uart)->port.membase + OFFSET_DLL)) 37#define UART_GET_DLL(uart) bfin_read16(((uart)->port.membase + OFFSET_DLL))
22#define UART_GET_IER(uart) bfin_read16(((uart)->port.membase + OFFSET_IER)) 38#define UART_GET_IER(uart) bfin_read16(((uart)->port.membase + OFFSET_IER))
@@ -92,7 +108,7 @@ static inline void UART_CLEAR_LSR(struct bfin_serial_port *uart)
92 bfin_write16(uart->port.membase + OFFSET_LSR, -1); 108 bfin_write16(uart->port.membase + OFFSET_LSR, -1);
93} 109}
94 110
95struct bfin_serial_port bfin_serial_ports[NR_PORTS]; 111struct bfin_serial_port bfin_serial_ports[BFIN_UART_NR_PORTS];
96struct bfin_serial_res { 112struct bfin_serial_res {
97 unsigned long uart_base_addr; 113 unsigned long uart_base_addr;
98 int uart_irq; 114 int uart_irq;
diff --git a/include/asm-blackfin/mach-bf527/bfin_sir.h b/include/asm-blackfin/mach-bf527/bfin_sir.h
new file mode 100644
index 000000000000..0612d0c9501c
--- /dev/null
+++ b/include/asm-blackfin/mach-bf527/bfin_sir.h
@@ -0,0 +1,133 @@
1/*
2 * Blackfin Infra-red Driver
3 *
4 * Copyright 2006-2008 Analog Devices Inc.
5 *
6 * Enter bugs at http://blackfin.uclinux.org/
7 *
8 * Licensed under the GPL-2 or later.
9 *
10 */
11
12#include <linux/serial.h>
13#include <asm/dma.h>
14#include <asm/portmux.h>
15
16#define SIR_UART_GET_CHAR(port) bfin_read16((port)->membase + OFFSET_RBR)
17#define SIR_UART_GET_DLL(port) bfin_read16((port)->membase + OFFSET_DLL)
18#define SIR_UART_GET_IER(port) bfin_read16((port)->membase + OFFSET_IER)
19#define SIR_UART_GET_DLH(port) bfin_read16((port)->membase + OFFSET_DLH)
20#define SIR_UART_GET_IIR(port) bfin_read16((port)->membase + OFFSET_IIR)
21#define SIR_UART_GET_LCR(port) bfin_read16((port)->membase + OFFSET_LCR)
22#define SIR_UART_GET_GCTL(port) bfin_read16((port)->membase + OFFSET_GCTL)
23
24#define SIR_UART_PUT_CHAR(port, v) bfin_write16(((port)->membase + OFFSET_THR), v)
25#define SIR_UART_PUT_DLL(port, v) bfin_write16(((port)->membase + OFFSET_DLL), v)
26#define SIR_UART_PUT_IER(port, v) bfin_write16(((port)->membase + OFFSET_IER), v)
27#define SIR_UART_PUT_DLH(port, v) bfin_write16(((port)->membase + OFFSET_DLH), v)
28#define SIR_UART_PUT_LCR(port, v) bfin_write16(((port)->membase + OFFSET_LCR), v)
29#define SIR_UART_PUT_GCTL(port, v) bfin_write16(((port)->membase + OFFSET_GCTL), v)
30
31#ifdef CONFIG_SIR_BFIN_DMA
32struct dma_rx_buf {
33 char *buf;
34 int head;
35 int tail;
36 };
37#endif /* CONFIG_SIR_BFIN_DMA */
38
39struct bfin_sir_port {
40 unsigned char __iomem *membase;
41 unsigned int irq;
42 unsigned int lsr;
43 unsigned long clk;
44 struct net_device *dev;
45#ifdef CONFIG_SIR_BFIN_DMA
46 int tx_done;
47 struct dma_rx_buf rx_dma_buf;
48 struct timer_list rx_dma_timer;
49 int rx_dma_nrows;
50#endif /* CONFIG_SIR_BFIN_DMA */
51 unsigned int tx_dma_channel;
52 unsigned int rx_dma_channel;
53};
54
55struct bfin_sir_port sir_ports[BFIN_UART_NR_PORTS];
56
57struct bfin_sir_port_res {
58 unsigned long base_addr;
59 int irq;
60 unsigned int rx_dma_channel;
61 unsigned int tx_dma_channel;
62};
63
64struct bfin_sir_port_res bfin_sir_port_resource[] = {
65#ifdef CONFIG_BFIN_SIR0
66 {
67 0xFFC00400,
68 IRQ_UART0_RX,
69 CH_UART0_RX,
70 CH_UART0_TX,
71 },
72#endif
73#ifdef CONFIG_BFIN_SIR1
74 {
75 0xFFC02000,
76 IRQ_UART1_RX,
77 CH_UART1_RX,
78 CH_UART1_TX,
79 },
80#endif
81};
82
83int nr_sirs = ARRAY_SIZE(bfin_sir_port_resource);
84
85struct bfin_sir_self {
86 struct bfin_sir_port *sir_port;
87 spinlock_t lock;
88 unsigned int open;
89 int speed;
90 int newspeed;
91
92 struct sk_buff *txskb;
93 struct sk_buff *rxskb;
94 struct net_device_stats stats;
95 struct device *dev;
96 struct irlap_cb *irlap;
97 struct qos_info qos;
98
99 iobuff_t tx_buff;
100 iobuff_t rx_buff;
101
102 struct work_struct work;
103 int mtt;
104};
105
106static inline unsigned int SIR_UART_GET_LSR(struct bfin_sir_port *port)
107{
108 unsigned int lsr = bfin_read16(port->membase + OFFSET_LSR);
109 port->lsr |= (lsr & (BI|FE|PE|OE));
110 return lsr | port->lsr;
111}
112
113static inline void SIR_UART_CLEAR_LSR(struct bfin_sir_port *port)
114{
115 port->lsr = 0;
116 bfin_read16(port->membase + OFFSET_LSR);
117}
118
119#define DRIVER_NAME "bfin_sir"
120
121static void bfin_sir_hw_init(void)
122{
123#ifdef CONFIG_BFIN_SIR0
124 peripheral_request(P_UART0_TX, DRIVER_NAME);
125 peripheral_request(P_UART0_RX, DRIVER_NAME);
126#endif
127
128#ifdef CONFIG_BFIN_SIR1
129 peripheral_request(P_UART1_TX, DRIVER_NAME);
130 peripheral_request(P_UART1_RX, DRIVER_NAME);
131#endif
132 SSYNC();
133}
diff --git a/include/asm-blackfin/mach-bf527/blackfin.h b/include/asm-blackfin/mach-bf527/blackfin.h
index 1bd07e30781c..2891727b6176 100644
--- a/include/asm-blackfin/mach-bf527/blackfin.h
+++ b/include/asm-blackfin/mach-bf527/blackfin.h
@@ -64,6 +64,21 @@
64#define STATUS_P1 0x02 64#define STATUS_P1 0x02
65#define STATUS_P0 0x01 65#define STATUS_P0 0x01
66 66
67#define BFIN_UART_NR_PORTS 2
68
69#define OFFSET_THR 0x00 /* Transmit Holding register */
70#define OFFSET_RBR 0x00 /* Receive Buffer register */
71#define OFFSET_DLL 0x00 /* Divisor Latch (Low-Byte) */
72#define OFFSET_IER 0x04 /* Interrupt Enable Register */
73#define OFFSET_DLH 0x04 /* Divisor Latch (High-Byte) */
74#define OFFSET_IIR 0x08 /* Interrupt Identification Register */
75#define OFFSET_LCR 0x0C /* Line Control Register */
76#define OFFSET_MCR 0x10 /* Modem Control Register */
77#define OFFSET_LSR 0x14 /* Line Status Register */
78#define OFFSET_MSR 0x18 /* Modem Status Register */
79#define OFFSET_SCR 0x1C /* SCR Scratch Register */
80#define OFFSET_GCTL 0x24 /* Global Control Register */
81
67/* DPMC*/ 82/* DPMC*/
68#define bfin_read_STOPCK_OFF() bfin_read_STOPCK() 83#define bfin_read_STOPCK_OFF() bfin_read_STOPCK()
69#define bfin_write_STOPCK_OFF(val) bfin_write_STOPCK(val) 84#define bfin_write_STOPCK_OFF(val) bfin_write_STOPCK(val)
diff --git a/include/asm-blackfin/mach-bf527/cdefBF52x_base.h b/include/asm-blackfin/mach-bf527/cdefBF52x_base.h
index 3f4de5d9d4cb..9dbdbec8ea1b 100644
--- a/include/asm-blackfin/mach-bf527/cdefBF52x_base.h
+++ b/include/asm-blackfin/mach-bf527/cdefBF52x_base.h
@@ -29,18 +29,71 @@
29 */ 29 */
30 30
31#ifndef _CDEF_BF52X_H 31#ifndef _CDEF_BF52X_H
32#define _CDEF_BF52X_H
33
34#include <asm/system.h>
35#include <asm/blackfin.h>
32 36
33#include "defBF52x_base.h" 37#include "defBF52x_base.h"
34 38
39/* Include core specific register pointer definitions */
40#include <asm/mach-common/cdef_LPBlackfin.h>
41
35/* ==== begin from cdefBF534.h ==== */ 42/* ==== begin from cdefBF534.h ==== */
36 43
37/* Clock and System Control (0xFFC00000 - 0xFFC000FF) */ 44/* Clock and System Control (0xFFC00000 - 0xFFC000FF) */
38#define bfin_read_PLL_CTL() bfin_read16(PLL_CTL) 45#define bfin_read_PLL_CTL() bfin_read16(PLL_CTL)
39#define bfin_write_PLL_CTL(val) bfin_write16(PLL_CTL, val) 46/* Writing to PLL_CTL initiates a PLL relock sequence. */
47static __inline__ void bfin_write_PLL_CTL(unsigned int val)
48{
49 unsigned long flags, iwr0, iwr1;
50
51 if (val == bfin_read_PLL_CTL())
52 return;
53
54 local_irq_save(flags);
55 /* Enable the PLL Wakeup bit in SIC IWR */
56 iwr0 = bfin_read32(SIC_IWR0);
57 iwr1 = bfin_read32(SIC_IWR1);
58 /* Only allow PPL Wakeup) */
59 bfin_write32(SIC_IWR0, IWR_ENABLE(0));
60 bfin_write32(SIC_IWR1, 0);
61
62 bfin_write16(PLL_CTL, val);
63 SSYNC();
64 asm("IDLE;");
65
66 bfin_write32(SIC_IWR0, iwr0);
67 bfin_write32(SIC_IWR1, iwr1);
68 local_irq_restore(flags);
69}
40#define bfin_read_PLL_DIV() bfin_read16(PLL_DIV) 70#define bfin_read_PLL_DIV() bfin_read16(PLL_DIV)
41#define bfin_write_PLL_DIV(val) bfin_write16(PLL_DIV, val) 71#define bfin_write_PLL_DIV(val) bfin_write16(PLL_DIV, val)
42#define bfin_read_VR_CTL() bfin_read16(VR_CTL) 72#define bfin_read_VR_CTL() bfin_read16(VR_CTL)
43#define bfin_write_VR_CTL(val) bfin_write16(VR_CTL, val) 73/* Writing to VR_CTL initiates a PLL relock sequence. */
74static __inline__ void bfin_write_VR_CTL(unsigned int val)
75{
76 unsigned long flags, iwr0, iwr1;
77
78 if (val == bfin_read_VR_CTL())
79 return;
80
81 local_irq_save(flags);
82 /* Enable the PLL Wakeup bit in SIC IWR */
83 iwr0 = bfin_read32(SIC_IWR0);
84 iwr1 = bfin_read32(SIC_IWR1);
85 /* Only allow PPL Wakeup) */
86 bfin_write32(SIC_IWR0, IWR_ENABLE(0));
87 bfin_write32(SIC_IWR1, 0);
88
89 bfin_write16(VR_CTL, val);
90 SSYNC();
91 asm("IDLE;");
92
93 bfin_write32(SIC_IWR0, iwr0);
94 bfin_write32(SIC_IWR1, iwr1);
95 local_irq_restore(flags);
96}
44#define bfin_read_PLL_STAT() bfin_read16(PLL_STAT) 97#define bfin_read_PLL_STAT() bfin_read16(PLL_STAT)
45#define bfin_write_PLL_STAT(val) bfin_write16(PLL_STAT, val) 98#define bfin_write_PLL_STAT(val) bfin_write16(PLL_STAT, val)
46#define bfin_read_PLL_LOCKCNT() bfin_read16(PLL_LOCKCNT) 99#define bfin_read_PLL_LOCKCNT() bfin_read16(PLL_LOCKCNT)
@@ -873,39 +926,6 @@
873 926
874 927
875/* Two-Wire Interface (0xFFC01400 - 0xFFC014FF) */ 928/* Two-Wire Interface (0xFFC01400 - 0xFFC014FF) */
876#define bfin_read_TWI_CLKDIV() bfin_read16(TWI_CLKDIV)
877#define bfin_write_TWI_CLKDIV(val) bfin_write16(TWI_CLKDIV, val)
878#define bfin_read_TWI_CONTROL() bfin_read16(TWI_CONTROL)
879#define bfin_write_TWI_CONTROL(val) bfin_write16(TWI_CONTROL, val)
880#define bfin_read_TWI_SLAVE_CTL() bfin_read16(TWI_SLAVE_CTL)
881#define bfin_write_TWI_SLAVE_CTL(val) bfin_write16(TWI_SLAVE_CTL, val)
882#define bfin_read_TWI_SLAVE_STAT() bfin_read16(TWI_SLAVE_STAT)
883#define bfin_write_TWI_SLAVE_STAT(val) bfin_write16(TWI_SLAVE_STAT, val)
884#define bfin_read_TWI_SLAVE_ADDR() bfin_read16(TWI_SLAVE_ADDR)
885#define bfin_write_TWI_SLAVE_ADDR(val) bfin_write16(TWI_SLAVE_ADDR, val)
886#define bfin_read_TWI_MASTER_CTL() bfin_read16(TWI_MASTER_CTL)
887#define bfin_write_TWI_MASTER_CTL(val) bfin_write16(TWI_MASTER_CTL, val)
888#define bfin_read_TWI_MASTER_STAT() bfin_read16(TWI_MASTER_STAT)
889#define bfin_write_TWI_MASTER_STAT(val) bfin_write16(TWI_MASTER_STAT, val)
890#define bfin_read_TWI_MASTER_ADDR() bfin_read16(TWI_MASTER_ADDR)
891#define bfin_write_TWI_MASTER_ADDR(val) bfin_write16(TWI_MASTER_ADDR, val)
892#define bfin_read_TWI_INT_STAT() bfin_read16(TWI_INT_STAT)
893#define bfin_write_TWI_INT_STAT(val) bfin_write16(TWI_INT_STAT, val)
894#define bfin_read_TWI_INT_MASK() bfin_read16(TWI_INT_MASK)
895#define bfin_write_TWI_INT_MASK(val) bfin_write16(TWI_INT_MASK, val)
896#define bfin_read_TWI_FIFO_CTL() bfin_read16(TWI_FIFO_CTL)
897#define bfin_write_TWI_FIFO_CTL(val) bfin_write16(TWI_FIFO_CTL, val)
898#define bfin_read_TWI_FIFO_STAT() bfin_read16(TWI_FIFO_STAT)
899#define bfin_write_TWI_FIFO_STAT(val) bfin_write16(TWI_FIFO_STAT, val)
900#define bfin_read_TWI_XMT_DATA8() bfin_read16(TWI_XMT_DATA8)
901#define bfin_write_TWI_XMT_DATA8(val) bfin_write16(TWI_XMT_DATA8, val)
902#define bfin_read_TWI_XMT_DATA16() bfin_read16(TWI_XMT_DATA16)
903#define bfin_write_TWI_XMT_DATA16(val) bfin_write16(TWI_XMT_DATA16, val)
904#define bfin_read_TWI_RCV_DATA8() bfin_read16(TWI_RCV_DATA8)
905#define bfin_write_TWI_RCV_DATA8(val) bfin_write16(TWI_RCV_DATA8, val)
906#define bfin_read_TWI_RCV_DATA16() bfin_read16(TWI_RCV_DATA16)
907#define bfin_write_TWI_RCV_DATA16(val) bfin_write16(TWI_RCV_DATA16, val)
908
909 929
910/* General Purpose I/O Port G (0xFFC01500 - 0xFFC015FF) */ 930/* General Purpose I/O Port G (0xFFC01500 - 0xFFC015FF) */
911#define bfin_read_PORTGIO() bfin_read16(PORTGIO) 931#define bfin_read_PORTGIO() bfin_read16(PORTGIO)
diff --git a/include/asm-blackfin/mach-bf527/dma.h b/include/asm-blackfin/mach-bf527/dma.h
index 2dfee12864f6..49dd693223e8 100644
--- a/include/asm-blackfin/mach-bf527/dma.h
+++ b/include/asm-blackfin/mach-bf527/dma.h
@@ -59,7 +59,4 @@
59#define CH_NFC CH_EMAC_TX /* PPI receive/transmit or NFC */ 59#define CH_NFC CH_EMAC_TX /* PPI receive/transmit or NFC */
60#endif 60#endif
61 61
62extern int channel2irq(unsigned int channel);
63extern struct dma_register *base_addr[];
64
65#endif 62#endif
diff --git a/include/asm-blackfin/mach-bf533/anomaly.h b/include/asm-blackfin/mach-bf533/anomaly.h
index 98209d40abba..5a6dcc5fa36c 100644
--- a/include/asm-blackfin/mach-bf533/anomaly.h
+++ b/include/asm-blackfin/mach-bf533/anomaly.h
@@ -7,7 +7,7 @@
7 */ 7 */
8 8
9/* This file shoule be up to date with: 9/* This file shoule be up to date with:
10 * - Revision B, 12/10/2007; ADSP-BF531/BF532/BF533 Blackfin Processor Anomaly List 10 * - Revision C, 02/08/2008; ADSP-BF531/BF532/BF533 Blackfin Processor Anomaly List
11 */ 11 */
12 12
13#ifndef _MACH_ANOMALY_H_ 13#ifndef _MACH_ANOMALY_H_
@@ -251,10 +251,18 @@
251#define ANOMALY_05000206 (__SILICON_REVISION__ < 3) 251#define ANOMALY_05000206 (__SILICON_REVISION__ < 3)
252/* Serial Port (SPORT) Multichannel Transmit Failure when Channel 0 Is Disabled */ 252/* Serial Port (SPORT) Multichannel Transmit Failure when Channel 0 Is Disabled */
253#define ANOMALY_05000357 (1) 253#define ANOMALY_05000357 (1)
254/* UART Break Signal Issues */
255#define ANOMALY_05000363 (__SILICON_REVISION__ < 5)
254/* PPI Underflow Error Goes Undetected in ITU-R 656 Mode */ 256/* PPI Underflow Error Goes Undetected in ITU-R 656 Mode */
255#define ANOMALY_05000366 (1) 257#define ANOMALY_05000366 (1)
256/* Possible RETS Register Corruption when Subroutine Is under 5 Cycles in Duration */ 258/* Possible RETS Register Corruption when Subroutine Is under 5 Cycles in Duration */
257#define ANOMALY_05000371 (1) 259#define ANOMALY_05000371 (1)
260/* PPI Does Not Start Properly In Specific Mode */
261#define ANOMALY_05000400 (__SILICON_REVISION__ == 5)
262/* SSYNC Stalls Processor when Executed from Non-Cacheable Memory */
263#define ANOMALY_05000402 (__SILICON_REVISION__ == 5)
264/* Level-Sensitive External GPIO Wakeups May Cause Indefinite Stall */
265#define ANOMALY_05000403 (1)
258 266
259/* Anomalies that don't exist on this proc */ 267/* Anomalies that don't exist on this proc */
260#define ANOMALY_05000266 (0) 268#define ANOMALY_05000266 (0)
diff --git a/include/asm-blackfin/mach-bf533/bfin_serial_5xx.h b/include/asm-blackfin/mach-bf533/bfin_serial_5xx.h
index b6f513bee56e..fbe88dee3e2d 100644
--- a/include/asm-blackfin/mach-bf533/bfin_serial_5xx.h
+++ b/include/asm-blackfin/mach-bf533/bfin_serial_5xx.h
@@ -1,22 +1,38 @@
1/*
2 * file: include/asm-blackfin/mach-bf533/bfin_serial_5xx.h
3 * based on:
4 * author:
5 *
6 * created:
7 * description:
8 * blackfin serial driver head file
9 * rev:
10 *
11 * modified:
12 *
13 *
14 * bugs: enter bugs at http://blackfin.uclinux.org/
15 *
16 * this program is free software; you can redistribute it and/or modify
17 * it under the terms of the gnu general public license as published by
18 * the free software foundation; either version 2, or (at your option)
19 * any later version.
20 *
21 * this program is distributed in the hope that it will be useful,
22 * but without any warranty; without even the implied warranty of
23 * merchantability or fitness for a particular purpose. see the
24 * gnu general public license for more details.
25 *
26 * you should have received a copy of the gnu general public license
27 * along with this program; see the file copying.
28 * if not, write to the free software foundation,
29 * 59 temple place - suite 330, boston, ma 02111-1307, usa.
30 */
31
1#include <linux/serial.h> 32#include <linux/serial.h>
2#include <asm/dma.h> 33#include <asm/dma.h>
3#include <asm/portmux.h> 34#include <asm/portmux.h>
4 35
5#define NR_PORTS 1
6
7#define OFFSET_THR 0x00 /* Transmit Holding register */
8#define OFFSET_RBR 0x00 /* Receive Buffer register */
9#define OFFSET_DLL 0x00 /* Divisor Latch (Low-Byte) */
10#define OFFSET_IER 0x04 /* Interrupt Enable Register */
11#define OFFSET_DLH 0x04 /* Divisor Latch (High-Byte) */
12#define OFFSET_IIR 0x08 /* Interrupt Identification Register */
13#define OFFSET_LCR 0x0C /* Line Control Register */
14#define OFFSET_MCR 0x10 /* Modem Control Register */
15#define OFFSET_LSR 0x14 /* Line Status Register */
16#define OFFSET_MSR 0x18 /* Modem Status Register */
17#define OFFSET_SCR 0x1C /* SCR Scratch Register */
18#define OFFSET_GCTL 0x24 /* Global Control Register */
19
20#define UART_GET_CHAR(uart) bfin_read16(((uart)->port.membase + OFFSET_RBR)) 36#define UART_GET_CHAR(uart) bfin_read16(((uart)->port.membase + OFFSET_RBR))
21#define UART_GET_DLL(uart) bfin_read16(((uart)->port.membase + OFFSET_DLL)) 37#define UART_GET_DLL(uart) bfin_read16(((uart)->port.membase + OFFSET_DLL))
22#define UART_GET_IER(uart) bfin_read16(((uart)->port.membase + OFFSET_IER)) 38#define UART_GET_IER(uart) bfin_read16(((uart)->port.membase + OFFSET_IER))
@@ -84,7 +100,7 @@ static inline void UART_CLEAR_LSR(struct bfin_serial_port *uart)
84 bfin_write16(uart->port.membase + OFFSET_LSR, -1); 100 bfin_write16(uart->port.membase + OFFSET_LSR, -1);
85} 101}
86 102
87struct bfin_serial_port bfin_serial_ports[NR_PORTS]; 103struct bfin_serial_port bfin_serial_ports[BFIN_UART_NR_PORTS];
88struct bfin_serial_res { 104struct bfin_serial_res {
89 unsigned long uart_base_addr; 105 unsigned long uart_base_addr;
90 int uart_irq; 106 int uart_irq;
@@ -115,7 +131,7 @@ struct bfin_serial_res bfin_serial_resource[] = {
115 131
116#define DRIVER_NAME "bfin-uart" 132#define DRIVER_NAME "bfin-uart"
117 133
118int nr_ports = NR_PORTS; 134int nr_ports = BFIN_UART_NR_PORTS;
119static void bfin_serial_hw_init(struct bfin_serial_port *uart) 135static void bfin_serial_hw_init(struct bfin_serial_port *uart)
120{ 136{
121 137
diff --git a/include/asm-blackfin/mach-bf533/bfin_sir.h b/include/asm-blackfin/mach-bf533/bfin_sir.h
new file mode 100644
index 000000000000..cefcf8bb505b
--- /dev/null
+++ b/include/asm-blackfin/mach-bf533/bfin_sir.h
@@ -0,0 +1,120 @@
1/*
2 * Blackfin Infra-red Driver
3 *
4 * Copyright 2006-2008 Analog Devices Inc.
5 *
6 * Enter bugs at http://blackfin.uclinux.org/
7 *
8 * Licensed under the GPL-2 or later.
9 *
10 */
11
12#include <linux/serial.h>
13#include <asm/dma.h>
14#include <asm/portmux.h>
15
16#define SIR_UART_GET_CHAR(port) bfin_read16((port)->membase + OFFSET_RBR)
17#define SIR_UART_GET_DLL(port) bfin_read16((port)->membase + OFFSET_DLL)
18#define SIR_UART_GET_IER(port) bfin_read16((port)->membase + OFFSET_IER)
19#define SIR_UART_GET_DLH(port) bfin_read16((port)->membase + OFFSET_DLH)
20#define SIR_UART_GET_IIR(port) bfin_read16((port)->membase + OFFSET_IIR)
21#define SIR_UART_GET_LCR(port) bfin_read16((port)->membase + OFFSET_LCR)
22#define SIR_UART_GET_GCTL(port) bfin_read16((port)->membase + OFFSET_GCTL)
23
24#define SIR_UART_PUT_CHAR(port, v) bfin_write16(((port)->membase + OFFSET_THR), v)
25#define SIR_UART_PUT_DLL(port, v) bfin_write16(((port)->membase + OFFSET_DLL), v)
26#define SIR_UART_PUT_IER(port, v) bfin_write16(((port)->membase + OFFSET_IER), v)
27#define SIR_UART_PUT_DLH(port, v) bfin_write16(((port)->membase + OFFSET_DLH), v)
28#define SIR_UART_PUT_LCR(port, v) bfin_write16(((port)->membase + OFFSET_LCR), v)
29#define SIR_UART_PUT_GCTL(port, v) bfin_write16(((port)->membase + OFFSET_GCTL), v)
30
31#ifdef CONFIG_SIR_BFIN_DMA
32struct dma_rx_buf {
33 char *buf;
34 int head;
35 int tail;
36 };
37#endif /* CONFIG_SIR_BFIN_DMA */
38
39struct bfin_sir_port {
40 unsigned char __iomem *membase;
41 unsigned int irq;
42 unsigned int lsr;
43 unsigned long clk;
44 struct net_device *dev;
45#ifdef CONFIG_SIR_BFIN_DMA
46 int tx_done;
47 struct dma_rx_buf rx_dma_buf;
48 struct timer_list rx_dma_timer;
49 int rx_dma_nrows;
50#endif /* CONFIG_SIR_BFIN_DMA */
51 unsigned int tx_dma_channel;
52 unsigned int rx_dma_channel;
53};
54
55struct bfin_sir_port sir_ports[BFIN_UART_NR_PORTS];
56
57struct bfin_sir_port_res {
58 unsigned long base_addr;
59 int irq;
60 unsigned int rx_dma_channel;
61 unsigned int tx_dma_channel;
62};
63
64struct bfin_sir_port_res bfin_sir_port_resource[] = {
65#ifdef CONFIG_BFIN_SIR0
66 {
67 0xFFC00400,
68 IRQ_UART_RX,
69 CH_UART_RX,
70 CH_UART_TX,
71 },
72#endif
73};
74
75int nr_sirs = ARRAY_SIZE(bfin_sir_port_resource);
76
77struct bfin_sir_self {
78 struct bfin_sir_port *sir_port;
79 spinlock_t lock;
80 unsigned int open;
81 int speed;
82 int newspeed;
83
84 struct sk_buff *txskb;
85 struct sk_buff *rxskb;
86 struct net_device_stats stats;
87 struct device *dev;
88 struct irlap_cb *irlap;
89 struct qos_info qos;
90
91 iobuff_t tx_buff;
92 iobuff_t rx_buff;
93
94 struct work_struct work;
95 int mtt;
96};
97
98static inline unsigned int SIR_UART_GET_LSR(struct bfin_sir_port *port)
99{
100 unsigned int lsr = bfin_read16(port->membase + OFFSET_LSR);
101 port->lsr |= (lsr & (BI|FE|PE|OE));
102 return lsr | port->lsr;
103}
104
105static inline void SIR_UART_CLEAR_LSR(struct bfin_sir_port *port)
106{
107 port->lsr = 0;
108 bfin_read16(port->membase + OFFSET_LSR);
109}
110
111#define DRIVER_NAME "bfin_sir"
112
113static void bfin_sir_hw_init(void)
114{
115#ifdef CONFIG_BFIN_SIR0
116 peripheral_request(P_UART0_TX, DRIVER_NAME);
117 peripheral_request(P_UART0_RX, DRIVER_NAME);
118#endif
119 SSYNC();
120}
diff --git a/include/asm-blackfin/mach-bf533/blackfin.h b/include/asm-blackfin/mach-bf533/blackfin.h
index f3b240abf170..d80971b4e3aa 100644
--- a/include/asm-blackfin/mach-bf533/blackfin.h
+++ b/include/asm-blackfin/mach-bf533/blackfin.h
@@ -42,4 +42,19 @@
42#include "cdefBF532.h" 42#include "cdefBF532.h"
43#endif 43#endif
44 44
45#define BFIN_UART_NR_PORTS 1
46
47#define OFFSET_THR 0x00 /* Transmit Holding register */
48#define OFFSET_RBR 0x00 /* Receive Buffer register */
49#define OFFSET_DLL 0x00 /* Divisor Latch (Low-Byte) */
50#define OFFSET_IER 0x04 /* Interrupt Enable Register */
51#define OFFSET_DLH 0x04 /* Divisor Latch (High-Byte) */
52#define OFFSET_IIR 0x08 /* Interrupt Identification Register */
53#define OFFSET_LCR 0x0C /* Line Control Register */
54#define OFFSET_MCR 0x10 /* Modem Control Register */
55#define OFFSET_LSR 0x14 /* Line Status Register */
56#define OFFSET_MSR 0x18 /* Modem Status Register */
57#define OFFSET_SCR 0x1C /* SCR Scratch Register */
58#define OFFSET_GCTL 0x24 /* Global Control Register */
59
45#endif /* _MACH_BLACKFIN_H_ */ 60#endif /* _MACH_BLACKFIN_H_ */
diff --git a/include/asm-blackfin/mach-bf533/cdefBF532.h b/include/asm-blackfin/mach-bf533/cdefBF532.h
index c803e14b529c..154655452d4c 100644
--- a/include/asm-blackfin/mach-bf533/cdefBF532.h
+++ b/include/asm-blackfin/mach-bf533/cdefBF532.h
@@ -43,7 +43,27 @@
43 43
44/* Clock and System Control (0xFFC0 0400-0xFFC0 07FF) */ 44/* Clock and System Control (0xFFC0 0400-0xFFC0 07FF) */
45#define bfin_read_PLL_CTL() bfin_read16(PLL_CTL) 45#define bfin_read_PLL_CTL() bfin_read16(PLL_CTL)
46#define bfin_write_PLL_CTL(val) bfin_write16(PLL_CTL,val) 46/* Writing to PLL_CTL initiates a PLL relock sequence. */
47static __inline__ void bfin_write_PLL_CTL(unsigned int val)
48{
49 unsigned long flags, iwr;
50
51 if (val == bfin_read_PLL_CTL())
52 return;
53
54 local_irq_save(flags);
55 /* Enable the PLL Wakeup bit in SIC IWR */
56 iwr = bfin_read32(SIC_IWR);
57 /* Only allow PPL Wakeup) */
58 bfin_write32(SIC_IWR, IWR_ENABLE(0));
59
60 bfin_write16(PLL_CTL, val);
61 SSYNC();
62 asm("IDLE;");
63
64 bfin_write32(SIC_IWR, iwr);
65 local_irq_restore(flags);
66}
47#define bfin_read_PLL_STAT() bfin_read16(PLL_STAT) 67#define bfin_read_PLL_STAT() bfin_read16(PLL_STAT)
48#define bfin_write_PLL_STAT(val) bfin_write16(PLL_STAT,val) 68#define bfin_write_PLL_STAT(val) bfin_write16(PLL_STAT,val)
49#define bfin_read_PLL_LOCKCNT() bfin_read16(PLL_LOCKCNT) 69#define bfin_read_PLL_LOCKCNT() bfin_read16(PLL_LOCKCNT)
@@ -57,6 +77,10 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
57{ 77{
58 unsigned long flags, iwr; 78 unsigned long flags, iwr;
59 79
80 if (val == bfin_read_VR_CTL())
81 return;
82
83 local_irq_save(flags);
60 /* Enable the PLL Wakeup bit in SIC IWR */ 84 /* Enable the PLL Wakeup bit in SIC IWR */
61 iwr = bfin_read32(SIC_IWR); 85 iwr = bfin_read32(SIC_IWR);
62 /* Only allow PPL Wakeup) */ 86 /* Only allow PPL Wakeup) */
@@ -64,11 +88,10 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
64 88
65 bfin_write16(VR_CTL, val); 89 bfin_write16(VR_CTL, val);
66 SSYNC(); 90 SSYNC();
67
68 local_irq_save(flags);
69 asm("IDLE;"); 91 asm("IDLE;");
70 local_irq_restore(flags); 92
71 bfin_write32(SIC_IWR, iwr); 93 bfin_write32(SIC_IWR, iwr);
94 local_irq_restore(flags);
72} 95}
73 96
74/* System Interrupt Controller (0xFFC0 0C00-0xFFC0 0FFF) */ 97/* System Interrupt Controller (0xFFC0 0C00-0xFFC0 0FFF) */
diff --git a/include/asm-blackfin/mach-bf533/defBF532.h b/include/asm-blackfin/mach-bf533/defBF532.h
index 37134aaf9954..17e1548cec08 100644
--- a/include/asm-blackfin/mach-bf533/defBF532.h
+++ b/include/asm-blackfin/mach-bf533/defBF532.h
@@ -88,20 +88,25 @@
88#define RTC_PREN 0xFFC00314 /* RTC Prescaler Enable Register (alternate macro) */ 88#define RTC_PREN 0xFFC00314 /* RTC Prescaler Enable Register (alternate macro) */
89 89
90/* UART Controller (0xFFC00400 - 0xFFC004FF) */ 90/* UART Controller (0xFFC00400 - 0xFFC004FF) */
91#define UART_THR 0xFFC00400 /* Transmit Holding register */ 91
92#define UART_RBR 0xFFC00400 /* Receive Buffer register */ 92/*
93#define UART_DLL 0xFFC00400 /* Divisor Latch (Low-Byte) */ 93 * Because include/linux/serial_reg.h have defined UART_*,
94#define UART_IER 0xFFC00404 /* Interrupt Enable Register */ 94 * So we define blackfin uart regs to BFIN_UART_*.
95#define UART_DLH 0xFFC00404 /* Divisor Latch (High-Byte) */ 95 */
96#define UART_IIR 0xFFC00408 /* Interrupt Identification Register */ 96#define BFIN_UART_THR 0xFFC00400 /* Transmit Holding register */
97#define UART_LCR 0xFFC0040C /* Line Control Register */ 97#define BFIN_UART_RBR 0xFFC00400 /* Receive Buffer register */
98#define UART_MCR 0xFFC00410 /* Modem Control Register */ 98#define BFIN_UART_DLL 0xFFC00400 /* Divisor Latch (Low-Byte) */
99#define UART_LSR 0xFFC00414 /* Line Status Register */ 99#define BFIN_UART_IER 0xFFC00404 /* Interrupt Enable Register */
100#define BFIN_UART_DLH 0xFFC00404 /* Divisor Latch (High-Byte) */
101#define BFIN_UART_IIR 0xFFC00408 /* Interrupt Identification Register */
102#define BFIN_UART_LCR 0xFFC0040C /* Line Control Register */
103#define BFIN_UART_MCR 0xFFC00410 /* Modem Control Register */
104#define BFIN_UART_LSR 0xFFC00414 /* Line Status Register */
100#if 0 105#if 0
101#define UART_MSR 0xFFC00418 /* Modem Status Register (UNUSED in ADSP-BF532) */ 106#define BFIN_UART_MSR 0xFFC00418 /* Modem Status Register (UNUSED in ADSP-BF532) */
102#endif 107#endif
103#define UART_SCR 0xFFC0041C /* SCR Scratch Register */ 108#define BFIN_UART_SCR 0xFFC0041C /* SCR Scratch Register */
104#define UART_GCTL 0xFFC00424 /* Global Control Register */ 109#define BFIN_UART_GCTL 0xFFC00424 /* Global Control Register */
105 110
106/* SPI Controller (0xFFC00500 - 0xFFC005FF) */ 111/* SPI Controller (0xFFC00500 - 0xFFC005FF) */
107#define SPI0_REGBASE 0xFFC00500 112#define SPI0_REGBASE 0xFFC00500
diff --git a/include/asm-blackfin/mach-bf533/dma.h b/include/asm-blackfin/mach-bf533/dma.h
index 16c672c01d80..bd9d5e94307d 100644
--- a/include/asm-blackfin/mach-bf533/dma.h
+++ b/include/asm-blackfin/mach-bf533/dma.h
@@ -51,7 +51,4 @@
51#define CH_MEM_STREAM1_DEST 10 /* TX */ 51#define CH_MEM_STREAM1_DEST 10 /* TX */
52#define CH_MEM_STREAM1_SRC 11 /* RX */ 52#define CH_MEM_STREAM1_SRC 11 /* RX */
53 53
54extern int channel2irq(unsigned int channel);
55extern struct dma_register *base_addr[];
56
57#endif 54#endif
diff --git a/include/asm-blackfin/mach-bf533/mem_init.h b/include/asm-blackfin/mach-bf533/mem_init.h
index 1620dae5254d..f8f31901fca9 100644
--- a/include/asm-blackfin/mach-bf533/mem_init.h
+++ b/include/asm-blackfin/mach-bf533/mem_init.h
@@ -29,7 +29,8 @@
29 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 29 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 */ 30 */
31 31
32#if (CONFIG_MEM_MT48LC16M16A2TG_75 || CONFIG_MEM_MT48LC64M4A2FB_7E || CONFIG_MEM_GENERIC_BOARD) 32#if (CONFIG_MEM_MT48LC16M16A2TG_75 || CONFIG_MEM_MT48LC64M4A2FB_7E || \
33 CONFIG_MEM_MT48LC32M16A2TG_75 || CONFIG_MEM_GENERIC_BOARD)
33#if (CONFIG_SCLK_HZ > 119402985) 34#if (CONFIG_SCLK_HZ > 119402985)
34#define SDRAM_tRP TRP_2 35#define SDRAM_tRP TRP_2
35#define SDRAM_tRP_num 2 36#define SDRAM_tRP_num 2
@@ -118,6 +119,13 @@
118#define SDRAM_CL CL_3 119#define SDRAM_CL CL_3
119#endif 120#endif
120 121
122#if (CONFIG_MEM_MT48LC32M16A2TG_75)
123 /*SDRAM INFORMATION: */
124#define SDRAM_Tref 64 /* Refresh period in milliseconds */
125#define SDRAM_NRA 8192 /* Number of row addresses in SDRAM */
126#define SDRAM_CL CL_3
127#endif
128
121#if (CONFIG_MEM_GENERIC_BOARD) 129#if (CONFIG_MEM_GENERIC_BOARD)
122 /*SDRAM INFORMATION: Modify this for your board */ 130 /*SDRAM INFORMATION: Modify this for your board */
123#define SDRAM_Tref 64 /* Refresh period in milliseconds */ 131#define SDRAM_Tref 64 /* Refresh period in milliseconds */
diff --git a/include/asm-blackfin/mach-bf537/anomaly.h b/include/asm-blackfin/mach-bf537/anomaly.h
index 746a794b3119..a6b08facb242 100644
--- a/include/asm-blackfin/mach-bf537/anomaly.h
+++ b/include/asm-blackfin/mach-bf537/anomaly.h
@@ -7,7 +7,7 @@
7 */ 7 */
8 8
9/* This file shoule be up to date with: 9/* This file shoule be up to date with:
10 * - Revision A, 09/04/2007; ADSP-BF534/ADSP-BF536/ADSP-BF537 Blackfin Processor Anomaly List 10 * - Revision C, 02/08/2008; ADSP-BF534/ADSP-BF536/ADSP-BF537 Blackfin Processor Anomaly List
11 */ 11 */
12 12
13#ifndef _MACH_ANOMALY_H_ 13#ifndef _MACH_ANOMALY_H_
@@ -132,10 +132,24 @@
132#define ANOMALY_05000322 (1) 132#define ANOMALY_05000322 (1)
133/* Ethernet MAC MDIO Reads Do Not Meet IEEE Specification */ 133/* Ethernet MAC MDIO Reads Do Not Meet IEEE Specification */
134#define ANOMALY_05000341 (__SILICON_REVISION__ >= 3) 134#define ANOMALY_05000341 (__SILICON_REVISION__ >= 3)
135/* New Feature: UART Remains Enabled after UART Boot (Not Available on Older Silicon) */
136#define ANOMALY_05000350 (__SILICON_REVISION__ < 3)
137/* Regulator Programming Blocked when Hibernate Wakeup Source Remains Active */
138#define ANOMALY_05000355 (1)
135/* Serial Port (SPORT) Multichannel Transmit Failure when Channel 0 Is Disabled */ 139/* Serial Port (SPORT) Multichannel Transmit Failure when Channel 0 Is Disabled */
136#define ANOMALY_05000357 (1) 140#define ANOMALY_05000357 (1)
137/* DMAs that Go Urgent during Tight Core Writes to External Memory Are Blocked */ 141/* DMAs that Go Urgent during Tight Core Writes to External Memory Are Blocked */
138#define ANOMALY_05000359 (1) 142#define ANOMALY_05000359 (1)
143/* PPI Underflow Error Goes Undetected in ITU-R 656 Mode */
144#define ANOMALY_05000366 (1)
145/* Possible RETS Register Corruption when Subroutine Is under 5 Cycles in Duration */
146#define ANOMALY_05000371 (1)
147/* SSYNC Stalls Processor when Executed from Non-Cacheable Memory */
148#define ANOMALY_05000402 (__SILICON_REVISION__ >= 3)
149/* Level-Sensitive External GPIO Wakeups May Cause Indefinite Stall */
150#define ANOMALY_05000403 (1)
151
152
139 153
140/* Anomalies that don't exist on this proc */ 154/* Anomalies that don't exist on this proc */
141#define ANOMALY_05000125 (0) 155#define ANOMALY_05000125 (0)
@@ -146,5 +160,6 @@
146#define ANOMALY_05000266 (0) 160#define ANOMALY_05000266 (0)
147#define ANOMALY_05000311 (0) 161#define ANOMALY_05000311 (0)
148#define ANOMALY_05000323 (0) 162#define ANOMALY_05000323 (0)
163#define ANOMALY_05000363 (0)
149 164
150#endif 165#endif
diff --git a/include/asm-blackfin/mach-bf537/bfin_serial_5xx.h b/include/asm-blackfin/mach-bf537/bfin_serial_5xx.h
index 8fc672d31057..fd100a415b98 100644
--- a/include/asm-blackfin/mach-bf537/bfin_serial_5xx.h
+++ b/include/asm-blackfin/mach-bf537/bfin_serial_5xx.h
@@ -1,22 +1,38 @@
1/*
2 * file: include/asm-blackfin/mach-bf537/bfin_serial_5xx.h
3 * based on:
4 * author:
5 *
6 * created:
7 * description:
8 * blackfin serial driver header files
9 * rev:
10 *
11 * modified:
12 *
13 *
14 * bugs: enter bugs at http://blackfin.uclinux.org/
15 *
16 * this program is free software; you can redistribute it and/or modify
17 * it under the terms of the gnu general public license as published by
18 * the free software foundation; either version 2, or (at your option)
19 * any later version.
20 *
21 * this program is distributed in the hope that it will be useful,
22 * but without any warranty; without even the implied warranty of
23 * merchantability or fitness for a particular purpose. see the
24 * gnu general public license for more details.
25 *
26 * you should have received a copy of the gnu general public license
27 * along with this program; see the file copying.
28 * if not, write to the free software foundation,
29 * 59 temple place - suite 330, boston, ma 02111-1307, usa.
30 */
31
1#include <linux/serial.h> 32#include <linux/serial.h>
2#include <asm/dma.h> 33#include <asm/dma.h>
3#include <asm/portmux.h> 34#include <asm/portmux.h>
4 35
5#define NR_PORTS 2
6
7#define OFFSET_THR 0x00 /* Transmit Holding register */
8#define OFFSET_RBR 0x00 /* Receive Buffer register */
9#define OFFSET_DLL 0x00 /* Divisor Latch (Low-Byte) */
10#define OFFSET_IER 0x04 /* Interrupt Enable Register */
11#define OFFSET_DLH 0x04 /* Divisor Latch (High-Byte) */
12#define OFFSET_IIR 0x08 /* Interrupt Identification Register */
13#define OFFSET_LCR 0x0C /* Line Control Register */
14#define OFFSET_MCR 0x10 /* Modem Control Register */
15#define OFFSET_LSR 0x14 /* Line Status Register */
16#define OFFSET_MSR 0x18 /* Modem Status Register */
17#define OFFSET_SCR 0x1C /* SCR Scratch Register */
18#define OFFSET_GCTL 0x24 /* Global Control Register */
19
20#define UART_GET_CHAR(uart) bfin_read16(((uart)->port.membase + OFFSET_RBR)) 36#define UART_GET_CHAR(uart) bfin_read16(((uart)->port.membase + OFFSET_RBR))
21#define UART_GET_DLL(uart) bfin_read16(((uart)->port.membase + OFFSET_DLL)) 37#define UART_GET_DLL(uart) bfin_read16(((uart)->port.membase + OFFSET_DLL))
22#define UART_GET_IER(uart) bfin_read16(((uart)->port.membase + OFFSET_IER)) 38#define UART_GET_IER(uart) bfin_read16(((uart)->port.membase + OFFSET_IER))
@@ -92,7 +108,7 @@ static inline void UART_CLEAR_LSR(struct bfin_serial_port *uart)
92 bfin_write16(uart->port.membase + OFFSET_LSR, -1); 108 bfin_write16(uart->port.membase + OFFSET_LSR, -1);
93} 109}
94 110
95struct bfin_serial_port bfin_serial_ports[NR_PORTS]; 111struct bfin_serial_port bfin_serial_ports[BFIN_UART_NR_PORTS];
96struct bfin_serial_res { 112struct bfin_serial_res {
97 unsigned long uart_base_addr; 113 unsigned long uart_base_addr;
98 int uart_irq; 114 int uart_irq;
diff --git a/include/asm-blackfin/mach-bf537/bfin_sir.h b/include/asm-blackfin/mach-bf537/bfin_sir.h
new file mode 100644
index 000000000000..0612d0c9501c
--- /dev/null
+++ b/include/asm-blackfin/mach-bf537/bfin_sir.h
@@ -0,0 +1,133 @@
1/*
2 * Blackfin Infra-red Driver
3 *
4 * Copyright 2006-2008 Analog Devices Inc.
5 *
6 * Enter bugs at http://blackfin.uclinux.org/
7 *
8 * Licensed under the GPL-2 or later.
9 *
10 */
11
12#include <linux/serial.h>
13#include <asm/dma.h>
14#include <asm/portmux.h>
15
16#define SIR_UART_GET_CHAR(port) bfin_read16((port)->membase + OFFSET_RBR)
17#define SIR_UART_GET_DLL(port) bfin_read16((port)->membase + OFFSET_DLL)
18#define SIR_UART_GET_IER(port) bfin_read16((port)->membase + OFFSET_IER)
19#define SIR_UART_GET_DLH(port) bfin_read16((port)->membase + OFFSET_DLH)
20#define SIR_UART_GET_IIR(port) bfin_read16((port)->membase + OFFSET_IIR)
21#define SIR_UART_GET_LCR(port) bfin_read16((port)->membase + OFFSET_LCR)
22#define SIR_UART_GET_GCTL(port) bfin_read16((port)->membase + OFFSET_GCTL)
23
24#define SIR_UART_PUT_CHAR(port, v) bfin_write16(((port)->membase + OFFSET_THR), v)
25#define SIR_UART_PUT_DLL(port, v) bfin_write16(((port)->membase + OFFSET_DLL), v)
26#define SIR_UART_PUT_IER(port, v) bfin_write16(((port)->membase + OFFSET_IER), v)
27#define SIR_UART_PUT_DLH(port, v) bfin_write16(((port)->membase + OFFSET_DLH), v)
28#define SIR_UART_PUT_LCR(port, v) bfin_write16(((port)->membase + OFFSET_LCR), v)
29#define SIR_UART_PUT_GCTL(port, v) bfin_write16(((port)->membase + OFFSET_GCTL), v)
30
31#ifdef CONFIG_SIR_BFIN_DMA
32struct dma_rx_buf {
33 char *buf;
34 int head;
35 int tail;
36 };
37#endif /* CONFIG_SIR_BFIN_DMA */
38
39struct bfin_sir_port {
40 unsigned char __iomem *membase;
41 unsigned int irq;
42 unsigned int lsr;
43 unsigned long clk;
44 struct net_device *dev;
45#ifdef CONFIG_SIR_BFIN_DMA
46 int tx_done;
47 struct dma_rx_buf rx_dma_buf;
48 struct timer_list rx_dma_timer;
49 int rx_dma_nrows;
50#endif /* CONFIG_SIR_BFIN_DMA */
51 unsigned int tx_dma_channel;
52 unsigned int rx_dma_channel;
53};
54
55struct bfin_sir_port sir_ports[BFIN_UART_NR_PORTS];
56
57struct bfin_sir_port_res {
58 unsigned long base_addr;
59 int irq;
60 unsigned int rx_dma_channel;
61 unsigned int tx_dma_channel;
62};
63
64struct bfin_sir_port_res bfin_sir_port_resource[] = {
65#ifdef CONFIG_BFIN_SIR0
66 {
67 0xFFC00400,
68 IRQ_UART0_RX,
69 CH_UART0_RX,
70 CH_UART0_TX,
71 },
72#endif
73#ifdef CONFIG_BFIN_SIR1
74 {
75 0xFFC02000,
76 IRQ_UART1_RX,
77 CH_UART1_RX,
78 CH_UART1_TX,
79 },
80#endif
81};
82
83int nr_sirs = ARRAY_SIZE(bfin_sir_port_resource);
84
85struct bfin_sir_self {
86 struct bfin_sir_port *sir_port;
87 spinlock_t lock;
88 unsigned int open;
89 int speed;
90 int newspeed;
91
92 struct sk_buff *txskb;
93 struct sk_buff *rxskb;
94 struct net_device_stats stats;
95 struct device *dev;
96 struct irlap_cb *irlap;
97 struct qos_info qos;
98
99 iobuff_t tx_buff;
100 iobuff_t rx_buff;
101
102 struct work_struct work;
103 int mtt;
104};
105
106static inline unsigned int SIR_UART_GET_LSR(struct bfin_sir_port *port)
107{
108 unsigned int lsr = bfin_read16(port->membase + OFFSET_LSR);
109 port->lsr |= (lsr & (BI|FE|PE|OE));
110 return lsr | port->lsr;
111}
112
113static inline void SIR_UART_CLEAR_LSR(struct bfin_sir_port *port)
114{
115 port->lsr = 0;
116 bfin_read16(port->membase + OFFSET_LSR);
117}
118
119#define DRIVER_NAME "bfin_sir"
120
121static void bfin_sir_hw_init(void)
122{
123#ifdef CONFIG_BFIN_SIR0
124 peripheral_request(P_UART0_TX, DRIVER_NAME);
125 peripheral_request(P_UART0_RX, DRIVER_NAME);
126#endif
127
128#ifdef CONFIG_BFIN_SIR1
129 peripheral_request(P_UART1_TX, DRIVER_NAME);
130 peripheral_request(P_UART1_RX, DRIVER_NAME);
131#endif
132 SSYNC();
133}
diff --git a/include/asm-blackfin/mach-bf537/blackfin.h b/include/asm-blackfin/mach-bf537/blackfin.h
index 53fcfa3408d0..cffc786b2a2b 100644
--- a/include/asm-blackfin/mach-bf537/blackfin.h
+++ b/include/asm-blackfin/mach-bf537/blackfin.h
@@ -82,8 +82,6 @@
82#define STATUS_P1 0x02 82#define STATUS_P1 0x02
83#define STATUS_P0 0x01 83#define STATUS_P0 0x01
84 84
85/* UART 0*/
86
87/* DMA Channnel */ 85/* DMA Channnel */
88#define bfin_read_CH_UART_RX() bfin_read_CH_UART0_RX() 86#define bfin_read_CH_UART_RX() bfin_read_CH_UART0_RX()
89#define bfin_write_CH_UART_RX(val) bfin_write_CH_UART0_RX(val) 87#define bfin_write_CH_UART_RX(val) bfin_write_CH_UART0_RX(val)
@@ -106,37 +104,52 @@
106/* MMR Registers*/ 104/* MMR Registers*/
107#define bfin_read_UART_THR() bfin_read_UART0_THR() 105#define bfin_read_UART_THR() bfin_read_UART0_THR()
108#define bfin_write_UART_THR(val) bfin_write_UART0_THR(val) 106#define bfin_write_UART_THR(val) bfin_write_UART0_THR(val)
109#define UART_THR UART0_THR 107#define BFIN_UART_THR UART0_THR
110#define bfin_read_UART_RBR() bfin_read_UART0_RBR() 108#define bfin_read_UART_RBR() bfin_read_UART0_RBR()
111#define bfin_write_UART_RBR(val) bfin_write_UART0_RBR(val) 109#define bfin_write_UART_RBR(val) bfin_write_UART0_RBR(val)
112#define UART_RBR UART0_RBR 110#define BFIN_UART_RBR UART0_RBR
113#define bfin_read_UART_DLL() bfin_read_UART0_DLL() 111#define bfin_read_UART_DLL() bfin_read_UART0_DLL()
114#define bfin_write_UART_DLL(val) bfin_write_UART0_DLL(val) 112#define bfin_write_UART_DLL(val) bfin_write_UART0_DLL(val)
115#define UART_DLL UART0_DLL 113#define BFIN_UART_DLL UART0_DLL
116#define bfin_read_UART_IER() bfin_read_UART0_IER() 114#define bfin_read_UART_IER() bfin_read_UART0_IER()
117#define bfin_write_UART_IER(val) bfin_write_UART0_IER(val) 115#define bfin_write_UART_IER(val) bfin_write_UART0_IER(val)
118#define UART_IER UART0_IER 116#define BFIN_UART_IER UART0_IER
119#define bfin_read_UART_DLH() bfin_read_UART0_DLH() 117#define bfin_read_UART_DLH() bfin_read_UART0_DLH()
120#define bfin_write_UART_DLH(val) bfin_write_UART0_DLH(val) 118#define bfin_write_UART_DLH(val) bfin_write_UART0_DLH(val)
121#define UART_DLH UART0_DLH 119#define BFIN_UART_DLH UART0_DLH
122#define bfin_read_UART_IIR() bfin_read_UART0_IIR() 120#define bfin_read_UART_IIR() bfin_read_UART0_IIR()
123#define bfin_write_UART_IIR(val) bfin_write_UART0_IIR(val) 121#define bfin_write_UART_IIR(val) bfin_write_UART0_IIR(val)
124#define UART_IIR UART0_IIR 122#define BFIN_UART_IIR UART0_IIR
125#define bfin_read_UART_LCR() bfin_read_UART0_LCR() 123#define bfin_read_UART_LCR() bfin_read_UART0_LCR()
126#define bfin_write_UART_LCR(val) bfin_write_UART0_LCR(val) 124#define bfin_write_UART_LCR(val) bfin_write_UART0_LCR(val)
127#define UART_LCR UART0_LCR 125#define BFIN_UART_LCR UART0_LCR
128#define bfin_read_UART_MCR() bfin_read_UART0_MCR() 126#define bfin_read_UART_MCR() bfin_read_UART0_MCR()
129#define bfin_write_UART_MCR(val) bfin_write_UART0_MCR(val) 127#define bfin_write_UART_MCR(val) bfin_write_UART0_MCR(val)
130#define UART_MCR UART0_MCR 128#define BFIN_UART_MCR UART0_MCR
131#define bfin_read_UART_LSR() bfin_read_UART0_LSR() 129#define bfin_read_UART_LSR() bfin_read_UART0_LSR()
132#define bfin_write_UART_LSR(val) bfin_write_UART0_LSR(val) 130#define bfin_write_UART_LSR(val) bfin_write_UART0_LSR(val)
133#define UART_LSR UART0_LSR 131#define BFIN_UART_LSR UART0_LSR
134#define bfin_read_UART_SCR() bfin_read_UART0_SCR() 132#define bfin_read_UART_SCR() bfin_read_UART0_SCR()
135#define bfin_write_UART_SCR(val) bfin_write_UART0_SCR(val) 133#define bfin_write_UART_SCR(val) bfin_write_UART0_SCR(val)
136#define UART_SCR UART0_SCR 134#define BFIN_UART_SCR UART0_SCR
137#define bfin_read_UART_GCTL() bfin_read_UART0_GCTL() 135#define bfin_read_UART_GCTL() bfin_read_UART0_GCTL()
138#define bfin_write_UART_GCTL(val) bfin_write_UART0_GCTL(val) 136#define bfin_write_UART_GCTL(val) bfin_write_UART0_GCTL(val)
139#define UART_GCTL UART0_GCTL 137#define BFIN_UART_GCTL UART0_GCTL
138
139#define BFIN_UART_NR_PORTS 2
140
141#define OFFSET_THR 0x00 /* Transmit Holding register */
142#define OFFSET_RBR 0x00 /* Receive Buffer register */
143#define OFFSET_DLL 0x00 /* Divisor Latch (Low-Byte) */
144#define OFFSET_IER 0x04 /* Interrupt Enable Register */
145#define OFFSET_DLH 0x04 /* Divisor Latch (High-Byte) */
146#define OFFSET_IIR 0x08 /* Interrupt Identification Register */
147#define OFFSET_LCR 0x0C /* Line Control Register */
148#define OFFSET_MCR 0x10 /* Modem Control Register */
149#define OFFSET_LSR 0x14 /* Line Status Register */
150#define OFFSET_MSR 0x18 /* Modem Status Register */
151#define OFFSET_SCR 0x1C /* SCR Scratch Register */
152#define OFFSET_GCTL 0x24 /* Global Control Register */
140 153
141/* DPMC*/ 154/* DPMC*/
142#define bfin_read_STOPCK_OFF() bfin_read_STOPCK() 155#define bfin_read_STOPCK_OFF() bfin_read_STOPCK()
diff --git a/include/asm-blackfin/mach-bf537/cdefBF534.h b/include/asm-blackfin/mach-bf537/cdefBF534.h
index 78227bc855df..82de526f8097 100644
--- a/include/asm-blackfin/mach-bf537/cdefBF534.h
+++ b/include/asm-blackfin/mach-bf537/cdefBF534.h
@@ -44,7 +44,27 @@
44 44
45/* Clock and System Control (0xFFC00000 - 0xFFC000FF) */ 45/* Clock and System Control (0xFFC00000 - 0xFFC000FF) */
46#define bfin_read_PLL_CTL() bfin_read16(PLL_CTL) 46#define bfin_read_PLL_CTL() bfin_read16(PLL_CTL)
47#define bfin_write_PLL_CTL(val) bfin_write16(PLL_CTL,val) 47/* Writing to PLL_CTL initiates a PLL relock sequence. */
48static __inline__ void bfin_write_PLL_CTL(unsigned int val)
49{
50 unsigned long flags, iwr;
51
52 if (val == bfin_read_PLL_CTL())
53 return;
54
55 local_irq_save(flags);
56 /* Enable the PLL Wakeup bit in SIC IWR */
57 iwr = bfin_read32(SIC_IWR);
58 /* Only allow PPL Wakeup) */
59 bfin_write32(SIC_IWR, IWR_ENABLE(0));
60
61 bfin_write16(PLL_CTL, val);
62 SSYNC();
63 asm("IDLE;");
64
65 bfin_write32(SIC_IWR, iwr);
66 local_irq_restore(flags);
67}
48#define bfin_read_PLL_DIV() bfin_read16(PLL_DIV) 68#define bfin_read_PLL_DIV() bfin_read16(PLL_DIV)
49#define bfin_write_PLL_DIV(val) bfin_write16(PLL_DIV,val) 69#define bfin_write_PLL_DIV(val) bfin_write16(PLL_DIV,val)
50#define bfin_read_VR_CTL() bfin_read16(VR_CTL) 70#define bfin_read_VR_CTL() bfin_read16(VR_CTL)
@@ -53,6 +73,10 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
53{ 73{
54 unsigned long flags, iwr; 74 unsigned long flags, iwr;
55 75
76 if (val == bfin_read_VR_CTL())
77 return;
78
79 local_irq_save(flags);
56 /* Enable the PLL Wakeup bit in SIC IWR */ 80 /* Enable the PLL Wakeup bit in SIC IWR */
57 iwr = bfin_read32(SIC_IWR); 81 iwr = bfin_read32(SIC_IWR);
58 /* Only allow PPL Wakeup) */ 82 /* Only allow PPL Wakeup) */
@@ -60,11 +84,10 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
60 84
61 bfin_write16(VR_CTL, val); 85 bfin_write16(VR_CTL, val);
62 SSYNC(); 86 SSYNC();
63
64 local_irq_save(flags);
65 asm("IDLE;"); 87 asm("IDLE;");
66 local_irq_restore(flags); 88
67 bfin_write32(SIC_IWR, iwr); 89 bfin_write32(SIC_IWR, iwr);
90 local_irq_restore(flags);
68} 91}
69#define bfin_read_PLL_STAT() bfin_read16(PLL_STAT) 92#define bfin_read_PLL_STAT() bfin_read16(PLL_STAT)
70#define bfin_write_PLL_STAT(val) bfin_write16(PLL_STAT,val) 93#define bfin_write_PLL_STAT(val) bfin_write16(PLL_STAT,val)
@@ -858,39 +881,7 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
858#define bfin_read_PPI_FRAME() bfin_read16(PPI_FRAME) 881#define bfin_read_PPI_FRAME() bfin_read16(PPI_FRAME)
859#define bfin_write_PPI_FRAME(val) bfin_write16(PPI_FRAME,val) 882#define bfin_write_PPI_FRAME(val) bfin_write16(PPI_FRAME,val)
860 883
861/* Two-Wire Interface (0xFFC01400 - 0xFFC014FF) */ 884/* Two-Wire Interface (0xFFC01400 - 0xFFC014FF) */
862#define bfin_read_TWI_CLKDIV() bfin_read16(TWI_CLKDIV)
863#define bfin_write_TWI_CLKDIV(val) bfin_write16(TWI_CLKDIV,val)
864#define bfin_read_TWI_CONTROL() bfin_read16(TWI_CONTROL)
865#define bfin_write_TWI_CONTROL(val) bfin_write16(TWI_CONTROL,val)
866#define bfin_read_TWI_SLAVE_CTL() bfin_read16(TWI_SLAVE_CTL)
867#define bfin_write_TWI_SLAVE_CTL(val) bfin_write16(TWI_SLAVE_CTL,val)
868#define bfin_read_TWI_SLAVE_STAT() bfin_read16(TWI_SLAVE_STAT)
869#define bfin_write_TWI_SLAVE_STAT(val) bfin_write16(TWI_SLAVE_STAT,val)
870#define bfin_read_TWI_SLAVE_ADDR() bfin_read16(TWI_SLAVE_ADDR)
871#define bfin_write_TWI_SLAVE_ADDR(val) bfin_write16(TWI_SLAVE_ADDR,val)
872#define bfin_read_TWI_MASTER_CTL() bfin_read16(TWI_MASTER_CTL)
873#define bfin_write_TWI_MASTER_CTL(val) bfin_write16(TWI_MASTER_CTL,val)
874#define bfin_read_TWI_MASTER_STAT() bfin_read16(TWI_MASTER_STAT)
875#define bfin_write_TWI_MASTER_STAT(val) bfin_write16(TWI_MASTER_STAT,val)
876#define bfin_read_TWI_MASTER_ADDR() bfin_read16(TWI_MASTER_ADDR)
877#define bfin_write_TWI_MASTER_ADDR(val) bfin_write16(TWI_MASTER_ADDR,val)
878#define bfin_read_TWI_INT_STAT() bfin_read16(TWI_INT_STAT)
879#define bfin_write_TWI_INT_STAT(val) bfin_write16(TWI_INT_STAT,val)
880#define bfin_read_TWI_INT_MASK() bfin_read16(TWI_INT_MASK)
881#define bfin_write_TWI_INT_MASK(val) bfin_write16(TWI_INT_MASK,val)
882#define bfin_read_TWI_FIFO_CTL() bfin_read16(TWI_FIFO_CTL)
883#define bfin_write_TWI_FIFO_CTL(val) bfin_write16(TWI_FIFO_CTL,val)
884#define bfin_read_TWI_FIFO_STAT() bfin_read16(TWI_FIFO_STAT)
885#define bfin_write_TWI_FIFO_STAT(val) bfin_write16(TWI_FIFO_STAT,val)
886#define bfin_read_TWI_XMT_DATA8() bfin_read16(TWI_XMT_DATA8)
887#define bfin_write_TWI_XMT_DATA8(val) bfin_write16(TWI_XMT_DATA8,val)
888#define bfin_read_TWI_XMT_DATA16() bfin_read16(TWI_XMT_DATA16)
889#define bfin_write_TWI_XMT_DATA16(val) bfin_write16(TWI_XMT_DATA16,val)
890#define bfin_read_TWI_RCV_DATA8() bfin_read16(TWI_RCV_DATA8)
891#define bfin_write_TWI_RCV_DATA8(val) bfin_write16(TWI_RCV_DATA8,val)
892#define bfin_read_TWI_RCV_DATA16() bfin_read16(TWI_RCV_DATA16)
893#define bfin_write_TWI_RCV_DATA16(val) bfin_write16(TWI_RCV_DATA16,val)
894 885
895/* General Purpose I/O Port G (0xFFC01500 - 0xFFC015FF) */ 886/* General Purpose I/O Port G (0xFFC01500 - 0xFFC015FF) */
896#define bfin_read_PORTGIO() bfin_read16(PORTGIO) 887#define bfin_read_PORTGIO() bfin_read16(PORTGIO)
diff --git a/include/asm-blackfin/mach-bf537/dma.h b/include/asm-blackfin/mach-bf537/dma.h
index 021991984e6e..7a964040870a 100644
--- a/include/asm-blackfin/mach-bf537/dma.h
+++ b/include/asm-blackfin/mach-bf537/dma.h
@@ -52,7 +52,4 @@
52#define CH_MEM_STREAM1_DEST 14 /* TX */ 52#define CH_MEM_STREAM1_DEST 14 /* TX */
53#define CH_MEM_STREAM1_SRC 15 /* RX */ 53#define CH_MEM_STREAM1_SRC 15 /* RX */
54 54
55extern int channel2irq(unsigned int channel);
56extern struct dma_register *base_addr[];
57
58#endif 55#endif
diff --git a/include/asm-blackfin/mach-bf548/anomaly.h b/include/asm-blackfin/mach-bf548/anomaly.h
index 850dc12eb7f2..49d3cebc5293 100644
--- a/include/asm-blackfin/mach-bf548/anomaly.h
+++ b/include/asm-blackfin/mach-bf548/anomaly.h
@@ -93,5 +93,6 @@
93#define ANOMALY_05000273 (0) 93#define ANOMALY_05000273 (0)
94#define ANOMALY_05000311 (0) 94#define ANOMALY_05000311 (0)
95#define ANOMALY_05000323 (0) 95#define ANOMALY_05000323 (0)
96#define ANOMALY_05000363 (0)
96 97
97#endif 98#endif
diff --git a/include/asm-blackfin/mach-bf548/bfin_serial_5xx.h b/include/asm-blackfin/mach-bf548/bfin_serial_5xx.h
index 7e6339f62a50..6547027cd3e6 100644
--- a/include/asm-blackfin/mach-bf548/bfin_serial_5xx.h
+++ b/include/asm-blackfin/mach-bf548/bfin_serial_5xx.h
@@ -1,22 +1,38 @@
1/*
2 * file: include/asm-blackfin/mach-bf548/bfin_serial_5xx.h
3 * based on:
4 * author:
5 *
6 * created:
7 * description:
8 * blackfin serial driver head file
9 * rev:
10 *
11 * modified:
12 *
13 *
14 * bugs: enter bugs at http://blackfin.uclinux.org/
15 *
16 * this program is free software; you can redistribute it and/or modify
17 * it under the terms of the gnu general public license as published by
18 * the free software foundation; either version 2, or (at your option)
19 * any later version.
20 *
21 * this program is distributed in the hope that it will be useful,
22 * but without any warranty; without even the implied warranty of
23 * merchantability or fitness for a particular purpose. see the
24 * gnu general public license for more details.
25 *
26 * you should have received a copy of the gnu general public license
27 * along with this program; see the file copying.
28 * if not, write to the free software foundation,
29 * 59 temple place - suite 330, boston, ma 02111-1307, usa.
30 */
31
1#include <linux/serial.h> 32#include <linux/serial.h>
2#include <asm/dma.h> 33#include <asm/dma.h>
3#include <asm/portmux.h> 34#include <asm/portmux.h>
4 35
5#define NR_PORTS 4
6
7#define OFFSET_DLL 0x00 /* Divisor Latch (Low-Byte) */
8#define OFFSET_DLH 0x04 /* Divisor Latch (High-Byte) */
9#define OFFSET_GCTL 0x08 /* Global Control Register */
10#define OFFSET_LCR 0x0C /* Line Control Register */
11#define OFFSET_MCR 0x10 /* Modem Control Register */
12#define OFFSET_LSR 0x14 /* Line Status Register */
13#define OFFSET_MSR 0x18 /* Modem Status Register */
14#define OFFSET_SCR 0x1C /* SCR Scratch Register */
15#define OFFSET_IER_SET 0x20 /* Set Interrupt Enable Register */
16#define OFFSET_IER_CLEAR 0x24 /* Clear Interrupt Enable Register */
17#define OFFSET_THR 0x28 /* Transmit Holding register */
18#define OFFSET_RBR 0x2C /* Receive Buffer register */
19
20#define UART_GET_CHAR(uart) bfin_read16(((uart)->port.membase + OFFSET_RBR)) 36#define UART_GET_CHAR(uart) bfin_read16(((uart)->port.membase + OFFSET_RBR))
21#define UART_GET_DLL(uart) bfin_read16(((uart)->port.membase + OFFSET_DLL)) 37#define UART_GET_DLL(uart) bfin_read16(((uart)->port.membase + OFFSET_DLL))
22#define UART_GET_DLH(uart) bfin_read16(((uart)->port.membase + OFFSET_DLH)) 38#define UART_GET_DLH(uart) bfin_read16(((uart)->port.membase + OFFSET_DLH))
@@ -80,7 +96,7 @@ struct bfin_serial_port {
80#endif 96#endif
81}; 97};
82 98
83struct bfin_serial_port bfin_serial_ports[NR_PORTS]; 99struct bfin_serial_port bfin_serial_ports[BFIN_UART_NR_PORTS];
84struct bfin_serial_res { 100struct bfin_serial_res {
85 unsigned long uart_base_addr; 101 unsigned long uart_base_addr;
86 int uart_irq; 102 int uart_irq;
diff --git a/include/asm-blackfin/mach-bf548/bfin_sir.h b/include/asm-blackfin/mach-bf548/bfin_sir.h
new file mode 100644
index 000000000000..5e94271c7e3b
--- /dev/null
+++ b/include/asm-blackfin/mach-bf548/bfin_sir.h
@@ -0,0 +1,149 @@
1/*
2 * Blackfin Infra-red Driver
3 *
4 * Copyright 2006-2008 Analog Devices Inc.
5 *
6 * Enter bugs at http://blackfin.uclinux.org/
7 *
8 * Licensed under the GPL-2 or later.
9 *
10 */
11
12#include <linux/serial.h>
13#include <asm/dma.h>
14#include <asm/portmux.h>
15
16#define SIR_UART_GET_CHAR(port) bfin_read16((port)->membase + OFFSET_RBR)
17#define SIR_UART_GET_DLL(port) bfin_read16((port)->membase + OFFSET_DLL)
18#define SIR_UART_GET_IER(port) bfin_read16((port)->membase + OFFSET_IER_SET)
19#define SIR_UART_GET_DLH(port) bfin_read16((port)->membase + OFFSET_DLH)
20#define SIR_UART_GET_LCR(port) bfin_read16((port)->membase + OFFSET_LCR)
21#define SIR_UART_GET_LSR(port) bfin_read16((port)->membase + OFFSET_LSR)
22#define SIR_UART_GET_GCTL(port) bfin_read16((port)->membase + OFFSET_GCTL)
23
24#define SIR_UART_PUT_CHAR(port, v) bfin_write16(((port)->membase + OFFSET_THR), v)
25#define SIR_UART_PUT_DLL(port, v) bfin_write16(((port)->membase + OFFSET_DLL), v)
26#define SIR_UART_SET_IER(port, v) bfin_write16(((port)->membase + OFFSET_IER_SET), v)
27#define SIR_UART_CLEAR_IER(port, v) bfin_write16(((port)->membase + OFFSET_IER_CLEAR), v)
28#define SIR_UART_PUT_DLH(port, v) bfin_write16(((port)->membase + OFFSET_DLH), v)
29#define SIR_UART_PUT_LSR(port, v) bfin_write16(((port)->membase + OFFSET_LSR), v)
30#define SIR_UART_PUT_LCR(port, v) bfin_write16(((port)->membase + OFFSET_LCR), v)
31#define SIR_UART_CLEAR_LSR(port) bfin_write16(((port)->membase + OFFSET_LSR), -1)
32#define SIR_UART_PUT_GCTL(port, v) bfin_write16(((port)->membase + OFFSET_GCTL), v)
33
34#ifdef CONFIG_SIR_BFIN_DMA
35struct dma_rx_buf {
36 char *buf;
37 int head;
38 int tail;
39 };
40#endif /* CONFIG_SIR_BFIN_DMA */
41
42struct bfin_sir_port {
43 unsigned char __iomem *membase;
44 unsigned int irq;
45 unsigned int lsr;
46 unsigned long clk;
47 struct net_device *dev;
48#ifdef CONFIG_SIR_BFIN_DMA
49 int tx_done;
50 struct dma_rx_buf rx_dma_buf;
51 struct timer_list rx_dma_timer;
52 int rx_dma_nrows;
53#endif /* CONFIG_SIR_BFIN_DMA */
54 unsigned int tx_dma_channel;
55 unsigned int rx_dma_channel;
56};
57
58struct bfin_sir_port sir_ports[BFIN_UART_NR_PORTS];
59
60struct bfin_sir_port_res {
61 unsigned long base_addr;
62 int irq;
63 unsigned int rx_dma_channel;
64 unsigned int tx_dma_channel;
65};
66
67struct bfin_sir_port_res bfin_sir_port_resource[] = {
68#ifdef CONFIG_BFIN_SIR0
69 {
70 0xFFC00400,
71 IRQ_UART0_RX,
72 CH_UART0_RX,
73 CH_UART0_TX,
74 },
75#endif
76#ifdef CONFIG_BFIN_SIR1
77 {
78 0xFFC02000,
79 IRQ_UART1_RX,
80 CH_UART1_RX,
81 CH_UART1_TX,
82 },
83#endif
84#ifdef CONFIG_BFIN_SIR2
85 {
86 0xFFC02100,
87 IRQ_UART2_RX,
88 CH_UART2_RX,
89 CH_UART2_TX,
90 },
91#endif
92#ifdef CONFIG_BFIN_SIR3
93 {
94 0xFFC03100,
95 IRQ_UART3_RX,
96 CH_UART3_RX,
97 CH_UART3_TX,
98 },
99#endif
100};
101
102int nr_sirs = ARRAY_SIZE(bfin_sir_port_resource);
103
104struct bfin_sir_self {
105 struct bfin_sir_port *sir_port;
106 spinlock_t lock;
107 unsigned int open;
108 int speed;
109 int newspeed;
110
111 struct sk_buff *txskb;
112 struct sk_buff *rxskb;
113 struct net_device_stats stats;
114 struct device *dev;
115 struct irlap_cb *irlap;
116 struct qos_info qos;
117
118 iobuff_t tx_buff;
119 iobuff_t rx_buff;
120
121 struct work_struct work;
122 int mtt;
123};
124
125#define DRIVER_NAME "bfin_sir"
126
127static void bfin_sir_hw_init(void)
128{
129#ifdef CONFIG_BFIN_SIR0
130 peripheral_request(P_UART0_TX, DRIVER_NAME);
131 peripheral_request(P_UART0_RX, DRIVER_NAME);
132#endif
133
134#ifdef CONFIG_BFIN_SIR1
135 peripheral_request(P_UART1_TX, DRIVER_NAME);
136 peripheral_request(P_UART1_RX, DRIVER_NAME);
137#endif
138
139#ifdef CONFIG_BFIN_SIR2
140 peripheral_request(P_UART2_TX, DRIVER_NAME);
141 peripheral_request(P_UART2_RX, DRIVER_NAME);
142#endif
143
144#ifdef CONFIG_BFIN_SIR3
145 peripheral_request(P_UART3_TX, DRIVER_NAME);
146 peripheral_request(P_UART3_RX, DRIVER_NAME);
147#endif
148 SSYNC();
149}
diff --git a/include/asm-blackfin/mach-bf548/blackfin.h b/include/asm-blackfin/mach-bf548/blackfin.h
index 3bd67da86053..d6ee74ac0460 100644
--- a/include/asm-blackfin/mach-bf548/blackfin.h
+++ b/include/asm-blackfin/mach-bf548/blackfin.h
@@ -153,17 +153,33 @@
153#define bfin_write_UART_SCR(val) bfin_write_UART1_SCR(val) 153#define bfin_write_UART_SCR(val) bfin_write_UART1_SCR(val)
154#define bfin_read_UART_GCTL() bfin_read_UART1_GCTL() 154#define bfin_read_UART_GCTL() bfin_read_UART1_GCTL()
155#define bfin_write_UART_GCTL(val) bfin_write_UART1_GCTL(val) 155#define bfin_write_UART_GCTL(val) bfin_write_UART1_GCTL(val)
156#define UART_THR UART1_THR 156
157#define UART_RBR UART1_RBR 157#define BFIN_UART_THR UART1_THR
158#define UART_DLL UART1_DLL 158#define BFIN_UART_RBR UART1_RBR
159#define UART_IER UART1_IER 159#define BFIN_UART_DLL UART1_DLL
160#define UART_DLH UART1_DLH 160#define BFIN_UART_IER UART1_IER
161#define UART_IIR UART1_IIR 161#define BFIN_UART_DLH UART1_DLH
162#define UART_LCR UART1_LCR 162#define BFIN_UART_IIR UART1_IIR
163#define UART_MCR UART1_MCR 163#define BFIN_UART_LCR UART1_LCR
164#define UART_LSR UART1_LSR 164#define BFIN_UART_MCR UART1_MCR
165#define UART_SCR UART1_SCR 165#define BFIN_UART_LSR UART1_LSR
166#define UART_GCTL UART1_GCTL 166#define BFIN_UART_SCR UART1_SCR
167#define BFIN_UART_GCTL UART1_GCTL
168
169#define BFIN_UART_NR_PORTS 4
170
171#define OFFSET_DLL 0x00 /* Divisor Latch (Low-Byte) */
172#define OFFSET_DLH 0x04 /* Divisor Latch (High-Byte) */
173#define OFFSET_GCTL 0x08 /* Global Control Register */
174#define OFFSET_LCR 0x0C /* Line Control Register */
175#define OFFSET_MCR 0x10 /* Modem Control Register */
176#define OFFSET_LSR 0x14 /* Line Status Register */
177#define OFFSET_MSR 0x18 /* Modem Status Register */
178#define OFFSET_SCR 0x1C /* SCR Scratch Register */
179#define OFFSET_IER_SET 0x20 /* Set Interrupt Enable Register */
180#define OFFSET_IER_CLEAR 0x24 /* Clear Interrupt Enable Register */
181#define OFFSET_THR 0x28 /* Transmit Holding register */
182#define OFFSET_RBR 0x2C /* Receive Buffer register */
167 183
168/* PLL_DIV Masks */ 184/* PLL_DIV Masks */
169#define CCLK_DIV1 CSEL_DIV1 /* CCLK = VCO / 1 */ 185#define CCLK_DIV1 CSEL_DIV1 /* CCLK = VCO / 1 */
diff --git a/include/asm-blackfin/mach-bf548/cdefBF542.h b/include/asm-blackfin/mach-bf548/cdefBF542.h
index 308b33ab5311..60b9f77576f1 100644
--- a/include/asm-blackfin/mach-bf548/cdefBF542.h
+++ b/include/asm-blackfin/mach-bf548/cdefBF542.h
@@ -123,12 +123,12 @@
123#define bfin_write_SDH_DATA_LGTH(val) bfin_write16(SDH_DATA_LGTH, val) 123#define bfin_write_SDH_DATA_LGTH(val) bfin_write16(SDH_DATA_LGTH, val)
124#define bfin_read_SDH_DATA_CTL() bfin_read16(SDH_DATA_CTL) 124#define bfin_read_SDH_DATA_CTL() bfin_read16(SDH_DATA_CTL)
125#define bfin_write_SDH_DATA_CTL(val) bfin_write16(SDH_DATA_CTL, val) 125#define bfin_write_SDH_DATA_CTL(val) bfin_write16(SDH_DATA_CTL, val)
126#define bfin_read_SDH_DATA_CNT() fin_read16(SDH_DATA_CNT) 126#define bfin_read_SDH_DATA_CNT() bfin_read16(SDH_DATA_CNT)
127#define bfin_write_SDH_DATA_CNT(val) bfin_write16(SDH_DATA_CNT, val) 127#define bfin_write_SDH_DATA_CNT(val) bfin_write16(SDH_DATA_CNT, val)
128#define bfin_read_SDH_STATUS() bfin_read32(SDH_STATUS) 128#define bfin_read_SDH_STATUS() bfin_read32(SDH_STATUS)
129#define bfin_write_SDH_STATUS(val) bfin_write32(SDH_STATUS, val) 129#define bfin_write_SDH_STATUS(val) bfin_write32(SDH_STATUS, val)
130#define bfin_read_SDH_STATUS_CLR() fin_read16(SDH_STATUS_CLR) 130#define bfin_read_SDH_STATUS_CLR() bfin_read16(SDH_STATUS_CLR)
131#define bfin_write_SDH_STATUS_CLR(val) fin_write16(SDH_STATUS_CLR, val) 131#define bfin_write_SDH_STATUS_CLR(val) bfin_write16(SDH_STATUS_CLR, val)
132#define bfin_read_SDH_MASK0() bfin_read32(SDH_MASK0) 132#define bfin_read_SDH_MASK0() bfin_read32(SDH_MASK0)
133#define bfin_write_SDH_MASK0(val) bfin_write32(SDH_MASK0, val) 133#define bfin_write_SDH_MASK0(val) bfin_write32(SDH_MASK0, val)
134#define bfin_read_SDH_MASK1() bfin_read32(SDH_MASK1) 134#define bfin_read_SDH_MASK1() bfin_read32(SDH_MASK1)
@@ -184,8 +184,8 @@
184#define bfin_write_USB_FRAME(val) bfin_write16(USB_FRAME, val) 184#define bfin_write_USB_FRAME(val) bfin_write16(USB_FRAME, val)
185#define bfin_read_USB_INDEX() bfin_read16(USB_INDEX) 185#define bfin_read_USB_INDEX() bfin_read16(USB_INDEX)
186#define bfin_write_USB_INDEX(val) bfin_write16(USB_INDEX, val) 186#define bfin_write_USB_INDEX(val) bfin_write16(USB_INDEX, val)
187#define bfin_read_USB_TESTMODE() fin_read16(USB_TESTMODE) 187#define bfin_read_USB_TESTMODE() bfin_read16(USB_TESTMODE)
188#define bfin_write_USB_TESTMODE(val) fin_write16(USB_TESTMODE, val) 188#define bfin_write_USB_TESTMODE(val) bfin_write16(USB_TESTMODE, val)
189#define bfin_read_USB_GLOBINTR() bfin_read16(USB_GLOBINTR) 189#define bfin_read_USB_GLOBINTR() bfin_read16(USB_GLOBINTR)
190#define bfin_write_USB_GLOBINTR(val) bfin_write16(USB_GLOBINTR, val) 190#define bfin_write_USB_GLOBINTR(val) bfin_write16(USB_GLOBINTR, val)
191#define bfin_read_USB_GLOBAL_CTL() bfin_read16(USB_GLOBAL_CTL) 191#define bfin_read_USB_GLOBAL_CTL() bfin_read16(USB_GLOBAL_CTL)
@@ -244,7 +244,7 @@
244#define bfin_read_USB_OTG_DEV_CTL() bfin_read16(USB_OTG_DEV_CTL) 244#define bfin_read_USB_OTG_DEV_CTL() bfin_read16(USB_OTG_DEV_CTL)
245#define bfin_write_USB_OTG_DEV_CTL(val) bfin_write16(USB_OTG_DEV_CTL, val) 245#define bfin_write_USB_OTG_DEV_CTL(val) bfin_write16(USB_OTG_DEV_CTL, val)
246#define bfin_read_USB_OTG_VBUS_IRQ() bfin_read16(USB_OTG_VBUS_IRQ) 246#define bfin_read_USB_OTG_VBUS_IRQ() bfin_read16(USB_OTG_VBUS_IRQ)
247#define bfin_write_USB_OTG_VBUS_IRQ(val) fin_write16(USB_OTG_VBUS_IRQ, val) 247#define bfin_write_USB_OTG_VBUS_IRQ(val) bfin_write16(USB_OTG_VBUS_IRQ, val)
248#define bfin_read_USB_OTG_VBUS_MASK() bfin_read16(USB_OTG_VBUS_MASK) 248#define bfin_read_USB_OTG_VBUS_MASK() bfin_read16(USB_OTG_VBUS_MASK)
249#define bfin_write_USB_OTG_VBUS_MASK(val) bfin_write16(USB_OTG_VBUS_MASK, val) 249#define bfin_write_USB_OTG_VBUS_MASK(val) bfin_write16(USB_OTG_VBUS_MASK, val)
250 250
diff --git a/include/asm-blackfin/mach-bf548/cdefBF544.h b/include/asm-blackfin/mach-bf548/cdefBF544.h
index 7a2d177c8dc2..ea9b4ab496f3 100644
--- a/include/asm-blackfin/mach-bf548/cdefBF544.h
+++ b/include/asm-blackfin/mach-bf548/cdefBF544.h
@@ -113,39 +113,6 @@
113 113
114/* Two Wire Interface Registers (TWI1) */ 114/* Two Wire Interface Registers (TWI1) */
115 115
116#define bfin_read_TWI1_CLKDIV() bfin_read16(TWI1_CLKDIV)
117#define bfin_write_TWI1_CLKDIV(val) bfin_write16(TWI1_CLKDIV, val)
118#define bfin_read_TWI1_CONTROL() bfin_read16(TWI1_CONTROL)
119#define bfin_write_TWI1_CONTROL(val) bfin_write16(TWI1_CONTROL, val)
120#define bfin_read_TWI1_SLAVE_CTRL() bfin_read16(TWI1_SLAVE_CTRL)
121#define bfin_write_TWI1_SLAVE_CTRL(val) bfin_write16(TWI1_SLAVE_CTRL, val)
122#define bfin_read_TWI1_SLAVE_STAT() bfin_read16(TWI1_SLAVE_STAT)
123#define bfin_write_TWI1_SLAVE_STAT(val) bfin_write16(TWI1_SLAVE_STAT, val)
124#define bfin_read_TWI1_SLAVE_ADDR() bfin_read16(TWI1_SLAVE_ADDR)
125#define bfin_write_TWI1_SLAVE_ADDR(val) bfin_write16(TWI1_SLAVE_ADDR, val)
126#define bfin_read_TWI1_MASTER_CTRL() bfin_read16(TWI1_MASTER_CTRL)
127#define bfin_write_TWI1_MASTER_CTRL(val) bfin_write16(TWI1_MASTER_CTRL, val)
128#define bfin_read_TWI1_MASTER_STAT() bfin_read16(TWI1_MASTER_STAT)
129#define bfin_write_TWI1_MASTER_STAT(val) bfin_write16(TWI1_MASTER_STAT, val)
130#define bfin_read_TWI1_MASTER_ADDR() bfin_read16(TWI1_MASTER_ADDR)
131#define bfin_write_TWI1_MASTER_ADDR(val) bfin_write16(TWI1_MASTER_ADDR, val)
132#define bfin_read_TWI1_INT_STAT() bfin_read16(TWI1_INT_STAT)
133#define bfin_write_TWI1_INT_STAT(val) bfin_write16(TWI1_INT_STAT, val)
134#define bfin_read_TWI1_INT_MASK() bfin_read16(TWI1_INT_MASK)
135#define bfin_write_TWI1_INT_MASK(val) bfin_write16(TWI1_INT_MASK, val)
136#define bfin_read_TWI1_FIFO_CTRL() bfin_read16(TWI1_FIFO_CTRL)
137#define bfin_write_TWI1_FIFO_CTRL(val) bfin_write16(TWI1_FIFO_CTRL, val)
138#define bfin_read_TWI1_FIFO_STAT() bfin_read16(TWI1_FIFO_STAT)
139#define bfin_write_TWI1_FIFO_STAT(val) bfin_write16(TWI1_FIFO_STAT, val)
140#define bfin_read_TWI1_XMT_DATA8() bfin_read16(TWI1_XMT_DATA8)
141#define bfin_write_TWI1_XMT_DATA8(val) bfin_write16(TWI1_XMT_DATA8, val)
142#define bfin_read_TWI1_XMT_DATA16() bfin_read16(TWI1_XMT_DATA16)
143#define bfin_write_TWI1_XMT_DATA16(val) bfin_write16(TWI1_XMT_DATA16, val)
144#define bfin_read_TWI1_RCV_DATA8() bfin_read16(TWI1_RCV_DATA8)
145#define bfin_write_TWI1_RCV_DATA8(val) bfin_write16(TWI1_RCV_DATA8, val)
146#define bfin_read_TWI1_RCV_DATA16() bfin_read16(TWI1_RCV_DATA16)
147#define bfin_write_TWI1_RCV_DATA16(val) bfin_write16(TWI1_RCV_DATA16, val)
148
149/* CAN Controller 1 Config 1 Registers */ 116/* CAN Controller 1 Config 1 Registers */
150 117
151#define bfin_read_CAN1_MC1() bfin_read16(CAN1_MC1) 118#define bfin_read_CAN1_MC1() bfin_read16(CAN1_MC1)
diff --git a/include/asm-blackfin/mach-bf548/cdefBF547.h b/include/asm-blackfin/mach-bf548/cdefBF547.h
index d0a200b08abd..ba716277c00d 100644
--- a/include/asm-blackfin/mach-bf548/cdefBF547.h
+++ b/include/asm-blackfin/mach-bf548/cdefBF547.h
@@ -185,39 +185,6 @@
185 185
186/* Two Wire Interface Registers (TWI1) */ 186/* Two Wire Interface Registers (TWI1) */
187 187
188#define bfin_read_TWI1_CLKDIV() bfin_read16(TWI1_CLKDIV)
189#define bfin_write_TWI1_CLKDIV(val) bfin_write16(TWI1_CLKDIV, val)
190#define bfin_read_TWI1_CONTROL() bfin_read16(TWI1_CONTROL)
191#define bfin_write_TWI1_CONTROL(val) bfin_write16(TWI1_CONTROL, val)
192#define bfin_read_TWI1_SLAVE_CTRL() bfin_read16(TWI1_SLAVE_CTRL)
193#define bfin_write_TWI1_SLAVE_CTRL(val) bfin_write16(TWI1_SLAVE_CTRL, val)
194#define bfin_read_TWI1_SLAVE_STAT() bfin_read16(TWI1_SLAVE_STAT)
195#define bfin_write_TWI1_SLAVE_STAT(val) bfin_write16(TWI1_SLAVE_STAT, val)
196#define bfin_read_TWI1_SLAVE_ADDR() bfin_read16(TWI1_SLAVE_ADDR)
197#define bfin_write_TWI1_SLAVE_ADDR(val) bfin_write16(TWI1_SLAVE_ADDR, val)
198#define bfin_read_TWI1_MASTER_CTRL() bfin_read16(TWI1_MASTER_CTRL)
199#define bfin_write_TWI1_MASTER_CTRL(val) bfin_write16(TWI1_MASTER_CTRL, val)
200#define bfin_read_TWI1_MASTER_STAT() bfin_read16(TWI1_MASTER_STAT)
201#define bfin_write_TWI1_MASTER_STAT(val) bfin_write16(TWI1_MASTER_STAT, val)
202#define bfin_read_TWI1_MASTER_ADDR() bfin_read16(TWI1_MASTER_ADDR)
203#define bfin_write_TWI1_MASTER_ADDR(val) bfin_write16(TWI1_MASTER_ADDR, val)
204#define bfin_read_TWI1_INT_STAT() bfin_read16(TWI1_INT_STAT)
205#define bfin_write_TWI1_INT_STAT(val) bfin_write16(TWI1_INT_STAT, val)
206#define bfin_read_TWI1_INT_MASK() bfin_read16(TWI1_INT_MASK)
207#define bfin_write_TWI1_INT_MASK(val) bfin_write16(TWI1_INT_MASK, val)
208#define bfin_read_TWI1_FIFO_CTRL() bfin_read16(TWI1_FIFO_CTRL)
209#define bfin_write_TWI1_FIFO_CTRL(val) bfin_write16(TWI1_FIFO_CTRL, val)
210#define bfin_read_TWI1_FIFO_STAT() bfin_read16(TWI1_FIFO_STAT)
211#define bfin_write_TWI1_FIFO_STAT(val) bfin_write16(TWI1_FIFO_STAT, val)
212#define bfin_read_TWI1_XMT_DATA8() bfin_read16(TWI1_XMT_DATA8)
213#define bfin_write_TWI1_XMT_DATA8(val) bfin_write16(TWI1_XMT_DATA8, val)
214#define bfin_read_TWI1_XMT_DATA16() bfin_read16(TWI1_XMT_DATA16)
215#define bfin_write_TWI1_XMT_DATA16(val) bfin_write16(TWI1_XMT_DATA16, val)
216#define bfin_read_TWI1_RCV_DATA8() bfin_read16(TWI1_RCV_DATA8)
217#define bfin_write_TWI1_RCV_DATA8(val) bfin_write16(TWI1_RCV_DATA8, val)
218#define bfin_read_TWI1_RCV_DATA16() bfin_read16(TWI1_RCV_DATA16)
219#define bfin_write_TWI1_RCV_DATA16(val) bfin_write16(TWI1_RCV_DATA16, val)
220
221/* SPI2 Registers */ 188/* SPI2 Registers */
222 189
223#define bfin_read_SPI2_CTL() bfin_read16(SPI2_CTL) 190#define bfin_read_SPI2_CTL() bfin_read16(SPI2_CTL)
diff --git a/include/asm-blackfin/mach-bf548/cdefBF548.h b/include/asm-blackfin/mach-bf548/cdefBF548.h
index 674be0216bff..ae971ebff6a0 100644
--- a/include/asm-blackfin/mach-bf548/cdefBF548.h
+++ b/include/asm-blackfin/mach-bf548/cdefBF548.h
@@ -185,39 +185,6 @@
185 185
186/* Two Wire Interface Registers (TWI1) */ 186/* Two Wire Interface Registers (TWI1) */
187 187
188#define bfin_read_TWI1_CLKDIV() bfin_read16(TWI1_CLKDIV)
189#define bfin_write_TWI1_CLKDIV(val) bfin_write16(TWI1_CLKDIV, val)
190#define bfin_read_TWI1_CONTROL() bfin_read16(TWI1_CONTROL)
191#define bfin_write_TWI1_CONTROL(val) bfin_write16(TWI1_CONTROL, val)
192#define bfin_read_TWI1_SLAVE_CTRL() bfin_read16(TWI1_SLAVE_CTRL)
193#define bfin_write_TWI1_SLAVE_CTRL(val) bfin_write16(TWI1_SLAVE_CTRL, val)
194#define bfin_read_TWI1_SLAVE_STAT() bfin_read16(TWI1_SLAVE_STAT)
195#define bfin_write_TWI1_SLAVE_STAT(val) bfin_write16(TWI1_SLAVE_STAT, val)
196#define bfin_read_TWI1_SLAVE_ADDR() bfin_read16(TWI1_SLAVE_ADDR)
197#define bfin_write_TWI1_SLAVE_ADDR(val) bfin_write16(TWI1_SLAVE_ADDR, val)
198#define bfin_read_TWI1_MASTER_CTRL() bfin_read16(TWI1_MASTER_CTRL)
199#define bfin_write_TWI1_MASTER_CTRL(val) bfin_write16(TWI1_MASTER_CTRL, val)
200#define bfin_read_TWI1_MASTER_STAT() bfin_read16(TWI1_MASTER_STAT)
201#define bfin_write_TWI1_MASTER_STAT(val) bfin_write16(TWI1_MASTER_STAT, val)
202#define bfin_read_TWI1_MASTER_ADDR() bfin_read16(TWI1_MASTER_ADDR)
203#define bfin_write_TWI1_MASTER_ADDR(val) bfin_write16(TWI1_MASTER_ADDR, val)
204#define bfin_read_TWI1_INT_STAT() bfin_read16(TWI1_INT_STAT)
205#define bfin_write_TWI1_INT_STAT(val) bfin_write16(TWI1_INT_STAT, val)
206#define bfin_read_TWI1_INT_MASK() bfin_read16(TWI1_INT_MASK)
207#define bfin_write_TWI1_INT_MASK(val) bfin_write16(TWI1_INT_MASK, val)
208#define bfin_read_TWI1_FIFO_CTRL() bfin_read16(TWI1_FIFO_CTRL)
209#define bfin_write_TWI1_FIFO_CTRL(val) bfin_write16(TWI1_FIFO_CTRL, val)
210#define bfin_read_TWI1_FIFO_STAT() bfin_read16(TWI1_FIFO_STAT)
211#define bfin_write_TWI1_FIFO_STAT(val) bfin_write16(TWI1_FIFO_STAT, val)
212#define bfin_read_TWI1_XMT_DATA8() bfin_read16(TWI1_XMT_DATA8)
213#define bfin_write_TWI1_XMT_DATA8(val) bfin_write16(TWI1_XMT_DATA8, val)
214#define bfin_read_TWI1_XMT_DATA16() bfin_read16(TWI1_XMT_DATA16)
215#define bfin_write_TWI1_XMT_DATA16(val) bfin_write16(TWI1_XMT_DATA16, val)
216#define bfin_read_TWI1_RCV_DATA8() bfin_read16(TWI1_RCV_DATA8)
217#define bfin_write_TWI1_RCV_DATA8(val) bfin_write16(TWI1_RCV_DATA8, val)
218#define bfin_read_TWI1_RCV_DATA16() bfin_read16(TWI1_RCV_DATA16)
219#define bfin_write_TWI1_RCV_DATA16(val) bfin_write16(TWI1_RCV_DATA16, val)
220
221/* SPI2 Registers */ 188/* SPI2 Registers */
222 189
223#define bfin_read_SPI2_CTL() bfin_read16(SPI2_CTL) 190#define bfin_read_SPI2_CTL() bfin_read16(SPI2_CTL)
diff --git a/include/asm-blackfin/mach-bf548/cdefBF549.h b/include/asm-blackfin/mach-bf548/cdefBF549.h
index 2ab5b7c00820..92d07d961999 100644
--- a/include/asm-blackfin/mach-bf548/cdefBF549.h
+++ b/include/asm-blackfin/mach-bf548/cdefBF549.h
@@ -185,39 +185,6 @@
185 185
186/* Two Wire Interface Registers (TWI1) */ 186/* Two Wire Interface Registers (TWI1) */
187 187
188#define bfin_read_TWI1_CLKDIV() bfin_read16(TWI1_CLKDIV)
189#define bfin_write_TWI1_CLKDIV(val) bfin_write16(TWI1_CLKDIV, val)
190#define bfin_read_TWI1_CONTROL() bfin_read16(TWI1_CONTROL)
191#define bfin_write_TWI1_CONTROL(val) bfin_write16(TWI1_CONTROL, val)
192#define bfin_read_TWI1_SLAVE_CTRL() bfin_read16(TWI1_SLAVE_CTRL)
193#define bfin_write_TWI1_SLAVE_CTRL(val) bfin_write16(TWI1_SLAVE_CTRL, val)
194#define bfin_read_TWI1_SLAVE_STAT() bfin_read16(TWI1_SLAVE_STAT)
195#define bfin_write_TWI1_SLAVE_STAT(val) bfin_write16(TWI1_SLAVE_STAT, val)
196#define bfin_read_TWI1_SLAVE_ADDR() bfin_read16(TWI1_SLAVE_ADDR)
197#define bfin_write_TWI1_SLAVE_ADDR(val) bfin_write16(TWI1_SLAVE_ADDR, val)
198#define bfin_read_TWI1_MASTER_CTRL() bfin_read16(TWI1_MASTER_CTRL)
199#define bfin_write_TWI1_MASTER_CTRL(val) bfin_write16(TWI1_MASTER_CTRL, val)
200#define bfin_read_TWI1_MASTER_STAT() bfin_read16(TWI1_MASTER_STAT)
201#define bfin_write_TWI1_MASTER_STAT(val) bfin_write16(TWI1_MASTER_STAT, val)
202#define bfin_read_TWI1_MASTER_ADDR() bfin_read16(TWI1_MASTER_ADDR)
203#define bfin_write_TWI1_MASTER_ADDR(val) bfin_write16(TWI1_MASTER_ADDR, val)
204#define bfin_read_TWI1_INT_STAT() bfin_read16(TWI1_INT_STAT)
205#define bfin_write_TWI1_INT_STAT(val) bfin_write16(TWI1_INT_STAT, val)
206#define bfin_read_TWI1_INT_MASK() bfin_read16(TWI1_INT_MASK)
207#define bfin_write_TWI1_INT_MASK(val) bfin_write16(TWI1_INT_MASK, val)
208#define bfin_read_TWI1_FIFO_CTRL() bfin_read16(TWI1_FIFO_CTRL)
209#define bfin_write_TWI1_FIFO_CTRL(val) bfin_write16(TWI1_FIFO_CTRL, val)
210#define bfin_read_TWI1_FIFO_STAT() bfin_read16(TWI1_FIFO_STAT)
211#define bfin_write_TWI1_FIFO_STAT(val) bfin_write16(TWI1_FIFO_STAT, val)
212#define bfin_read_TWI1_XMT_DATA8() bfin_read16(TWI1_XMT_DATA8)
213#define bfin_write_TWI1_XMT_DATA8(val) bfin_write16(TWI1_XMT_DATA8, val)
214#define bfin_read_TWI1_XMT_DATA16() bfin_read16(TWI1_XMT_DATA16)
215#define bfin_write_TWI1_XMT_DATA16(val) bfin_write16(TWI1_XMT_DATA16, val)
216#define bfin_read_TWI1_RCV_DATA8() bfin_read16(TWI1_RCV_DATA8)
217#define bfin_write_TWI1_RCV_DATA8(val) bfin_write16(TWI1_RCV_DATA8, val)
218#define bfin_read_TWI1_RCV_DATA16() bfin_read16(TWI1_RCV_DATA16)
219#define bfin_write_TWI1_RCV_DATA16(val) bfin_write16(TWI1_RCV_DATA16, val)
220
221/* SPI2 Registers */ 188/* SPI2 Registers */
222 189
223#define bfin_read_SPI2_CTL() bfin_read16(SPI2_CTL) 190#define bfin_read_SPI2_CTL() bfin_read16(SPI2_CTL)
@@ -1773,7 +1740,7 @@
1773#define bfin_read_USB_DMA5ADDRHIGH() bfin_read16(USB_DMA5ADDRHIGH) 1740#define bfin_read_USB_DMA5ADDRHIGH() bfin_read16(USB_DMA5ADDRHIGH)
1774#define bfin_write_USB_DMA5ADDRHIGH(val) bfin_write16(USB_DMA5ADDRHIGH, val) 1741#define bfin_write_USB_DMA5ADDRHIGH(val) bfin_write16(USB_DMA5ADDRHIGH, val)
1775#define bfin_read_USB_DMA5COUNTLOW() bfin_read16(USB_DMA5COUNTLOW) 1742#define bfin_read_USB_DMA5COUNTLOW() bfin_read16(USB_DMA5COUNTLOW)
1776#define bfin_write_USB_DMA5COUNTLOW(val) fin_write16(USB_DMA5COUNTLOW, val) 1743#define bfin_write_USB_DMA5COUNTLOW(val) bfin_write16(USB_DMA5COUNTLOW, val)
1777#define bfin_read_USB_DMA5COUNTHIGH() bfin_read16(USB_DMA5COUNTHIGH) 1744#define bfin_read_USB_DMA5COUNTHIGH() bfin_read16(USB_DMA5COUNTHIGH)
1778#define bfin_write_USB_DMA5COUNTHIGH(val) bfin_write16(USB_DMA5COUNTHIGH, val) 1745#define bfin_write_USB_DMA5COUNTHIGH(val) bfin_write16(USB_DMA5COUNTHIGH, val)
1779 1746
diff --git a/include/asm-blackfin/mach-bf548/cdefBF54x_base.h b/include/asm-blackfin/mach-bf548/cdefBF54x_base.h
index 19ddcd83c71f..57ac8cb9b1f6 100644
--- a/include/asm-blackfin/mach-bf548/cdefBF54x_base.h
+++ b/include/asm-blackfin/mach-bf548/cdefBF54x_base.h
@@ -43,7 +43,33 @@
43/* PLL Registers */ 43/* PLL Registers */
44 44
45#define bfin_read_PLL_CTL() bfin_read16(PLL_CTL) 45#define bfin_read_PLL_CTL() bfin_read16(PLL_CTL)
46#define bfin_write_PLL_CTL(val) bfin_write16(PLL_CTL, val) 46/* Writing to PLL_CTL initiates a PLL relock sequence. */
47static __inline__ void bfin_write_PLL_CTL(unsigned int val)
48{
49 unsigned long flags, iwr0, iwr1, iwr2;
50
51 if (val == bfin_read_PLL_CTL())
52 return;
53
54 local_irq_save(flags);
55 /* Enable the PLL Wakeup bit in SIC IWR */
56 iwr0 = bfin_read32(SIC_IWR0);
57 iwr1 = bfin_read32(SIC_IWR1);
58 iwr2 = bfin_read32(SIC_IWR2);
59 /* Only allow PPL Wakeup) */
60 bfin_write32(SIC_IWR0, IWR_ENABLE(0));
61 bfin_write32(SIC_IWR1, 0);
62 bfin_write32(SIC_IWR2, 0);
63
64 bfin_write16(PLL_CTL, val);
65 SSYNC();
66 asm("IDLE;");
67
68 bfin_write32(SIC_IWR0, iwr0);
69 bfin_write32(SIC_IWR1, iwr1);
70 bfin_write32(SIC_IWR2, iwr2);
71 local_irq_restore(flags);
72}
47#define bfin_read_PLL_DIV() bfin_read16(PLL_DIV) 73#define bfin_read_PLL_DIV() bfin_read16(PLL_DIV)
48#define bfin_write_PLL_DIV(val) bfin_write16(PLL_DIV, val) 74#define bfin_write_PLL_DIV(val) bfin_write16(PLL_DIV, val)
49#define bfin_read_VR_CTL() bfin_read16(VR_CTL) 75#define bfin_read_VR_CTL() bfin_read16(VR_CTL)
@@ -52,6 +78,10 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
52{ 78{
53 unsigned long flags, iwr0, iwr1, iwr2; 79 unsigned long flags, iwr0, iwr1, iwr2;
54 80
81 if (val == bfin_read_VR_CTL())
82 return;
83
84 local_irq_save(flags);
55 /* Enable the PLL Wakeup bit in SIC IWR */ 85 /* Enable the PLL Wakeup bit in SIC IWR */
56 iwr0 = bfin_read32(SIC_IWR0); 86 iwr0 = bfin_read32(SIC_IWR0);
57 iwr1 = bfin_read32(SIC_IWR1); 87 iwr1 = bfin_read32(SIC_IWR1);
@@ -63,13 +93,12 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
63 93
64 bfin_write16(VR_CTL, val); 94 bfin_write16(VR_CTL, val);
65 SSYNC(); 95 SSYNC();
66
67 local_irq_save(flags);
68 asm("IDLE;"); 96 asm("IDLE;");
69 local_irq_restore(flags); 97
70 bfin_write32(SIC_IWR0, iwr0); 98 bfin_write32(SIC_IWR0, iwr0);
71 bfin_write32(SIC_IWR1, iwr1); 99 bfin_write32(SIC_IWR1, iwr1);
72 bfin_write32(SIC_IWR2, iwr2); 100 bfin_write32(SIC_IWR2, iwr2);
101 local_irq_restore(flags);
73} 102}
74#define bfin_read_PLL_STAT() bfin_read16(PLL_STAT) 103#define bfin_read_PLL_STAT() bfin_read16(PLL_STAT)
75#define bfin_write_PLL_STAT(val) bfin_write16(PLL_STAT, val) 104#define bfin_write_PLL_STAT(val) bfin_write16(PLL_STAT, val)
@@ -211,39 +240,6 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
211 240
212/* Two Wire Interface Registers (TWI0) */ 241/* Two Wire Interface Registers (TWI0) */
213 242
214#define bfin_read_TWI0_CLKDIV() bfin_read16(TWI0_CLKDIV)
215#define bfin_write_TWI0_CLKDIV(val) bfin_write16(TWI0_CLKDIV, val)
216#define bfin_read_TWI0_CONTROL() bfin_read16(TWI0_CONTROL)
217#define bfin_write_TWI0_CONTROL(val) bfin_write16(TWI0_CONTROL, val)
218#define bfin_read_TWI0_SLAVE_CTRL() bfin_read16(TWI0_SLAVE_CTRL)
219#define bfin_write_TWI0_SLAVE_CTRL(val) bfin_write16(TWI0_SLAVE_CTRL, val)
220#define bfin_read_TWI0_SLAVE_STAT() bfin_read16(TWI0_SLAVE_STAT)
221#define bfin_write_TWI0_SLAVE_STAT(val) bfin_write16(TWI0_SLAVE_STAT, val)
222#define bfin_read_TWI0_SLAVE_ADDR() bfin_read16(TWI0_SLAVE_ADDR)
223#define bfin_write_TWI0_SLAVE_ADDR(val) bfin_write16(TWI0_SLAVE_ADDR, val)
224#define bfin_read_TWI0_MASTER_CTRL() bfin_read16(TWI0_MASTER_CTRL)
225#define bfin_write_TWI0_MASTER_CTRL(val) bfin_write16(TWI0_MASTER_CTRL, val)
226#define bfin_read_TWI0_MASTER_STAT() bfin_read16(TWI0_MASTER_STAT)
227#define bfin_write_TWI0_MASTER_STAT(val) bfin_write16(TWI0_MASTER_STAT, val)
228#define bfin_read_TWI0_MASTER_ADDR() bfin_read16(TWI0_MASTER_ADDR)
229#define bfin_write_TWI0_MASTER_ADDR(val) bfin_write16(TWI0_MASTER_ADDR, val)
230#define bfin_read_TWI0_INT_STAT() bfin_read16(TWI0_INT_STAT)
231#define bfin_write_TWI0_INT_STAT(val) bfin_write16(TWI0_INT_STAT, val)
232#define bfin_read_TWI0_INT_MASK() bfin_read16(TWI0_INT_MASK)
233#define bfin_write_TWI0_INT_MASK(val) bfin_write16(TWI0_INT_MASK, val)
234#define bfin_read_TWI0_FIFO_CTRL() bfin_read16(TWI0_FIFO_CTRL)
235#define bfin_write_TWI0_FIFO_CTRL(val) bfin_write16(TWI0_FIFO_CTRL, val)
236#define bfin_read_TWI0_FIFO_STAT() bfin_read16(TWI0_FIFO_STAT)
237#define bfin_write_TWI0_FIFO_STAT(val) bfin_write16(TWI0_FIFO_STAT, val)
238#define bfin_read_TWI0_XMT_DATA8() bfin_read16(TWI0_XMT_DATA8)
239#define bfin_write_TWI0_XMT_DATA8(val) bfin_write16(TWI0_XMT_DATA8, val)
240#define bfin_read_TWI0_XMT_DATA16() bfin_read16(TWI0_XMT_DATA16)
241#define bfin_write_TWI0_XMT_DATA16(val) bfin_write16(TWI0_XMT_DATA16, val)
242#define bfin_read_TWI0_RCV_DATA8() bfin_read16(TWI0_RCV_DATA8)
243#define bfin_write_TWI0_RCV_DATA8(val) bfin_write16(TWI0_RCV_DATA8, val)
244#define bfin_read_TWI0_RCV_DATA16() bfin_read16(TWI0_RCV_DATA16)
245#define bfin_write_TWI0_RCV_DATA16(val) bfin_write16(TWI0_RCV_DATA16, val)
246
247/* SPORT0 is not defined in the shared file because it is not available on the ADSP-BF542 and ADSP-BF544 bfin_read_()rocessors */ 243/* SPORT0 is not defined in the shared file because it is not available on the ADSP-BF542 and ADSP-BF544 bfin_read_()rocessors */
248 244
249/* SPORT1 Registers */ 245/* SPORT1 Registers */
@@ -323,7 +319,7 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
323#define bfin_read_EBIU_DDRQUE() bfin_read32(EBIU_DDRQUE) 319#define bfin_read_EBIU_DDRQUE() bfin_read32(EBIU_DDRQUE)
324#define bfin_write_EBIU_DDRQUE(val) bfin_write32(EBIU_DDRQUE, val) 320#define bfin_write_EBIU_DDRQUE(val) bfin_write32(EBIU_DDRQUE, val)
325#define bfin_read_EBIU_ERRADD() bfin_read32(EBIU_ERRADD) 321#define bfin_read_EBIU_ERRADD() bfin_read32(EBIU_ERRADD)
326#define bfin_write_EBIU_ERRADD(val) bfin_write32(EBIU_ERRADD) 322#define bfin_write_EBIU_ERRADD(val) bfin_write32(EBIU_ERRADD, val)
327#define bfin_read_EBIU_ERRMST() bfin_read16(EBIU_ERRMST) 323#define bfin_read_EBIU_ERRMST() bfin_read16(EBIU_ERRMST)
328#define bfin_write_EBIU_ERRMST(val) bfin_write16(EBIU_ERRMST, val) 324#define bfin_write_EBIU_ERRMST(val) bfin_write16(EBIU_ERRMST, val)
329#define bfin_read_EBIU_RSTCTL() bfin_read16(EBIU_RSTCTL) 325#define bfin_read_EBIU_RSTCTL() bfin_read16(EBIU_RSTCTL)
@@ -392,23 +388,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
392/* DMA Channel 0 Registers */ 388/* DMA Channel 0 Registers */
393 389
394#define bfin_read_DMA0_NEXT_DESC_PTR() bfin_read32(DMA0_NEXT_DESC_PTR) 390#define bfin_read_DMA0_NEXT_DESC_PTR() bfin_read32(DMA0_NEXT_DESC_PTR)
395#define bfin_write_DMA0_NEXT_DESC_PTR(val) bfin_write32(DMA0_NEXT_DESC_PTR) 391#define bfin_write_DMA0_NEXT_DESC_PTR(val) bfin_write32(DMA0_NEXT_DESC_PTR, val)
396#define bfin_read_DMA0_START_ADDR() bfin_read32(DMA0_START_ADDR) 392#define bfin_read_DMA0_START_ADDR() bfin_read32(DMA0_START_ADDR)
397#define bfin_write_DMA0_START_ADDR(val) bfin_write32(DMA0_START_ADDR) 393#define bfin_write_DMA0_START_ADDR(val) bfin_write32(DMA0_START_ADDR, val)
398#define bfin_read_DMA0_CONFIG() bfin_read16(DMA0_CONFIG) 394#define bfin_read_DMA0_CONFIG() bfin_read16(DMA0_CONFIG)
399#define bfin_write_DMA0_CONFIG(val) bfin_write16(DMA0_CONFIG, val) 395#define bfin_write_DMA0_CONFIG(val) bfin_write16(DMA0_CONFIG, val)
400#define bfin_read_DMA0_X_COUNT() bfin_read16(DMA0_X_COUNT) 396#define bfin_read_DMA0_X_COUNT() bfin_read16(DMA0_X_COUNT)
401#define bfin_write_DMA0_X_COUNT(val) bfin_write16(DMA0_X_COUNT, val) 397#define bfin_write_DMA0_X_COUNT(val) bfin_write16(DMA0_X_COUNT, val)
402#define bfin_read_DMA0_X_MODIFY() bfin_read16(DMA0_X_MODIFY) 398#define bfin_read_DMA0_X_MODIFY() bfin_read16(DMA0_X_MODIFY)
403#define bfin_write_DMA0_X_MODIFY(val) bfin_write16(DMA0_X_MODIFY) 399#define bfin_write_DMA0_X_MODIFY(val) bfin_write16(DMA0_X_MODIFY, val)
404#define bfin_read_DMA0_Y_COUNT() bfin_read16(DMA0_Y_COUNT) 400#define bfin_read_DMA0_Y_COUNT() bfin_read16(DMA0_Y_COUNT)
405#define bfin_write_DMA0_Y_COUNT(val) bfin_write16(DMA0_Y_COUNT, val) 401#define bfin_write_DMA0_Y_COUNT(val) bfin_write16(DMA0_Y_COUNT, val)
406#define bfin_read_DMA0_Y_MODIFY() bfin_read16(DMA0_Y_MODIFY) 402#define bfin_read_DMA0_Y_MODIFY() bfin_read16(DMA0_Y_MODIFY)
407#define bfin_write_DMA0_Y_MODIFY(val) bfin_write16(DMA0_Y_MODIFY) 403#define bfin_write_DMA0_Y_MODIFY(val) bfin_write16(DMA0_Y_MODIFY, val)
408#define bfin_read_DMA0_CURR_DESC_PTR() bfin_read32(DMA0_CURR_DESC_PTR) 404#define bfin_read_DMA0_CURR_DESC_PTR() bfin_read32(DMA0_CURR_DESC_PTR)
409#define bfin_write_DMA0_CURR_DESC_PTR(val) bfin_write32(DMA0_CURR_DESC_PTR) 405#define bfin_write_DMA0_CURR_DESC_PTR(val) bfin_write32(DMA0_CURR_DESC_PTR, val)
410#define bfin_read_DMA0_CURR_ADDR() bfin_read32(DMA0_CURR_ADDR) 406#define bfin_read_DMA0_CURR_ADDR() bfin_read32(DMA0_CURR_ADDR)
411#define bfin_write_DMA0_CURR_ADDR(val) bfin_write32(DMA0_CURR_ADDR) 407#define bfin_write_DMA0_CURR_ADDR(val) bfin_write32(DMA0_CURR_ADDR, val)
412#define bfin_read_DMA0_IRQ_STATUS() bfin_read16(DMA0_IRQ_STATUS) 408#define bfin_read_DMA0_IRQ_STATUS() bfin_read16(DMA0_IRQ_STATUS)
413#define bfin_write_DMA0_IRQ_STATUS(val) bfin_write16(DMA0_IRQ_STATUS, val) 409#define bfin_write_DMA0_IRQ_STATUS(val) bfin_write16(DMA0_IRQ_STATUS, val)
414#define bfin_read_DMA0_PERIPHERAL_MAP() bfin_read16(DMA0_PERIPHERAL_MAP) 410#define bfin_read_DMA0_PERIPHERAL_MAP() bfin_read16(DMA0_PERIPHERAL_MAP)
@@ -421,23 +417,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
421/* DMA Channel 1 Registers */ 417/* DMA Channel 1 Registers */
422 418
423#define bfin_read_DMA1_NEXT_DESC_PTR() bfin_read32(DMA1_NEXT_DESC_PTR) 419#define bfin_read_DMA1_NEXT_DESC_PTR() bfin_read32(DMA1_NEXT_DESC_PTR)
424#define bfin_write_DMA1_NEXT_DESC_PTR(val) bfin_write32(DMA1_NEXT_DESC_PTR) 420#define bfin_write_DMA1_NEXT_DESC_PTR(val) bfin_write32(DMA1_NEXT_DESC_PTR, val)
425#define bfin_read_DMA1_START_ADDR() bfin_read32(DMA1_START_ADDR) 421#define bfin_read_DMA1_START_ADDR() bfin_read32(DMA1_START_ADDR)
426#define bfin_write_DMA1_START_ADDR(val) bfin_write32(DMA1_START_ADDR) 422#define bfin_write_DMA1_START_ADDR(val) bfin_write32(DMA1_START_ADDR, val)
427#define bfin_read_DMA1_CONFIG() bfin_read16(DMA1_CONFIG) 423#define bfin_read_DMA1_CONFIG() bfin_read16(DMA1_CONFIG)
428#define bfin_write_DMA1_CONFIG(val) bfin_write16(DMA1_CONFIG, val) 424#define bfin_write_DMA1_CONFIG(val) bfin_write16(DMA1_CONFIG, val)
429#define bfin_read_DMA1_X_COUNT() bfin_read16(DMA1_X_COUNT) 425#define bfin_read_DMA1_X_COUNT() bfin_read16(DMA1_X_COUNT)
430#define bfin_write_DMA1_X_COUNT(val) bfin_write16(DMA1_X_COUNT, val) 426#define bfin_write_DMA1_X_COUNT(val) bfin_write16(DMA1_X_COUNT, val)
431#define bfin_read_DMA1_X_MODIFY() bfin_read16(DMA1_X_MODIFY) 427#define bfin_read_DMA1_X_MODIFY() bfin_read16(DMA1_X_MODIFY)
432#define bfin_write_DMA1_X_MODIFY(val) bfin_write16(DMA1_X_MODIFY) 428#define bfin_write_DMA1_X_MODIFY(val) bfin_write16(DMA1_X_MODIFY, val)
433#define bfin_read_DMA1_Y_COUNT() bfin_read16(DMA1_Y_COUNT) 429#define bfin_read_DMA1_Y_COUNT() bfin_read16(DMA1_Y_COUNT)
434#define bfin_write_DMA1_Y_COUNT(val) bfin_write16(DMA1_Y_COUNT, val) 430#define bfin_write_DMA1_Y_COUNT(val) bfin_write16(DMA1_Y_COUNT, val)
435#define bfin_read_DMA1_Y_MODIFY() bfin_read16(DMA1_Y_MODIFY) 431#define bfin_read_DMA1_Y_MODIFY() bfin_read16(DMA1_Y_MODIFY)
436#define bfin_write_DMA1_Y_MODIFY(val) bfin_write16(DMA1_Y_MODIFY) 432#define bfin_write_DMA1_Y_MODIFY(val) bfin_write16(DMA1_Y_MODIFY, val)
437#define bfin_read_DMA1_CURR_DESC_PTR() bfin_read32(DMA1_CURR_DESC_PTR) 433#define bfin_read_DMA1_CURR_DESC_PTR() bfin_read32(DMA1_CURR_DESC_PTR)
438#define bfin_write_DMA1_CURR_DESC_PTR(val) bfin_write32(DMA1_CURR_DESC_PTR) 434#define bfin_write_DMA1_CURR_DESC_PTR(val) bfin_write32(DMA1_CURR_DESC_PTR, val)
439#define bfin_read_DMA1_CURR_ADDR() bfin_read32(DMA1_CURR_ADDR) 435#define bfin_read_DMA1_CURR_ADDR() bfin_read32(DMA1_CURR_ADDR)
440#define bfin_write_DMA1_CURR_ADDR(val) bfin_write32(DMA1_CURR_ADDR) 436#define bfin_write_DMA1_CURR_ADDR(val) bfin_write32(DMA1_CURR_ADDR, val)
441#define bfin_read_DMA1_IRQ_STATUS() bfin_read16(DMA1_IRQ_STATUS) 437#define bfin_read_DMA1_IRQ_STATUS() bfin_read16(DMA1_IRQ_STATUS)
442#define bfin_write_DMA1_IRQ_STATUS(val) bfin_write16(DMA1_IRQ_STATUS, val) 438#define bfin_write_DMA1_IRQ_STATUS(val) bfin_write16(DMA1_IRQ_STATUS, val)
443#define bfin_read_DMA1_PERIPHERAL_MAP() bfin_read16(DMA1_PERIPHERAL_MAP) 439#define bfin_read_DMA1_PERIPHERAL_MAP() bfin_read16(DMA1_PERIPHERAL_MAP)
@@ -450,23 +446,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
450/* DMA Channel 2 Registers */ 446/* DMA Channel 2 Registers */
451 447
452#define bfin_read_DMA2_NEXT_DESC_PTR() bfin_read32(DMA2_NEXT_DESC_PTR) 448#define bfin_read_DMA2_NEXT_DESC_PTR() bfin_read32(DMA2_NEXT_DESC_PTR)
453#define bfin_write_DMA2_NEXT_DESC_PTR(val) bfin_write32(DMA2_NEXT_DESC_PTR) 449#define bfin_write_DMA2_NEXT_DESC_PTR(val) bfin_write32(DMA2_NEXT_DESC_PTR, val)
454#define bfin_read_DMA2_START_ADDR() bfin_read32(DMA2_START_ADDR) 450#define bfin_read_DMA2_START_ADDR() bfin_read32(DMA2_START_ADDR)
455#define bfin_write_DMA2_START_ADDR(val) bfin_write32(DMA2_START_ADDR) 451#define bfin_write_DMA2_START_ADDR(val) bfin_write32(DMA2_START_ADDR, val)
456#define bfin_read_DMA2_CONFIG() bfin_read16(DMA2_CONFIG) 452#define bfin_read_DMA2_CONFIG() bfin_read16(DMA2_CONFIG)
457#define bfin_write_DMA2_CONFIG(val) bfin_write16(DMA2_CONFIG, val) 453#define bfin_write_DMA2_CONFIG(val) bfin_write16(DMA2_CONFIG, val)
458#define bfin_read_DMA2_X_COUNT() bfin_read16(DMA2_X_COUNT) 454#define bfin_read_DMA2_X_COUNT() bfin_read16(DMA2_X_COUNT)
459#define bfin_write_DMA2_X_COUNT(val) bfin_write16(DMA2_X_COUNT, val) 455#define bfin_write_DMA2_X_COUNT(val) bfin_write16(DMA2_X_COUNT, val)
460#define bfin_read_DMA2_X_MODIFY() bfin_read16(DMA2_X_MODIFY) 456#define bfin_read_DMA2_X_MODIFY() bfin_read16(DMA2_X_MODIFY)
461#define bfin_write_DMA2_X_MODIFY(val) bfin_write16(DMA2_X_MODIFY) 457#define bfin_write_DMA2_X_MODIFY(val) bfin_write16(DMA2_X_MODIFY, val)
462#define bfin_read_DMA2_Y_COUNT() bfin_read16(DMA2_Y_COUNT) 458#define bfin_read_DMA2_Y_COUNT() bfin_read16(DMA2_Y_COUNT)
463#define bfin_write_DMA2_Y_COUNT(val) bfin_write16(DMA2_Y_COUNT, val) 459#define bfin_write_DMA2_Y_COUNT(val) bfin_write16(DMA2_Y_COUNT, val)
464#define bfin_read_DMA2_Y_MODIFY() bfin_read16(DMA2_Y_MODIFY) 460#define bfin_read_DMA2_Y_MODIFY() bfin_read16(DMA2_Y_MODIFY)
465#define bfin_write_DMA2_Y_MODIFY(val) bfin_write16(DMA2_Y_MODIFY) 461#define bfin_write_DMA2_Y_MODIFY(val) bfin_write16(DMA2_Y_MODIFY, val)
466#define bfin_read_DMA2_CURR_DESC_PTR() bfin_read32(DMA2_CURR_DESC_PTR) 462#define bfin_read_DMA2_CURR_DESC_PTR() bfin_read32(DMA2_CURR_DESC_PTR)
467#define bfin_write_DMA2_CURR_DESC_PTR(val) bfin_write32(DMA2_CURR_DESC_PTR) 463#define bfin_write_DMA2_CURR_DESC_PTR(val) bfin_write32(DMA2_CURR_DESC_PTR, val)
468#define bfin_read_DMA2_CURR_ADDR() bfin_read32(DMA2_CURR_ADDR) 464#define bfin_read_DMA2_CURR_ADDR() bfin_read32(DMA2_CURR_ADDR)
469#define bfin_write_DMA2_CURR_ADDR(val) bfin_write32(DMA2_CURR_ADDR) 465#define bfin_write_DMA2_CURR_ADDR(val) bfin_write32(DMA2_CURR_ADDR, val)
470#define bfin_read_DMA2_IRQ_STATUS() bfin_read16(DMA2_IRQ_STATUS) 466#define bfin_read_DMA2_IRQ_STATUS() bfin_read16(DMA2_IRQ_STATUS)
471#define bfin_write_DMA2_IRQ_STATUS(val) bfin_write16(DMA2_IRQ_STATUS, val) 467#define bfin_write_DMA2_IRQ_STATUS(val) bfin_write16(DMA2_IRQ_STATUS, val)
472#define bfin_read_DMA2_PERIPHERAL_MAP() bfin_read16(DMA2_PERIPHERAL_MAP) 468#define bfin_read_DMA2_PERIPHERAL_MAP() bfin_read16(DMA2_PERIPHERAL_MAP)
@@ -479,23 +475,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
479/* DMA Channel 3 Registers */ 475/* DMA Channel 3 Registers */
480 476
481#define bfin_read_DMA3_NEXT_DESC_PTR() bfin_read32(DMA3_NEXT_DESC_PTR) 477#define bfin_read_DMA3_NEXT_DESC_PTR() bfin_read32(DMA3_NEXT_DESC_PTR)
482#define bfin_write_DMA3_NEXT_DESC_PTR(val) bfin_write32(DMA3_NEXT_DESC_PTR) 478#define bfin_write_DMA3_NEXT_DESC_PTR(val) bfin_write32(DMA3_NEXT_DESC_PTR, val)
483#define bfin_read_DMA3_START_ADDR() bfin_read32(DMA3_START_ADDR) 479#define bfin_read_DMA3_START_ADDR() bfin_read32(DMA3_START_ADDR)
484#define bfin_write_DMA3_START_ADDR(val) bfin_write32(DMA3_START_ADDR) 480#define bfin_write_DMA3_START_ADDR(val) bfin_write32(DMA3_START_ADDR, val)
485#define bfin_read_DMA3_CONFIG() bfin_read16(DMA3_CONFIG) 481#define bfin_read_DMA3_CONFIG() bfin_read16(DMA3_CONFIG)
486#define bfin_write_DMA3_CONFIG(val) bfin_write16(DMA3_CONFIG, val) 482#define bfin_write_DMA3_CONFIG(val) bfin_write16(DMA3_CONFIG, val)
487#define bfin_read_DMA3_X_COUNT() bfin_read16(DMA3_X_COUNT) 483#define bfin_read_DMA3_X_COUNT() bfin_read16(DMA3_X_COUNT)
488#define bfin_write_DMA3_X_COUNT(val) bfin_write16(DMA3_X_COUNT, val) 484#define bfin_write_DMA3_X_COUNT(val) bfin_write16(DMA3_X_COUNT, val)
489#define bfin_read_DMA3_X_MODIFY() bfin_read16(DMA3_X_MODIFY) 485#define bfin_read_DMA3_X_MODIFY() bfin_read16(DMA3_X_MODIFY)
490#define bfin_write_DMA3_X_MODIFY(val) bfin_write16(DMA3_X_MODIFY) 486#define bfin_write_DMA3_X_MODIFY(val) bfin_write16(DMA3_X_MODIFY, val)
491#define bfin_read_DMA3_Y_COUNT() bfin_read16(DMA3_Y_COUNT) 487#define bfin_read_DMA3_Y_COUNT() bfin_read16(DMA3_Y_COUNT)
492#define bfin_write_DMA3_Y_COUNT(val) bfin_write16(DMA3_Y_COUNT, val) 488#define bfin_write_DMA3_Y_COUNT(val) bfin_write16(DMA3_Y_COUNT, val)
493#define bfin_read_DMA3_Y_MODIFY() bfin_read16(DMA3_Y_MODIFY) 489#define bfin_read_DMA3_Y_MODIFY() bfin_read16(DMA3_Y_MODIFY)
494#define bfin_write_DMA3_Y_MODIFY(val) bfin_write16(DMA3_Y_MODIFY) 490#define bfin_write_DMA3_Y_MODIFY(val) bfin_write16(DMA3_Y_MODIFY, val)
495#define bfin_read_DMA3_CURR_DESC_PTR() bfin_read32(DMA3_CURR_DESC_PTR) 491#define bfin_read_DMA3_CURR_DESC_PTR() bfin_read32(DMA3_CURR_DESC_PTR)
496#define bfin_write_DMA3_CURR_DESC_PTR(val) bfin_write32(DMA3_CURR_DESC_PTR) 492#define bfin_write_DMA3_CURR_DESC_PTR(val) bfin_write32(DMA3_CURR_DESC_PTR, val)
497#define bfin_read_DMA3_CURR_ADDR() bfin_read32(DMA3_CURR_ADDR) 493#define bfin_read_DMA3_CURR_ADDR() bfin_read32(DMA3_CURR_ADDR)
498#define bfin_write_DMA3_CURR_ADDR(val) bfin_write32(DMA3_CURR_ADDR) 494#define bfin_write_DMA3_CURR_ADDR(val) bfin_write32(DMA3_CURR_ADDR, val)
499#define bfin_read_DMA3_IRQ_STATUS() bfin_read16(DMA3_IRQ_STATUS) 495#define bfin_read_DMA3_IRQ_STATUS() bfin_read16(DMA3_IRQ_STATUS)
500#define bfin_write_DMA3_IRQ_STATUS(val) bfin_write16(DMA3_IRQ_STATUS, val) 496#define bfin_write_DMA3_IRQ_STATUS(val) bfin_write16(DMA3_IRQ_STATUS, val)
501#define bfin_read_DMA3_PERIPHERAL_MAP() bfin_read16(DMA3_PERIPHERAL_MAP) 497#define bfin_read_DMA3_PERIPHERAL_MAP() bfin_read16(DMA3_PERIPHERAL_MAP)
@@ -508,23 +504,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
508/* DMA Channel 4 Registers */ 504/* DMA Channel 4 Registers */
509 505
510#define bfin_read_DMA4_NEXT_DESC_PTR() bfin_read32(DMA4_NEXT_DESC_PTR) 506#define bfin_read_DMA4_NEXT_DESC_PTR() bfin_read32(DMA4_NEXT_DESC_PTR)
511#define bfin_write_DMA4_NEXT_DESC_PTR(val) bfin_write32(DMA4_NEXT_DESC_PTR) 507#define bfin_write_DMA4_NEXT_DESC_PTR(val) bfin_write32(DMA4_NEXT_DESC_PTR, val)
512#define bfin_read_DMA4_START_ADDR() bfin_read32(DMA4_START_ADDR) 508#define bfin_read_DMA4_START_ADDR() bfin_read32(DMA4_START_ADDR)
513#define bfin_write_DMA4_START_ADDR(val) bfin_write32(DMA4_START_ADDR) 509#define bfin_write_DMA4_START_ADDR(val) bfin_write32(DMA4_START_ADDR, val)
514#define bfin_read_DMA4_CONFIG() bfin_read16(DMA4_CONFIG) 510#define bfin_read_DMA4_CONFIG() bfin_read16(DMA4_CONFIG)
515#define bfin_write_DMA4_CONFIG(val) bfin_write16(DMA4_CONFIG, val) 511#define bfin_write_DMA4_CONFIG(val) bfin_write16(DMA4_CONFIG, val)
516#define bfin_read_DMA4_X_COUNT() bfin_read16(DMA4_X_COUNT) 512#define bfin_read_DMA4_X_COUNT() bfin_read16(DMA4_X_COUNT)
517#define bfin_write_DMA4_X_COUNT(val) bfin_write16(DMA4_X_COUNT, val) 513#define bfin_write_DMA4_X_COUNT(val) bfin_write16(DMA4_X_COUNT, val)
518#define bfin_read_DMA4_X_MODIFY() bfin_read16(DMA4_X_MODIFY) 514#define bfin_read_DMA4_X_MODIFY() bfin_read16(DMA4_X_MODIFY)
519#define bfin_write_DMA4_X_MODIFY(val) bfin_write16(DMA4_X_MODIFY) 515#define bfin_write_DMA4_X_MODIFY(val) bfin_write16(DMA4_X_MODIFY, val)
520#define bfin_read_DMA4_Y_COUNT() bfin_read16(DMA4_Y_COUNT) 516#define bfin_read_DMA4_Y_COUNT() bfin_read16(DMA4_Y_COUNT)
521#define bfin_write_DMA4_Y_COUNT(val) bfin_write16(DMA4_Y_COUNT, val) 517#define bfin_write_DMA4_Y_COUNT(val) bfin_write16(DMA4_Y_COUNT, val)
522#define bfin_read_DMA4_Y_MODIFY() bfin_read16(DMA4_Y_MODIFY) 518#define bfin_read_DMA4_Y_MODIFY() bfin_read16(DMA4_Y_MODIFY)
523#define bfin_write_DMA4_Y_MODIFY(val) bfin_write16(DMA4_Y_MODIFY) 519#define bfin_write_DMA4_Y_MODIFY(val) bfin_write16(DMA4_Y_MODIFY, val)
524#define bfin_read_DMA4_CURR_DESC_PTR() bfin_read32(DMA4_CURR_DESC_PTR) 520#define bfin_read_DMA4_CURR_DESC_PTR() bfin_read32(DMA4_CURR_DESC_PTR)
525#define bfin_write_DMA4_CURR_DESC_PTR(val) bfin_write32(DMA4_CURR_DESC_PTR) 521#define bfin_write_DMA4_CURR_DESC_PTR(val) bfin_write32(DMA4_CURR_DESC_PTR, val)
526#define bfin_read_DMA4_CURR_ADDR() bfin_read32(DMA4_CURR_ADDR) 522#define bfin_read_DMA4_CURR_ADDR() bfin_read32(DMA4_CURR_ADDR)
527#define bfin_write_DMA4_CURR_ADDR(val) bfin_write32(DMA4_CURR_ADDR) 523#define bfin_write_DMA4_CURR_ADDR(val) bfin_write32(DMA4_CURR_ADDR, val)
528#define bfin_read_DMA4_IRQ_STATUS() bfin_read16(DMA4_IRQ_STATUS) 524#define bfin_read_DMA4_IRQ_STATUS() bfin_read16(DMA4_IRQ_STATUS)
529#define bfin_write_DMA4_IRQ_STATUS(val) bfin_write16(DMA4_IRQ_STATUS, val) 525#define bfin_write_DMA4_IRQ_STATUS(val) bfin_write16(DMA4_IRQ_STATUS, val)
530#define bfin_read_DMA4_PERIPHERAL_MAP() bfin_read16(DMA4_PERIPHERAL_MAP) 526#define bfin_read_DMA4_PERIPHERAL_MAP() bfin_read16(DMA4_PERIPHERAL_MAP)
@@ -537,23 +533,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
537/* DMA Channel 5 Registers */ 533/* DMA Channel 5 Registers */
538 534
539#define bfin_read_DMA5_NEXT_DESC_PTR() bfin_read32(DMA5_NEXT_DESC_PTR) 535#define bfin_read_DMA5_NEXT_DESC_PTR() bfin_read32(DMA5_NEXT_DESC_PTR)
540#define bfin_write_DMA5_NEXT_DESC_PTR(val) bfin_write32(DMA5_NEXT_DESC_PTR) 536#define bfin_write_DMA5_NEXT_DESC_PTR(val) bfin_write32(DMA5_NEXT_DESC_PTR, val)
541#define bfin_read_DMA5_START_ADDR() bfin_read32(DMA5_START_ADDR) 537#define bfin_read_DMA5_START_ADDR() bfin_read32(DMA5_START_ADDR)
542#define bfin_write_DMA5_START_ADDR(val) bfin_write32(DMA5_START_ADDR) 538#define bfin_write_DMA5_START_ADDR(val) bfin_write32(DMA5_START_ADDR, val)
543#define bfin_read_DMA5_CONFIG() bfin_read16(DMA5_CONFIG) 539#define bfin_read_DMA5_CONFIG() bfin_read16(DMA5_CONFIG)
544#define bfin_write_DMA5_CONFIG(val) bfin_write16(DMA5_CONFIG, val) 540#define bfin_write_DMA5_CONFIG(val) bfin_write16(DMA5_CONFIG, val)
545#define bfin_read_DMA5_X_COUNT() bfin_read16(DMA5_X_COUNT) 541#define bfin_read_DMA5_X_COUNT() bfin_read16(DMA5_X_COUNT)
546#define bfin_write_DMA5_X_COUNT(val) bfin_write16(DMA5_X_COUNT, val) 542#define bfin_write_DMA5_X_COUNT(val) bfin_write16(DMA5_X_COUNT, val)
547#define bfin_read_DMA5_X_MODIFY() bfin_read16(DMA5_X_MODIFY) 543#define bfin_read_DMA5_X_MODIFY() bfin_read16(DMA5_X_MODIFY)
548#define bfin_write_DMA5_X_MODIFY(val) bfin_write16(DMA5_X_MODIFY) 544#define bfin_write_DMA5_X_MODIFY(val) bfin_write16(DMA5_X_MODIFY, val)
549#define bfin_read_DMA5_Y_COUNT() bfin_read16(DMA5_Y_COUNT) 545#define bfin_read_DMA5_Y_COUNT() bfin_read16(DMA5_Y_COUNT)
550#define bfin_write_DMA5_Y_COUNT(val) bfin_write16(DMA5_Y_COUNT, val) 546#define bfin_write_DMA5_Y_COUNT(val) bfin_write16(DMA5_Y_COUNT, val)
551#define bfin_read_DMA5_Y_MODIFY() bfin_read16(DMA5_Y_MODIFY) 547#define bfin_read_DMA5_Y_MODIFY() bfin_read16(DMA5_Y_MODIFY)
552#define bfin_write_DMA5_Y_MODIFY(val) bfin_write16(DMA5_Y_MODIFY) 548#define bfin_write_DMA5_Y_MODIFY(val) bfin_write16(DMA5_Y_MODIFY, val)
553#define bfin_read_DMA5_CURR_DESC_PTR() bfin_read32(DMA5_CURR_DESC_PTR) 549#define bfin_read_DMA5_CURR_DESC_PTR() bfin_read32(DMA5_CURR_DESC_PTR)
554#define bfin_write_DMA5_CURR_DESC_PTR(val) bfin_write32(DMA5_CURR_DESC_PTR) 550#define bfin_write_DMA5_CURR_DESC_PTR(val) bfin_write32(DMA5_CURR_DESC_PTR, val)
555#define bfin_read_DMA5_CURR_ADDR() bfin_read32(DMA5_CURR_ADDR) 551#define bfin_read_DMA5_CURR_ADDR() bfin_read32(DMA5_CURR_ADDR)
556#define bfin_write_DMA5_CURR_ADDR(val) bfin_write32(DMA5_CURR_ADDR) 552#define bfin_write_DMA5_CURR_ADDR(val) bfin_write32(DMA5_CURR_ADDR, val)
557#define bfin_read_DMA5_IRQ_STATUS() bfin_read16(DMA5_IRQ_STATUS) 553#define bfin_read_DMA5_IRQ_STATUS() bfin_read16(DMA5_IRQ_STATUS)
558#define bfin_write_DMA5_IRQ_STATUS(val) bfin_write16(DMA5_IRQ_STATUS, val) 554#define bfin_write_DMA5_IRQ_STATUS(val) bfin_write16(DMA5_IRQ_STATUS, val)
559#define bfin_read_DMA5_PERIPHERAL_MAP() bfin_read16(DMA5_PERIPHERAL_MAP) 555#define bfin_read_DMA5_PERIPHERAL_MAP() bfin_read16(DMA5_PERIPHERAL_MAP)
@@ -566,23 +562,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
566/* DMA Channel 6 Registers */ 562/* DMA Channel 6 Registers */
567 563
568#define bfin_read_DMA6_NEXT_DESC_PTR() bfin_read32(DMA6_NEXT_DESC_PTR) 564#define bfin_read_DMA6_NEXT_DESC_PTR() bfin_read32(DMA6_NEXT_DESC_PTR)
569#define bfin_write_DMA6_NEXT_DESC_PTR(val) bfin_write32(DMA6_NEXT_DESC_PTR) 565#define bfin_write_DMA6_NEXT_DESC_PTR(val) bfin_write32(DMA6_NEXT_DESC_PTR, val)
570#define bfin_read_DMA6_START_ADDR() bfin_read32(DMA6_START_ADDR) 566#define bfin_read_DMA6_START_ADDR() bfin_read32(DMA6_START_ADDR)
571#define bfin_write_DMA6_START_ADDR(val) bfin_write32(DMA6_START_ADDR) 567#define bfin_write_DMA6_START_ADDR(val) bfin_write32(DMA6_START_ADDR, val)
572#define bfin_read_DMA6_CONFIG() bfin_read16(DMA6_CONFIG) 568#define bfin_read_DMA6_CONFIG() bfin_read16(DMA6_CONFIG)
573#define bfin_write_DMA6_CONFIG(val) bfin_write16(DMA6_CONFIG, val) 569#define bfin_write_DMA6_CONFIG(val) bfin_write16(DMA6_CONFIG, val)
574#define bfin_read_DMA6_X_COUNT() bfin_read16(DMA6_X_COUNT) 570#define bfin_read_DMA6_X_COUNT() bfin_read16(DMA6_X_COUNT)
575#define bfin_write_DMA6_X_COUNT(val) bfin_write16(DMA6_X_COUNT, val) 571#define bfin_write_DMA6_X_COUNT(val) bfin_write16(DMA6_X_COUNT, val)
576#define bfin_read_DMA6_X_MODIFY() bfin_read16(DMA6_X_MODIFY) 572#define bfin_read_DMA6_X_MODIFY() bfin_read16(DMA6_X_MODIFY)
577#define bfin_write_DMA6_X_MODIFY(val) bfin_write16(DMA6_X_MODIFY) 573#define bfin_write_DMA6_X_MODIFY(val) bfin_write16(DMA6_X_MODIFY, val)
578#define bfin_read_DMA6_Y_COUNT() bfin_read16(DMA6_Y_COUNT) 574#define bfin_read_DMA6_Y_COUNT() bfin_read16(DMA6_Y_COUNT)
579#define bfin_write_DMA6_Y_COUNT(val) bfin_write16(DMA6_Y_COUNT, val) 575#define bfin_write_DMA6_Y_COUNT(val) bfin_write16(DMA6_Y_COUNT, val)
580#define bfin_read_DMA6_Y_MODIFY() bfin_read16(DMA6_Y_MODIFY) 576#define bfin_read_DMA6_Y_MODIFY() bfin_read16(DMA6_Y_MODIFY)
581#define bfin_write_DMA6_Y_MODIFY(val) bfin_write16(DMA6_Y_MODIFY) 577#define bfin_write_DMA6_Y_MODIFY(val) bfin_write16(DMA6_Y_MODIFY, val)
582#define bfin_read_DMA6_CURR_DESC_PTR() bfin_read32(DMA6_CURR_DESC_PTR) 578#define bfin_read_DMA6_CURR_DESC_PTR() bfin_read32(DMA6_CURR_DESC_PTR)
583#define bfin_write_DMA6_CURR_DESC_PTR(val) bfin_write32(DMA6_CURR_DESC_PTR) 579#define bfin_write_DMA6_CURR_DESC_PTR(val) bfin_write32(DMA6_CURR_DESC_PTR, val)
584#define bfin_read_DMA6_CURR_ADDR() bfin_read32(DMA6_CURR_ADDR) 580#define bfin_read_DMA6_CURR_ADDR() bfin_read32(DMA6_CURR_ADDR)
585#define bfin_write_DMA6_CURR_ADDR(val) bfin_write32(DMA6_CURR_ADDR) 581#define bfin_write_DMA6_CURR_ADDR(val) bfin_write32(DMA6_CURR_ADDR, val)
586#define bfin_read_DMA6_IRQ_STATUS() bfin_read16(DMA6_IRQ_STATUS) 582#define bfin_read_DMA6_IRQ_STATUS() bfin_read16(DMA6_IRQ_STATUS)
587#define bfin_write_DMA6_IRQ_STATUS(val) bfin_write16(DMA6_IRQ_STATUS, val) 583#define bfin_write_DMA6_IRQ_STATUS(val) bfin_write16(DMA6_IRQ_STATUS, val)
588#define bfin_read_DMA6_PERIPHERAL_MAP() bfin_read16(DMA6_PERIPHERAL_MAP) 584#define bfin_read_DMA6_PERIPHERAL_MAP() bfin_read16(DMA6_PERIPHERAL_MAP)
@@ -595,23 +591,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
595/* DMA Channel 7 Registers */ 591/* DMA Channel 7 Registers */
596 592
597#define bfin_read_DMA7_NEXT_DESC_PTR() bfin_read32(DMA7_NEXT_DESC_PTR) 593#define bfin_read_DMA7_NEXT_DESC_PTR() bfin_read32(DMA7_NEXT_DESC_PTR)
598#define bfin_write_DMA7_NEXT_DESC_PTR(val) bfin_write32(DMA7_NEXT_DESC_PTR) 594#define bfin_write_DMA7_NEXT_DESC_PTR(val) bfin_write32(DMA7_NEXT_DESC_PTR, val)
599#define bfin_read_DMA7_START_ADDR() bfin_read32(DMA7_START_ADDR) 595#define bfin_read_DMA7_START_ADDR() bfin_read32(DMA7_START_ADDR)
600#define bfin_write_DMA7_START_ADDR(val) bfin_write32(DMA7_START_ADDR) 596#define bfin_write_DMA7_START_ADDR(val) bfin_write32(DMA7_START_ADDR, val)
601#define bfin_read_DMA7_CONFIG() bfin_read16(DMA7_CONFIG) 597#define bfin_read_DMA7_CONFIG() bfin_read16(DMA7_CONFIG)
602#define bfin_write_DMA7_CONFIG(val) bfin_write16(DMA7_CONFIG, val) 598#define bfin_write_DMA7_CONFIG(val) bfin_write16(DMA7_CONFIG, val)
603#define bfin_read_DMA7_X_COUNT() bfin_read16(DMA7_X_COUNT) 599#define bfin_read_DMA7_X_COUNT() bfin_read16(DMA7_X_COUNT)
604#define bfin_write_DMA7_X_COUNT(val) bfin_write16(DMA7_X_COUNT, val) 600#define bfin_write_DMA7_X_COUNT(val) bfin_write16(DMA7_X_COUNT, val)
605#define bfin_read_DMA7_X_MODIFY() bfin_read16(DMA7_X_MODIFY) 601#define bfin_read_DMA7_X_MODIFY() bfin_read16(DMA7_X_MODIFY)
606#define bfin_write_DMA7_X_MODIFY(val) bfin_write16(DMA7_X_MODIFY) 602#define bfin_write_DMA7_X_MODIFY(val) bfin_write16(DMA7_X_MODIFY, val)
607#define bfin_read_DMA7_Y_COUNT() bfin_read16(DMA7_Y_COUNT) 603#define bfin_read_DMA7_Y_COUNT() bfin_read16(DMA7_Y_COUNT)
608#define bfin_write_DMA7_Y_COUNT(val) bfin_write16(DMA7_Y_COUNT, val) 604#define bfin_write_DMA7_Y_COUNT(val) bfin_write16(DMA7_Y_COUNT, val)
609#define bfin_read_DMA7_Y_MODIFY() bfin_read16(DMA7_Y_MODIFY) 605#define bfin_read_DMA7_Y_MODIFY() bfin_read16(DMA7_Y_MODIFY)
610#define bfin_write_DMA7_Y_MODIFY(val) bfin_write16(DMA7_Y_MODIFY) 606#define bfin_write_DMA7_Y_MODIFY(val) bfin_write16(DMA7_Y_MODIFY, val)
611#define bfin_read_DMA7_CURR_DESC_PTR() bfin_read32(DMA7_CURR_DESC_PTR) 607#define bfin_read_DMA7_CURR_DESC_PTR() bfin_read32(DMA7_CURR_DESC_PTR)
612#define bfin_write_DMA7_CURR_DESC_PTR(val) bfin_write32(DMA7_CURR_DESC_PTR) 608#define bfin_write_DMA7_CURR_DESC_PTR(val) bfin_write32(DMA7_CURR_DESC_PTR, val)
613#define bfin_read_DMA7_CURR_ADDR() bfin_read32(DMA7_CURR_ADDR) 609#define bfin_read_DMA7_CURR_ADDR() bfin_read32(DMA7_CURR_ADDR)
614#define bfin_write_DMA7_CURR_ADDR(val) bfin_write32(DMA7_CURR_ADDR) 610#define bfin_write_DMA7_CURR_ADDR(val) bfin_write32(DMA7_CURR_ADDR, val)
615#define bfin_read_DMA7_IRQ_STATUS() bfin_read16(DMA7_IRQ_STATUS) 611#define bfin_read_DMA7_IRQ_STATUS() bfin_read16(DMA7_IRQ_STATUS)
616#define bfin_write_DMA7_IRQ_STATUS(val) bfin_write16(DMA7_IRQ_STATUS, val) 612#define bfin_write_DMA7_IRQ_STATUS(val) bfin_write16(DMA7_IRQ_STATUS, val)
617#define bfin_read_DMA7_PERIPHERAL_MAP() bfin_read16(DMA7_PERIPHERAL_MAP) 613#define bfin_read_DMA7_PERIPHERAL_MAP() bfin_read16(DMA7_PERIPHERAL_MAP)
@@ -624,23 +620,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
624/* DMA Channel 8 Registers */ 620/* DMA Channel 8 Registers */
625 621
626#define bfin_read_DMA8_NEXT_DESC_PTR() bfin_read32(DMA8_NEXT_DESC_PTR) 622#define bfin_read_DMA8_NEXT_DESC_PTR() bfin_read32(DMA8_NEXT_DESC_PTR)
627#define bfin_write_DMA8_NEXT_DESC_PTR(val) bfin_write32(DMA8_NEXT_DESC_PTR) 623#define bfin_write_DMA8_NEXT_DESC_PTR(val) bfin_write32(DMA8_NEXT_DESC_PTR, val)
628#define bfin_read_DMA8_START_ADDR() bfin_read32(DMA8_START_ADDR) 624#define bfin_read_DMA8_START_ADDR() bfin_read32(DMA8_START_ADDR)
629#define bfin_write_DMA8_START_ADDR(val) bfin_write32(DMA8_START_ADDR) 625#define bfin_write_DMA8_START_ADDR(val) bfin_write32(DMA8_START_ADDR, val)
630#define bfin_read_DMA8_CONFIG() bfin_read16(DMA8_CONFIG) 626#define bfin_read_DMA8_CONFIG() bfin_read16(DMA8_CONFIG)
631#define bfin_write_DMA8_CONFIG(val) bfin_write16(DMA8_CONFIG, val) 627#define bfin_write_DMA8_CONFIG(val) bfin_write16(DMA8_CONFIG, val)
632#define bfin_read_DMA8_X_COUNT() bfin_read16(DMA8_X_COUNT) 628#define bfin_read_DMA8_X_COUNT() bfin_read16(DMA8_X_COUNT)
633#define bfin_write_DMA8_X_COUNT(val) bfin_write16(DMA8_X_COUNT, val) 629#define bfin_write_DMA8_X_COUNT(val) bfin_write16(DMA8_X_COUNT, val)
634#define bfin_read_DMA8_X_MODIFY() bfin_read16(DMA8_X_MODIFY) 630#define bfin_read_DMA8_X_MODIFY() bfin_read16(DMA8_X_MODIFY)
635#define bfin_write_DMA8_X_MODIFY(val) bfin_write16(DMA8_X_MODIFY) 631#define bfin_write_DMA8_X_MODIFY(val) bfin_write16(DMA8_X_MODIFY, val)
636#define bfin_read_DMA8_Y_COUNT() bfin_read16(DMA8_Y_COUNT) 632#define bfin_read_DMA8_Y_COUNT() bfin_read16(DMA8_Y_COUNT)
637#define bfin_write_DMA8_Y_COUNT(val) bfin_write16(DMA8_Y_COUNT, val) 633#define bfin_write_DMA8_Y_COUNT(val) bfin_write16(DMA8_Y_COUNT, val)
638#define bfin_read_DMA8_Y_MODIFY() bfin_read16(DMA8_Y_MODIFY) 634#define bfin_read_DMA8_Y_MODIFY() bfin_read16(DMA8_Y_MODIFY)
639#define bfin_write_DMA8_Y_MODIFY(val) bfin_write16(DMA8_Y_MODIFY) 635#define bfin_write_DMA8_Y_MODIFY(val) bfin_write16(DMA8_Y_MODIFY, val)
640#define bfin_read_DMA8_CURR_DESC_PTR() bfin_read32(DMA8_CURR_DESC_PTR) 636#define bfin_read_DMA8_CURR_DESC_PTR() bfin_read32(DMA8_CURR_DESC_PTR)
641#define bfin_write_DMA8_CURR_DESC_PTR(val) bfin_write32(DMA8_CURR_DESC_PTR) 637#define bfin_write_DMA8_CURR_DESC_PTR(val) bfin_write32(DMA8_CURR_DESC_PTR, val)
642#define bfin_read_DMA8_CURR_ADDR() bfin_read32(DMA8_CURR_ADDR) 638#define bfin_read_DMA8_CURR_ADDR() bfin_read32(DMA8_CURR_ADDR)
643#define bfin_write_DMA8_CURR_ADDR(val) bfin_write32(DMA8_CURR_ADDR) 639#define bfin_write_DMA8_CURR_ADDR(val) bfin_write32(DMA8_CURR_ADDR, val)
644#define bfin_read_DMA8_IRQ_STATUS() bfin_read16(DMA8_IRQ_STATUS) 640#define bfin_read_DMA8_IRQ_STATUS() bfin_read16(DMA8_IRQ_STATUS)
645#define bfin_write_DMA8_IRQ_STATUS(val) bfin_write16(DMA8_IRQ_STATUS, val) 641#define bfin_write_DMA8_IRQ_STATUS(val) bfin_write16(DMA8_IRQ_STATUS, val)
646#define bfin_read_DMA8_PERIPHERAL_MAP() bfin_read16(DMA8_PERIPHERAL_MAP) 642#define bfin_read_DMA8_PERIPHERAL_MAP() bfin_read16(DMA8_PERIPHERAL_MAP)
@@ -653,23 +649,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
653/* DMA Channel 9 Registers */ 649/* DMA Channel 9 Registers */
654 650
655#define bfin_read_DMA9_NEXT_DESC_PTR() bfin_read32(DMA9_NEXT_DESC_PTR) 651#define bfin_read_DMA9_NEXT_DESC_PTR() bfin_read32(DMA9_NEXT_DESC_PTR)
656#define bfin_write_DMA9_NEXT_DESC_PTR(val) bfin_write32(DMA9_NEXT_DESC_PTR) 652#define bfin_write_DMA9_NEXT_DESC_PTR(val) bfin_write32(DMA9_NEXT_DESC_PTR, val)
657#define bfin_read_DMA9_START_ADDR() bfin_read32(DMA9_START_ADDR) 653#define bfin_read_DMA9_START_ADDR() bfin_read32(DMA9_START_ADDR)
658#define bfin_write_DMA9_START_ADDR(val) bfin_write32(DMA9_START_ADDR) 654#define bfin_write_DMA9_START_ADDR(val) bfin_write32(DMA9_START_ADDR, val)
659#define bfin_read_DMA9_CONFIG() bfin_read16(DMA9_CONFIG) 655#define bfin_read_DMA9_CONFIG() bfin_read16(DMA9_CONFIG)
660#define bfin_write_DMA9_CONFIG(val) bfin_write16(DMA9_CONFIG, val) 656#define bfin_write_DMA9_CONFIG(val) bfin_write16(DMA9_CONFIG, val)
661#define bfin_read_DMA9_X_COUNT() bfin_read16(DMA9_X_COUNT) 657#define bfin_read_DMA9_X_COUNT() bfin_read16(DMA9_X_COUNT)
662#define bfin_write_DMA9_X_COUNT(val) bfin_write16(DMA9_X_COUNT, val) 658#define bfin_write_DMA9_X_COUNT(val) bfin_write16(DMA9_X_COUNT, val)
663#define bfin_read_DMA9_X_MODIFY() bfin_read16(DMA9_X_MODIFY) 659#define bfin_read_DMA9_X_MODIFY() bfin_read16(DMA9_X_MODIFY)
664#define bfin_write_DMA9_X_MODIFY(val) bfin_write16(DMA9_X_MODIFY) 660#define bfin_write_DMA9_X_MODIFY(val) bfin_write16(DMA9_X_MODIFY, val)
665#define bfin_read_DMA9_Y_COUNT() bfin_read16(DMA9_Y_COUNT) 661#define bfin_read_DMA9_Y_COUNT() bfin_read16(DMA9_Y_COUNT)
666#define bfin_write_DMA9_Y_COUNT(val) bfin_write16(DMA9_Y_COUNT, val) 662#define bfin_write_DMA9_Y_COUNT(val) bfin_write16(DMA9_Y_COUNT, val)
667#define bfin_read_DMA9_Y_MODIFY() bfin_read16(DMA9_Y_MODIFY) 663#define bfin_read_DMA9_Y_MODIFY() bfin_read16(DMA9_Y_MODIFY)
668#define bfin_write_DMA9_Y_MODIFY(val) bfin_write16(DMA9_Y_MODIFY) 664#define bfin_write_DMA9_Y_MODIFY(val) bfin_write16(DMA9_Y_MODIFY, val)
669#define bfin_read_DMA9_CURR_DESC_PTR() bfin_read32(DMA9_CURR_DESC_PTR) 665#define bfin_read_DMA9_CURR_DESC_PTR() bfin_read32(DMA9_CURR_DESC_PTR)
670#define bfin_write_DMA9_CURR_DESC_PTR(val) bfin_write32(DMA9_CURR_DESC_PTR) 666#define bfin_write_DMA9_CURR_DESC_PTR(val) bfin_write32(DMA9_CURR_DESC_PTR, val)
671#define bfin_read_DMA9_CURR_ADDR() bfin_read32(DMA9_CURR_ADDR) 667#define bfin_read_DMA9_CURR_ADDR() bfin_read32(DMA9_CURR_ADDR)
672#define bfin_write_DMA9_CURR_ADDR(val) bfin_write32(DMA9_CURR_ADDR) 668#define bfin_write_DMA9_CURR_ADDR(val) bfin_write32(DMA9_CURR_ADDR, val)
673#define bfin_read_DMA9_IRQ_STATUS() bfin_read16(DMA9_IRQ_STATUS) 669#define bfin_read_DMA9_IRQ_STATUS() bfin_read16(DMA9_IRQ_STATUS)
674#define bfin_write_DMA9_IRQ_STATUS(val) bfin_write16(DMA9_IRQ_STATUS, val) 670#define bfin_write_DMA9_IRQ_STATUS(val) bfin_write16(DMA9_IRQ_STATUS, val)
675#define bfin_read_DMA9_PERIPHERAL_MAP() bfin_read16(DMA9_PERIPHERAL_MAP) 671#define bfin_read_DMA9_PERIPHERAL_MAP() bfin_read16(DMA9_PERIPHERAL_MAP)
@@ -682,23 +678,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
682/* DMA Channel 10 Registers */ 678/* DMA Channel 10 Registers */
683 679
684#define bfin_read_DMA10_NEXT_DESC_PTR() bfin_read32(DMA10_NEXT_DESC_PTR) 680#define bfin_read_DMA10_NEXT_DESC_PTR() bfin_read32(DMA10_NEXT_DESC_PTR)
685#define bfin_write_DMA10_NEXT_DESC_PTR(val) bfin_write32(DMA10_NEXT_DESC_PTR) 681#define bfin_write_DMA10_NEXT_DESC_PTR(val) bfin_write32(DMA10_NEXT_DESC_PTR, val)
686#define bfin_read_DMA10_START_ADDR() bfin_read32(DMA10_START_ADDR) 682#define bfin_read_DMA10_START_ADDR() bfin_read32(DMA10_START_ADDR)
687#define bfin_write_DMA10_START_ADDR(val) bfin_write32(DMA10_START_ADDR) 683#define bfin_write_DMA10_START_ADDR(val) bfin_write32(DMA10_START_ADDR, val)
688#define bfin_read_DMA10_CONFIG() bfin_read16(DMA10_CONFIG) 684#define bfin_read_DMA10_CONFIG() bfin_read16(DMA10_CONFIG)
689#define bfin_write_DMA10_CONFIG(val) bfin_write16(DMA10_CONFIG, val) 685#define bfin_write_DMA10_CONFIG(val) bfin_write16(DMA10_CONFIG, val)
690#define bfin_read_DMA10_X_COUNT() bfin_read16(DMA10_X_COUNT) 686#define bfin_read_DMA10_X_COUNT() bfin_read16(DMA10_X_COUNT)
691#define bfin_write_DMA10_X_COUNT(val) bfin_write16(DMA10_X_COUNT, val) 687#define bfin_write_DMA10_X_COUNT(val) bfin_write16(DMA10_X_COUNT, val)
692#define bfin_read_DMA10_X_MODIFY() bfin_read16(DMA10_X_MODIFY) 688#define bfin_read_DMA10_X_MODIFY() bfin_read16(DMA10_X_MODIFY)
693#define bfin_write_DMA10_X_MODIFY(val) bfin_write16(DMA10_X_MODIFY) 689#define bfin_write_DMA10_X_MODIFY(val) bfin_write16(DMA10_X_MODIFY, val)
694#define bfin_read_DMA10_Y_COUNT() bfin_read16(DMA10_Y_COUNT) 690#define bfin_read_DMA10_Y_COUNT() bfin_read16(DMA10_Y_COUNT)
695#define bfin_write_DMA10_Y_COUNT(val) bfin_write16(DMA10_Y_COUNT, val) 691#define bfin_write_DMA10_Y_COUNT(val) bfin_write16(DMA10_Y_COUNT, val)
696#define bfin_read_DMA10_Y_MODIFY() bfin_read16(DMA10_Y_MODIFY) 692#define bfin_read_DMA10_Y_MODIFY() bfin_read16(DMA10_Y_MODIFY)
697#define bfin_write_DMA10_Y_MODIFY(val) bfin_write16(DMA10_Y_MODIFY) 693#define bfin_write_DMA10_Y_MODIFY(val) bfin_write16(DMA10_Y_MODIFY, val)
698#define bfin_read_DMA10_CURR_DESC_PTR() bfin_read32(DMA10_CURR_DESC_PTR) 694#define bfin_read_DMA10_CURR_DESC_PTR() bfin_read32(DMA10_CURR_DESC_PTR)
699#define bfin_write_DMA10_CURR_DESC_PTR(val) bfin_write32(DMA10_CURR_DESC_PTR) 695#define bfin_write_DMA10_CURR_DESC_PTR(val) bfin_write32(DMA10_CURR_DESC_PTR, val)
700#define bfin_read_DMA10_CURR_ADDR() bfin_read32(DMA10_CURR_ADDR) 696#define bfin_read_DMA10_CURR_ADDR() bfin_read32(DMA10_CURR_ADDR)
701#define bfin_write_DMA10_CURR_ADDR(val) bfin_write32(DMA10_CURR_ADDR) 697#define bfin_write_DMA10_CURR_ADDR(val) bfin_write32(DMA10_CURR_ADDR, val)
702#define bfin_read_DMA10_IRQ_STATUS() bfin_read16(DMA10_IRQ_STATUS) 698#define bfin_read_DMA10_IRQ_STATUS() bfin_read16(DMA10_IRQ_STATUS)
703#define bfin_write_DMA10_IRQ_STATUS(val) bfin_write16(DMA10_IRQ_STATUS, val) 699#define bfin_write_DMA10_IRQ_STATUS(val) bfin_write16(DMA10_IRQ_STATUS, val)
704#define bfin_read_DMA10_PERIPHERAL_MAP() bfin_read16(DMA10_PERIPHERAL_MAP) 700#define bfin_read_DMA10_PERIPHERAL_MAP() bfin_read16(DMA10_PERIPHERAL_MAP)
@@ -711,23 +707,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
711/* DMA Channel 11 Registers */ 707/* DMA Channel 11 Registers */
712 708
713#define bfin_read_DMA11_NEXT_DESC_PTR() bfin_read32(DMA11_NEXT_DESC_PTR) 709#define bfin_read_DMA11_NEXT_DESC_PTR() bfin_read32(DMA11_NEXT_DESC_PTR)
714#define bfin_write_DMA11_NEXT_DESC_PTR(val) bfin_write32(DMA11_NEXT_DESC_PTR) 710#define bfin_write_DMA11_NEXT_DESC_PTR(val) bfin_write32(DMA11_NEXT_DESC_PTR, val)
715#define bfin_read_DMA11_START_ADDR() bfin_read32(DMA11_START_ADDR) 711#define bfin_read_DMA11_START_ADDR() bfin_read32(DMA11_START_ADDR)
716#define bfin_write_DMA11_START_ADDR(val) bfin_write32(DMA11_START_ADDR) 712#define bfin_write_DMA11_START_ADDR(val) bfin_write32(DMA11_START_ADDR, val)
717#define bfin_read_DMA11_CONFIG() bfin_read16(DMA11_CONFIG) 713#define bfin_read_DMA11_CONFIG() bfin_read16(DMA11_CONFIG)
718#define bfin_write_DMA11_CONFIG(val) bfin_write16(DMA11_CONFIG, val) 714#define bfin_write_DMA11_CONFIG(val) bfin_write16(DMA11_CONFIG, val)
719#define bfin_read_DMA11_X_COUNT() bfin_read16(DMA11_X_COUNT) 715#define bfin_read_DMA11_X_COUNT() bfin_read16(DMA11_X_COUNT)
720#define bfin_write_DMA11_X_COUNT(val) bfin_write16(DMA11_X_COUNT, val) 716#define bfin_write_DMA11_X_COUNT(val) bfin_write16(DMA11_X_COUNT, val)
721#define bfin_read_DMA11_X_MODIFY() bfin_read16(DMA11_X_MODIFY) 717#define bfin_read_DMA11_X_MODIFY() bfin_read16(DMA11_X_MODIFY)
722#define bfin_write_DMA11_X_MODIFY(val) bfin_write16(DMA11_X_MODIFY) 718#define bfin_write_DMA11_X_MODIFY(val) bfin_write16(DMA11_X_MODIFY, val)
723#define bfin_read_DMA11_Y_COUNT() bfin_read16(DMA11_Y_COUNT) 719#define bfin_read_DMA11_Y_COUNT() bfin_read16(DMA11_Y_COUNT)
724#define bfin_write_DMA11_Y_COUNT(val) bfin_write16(DMA11_Y_COUNT, val) 720#define bfin_write_DMA11_Y_COUNT(val) bfin_write16(DMA11_Y_COUNT, val)
725#define bfin_read_DMA11_Y_MODIFY() bfin_read16(DMA11_Y_MODIFY) 721#define bfin_read_DMA11_Y_MODIFY() bfin_read16(DMA11_Y_MODIFY)
726#define bfin_write_DMA11_Y_MODIFY(val) bfin_write16(DMA11_Y_MODIFY) 722#define bfin_write_DMA11_Y_MODIFY(val) bfin_write16(DMA11_Y_MODIFY, val)
727#define bfin_read_DMA11_CURR_DESC_PTR() bfin_read32(DMA11_CURR_DESC_PTR) 723#define bfin_read_DMA11_CURR_DESC_PTR() bfin_read32(DMA11_CURR_DESC_PTR)
728#define bfin_write_DMA11_CURR_DESC_PTR(val) bfin_write32(DMA11_CURR_DESC_PTR) 724#define bfin_write_DMA11_CURR_DESC_PTR(val) bfin_write32(DMA11_CURR_DESC_PTR, val)
729#define bfin_read_DMA11_CURR_ADDR() bfin_read32(DMA11_CURR_ADDR) 725#define bfin_read_DMA11_CURR_ADDR() bfin_read32(DMA11_CURR_ADDR)
730#define bfin_write_DMA11_CURR_ADDR(val) bfin_write32(DMA11_CURR_ADDR) 726#define bfin_write_DMA11_CURR_ADDR(val) bfin_write32(DMA11_CURR_ADDR, val)
731#define bfin_read_DMA11_IRQ_STATUS() bfin_read16(DMA11_IRQ_STATUS) 727#define bfin_read_DMA11_IRQ_STATUS() bfin_read16(DMA11_IRQ_STATUS)
732#define bfin_write_DMA11_IRQ_STATUS(val) bfin_write16(DMA11_IRQ_STATUS, val) 728#define bfin_write_DMA11_IRQ_STATUS(val) bfin_write16(DMA11_IRQ_STATUS, val)
733#define bfin_read_DMA11_PERIPHERAL_MAP() bfin_read16(DMA11_PERIPHERAL_MAP) 729#define bfin_read_DMA11_PERIPHERAL_MAP() bfin_read16(DMA11_PERIPHERAL_MAP)
@@ -740,7 +736,7 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
740/* MDMA Stream 0 Registers */ 736/* MDMA Stream 0 Registers */
741 737
742#define bfin_read_MDMA_D0_NEXT_DESC_PTR() bfin_read32(MDMA_D0_NEXT_DESC_PTR) 738#define bfin_read_MDMA_D0_NEXT_DESC_PTR() bfin_read32(MDMA_D0_NEXT_DESC_PTR)
743#define bfin_write_MDMA_D0_NEXT_DESC_PTR(val) bfin_write32(MDMA_D0_NEXT_DESC_PTR) 739#define bfin_write_MDMA_D0_NEXT_DESC_PTR(val) bfin_write32(MDMA_D0_NEXT_DESC_PTR, val)
744#define bfin_read_MDMA_D0_START_ADDR() bfin_read32(MDMA_D0_START_ADDR) 740#define bfin_read_MDMA_D0_START_ADDR() bfin_read32(MDMA_D0_START_ADDR)
745#define bfin_write_MDMA_D0_START_ADDR(val) bfin_write32(MDMA_D0_START_ADDR, val) 741#define bfin_write_MDMA_D0_START_ADDR(val) bfin_write32(MDMA_D0_START_ADDR, val)
746#define bfin_read_MDMA_D0_CONFIG() bfin_read16(MDMA_D0_CONFIG) 742#define bfin_read_MDMA_D0_CONFIG() bfin_read16(MDMA_D0_CONFIG)
@@ -803,11 +799,11 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
803#define bfin_read_MDMA_D1_X_COUNT() bfin_read16(MDMA_D1_X_COUNT) 799#define bfin_read_MDMA_D1_X_COUNT() bfin_read16(MDMA_D1_X_COUNT)
804#define bfin_write_MDMA_D1_X_COUNT(val) bfin_write16(MDMA_D1_X_COUNT, val) 800#define bfin_write_MDMA_D1_X_COUNT(val) bfin_write16(MDMA_D1_X_COUNT, val)
805#define bfin_read_MDMA_D1_X_MODIFY() bfin_read16(MDMA_D1_X_MODIFY) 801#define bfin_read_MDMA_D1_X_MODIFY() bfin_read16(MDMA_D1_X_MODIFY)
806#define bfin_write_MDMA_D1_X_MODIFY(val) bfin_write16(MDMA_D1_X_MODIFY) 802#define bfin_write_MDMA_D1_X_MODIFY(val) bfin_write16(MDMA_D1_X_MODIFY, val)
807#define bfin_read_MDMA_D1_Y_COUNT() bfin_read16(MDMA_D1_Y_COUNT) 803#define bfin_read_MDMA_D1_Y_COUNT() bfin_read16(MDMA_D1_Y_COUNT)
808#define bfin_write_MDMA_D1_Y_COUNT(val) bfin_write16(MDMA_D1_Y_COUNT, val) 804#define bfin_write_MDMA_D1_Y_COUNT(val) bfin_write16(MDMA_D1_Y_COUNT, val)
809#define bfin_read_MDMA_D1_Y_MODIFY() bfin_read16(MDMA_D1_Y_MODIFY) 805#define bfin_read_MDMA_D1_Y_MODIFY() bfin_read16(MDMA_D1_Y_MODIFY)
810#define bfin_write_MDMA_D1_Y_MODIFY(val) bfin_write16(MDMA_D1_Y_MODIFY) 806#define bfin_write_MDMA_D1_Y_MODIFY(val) bfin_write16(MDMA_D1_Y_MODIFY, val)
811#define bfin_read_MDMA_D1_CURR_DESC_PTR() bfin_read32(MDMA_D1_CURR_DESC_PTR) 807#define bfin_read_MDMA_D1_CURR_DESC_PTR() bfin_read32(MDMA_D1_CURR_DESC_PTR)
812#define bfin_write_MDMA_D1_CURR_DESC_PTR(val) bfin_write32(MDMA_D1_CURR_DESC_PTR, val) 808#define bfin_write_MDMA_D1_CURR_DESC_PTR(val) bfin_write32(MDMA_D1_CURR_DESC_PTR, val)
813#define bfin_read_MDMA_D1_CURR_ADDR() bfin_read32(MDMA_D1_CURR_ADDR) 809#define bfin_read_MDMA_D1_CURR_ADDR() bfin_read32(MDMA_D1_CURR_ADDR)
@@ -829,11 +825,11 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
829#define bfin_read_MDMA_S1_X_COUNT() bfin_read16(MDMA_S1_X_COUNT) 825#define bfin_read_MDMA_S1_X_COUNT() bfin_read16(MDMA_S1_X_COUNT)
830#define bfin_write_MDMA_S1_X_COUNT(val) bfin_write16(MDMA_S1_X_COUNT, val) 826#define bfin_write_MDMA_S1_X_COUNT(val) bfin_write16(MDMA_S1_X_COUNT, val)
831#define bfin_read_MDMA_S1_X_MODIFY() bfin_read16(MDMA_S1_X_MODIFY) 827#define bfin_read_MDMA_S1_X_MODIFY() bfin_read16(MDMA_S1_X_MODIFY)
832#define bfin_write_MDMA_S1_X_MODIFY(val) bfin_write16(MDMA_S1_X_MODIFY) 828#define bfin_write_MDMA_S1_X_MODIFY(val) bfin_write16(MDMA_S1_X_MODIFY, val)
833#define bfin_read_MDMA_S1_Y_COUNT() bfin_read16(MDMA_S1_Y_COUNT) 829#define bfin_read_MDMA_S1_Y_COUNT() bfin_read16(MDMA_S1_Y_COUNT)
834#define bfin_write_MDMA_S1_Y_COUNT(val) bfin_write16(MDMA_S1_Y_COUNT, val) 830#define bfin_write_MDMA_S1_Y_COUNT(val) bfin_write16(MDMA_S1_Y_COUNT, val)
835#define bfin_read_MDMA_S1_Y_MODIFY() bfin_read16(MDMA_S1_Y_MODIFY) 831#define bfin_read_MDMA_S1_Y_MODIFY() bfin_read16(MDMA_S1_Y_MODIFY)
836#define bfin_write_MDMA_S1_Y_MODIFY(val) bfin_write16(MDMA_S1_Y_MODIFY) 832#define bfin_write_MDMA_S1_Y_MODIFY(val) bfin_write16(MDMA_S1_Y_MODIFY, val)
837#define bfin_read_MDMA_S1_CURR_DESC_PTR() bfin_read32(MDMA_S1_CURR_DESC_PTR) 833#define bfin_read_MDMA_S1_CURR_DESC_PTR() bfin_read32(MDMA_S1_CURR_DESC_PTR)
838#define bfin_write_MDMA_S1_CURR_DESC_PTR(val) bfin_write32(MDMA_S1_CURR_DESC_PTR, val) 834#define bfin_write_MDMA_S1_CURR_DESC_PTR(val) bfin_write32(MDMA_S1_CURR_DESC_PTR, val)
839#define bfin_read_MDMA_S1_CURR_ADDR() bfin_read32(MDMA_S1_CURR_ADDR) 835#define bfin_read_MDMA_S1_CURR_ADDR() bfin_read32(MDMA_S1_CURR_ADDR)
@@ -1246,23 +1242,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
1246/* DMA Channel 12 Registers */ 1242/* DMA Channel 12 Registers */
1247 1243
1248#define bfin_read_DMA12_NEXT_DESC_PTR() bfin_read32(DMA12_NEXT_DESC_PTR) 1244#define bfin_read_DMA12_NEXT_DESC_PTR() bfin_read32(DMA12_NEXT_DESC_PTR)
1249#define bfin_write_DMA12_NEXT_DESC_PTR(val) bfin_write32(DMA12_NEXT_DESC_PTR) 1245#define bfin_write_DMA12_NEXT_DESC_PTR(val) bfin_write32(DMA12_NEXT_DESC_PTR, val)
1250#define bfin_read_DMA12_START_ADDR() bfin_read32(DMA12_START_ADDR) 1246#define bfin_read_DMA12_START_ADDR() bfin_read32(DMA12_START_ADDR)
1251#define bfin_write_DMA12_START_ADDR(val) bfin_write32(DMA12_START_ADDR) 1247#define bfin_write_DMA12_START_ADDR(val) bfin_write32(DMA12_START_ADDR, val)
1252#define bfin_read_DMA12_CONFIG() bfin_read16(DMA12_CONFIG) 1248#define bfin_read_DMA12_CONFIG() bfin_read16(DMA12_CONFIG)
1253#define bfin_write_DMA12_CONFIG(val) bfin_write16(DMA12_CONFIG, val) 1249#define bfin_write_DMA12_CONFIG(val) bfin_write16(DMA12_CONFIG, val)
1254#define bfin_read_DMA12_X_COUNT() bfin_read16(DMA12_X_COUNT) 1250#define bfin_read_DMA12_X_COUNT() bfin_read16(DMA12_X_COUNT)
1255#define bfin_write_DMA12_X_COUNT(val) bfin_write16(DMA12_X_COUNT, val) 1251#define bfin_write_DMA12_X_COUNT(val) bfin_write16(DMA12_X_COUNT, val)
1256#define bfin_read_DMA12_X_MODIFY() bfin_read16(DMA12_X_MODIFY) 1252#define bfin_read_DMA12_X_MODIFY() bfin_read16(DMA12_X_MODIFY)
1257#define bfin_write_DMA12_X_MODIFY(val) bfin_write16(DMA12_X_MODIFY) 1253#define bfin_write_DMA12_X_MODIFY(val) bfin_write16(DMA12_X_MODIFY, val)
1258#define bfin_read_DMA12_Y_COUNT() bfin_read16(DMA12_Y_COUNT) 1254#define bfin_read_DMA12_Y_COUNT() bfin_read16(DMA12_Y_COUNT)
1259#define bfin_write_DMA12_Y_COUNT(val) bfin_write16(DMA12_Y_COUNT, val) 1255#define bfin_write_DMA12_Y_COUNT(val) bfin_write16(DMA12_Y_COUNT, val)
1260#define bfin_read_DMA12_Y_MODIFY() bfin_read16(DMA12_Y_MODIFY) 1256#define bfin_read_DMA12_Y_MODIFY() bfin_read16(DMA12_Y_MODIFY)
1261#define bfin_write_DMA12_Y_MODIFY(val) bfin_write16(DMA12_Y_MODIFY) 1257#define bfin_write_DMA12_Y_MODIFY(val) bfin_write16(DMA12_Y_MODIFY, val)
1262#define bfin_read_DMA12_CURR_DESC_PTR() bfin_read32(DMA12_CURR_DESC_PTR) 1258#define bfin_read_DMA12_CURR_DESC_PTR() bfin_read32(DMA12_CURR_DESC_PTR)
1263#define bfin_write_DMA12_CURR_DESC_PTR(val) bfin_write32(DMA12_CURR_DESC_PTR) 1259#define bfin_write_DMA12_CURR_DESC_PTR(val) bfin_write32(DMA12_CURR_DESC_PTR, val)
1264#define bfin_read_DMA12_CURR_ADDR() bfin_read32(DMA12_CURR_ADDR) 1260#define bfin_read_DMA12_CURR_ADDR() bfin_read32(DMA12_CURR_ADDR)
1265#define bfin_write_DMA12_CURR_ADDR(val) bfin_write32(DMA12_CURR_ADDR) 1261#define bfin_write_DMA12_CURR_ADDR(val) bfin_write32(DMA12_CURR_ADDR, val)
1266#define bfin_read_DMA12_IRQ_STATUS() bfin_read16(DMA12_IRQ_STATUS) 1262#define bfin_read_DMA12_IRQ_STATUS() bfin_read16(DMA12_IRQ_STATUS)
1267#define bfin_write_DMA12_IRQ_STATUS(val) bfin_write16(DMA12_IRQ_STATUS, val) 1263#define bfin_write_DMA12_IRQ_STATUS(val) bfin_write16(DMA12_IRQ_STATUS, val)
1268#define bfin_read_DMA12_PERIPHERAL_MAP() bfin_read16(DMA12_PERIPHERAL_MAP) 1264#define bfin_read_DMA12_PERIPHERAL_MAP() bfin_read16(DMA12_PERIPHERAL_MAP)
@@ -1275,23 +1271,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
1275/* DMA Channel 13 Registers */ 1271/* DMA Channel 13 Registers */
1276 1272
1277#define bfin_read_DMA13_NEXT_DESC_PTR() bfin_read32(DMA13_NEXT_DESC_PTR) 1273#define bfin_read_DMA13_NEXT_DESC_PTR() bfin_read32(DMA13_NEXT_DESC_PTR)
1278#define bfin_write_DMA13_NEXT_DESC_PTR(val) bfin_write32(DMA13_NEXT_DESC_PTR) 1274#define bfin_write_DMA13_NEXT_DESC_PTR(val) bfin_write32(DMA13_NEXT_DESC_PTR, val)
1279#define bfin_read_DMA13_START_ADDR() bfin_read32(DMA13_START_ADDR) 1275#define bfin_read_DMA13_START_ADDR() bfin_read32(DMA13_START_ADDR)
1280#define bfin_write_DMA13_START_ADDR(val) bfin_write32(DMA13_START_ADDR) 1276#define bfin_write_DMA13_START_ADDR(val) bfin_write32(DMA13_START_ADDR, val)
1281#define bfin_read_DMA13_CONFIG() bfin_read16(DMA13_CONFIG) 1277#define bfin_read_DMA13_CONFIG() bfin_read16(DMA13_CONFIG)
1282#define bfin_write_DMA13_CONFIG(val) bfin_write16(DMA13_CONFIG, val) 1278#define bfin_write_DMA13_CONFIG(val) bfin_write16(DMA13_CONFIG, val)
1283#define bfin_read_DMA13_X_COUNT() bfin_read16(DMA13_X_COUNT) 1279#define bfin_read_DMA13_X_COUNT() bfin_read16(DMA13_X_COUNT)
1284#define bfin_write_DMA13_X_COUNT(val) bfin_write16(DMA13_X_COUNT, val) 1280#define bfin_write_DMA13_X_COUNT(val) bfin_write16(DMA13_X_COUNT, val)
1285#define bfin_read_DMA13_X_MODIFY() bfin_read16(DMA13_X_MODIFY) 1281#define bfin_read_DMA13_X_MODIFY() bfin_read16(DMA13_X_MODIFY)
1286#define bfin_write_DMA13_X_MODIFY(val) bfin_write16(DMA13_X_MODIFY) 1282#define bfin_write_DMA13_X_MODIFY(val) bfin_write16(DMA13_X_MODIFY, val)
1287#define bfin_read_DMA13_Y_COUNT() bfin_read16(DMA13_Y_COUNT) 1283#define bfin_read_DMA13_Y_COUNT() bfin_read16(DMA13_Y_COUNT)
1288#define bfin_write_DMA13_Y_COUNT(val) bfin_write16(DMA13_Y_COUNT, val) 1284#define bfin_write_DMA13_Y_COUNT(val) bfin_write16(DMA13_Y_COUNT, val)
1289#define bfin_read_DMA13_Y_MODIFY() bfin_read16(DMA13_Y_MODIFY) 1285#define bfin_read_DMA13_Y_MODIFY() bfin_read16(DMA13_Y_MODIFY)
1290#define bfin_write_DMA13_Y_MODIFY(val) bfin_write16(DMA13_Y_MODIFY) 1286#define bfin_write_DMA13_Y_MODIFY(val) bfin_write16(DMA13_Y_MODIFY, val)
1291#define bfin_read_DMA13_CURR_DESC_PTR() bfin_read32(DMA13_CURR_DESC_PTR) 1287#define bfin_read_DMA13_CURR_DESC_PTR() bfin_read32(DMA13_CURR_DESC_PTR)
1292#define bfin_write_DMA13_CURR_DESC_PTR(val) bfin_write32(DMA13_CURR_DESC_PTR) 1288#define bfin_write_DMA13_CURR_DESC_PTR(val) bfin_write32(DMA13_CURR_DESC_PTR, val)
1293#define bfin_read_DMA13_CURR_ADDR() bfin_read32(DMA13_CURR_ADDR) 1289#define bfin_read_DMA13_CURR_ADDR() bfin_read32(DMA13_CURR_ADDR)
1294#define bfin_write_DMA13_CURR_ADDR(val) bfin_write32(DMA13_CURR_ADDR) 1290#define bfin_write_DMA13_CURR_ADDR(val) bfin_write32(DMA13_CURR_ADDR, val)
1295#define bfin_read_DMA13_IRQ_STATUS() bfin_read16(DMA13_IRQ_STATUS) 1291#define bfin_read_DMA13_IRQ_STATUS() bfin_read16(DMA13_IRQ_STATUS)
1296#define bfin_write_DMA13_IRQ_STATUS(val) bfin_write16(DMA13_IRQ_STATUS, val) 1292#define bfin_write_DMA13_IRQ_STATUS(val) bfin_write16(DMA13_IRQ_STATUS, val)
1297#define bfin_read_DMA13_PERIPHERAL_MAP() bfin_read16(DMA13_PERIPHERAL_MAP) 1293#define bfin_read_DMA13_PERIPHERAL_MAP() bfin_read16(DMA13_PERIPHERAL_MAP)
@@ -1304,23 +1300,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
1304/* DMA Channel 14 Registers */ 1300/* DMA Channel 14 Registers */
1305 1301
1306#define bfin_read_DMA14_NEXT_DESC_PTR() bfin_read32(DMA14_NEXT_DESC_PTR) 1302#define bfin_read_DMA14_NEXT_DESC_PTR() bfin_read32(DMA14_NEXT_DESC_PTR)
1307#define bfin_write_DMA14_NEXT_DESC_PTR(val) bfin_write32(DMA14_NEXT_DESC_PTR) 1303#define bfin_write_DMA14_NEXT_DESC_PTR(val) bfin_write32(DMA14_NEXT_DESC_PTR, val)
1308#define bfin_read_DMA14_START_ADDR() bfin_read32(DMA14_START_ADDR) 1304#define bfin_read_DMA14_START_ADDR() bfin_read32(DMA14_START_ADDR)
1309#define bfin_write_DMA14_START_ADDR(val) bfin_write32(DMA14_START_ADDR) 1305#define bfin_write_DMA14_START_ADDR(val) bfin_write32(DMA14_START_ADDR, val)
1310#define bfin_read_DMA14_CONFIG() bfin_read16(DMA14_CONFIG) 1306#define bfin_read_DMA14_CONFIG() bfin_read16(DMA14_CONFIG)
1311#define bfin_write_DMA14_CONFIG(val) bfin_write16(DMA14_CONFIG, val) 1307#define bfin_write_DMA14_CONFIG(val) bfin_write16(DMA14_CONFIG, val)
1312#define bfin_read_DMA14_X_COUNT() bfin_read16(DMA14_X_COUNT) 1308#define bfin_read_DMA14_X_COUNT() bfin_read16(DMA14_X_COUNT)
1313#define bfin_write_DMA14_X_COUNT(val) bfin_write16(DMA14_X_COUNT, val) 1309#define bfin_write_DMA14_X_COUNT(val) bfin_write16(DMA14_X_COUNT, val)
1314#define bfin_read_DMA14_X_MODIFY() bfin_read16(DMA14_X_MODIFY) 1310#define bfin_read_DMA14_X_MODIFY() bfin_read16(DMA14_X_MODIFY)
1315#define bfin_write_DMA14_X_MODIFY(val) bfin_write16(DMA14_X_MODIFY) 1311#define bfin_write_DMA14_X_MODIFY(val) bfin_write16(DMA14_X_MODIFY, val)
1316#define bfin_read_DMA14_Y_COUNT() bfin_read16(DMA14_Y_COUNT) 1312#define bfin_read_DMA14_Y_COUNT() bfin_read16(DMA14_Y_COUNT)
1317#define bfin_write_DMA14_Y_COUNT(val) bfin_write16(DMA14_Y_COUNT, val) 1313#define bfin_write_DMA14_Y_COUNT(val) bfin_write16(DMA14_Y_COUNT, val)
1318#define bfin_read_DMA14_Y_MODIFY() bfin_read16(DMA14_Y_MODIFY) 1314#define bfin_read_DMA14_Y_MODIFY() bfin_read16(DMA14_Y_MODIFY)
1319#define bfin_write_DMA14_Y_MODIFY(val) bfin_write16(DMA14_Y_MODIFY) 1315#define bfin_write_DMA14_Y_MODIFY(val) bfin_write16(DMA14_Y_MODIFY, val)
1320#define bfin_read_DMA14_CURR_DESC_PTR() bfin_read32(DMA14_CURR_DESC_PTR) 1316#define bfin_read_DMA14_CURR_DESC_PTR() bfin_read32(DMA14_CURR_DESC_PTR)
1321#define bfin_write_DMA14_CURR_DESC_PTR(val) bfin_write32(DMA14_CURR_DESC_PTR) 1317#define bfin_write_DMA14_CURR_DESC_PTR(val) bfin_write32(DMA14_CURR_DESC_PTR, val)
1322#define bfin_read_DMA14_CURR_ADDR() bfin_read32(DMA14_CURR_ADDR) 1318#define bfin_read_DMA14_CURR_ADDR() bfin_read32(DMA14_CURR_ADDR)
1323#define bfin_write_DMA14_CURR_ADDR(val) bfin_write32(DMA14_CURR_ADDR) 1319#define bfin_write_DMA14_CURR_ADDR(val) bfin_write32(DMA14_CURR_ADDR, val)
1324#define bfin_read_DMA14_IRQ_STATUS() bfin_read16(DMA14_IRQ_STATUS) 1320#define bfin_read_DMA14_IRQ_STATUS() bfin_read16(DMA14_IRQ_STATUS)
1325#define bfin_write_DMA14_IRQ_STATUS(val) bfin_write16(DMA14_IRQ_STATUS, val) 1321#define bfin_write_DMA14_IRQ_STATUS(val) bfin_write16(DMA14_IRQ_STATUS, val)
1326#define bfin_read_DMA14_PERIPHERAL_MAP() bfin_read16(DMA14_PERIPHERAL_MAP) 1322#define bfin_read_DMA14_PERIPHERAL_MAP() bfin_read16(DMA14_PERIPHERAL_MAP)
@@ -1333,23 +1329,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
1333/* DMA Channel 15 Registers */ 1329/* DMA Channel 15 Registers */
1334 1330
1335#define bfin_read_DMA15_NEXT_DESC_PTR() bfin_read32(DMA15_NEXT_DESC_PTR) 1331#define bfin_read_DMA15_NEXT_DESC_PTR() bfin_read32(DMA15_NEXT_DESC_PTR)
1336#define bfin_write_DMA15_NEXT_DESC_PTR(val) bfin_write32(DMA15_NEXT_DESC_PTR) 1332#define bfin_write_DMA15_NEXT_DESC_PTR(val) bfin_write32(DMA15_NEXT_DESC_PTR, val)
1337#define bfin_read_DMA15_START_ADDR() bfin_read32(DMA15_START_ADDR) 1333#define bfin_read_DMA15_START_ADDR() bfin_read32(DMA15_START_ADDR)
1338#define bfin_write_DMA15_START_ADDR(val) bfin_write32(DMA15_START_ADDR) 1334#define bfin_write_DMA15_START_ADDR(val) bfin_write32(DMA15_START_ADDR, val)
1339#define bfin_read_DMA15_CONFIG() bfin_read16(DMA15_CONFIG) 1335#define bfin_read_DMA15_CONFIG() bfin_read16(DMA15_CONFIG)
1340#define bfin_write_DMA15_CONFIG(val) bfin_write16(DMA15_CONFIG, val) 1336#define bfin_write_DMA15_CONFIG(val) bfin_write16(DMA15_CONFIG, val)
1341#define bfin_read_DMA15_X_COUNT() bfin_read16(DMA15_X_COUNT) 1337#define bfin_read_DMA15_X_COUNT() bfin_read16(DMA15_X_COUNT)
1342#define bfin_write_DMA15_X_COUNT(val) bfin_write16(DMA15_X_COUNT, val) 1338#define bfin_write_DMA15_X_COUNT(val) bfin_write16(DMA15_X_COUNT, val)
1343#define bfin_read_DMA15_X_MODIFY() bfin_read16(DMA15_X_MODIFY) 1339#define bfin_read_DMA15_X_MODIFY() bfin_read16(DMA15_X_MODIFY)
1344#define bfin_write_DMA15_X_MODIFY(val) bfin_write16(DMA15_X_MODIFY) 1340#define bfin_write_DMA15_X_MODIFY(val) bfin_write16(DMA15_X_MODIFY, val)
1345#define bfin_read_DMA15_Y_COUNT() bfin_read16(DMA15_Y_COUNT) 1341#define bfin_read_DMA15_Y_COUNT() bfin_read16(DMA15_Y_COUNT)
1346#define bfin_write_DMA15_Y_COUNT(val) bfin_write16(DMA15_Y_COUNT, val) 1342#define bfin_write_DMA15_Y_COUNT(val) bfin_write16(DMA15_Y_COUNT, val)
1347#define bfin_read_DMA15_Y_MODIFY() bfin_read16(DMA15_Y_MODIFY) 1343#define bfin_read_DMA15_Y_MODIFY() bfin_read16(DMA15_Y_MODIFY)
1348#define bfin_write_DMA15_Y_MODIFY(val) bfin_write16(DMA15_Y_MODIFY) 1344#define bfin_write_DMA15_Y_MODIFY(val) bfin_write16(DMA15_Y_MODIFY, val)
1349#define bfin_read_DMA15_CURR_DESC_PTR() bfin_read32(DMA15_CURR_DESC_PTR) 1345#define bfin_read_DMA15_CURR_DESC_PTR() bfin_read32(DMA15_CURR_DESC_PTR)
1350#define bfin_write_DMA15_CURR_DESC_PTR(val) bfin_write32(DMA15_CURR_DESC_PTR) 1346#define bfin_write_DMA15_CURR_DESC_PTR(val) bfin_write32(DMA15_CURR_DESC_PTR, val)
1351#define bfin_read_DMA15_CURR_ADDR() bfin_read32(DMA15_CURR_ADDR) 1347#define bfin_read_DMA15_CURR_ADDR() bfin_read32(DMA15_CURR_ADDR)
1352#define bfin_write_DMA15_CURR_ADDR(val) bfin_write32(DMA15_CURR_ADDR) 1348#define bfin_write_DMA15_CURR_ADDR(val) bfin_write32(DMA15_CURR_ADDR, val)
1353#define bfin_read_DMA15_IRQ_STATUS() bfin_read16(DMA15_IRQ_STATUS) 1349#define bfin_read_DMA15_IRQ_STATUS() bfin_read16(DMA15_IRQ_STATUS)
1354#define bfin_write_DMA15_IRQ_STATUS(val) bfin_write16(DMA15_IRQ_STATUS, val) 1350#define bfin_write_DMA15_IRQ_STATUS(val) bfin_write16(DMA15_IRQ_STATUS, val)
1355#define bfin_read_DMA15_PERIPHERAL_MAP() bfin_read16(DMA15_PERIPHERAL_MAP) 1351#define bfin_read_DMA15_PERIPHERAL_MAP() bfin_read16(DMA15_PERIPHERAL_MAP)
@@ -1362,23 +1358,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
1362/* DMA Channel 16 Registers */ 1358/* DMA Channel 16 Registers */
1363 1359
1364#define bfin_read_DMA16_NEXT_DESC_PTR() bfin_read32(DMA16_NEXT_DESC_PTR) 1360#define bfin_read_DMA16_NEXT_DESC_PTR() bfin_read32(DMA16_NEXT_DESC_PTR)
1365#define bfin_write_DMA16_NEXT_DESC_PTR(val) bfin_write32(DMA16_NEXT_DESC_PTR) 1361#define bfin_write_DMA16_NEXT_DESC_PTR(val) bfin_write32(DMA16_NEXT_DESC_PTR, val)
1366#define bfin_read_DMA16_START_ADDR() bfin_read32(DMA16_START_ADDR) 1362#define bfin_read_DMA16_START_ADDR() bfin_read32(DMA16_START_ADDR)
1367#define bfin_write_DMA16_START_ADDR(val) bfin_write32(DMA16_START_ADDR) 1363#define bfin_write_DMA16_START_ADDR(val) bfin_write32(DMA16_START_ADDR, val)
1368#define bfin_read_DMA16_CONFIG() bfin_read16(DMA16_CONFIG) 1364#define bfin_read_DMA16_CONFIG() bfin_read16(DMA16_CONFIG)
1369#define bfin_write_DMA16_CONFIG(val) bfin_write16(DMA16_CONFIG, val) 1365#define bfin_write_DMA16_CONFIG(val) bfin_write16(DMA16_CONFIG, val)
1370#define bfin_read_DMA16_X_COUNT() bfin_read16(DMA16_X_COUNT) 1366#define bfin_read_DMA16_X_COUNT() bfin_read16(DMA16_X_COUNT)
1371#define bfin_write_DMA16_X_COUNT(val) bfin_write16(DMA16_X_COUNT, val) 1367#define bfin_write_DMA16_X_COUNT(val) bfin_write16(DMA16_X_COUNT, val)
1372#define bfin_read_DMA16_X_MODIFY() bfin_read16(DMA16_X_MODIFY) 1368#define bfin_read_DMA16_X_MODIFY() bfin_read16(DMA16_X_MODIFY)
1373#define bfin_write_DMA16_X_MODIFY(val) bfin_write16(DMA16_X_MODIFY) 1369#define bfin_write_DMA16_X_MODIFY(val) bfin_write16(DMA16_X_MODIFY, val)
1374#define bfin_read_DMA16_Y_COUNT() bfin_read16(DMA16_Y_COUNT) 1370#define bfin_read_DMA16_Y_COUNT() bfin_read16(DMA16_Y_COUNT)
1375#define bfin_write_DMA16_Y_COUNT(val) bfin_write16(DMA16_Y_COUNT, val) 1371#define bfin_write_DMA16_Y_COUNT(val) bfin_write16(DMA16_Y_COUNT, val)
1376#define bfin_read_DMA16_Y_MODIFY() bfin_read16(DMA16_Y_MODIFY) 1372#define bfin_read_DMA16_Y_MODIFY() bfin_read16(DMA16_Y_MODIFY)
1377#define bfin_write_DMA16_Y_MODIFY(val) bfin_write16(DMA16_Y_MODIFY) 1373#define bfin_write_DMA16_Y_MODIFY(val) bfin_write16(DMA16_Y_MODIFY, val)
1378#define bfin_read_DMA16_CURR_DESC_PTR() bfin_read32(DMA16_CURR_DESC_PTR) 1374#define bfin_read_DMA16_CURR_DESC_PTR() bfin_read32(DMA16_CURR_DESC_PTR)
1379#define bfin_write_DMA16_CURR_DESC_PTR(val) bfin_write32(DMA16_CURR_DESC_PTR) 1375#define bfin_write_DMA16_CURR_DESC_PTR(val) bfin_write32(DMA16_CURR_DESC_PTR, val)
1380#define bfin_read_DMA16_CURR_ADDR() bfin_read32(DMA16_CURR_ADDR) 1376#define bfin_read_DMA16_CURR_ADDR() bfin_read32(DMA16_CURR_ADDR)
1381#define bfin_write_DMA16_CURR_ADDR(val) bfin_write32(DMA16_CURR_ADDR) 1377#define bfin_write_DMA16_CURR_ADDR(val) bfin_write32(DMA16_CURR_ADDR, val)
1382#define bfin_read_DMA16_IRQ_STATUS() bfin_read16(DMA16_IRQ_STATUS) 1378#define bfin_read_DMA16_IRQ_STATUS() bfin_read16(DMA16_IRQ_STATUS)
1383#define bfin_write_DMA16_IRQ_STATUS(val) bfin_write16(DMA16_IRQ_STATUS, val) 1379#define bfin_write_DMA16_IRQ_STATUS(val) bfin_write16(DMA16_IRQ_STATUS, val)
1384#define bfin_read_DMA16_PERIPHERAL_MAP() bfin_read16(DMA16_PERIPHERAL_MAP) 1380#define bfin_read_DMA16_PERIPHERAL_MAP() bfin_read16(DMA16_PERIPHERAL_MAP)
@@ -1391,23 +1387,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
1391/* DMA Channel 17 Registers */ 1387/* DMA Channel 17 Registers */
1392 1388
1393#define bfin_read_DMA17_NEXT_DESC_PTR() bfin_read32(DMA17_NEXT_DESC_PTR) 1389#define bfin_read_DMA17_NEXT_DESC_PTR() bfin_read32(DMA17_NEXT_DESC_PTR)
1394#define bfin_write_DMA17_NEXT_DESC_PTR(val) bfin_write32(DMA17_NEXT_DESC_PTR) 1390#define bfin_write_DMA17_NEXT_DESC_PTR(val) bfin_write32(DMA17_NEXT_DESC_PTR, val)
1395#define bfin_read_DMA17_START_ADDR() bfin_read32(DMA17_START_ADDR) 1391#define bfin_read_DMA17_START_ADDR() bfin_read32(DMA17_START_ADDR)
1396#define bfin_write_DMA17_START_ADDR(val) bfin_write32(DMA17_START_ADDR) 1392#define bfin_write_DMA17_START_ADDR(val) bfin_write32(DMA17_START_ADDR, val)
1397#define bfin_read_DMA17_CONFIG() bfin_read16(DMA17_CONFIG) 1393#define bfin_read_DMA17_CONFIG() bfin_read16(DMA17_CONFIG)
1398#define bfin_write_DMA17_CONFIG(val) bfin_write16(DMA17_CONFIG, val) 1394#define bfin_write_DMA17_CONFIG(val) bfin_write16(DMA17_CONFIG, val)
1399#define bfin_read_DMA17_X_COUNT() bfin_read16(DMA17_X_COUNT) 1395#define bfin_read_DMA17_X_COUNT() bfin_read16(DMA17_X_COUNT)
1400#define bfin_write_DMA17_X_COUNT(val) bfin_write16(DMA17_X_COUNT, val) 1396#define bfin_write_DMA17_X_COUNT(val) bfin_write16(DMA17_X_COUNT, val)
1401#define bfin_read_DMA17_X_MODIFY() bfin_read16(DMA17_X_MODIFY) 1397#define bfin_read_DMA17_X_MODIFY() bfin_read16(DMA17_X_MODIFY)
1402#define bfin_write_DMA17_X_MODIFY(val) bfin_write16(DMA17_X_MODIFY) 1398#define bfin_write_DMA17_X_MODIFY(val) bfin_write16(DMA17_X_MODIFY, val)
1403#define bfin_read_DMA17_Y_COUNT() bfin_read16(DMA17_Y_COUNT) 1399#define bfin_read_DMA17_Y_COUNT() bfin_read16(DMA17_Y_COUNT)
1404#define bfin_write_DMA17_Y_COUNT(val) bfin_write16(DMA17_Y_COUNT, val) 1400#define bfin_write_DMA17_Y_COUNT(val) bfin_write16(DMA17_Y_COUNT, val)
1405#define bfin_read_DMA17_Y_MODIFY() bfin_read16(DMA17_Y_MODIFY) 1401#define bfin_read_DMA17_Y_MODIFY() bfin_read16(DMA17_Y_MODIFY)
1406#define bfin_write_DMA17_Y_MODIFY(val) bfin_write16(DMA17_Y_MODIFY) 1402#define bfin_write_DMA17_Y_MODIFY(val) bfin_write16(DMA17_Y_MODIFY, val)
1407#define bfin_read_DMA17_CURR_DESC_PTR() bfin_read32(DMA17_CURR_DESC_PTR) 1403#define bfin_read_DMA17_CURR_DESC_PTR() bfin_read32(DMA17_CURR_DESC_PTR)
1408#define bfin_write_DMA17_CURR_DESC_PTR(val) bfin_write32(DMA17_CURR_DESC_PTR) 1404#define bfin_write_DMA17_CURR_DESC_PTR(val) bfin_write32(DMA17_CURR_DESC_PTR, val)
1409#define bfin_read_DMA17_CURR_ADDR() bfin_read32(DMA17_CURR_ADDR) 1405#define bfin_read_DMA17_CURR_ADDR() bfin_read32(DMA17_CURR_ADDR)
1410#define bfin_write_DMA17_CURR_ADDR(val) bfin_write32(DMA17_CURR_ADDR) 1406#define bfin_write_DMA17_CURR_ADDR(val) bfin_write32(DMA17_CURR_ADDR, val)
1411#define bfin_read_DMA17_IRQ_STATUS() bfin_read16(DMA17_IRQ_STATUS) 1407#define bfin_read_DMA17_IRQ_STATUS() bfin_read16(DMA17_IRQ_STATUS)
1412#define bfin_write_DMA17_IRQ_STATUS(val) bfin_write16(DMA17_IRQ_STATUS, val) 1408#define bfin_write_DMA17_IRQ_STATUS(val) bfin_write16(DMA17_IRQ_STATUS, val)
1413#define bfin_read_DMA17_PERIPHERAL_MAP() bfin_read16(DMA17_PERIPHERAL_MAP) 1409#define bfin_read_DMA17_PERIPHERAL_MAP() bfin_read16(DMA17_PERIPHERAL_MAP)
@@ -1420,23 +1416,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
1420/* DMA Channel 18 Registers */ 1416/* DMA Channel 18 Registers */
1421 1417
1422#define bfin_read_DMA18_NEXT_DESC_PTR() bfin_read32(DMA18_NEXT_DESC_PTR) 1418#define bfin_read_DMA18_NEXT_DESC_PTR() bfin_read32(DMA18_NEXT_DESC_PTR)
1423#define bfin_write_DMA18_NEXT_DESC_PTR(val) bfin_write32(DMA18_NEXT_DESC_PTR) 1419#define bfin_write_DMA18_NEXT_DESC_PTR(val) bfin_write32(DMA18_NEXT_DESC_PTR, val)
1424#define bfin_read_DMA18_START_ADDR() bfin_read32(DMA18_START_ADDR) 1420#define bfin_read_DMA18_START_ADDR() bfin_read32(DMA18_START_ADDR)
1425#define bfin_write_DMA18_START_ADDR(val) bfin_write32(DMA18_START_ADDR) 1421#define bfin_write_DMA18_START_ADDR(val) bfin_write32(DMA18_START_ADDR, val)
1426#define bfin_read_DMA18_CONFIG() bfin_read16(DMA18_CONFIG) 1422#define bfin_read_DMA18_CONFIG() bfin_read16(DMA18_CONFIG)
1427#define bfin_write_DMA18_CONFIG(val) bfin_write16(DMA18_CONFIG, val) 1423#define bfin_write_DMA18_CONFIG(val) bfin_write16(DMA18_CONFIG, val)
1428#define bfin_read_DMA18_X_COUNT() bfin_read16(DMA18_X_COUNT) 1424#define bfin_read_DMA18_X_COUNT() bfin_read16(DMA18_X_COUNT)
1429#define bfin_write_DMA18_X_COUNT(val) bfin_write16(DMA18_X_COUNT, val) 1425#define bfin_write_DMA18_X_COUNT(val) bfin_write16(DMA18_X_COUNT, val)
1430#define bfin_read_DMA18_X_MODIFY() bfin_read16(DMA18_X_MODIFY) 1426#define bfin_read_DMA18_X_MODIFY() bfin_read16(DMA18_X_MODIFY)
1431#define bfin_write_DMA18_X_MODIFY(val) bfin_write16(DMA18_X_MODIFY) 1427#define bfin_write_DMA18_X_MODIFY(val) bfin_write16(DMA18_X_MODIFY, val)
1432#define bfin_read_DMA18_Y_COUNT() bfin_read16(DMA18_Y_COUNT) 1428#define bfin_read_DMA18_Y_COUNT() bfin_read16(DMA18_Y_COUNT)
1433#define bfin_write_DMA18_Y_COUNT(val) bfin_write16(DMA18_Y_COUNT, val) 1429#define bfin_write_DMA18_Y_COUNT(val) bfin_write16(DMA18_Y_COUNT, val)
1434#define bfin_read_DMA18_Y_MODIFY() bfin_read16(DMA18_Y_MODIFY) 1430#define bfin_read_DMA18_Y_MODIFY() bfin_read16(DMA18_Y_MODIFY)
1435#define bfin_write_DMA18_Y_MODIFY(val) bfin_write16(DMA18_Y_MODIFY) 1431#define bfin_write_DMA18_Y_MODIFY(val) bfin_write16(DMA18_Y_MODIFY, val)
1436#define bfin_read_DMA18_CURR_DESC_PTR() bfin_read32(DMA18_CURR_DESC_PTR) 1432#define bfin_read_DMA18_CURR_DESC_PTR() bfin_read32(DMA18_CURR_DESC_PTR)
1437#define bfin_write_DMA18_CURR_DESC_PTR(val) bfin_write32(DMA18_CURR_DESC_PTR) 1433#define bfin_write_DMA18_CURR_DESC_PTR(val) bfin_write32(DMA18_CURR_DESC_PTR, val)
1438#define bfin_read_DMA18_CURR_ADDR() bfin_read32(DMA18_CURR_ADDR) 1434#define bfin_read_DMA18_CURR_ADDR() bfin_read32(DMA18_CURR_ADDR)
1439#define bfin_write_DMA18_CURR_ADDR(val) bfin_write32(DMA18_CURR_ADDR) 1435#define bfin_write_DMA18_CURR_ADDR(val) bfin_write32(DMA18_CURR_ADDR, val)
1440#define bfin_read_DMA18_IRQ_STATUS() bfin_read16(DMA18_IRQ_STATUS) 1436#define bfin_read_DMA18_IRQ_STATUS() bfin_read16(DMA18_IRQ_STATUS)
1441#define bfin_write_DMA18_IRQ_STATUS(val) bfin_write16(DMA18_IRQ_STATUS, val) 1437#define bfin_write_DMA18_IRQ_STATUS(val) bfin_write16(DMA18_IRQ_STATUS, val)
1442#define bfin_read_DMA18_PERIPHERAL_MAP() bfin_read16(DMA18_PERIPHERAL_MAP) 1438#define bfin_read_DMA18_PERIPHERAL_MAP() bfin_read16(DMA18_PERIPHERAL_MAP)
@@ -1449,23 +1445,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
1449/* DMA Channel 19 Registers */ 1445/* DMA Channel 19 Registers */
1450 1446
1451#define bfin_read_DMA19_NEXT_DESC_PTR() bfin_read32(DMA19_NEXT_DESC_PTR) 1447#define bfin_read_DMA19_NEXT_DESC_PTR() bfin_read32(DMA19_NEXT_DESC_PTR)
1452#define bfin_write_DMA19_NEXT_DESC_PTR(val) bfin_write32(DMA19_NEXT_DESC_PTR) 1448#define bfin_write_DMA19_NEXT_DESC_PTR(val) bfin_write32(DMA19_NEXT_DESC_PTR, val)
1453#define bfin_read_DMA19_START_ADDR() bfin_read32(DMA19_START_ADDR) 1449#define bfin_read_DMA19_START_ADDR() bfin_read32(DMA19_START_ADDR)
1454#define bfin_write_DMA19_START_ADDR(val) bfin_write32(DMA19_START_ADDR) 1450#define bfin_write_DMA19_START_ADDR(val) bfin_write32(DMA19_START_ADDR, val)
1455#define bfin_read_DMA19_CONFIG() bfin_read16(DMA19_CONFIG) 1451#define bfin_read_DMA19_CONFIG() bfin_read16(DMA19_CONFIG)
1456#define bfin_write_DMA19_CONFIG(val) bfin_write16(DMA19_CONFIG, val) 1452#define bfin_write_DMA19_CONFIG(val) bfin_write16(DMA19_CONFIG, val)
1457#define bfin_read_DMA19_X_COUNT() bfin_read16(DMA19_X_COUNT) 1453#define bfin_read_DMA19_X_COUNT() bfin_read16(DMA19_X_COUNT)
1458#define bfin_write_DMA19_X_COUNT(val) bfin_write16(DMA19_X_COUNT, val) 1454#define bfin_write_DMA19_X_COUNT(val) bfin_write16(DMA19_X_COUNT, val)
1459#define bfin_read_DMA19_X_MODIFY() bfin_read16(DMA19_X_MODIFY) 1455#define bfin_read_DMA19_X_MODIFY() bfin_read16(DMA19_X_MODIFY)
1460#define bfin_write_DMA19_X_MODIFY(val) bfin_write16(DMA19_X_MODIFY) 1456#define bfin_write_DMA19_X_MODIFY(val) bfin_write16(DMA19_X_MODIFY, val)
1461#define bfin_read_DMA19_Y_COUNT() bfin_read16(DMA19_Y_COUNT) 1457#define bfin_read_DMA19_Y_COUNT() bfin_read16(DMA19_Y_COUNT)
1462#define bfin_write_DMA19_Y_COUNT(val) bfin_write16(DMA19_Y_COUNT, val) 1458#define bfin_write_DMA19_Y_COUNT(val) bfin_write16(DMA19_Y_COUNT, val)
1463#define bfin_read_DMA19_Y_MODIFY() bfin_read16(DMA19_Y_MODIFY) 1459#define bfin_read_DMA19_Y_MODIFY() bfin_read16(DMA19_Y_MODIFY)
1464#define bfin_write_DMA19_Y_MODIFY(val) bfin_write16(DMA19_Y_MODIFY) 1460#define bfin_write_DMA19_Y_MODIFY(val) bfin_write16(DMA19_Y_MODIFY, val)
1465#define bfin_read_DMA19_CURR_DESC_PTR() bfin_read32(DMA19_CURR_DESC_PTR) 1461#define bfin_read_DMA19_CURR_DESC_PTR() bfin_read32(DMA19_CURR_DESC_PTR)
1466#define bfin_write_DMA19_CURR_DESC_PTR(val) bfin_write32(DMA19_CURR_DESC_PTR) 1462#define bfin_write_DMA19_CURR_DESC_PTR(val) bfin_write32(DMA19_CURR_DESC_PTR, val)
1467#define bfin_read_DMA19_CURR_ADDR() bfin_read32(DMA19_CURR_ADDR) 1463#define bfin_read_DMA19_CURR_ADDR() bfin_read32(DMA19_CURR_ADDR)
1468#define bfin_write_DMA19_CURR_ADDR(val) bfin_write32(DMA19_CURR_ADDR) 1464#define bfin_write_DMA19_CURR_ADDR(val) bfin_write32(DMA19_CURR_ADDR, val)
1469#define bfin_read_DMA19_IRQ_STATUS() bfin_read16(DMA19_IRQ_STATUS) 1465#define bfin_read_DMA19_IRQ_STATUS() bfin_read16(DMA19_IRQ_STATUS)
1470#define bfin_write_DMA19_IRQ_STATUS(val) bfin_write16(DMA19_IRQ_STATUS, val) 1466#define bfin_write_DMA19_IRQ_STATUS(val) bfin_write16(DMA19_IRQ_STATUS, val)
1471#define bfin_read_DMA19_PERIPHERAL_MAP() bfin_read16(DMA19_PERIPHERAL_MAP) 1467#define bfin_read_DMA19_PERIPHERAL_MAP() bfin_read16(DMA19_PERIPHERAL_MAP)
@@ -1478,23 +1474,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
1478/* DMA Channel 20 Registers */ 1474/* DMA Channel 20 Registers */
1479 1475
1480#define bfin_read_DMA20_NEXT_DESC_PTR() bfin_read32(DMA20_NEXT_DESC_PTR) 1476#define bfin_read_DMA20_NEXT_DESC_PTR() bfin_read32(DMA20_NEXT_DESC_PTR)
1481#define bfin_write_DMA20_NEXT_DESC_PTR(val) bfin_write32(DMA20_NEXT_DESC_PTR) 1477#define bfin_write_DMA20_NEXT_DESC_PTR(val) bfin_write32(DMA20_NEXT_DESC_PTR, val)
1482#define bfin_read_DMA20_START_ADDR() bfin_read32(DMA20_START_ADDR) 1478#define bfin_read_DMA20_START_ADDR() bfin_read32(DMA20_START_ADDR)
1483#define bfin_write_DMA20_START_ADDR(val) bfin_write32(DMA20_START_ADDR) 1479#define bfin_write_DMA20_START_ADDR(val) bfin_write32(DMA20_START_ADDR, val)
1484#define bfin_read_DMA20_CONFIG() bfin_read16(DMA20_CONFIG) 1480#define bfin_read_DMA20_CONFIG() bfin_read16(DMA20_CONFIG)
1485#define bfin_write_DMA20_CONFIG(val) bfin_write16(DMA20_CONFIG, val) 1481#define bfin_write_DMA20_CONFIG(val) bfin_write16(DMA20_CONFIG, val)
1486#define bfin_read_DMA20_X_COUNT() bfin_read16(DMA20_X_COUNT) 1482#define bfin_read_DMA20_X_COUNT() bfin_read16(DMA20_X_COUNT)
1487#define bfin_write_DMA20_X_COUNT(val) bfin_write16(DMA20_X_COUNT, val) 1483#define bfin_write_DMA20_X_COUNT(val) bfin_write16(DMA20_X_COUNT, val)
1488#define bfin_read_DMA20_X_MODIFY() bfin_read16(DMA20_X_MODIFY) 1484#define bfin_read_DMA20_X_MODIFY() bfin_read16(DMA20_X_MODIFY)
1489#define bfin_write_DMA20_X_MODIFY(val) bfin_write16(DMA20_X_MODIFY) 1485#define bfin_write_DMA20_X_MODIFY(val) bfin_write16(DMA20_X_MODIFY, val)
1490#define bfin_read_DMA20_Y_COUNT() bfin_read16(DMA20_Y_COUNT) 1486#define bfin_read_DMA20_Y_COUNT() bfin_read16(DMA20_Y_COUNT)
1491#define bfin_write_DMA20_Y_COUNT(val) bfin_write16(DMA20_Y_COUNT, val) 1487#define bfin_write_DMA20_Y_COUNT(val) bfin_write16(DMA20_Y_COUNT, val)
1492#define bfin_read_DMA20_Y_MODIFY() bfin_read16(DMA20_Y_MODIFY) 1488#define bfin_read_DMA20_Y_MODIFY() bfin_read16(DMA20_Y_MODIFY)
1493#define bfin_write_DMA20_Y_MODIFY(val) bfin_write16(DMA20_Y_MODIFY) 1489#define bfin_write_DMA20_Y_MODIFY(val) bfin_write16(DMA20_Y_MODIFY, val)
1494#define bfin_read_DMA20_CURR_DESC_PTR() bfin_read32(DMA20_CURR_DESC_PTR) 1490#define bfin_read_DMA20_CURR_DESC_PTR() bfin_read32(DMA20_CURR_DESC_PTR)
1495#define bfin_write_DMA20_CURR_DESC_PTR(val) bfin_write32(DMA20_CURR_DESC_PTR) 1491#define bfin_write_DMA20_CURR_DESC_PTR(val) bfin_write32(DMA20_CURR_DESC_PTR, val)
1496#define bfin_read_DMA20_CURR_ADDR() bfin_read32(DMA20_CURR_ADDR) 1492#define bfin_read_DMA20_CURR_ADDR() bfin_read32(DMA20_CURR_ADDR)
1497#define bfin_write_DMA20_CURR_ADDR(val) bfin_write32(DMA20_CURR_ADDR) 1493#define bfin_write_DMA20_CURR_ADDR(val) bfin_write32(DMA20_CURR_ADDR, val)
1498#define bfin_read_DMA20_IRQ_STATUS() bfin_read16(DMA20_IRQ_STATUS) 1494#define bfin_read_DMA20_IRQ_STATUS() bfin_read16(DMA20_IRQ_STATUS)
1499#define bfin_write_DMA20_IRQ_STATUS(val) bfin_write16(DMA20_IRQ_STATUS, val) 1495#define bfin_write_DMA20_IRQ_STATUS(val) bfin_write16(DMA20_IRQ_STATUS, val)
1500#define bfin_read_DMA20_PERIPHERAL_MAP() bfin_read16(DMA20_PERIPHERAL_MAP) 1496#define bfin_read_DMA20_PERIPHERAL_MAP() bfin_read16(DMA20_PERIPHERAL_MAP)
@@ -1507,23 +1503,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
1507/* DMA Channel 21 Registers */ 1503/* DMA Channel 21 Registers */
1508 1504
1509#define bfin_read_DMA21_NEXT_DESC_PTR() bfin_read32(DMA21_NEXT_DESC_PTR) 1505#define bfin_read_DMA21_NEXT_DESC_PTR() bfin_read32(DMA21_NEXT_DESC_PTR)
1510#define bfin_write_DMA21_NEXT_DESC_PTR(val) bfin_write32(DMA21_NEXT_DESC_PTR) 1506#define bfin_write_DMA21_NEXT_DESC_PTR(val) bfin_write32(DMA21_NEXT_DESC_PTR, val)
1511#define bfin_read_DMA21_START_ADDR() bfin_read32(DMA21_START_ADDR) 1507#define bfin_read_DMA21_START_ADDR() bfin_read32(DMA21_START_ADDR)
1512#define bfin_write_DMA21_START_ADDR(val) bfin_write32(DMA21_START_ADDR) 1508#define bfin_write_DMA21_START_ADDR(val) bfin_write32(DMA21_START_ADDR, val)
1513#define bfin_read_DMA21_CONFIG() bfin_read16(DMA21_CONFIG) 1509#define bfin_read_DMA21_CONFIG() bfin_read16(DMA21_CONFIG)
1514#define bfin_write_DMA21_CONFIG(val) bfin_write16(DMA21_CONFIG, val) 1510#define bfin_write_DMA21_CONFIG(val) bfin_write16(DMA21_CONFIG, val)
1515#define bfin_read_DMA21_X_COUNT() bfin_read16(DMA21_X_COUNT) 1511#define bfin_read_DMA21_X_COUNT() bfin_read16(DMA21_X_COUNT)
1516#define bfin_write_DMA21_X_COUNT(val) bfin_write16(DMA21_X_COUNT, val) 1512#define bfin_write_DMA21_X_COUNT(val) bfin_write16(DMA21_X_COUNT, val)
1517#define bfin_read_DMA21_X_MODIFY() bfin_read16(DMA21_X_MODIFY) 1513#define bfin_read_DMA21_X_MODIFY() bfin_read16(DMA21_X_MODIFY)
1518#define bfin_write_DMA21_X_MODIFY(val) bfin_write16(DMA21_X_MODIFY) 1514#define bfin_write_DMA21_X_MODIFY(val) bfin_write16(DMA21_X_MODIFY, val)
1519#define bfin_read_DMA21_Y_COUNT() bfin_read16(DMA21_Y_COUNT) 1515#define bfin_read_DMA21_Y_COUNT() bfin_read16(DMA21_Y_COUNT)
1520#define bfin_write_DMA21_Y_COUNT(val) bfin_write16(DMA21_Y_COUNT, val) 1516#define bfin_write_DMA21_Y_COUNT(val) bfin_write16(DMA21_Y_COUNT, val)
1521#define bfin_read_DMA21_Y_MODIFY() bfin_read16(DMA21_Y_MODIFY) 1517#define bfin_read_DMA21_Y_MODIFY() bfin_read16(DMA21_Y_MODIFY)
1522#define bfin_write_DMA21_Y_MODIFY(val) bfin_write16(DMA21_Y_MODIFY) 1518#define bfin_write_DMA21_Y_MODIFY(val) bfin_write16(DMA21_Y_MODIFY, val)
1523#define bfin_read_DMA21_CURR_DESC_PTR() bfin_read32(DMA21_CURR_DESC_PTR) 1519#define bfin_read_DMA21_CURR_DESC_PTR() bfin_read32(DMA21_CURR_DESC_PTR)
1524#define bfin_write_DMA21_CURR_DESC_PTR(val) bfin_write32(DMA21_CURR_DESC_PTR) 1520#define bfin_write_DMA21_CURR_DESC_PTR(val) bfin_write32(DMA21_CURR_DESC_PTR, val)
1525#define bfin_read_DMA21_CURR_ADDR() bfin_read32(DMA21_CURR_ADDR) 1521#define bfin_read_DMA21_CURR_ADDR() bfin_read32(DMA21_CURR_ADDR)
1526#define bfin_write_DMA21_CURR_ADDR(val) bfin_write32(DMA21_CURR_ADDR) 1522#define bfin_write_DMA21_CURR_ADDR(val) bfin_write32(DMA21_CURR_ADDR, val)
1527#define bfin_read_DMA21_IRQ_STATUS() bfin_read16(DMA21_IRQ_STATUS) 1523#define bfin_read_DMA21_IRQ_STATUS() bfin_read16(DMA21_IRQ_STATUS)
1528#define bfin_write_DMA21_IRQ_STATUS(val) bfin_write16(DMA21_IRQ_STATUS, val) 1524#define bfin_write_DMA21_IRQ_STATUS(val) bfin_write16(DMA21_IRQ_STATUS, val)
1529#define bfin_read_DMA21_PERIPHERAL_MAP() bfin_read16(DMA21_PERIPHERAL_MAP) 1525#define bfin_read_DMA21_PERIPHERAL_MAP() bfin_read16(DMA21_PERIPHERAL_MAP)
@@ -1536,23 +1532,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
1536/* DMA Channel 22 Registers */ 1532/* DMA Channel 22 Registers */
1537 1533
1538#define bfin_read_DMA22_NEXT_DESC_PTR() bfin_read32(DMA22_NEXT_DESC_PTR) 1534#define bfin_read_DMA22_NEXT_DESC_PTR() bfin_read32(DMA22_NEXT_DESC_PTR)
1539#define bfin_write_DMA22_NEXT_DESC_PTR(val) bfin_write32(DMA22_NEXT_DESC_PTR) 1535#define bfin_write_DMA22_NEXT_DESC_PTR(val) bfin_write32(DMA22_NEXT_DESC_PTR, val)
1540#define bfin_read_DMA22_START_ADDR() bfin_read32(DMA22_START_ADDR) 1536#define bfin_read_DMA22_START_ADDR() bfin_read32(DMA22_START_ADDR)
1541#define bfin_write_DMA22_START_ADDR(val) bfin_write32(DMA22_START_ADDR) 1537#define bfin_write_DMA22_START_ADDR(val) bfin_write32(DMA22_START_ADDR, val)
1542#define bfin_read_DMA22_CONFIG() bfin_read16(DMA22_CONFIG) 1538#define bfin_read_DMA22_CONFIG() bfin_read16(DMA22_CONFIG)
1543#define bfin_write_DMA22_CONFIG(val) bfin_write16(DMA22_CONFIG, val) 1539#define bfin_write_DMA22_CONFIG(val) bfin_write16(DMA22_CONFIG, val)
1544#define bfin_read_DMA22_X_COUNT() bfin_read16(DMA22_X_COUNT) 1540#define bfin_read_DMA22_X_COUNT() bfin_read16(DMA22_X_COUNT)
1545#define bfin_write_DMA22_X_COUNT(val) bfin_write16(DMA22_X_COUNT, val) 1541#define bfin_write_DMA22_X_COUNT(val) bfin_write16(DMA22_X_COUNT, val)
1546#define bfin_read_DMA22_X_MODIFY() bfin_read16(DMA22_X_MODIFY) 1542#define bfin_read_DMA22_X_MODIFY() bfin_read16(DMA22_X_MODIFY)
1547#define bfin_write_DMA22_X_MODIFY(val) bfin_write16(DMA22_X_MODIFY) 1543#define bfin_write_DMA22_X_MODIFY(val) bfin_write16(DMA22_X_MODIFY, val)
1548#define bfin_read_DMA22_Y_COUNT() bfin_read16(DMA22_Y_COUNT) 1544#define bfin_read_DMA22_Y_COUNT() bfin_read16(DMA22_Y_COUNT)
1549#define bfin_write_DMA22_Y_COUNT(val) bfin_write16(DMA22_Y_COUNT, val) 1545#define bfin_write_DMA22_Y_COUNT(val) bfin_write16(DMA22_Y_COUNT, val)
1550#define bfin_read_DMA22_Y_MODIFY() bfin_read16(DMA22_Y_MODIFY) 1546#define bfin_read_DMA22_Y_MODIFY() bfin_read16(DMA22_Y_MODIFY)
1551#define bfin_write_DMA22_Y_MODIFY(val) bfin_write16(DMA22_Y_MODIFY) 1547#define bfin_write_DMA22_Y_MODIFY(val) bfin_write16(DMA22_Y_MODIFY, val)
1552#define bfin_read_DMA22_CURR_DESC_PTR() bfin_read32(DMA22_CURR_DESC_PTR) 1548#define bfin_read_DMA22_CURR_DESC_PTR() bfin_read32(DMA22_CURR_DESC_PTR)
1553#define bfin_write_DMA22_CURR_DESC_PTR(val) bfin_write32(DMA22_CURR_DESC_PTR) 1549#define bfin_write_DMA22_CURR_DESC_PTR(val) bfin_write32(DMA22_CURR_DESC_PTR, val)
1554#define bfin_read_DMA22_CURR_ADDR() bfin_read32(DMA22_CURR_ADDR) 1550#define bfin_read_DMA22_CURR_ADDR() bfin_read32(DMA22_CURR_ADDR)
1555#define bfin_write_DMA22_CURR_ADDR(val) bfin_write32(DMA22_CURR_ADDR) 1551#define bfin_write_DMA22_CURR_ADDR(val) bfin_write32(DMA22_CURR_ADDR, val)
1556#define bfin_read_DMA22_IRQ_STATUS() bfin_read16(DMA22_IRQ_STATUS) 1552#define bfin_read_DMA22_IRQ_STATUS() bfin_read16(DMA22_IRQ_STATUS)
1557#define bfin_write_DMA22_IRQ_STATUS(val) bfin_write16(DMA22_IRQ_STATUS, val) 1553#define bfin_write_DMA22_IRQ_STATUS(val) bfin_write16(DMA22_IRQ_STATUS, val)
1558#define bfin_read_DMA22_PERIPHERAL_MAP() bfin_read16(DMA22_PERIPHERAL_MAP) 1554#define bfin_read_DMA22_PERIPHERAL_MAP() bfin_read16(DMA22_PERIPHERAL_MAP)
@@ -1565,23 +1561,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
1565/* DMA Channel 23 Registers */ 1561/* DMA Channel 23 Registers */
1566 1562
1567#define bfin_read_DMA23_NEXT_DESC_PTR() bfin_read32(DMA23_NEXT_DESC_PTR) 1563#define bfin_read_DMA23_NEXT_DESC_PTR() bfin_read32(DMA23_NEXT_DESC_PTR)
1568#define bfin_write_DMA23_NEXT_DESC_PTR(val) bfin_write32(DMA23_NEXT_DESC_PTR) 1564#define bfin_write_DMA23_NEXT_DESC_PTR(val) bfin_write32(DMA23_NEXT_DESC_PTR, val)
1569#define bfin_read_DMA23_START_ADDR() bfin_read32(DMA23_START_ADDR) 1565#define bfin_read_DMA23_START_ADDR() bfin_read32(DMA23_START_ADDR)
1570#define bfin_write_DMA23_START_ADDR(val) bfin_write32(DMA23_START_ADDR) 1566#define bfin_write_DMA23_START_ADDR(val) bfin_write32(DMA23_START_ADDR, val)
1571#define bfin_read_DMA23_CONFIG() bfin_read16(DMA23_CONFIG) 1567#define bfin_read_DMA23_CONFIG() bfin_read16(DMA23_CONFIG)
1572#define bfin_write_DMA23_CONFIG(val) bfin_write16(DMA23_CONFIG, val) 1568#define bfin_write_DMA23_CONFIG(val) bfin_write16(DMA23_CONFIG, val)
1573#define bfin_read_DMA23_X_COUNT() bfin_read16(DMA23_X_COUNT) 1569#define bfin_read_DMA23_X_COUNT() bfin_read16(DMA23_X_COUNT)
1574#define bfin_write_DMA23_X_COUNT(val) bfin_write16(DMA23_X_COUNT, val) 1570#define bfin_write_DMA23_X_COUNT(val) bfin_write16(DMA23_X_COUNT, val)
1575#define bfin_read_DMA23_X_MODIFY() bfin_read16(DMA23_X_MODIFY) 1571#define bfin_read_DMA23_X_MODIFY() bfin_read16(DMA23_X_MODIFY)
1576#define bfin_write_DMA23_X_MODIFY(val) bfin_write16(DMA23_X_MODIFY) 1572#define bfin_write_DMA23_X_MODIFY(val) bfin_write16(DMA23_X_MODIFY, val)
1577#define bfin_read_DMA23_Y_COUNT() bfin_read16(DMA23_Y_COUNT) 1573#define bfin_read_DMA23_Y_COUNT() bfin_read16(DMA23_Y_COUNT)
1578#define bfin_write_DMA23_Y_COUNT(val) bfin_write16(DMA23_Y_COUNT, val) 1574#define bfin_write_DMA23_Y_COUNT(val) bfin_write16(DMA23_Y_COUNT, val)
1579#define bfin_read_DMA23_Y_MODIFY() bfin_read16(DMA23_Y_MODIFY) 1575#define bfin_read_DMA23_Y_MODIFY() bfin_read16(DMA23_Y_MODIFY)
1580#define bfin_write_DMA23_Y_MODIFY(val) bfin_write16(DMA23_Y_MODIFY) 1576#define bfin_write_DMA23_Y_MODIFY(val) bfin_write16(DMA23_Y_MODIFY, val)
1581#define bfin_read_DMA23_CURR_DESC_PTR() bfin_read32(DMA23_CURR_DESC_PTR) 1577#define bfin_read_DMA23_CURR_DESC_PTR() bfin_read32(DMA23_CURR_DESC_PTR)
1582#define bfin_write_DMA23_CURR_DESC_PTR(val) bfin_write32(DMA23_CURR_DESC_PTR) 1578#define bfin_write_DMA23_CURR_DESC_PTR(val) bfin_write32(DMA23_CURR_DESC_PTR, val)
1583#define bfin_read_DMA23_CURR_ADDR() bfin_read32(DMA23_CURR_ADDR) 1579#define bfin_read_DMA23_CURR_ADDR() bfin_read32(DMA23_CURR_ADDR)
1584#define bfin_write_DMA23_CURR_ADDR(val) bfin_write32(DMA23_CURR_ADDR) 1580#define bfin_write_DMA23_CURR_ADDR(val) bfin_write32(DMA23_CURR_ADDR, val)
1585#define bfin_read_DMA23_IRQ_STATUS() bfin_read16(DMA23_IRQ_STATUS) 1581#define bfin_read_DMA23_IRQ_STATUS() bfin_read16(DMA23_IRQ_STATUS)
1586#define bfin_write_DMA23_IRQ_STATUS(val) bfin_write16(DMA23_IRQ_STATUS, val) 1582#define bfin_write_DMA23_IRQ_STATUS(val) bfin_write16(DMA23_IRQ_STATUS, val)
1587#define bfin_read_DMA23_PERIPHERAL_MAP() bfin_read16(DMA23_PERIPHERAL_MAP) 1583#define bfin_read_DMA23_PERIPHERAL_MAP() bfin_read16(DMA23_PERIPHERAL_MAP)
@@ -1594,23 +1590,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
1594/* MDMA Stream 2 Registers */ 1590/* MDMA Stream 2 Registers */
1595 1591
1596#define bfin_read_MDMA_D2_NEXT_DESC_PTR() bfin_read32(MDMA_D2_NEXT_DESC_PTR) 1592#define bfin_read_MDMA_D2_NEXT_DESC_PTR() bfin_read32(MDMA_D2_NEXT_DESC_PTR)
1597#define bfin_write_MDMA_D2_NEXT_DESC_PTR(val) bfin_write32(MDMA_D2_NEXT_DESC_PTR) 1593#define bfin_write_MDMA_D2_NEXT_DESC_PTR(val) bfin_write32(MDMA_D2_NEXT_DESC_PTR, val)
1598#define bfin_read_MDMA_D2_START_ADDR() bfin_read32(MDMA_D2_START_ADDR) 1594#define bfin_read_MDMA_D2_START_ADDR() bfin_read32(MDMA_D2_START_ADDR)
1599#define bfin_write_MDMA_D2_START_ADDR(val) bfin_write32(MDMA_D2_START_ADDR) 1595#define bfin_write_MDMA_D2_START_ADDR(val) bfin_write32(MDMA_D2_START_ADDR, val)
1600#define bfin_read_MDMA_D2_CONFIG() bfin_read16(MDMA_D2_CONFIG) 1596#define bfin_read_MDMA_D2_CONFIG() bfin_read16(MDMA_D2_CONFIG)
1601#define bfin_write_MDMA_D2_CONFIG(val) bfin_write16(MDMA_D2_CONFIG, val) 1597#define bfin_write_MDMA_D2_CONFIG(val) bfin_write16(MDMA_D2_CONFIG, val)
1602#define bfin_read_MDMA_D2_X_COUNT() bfin_read16(MDMA_D2_X_COUNT) 1598#define bfin_read_MDMA_D2_X_COUNT() bfin_read16(MDMA_D2_X_COUNT)
1603#define bfin_write_MDMA_D2_X_COUNT(val) bfin_write16(MDMA_D2_X_COUNT, val) 1599#define bfin_write_MDMA_D2_X_COUNT(val) bfin_write16(MDMA_D2_X_COUNT, val)
1604#define bfin_read_MDMA_D2_X_MODIFY() bfin_read16(MDMA_D2_X_MODIFY) 1600#define bfin_read_MDMA_D2_X_MODIFY() bfin_read16(MDMA_D2_X_MODIFY)
1605#define bfin_write_MDMA_D2_X_MODIFY(val) bfin_write16(MDMA_D2_X_MODIFY) 1601#define bfin_write_MDMA_D2_X_MODIFY(val) bfin_write16(MDMA_D2_X_MODIFY, val)
1606#define bfin_read_MDMA_D2_Y_COUNT() bfin_read16(MDMA_D2_Y_COUNT) 1602#define bfin_read_MDMA_D2_Y_COUNT() bfin_read16(MDMA_D2_Y_COUNT)
1607#define bfin_write_MDMA_D2_Y_COUNT(val) bfin_write16(MDMA_D2_Y_COUNT, val) 1603#define bfin_write_MDMA_D2_Y_COUNT(val) bfin_write16(MDMA_D2_Y_COUNT, val)
1608#define bfin_read_MDMA_D2_Y_MODIFY() bfin_read16(MDMA_D2_Y_MODIFY) 1604#define bfin_read_MDMA_D2_Y_MODIFY() bfin_read16(MDMA_D2_Y_MODIFY)
1609#define bfin_write_MDMA_D2_Y_MODIFY(val) bfin_write16(MDMA_D2_Y_MODIFY) 1605#define bfin_write_MDMA_D2_Y_MODIFY(val) bfin_write16(MDMA_D2_Y_MODIFY, val)
1610#define bfin_read_MDMA_D2_CURR_DESC_PTR() bfin_read32(MDMA_D2_CURR_DESC_PTR) 1606#define bfin_read_MDMA_D2_CURR_DESC_PTR() bfin_read32(MDMA_D2_CURR_DESC_PTR)
1611#define bfin_write_MDMA_D2_CURR_DESC_PTR(val) bfin_write32(MDMA_D2_CURR_DESC_PTR) 1607#define bfin_write_MDMA_D2_CURR_DESC_PTR(val) bfin_write32(MDMA_D2_CURR_DESC_PTR, val)
1612#define bfin_read_MDMA_D2_CURR_ADDR() bfin_read32(MDMA_D2_CURR_ADDR) 1608#define bfin_read_MDMA_D2_CURR_ADDR() bfin_read32(MDMA_D2_CURR_ADDR)
1613#define bfin_write_MDMA_D2_CURR_ADDR(val) bfin_write32(MDMA_D2_CURR_ADDR) 1609#define bfin_write_MDMA_D2_CURR_ADDR(val) bfin_write32(MDMA_D2_CURR_ADDR, val)
1614#define bfin_read_MDMA_D2_IRQ_STATUS() bfin_read16(MDMA_D2_IRQ_STATUS) 1610#define bfin_read_MDMA_D2_IRQ_STATUS() bfin_read16(MDMA_D2_IRQ_STATUS)
1615#define bfin_write_MDMA_D2_IRQ_STATUS(val) bfin_write16(MDMA_D2_IRQ_STATUS, val) 1611#define bfin_write_MDMA_D2_IRQ_STATUS(val) bfin_write16(MDMA_D2_IRQ_STATUS, val)
1616#define bfin_read_MDMA_D2_PERIPHERAL_MAP() bfin_read16(MDMA_D2_PERIPHERAL_MAP) 1612#define bfin_read_MDMA_D2_PERIPHERAL_MAP() bfin_read16(MDMA_D2_PERIPHERAL_MAP)
@@ -1620,23 +1616,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
1620#define bfin_read_MDMA_D2_CURR_Y_COUNT() bfin_read16(MDMA_D2_CURR_Y_COUNT) 1616#define bfin_read_MDMA_D2_CURR_Y_COUNT() bfin_read16(MDMA_D2_CURR_Y_COUNT)
1621#define bfin_write_MDMA_D2_CURR_Y_COUNT(val) bfin_write16(MDMA_D2_CURR_Y_COUNT, val) 1617#define bfin_write_MDMA_D2_CURR_Y_COUNT(val) bfin_write16(MDMA_D2_CURR_Y_COUNT, val)
1622#define bfin_read_MDMA_S2_NEXT_DESC_PTR() bfin_read32(MDMA_S2_NEXT_DESC_PTR) 1618#define bfin_read_MDMA_S2_NEXT_DESC_PTR() bfin_read32(MDMA_S2_NEXT_DESC_PTR)
1623#define bfin_write_MDMA_S2_NEXT_DESC_PTR(val) bfin_write32(MDMA_S2_NEXT_DESC_PTR) 1619#define bfin_write_MDMA_S2_NEXT_DESC_PTR(val) bfin_write32(MDMA_S2_NEXT_DESC_PTR, val)
1624#define bfin_read_MDMA_S2_START_ADDR() bfin_read32(MDMA_S2_START_ADDR) 1620#define bfin_read_MDMA_S2_START_ADDR() bfin_read32(MDMA_S2_START_ADDR)
1625#define bfin_write_MDMA_S2_START_ADDR(val) bfin_write32(MDMA_S2_START_ADDR) 1621#define bfin_write_MDMA_S2_START_ADDR(val) bfin_write32(MDMA_S2_START_ADDR, val)
1626#define bfin_read_MDMA_S2_CONFIG() bfin_read16(MDMA_S2_CONFIG) 1622#define bfin_read_MDMA_S2_CONFIG() bfin_read16(MDMA_S2_CONFIG)
1627#define bfin_write_MDMA_S2_CONFIG(val) bfin_write16(MDMA_S2_CONFIG, val) 1623#define bfin_write_MDMA_S2_CONFIG(val) bfin_write16(MDMA_S2_CONFIG, val)
1628#define bfin_read_MDMA_S2_X_COUNT() bfin_read16(MDMA_S2_X_COUNT) 1624#define bfin_read_MDMA_S2_X_COUNT() bfin_read16(MDMA_S2_X_COUNT)
1629#define bfin_write_MDMA_S2_X_COUNT(val) bfin_write16(MDMA_S2_X_COUNT, val) 1625#define bfin_write_MDMA_S2_X_COUNT(val) bfin_write16(MDMA_S2_X_COUNT, val)
1630#define bfin_read_MDMA_S2_X_MODIFY() bfin_read16(MDMA_S2_X_MODIFY) 1626#define bfin_read_MDMA_S2_X_MODIFY() bfin_read16(MDMA_S2_X_MODIFY)
1631#define bfin_write_MDMA_S2_X_MODIFY(val) bfin_write16(MDMA_S2_X_MODIFY) 1627#define bfin_write_MDMA_S2_X_MODIFY(val) bfin_write16(MDMA_S2_X_MODIFY, val)
1632#define bfin_read_MDMA_S2_Y_COUNT() bfin_read16(MDMA_S2_Y_COUNT) 1628#define bfin_read_MDMA_S2_Y_COUNT() bfin_read16(MDMA_S2_Y_COUNT)
1633#define bfin_write_MDMA_S2_Y_COUNT(val) bfin_write16(MDMA_S2_Y_COUNT, val) 1629#define bfin_write_MDMA_S2_Y_COUNT(val) bfin_write16(MDMA_S2_Y_COUNT, val)
1634#define bfin_read_MDMA_S2_Y_MODIFY() bfin_read16(MDMA_S2_Y_MODIFY) 1630#define bfin_read_MDMA_S2_Y_MODIFY() bfin_read16(MDMA_S2_Y_MODIFY)
1635#define bfin_write_MDMA_S2_Y_MODIFY(val) bfin_write16(MDMA_S2_Y_MODIFY) 1631#define bfin_write_MDMA_S2_Y_MODIFY(val) bfin_write16(MDMA_S2_Y_MODIFY, val)
1636#define bfin_read_MDMA_S2_CURR_DESC_PTR() bfin_read32(MDMA_S2_CURR_DESC_PTR) 1632#define bfin_read_MDMA_S2_CURR_DESC_PTR() bfin_read32(MDMA_S2_CURR_DESC_PTR)
1637#define bfin_write_MDMA_S2_CURR_DESC_PTR(val) bfin_write32(MDMA_S2_CURR_DESC_PTR) 1633#define bfin_write_MDMA_S2_CURR_DESC_PTR(val) bfin_write32(MDMA_S2_CURR_DESC_PTR, val)
1638#define bfin_read_MDMA_S2_CURR_ADDR() bfin_read32(MDMA_S2_CURR_ADDR) 1634#define bfin_read_MDMA_S2_CURR_ADDR() bfin_read32(MDMA_S2_CURR_ADDR)
1639#define bfin_write_MDMA_S2_CURR_ADDR(val) bfin_write32(MDMA_S2_CURR_ADDR) 1635#define bfin_write_MDMA_S2_CURR_ADDR(val) bfin_write32(MDMA_S2_CURR_ADDR, val)
1640#define bfin_read_MDMA_S2_IRQ_STATUS() bfin_read16(MDMA_S2_IRQ_STATUS) 1636#define bfin_read_MDMA_S2_IRQ_STATUS() bfin_read16(MDMA_S2_IRQ_STATUS)
1641#define bfin_write_MDMA_S2_IRQ_STATUS(val) bfin_write16(MDMA_S2_IRQ_STATUS, val) 1637#define bfin_write_MDMA_S2_IRQ_STATUS(val) bfin_write16(MDMA_S2_IRQ_STATUS, val)
1642#define bfin_read_MDMA_S2_PERIPHERAL_MAP() bfin_read16(MDMA_S2_PERIPHERAL_MAP) 1638#define bfin_read_MDMA_S2_PERIPHERAL_MAP() bfin_read16(MDMA_S2_PERIPHERAL_MAP)
@@ -1649,23 +1645,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
1649/* MDMA Stream 3 Registers */ 1645/* MDMA Stream 3 Registers */
1650 1646
1651#define bfin_read_MDMA_D3_NEXT_DESC_PTR() bfin_read32(MDMA_D3_NEXT_DESC_PTR) 1647#define bfin_read_MDMA_D3_NEXT_DESC_PTR() bfin_read32(MDMA_D3_NEXT_DESC_PTR)
1652#define bfin_write_MDMA_D3_NEXT_DESC_PTR(val) bfin_write32(MDMA_D3_NEXT_DESC_PTR) 1648#define bfin_write_MDMA_D3_NEXT_DESC_PTR(val) bfin_write32(MDMA_D3_NEXT_DESC_PTR, val)
1653#define bfin_read_MDMA_D3_START_ADDR() bfin_read32(MDMA_D3_START_ADDR) 1649#define bfin_read_MDMA_D3_START_ADDR() bfin_read32(MDMA_D3_START_ADDR)
1654#define bfin_write_MDMA_D3_START_ADDR(val) bfin_write32(MDMA_D3_START_ADDR) 1650#define bfin_write_MDMA_D3_START_ADDR(val) bfin_write32(MDMA_D3_START_ADDR, val)
1655#define bfin_read_MDMA_D3_CONFIG() bfin_read16(MDMA_D3_CONFIG) 1651#define bfin_read_MDMA_D3_CONFIG() bfin_read16(MDMA_D3_CONFIG)
1656#define bfin_write_MDMA_D3_CONFIG(val) bfin_write16(MDMA_D3_CONFIG, val) 1652#define bfin_write_MDMA_D3_CONFIG(val) bfin_write16(MDMA_D3_CONFIG, val)
1657#define bfin_read_MDMA_D3_X_COUNT() bfin_read16(MDMA_D3_X_COUNT) 1653#define bfin_read_MDMA_D3_X_COUNT() bfin_read16(MDMA_D3_X_COUNT)
1658#define bfin_write_MDMA_D3_X_COUNT(val) bfin_write16(MDMA_D3_X_COUNT, val) 1654#define bfin_write_MDMA_D3_X_COUNT(val) bfin_write16(MDMA_D3_X_COUNT, val)
1659#define bfin_read_MDMA_D3_X_MODIFY() bfin_read16(MDMA_D3_X_MODIFY) 1655#define bfin_read_MDMA_D3_X_MODIFY() bfin_read16(MDMA_D3_X_MODIFY)
1660#define bfin_write_MDMA_D3_X_MODIFY(val) bfin_write16(MDMA_D3_X_MODIFY) 1656#define bfin_write_MDMA_D3_X_MODIFY(val) bfin_write16(MDMA_D3_X_MODIFY, val)
1661#define bfin_read_MDMA_D3_Y_COUNT() bfin_read16(MDMA_D3_Y_COUNT) 1657#define bfin_read_MDMA_D3_Y_COUNT() bfin_read16(MDMA_D3_Y_COUNT)
1662#define bfin_write_MDMA_D3_Y_COUNT(val) bfin_write16(MDMA_D3_Y_COUNT, val) 1658#define bfin_write_MDMA_D3_Y_COUNT(val) bfin_write16(MDMA_D3_Y_COUNT, val)
1663#define bfin_read_MDMA_D3_Y_MODIFY() bfin_read16(MDMA_D3_Y_MODIFY) 1659#define bfin_read_MDMA_D3_Y_MODIFY() bfin_read16(MDMA_D3_Y_MODIFY)
1664#define bfin_write_MDMA_D3_Y_MODIFY(val) bfin_write16(MDMA_D3_Y_MODIFY) 1660#define bfin_write_MDMA_D3_Y_MODIFY(val) bfin_write16(MDMA_D3_Y_MODIFY, val)
1665#define bfin_read_MDMA_D3_CURR_DESC_PTR() bfin_read32(MDMA_D3_CURR_DESC_PTR) 1661#define bfin_read_MDMA_D3_CURR_DESC_PTR() bfin_read32(MDMA_D3_CURR_DESC_PTR)
1666#define bfin_write_MDMA_D3_CURR_DESC_PTR(val) bfin_write32(MDMA_D3_CURR_DESC_PTR) 1662#define bfin_write_MDMA_D3_CURR_DESC_PTR(val) bfin_write32(MDMA_D3_CURR_DESC_PTR, val)
1667#define bfin_read_MDMA_D3_CURR_ADDR() bfin_read32(MDMA_D3_CURR_ADDR) 1663#define bfin_read_MDMA_D3_CURR_ADDR() bfin_read32(MDMA_D3_CURR_ADDR)
1668#define bfin_write_MDMA_D3_CURR_ADDR(val) bfin_write32(MDMA_D3_CURR_ADDR) 1664#define bfin_write_MDMA_D3_CURR_ADDR(val) bfin_write32(MDMA_D3_CURR_ADDR, val)
1669#define bfin_read_MDMA_D3_IRQ_STATUS() bfin_read16(MDMA_D3_IRQ_STATUS) 1665#define bfin_read_MDMA_D3_IRQ_STATUS() bfin_read16(MDMA_D3_IRQ_STATUS)
1670#define bfin_write_MDMA_D3_IRQ_STATUS(val) bfin_write16(MDMA_D3_IRQ_STATUS, val) 1666#define bfin_write_MDMA_D3_IRQ_STATUS(val) bfin_write16(MDMA_D3_IRQ_STATUS, val)
1671#define bfin_read_MDMA_D3_PERIPHERAL_MAP() bfin_read16(MDMA_D3_PERIPHERAL_MAP) 1667#define bfin_read_MDMA_D3_PERIPHERAL_MAP() bfin_read16(MDMA_D3_PERIPHERAL_MAP)
@@ -1675,23 +1671,23 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
1675#define bfin_read_MDMA_D3_CURR_Y_COUNT() bfin_read16(MDMA_D3_CURR_Y_COUNT) 1671#define bfin_read_MDMA_D3_CURR_Y_COUNT() bfin_read16(MDMA_D3_CURR_Y_COUNT)
1676#define bfin_write_MDMA_D3_CURR_Y_COUNT(val) bfin_write16(MDMA_D3_CURR_Y_COUNT, val) 1672#define bfin_write_MDMA_D3_CURR_Y_COUNT(val) bfin_write16(MDMA_D3_CURR_Y_COUNT, val)
1677#define bfin_read_MDMA_S3_NEXT_DESC_PTR() bfin_read32(MDMA_S3_NEXT_DESC_PTR) 1673#define bfin_read_MDMA_S3_NEXT_DESC_PTR() bfin_read32(MDMA_S3_NEXT_DESC_PTR)
1678#define bfin_write_MDMA_S3_NEXT_DESC_PTR(val) bfin_write32(MDMA_S3_NEXT_DESC_PTR) 1674#define bfin_write_MDMA_S3_NEXT_DESC_PTR(val) bfin_write32(MDMA_S3_NEXT_DESC_PTR, val)
1679#define bfin_read_MDMA_S3_START_ADDR() bfin_read32(MDMA_S3_START_ADDR) 1675#define bfin_read_MDMA_S3_START_ADDR() bfin_read32(MDMA_S3_START_ADDR)
1680#define bfin_write_MDMA_S3_START_ADDR(val) bfin_write32(MDMA_S3_START_ADDR) 1676#define bfin_write_MDMA_S3_START_ADDR(val) bfin_write32(MDMA_S3_START_ADDR, val)
1681#define bfin_read_MDMA_S3_CONFIG() bfin_read16(MDMA_S3_CONFIG) 1677#define bfin_read_MDMA_S3_CONFIG() bfin_read16(MDMA_S3_CONFIG)
1682#define bfin_write_MDMA_S3_CONFIG(val) bfin_write16(MDMA_S3_CONFIG, val) 1678#define bfin_write_MDMA_S3_CONFIG(val) bfin_write16(MDMA_S3_CONFIG, val)
1683#define bfin_read_MDMA_S3_X_COUNT() bfin_read16(MDMA_S3_X_COUNT) 1679#define bfin_read_MDMA_S3_X_COUNT() bfin_read16(MDMA_S3_X_COUNT)
1684#define bfin_write_MDMA_S3_X_COUNT(val) bfin_write16(MDMA_S3_X_COUNT, val) 1680#define bfin_write_MDMA_S3_X_COUNT(val) bfin_write16(MDMA_S3_X_COUNT, val)
1685#define bfin_read_MDMA_S3_X_MODIFY() bfin_read16(MDMA_S3_X_MODIFY) 1681#define bfin_read_MDMA_S3_X_MODIFY() bfin_read16(MDMA_S3_X_MODIFY)
1686#define bfin_write_MDMA_S3_X_MODIFY(val) bfin_write16(MDMA_S3_X_MODIFY) 1682#define bfin_write_MDMA_S3_X_MODIFY(val) bfin_write16(MDMA_S3_X_MODIFY, val)
1687#define bfin_read_MDMA_S3_Y_COUNT() bfin_read16(MDMA_S3_Y_COUNT) 1683#define bfin_read_MDMA_S3_Y_COUNT() bfin_read16(MDMA_S3_Y_COUNT)
1688#define bfin_write_MDMA_S3_Y_COUNT(val) bfin_write16(MDMA_S3_Y_COUNT, val) 1684#define bfin_write_MDMA_S3_Y_COUNT(val) bfin_write16(MDMA_S3_Y_COUNT, val)
1689#define bfin_read_MDMA_S3_Y_MODIFY() bfin_read16(MDMA_S3_Y_MODIFY) 1685#define bfin_read_MDMA_S3_Y_MODIFY() bfin_read16(MDMA_S3_Y_MODIFY)
1690#define bfin_write_MDMA_S3_Y_MODIFY(val) bfin_write16(MDMA_S3_Y_MODIFY) 1686#define bfin_write_MDMA_S3_Y_MODIFY(val) bfin_write16(MDMA_S3_Y_MODIFY, val)
1691#define bfin_read_MDMA_S3_CURR_DESC_PTR() bfin_read32(MDMA_S3_CURR_DESC_PTR) 1687#define bfin_read_MDMA_S3_CURR_DESC_PTR() bfin_read32(MDMA_S3_CURR_DESC_PTR)
1692#define bfin_write_MDMA_S3_CURR_DESC_PTR(val) bfin_write32(MDMA_S3_CURR_DESC_PTR) 1688#define bfin_write_MDMA_S3_CURR_DESC_PTR(val) bfin_write32(MDMA_S3_CURR_DESC_PTR, val)
1693#define bfin_read_MDMA_S3_CURR_ADDR() bfin_read32(MDMA_S3_CURR_ADDR) 1689#define bfin_read_MDMA_S3_CURR_ADDR() bfin_read32(MDMA_S3_CURR_ADDR)
1694#define bfin_write_MDMA_S3_CURR_ADDR(val) bfin_write32(MDMA_S3_CURR_ADDR) 1690#define bfin_write_MDMA_S3_CURR_ADDR(val) bfin_write32(MDMA_S3_CURR_ADDR, val)
1695#define bfin_read_MDMA_S3_IRQ_STATUS() bfin_read16(MDMA_S3_IRQ_STATUS) 1691#define bfin_read_MDMA_S3_IRQ_STATUS() bfin_read16(MDMA_S3_IRQ_STATUS)
1696#define bfin_write_MDMA_S3_IRQ_STATUS(val) bfin_write16(MDMA_S3_IRQ_STATUS, val) 1692#define bfin_write_MDMA_S3_IRQ_STATUS(val) bfin_write16(MDMA_S3_IRQ_STATUS, val)
1697#define bfin_read_MDMA_S3_PERIPHERAL_MAP() bfin_read16(MDMA_S3_PERIPHERAL_MAP) 1693#define bfin_read_MDMA_S3_PERIPHERAL_MAP() bfin_read16(MDMA_S3_PERIPHERAL_MAP)
diff --git a/include/asm-blackfin/mach-bf548/dma.h b/include/asm-blackfin/mach-bf548/dma.h
index 46ff31f20ae5..36a2ef7e7849 100644
--- a/include/asm-blackfin/mach-bf548/dma.h
+++ b/include/asm-blackfin/mach-bf548/dma.h
@@ -73,6 +73,4 @@
73 73
74#define MAX_BLACKFIN_DMA_CHANNEL 32 74#define MAX_BLACKFIN_DMA_CHANNEL 32
75 75
76extern int channel2irq(unsigned int channel);
77extern struct dma_register *base_addr[MAX_BLACKFIN_DMA_CHANNEL];
78#endif 76#endif
diff --git a/include/asm-blackfin/mach-bf548/mem_init.h b/include/asm-blackfin/mach-bf548/mem_init.h
index befc2903d5a5..ab0b863eee66 100644
--- a/include/asm-blackfin/mach-bf548/mem_init.h
+++ b/include/asm-blackfin/mach-bf548/mem_init.h
@@ -29,16 +29,19 @@
29 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 29 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30 */ 30 */
31#define MIN_DDR_SCLK(x) (x*(CONFIG_SCLK_HZ/1000/1000)/1000 + 1) 31#define MIN_DDR_SCLK(x) (x*(CONFIG_SCLK_HZ/1000/1000)/1000 + 1)
32#define MAX_DDR_SCLK(x) (x*(CONFIG_SCLK_HZ/1000/1000)/1000)
33#define DDR_CLK_HZ(x) (1000*1000*1000/x)
32 34
33#if (CONFIG_MEM_MT46V32M16_6T) 35#if (CONFIG_MEM_MT46V32M16_6T)
34#define DDR_SIZE DEVSZ_512 36#define DDR_SIZE DEVSZ_512
35#define DDR_WIDTH DEVWD_16 37#define DDR_WIDTH DEVWD_16
38#define DDR_MAX_tCK 13
36 39
37#define DDR_tRC DDR_TRC(MIN_DDR_SCLK(60)) 40#define DDR_tRC DDR_TRC(MIN_DDR_SCLK(60))
38#define DDR_tRAS DDR_TRAS(MIN_DDR_SCLK(42)) 41#define DDR_tRAS DDR_TRAS(MIN_DDR_SCLK(42))
39#define DDR_tRP DDR_TRP(MIN_DDR_SCLK(15)) 42#define DDR_tRP DDR_TRP(MIN_DDR_SCLK(15))
40#define DDR_tRFC DDR_TRFC(MIN_DDR_SCLK(72)) 43#define DDR_tRFC DDR_TRFC(MIN_DDR_SCLK(72))
41#define DDR_tREFI DDR_TREFI(MIN_DDR_SCLK(7800)) 44#define DDR_tREFI DDR_TREFI(MAX_DDR_SCLK(7800))
42 45
43#define DDR_tRCD DDR_TRCD(MIN_DDR_SCLK(15)) 46#define DDR_tRCD DDR_TRCD(MIN_DDR_SCLK(15))
44#define DDR_tWTR DDR_TWTR(1) 47#define DDR_tWTR DDR_TWTR(1)
@@ -49,12 +52,13 @@
49#if (CONFIG_MEM_MT46V32M16_5B) 52#if (CONFIG_MEM_MT46V32M16_5B)
50#define DDR_SIZE DEVSZ_512 53#define DDR_SIZE DEVSZ_512
51#define DDR_WIDTH DEVWD_16 54#define DDR_WIDTH DEVWD_16
55#define DDR_MAX_tCK 13
52 56
53#define DDR_tRC DDR_TRC(MIN_DDR_SCLK(55)) 57#define DDR_tRC DDR_TRC(MIN_DDR_SCLK(55))
54#define DDR_tRAS DDR_TRAS(MIN_DDR_SCLK(40)) 58#define DDR_tRAS DDR_TRAS(MIN_DDR_SCLK(40))
55#define DDR_tRP DDR_TRP(MIN_DDR_SCLK(15)) 59#define DDR_tRP DDR_TRP(MIN_DDR_SCLK(15))
56#define DDR_tRFC DDR_TRFC(MIN_DDR_SCLK(70)) 60#define DDR_tRFC DDR_TRFC(MIN_DDR_SCLK(70))
57#define DDR_tREFI DDR_TREFI(MIN_DDR_SCLK(7800)) 61#define DDR_tREFI DDR_TREFI(MAX_DDR_SCLK(7800))
58 62
59#define DDR_tRCD DDR_TRCD(MIN_DDR_SCLK(15)) 63#define DDR_tRCD DDR_TRCD(MIN_DDR_SCLK(15))
60#define DDR_tWTR DDR_TWTR(2) 64#define DDR_tWTR DDR_TWTR(2)
@@ -65,6 +69,7 @@
65#if (CONFIG_MEM_GENERIC_BOARD) 69#if (CONFIG_MEM_GENERIC_BOARD)
66#define DDR_SIZE DEVSZ_512 70#define DDR_SIZE DEVSZ_512
67#define DDR_WIDTH DEVWD_16 71#define DDR_WIDTH DEVWD_16
72#define DDR_MAX_tCK 13
68 73
69#define DDR_tRCD DDR_TRCD(3) 74#define DDR_tRCD DDR_TRCD(3)
70#define DDR_tWTR DDR_TWTR(2) 75#define DDR_tWTR DDR_TWTR(2)
@@ -77,14 +82,15 @@
77#define DDR_tREFI DDR_TREFI(1288) 82#define DDR_tREFI DDR_TREFI(1288)
78#endif 83#endif
79 84
80#if (CONFIG_SCLK_HZ <= 133333333) 85#if (CONFIG_SCLK_HZ < DDR_CLK_HZ(DDR_MAX_tCK))
81#define DDR_CL CL_2 86# error "CONFIG_SCLK_HZ is too small (<DDR_CLK_HZ(DDR_MAX_tCK) Hz)."
82#elif (CONFIG_SCLK_HZ <= 166666666) 87#elif(CONFIG_SCLK_HZ <= 133333333)
83#define DDR_CL CL_2_5 88# define DDR_CL CL_2
84#else 89#else
85#define DDR_CL CL_3 90# error "CONFIG_SCLK_HZ is too large (>133333333 Hz)."
86#endif 91#endif
87 92
93
88#define mem_DDRCTL0 (DDR_tRP | DDR_tRAS | DDR_tRC | DDR_tRFC | DDR_tREFI) 94#define mem_DDRCTL0 (DDR_tRP | DDR_tRAS | DDR_tRC | DDR_tRFC | DDR_tREFI)
89#define mem_DDRCTL1 (DDR_DATWIDTH | EXTBANK_1 | DDR_SIZE | DDR_WIDTH | DDR_tWTR \ 95#define mem_DDRCTL1 (DDR_DATWIDTH | EXTBANK_1 | DDR_SIZE | DDR_WIDTH | DDR_tWTR \
90 | DDR_tMRD | DDR_tWR | DDR_tRCD) 96 | DDR_tMRD | DDR_tWR | DDR_tRCD)
diff --git a/include/asm-blackfin/mach-bf561/anomaly.h b/include/asm-blackfin/mach-bf561/anomaly.h
index 0c1d46193939..82157caa96a2 100644
--- a/include/asm-blackfin/mach-bf561/anomaly.h
+++ b/include/asm-blackfin/mach-bf561/anomaly.h
@@ -7,7 +7,7 @@
7 */ 7 */
8 8
9/* This file shoule be up to date with: 9/* This file shoule be up to date with:
10 * - Revision O, 11/15/2007; ADSP-BF561 Blackfin Processor Anomaly List 10 * - Revision P, 02/08/2008; ADSP-BF561 Blackfin Processor Anomaly List
11 */ 11 */
12 12
13#ifndef _MACH_ANOMALY_H_ 13#ifndef _MACH_ANOMALY_H_
@@ -256,10 +256,14 @@
256#define ANOMALY_05000357 (1) 256#define ANOMALY_05000357 (1)
257/* Conflicting Column Address Widths Causes SDRAM Errors */ 257/* Conflicting Column Address Widths Causes SDRAM Errors */
258#define ANOMALY_05000362 (1) 258#define ANOMALY_05000362 (1)
259/* UART Break Signal Issues */
260#define ANOMALY_05000363 (__SILICON_REVISION__ < 5)
259/* PPI Underflow Error Goes Undetected in ITU-R 656 Mode */ 261/* PPI Underflow Error Goes Undetected in ITU-R 656 Mode */
260#define ANOMALY_05000366 (1) 262#define ANOMALY_05000366 (1)
261/* Possible RETS Register Corruption when Subroutine Is under 5 Cycles in Duration */ 263/* Possible RETS Register Corruption when Subroutine Is under 5 Cycles in Duration */
262#define ANOMALY_05000371 (1) 264#define ANOMALY_05000371 (1)
265/* Level-Sensitive External GPIO Wakeups May Cause Indefinite Stall */
266#define ANOMALY_05000403 (1)
263 267
264/* Anomalies that don't exist on this proc */ 268/* Anomalies that don't exist on this proc */
265#define ANOMALY_05000158 (0) 269#define ANOMALY_05000158 (0)
diff --git a/include/asm-blackfin/mach-bf561/bfin_serial_5xx.h b/include/asm-blackfin/mach-bf561/bfin_serial_5xx.h
index b6f513bee56e..8a4e66d1db37 100644
--- a/include/asm-blackfin/mach-bf561/bfin_serial_5xx.h
+++ b/include/asm-blackfin/mach-bf561/bfin_serial_5xx.h
@@ -1,22 +1,38 @@
1/*
2 * file: include/asm-blackfin/mach-bf561/bfin_serial_5xx.h
3 * based on:
4 * author:
5 *
6 * created:
7 * description:
8 * blackfin serial driver head file
9 * rev:
10 *
11 * modified:
12 *
13 *
14 * bugs: enter bugs at http://blackfin.uclinux.org/
15 *
16 * this program is free software; you can redistribute it and/or modify
17 * it under the terms of the gnu general public license as published by
18 * the free software foundation; either version 2, or (at your option)
19 * any later version.
20 *
21 * this program is distributed in the hope that it will be useful,
22 * but without any warranty; without even the implied warranty of
23 * merchantability or fitness for a particular purpose. see the
24 * gnu general public license for more details.
25 *
26 * you should have received a copy of the gnu general public license
27 * along with this program; see the file copying.
28 * if not, write to the free software foundation,
29 * 59 temple place - suite 330, boston, ma 02111-1307, usa.
30 */
31
1#include <linux/serial.h> 32#include <linux/serial.h>
2#include <asm/dma.h> 33#include <asm/dma.h>
3#include <asm/portmux.h> 34#include <asm/portmux.h>
4 35
5#define NR_PORTS 1
6
7#define OFFSET_THR 0x00 /* Transmit Holding register */
8#define OFFSET_RBR 0x00 /* Receive Buffer register */
9#define OFFSET_DLL 0x00 /* Divisor Latch (Low-Byte) */
10#define OFFSET_IER 0x04 /* Interrupt Enable Register */
11#define OFFSET_DLH 0x04 /* Divisor Latch (High-Byte) */
12#define OFFSET_IIR 0x08 /* Interrupt Identification Register */
13#define OFFSET_LCR 0x0C /* Line Control Register */
14#define OFFSET_MCR 0x10 /* Modem Control Register */
15#define OFFSET_LSR 0x14 /* Line Status Register */
16#define OFFSET_MSR 0x18 /* Modem Status Register */
17#define OFFSET_SCR 0x1C /* SCR Scratch Register */
18#define OFFSET_GCTL 0x24 /* Global Control Register */
19
20#define UART_GET_CHAR(uart) bfin_read16(((uart)->port.membase + OFFSET_RBR)) 36#define UART_GET_CHAR(uart) bfin_read16(((uart)->port.membase + OFFSET_RBR))
21#define UART_GET_DLL(uart) bfin_read16(((uart)->port.membase + OFFSET_DLL)) 37#define UART_GET_DLL(uart) bfin_read16(((uart)->port.membase + OFFSET_DLL))
22#define UART_GET_IER(uart) bfin_read16(((uart)->port.membase + OFFSET_IER)) 38#define UART_GET_IER(uart) bfin_read16(((uart)->port.membase + OFFSET_IER))
@@ -84,7 +100,7 @@ static inline void UART_CLEAR_LSR(struct bfin_serial_port *uart)
84 bfin_write16(uart->port.membase + OFFSET_LSR, -1); 100 bfin_write16(uart->port.membase + OFFSET_LSR, -1);
85} 101}
86 102
87struct bfin_serial_port bfin_serial_ports[NR_PORTS]; 103struct bfin_serial_port bfin_serial_ports[BFIN_UART_NR_PORTS];
88struct bfin_serial_res { 104struct bfin_serial_res {
89 unsigned long uart_base_addr; 105 unsigned long uart_base_addr;
90 int uart_irq; 106 int uart_irq;
@@ -115,7 +131,7 @@ struct bfin_serial_res bfin_serial_resource[] = {
115 131
116#define DRIVER_NAME "bfin-uart" 132#define DRIVER_NAME "bfin-uart"
117 133
118int nr_ports = NR_PORTS; 134int nr_ports = BFIN_UART_NR_PORTS;
119static void bfin_serial_hw_init(struct bfin_serial_port *uart) 135static void bfin_serial_hw_init(struct bfin_serial_port *uart)
120{ 136{
121 137
diff --git a/include/asm-blackfin/mach-bf561/bfin_sir.h b/include/asm-blackfin/mach-bf561/bfin_sir.h
new file mode 100644
index 000000000000..cefcf8bb505b
--- /dev/null
+++ b/include/asm-blackfin/mach-bf561/bfin_sir.h
@@ -0,0 +1,120 @@
1/*
2 * Blackfin Infra-red Driver
3 *
4 * Copyright 2006-2008 Analog Devices Inc.
5 *
6 * Enter bugs at http://blackfin.uclinux.org/
7 *
8 * Licensed under the GPL-2 or later.
9 *
10 */
11
12#include <linux/serial.h>
13#include <asm/dma.h>
14#include <asm/portmux.h>
15
16#define SIR_UART_GET_CHAR(port) bfin_read16((port)->membase + OFFSET_RBR)
17#define SIR_UART_GET_DLL(port) bfin_read16((port)->membase + OFFSET_DLL)
18#define SIR_UART_GET_IER(port) bfin_read16((port)->membase + OFFSET_IER)
19#define SIR_UART_GET_DLH(port) bfin_read16((port)->membase + OFFSET_DLH)
20#define SIR_UART_GET_IIR(port) bfin_read16((port)->membase + OFFSET_IIR)
21#define SIR_UART_GET_LCR(port) bfin_read16((port)->membase + OFFSET_LCR)
22#define SIR_UART_GET_GCTL(port) bfin_read16((port)->membase + OFFSET_GCTL)
23
24#define SIR_UART_PUT_CHAR(port, v) bfin_write16(((port)->membase + OFFSET_THR), v)
25#define SIR_UART_PUT_DLL(port, v) bfin_write16(((port)->membase + OFFSET_DLL), v)
26#define SIR_UART_PUT_IER(port, v) bfin_write16(((port)->membase + OFFSET_IER), v)
27#define SIR_UART_PUT_DLH(port, v) bfin_write16(((port)->membase + OFFSET_DLH), v)
28#define SIR_UART_PUT_LCR(port, v) bfin_write16(((port)->membase + OFFSET_LCR), v)
29#define SIR_UART_PUT_GCTL(port, v) bfin_write16(((port)->membase + OFFSET_GCTL), v)
30
31#ifdef CONFIG_SIR_BFIN_DMA
32struct dma_rx_buf {
33 char *buf;
34 int head;
35 int tail;
36 };
37#endif /* CONFIG_SIR_BFIN_DMA */
38
39struct bfin_sir_port {
40 unsigned char __iomem *membase;
41 unsigned int irq;
42 unsigned int lsr;
43 unsigned long clk;
44 struct net_device *dev;
45#ifdef CONFIG_SIR_BFIN_DMA
46 int tx_done;
47 struct dma_rx_buf rx_dma_buf;
48 struct timer_list rx_dma_timer;
49 int rx_dma_nrows;
50#endif /* CONFIG_SIR_BFIN_DMA */
51 unsigned int tx_dma_channel;
52 unsigned int rx_dma_channel;
53};
54
55struct bfin_sir_port sir_ports[BFIN_UART_NR_PORTS];
56
57struct bfin_sir_port_res {
58 unsigned long base_addr;
59 int irq;
60 unsigned int rx_dma_channel;
61 unsigned int tx_dma_channel;
62};
63
64struct bfin_sir_port_res bfin_sir_port_resource[] = {
65#ifdef CONFIG_BFIN_SIR0
66 {
67 0xFFC00400,
68 IRQ_UART_RX,
69 CH_UART_RX,
70 CH_UART_TX,
71 },
72#endif
73};
74
75int nr_sirs = ARRAY_SIZE(bfin_sir_port_resource);
76
77struct bfin_sir_self {
78 struct bfin_sir_port *sir_port;
79 spinlock_t lock;
80 unsigned int open;
81 int speed;
82 int newspeed;
83
84 struct sk_buff *txskb;
85 struct sk_buff *rxskb;
86 struct net_device_stats stats;
87 struct device *dev;
88 struct irlap_cb *irlap;
89 struct qos_info qos;
90
91 iobuff_t tx_buff;
92 iobuff_t rx_buff;
93
94 struct work_struct work;
95 int mtt;
96};
97
98static inline unsigned int SIR_UART_GET_LSR(struct bfin_sir_port *port)
99{
100 unsigned int lsr = bfin_read16(port->membase + OFFSET_LSR);
101 port->lsr |= (lsr & (BI|FE|PE|OE));
102 return lsr | port->lsr;
103}
104
105static inline void SIR_UART_CLEAR_LSR(struct bfin_sir_port *port)
106{
107 port->lsr = 0;
108 bfin_read16(port->membase + OFFSET_LSR);
109}
110
111#define DRIVER_NAME "bfin_sir"
112
113static void bfin_sir_hw_init(void)
114{
115#ifdef CONFIG_BFIN_SIR0
116 peripheral_request(P_UART0_TX, DRIVER_NAME);
117 peripheral_request(P_UART0_RX, DRIVER_NAME);
118#endif
119 SSYNC();
120}
diff --git a/include/asm-blackfin/mach-bf561/blackfin.h b/include/asm-blackfin/mach-bf561/blackfin.h
index 3a16df2c86d8..0ea8666e6764 100644
--- a/include/asm-blackfin/mach-bf561/blackfin.h
+++ b/include/asm-blackfin/mach-bf561/blackfin.h
@@ -69,5 +69,19 @@
69#define bfin_read_SIC_ISR(x) bfin_read32(SICA_ISR0 + (x << 2)) 69#define bfin_read_SIC_ISR(x) bfin_read32(SICA_ISR0 + (x << 2))
70#define bfin_write_SIC_ISR(x, val) bfin_write32((SICA_ISR0 + (x << 2)), val) 70#define bfin_write_SIC_ISR(x, val) bfin_write32((SICA_ISR0 + (x << 2)), val)
71 71
72#define BFIN_UART_NR_PORTS 1
73
74#define OFFSET_THR 0x00 /* Transmit Holding register */
75#define OFFSET_RBR 0x00 /* Receive Buffer register */
76#define OFFSET_DLL 0x00 /* Divisor Latch (Low-Byte) */
77#define OFFSET_IER 0x04 /* Interrupt Enable Register */
78#define OFFSET_DLH 0x04 /* Divisor Latch (High-Byte) */
79#define OFFSET_IIR 0x08 /* Interrupt Identification Register */
80#define OFFSET_LCR 0x0C /* Line Control Register */
81#define OFFSET_MCR 0x10 /* Modem Control Register */
82#define OFFSET_LSR 0x14 /* Line Status Register */
83#define OFFSET_MSR 0x18 /* Modem Status Register */
84#define OFFSET_SCR 0x1C /* SCR Scratch Register */
85#define OFFSET_GCTL 0x24 /* Global Control Register */
72 86
73#endif /* _MACH_BLACKFIN_H_ */ 87#endif /* _MACH_BLACKFIN_H_ */
diff --git a/include/asm-blackfin/mach-bf561/cdefBF561.h b/include/asm-blackfin/mach-bf561/cdefBF561.h
index 1bc8d2f89ccc..b07ffccd66dd 100644
--- a/include/asm-blackfin/mach-bf561/cdefBF561.h
+++ b/include/asm-blackfin/mach-bf561/cdefBF561.h
@@ -47,7 +47,30 @@
47 47
48/* Clock and System Control (0xFFC00000 - 0xFFC000FF) */ 48/* Clock and System Control (0xFFC00000 - 0xFFC000FF) */
49#define bfin_read_PLL_CTL() bfin_read16(PLL_CTL) 49#define bfin_read_PLL_CTL() bfin_read16(PLL_CTL)
50#define bfin_write_PLL_CTL(val) bfin_write16(PLL_CTL,val) 50/* Writing to PLL_CTL initiates a PLL relock sequence. */
51static __inline__ void bfin_write_PLL_CTL(unsigned int val)
52{
53 unsigned long flags, iwr0, iwr1;
54
55 if (val == bfin_read_PLL_CTL())
56 return;
57
58 local_irq_save(flags);
59 /* Enable the PLL Wakeup bit in SIC IWR */
60 iwr0 = bfin_read32(SICA_IWR0);
61 iwr1 = bfin_read32(SICA_IWR1);
62 /* Only allow PPL Wakeup) */
63 bfin_write32(SICA_IWR0, IWR_ENABLE(0));
64 bfin_write32(SICA_IWR1, 0);
65
66 bfin_write16(PLL_CTL, val);
67 SSYNC();
68 asm("IDLE;");
69
70 bfin_write32(SICA_IWR0, iwr0);
71 bfin_write32(SICA_IWR1, iwr1);
72 local_irq_restore(flags);
73}
51#define bfin_read_PLL_DIV() bfin_read16(PLL_DIV) 74#define bfin_read_PLL_DIV() bfin_read16(PLL_DIV)
52#define bfin_write_PLL_DIV(val) bfin_write16(PLL_DIV,val) 75#define bfin_write_PLL_DIV(val) bfin_write16(PLL_DIV,val)
53#define bfin_read_VR_CTL() bfin_read16(VR_CTL) 76#define bfin_read_VR_CTL() bfin_read16(VR_CTL)
@@ -56,6 +79,10 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
56{ 79{
57 unsigned long flags, iwr0, iwr1; 80 unsigned long flags, iwr0, iwr1;
58 81
82 if (val == bfin_read_VR_CTL())
83 return;
84
85 local_irq_save(flags);
59 /* Enable the PLL Wakeup bit in SIC IWR */ 86 /* Enable the PLL Wakeup bit in SIC IWR */
60 iwr0 = bfin_read32(SICA_IWR0); 87 iwr0 = bfin_read32(SICA_IWR0);
61 iwr1 = bfin_read32(SICA_IWR1); 88 iwr1 = bfin_read32(SICA_IWR1);
@@ -65,12 +92,11 @@ static __inline__ void bfin_write_VR_CTL(unsigned int val)
65 92
66 bfin_write16(VR_CTL, val); 93 bfin_write16(VR_CTL, val);
67 SSYNC(); 94 SSYNC();
68
69 local_irq_save(flags);
70 asm("IDLE;"); 95 asm("IDLE;");
71 local_irq_restore(flags); 96
72 bfin_write32(SICA_IWR0, iwr0); 97 bfin_write32(SICA_IWR0, iwr0);
73 bfin_write32(SICA_IWR1, iwr1); 98 bfin_write32(SICA_IWR1, iwr1);
99 local_irq_restore(flags);
74} 100}
75#define bfin_read_PLL_STAT() bfin_read16(PLL_STAT) 101#define bfin_read_PLL_STAT() bfin_read16(PLL_STAT)
76#define bfin_write_PLL_STAT(val) bfin_write16(PLL_STAT,val) 102#define bfin_write_PLL_STAT(val) bfin_write16(PLL_STAT,val)
diff --git a/include/asm-blackfin/mach-bf561/defBF561.h b/include/asm-blackfin/mach-bf561/defBF561.h
index c3c0eb13c819..366c9b9a0cb7 100644
--- a/include/asm-blackfin/mach-bf561/defBF561.h
+++ b/include/asm-blackfin/mach-bf561/defBF561.h
@@ -110,18 +110,23 @@
110#define WDOGB_STAT 0xFFC01208 /* Watchdog Status register */ 110#define WDOGB_STAT 0xFFC01208 /* Watchdog Status register */
111 111
112/* UART Controller (0xFFC00400 - 0xFFC004FF) */ 112/* UART Controller (0xFFC00400 - 0xFFC004FF) */
113#define UART_THR 0xFFC00400 /* Transmit Holding register */ 113
114#define UART_RBR 0xFFC00400 /* Receive Buffer register */ 114/*
115#define UART_DLL 0xFFC00400 /* Divisor Latch (Low-Byte) */ 115 * Because include/linux/serial_reg.h have defined UART_*,
116#define UART_IER 0xFFC00404 /* Interrupt Enable Register */ 116 * So we define blackfin uart regs to BFIN_UART0_*.
117#define UART_DLH 0xFFC00404 /* Divisor Latch (High-Byte) */ 117 */
118#define UART_IIR 0xFFC00408 /* Interrupt Identification Register */ 118#define BFIN_UART_THR 0xFFC00400 /* Transmit Holding register */
119#define UART_LCR 0xFFC0040C /* Line Control Register */ 119#define BFIN_UART_RBR 0xFFC00400 /* Receive Buffer register */
120#define UART_MCR 0xFFC00410 /* Modem Control Register */ 120#define BFIN_UART_DLL 0xFFC00400 /* Divisor Latch (Low-Byte) */
121#define UART_LSR 0xFFC00414 /* Line Status Register */ 121#define BFIN_UART_IER 0xFFC00404 /* Interrupt Enable Register */
122#define UART_MSR 0xFFC00418 /* Modem Status Register */ 122#define BFIN_UART_DLH 0xFFC00404 /* Divisor Latch (High-Byte) */
123#define UART_SCR 0xFFC0041C /* SCR Scratch Register */ 123#define BFIN_UART_IIR 0xFFC00408 /* Interrupt Identification Register */
124#define UART_GCTL 0xFFC00424 /* Global Control Register */ 124#define BFIN_UART_LCR 0xFFC0040C /* Line Control Register */
125#define BFIN_UART_MCR 0xFFC00410 /* Modem Control Register */
126#define BFIN_UART_LSR 0xFFC00414 /* Line Status Register */
127#define BFIN_UART_MSR 0xFFC00418 /* Modem Status Register */
128#define BFIN_UART_SCR 0xFFC0041C /* SCR Scratch Register */
129#define BFIN_UART_GCTL 0xFFC00424 /* Global Control Register */
125 130
126/* SPI Controller (0xFFC00500 - 0xFFC005FF) */ 131/* SPI Controller (0xFFC00500 - 0xFFC005FF) */
127#define SPI0_REGBASE 0xFFC00500 132#define SPI0_REGBASE 0xFFC00500
@@ -866,6 +871,8 @@
866/* PLL_DIV Masks */ 871/* PLL_DIV Masks */
867#define SCLK_DIV(x) (x) /* SCLK = VCO / x */ 872#define SCLK_DIV(x) (x) /* SCLK = VCO / x */
868 873
874#define CSEL 0x30 /* Core Select */
875#define SSEL 0xf /* System Select */
869#define CCLK_DIV1 0x00000000 /* CCLK = VCO / 1 */ 876#define CCLK_DIV1 0x00000000 /* CCLK = VCO / 1 */
870#define CCLK_DIV2 0x00000010 /* CCLK = VCO / 2 */ 877#define CCLK_DIV2 0x00000010 /* CCLK = VCO / 2 */
871#define CCLK_DIV4 0x00000020 /* CCLK = VCO / 4 */ 878#define CCLK_DIV4 0x00000020 /* CCLK = VCO / 4 */
diff --git a/include/asm-blackfin/mach-bf561/dma.h b/include/asm-blackfin/mach-bf561/dma.h
index 766334b7d8ab..21d982003e75 100644
--- a/include/asm-blackfin/mach-bf561/dma.h
+++ b/include/asm-blackfin/mach-bf561/dma.h
@@ -32,7 +32,4 @@
32#define CH_IMEM_STREAM1_SRC 34 32#define CH_IMEM_STREAM1_SRC 34
33#define CH_IMEM_STREAM1_DEST 35 33#define CH_IMEM_STREAM1_DEST 35
34 34
35extern int channel2irq(unsigned int channel);
36extern struct dma_register *base_addr[];
37
38#endif 35#endif
diff --git a/include/asm-blackfin/portmux.h b/include/asm-blackfin/portmux.h
index 0d3f650d2d99..0807b286cd9e 100644
--- a/include/asm-blackfin/portmux.h
+++ b/include/asm-blackfin/portmux.h
@@ -17,8 +17,8 @@
17 17
18int peripheral_request(unsigned short per, const char *label); 18int peripheral_request(unsigned short per, const char *label);
19void peripheral_free(unsigned short per); 19void peripheral_free(unsigned short per);
20int peripheral_request_list(unsigned short per[], const char *label); 20int peripheral_request_list(const unsigned short per[], const char *label);
21void peripheral_free_list(unsigned short per[]); 21void peripheral_free_list(const unsigned short per[]);
22 22
23#include <asm/gpio.h> 23#include <asm/gpio.h>
24#include <asm/mach/portmux.h> 24#include <asm/mach/portmux.h>
diff --git a/include/asm-blackfin/processor.h b/include/asm-blackfin/processor.h
index 1033e5c76011..1c0040724612 100644
--- a/include/asm-blackfin/processor.h
+++ b/include/asm-blackfin/processor.h
@@ -26,9 +26,10 @@ static inline void wrusp(unsigned long usp)
26 26
27/* 27/*
28 * User space process size: 1st byte beyond user address space. 28 * User space process size: 1st byte beyond user address space.
29 * Fairly meaningless on nommu. Parts of user programs can be scattered
30 * in a lot of places, so just disable this by setting it to 0xFFFFFFFF.
29 */ 31 */
30extern unsigned long memory_end; 32#define TASK_SIZE 0xFFFFFFFF
31#define TASK_SIZE (memory_end)
32 33
33#ifdef __KERNEL__ 34#ifdef __KERNEL__
34#define STACK_TOP TASK_SIZE 35#define STACK_TOP TASK_SIZE
diff --git a/include/asm-blackfin/signal.h b/include/asm-blackfin/signal.h
index 0250429b736a..87951d251458 100644
--- a/include/asm-blackfin/signal.h
+++ b/include/asm-blackfin/signal.h
@@ -143,7 +143,7 @@ struct sigaction {
143#endif /* __KERNEL__ */ 143#endif /* __KERNEL__ */
144 144
145typedef struct sigaltstack { 145typedef struct sigaltstack {
146 void *ss_sp; 146 void __user *ss_sp;
147 int ss_flags; 147 int ss_flags;
148 size_t ss_size; 148 size_t ss_size;
149} stack_t; 149} stack_t;
diff --git a/include/asm-blackfin/thread_info.h b/include/asm-blackfin/thread_info.h
index 15b99cf4f50b..bc2fe5accf20 100644
--- a/include/asm-blackfin/thread_info.h
+++ b/include/asm-blackfin/thread_info.h
@@ -81,14 +81,11 @@ struct thread_info {
81#define init_thread_info (init_thread_union.thread_info) 81#define init_thread_info (init_thread_union.thread_info)
82#define init_stack (init_thread_union.stack) 82#define init_stack (init_thread_union.stack)
83 83
84/* How to get the thread information struct from C */ 84/* Given a task stack pointer, you can find its corresponding
85 85 * thread_info structure just by masking it to the THREAD_SIZE
86static inline struct thread_info *current_thread_info(void) 86 * boundary (currently 8K as you can see above).
87 __attribute__ ((__const__));
88
89/* Given a task stack pointer, you can find it's task structure
90 * just by masking it to the 8K boundary.
91 */ 87 */
88__attribute_const__
92static inline struct thread_info *current_thread_info(void) 89static inline struct thread_info *current_thread_info(void)
93{ 90{
94 struct thread_info *ti; 91 struct thread_info *ti;
diff --git a/include/asm-blackfin/time.h b/include/asm-blackfin/time.h
new file mode 100644
index 000000000000..6e5859b6ea32
--- /dev/null
+++ b/include/asm-blackfin/time.h
@@ -0,0 +1,36 @@
1/*
2 * asm-blackfin/time.h:
3 *
4 * Copyright 2004-2008 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
7 */
8
9#ifndef _ASM_BLACKFIN_TIME_H
10#define _ASM_BLACKFIN_TIME_H
11
12/*
13 * The way that the Blackfin core timer works is:
14 * - CCLK is divided by a programmable 8-bit pre-scaler (TSCALE)
15 * - Every time TSCALE ticks, a 32bit is counted down (TCOUNT)
16 *
17 * If you take the fastest clock (1ns, or 1GHz to make the math work easier)
18 * 10ms is 10,000,000 clock ticks, which fits easy into a 32-bit counter
19 * (32 bit counter is 4,294,967,296ns or 4.2 seconds) so, we don't need
20 * to use TSCALE, and program it to zero (which is pass CCLK through).
21 * If you feel like using it, try to keep HZ * TIMESCALE to some
22 * value that divides easy (like power of 2).
23 */
24
25#ifndef CONFIG_CPU_FREQ
26#define TIME_SCALE 1
27#else
28/*
29 * Blackfin CPU frequency scaling supports max Core Clock 1, 1/2 and 1/4 .
30 * Whenever we change the Core Clock frequency changes we immediately
31 * adjust the Core Timer Presale Register. This way we don't lose time.
32 */
33#define TIME_SCALE 4
34#endif
35
36#endif
diff --git a/include/asm-blackfin/timex.h b/include/asm-blackfin/timex.h
index 828590117f51..22b0806161bb 100644
--- a/include/asm-blackfin/timex.h
+++ b/include/asm-blackfin/timex.h
@@ -1,18 +1,23 @@
1/* blackfin architecture timex specifications: Lineo Inc. 2001 1/*
2 * asm-blackfin/timex.h: cpu cycles!
2 * 3 *
3 * Based on: include/asm-m68knommu/timex.h 4 * Copyright 2004-2008 Analog Devices Inc.
5 *
6 * Licensed under the GPL-2 or later.
4 */ 7 */
5 8
6#ifndef _ASMBLACKFIN_TIMEX_H 9#ifndef _ASM_BLACKFIN_TIMEX_H
7#define _ASMBLACKFIN_TIMEX_H 10#define _ASM_BLACKFIN_TIMEX_H
8 11
9#define CLOCK_TICK_RATE 1000000 /* Underlying HZ */ 12#define CLOCK_TICK_RATE 1000000 /* Underlying HZ */
10 13
11typedef unsigned long cycles_t; 14typedef unsigned long long cycles_t;
12 15
13static inline cycles_t get_cycles(void) 16static inline cycles_t get_cycles(void)
14{ 17{
15 return 0; 18 unsigned long tmp, tmp2;
19 __asm__("%0 = cycles; %1 = cycles2;" : "=d"(tmp), "=d"(tmp2));
20 return tmp | ((cycles_t)tmp2 << 32);
16} 21}
17 22
18#endif 23#endif
diff --git a/include/asm-blackfin/trace.h b/include/asm-blackfin/trace.h
index ef18afbc2101..312b596b9731 100644
--- a/include/asm-blackfin/trace.h
+++ b/include/asm-blackfin/trace.h
@@ -62,14 +62,14 @@ extern unsigned long software_trace_buff[];
62 preg.L = LO(TBUFCTL); \ 62 preg.L = LO(TBUFCTL); \
63 preg.H = HI(TBUFCTL); \ 63 preg.H = HI(TBUFCTL); \
64 dreg = [preg]; \ 64 dreg = [preg]; \
65 [sp++] = dreg; \ 65 [--sp] = dreg; \
66 dreg = 0x1; \ 66 dreg = 0x1; \
67 [preg] = dreg; 67 [preg] = dreg;
68 68
69#define trace_buffer_restore(preg, dreg) \ 69#define trace_buffer_restore(preg, dreg) \
70 preg.L = LO(TBUFCTL); \ 70 preg.L = LO(TBUFCTL); \
71 preg.H = HI(TBUFCTL); \ 71 preg.H = HI(TBUFCTL); \
72 dreg = [sp--]; \ 72 dreg = [sp++]; \
73 [preg] = dreg; 73 [preg] = dreg;
74 74
75#else /* CONFIG_DEBUG_BFIN_HWTRACE_ON */ 75#else /* CONFIG_DEBUG_BFIN_HWTRACE_ON */
diff --git a/include/asm-blackfin/uaccess.h b/include/asm-blackfin/uaccess.h
index 22a410b8003b..d928b8099056 100644
--- a/include/asm-blackfin/uaccess.h
+++ b/include/asm-blackfin/uaccess.h
@@ -133,7 +133,7 @@ static inline int bad_user_access_length(void)
133} 133}
134 134
135#define __put_user_bad() (printk(KERN_INFO "put_user_bad %s:%d %s\n",\ 135#define __put_user_bad() (printk(KERN_INFO "put_user_bad %s:%d %s\n",\
136 __FILE__, __LINE__, __FUNCTION__),\ 136 __FILE__, __LINE__, __func__),\
137 bad_user_access_length(), (-EFAULT)) 137 bad_user_access_length(), (-EFAULT))
138 138
139/* 139/*
@@ -177,7 +177,7 @@ static inline int bad_user_access_length(void)
177 default: \ 177 default: \
178 x = 0; \ 178 x = 0; \
179 printk(KERN_INFO "get_user_bad: %s:%d %s\n", \ 179 printk(KERN_INFO "get_user_bad: %s:%d %s\n", \
180 __FILE__, __LINE__, __FUNCTION__); \ 180 __FILE__, __LINE__, __func__); \
181 _err = __get_user_bad(); \ 181 _err = __get_user_bad(); \
182 break; \ 182 break; \
183 } \ 183 } \
diff --git a/include/asm-blackfin/unistd.h b/include/asm-blackfin/unistd.h
index c18a399f6e3e..42955d0c439b 100644
--- a/include/asm-blackfin/unistd.h
+++ b/include/asm-blackfin/unistd.h
@@ -265,14 +265,14 @@
265 /* 258 __NR_remap_file_pages */ 265 /* 258 __NR_remap_file_pages */
266#define __NR_set_tid_address 259 266#define __NR_set_tid_address 259
267#define __NR_timer_create 260 267#define __NR_timer_create 260
268#define __NR_timer_settime (__NR_timer_create+1) 268#define __NR_timer_settime 261
269#define __NR_timer_gettime (__NR_timer_create+2) 269#define __NR_timer_gettime 262
270#define __NR_timer_getoverrun (__NR_timer_create+3) 270#define __NR_timer_getoverrun 263
271#define __NR_timer_delete (__NR_timer_create+4) 271#define __NR_timer_delete 264
272#define __NR_clock_settime (__NR_timer_create+5) 272#define __NR_clock_settime 265
273#define __NR_clock_gettime (__NR_timer_create+6) 273#define __NR_clock_gettime 266
274#define __NR_clock_getres (__NR_timer_create+7) 274#define __NR_clock_getres 267
275#define __NR_clock_nanosleep (__NR_timer_create+8) 275#define __NR_clock_nanosleep 268
276#define __NR_statfs64 269 276#define __NR_statfs64 269
277#define __NR_fstatfs64 270 277#define __NR_fstatfs64 270
278#define __NR_tgkill 271 278#define __NR_tgkill 271
@@ -283,11 +283,11 @@
283 /* 276 __NR_get_mempolicy */ 283 /* 276 __NR_get_mempolicy */
284 /* 277 __NR_set_mempolicy */ 284 /* 277 __NR_set_mempolicy */
285#define __NR_mq_open 278 285#define __NR_mq_open 278
286#define __NR_mq_unlink (__NR_mq_open+1) 286#define __NR_mq_unlink 279
287#define __NR_mq_timedsend (__NR_mq_open+2) 287#define __NR_mq_timedsend 280
288#define __NR_mq_timedreceive (__NR_mq_open+3) 288#define __NR_mq_timedreceive 281
289#define __NR_mq_notify (__NR_mq_open+4) 289#define __NR_mq_notify 282
290#define __NR_mq_getsetattr (__NR_mq_open+5) 290#define __NR_mq_getsetattr 283
291#define __NR_kexec_load 284 291#define __NR_kexec_load 284
292#define __NR_waitid 285 292#define __NR_waitid 285
293#define __NR_add_key 286 293#define __NR_add_key 286
diff --git a/include/asm-sparc/device.h b/include/asm-sparc/device.h
index 680e51d87374..19790eb99cc6 100644
--- a/include/asm-sparc/device.h
+++ b/include/asm-sparc/device.h
@@ -16,6 +16,8 @@ struct dev_archdata {
16 16
17 struct device_node *prom_node; 17 struct device_node *prom_node;
18 struct of_device *op; 18 struct of_device *op;
19
20 int numa_node;
19}; 21};
20 22
21#endif /* _ASM_SPARC_DEVICE_H */ 23#endif /* _ASM_SPARC_DEVICE_H */
diff --git a/include/asm-sparc/prom.h b/include/asm-sparc/prom.h
index df5dc4422483..fd55522481cd 100644
--- a/include/asm-sparc/prom.h
+++ b/include/asm-sparc/prom.h
@@ -77,6 +77,11 @@ extern int of_getintprop_default(struct device_node *np,
77 const char *name, 77 const char *name,
78 int def); 78 int def);
79extern int of_find_in_proplist(const char *list, const char *match, int len); 79extern int of_find_in_proplist(const char *list, const char *match, int len);
80#ifdef CONFIG_NUMA
81extern int of_node_to_nid(struct device_node *dp);
82#else
83#define of_node_to_nid(dp) (-1)
84#endif
80 85
81extern void prom_build_devicetree(void); 86extern void prom_build_devicetree(void);
82 87
diff --git a/include/asm-sparc64/iommu.h b/include/asm-sparc64/iommu.h
index 46325ddee23b..d7b9afcba08b 100644
--- a/include/asm-sparc64/iommu.h
+++ b/include/asm-sparc64/iommu.h
@@ -56,6 +56,7 @@ struct strbuf {
56}; 56};
57 57
58extern int iommu_table_init(struct iommu *iommu, int tsbsize, 58extern int iommu_table_init(struct iommu *iommu, int tsbsize,
59 u32 dma_offset, u32 dma_addr_mask); 59 u32 dma_offset, u32 dma_addr_mask,
60 int numa_node);
60 61
61#endif /* !(_SPARC64_IOMMU_H) */ 62#endif /* !(_SPARC64_IOMMU_H) */
diff --git a/include/asm-sparc64/mmzone.h b/include/asm-sparc64/mmzone.h
new file mode 100644
index 000000000000..ebf5986c12ed
--- /dev/null
+++ b/include/asm-sparc64/mmzone.h
@@ -0,0 +1,17 @@
1#ifndef _SPARC64_MMZONE_H
2#define _SPARC64_MMZONE_H
3
4#ifdef CONFIG_NEED_MULTIPLE_NODES
5
6extern struct pglist_data *node_data[];
7
8#define NODE_DATA(nid) (node_data[nid])
9#define node_start_pfn(nid) (NODE_DATA(nid)->node_start_pfn)
10#define node_end_pfn(nid) (NODE_DATA(nid)->node_end_pfn)
11
12extern int numa_cpu_lookup_table[];
13extern cpumask_t numa_cpumask_lookup_table[];
14
15#endif /* CONFIG_NEED_MULTIPLE_NODES */
16
17#endif /* _SPARC64_MMZONE_H */
diff --git a/include/asm-sparc64/numnodes.h b/include/asm-sparc64/numnodes.h
deleted file mode 100644
index 017e7e74f5e7..000000000000
--- a/include/asm-sparc64/numnodes.h
+++ /dev/null
@@ -1,6 +0,0 @@
1#ifndef _SPARC64_NUMNODES_H
2#define _SPARC64_NUMNODES_H
3
4#define NODES_SHIFT 0
5
6#endif /* !(_SPARC64_NUMNODES_H) */
diff --git a/include/asm-sparc64/ptrace.h b/include/asm-sparc64/ptrace.h
index 6da197803efc..b4b951d570bb 100644
--- a/include/asm-sparc64/ptrace.h
+++ b/include/asm-sparc64/ptrace.h
@@ -8,6 +8,8 @@
8 * stack during a system call and basically all traps. 8 * stack during a system call and basically all traps.
9 */ 9 */
10 10
11#define PT_REGS_MAGIC 0x57ac6c00
12
11#ifndef __ASSEMBLY__ 13#ifndef __ASSEMBLY__
12 14
13struct pt_regs { 15struct pt_regs {
@@ -16,7 +18,19 @@ struct pt_regs {
16 unsigned long tpc; 18 unsigned long tpc;
17 unsigned long tnpc; 19 unsigned long tnpc;
18 unsigned int y; 20 unsigned int y;
19 unsigned int fprs; 21
22 /* We encode a magic number, PT_REGS_MAGIC, along
23 * with the %tt (trap type) register value at trap
24 * entry time. The magic number allows us to identify
25 * accurately a trap stack frame in the stack
26 * unwinder, and the %tt value allows us to test
27 * things like "in a system call" etc. for an arbitray
28 * process.
29 *
30 * The PT_REGS_MAGIC is choosen such that it can be
31 * loaded completely using just a sethi instruction.
32 */
33 unsigned int magic;
20}; 34};
21 35
22struct pt_regs32 { 36struct pt_regs32 {
@@ -147,7 +161,7 @@ extern void __show_regs(struct pt_regs *);
147#define PT_V9_TPC 0x88 161#define PT_V9_TPC 0x88
148#define PT_V9_TNPC 0x90 162#define PT_V9_TNPC 0x90
149#define PT_V9_Y 0x98 163#define PT_V9_Y 0x98
150#define PT_V9_FPRS 0x9c 164#define PT_V9_MAGIC 0x9c
151#define PT_TSTATE PT_V9_TSTATE 165#define PT_TSTATE PT_V9_TSTATE
152#define PT_TPC PT_V9_TPC 166#define PT_TPC PT_V9_TPC
153#define PT_TNPC PT_V9_TNPC 167#define PT_TNPC PT_V9_TNPC
diff --git a/include/asm-sparc64/sparsemem.h b/include/asm-sparc64/sparsemem.h
index 77bcd2bfa53c..b99d4e4b6d28 100644
--- a/include/asm-sparc64/sparsemem.h
+++ b/include/asm-sparc64/sparsemem.h
@@ -3,7 +3,7 @@
3 3
4#ifdef __KERNEL__ 4#ifdef __KERNEL__
5 5
6#define SECTION_SIZE_BITS 31 6#define SECTION_SIZE_BITS 30
7#define MAX_PHYSADDR_BITS 42 7#define MAX_PHYSADDR_BITS 42
8#define MAX_PHYSMEM_BITS 42 8#define MAX_PHYSMEM_BITS 42
9 9
diff --git a/include/asm-sparc64/topology.h b/include/asm-sparc64/topology.h
index c6b557034f68..001c04027c82 100644
--- a/include/asm-sparc64/topology.h
+++ b/include/asm-sparc64/topology.h
@@ -1,6 +1,77 @@
1#ifndef _ASM_SPARC64_TOPOLOGY_H 1#ifndef _ASM_SPARC64_TOPOLOGY_H
2#define _ASM_SPARC64_TOPOLOGY_H 2#define _ASM_SPARC64_TOPOLOGY_H
3 3
4#ifdef CONFIG_NUMA
5
6#include <asm/mmzone.h>
7
8static inline int cpu_to_node(int cpu)
9{
10 return numa_cpu_lookup_table[cpu];
11}
12
13#define parent_node(node) (node)
14
15static inline cpumask_t node_to_cpumask(int node)
16{
17 return numa_cpumask_lookup_table[node];
18}
19
20/* Returns a pointer to the cpumask of CPUs on Node 'node'. */
21#define node_to_cpumask_ptr(v, node) \
22 cpumask_t *v = &(numa_cpumask_lookup_table[node])
23
24#define node_to_cpumask_ptr_next(v, node) \
25 v = &(numa_cpumask_lookup_table[node])
26
27static inline int node_to_first_cpu(int node)
28{
29 cpumask_t tmp;
30 tmp = node_to_cpumask(node);
31 return first_cpu(tmp);
32}
33
34struct pci_bus;
35#ifdef CONFIG_PCI
36extern int pcibus_to_node(struct pci_bus *pbus);
37#else
38static inline int pcibus_to_node(struct pci_bus *pbus)
39{
40 return -1;
41}
42#endif
43
44#define pcibus_to_cpumask(bus) \
45 (pcibus_to_node(bus) == -1 ? \
46 CPU_MASK_ALL : \
47 node_to_cpumask(pcibus_to_node(bus)))
48
49#define SD_NODE_INIT (struct sched_domain) { \
50 .min_interval = 8, \
51 .max_interval = 32, \
52 .busy_factor = 32, \
53 .imbalance_pct = 125, \
54 .cache_nice_tries = 2, \
55 .busy_idx = 3, \
56 .idle_idx = 2, \
57 .newidle_idx = 0, \
58 .wake_idx = 1, \
59 .forkexec_idx = 1, \
60 .flags = SD_LOAD_BALANCE \
61 | SD_BALANCE_FORK \
62 | SD_BALANCE_EXEC \
63 | SD_SERIALIZE \
64 | SD_WAKE_BALANCE, \
65 .last_balance = jiffies, \
66 .balance_interval = 1, \
67}
68
69#else /* CONFIG_NUMA */
70
71#include <asm-generic/topology.h>
72
73#endif /* !(CONFIG_NUMA) */
74
4#ifdef CONFIG_SMP 75#ifdef CONFIG_SMP
5#define topology_physical_package_id(cpu) (cpu_data(cpu).proc_id) 76#define topology_physical_package_id(cpu) (cpu_data(cpu).proc_id)
6#define topology_core_id(cpu) (cpu_data(cpu).core_id) 77#define topology_core_id(cpu) (cpu_data(cpu).core_id)
@@ -10,8 +81,6 @@
10#define smt_capable() (sparc64_multi_core) 81#define smt_capable() (sparc64_multi_core)
11#endif /* CONFIG_SMP */ 82#endif /* CONFIG_SMP */
12 83
13#include <asm-generic/topology.h>
14
15#define cpu_coregroup_map(cpu) (cpu_core_map[cpu]) 84#define cpu_coregroup_map(cpu) (cpu_core_map[cpu])
16 85
17#endif /* _ASM_SPARC64_TOPOLOGY_H */ 86#endif /* _ASM_SPARC64_TOPOLOGY_H */
diff --git a/include/asm-sparc64/ttable.h b/include/asm-sparc64/ttable.h
index 7208a777750e..d3cc4eff39a6 100644
--- a/include/asm-sparc64/ttable.h
+++ b/include/asm-sparc64/ttable.h
@@ -28,7 +28,7 @@
28 call routine; \ 28 call routine; \
29 add %sp, PTREGS_OFF, %o0; \ 29 add %sp, PTREGS_OFF, %o0; \
30 ba,pt %xcc, rtrap; \ 30 ba,pt %xcc, rtrap; \
31 clr %l6; \ 31 nop; \
32 nop; 32 nop;
33 33
34#define TRAP_7INSNS(routine) \ 34#define TRAP_7INSNS(routine) \
@@ -38,7 +38,7 @@
38 call routine; \ 38 call routine; \
39 add %sp, PTREGS_OFF, %o0; \ 39 add %sp, PTREGS_OFF, %o0; \
40 ba,pt %xcc, rtrap; \ 40 ba,pt %xcc, rtrap; \
41 clr %l6; 41 nop;
42 42
43#define TRAP_SAVEFPU(routine) \ 43#define TRAP_SAVEFPU(routine) \
44 sethi %hi(109f), %g7; \ 44 sethi %hi(109f), %g7; \
@@ -47,7 +47,7 @@
47 call routine; \ 47 call routine; \
48 add %sp, PTREGS_OFF, %o0; \ 48 add %sp, PTREGS_OFF, %o0; \
49 ba,pt %xcc, rtrap; \ 49 ba,pt %xcc, rtrap; \
50 clr %l6; \ 50 nop; \
51 nop; 51 nop;
52 52
53#define TRAP_NOSAVE(routine) \ 53#define TRAP_NOSAVE(routine) \
@@ -67,7 +67,7 @@
67 call routine; \ 67 call routine; \
68 add %sp, PTREGS_OFF, %o0; \ 68 add %sp, PTREGS_OFF, %o0; \
69 ba,pt %xcc, rtrap; \ 69 ba,pt %xcc, rtrap; \
70 clr %l6; \ 70 nop; \
71 nop; 71 nop;
72 72
73#define TRAP_ARG(routine, arg) \ 73#define TRAP_ARG(routine, arg) \
@@ -78,7 +78,7 @@
78 call routine; \ 78 call routine; \
79 mov arg, %o1; \ 79 mov arg, %o1; \
80 ba,pt %xcc, rtrap; \ 80 ba,pt %xcc, rtrap; \
81 clr %l6; 81 nop;
82 82
83#define TRAPTL1_ARG(routine, arg) \ 83#define TRAPTL1_ARG(routine, arg) \
84 sethi %hi(109f), %g7; \ 84 sethi %hi(109f), %g7; \
@@ -88,7 +88,7 @@
88 call routine; \ 88 call routine; \
89 mov arg, %o1; \ 89 mov arg, %o1; \
90 ba,pt %xcc, rtrap; \ 90 ba,pt %xcc, rtrap; \
91 clr %l6; 91 nop;
92 92
93#define SYSCALL_TRAP(routine, systbl) \ 93#define SYSCALL_TRAP(routine, systbl) \
94 sethi %hi(109f), %g7; \ 94 sethi %hi(109f), %g7; \
@@ -166,7 +166,7 @@
166 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1; \ 166 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1; \
167 add %l1, 4, %l2; \ 167 add %l1, 4, %l2; \
168 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]; \ 168 stx %l1, [%sp + PTREGS_OFF + PT_V9_TPC]; \
169 ba,pt %xcc, rtrap_clr_l6; \ 169 ba,pt %xcc, rtrap; \
170 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC]; 170 stx %l2, [%sp + PTREGS_OFF + PT_V9_TNPC];
171 171
172#ifdef CONFIG_KPROBES 172#ifdef CONFIG_KPROBES
diff --git a/include/linux/dvb/dmx.h b/include/linux/dvb/dmx.h
index c6a2353c4e68..402fb7a8d922 100644
--- a/include/linux/dvb/dmx.h
+++ b/include/linux/dvb/dmx.h
@@ -39,9 +39,10 @@ typedef enum
39 DMX_OUT_DECODER, /* Streaming directly to decoder. */ 39 DMX_OUT_DECODER, /* Streaming directly to decoder. */
40 DMX_OUT_TAP, /* Output going to a memory buffer */ 40 DMX_OUT_TAP, /* Output going to a memory buffer */
41 /* (to be retrieved via the read command).*/ 41 /* (to be retrieved via the read command).*/
42 DMX_OUT_TS_TAP /* Output multiplexed into a new TS */ 42 DMX_OUT_TS_TAP, /* Output multiplexed into a new TS */
43 /* (to be retrieved by reading from the */ 43 /* (to be retrieved by reading from the */
44 /* logical DVR device). */ 44 /* logical DVR device). */
45 DMX_OUT_TSDEMUX_TAP /* Like TS_TAP but retrieved from the DMX device */
45} dmx_output_t; 46} dmx_output_t;
46 47
47 48
diff --git a/include/linux/exportfs.h b/include/linux/exportfs.h
index adcbb05b120b..de8387b7ceb6 100644
--- a/include/linux/exportfs.h
+++ b/include/linux/exportfs.h
@@ -43,7 +43,7 @@ struct fid {
43 u32 parent_ino; 43 u32 parent_ino;
44 u32 parent_gen; 44 u32 parent_gen;
45 } i32; 45 } i32;
46 __u32 raw[6]; 46 __u32 raw[0];
47 }; 47 };
48}; 48};
49 49
diff --git a/include/linux/i2c-id.h b/include/linux/i2c-id.h
index b979112f74e0..32eb8bbe4831 100644
--- a/include/linux/i2c-id.h
+++ b/include/linux/i2c-id.h
@@ -125,6 +125,7 @@
125#define I2C_HW_B_CX2341X 0x010020 /* Conexant CX2341X MPEG encoder cards */ 125#define I2C_HW_B_CX2341X 0x010020 /* Conexant CX2341X MPEG encoder cards */
126#define I2C_HW_B_INTELFB 0x010021 /* intel framebuffer driver */ 126#define I2C_HW_B_INTELFB 0x010021 /* intel framebuffer driver */
127#define I2C_HW_B_CX23885 0x010022 /* conexant 23885 based tv cards (bus1) */ 127#define I2C_HW_B_CX23885 0x010022 /* conexant 23885 based tv cards (bus1) */
128#define I2C_HW_B_AU0828 0x010023 /* auvitek au0828 usb bridge */
128 129
129/* --- PCF 8584 based algorithms */ 130/* --- PCF 8584 based algorithms */
130#define I2C_HW_P_ELEK 0x020002 /* Elektor ISA Bus inteface card */ 131#define I2C_HW_P_ELEK 0x020002 /* Elektor ISA Bus inteface card */
diff --git a/include/linux/ieee80211.h b/include/linux/ieee80211.h
index f27d11ab418b..529f301d9372 100644
--- a/include/linux/ieee80211.h
+++ b/include/linux/ieee80211.h
@@ -465,13 +465,19 @@ enum ieee80211_eid {
465 WLAN_EID_TS_DELAY = 43, 465 WLAN_EID_TS_DELAY = 43,
466 WLAN_EID_TCLAS_PROCESSING = 44, 466 WLAN_EID_TCLAS_PROCESSING = 44,
467 WLAN_EID_QOS_CAPA = 46, 467 WLAN_EID_QOS_CAPA = 46,
468 /* 802.11s */ 468 /* 802.11s
469 WLAN_EID_MESH_CONFIG = 36, /* Pending IEEE 802.11 ANA approval */ 469 *
470 WLAN_EID_MESH_ID = 37, /* Pending IEEE 802.11 ANA approval */ 470 * All mesh EID numbers are pending IEEE 802.11 ANA approval.
471 WLAN_EID_PEER_LINK = 40, /* Pending IEEE 802.11 ANA approval */ 471 * The numbers have been incremented from those suggested in
472 WLAN_EID_PREQ = 53, /* Pending IEEE 802.11 ANA approval */ 472 * 802.11s/D2.0 so that MESH_CONFIG does not conflict with
473 WLAN_EID_PREP = 54, /* Pending IEEE 802.11 ANA approval */ 473 * EXT_SUPP_RATES.
474 WLAN_EID_PERR = 55, /* Pending IEEE 802.11 ANA approval */ 474 */
475 WLAN_EID_MESH_CONFIG = 51,
476 WLAN_EID_MESH_ID = 52,
477 WLAN_EID_PEER_LINK = 55,
478 WLAN_EID_PREQ = 68,
479 WLAN_EID_PREP = 69,
480 WLAN_EID_PERR = 70,
475 /* 802.11h */ 481 /* 802.11h */
476 WLAN_EID_PWR_CONSTRAINT = 32, 482 WLAN_EID_PWR_CONSTRAINT = 32,
477 WLAN_EID_PWR_CAPABILITY = 33, 483 WLAN_EID_PWR_CAPABILITY = 33,
diff --git a/include/linux/lockd/lockd.h b/include/linux/lockd/lockd.h
index 4babb2a129ac..94649a8da014 100644
--- a/include/linux/lockd/lockd.h
+++ b/include/linux/lockd/lockd.h
@@ -91,6 +91,7 @@ struct nlm_wait;
91 */ 91 */
92#define NLMCLNT_OHSIZE ((__NEW_UTS_LEN) + 10u) 92#define NLMCLNT_OHSIZE ((__NEW_UTS_LEN) + 10u)
93struct nlm_rqst { 93struct nlm_rqst {
94 atomic_t a_count;
94 unsigned int a_flags; /* initial RPC task flags */ 95 unsigned int a_flags; /* initial RPC task flags */
95 struct nlm_host * a_host; /* host handle */ 96 struct nlm_host * a_host; /* host handle */
96 struct nlm_args a_args; /* arguments */ 97 struct nlm_args a_args; /* arguments */
@@ -173,8 +174,10 @@ void nlmclnt_next_cookie(struct nlm_cookie *);
173/* 174/*
174 * Host cache 175 * Host cache
175 */ 176 */
176struct nlm_host *nlmclnt_lookup_host(const struct sockaddr_in *, int, int, 177struct nlm_host *nlmclnt_lookup_host(const struct sockaddr_in *sin,
177 const char *, unsigned int); 178 int proto, u32 version,
179 const char *hostname,
180 unsigned int hostname_len);
178struct nlm_host *nlmsvc_lookup_host(struct svc_rqst *, const char *, 181struct nlm_host *nlmsvc_lookup_host(struct svc_rqst *, const char *,
179 unsigned int); 182 unsigned int);
180struct rpc_clnt * nlm_bind_host(struct nlm_host *); 183struct rpc_clnt * nlm_bind_host(struct nlm_host *);
@@ -217,8 +220,7 @@ void nlmsvc_mark_resources(void);
217void nlmsvc_free_host_resources(struct nlm_host *); 220void nlmsvc_free_host_resources(struct nlm_host *);
218void nlmsvc_invalidate_all(void); 221void nlmsvc_invalidate_all(void);
219 222
220static __inline__ struct inode * 223static inline struct inode *nlmsvc_file_inode(struct nlm_file *file)
221nlmsvc_file_inode(struct nlm_file *file)
222{ 224{
223 return file->f_file->f_path.dentry->d_inode; 225 return file->f_file->f_path.dentry->d_inode;
224} 226}
@@ -226,8 +228,8 @@ nlmsvc_file_inode(struct nlm_file *file)
226/* 228/*
227 * Compare two host addresses (needs modifying for ipv6) 229 * Compare two host addresses (needs modifying for ipv6)
228 */ 230 */
229static __inline__ int 231static inline int nlm_cmp_addr(const struct sockaddr_in *sin1,
230nlm_cmp_addr(const struct sockaddr_in *sin1, const struct sockaddr_in *sin2) 232 const struct sockaddr_in *sin2)
231{ 233{
232 return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr; 234 return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr;
233} 235}
@@ -236,8 +238,8 @@ nlm_cmp_addr(const struct sockaddr_in *sin1, const struct sockaddr_in *sin2)
236 * Compare two NLM locks. 238 * Compare two NLM locks.
237 * When the second lock is of type F_UNLCK, this acts like a wildcard. 239 * When the second lock is of type F_UNLCK, this acts like a wildcard.
238 */ 240 */
239static __inline__ int 241static inline int nlm_compare_locks(const struct file_lock *fl1,
240nlm_compare_locks(const struct file_lock *fl1, const struct file_lock *fl2) 242 const struct file_lock *fl2)
241{ 243{
242 return fl1->fl_pid == fl2->fl_pid 244 return fl1->fl_pid == fl2->fl_pid
243 && fl1->fl_owner == fl2->fl_owner 245 && fl1->fl_owner == fl2->fl_owner
diff --git a/include/linux/lockd/sm_inter.h b/include/linux/lockd/sm_inter.h
index 22a645828f26..5a5448bdb17d 100644
--- a/include/linux/lockd/sm_inter.h
+++ b/include/linux/lockd/sm_inter.h
@@ -19,6 +19,7 @@
19#define SM_NOTIFY 6 19#define SM_NOTIFY 6
20 20
21#define SM_MAXSTRLEN 1024 21#define SM_MAXSTRLEN 1024
22#define SM_PRIV_SIZE 16
22 23
23/* 24/*
24 * Arguments for all calls to statd 25 * Arguments for all calls to statd
diff --git a/include/linux/meye.h b/include/linux/meye.h
index 39fd9c8ddd4b..12010ace1f04 100644
--- a/include/linux/meye.h
+++ b/include/linux/meye.h
@@ -58,7 +58,7 @@ struct meye_params {
58 58
59/* V4L2 private controls */ 59/* V4L2 private controls */
60#define V4L2_CID_AGC V4L2_CID_PRIVATE_BASE 60#define V4L2_CID_AGC V4L2_CID_PRIVATE_BASE
61#define V4L2_CID_SHARPNESS (V4L2_CID_PRIVATE_BASE + 1) 61#define V4L2_CID_MEYE_SHARPNESS (V4L2_CID_PRIVATE_BASE + 1)
62#define V4L2_CID_PICTURE (V4L2_CID_PRIVATE_BASE + 2) 62#define V4L2_CID_PICTURE (V4L2_CID_PRIVATE_BASE + 2)
63#define V4L2_CID_JPEGQUAL (V4L2_CID_PRIVATE_BASE + 3) 63#define V4L2_CID_JPEGQUAL (V4L2_CID_PRIVATE_BASE + 3)
64#define V4L2_CID_FRAMERATE (V4L2_CID_PRIVATE_BASE + 4) 64#define V4L2_CID_FRAMERATE (V4L2_CID_PRIVATE_BASE + 4)
diff --git a/include/linux/nfs3.h b/include/linux/nfs3.h
index 7f11fa589207..539f3b550eab 100644
--- a/include/linux/nfs3.h
+++ b/include/linux/nfs3.h
@@ -96,7 +96,7 @@ struct nfs3_fh {
96#define MOUNTPROC3_UMNTALL 4 96#define MOUNTPROC3_UMNTALL 4
97 97
98 98
99#if defined(__KERNEL__) || defined(NFS_NEED_KERNEL_TYPES) 99#if defined(__KERNEL__)
100 100
101/* Number of 32bit words in post_op_attr */ 101/* Number of 32bit words in post_op_attr */
102#define NFS3_POST_OP_ATTR_WORDS 22 102#define NFS3_POST_OP_ATTR_WORDS 22
diff --git a/include/linux/nfs_fs.h b/include/linux/nfs_fs.h
index f4a0e4c218df..27d6a8d98cef 100644
--- a/include/linux/nfs_fs.h
+++ b/include/linux/nfs_fs.h
@@ -430,7 +430,6 @@ extern void nfs_unregister_sysctl(void);
430/* 430/*
431 * linux/fs/nfs/namespace.c 431 * linux/fs/nfs/namespace.c
432 */ 432 */
433extern struct list_head nfs_automount_list;
434extern const struct inode_operations nfs_mountpoint_inode_operations; 433extern const struct inode_operations nfs_mountpoint_inode_operations;
435extern const struct inode_operations nfs_referral_inode_operations; 434extern const struct inode_operations nfs_referral_inode_operations;
436extern int nfs_mountpoint_expiry_timeout; 435extern int nfs_mountpoint_expiry_timeout;
@@ -466,9 +465,9 @@ extern int nfs_wb_page(struct inode *inode, struct page* page);
466extern int nfs_wb_page_cancel(struct inode *inode, struct page* page); 465extern int nfs_wb_page_cancel(struct inode *inode, struct page* page);
467#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4) 466#if defined(CONFIG_NFS_V3) || defined(CONFIG_NFS_V4)
468extern int nfs_commit_inode(struct inode *, int); 467extern int nfs_commit_inode(struct inode *, int);
469extern struct nfs_write_data *nfs_commit_alloc(void); 468extern struct nfs_write_data *nfs_commitdata_alloc(void);
470extern void nfs_commit_free(struct nfs_write_data *wdata); 469extern void nfs_commit_free(struct nfs_write_data *wdata);
471extern void nfs_commit_release(void *wdata); 470extern void nfs_commitdata_release(void *wdata);
472#else 471#else
473static inline int 472static inline int
474nfs_commit_inode(struct inode *inode, int how) 473nfs_commit_inode(struct inode *inode, int how)
diff --git a/include/linux/nfs_fs_sb.h b/include/linux/nfs_fs_sb.h
index 3423c6761bf7..c9beacd16c00 100644
--- a/include/linux/nfs_fs_sb.h
+++ b/include/linux/nfs_fs_sb.h
@@ -32,6 +32,8 @@ struct nfs_client {
32 const struct nfs_rpc_ops *rpc_ops; /* NFS protocol vector */ 32 const struct nfs_rpc_ops *rpc_ops; /* NFS protocol vector */
33 int cl_proto; /* Network transport protocol */ 33 int cl_proto; /* Network transport protocol */
34 34
35 struct rpc_cred *cl_machine_cred;
36
35#ifdef CONFIG_NFS_V4 37#ifdef CONFIG_NFS_V4
36 u64 cl_clientid; /* constant */ 38 u64 cl_clientid; /* constant */
37 nfs4_verifier cl_confirm; 39 nfs4_verifier cl_confirm;
@@ -93,6 +95,7 @@ struct nfs_server {
93 unsigned int wpages; /* write size (in pages) */ 95 unsigned int wpages; /* write size (in pages) */
94 unsigned int wtmult; /* server disk block size */ 96 unsigned int wtmult; /* server disk block size */
95 unsigned int dtsize; /* readdir size */ 97 unsigned int dtsize; /* readdir size */
98 unsigned short port; /* "port=" setting */
96 unsigned int bsize; /* server block size */ 99 unsigned int bsize; /* server block size */
97 unsigned int acregmin; /* attr cache timeouts */ 100 unsigned int acregmin; /* attr cache timeouts */
98 unsigned int acregmax; 101 unsigned int acregmax;
@@ -117,6 +120,13 @@ struct nfs_server {
117 120
118 atomic_t active; /* Keep trace of any activity to this server */ 121 atomic_t active; /* Keep trace of any activity to this server */
119 wait_queue_head_t active_wq; /* Wait for any activity to stop */ 122 wait_queue_head_t active_wq; /* Wait for any activity to stop */
123
124 /* mountd-related mount options */
125 struct sockaddr_storage mountd_address;
126 size_t mountd_addrlen;
127 u32 mountd_version;
128 unsigned short mountd_port;
129 unsigned short mountd_protocol;
120}; 130};
121 131
122/* Server capabilities */ 132/* Server capabilities */
diff --git a/include/linux/nfs_xdr.h b/include/linux/nfs_xdr.h
index f301d0b8babc..24263bb8e0be 100644
--- a/include/linux/nfs_xdr.h
+++ b/include/linux/nfs_xdr.h
@@ -140,6 +140,7 @@ struct nfs_openres {
140 __u32 rflags; 140 __u32 rflags;
141 struct nfs_fattr * f_attr; 141 struct nfs_fattr * f_attr;
142 struct nfs_fattr * dir_attr; 142 struct nfs_fattr * dir_attr;
143 struct nfs_seqid * seqid;
143 const struct nfs_server *server; 144 const struct nfs_server *server;
144 int delegation_type; 145 int delegation_type;
145 nfs4_stateid delegation; 146 nfs4_stateid delegation;
@@ -159,6 +160,7 @@ struct nfs_open_confirmargs {
159 160
160struct nfs_open_confirmres { 161struct nfs_open_confirmres {
161 nfs4_stateid stateid; 162 nfs4_stateid stateid;
163 struct nfs_seqid * seqid;
162}; 164};
163 165
164/* 166/*
@@ -175,6 +177,7 @@ struct nfs_closeargs {
175struct nfs_closeres { 177struct nfs_closeres {
176 nfs4_stateid stateid; 178 nfs4_stateid stateid;
177 struct nfs_fattr * fattr; 179 struct nfs_fattr * fattr;
180 struct nfs_seqid * seqid;
178 const struct nfs_server *server; 181 const struct nfs_server *server;
179}; 182};
180/* 183/*
@@ -199,7 +202,9 @@ struct nfs_lock_args {
199}; 202};
200 203
201struct nfs_lock_res { 204struct nfs_lock_res {
202 nfs4_stateid stateid; 205 nfs4_stateid stateid;
206 struct nfs_seqid * lock_seqid;
207 struct nfs_seqid * open_seqid;
203}; 208};
204 209
205struct nfs_locku_args { 210struct nfs_locku_args {
@@ -210,7 +215,8 @@ struct nfs_locku_args {
210}; 215};
211 216
212struct nfs_locku_res { 217struct nfs_locku_res {
213 nfs4_stateid stateid; 218 nfs4_stateid stateid;
219 struct nfs_seqid * seqid;
214}; 220};
215 221
216struct nfs_lockt_args { 222struct nfs_lockt_args {
diff --git a/include/linux/nfsd/Kbuild b/include/linux/nfsd/Kbuild
index e726fc3a4375..fc972048e572 100644
--- a/include/linux/nfsd/Kbuild
+++ b/include/linux/nfsd/Kbuild
@@ -1,6 +1,6 @@
1unifdef-y += const.h 1unifdef-y += const.h
2unifdef-y += debug.h
2unifdef-y += export.h 3unifdef-y += export.h
4unifdef-y += nfsfh.h
3unifdef-y += stats.h 5unifdef-y += stats.h
4unifdef-y += syscall.h 6unifdef-y += syscall.h
5unifdef-y += nfsfh.h
6unifdef-y += debug.h
diff --git a/include/linux/nfsd/cache.h b/include/linux/nfsd/cache.h
index 7b5d784cc858..04b355c801d8 100644
--- a/include/linux/nfsd/cache.h
+++ b/include/linux/nfsd/cache.h
@@ -10,7 +10,6 @@
10#ifndef NFSCACHE_H 10#ifndef NFSCACHE_H
11#define NFSCACHE_H 11#define NFSCACHE_H
12 12
13#ifdef __KERNEL__
14#include <linux/in.h> 13#include <linux/in.h>
15#include <linux/uio.h> 14#include <linux/uio.h>
16 15
@@ -77,5 +76,4 @@ void nfsd_reply_cache_shutdown(void);
77int nfsd_cache_lookup(struct svc_rqst *, int); 76int nfsd_cache_lookup(struct svc_rqst *, int);
78void nfsd_cache_update(struct svc_rqst *, int, __be32 *); 77void nfsd_cache_update(struct svc_rqst *, int, __be32 *);
79 78
80#endif /* __KERNEL__ */
81#endif /* NFSCACHE_H */ 79#endif /* NFSCACHE_H */
diff --git a/include/linux/nfsd/nfsd.h b/include/linux/nfsd/nfsd.h
index 8caf4c4f64e6..21ee440dd3e7 100644
--- a/include/linux/nfsd/nfsd.h
+++ b/include/linux/nfsd/nfsd.h
@@ -27,7 +27,6 @@
27#define NFSD_VERSION "0.5" 27#define NFSD_VERSION "0.5"
28#define NFSD_SUPPORTED_MINOR_VERSION 0 28#define NFSD_SUPPORTED_MINOR_VERSION 0
29 29
30#ifdef __KERNEL__
31/* 30/*
32 * Special flags for nfsd_permission. These must be different from MAY_READ, 31 * Special flags for nfsd_permission. These must be different from MAY_READ,
33 * MAY_WRITE, and MAY_EXEC. 32 * MAY_WRITE, and MAY_EXEC.
@@ -56,12 +55,20 @@ extern struct svc_program nfsd_program;
56extern struct svc_version nfsd_version2, nfsd_version3, 55extern struct svc_version nfsd_version2, nfsd_version3,
57 nfsd_version4; 56 nfsd_version4;
58extern struct svc_serv *nfsd_serv; 57extern struct svc_serv *nfsd_serv;
58
59extern struct seq_operations nfs_exports_op;
60
59/* 61/*
60 * Function prototypes. 62 * Function prototypes.
61 */ 63 */
62int nfsd_svc(unsigned short port, int nrservs); 64int nfsd_svc(unsigned short port, int nrservs);
63int nfsd_dispatch(struct svc_rqst *rqstp, __be32 *statp); 65int nfsd_dispatch(struct svc_rqst *rqstp, __be32 *statp);
64 66
67int nfsd_nrthreads(void);
68int nfsd_nrpools(void);
69int nfsd_get_nrthreads(int n, int *);
70int nfsd_set_nrthreads(int n, int *);
71
65/* nfsd/vfs.c */ 72/* nfsd/vfs.c */
66int fh_lock_parent(struct svc_fh *, struct dentry *); 73int fh_lock_parent(struct svc_fh *, struct dentry *);
67int nfsd_racache_init(int); 74int nfsd_racache_init(int);
@@ -326,6 +333,4 @@ extern struct timeval nfssvc_boot;
326 333
327#endif /* CONFIG_NFSD_V4 */ 334#endif /* CONFIG_NFSD_V4 */
328 335
329#endif /* __KERNEL__ */
330
331#endif /* LINUX_NFSD_NFSD_H */ 336#endif /* LINUX_NFSD_NFSD_H */
diff --git a/include/linux/rtnetlink.h b/include/linux/rtnetlink.h
index b9e174079002..44c81c744538 100644
--- a/include/linux/rtnetlink.h
+++ b/include/linux/rtnetlink.h
@@ -740,13 +740,13 @@ extern void rtmsg_ifinfo(int type, struct net_device *dev, unsigned change);
740extern void rtnl_lock(void); 740extern void rtnl_lock(void);
741extern void rtnl_unlock(void); 741extern void rtnl_unlock(void);
742extern int rtnl_trylock(void); 742extern int rtnl_trylock(void);
743extern int rtnl_is_locked(void);
743 744
744extern void rtnetlink_init(void); 745extern void rtnetlink_init(void);
745extern void __rtnl_unlock(void); 746extern void __rtnl_unlock(void);
746 747
747#define ASSERT_RTNL() do { \ 748#define ASSERT_RTNL() do { \
748 if (unlikely(rtnl_trylock())) { \ 749 if (unlikely(!rtnl_is_locked())) { \
749 rtnl_unlock(); \
750 printk(KERN_ERR "RTNL: assertion failed at %s (%d)\n", \ 750 printk(KERN_ERR "RTNL: assertion failed at %s (%d)\n", \
751 __FILE__, __LINE__); \ 751 __FILE__, __LINE__); \
752 dump_stack(); \ 752 dump_stack(); \
diff --git a/include/linux/sunrpc/auth.h b/include/linux/sunrpc/auth.h
index 7a69ca3bebaf..3f632182d8eb 100644
--- a/include/linux/sunrpc/auth.h
+++ b/include/linux/sunrpc/auth.h
@@ -26,6 +26,7 @@ struct auth_cred {
26 uid_t uid; 26 uid_t uid;
27 gid_t gid; 27 gid_t gid;
28 struct group_info *group_info; 28 struct group_info *group_info;
29 unsigned char machine_cred : 1;
29}; 30};
30 31
31/* 32/*
@@ -59,8 +60,8 @@ struct rpc_cred {
59/* 60/*
60 * Client authentication handle 61 * Client authentication handle
61 */ 62 */
62#define RPC_CREDCACHE_NR 8 63#define RPC_CREDCACHE_HASHBITS 4
63#define RPC_CREDCACHE_MASK (RPC_CREDCACHE_NR - 1) 64#define RPC_CREDCACHE_NR (1 << RPC_CREDCACHE_HASHBITS)
64struct rpc_cred_cache { 65struct rpc_cred_cache {
65 struct hlist_head hashtable[RPC_CREDCACHE_NR]; 66 struct hlist_head hashtable[RPC_CREDCACHE_NR];
66 spinlock_t lock; 67 spinlock_t lock;
@@ -89,7 +90,6 @@ struct rpc_auth {
89 90
90/* Flags for rpcauth_lookupcred() */ 91/* Flags for rpcauth_lookupcred() */
91#define RPCAUTH_LOOKUP_NEW 0x01 /* Accept an uninitialised cred */ 92#define RPCAUTH_LOOKUP_NEW 0x01 /* Accept an uninitialised cred */
92#define RPCAUTH_LOOKUP_ROOTCREDS 0x02 /* This really ought to go! */
93 93
94/* 94/*
95 * Client authentication ops 95 * Client authentication ops
@@ -97,9 +97,7 @@ struct rpc_auth {
97struct rpc_authops { 97struct rpc_authops {
98 struct module *owner; 98 struct module *owner;
99 rpc_authflavor_t au_flavor; /* flavor (RPC_AUTH_*) */ 99 rpc_authflavor_t au_flavor; /* flavor (RPC_AUTH_*) */
100#ifdef RPC_DEBUG
101 char * au_name; 100 char * au_name;
102#endif
103 struct rpc_auth * (*create)(struct rpc_clnt *, rpc_authflavor_t); 101 struct rpc_auth * (*create)(struct rpc_clnt *, rpc_authflavor_t);
104 void (*destroy)(struct rpc_auth *); 102 void (*destroy)(struct rpc_auth *);
105 103
@@ -113,6 +111,7 @@ struct rpc_credops {
113 void (*crdestroy)(struct rpc_cred *); 111 void (*crdestroy)(struct rpc_cred *);
114 112
115 int (*crmatch)(struct auth_cred *, struct rpc_cred *, int); 113 int (*crmatch)(struct auth_cred *, struct rpc_cred *, int);
114 void (*crbind)(struct rpc_task *, struct rpc_cred *);
116 __be32 * (*crmarshal)(struct rpc_task *, __be32 *); 115 __be32 * (*crmarshal)(struct rpc_task *, __be32 *);
117 int (*crrefresh)(struct rpc_task *); 116 int (*crrefresh)(struct rpc_task *);
118 __be32 * (*crvalidate)(struct rpc_task *, __be32 *); 117 __be32 * (*crvalidate)(struct rpc_task *, __be32 *);
@@ -126,9 +125,13 @@ extern const struct rpc_authops authunix_ops;
126extern const struct rpc_authops authnull_ops; 125extern const struct rpc_authops authnull_ops;
127 126
128void __init rpc_init_authunix(void); 127void __init rpc_init_authunix(void);
128void __init rpc_init_generic_auth(void);
129void __init rpcauth_init_module(void); 129void __init rpcauth_init_module(void);
130void __exit rpcauth_remove_module(void); 130void __exit rpcauth_remove_module(void);
131void __exit rpc_destroy_generic_auth(void);
131 132
133struct rpc_cred * rpc_lookup_cred(void);
134struct rpc_cred * rpc_lookup_machine_cred(void);
132int rpcauth_register(const struct rpc_authops *); 135int rpcauth_register(const struct rpc_authops *);
133int rpcauth_unregister(const struct rpc_authops *); 136int rpcauth_unregister(const struct rpc_authops *);
134struct rpc_auth * rpcauth_create(rpc_authflavor_t, struct rpc_clnt *); 137struct rpc_auth * rpcauth_create(rpc_authflavor_t, struct rpc_clnt *);
@@ -136,8 +139,8 @@ void rpcauth_release(struct rpc_auth *);
136struct rpc_cred * rpcauth_lookup_credcache(struct rpc_auth *, struct auth_cred *, int); 139struct rpc_cred * rpcauth_lookup_credcache(struct rpc_auth *, struct auth_cred *, int);
137void rpcauth_init_cred(struct rpc_cred *, const struct auth_cred *, struct rpc_auth *, const struct rpc_credops *); 140void rpcauth_init_cred(struct rpc_cred *, const struct auth_cred *, struct rpc_auth *, const struct rpc_credops *);
138struct rpc_cred * rpcauth_lookupcred(struct rpc_auth *, int); 141struct rpc_cred * rpcauth_lookupcred(struct rpc_auth *, int);
139struct rpc_cred * rpcauth_bindcred(struct rpc_task *); 142void rpcauth_bindcred(struct rpc_task *, struct rpc_cred *, int);
140void rpcauth_holdcred(struct rpc_task *); 143void rpcauth_generic_bind_cred(struct rpc_task *, struct rpc_cred *);
141void put_rpccred(struct rpc_cred *); 144void put_rpccred(struct rpc_cred *);
142void rpcauth_unbindcred(struct rpc_task *); 145void rpcauth_unbindcred(struct rpc_task *);
143__be32 * rpcauth_marshcred(struct rpc_task *, __be32 *); 146__be32 * rpcauth_marshcred(struct rpc_task *, __be32 *);
diff --git a/include/linux/sunrpc/auth_gss.h b/include/linux/sunrpc/auth_gss.h
index 67658e17a375..fec6899bf355 100644
--- a/include/linux/sunrpc/auth_gss.h
+++ b/include/linux/sunrpc/auth_gss.h
@@ -84,6 +84,7 @@ struct gss_cred {
84 enum rpc_gss_svc gc_service; 84 enum rpc_gss_svc gc_service;
85 struct gss_cl_ctx *gc_ctx; 85 struct gss_cl_ctx *gc_ctx;
86 struct gss_upcall_msg *gc_upcall; 86 struct gss_upcall_msg *gc_upcall;
87 unsigned char gc_machine_cred : 1;
87}; 88};
88 89
89#endif /* __KERNEL__ */ 90#endif /* __KERNEL__ */
diff --git a/include/linux/sunrpc/cache.h b/include/linux/sunrpc/cache.h
index 03547d6abee5..2d8b211b9324 100644
--- a/include/linux/sunrpc/cache.h
+++ b/include/linux/sunrpc/cache.h
@@ -120,7 +120,6 @@ struct cache_deferred_req {
120 struct list_head hash; /* on hash chain */ 120 struct list_head hash; /* on hash chain */
121 struct list_head recent; /* on fifo */ 121 struct list_head recent; /* on fifo */
122 struct cache_head *item; /* cache item we wait on */ 122 struct cache_head *item; /* cache item we wait on */
123 time_t recv_time;
124 void *owner; /* we might need to discard all defered requests 123 void *owner; /* we might need to discard all defered requests
125 * owned by someone */ 124 * owned by someone */
126 void (*revisit)(struct cache_deferred_req *req, 125 void (*revisit)(struct cache_deferred_req *req,
diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
index 129a86e25d29..6fff7f82ef12 100644
--- a/include/linux/sunrpc/clnt.h
+++ b/include/linux/sunrpc/clnt.h
@@ -127,11 +127,12 @@ int rpcb_getport_sync(struct sockaddr_in *, u32, u32, int);
127void rpcb_getport_async(struct rpc_task *); 127void rpcb_getport_async(struct rpc_task *);
128 128
129void rpc_call_start(struct rpc_task *); 129void rpc_call_start(struct rpc_task *);
130int rpc_call_async(struct rpc_clnt *clnt, struct rpc_message *msg, 130int rpc_call_async(struct rpc_clnt *clnt,
131 int flags, const struct rpc_call_ops *tk_ops, 131 const struct rpc_message *msg, int flags,
132 const struct rpc_call_ops *tk_ops,
132 void *calldata); 133 void *calldata);
133int rpc_call_sync(struct rpc_clnt *clnt, struct rpc_message *msg, 134int rpc_call_sync(struct rpc_clnt *clnt,
134 int flags); 135 const struct rpc_message *msg, int flags);
135struct rpc_task *rpc_call_null(struct rpc_clnt *clnt, struct rpc_cred *cred, 136struct rpc_task *rpc_call_null(struct rpc_clnt *clnt, struct rpc_cred *cred,
136 int flags); 137 int flags);
137void rpc_restart_call(struct rpc_task *); 138void rpc_restart_call(struct rpc_task *);
diff --git a/include/linux/sunrpc/gss_krb5.h b/include/linux/sunrpc/gss_krb5.h
index 5a4b1e0206e3..a10f1fb0bf7c 100644
--- a/include/linux/sunrpc/gss_krb5.h
+++ b/include/linux/sunrpc/gss_krb5.h
@@ -70,8 +70,6 @@ enum seal_alg {
70 SEAL_ALG_DES3KD = 0x0002 70 SEAL_ALG_DES3KD = 0x0002
71}; 71};
72 72
73#define KRB5_CKSUM_LENGTH 8
74
75#define CKSUMTYPE_CRC32 0x0001 73#define CKSUMTYPE_CRC32 0x0001
76#define CKSUMTYPE_RSA_MD4 0x0002 74#define CKSUMTYPE_RSA_MD4 0x0002
77#define CKSUMTYPE_RSA_MD4_DES 0x0003 75#define CKSUMTYPE_RSA_MD4_DES 0x0003
@@ -150,9 +148,9 @@ gss_decrypt_xdr_buf(struct crypto_blkcipher *tfm, struct xdr_buf *inbuf,
150s32 148s32
151krb5_make_seq_num(struct crypto_blkcipher *key, 149krb5_make_seq_num(struct crypto_blkcipher *key,
152 int direction, 150 int direction,
153 s32 seqnum, unsigned char *cksum, unsigned char *buf); 151 u32 seqnum, unsigned char *cksum, unsigned char *buf);
154 152
155s32 153s32
156krb5_get_seq_num(struct crypto_blkcipher *key, 154krb5_get_seq_num(struct crypto_blkcipher *key,
157 unsigned char *cksum, 155 unsigned char *cksum,
158 unsigned char *buf, int *direction, s32 * seqnum); 156 unsigned char *buf, int *direction, u32 *seqnum);
diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
index f689f02e6793..d1a5c8c1a0f1 100644
--- a/include/linux/sunrpc/sched.h
+++ b/include/linux/sunrpc/sched.h
@@ -11,7 +11,6 @@
11 11
12#include <linux/timer.h> 12#include <linux/timer.h>
13#include <linux/sunrpc/types.h> 13#include <linux/sunrpc/types.h>
14#include <linux/rcupdate.h>
15#include <linux/spinlock.h> 14#include <linux/spinlock.h>
16#include <linux/wait.h> 15#include <linux/wait.h>
17#include <linux/workqueue.h> 16#include <linux/workqueue.h>
@@ -33,7 +32,8 @@ struct rpc_wait_queue;
33struct rpc_wait { 32struct rpc_wait {
34 struct list_head list; /* wait queue links */ 33 struct list_head list; /* wait queue links */
35 struct list_head links; /* Links to related tasks */ 34 struct list_head links; /* Links to related tasks */
36 struct rpc_wait_queue * rpc_waitq; /* RPC wait queue we're on */ 35 struct list_head timer_list; /* Timer list */
36 unsigned long expires;
37}; 37};
38 38
39/* 39/*
@@ -57,33 +57,25 @@ struct rpc_task {
57 __u8 tk_cred_retry; 57 __u8 tk_cred_retry;
58 58
59 /* 59 /*
60 * timeout_fn to be executed by timer bottom half
61 * callback to be executed after waking up 60 * callback to be executed after waking up
62 * action next procedure for async tasks 61 * action next procedure for async tasks
63 * tk_ops caller callbacks 62 * tk_ops caller callbacks
64 */ 63 */
65 void (*tk_timeout_fn)(struct rpc_task *);
66 void (*tk_callback)(struct rpc_task *); 64 void (*tk_callback)(struct rpc_task *);
67 void (*tk_action)(struct rpc_task *); 65 void (*tk_action)(struct rpc_task *);
68 const struct rpc_call_ops *tk_ops; 66 const struct rpc_call_ops *tk_ops;
69 void * tk_calldata; 67 void * tk_calldata;
70 68
71 /*
72 * tk_timer is used for async processing by the RPC scheduling
73 * primitives. You should not access this directly unless
74 * you have a pathological interest in kernel oopses.
75 */
76 struct timer_list tk_timer; /* kernel timer */
77 unsigned long tk_timeout; /* timeout for rpc_sleep() */ 69 unsigned long tk_timeout; /* timeout for rpc_sleep() */
78 unsigned short tk_flags; /* misc flags */ 70 unsigned short tk_flags; /* misc flags */
79 unsigned long tk_runstate; /* Task run status */ 71 unsigned long tk_runstate; /* Task run status */
80 struct workqueue_struct *tk_workqueue; /* Normally rpciod, but could 72 struct workqueue_struct *tk_workqueue; /* Normally rpciod, but could
81 * be any workqueue 73 * be any workqueue
82 */ 74 */
75 struct rpc_wait_queue *tk_waitqueue; /* RPC wait queue we're on */
83 union { 76 union {
84 struct work_struct tk_work; /* Async task work queue */ 77 struct work_struct tk_work; /* Async task work queue */
85 struct rpc_wait tk_wait; /* RPC wait */ 78 struct rpc_wait tk_wait; /* RPC wait */
86 struct rcu_head tk_rcu; /* for task deletion */
87 } u; 79 } u;
88 80
89 unsigned short tk_timeouts; /* maj timeouts */ 81 unsigned short tk_timeouts; /* maj timeouts */
@@ -123,6 +115,7 @@ struct rpc_task_setup {
123 const struct rpc_message *rpc_message; 115 const struct rpc_message *rpc_message;
124 const struct rpc_call_ops *callback_ops; 116 const struct rpc_call_ops *callback_ops;
125 void *callback_data; 117 void *callback_data;
118 struct workqueue_struct *workqueue;
126 unsigned short flags; 119 unsigned short flags;
127 signed char priority; 120 signed char priority;
128}; 121};
@@ -147,9 +140,7 @@ struct rpc_task_setup {
147 140
148#define RPC_TASK_RUNNING 0 141#define RPC_TASK_RUNNING 0
149#define RPC_TASK_QUEUED 1 142#define RPC_TASK_QUEUED 1
150#define RPC_TASK_WAKEUP 2 143#define RPC_TASK_ACTIVE 2
151#define RPC_TASK_HAS_TIMER 3
152#define RPC_TASK_ACTIVE 4
153 144
154#define RPC_IS_RUNNING(t) test_bit(RPC_TASK_RUNNING, &(t)->tk_runstate) 145#define RPC_IS_RUNNING(t) test_bit(RPC_TASK_RUNNING, &(t)->tk_runstate)
155#define rpc_set_running(t) set_bit(RPC_TASK_RUNNING, &(t)->tk_runstate) 146#define rpc_set_running(t) set_bit(RPC_TASK_RUNNING, &(t)->tk_runstate)
@@ -171,15 +162,6 @@ struct rpc_task_setup {
171 smp_mb__after_clear_bit(); \ 162 smp_mb__after_clear_bit(); \
172 } while (0) 163 } while (0)
173 164
174#define rpc_start_wakeup(t) \
175 (test_and_set_bit(RPC_TASK_WAKEUP, &(t)->tk_runstate) == 0)
176#define rpc_finish_wakeup(t) \
177 do { \
178 smp_mb__before_clear_bit(); \
179 clear_bit(RPC_TASK_WAKEUP, &(t)->tk_runstate); \
180 smp_mb__after_clear_bit(); \
181 } while (0)
182
183#define RPC_IS_ACTIVATED(t) test_bit(RPC_TASK_ACTIVE, &(t)->tk_runstate) 165#define RPC_IS_ACTIVATED(t) test_bit(RPC_TASK_ACTIVE, &(t)->tk_runstate)
184 166
185/* 167/*
@@ -192,6 +174,12 @@ struct rpc_task_setup {
192#define RPC_PRIORITY_HIGH (1) 174#define RPC_PRIORITY_HIGH (1)
193#define RPC_NR_PRIORITY (1 + RPC_PRIORITY_HIGH - RPC_PRIORITY_LOW) 175#define RPC_NR_PRIORITY (1 + RPC_PRIORITY_HIGH - RPC_PRIORITY_LOW)
194 176
177struct rpc_timer {
178 struct timer_list timer;
179 struct list_head list;
180 unsigned long expires;
181};
182
195/* 183/*
196 * RPC synchronization objects 184 * RPC synchronization objects
197 */ 185 */
@@ -204,6 +192,7 @@ struct rpc_wait_queue {
204 unsigned char count; /* # task groups remaining serviced so far */ 192 unsigned char count; /* # task groups remaining serviced so far */
205 unsigned char nr; /* # tasks remaining for cookie */ 193 unsigned char nr; /* # tasks remaining for cookie */
206 unsigned short qlen; /* total # tasks waiting in queue */ 194 unsigned short qlen; /* total # tasks waiting in queue */
195 struct rpc_timer timer_list;
207#ifdef RPC_DEBUG 196#ifdef RPC_DEBUG
208 const char * name; 197 const char * name;
209#endif 198#endif
@@ -229,9 +218,11 @@ void rpc_killall_tasks(struct rpc_clnt *);
229void rpc_execute(struct rpc_task *); 218void rpc_execute(struct rpc_task *);
230void rpc_init_priority_wait_queue(struct rpc_wait_queue *, const char *); 219void rpc_init_priority_wait_queue(struct rpc_wait_queue *, const char *);
231void rpc_init_wait_queue(struct rpc_wait_queue *, const char *); 220void rpc_init_wait_queue(struct rpc_wait_queue *, const char *);
221void rpc_destroy_wait_queue(struct rpc_wait_queue *);
232void rpc_sleep_on(struct rpc_wait_queue *, struct rpc_task *, 222void rpc_sleep_on(struct rpc_wait_queue *, struct rpc_task *,
233 rpc_action action, rpc_action timer); 223 rpc_action action);
234void rpc_wake_up_task(struct rpc_task *); 224void rpc_wake_up_queued_task(struct rpc_wait_queue *,
225 struct rpc_task *);
235void rpc_wake_up(struct rpc_wait_queue *); 226void rpc_wake_up(struct rpc_wait_queue *);
236struct rpc_task *rpc_wake_up_next(struct rpc_wait_queue *); 227struct rpc_task *rpc_wake_up_next(struct rpc_wait_queue *);
237void rpc_wake_up_status(struct rpc_wait_queue *, int); 228void rpc_wake_up_status(struct rpc_wait_queue *, int);
diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
index 64c97552964a..4b54c5fdcfd9 100644
--- a/include/linux/sunrpc/svc.h
+++ b/include/linux/sunrpc/svc.h
@@ -386,7 +386,6 @@ struct svc_serv * svc_create(struct svc_program *, unsigned int,
386 void (*shutdown)(struct svc_serv*)); 386 void (*shutdown)(struct svc_serv*));
387struct svc_rqst *svc_prepare_thread(struct svc_serv *serv, 387struct svc_rqst *svc_prepare_thread(struct svc_serv *serv,
388 struct svc_pool *pool); 388 struct svc_pool *pool);
389int svc_create_thread(svc_thread_fn, struct svc_serv *);
390void svc_exit_thread(struct svc_rqst *); 389void svc_exit_thread(struct svc_rqst *);
391struct svc_serv * svc_create_pooled(struct svc_program *, unsigned int, 390struct svc_serv * svc_create_pooled(struct svc_program *, unsigned int,
392 void (*shutdown)(struct svc_serv*), 391 void (*shutdown)(struct svc_serv*),
diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
index 22e1ef8e200e..d39dbdc7b10f 100644
--- a/include/linux/sunrpc/svcauth.h
+++ b/include/linux/sunrpc/svcauth.h
@@ -24,6 +24,7 @@ struct svc_cred {
24}; 24};
25 25
26struct svc_rqst; /* forward decl */ 26struct svc_rqst; /* forward decl */
27struct in6_addr;
27 28
28/* Authentication is done in the context of a domain. 29/* Authentication is done in the context of a domain.
29 * 30 *
@@ -120,10 +121,10 @@ extern void svc_auth_unregister(rpc_authflavor_t flavor);
120 121
121extern struct auth_domain *unix_domain_find(char *name); 122extern struct auth_domain *unix_domain_find(char *name);
122extern void auth_domain_put(struct auth_domain *item); 123extern void auth_domain_put(struct auth_domain *item);
123extern int auth_unix_add_addr(struct in_addr addr, struct auth_domain *dom); 124extern int auth_unix_add_addr(struct in6_addr *addr, struct auth_domain *dom);
124extern struct auth_domain *auth_domain_lookup(char *name, struct auth_domain *new); 125extern struct auth_domain *auth_domain_lookup(char *name, struct auth_domain *new);
125extern struct auth_domain *auth_domain_find(char *name); 126extern struct auth_domain *auth_domain_find(char *name);
126extern struct auth_domain *auth_unix_lookup(struct in_addr addr); 127extern struct auth_domain *auth_unix_lookup(struct in6_addr *addr);
127extern int auth_unix_forget_old(struct auth_domain *dom); 128extern int auth_unix_forget_old(struct auth_domain *dom);
128extern void svcauth_unix_purge(void); 129extern void svcauth_unix_purge(void);
129extern void svcauth_unix_info_release(void *); 130extern void svcauth_unix_info_release(void *);
diff --git a/include/linux/sunrpc/svcsock.h b/include/linux/sunrpc/svcsock.h
index 206f092ad4c7..8cff696dedf5 100644
--- a/include/linux/sunrpc/svcsock.h
+++ b/include/linux/sunrpc/svcsock.h
@@ -26,8 +26,8 @@ struct svc_sock {
26 void (*sk_owspace)(struct sock *); 26 void (*sk_owspace)(struct sock *);
27 27
28 /* private TCP part */ 28 /* private TCP part */
29 int sk_reclen; /* length of record */ 29 u32 sk_reclen; /* length of record */
30 int sk_tcplen; /* current read length */ 30 u32 sk_tcplen; /* current read length */
31}; 31};
32 32
33/* 33/*
diff --git a/include/linux/sunrpc/xprt.h b/include/linux/sunrpc/xprt.h
index b3ff9a815e6f..4d80a118d538 100644
--- a/include/linux/sunrpc/xprt.h
+++ b/include/linux/sunrpc/xprt.h
@@ -86,6 +86,10 @@ struct rpc_rqst {
86 unsigned long rq_majortimeo; /* major timeout alarm */ 86 unsigned long rq_majortimeo; /* major timeout alarm */
87 unsigned long rq_timeout; /* Current timeout value */ 87 unsigned long rq_timeout; /* Current timeout value */
88 unsigned int rq_retries; /* # of retries */ 88 unsigned int rq_retries; /* # of retries */
89 unsigned int rq_connect_cookie;
90 /* A cookie used to track the
91 state of the transport
92 connection */
89 93
90 /* 94 /*
91 * Partial send handling 95 * Partial send handling
@@ -152,6 +156,9 @@ struct rpc_xprt {
152 unsigned long connect_timeout, 156 unsigned long connect_timeout,
153 bind_timeout, 157 bind_timeout,
154 reestablish_timeout; 158 reestablish_timeout;
159 unsigned int connect_cookie; /* A cookie that gets bumped
160 every time the transport
161 is reconnected */
155 162
156 /* 163 /*
157 * Disconnection of idle transports 164 * Disconnection of idle transports
@@ -232,7 +239,7 @@ int xprt_unregister_transport(struct xprt_class *type);
232void xprt_set_retrans_timeout_def(struct rpc_task *task); 239void xprt_set_retrans_timeout_def(struct rpc_task *task);
233void xprt_set_retrans_timeout_rtt(struct rpc_task *task); 240void xprt_set_retrans_timeout_rtt(struct rpc_task *task);
234void xprt_wake_pending_tasks(struct rpc_xprt *xprt, int status); 241void xprt_wake_pending_tasks(struct rpc_xprt *xprt, int status);
235void xprt_wait_for_buffer_space(struct rpc_task *task); 242void xprt_wait_for_buffer_space(struct rpc_task *task, rpc_action action);
236void xprt_write_space(struct rpc_xprt *xprt); 243void xprt_write_space(struct rpc_xprt *xprt);
237void xprt_update_rtt(struct rpc_task *task); 244void xprt_update_rtt(struct rpc_task *task);
238void xprt_adjust_cwnd(struct rpc_task *task, int result); 245void xprt_adjust_cwnd(struct rpc_task *task, int result);
@@ -241,6 +248,7 @@ void xprt_complete_rqst(struct rpc_task *task, int copied);
241void xprt_release_rqst_cong(struct rpc_task *task); 248void xprt_release_rqst_cong(struct rpc_task *task);
242void xprt_disconnect_done(struct rpc_xprt *xprt); 249void xprt_disconnect_done(struct rpc_xprt *xprt);
243void xprt_force_disconnect(struct rpc_xprt *xprt); 250void xprt_force_disconnect(struct rpc_xprt *xprt);
251void xprt_conditional_disconnect(struct rpc_xprt *xprt, unsigned int cookie);
244 252
245/* 253/*
246 * Reserved bit positions in xprt->state 254 * Reserved bit positions in xprt->state
diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h
index 17a80177a674..c1411189ba6c 100644
--- a/include/linux/videodev2.h
+++ b/include/linux/videodev2.h
@@ -282,6 +282,7 @@ struct v4l2_pix_format
282#define V4L2_PIX_FMT_BGR32 v4l2_fourcc('B','G','R','4') /* 32 BGR-8-8-8-8 */ 282#define V4L2_PIX_FMT_BGR32 v4l2_fourcc('B','G','R','4') /* 32 BGR-8-8-8-8 */
283#define V4L2_PIX_FMT_RGB32 v4l2_fourcc('R','G','B','4') /* 32 RGB-8-8-8-8 */ 283#define V4L2_PIX_FMT_RGB32 v4l2_fourcc('R','G','B','4') /* 32 RGB-8-8-8-8 */
284#define V4L2_PIX_FMT_GREY v4l2_fourcc('G','R','E','Y') /* 8 Greyscale */ 284#define V4L2_PIX_FMT_GREY v4l2_fourcc('G','R','E','Y') /* 8 Greyscale */
285#define V4L2_PIX_FMT_Y16 v4l2_fourcc('Y','1','6',' ') /* 16 Greyscale */
285#define V4L2_PIX_FMT_PAL8 v4l2_fourcc('P','A','L','8') /* 8 8-bit palette */ 286#define V4L2_PIX_FMT_PAL8 v4l2_fourcc('P','A','L','8') /* 8 8-bit palette */
286#define V4L2_PIX_FMT_YVU410 v4l2_fourcc('Y','V','U','9') /* 9 YVU 4:1:0 */ 287#define V4L2_PIX_FMT_YVU410 v4l2_fourcc('Y','V','U','9') /* 9 YVU 4:1:0 */
287#define V4L2_PIX_FMT_YVU420 v4l2_fourcc('Y','V','1','2') /* 12 YVU 4:2:0 */ 288#define V4L2_PIX_FMT_YVU420 v4l2_fourcc('Y','V','1','2') /* 12 YVU 4:2:0 */
@@ -308,6 +309,7 @@ struct v4l2_pix_format
308 309
309/* see http://www.siliconimaging.com/RGB%20Bayer.htm */ 310/* see http://www.siliconimaging.com/RGB%20Bayer.htm */
310#define V4L2_PIX_FMT_SBGGR8 v4l2_fourcc('B','A','8','1') /* 8 BGBG.. GRGR.. */ 311#define V4L2_PIX_FMT_SBGGR8 v4l2_fourcc('B','A','8','1') /* 8 BGBG.. GRGR.. */
312#define V4L2_PIX_FMT_SBGGR16 v4l2_fourcc('B','Y','R','2') /* 16 BGBG.. GRGR.. */
311 313
312/* compressed formats */ 314/* compressed formats */
313#define V4L2_PIX_FMT_MJPEG v4l2_fourcc('M','J','P','G') /* Motion-JPEG */ 315#define V4L2_PIX_FMT_MJPEG v4l2_fourcc('M','J','P','G') /* Motion-JPEG */
@@ -793,6 +795,7 @@ struct v4l2_ext_controls
793/* Values for ctrl_class field */ 795/* Values for ctrl_class field */
794#define V4L2_CTRL_CLASS_USER 0x00980000 /* Old-style 'user' controls */ 796#define V4L2_CTRL_CLASS_USER 0x00980000 /* Old-style 'user' controls */
795#define V4L2_CTRL_CLASS_MPEG 0x00990000 /* MPEG-compression controls */ 797#define V4L2_CTRL_CLASS_MPEG 0x00990000 /* MPEG-compression controls */
798#define V4L2_CTRL_CLASS_CAMERA 0x009a0000 /* Camera class controls */
796 799
797#define V4L2_CTRL_ID_MASK (0x0fffffff) 800#define V4L2_CTRL_ID_MASK (0x0fffffff)
798#define V4L2_CTRL_ID2CLASS(id) ((id) & 0x0fff0000UL) 801#define V4L2_CTRL_ID2CLASS(id) ((id) & 0x0fff0000UL)
@@ -849,21 +852,37 @@ struct v4l2_querymenu
849#define V4L2_CID_AUDIO_TREBLE (V4L2_CID_BASE+8) 852#define V4L2_CID_AUDIO_TREBLE (V4L2_CID_BASE+8)
850#define V4L2_CID_AUDIO_MUTE (V4L2_CID_BASE+9) 853#define V4L2_CID_AUDIO_MUTE (V4L2_CID_BASE+9)
851#define V4L2_CID_AUDIO_LOUDNESS (V4L2_CID_BASE+10) 854#define V4L2_CID_AUDIO_LOUDNESS (V4L2_CID_BASE+10)
852#define V4L2_CID_BLACK_LEVEL (V4L2_CID_BASE+11) 855#define V4L2_CID_BLACK_LEVEL (V4L2_CID_BASE+11) /* Deprecated */
853#define V4L2_CID_AUTO_WHITE_BALANCE (V4L2_CID_BASE+12) 856#define V4L2_CID_AUTO_WHITE_BALANCE (V4L2_CID_BASE+12)
854#define V4L2_CID_DO_WHITE_BALANCE (V4L2_CID_BASE+13) 857#define V4L2_CID_DO_WHITE_BALANCE (V4L2_CID_BASE+13)
855#define V4L2_CID_RED_BALANCE (V4L2_CID_BASE+14) 858#define V4L2_CID_RED_BALANCE (V4L2_CID_BASE+14)
856#define V4L2_CID_BLUE_BALANCE (V4L2_CID_BASE+15) 859#define V4L2_CID_BLUE_BALANCE (V4L2_CID_BASE+15)
857#define V4L2_CID_GAMMA (V4L2_CID_BASE+16) 860#define V4L2_CID_GAMMA (V4L2_CID_BASE+16)
858#define V4L2_CID_WHITENESS (V4L2_CID_GAMMA) /* ? Not sure */ 861#define V4L2_CID_WHITENESS (V4L2_CID_GAMMA) /* Deprecated */
859#define V4L2_CID_EXPOSURE (V4L2_CID_BASE+17) 862#define V4L2_CID_EXPOSURE (V4L2_CID_BASE+17)
860#define V4L2_CID_AUTOGAIN (V4L2_CID_BASE+18) 863#define V4L2_CID_AUTOGAIN (V4L2_CID_BASE+18)
861#define V4L2_CID_GAIN (V4L2_CID_BASE+19) 864#define V4L2_CID_GAIN (V4L2_CID_BASE+19)
862#define V4L2_CID_HFLIP (V4L2_CID_BASE+20) 865#define V4L2_CID_HFLIP (V4L2_CID_BASE+20)
863#define V4L2_CID_VFLIP (V4L2_CID_BASE+21) 866#define V4L2_CID_VFLIP (V4L2_CID_BASE+21)
864#define V4L2_CID_HCENTER (V4L2_CID_BASE+22) 867
865#define V4L2_CID_VCENTER (V4L2_CID_BASE+23) 868/* Deprecated, use V4L2_CID_PAN_RESET and V4L2_CID_TILT_RESET */
866#define V4L2_CID_LASTP1 (V4L2_CID_BASE+24) /* last CID + 1 */ 869#define V4L2_CID_HCENTER_DEPRECATED (V4L2_CID_BASE+22)
870#define V4L2_CID_VCENTER_DEPRECATED (V4L2_CID_BASE+23)
871
872#define V4L2_CID_POWER_LINE_FREQUENCY (V4L2_CID_BASE+24)
873enum v4l2_power_line_frequency {
874 V4L2_CID_POWER_LINE_FREQUENCY_DISABLED = 0,
875 V4L2_CID_POWER_LINE_FREQUENCY_50HZ = 1,
876 V4L2_CID_POWER_LINE_FREQUENCY_60HZ = 2,
877};
878#define V4L2_CID_HUE_AUTO (V4L2_CID_BASE+25)
879#define V4L2_CID_WHITE_BALANCE_TEMPERATURE (V4L2_CID_BASE+26)
880#define V4L2_CID_SHARPNESS (V4L2_CID_BASE+27)
881#define V4L2_CID_BACKLIGHT_COMPENSATION (V4L2_CID_BASE+28)
882#define V4L2_CID_CHROMA_AGC (V4L2_CID_BASE+29)
883#define V4L2_CID_COLOR_KILLER (V4L2_CID_BASE+30)
884/* last CID + 1 */
885#define V4L2_CID_LASTP1 (V4L2_CID_BASE+31)
867 886
868/* MPEG-class control IDs defined by V4L2 */ 887/* MPEG-class control IDs defined by V4L2 */
869#define V4L2_CID_MPEG_BASE (V4L2_CTRL_CLASS_MPEG | 0x900) 888#define V4L2_CID_MPEG_BASE (V4L2_CTRL_CLASS_MPEG | 0x900)
@@ -1051,6 +1070,32 @@ enum v4l2_mpeg_cx2341x_video_median_filter_type {
1051#define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP (V4L2_CID_MPEG_CX2341X_BASE+10) 1070#define V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP (V4L2_CID_MPEG_CX2341X_BASE+10)
1052#define V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS (V4L2_CID_MPEG_CX2341X_BASE+11) 1071#define V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS (V4L2_CID_MPEG_CX2341X_BASE+11)
1053 1072
1073/* Camera class control IDs */
1074#define V4L2_CID_CAMERA_CLASS_BASE (V4L2_CTRL_CLASS_CAMERA | 0x900)
1075#define V4L2_CID_CAMERA_CLASS (V4L2_CTRL_CLASS_CAMERA | 1)
1076
1077#define V4L2_CID_EXPOSURE_AUTO (V4L2_CID_CAMERA_CLASS_BASE+1)
1078enum v4l2_exposure_auto_type {
1079 V4L2_EXPOSURE_AUTO = 0,
1080 V4L2_EXPOSURE_MANUAL = 1,
1081 V4L2_EXPOSURE_SHUTTER_PRIORITY = 2,
1082 V4L2_EXPOSURE_APERTURE_PRIORITY = 3
1083};
1084#define V4L2_CID_EXPOSURE_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+2)
1085#define V4L2_CID_EXPOSURE_AUTO_PRIORITY (V4L2_CID_CAMERA_CLASS_BASE+3)
1086
1087#define V4L2_CID_PAN_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+4)
1088#define V4L2_CID_TILT_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+5)
1089#define V4L2_CID_PAN_RESET (V4L2_CID_CAMERA_CLASS_BASE+6)
1090#define V4L2_CID_TILT_RESET (V4L2_CID_CAMERA_CLASS_BASE+7)
1091
1092#define V4L2_CID_PAN_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+8)
1093#define V4L2_CID_TILT_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+9)
1094
1095#define V4L2_CID_FOCUS_ABSOLUTE (V4L2_CID_CAMERA_CLASS_BASE+10)
1096#define V4L2_CID_FOCUS_RELATIVE (V4L2_CID_CAMERA_CLASS_BASE+11)
1097#define V4L2_CID_FOCUS_AUTO (V4L2_CID_CAMERA_CLASS_BASE+12)
1098
1054/* 1099/*
1055 * T U N I N G 1100 * T U N I N G
1056 */ 1101 */
diff --git a/include/media/ir-common.h b/include/media/ir-common.h
index a4274203f252..bfee8be5d63f 100644
--- a/include/media/ir-common.h
+++ b/include/media/ir-common.h
@@ -107,6 +107,7 @@ extern IR_KEYTAB_TYPE ir_codes_avermedia[IR_KEYTAB_SIZE];
107extern IR_KEYTAB_TYPE ir_codes_avermedia_dvbt[IR_KEYTAB_SIZE]; 107extern IR_KEYTAB_TYPE ir_codes_avermedia_dvbt[IR_KEYTAB_SIZE];
108extern IR_KEYTAB_TYPE ir_codes_apac_viewcomp[IR_KEYTAB_SIZE]; 108extern IR_KEYTAB_TYPE ir_codes_apac_viewcomp[IR_KEYTAB_SIZE];
109extern IR_KEYTAB_TYPE ir_codes_pixelview[IR_KEYTAB_SIZE]; 109extern IR_KEYTAB_TYPE ir_codes_pixelview[IR_KEYTAB_SIZE];
110extern IR_KEYTAB_TYPE ir_codes_pixelview_new[IR_KEYTAB_SIZE];
110extern IR_KEYTAB_TYPE ir_codes_nebula[IR_KEYTAB_SIZE]; 111extern IR_KEYTAB_TYPE ir_codes_nebula[IR_KEYTAB_SIZE];
111extern IR_KEYTAB_TYPE ir_codes_dntv_live_dvb_t[IR_KEYTAB_SIZE]; 112extern IR_KEYTAB_TYPE ir_codes_dntv_live_dvb_t[IR_KEYTAB_SIZE];
112extern IR_KEYTAB_TYPE ir_codes_iodata_bctv7e[IR_KEYTAB_SIZE]; 113extern IR_KEYTAB_TYPE ir_codes_iodata_bctv7e[IR_KEYTAB_SIZE];
@@ -141,8 +142,10 @@ extern IR_KEYTAB_TYPE ir_codes_encore_enltv[IR_KEYTAB_SIZE];
141extern IR_KEYTAB_TYPE ir_codes_tt_1500[IR_KEYTAB_SIZE]; 142extern IR_KEYTAB_TYPE ir_codes_tt_1500[IR_KEYTAB_SIZE];
142extern IR_KEYTAB_TYPE ir_codes_fusionhdtv_mce[IR_KEYTAB_SIZE]; 143extern IR_KEYTAB_TYPE ir_codes_fusionhdtv_mce[IR_KEYTAB_SIZE];
143extern IR_KEYTAB_TYPE ir_codes_behold[IR_KEYTAB_SIZE]; 144extern IR_KEYTAB_TYPE ir_codes_behold[IR_KEYTAB_SIZE];
145extern IR_KEYTAB_TYPE ir_codes_behold_columbus[IR_KEYTAB_SIZE];
144extern IR_KEYTAB_TYPE ir_codes_pinnacle_pctv_hd[IR_KEYTAB_SIZE]; 146extern IR_KEYTAB_TYPE ir_codes_pinnacle_pctv_hd[IR_KEYTAB_SIZE];
145extern IR_KEYTAB_TYPE ir_codes_genius_tvgo_a11mce[IR_KEYTAB_SIZE]; 147extern IR_KEYTAB_TYPE ir_codes_genius_tvgo_a11mce[IR_KEYTAB_SIZE];
148extern IR_KEYTAB_TYPE ir_codes_powercolor_real_angel[IR_KEYTAB_SIZE];
146 149
147#endif 150#endif
148 151
diff --git a/include/media/soc_camera.h b/include/media/soc_camera.h
new file mode 100644
index 000000000000..6a8c8be7a1ae
--- /dev/null
+++ b/include/media/soc_camera.h
@@ -0,0 +1,179 @@
1/*
2 * camera image capture (abstract) bus driver header
3 *
4 * Copyright (C) 2006, Sascha Hauer, Pengutronix
5 * Copyright (C) 2008, Guennadi Liakhovetski <kernel@pengutronix.de>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef SOC_CAMERA_H
13#define SOC_CAMERA_H
14
15#include <linux/videodev2.h>
16#include <media/videobuf-dma-sg.h>
17
18struct soc_camera_device {
19 struct list_head list;
20 struct device dev;
21 struct device *control;
22 unsigned short width; /* Current window */
23 unsigned short height; /* sizes */
24 unsigned short x_min; /* Camera capabilities */
25 unsigned short y_min;
26 unsigned short x_current; /* Current window location */
27 unsigned short y_current;
28 unsigned short width_min;
29 unsigned short width_max;
30 unsigned short height_min;
31 unsigned short height_max;
32 unsigned short y_skip_top; /* Lines to skip at the top */
33 unsigned short gain;
34 unsigned short exposure;
35 unsigned char iface; /* Host number */
36 unsigned char devnum; /* Device number per host */
37 unsigned char buswidth; /* See comment in .c */
38 struct soc_camera_ops *ops;
39 struct video_device *vdev;
40 const struct soc_camera_data_format *current_fmt;
41 const struct soc_camera_data_format *formats;
42 int num_formats;
43 struct module *owner;
44 /* soc_camera.c private count. Only accessed with video_lock held */
45 int use_count;
46};
47
48struct soc_camera_file {
49 struct soc_camera_device *icd;
50 struct videobuf_queue vb_vidq;
51 spinlock_t *lock;
52};
53
54struct soc_camera_host {
55 struct list_head list;
56 struct device dev;
57 unsigned char nr; /* Host number */
58 size_t msize;
59 struct videobuf_queue_ops *vbq_ops;
60 void *priv;
61 char *drv_name;
62 struct soc_camera_host_ops *ops;
63};
64
65struct soc_camera_host_ops {
66 struct module *owner;
67 int (*add)(struct soc_camera_device *);
68 void (*remove)(struct soc_camera_device *);
69 int (*set_fmt_cap)(struct soc_camera_device *, __u32,
70 struct v4l2_rect *);
71 int (*try_fmt_cap)(struct soc_camera_device *, struct v4l2_format *);
72 int (*reqbufs)(struct soc_camera_file *, struct v4l2_requestbuffers *);
73 int (*querycap)(struct soc_camera_host *, struct v4l2_capability *);
74 int (*try_bus_param)(struct soc_camera_device *, __u32);
75 int (*set_bus_param)(struct soc_camera_device *, __u32);
76 unsigned int (*poll)(struct file *, poll_table *);
77 spinlock_t* (*spinlock_alloc)(struct soc_camera_file *);
78 void (*spinlock_free)(spinlock_t *);
79};
80
81struct soc_camera_link {
82 /* Camera bus id, used to match a camera and a bus */
83 int bus_id;
84 /* GPIO number to switch between 8 and 10 bit modes */
85 unsigned int gpio;
86};
87
88static inline struct soc_camera_device *to_soc_camera_dev(struct device *dev)
89{
90 return container_of(dev, struct soc_camera_device, dev);
91}
92
93static inline struct soc_camera_host *to_soc_camera_host(struct device *dev)
94{
95 return container_of(dev, struct soc_camera_host, dev);
96}
97
98extern int soc_camera_host_register(struct soc_camera_host *ici);
99extern void soc_camera_host_unregister(struct soc_camera_host *ici);
100extern int soc_camera_device_register(struct soc_camera_device *icd);
101extern void soc_camera_device_unregister(struct soc_camera_device *icd);
102
103extern int soc_camera_video_start(struct soc_camera_device *icd);
104extern void soc_camera_video_stop(struct soc_camera_device *icd);
105
106struct soc_camera_data_format {
107 char *name;
108 unsigned int depth;
109 __u32 fourcc;
110 enum v4l2_colorspace colorspace;
111};
112
113struct soc_camera_ops {
114 struct module *owner;
115 int (*probe)(struct soc_camera_device *);
116 void (*remove)(struct soc_camera_device *);
117 int (*init)(struct soc_camera_device *);
118 int (*release)(struct soc_camera_device *);
119 int (*start_capture)(struct soc_camera_device *);
120 int (*stop_capture)(struct soc_camera_device *);
121 int (*set_fmt_cap)(struct soc_camera_device *, __u32,
122 struct v4l2_rect *);
123 int (*try_fmt_cap)(struct soc_camera_device *, struct v4l2_format *);
124 unsigned long (*query_bus_param)(struct soc_camera_device *);
125 int (*set_bus_param)(struct soc_camera_device *, unsigned long);
126 int (*get_chip_id)(struct soc_camera_device *,
127 struct v4l2_chip_ident *);
128#ifdef CONFIG_VIDEO_ADV_DEBUG
129 int (*get_register)(struct soc_camera_device *, struct v4l2_register *);
130 int (*set_register)(struct soc_camera_device *, struct v4l2_register *);
131#endif
132 int (*get_control)(struct soc_camera_device *, struct v4l2_control *);
133 int (*set_control)(struct soc_camera_device *, struct v4l2_control *);
134 const struct v4l2_queryctrl *controls;
135 int num_controls;
136};
137
138static inline struct v4l2_queryctrl const *soc_camera_find_qctrl(
139 struct soc_camera_ops *ops, int id)
140{
141 int i;
142
143 for (i = 0; i < ops->num_controls; i++)
144 if (ops->controls[i].id == id)
145 return &ops->controls[i];
146
147 return NULL;
148}
149
150#define SOCAM_MASTER (1 << 0)
151#define SOCAM_SLAVE (1 << 1)
152#define SOCAM_HSYNC_ACTIVE_HIGH (1 << 2)
153#define SOCAM_HSYNC_ACTIVE_LOW (1 << 3)
154#define SOCAM_VSYNC_ACTIVE_HIGH (1 << 4)
155#define SOCAM_VSYNC_ACTIVE_LOW (1 << 5)
156#define SOCAM_DATAWIDTH_8 (1 << 6)
157#define SOCAM_DATAWIDTH_9 (1 << 7)
158#define SOCAM_DATAWIDTH_10 (1 << 8)
159#define SOCAM_PCLK_SAMPLE_RISING (1 << 9)
160#define SOCAM_PCLK_SAMPLE_FALLING (1 << 10)
161
162#define SOCAM_DATAWIDTH_MASK (SOCAM_DATAWIDTH_8 | SOCAM_DATAWIDTH_9 | \
163 SOCAM_DATAWIDTH_10)
164
165static inline unsigned long soc_camera_bus_param_compatible(
166 unsigned long camera_flags, unsigned long bus_flags)
167{
168 unsigned long common_flags, hsync, vsync, pclk;
169
170 common_flags = camera_flags & bus_flags;
171
172 hsync = common_flags & (SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_HSYNC_ACTIVE_LOW);
173 vsync = common_flags & (SOCAM_VSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_LOW);
174 pclk = common_flags & (SOCAM_PCLK_SAMPLE_RISING | SOCAM_PCLK_SAMPLE_FALLING);
175
176 return (!hsync || !vsync || !pclk) ? 0 : common_flags;
177}
178
179#endif
diff --git a/include/media/tuner-types.h b/include/media/tuner-types.h
index b201371416a0..ab03c5344209 100644
--- a/include/media/tuner-types.h
+++ b/include/media/tuner-types.h
@@ -6,10 +6,11 @@
6#define __TUNER_TYPES_H__ 6#define __TUNER_TYPES_H__
7 7
8enum param_type { 8enum param_type {
9 TUNER_PARAM_TYPE_RADIO, \ 9 TUNER_PARAM_TYPE_RADIO,
10 TUNER_PARAM_TYPE_PAL, \ 10 TUNER_PARAM_TYPE_PAL,
11 TUNER_PARAM_TYPE_SECAM, \ 11 TUNER_PARAM_TYPE_SECAM,
12 TUNER_PARAM_TYPE_NTSC 12 TUNER_PARAM_TYPE_NTSC,
13 TUNER_PARAM_TYPE_DIGITAL,
13}; 14};
14 15
15struct tuner_range { 16struct tuner_range {
@@ -105,6 +106,7 @@ struct tuner_params {
105 the SECAM-L/L' standards. Range: -16:+15 */ 106 the SECAM-L/L' standards. Range: -16:+15 */
106 signed int default_top_secam_high:5; 107 signed int default_top_secam_high:5;
107 108
109 u16 iffreq;
108 110
109 unsigned int count; 111 unsigned int count;
110 struct tuner_range *ranges; 112 struct tuner_range *ranges;
@@ -114,6 +116,13 @@ struct tunertype {
114 char *name; 116 char *name;
115 unsigned int count; 117 unsigned int count;
116 struct tuner_params *params; 118 struct tuner_params *params;
119
120 u16 min;
121 u16 max;
122 u32 stepsize;
123
124 u8 *initdata;
125 u8 *sleepdata;
117}; 126};
118 127
119extern struct tunertype tuners[]; 128extern struct tunertype tuners[];
diff --git a/include/media/tuner.h b/include/media/tuner.h
index 1bf24a6ed8f1..77068fcc86bd 100644
--- a/include/media/tuner.h
+++ b/include/media/tuner.h
@@ -78,7 +78,7 @@
78 78
79#define TUNER_HITACHI_NTSC 40 79#define TUNER_HITACHI_NTSC 40
80#define TUNER_PHILIPS_PAL_MK 41 80#define TUNER_PHILIPS_PAL_MK 41
81#define TUNER_PHILIPS_ATSC 42 81#define TUNER_PHILIPS_FCV1236D 42
82#define TUNER_PHILIPS_FM1236_MK3 43 82#define TUNER_PHILIPS_FM1236_MK3 43
83 83
84#define TUNER_PHILIPS_4IN1 44 /* ATI TV Wonder Pro - Conexant */ 84#define TUNER_PHILIPS_4IN1 44 /* ATI TV Wonder Pro - Conexant */
diff --git a/include/media/v4l2-chip-ident.h b/include/media/v4l2-chip-ident.h
index 032bb75f69c2..0ea0bd85c036 100644
--- a/include/media/v4l2-chip-ident.h
+++ b/include/media/v4l2-chip-ident.h
@@ -153,6 +153,12 @@ enum {
153 V4L2_IDENT_MSP4428G = 44287, 153 V4L2_IDENT_MSP4428G = 44287,
154 V4L2_IDENT_MSP4448G = 44487, 154 V4L2_IDENT_MSP4448G = 44487,
155 V4L2_IDENT_MSP4458G = 44587, 155 V4L2_IDENT_MSP4458G = 44587,
156
157 /* Micron CMOS sensor chips: 45000-45099 */
158 V4L2_IDENT_MT9M001C12ST = 45000,
159 V4L2_IDENT_MT9M001C12STM = 45005,
160 V4L2_IDENT_MT9V022IX7ATC = 45010, /* No way to detect "normal" I77ATx */
161 V4L2_IDENT_MT9V022IX7ATM = 45015, /* and "lead free" IA7ATx chips */
156}; 162};
157 163
158#endif 164#endif
diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
index f2114459995d..a807d2f86ee8 100644
--- a/include/media/v4l2-dev.h
+++ b/include/media/v4l2-dev.h
@@ -318,6 +318,10 @@ struct video_device
318 int (*vidioc_g_chip_ident) (struct file *file, void *fh, 318 int (*vidioc_g_chip_ident) (struct file *file, void *fh,
319 struct v4l2_chip_ident *chip); 319 struct v4l2_chip_ident *chip);
320 320
321 /* For other private ioctls */
322 int (*vidioc_default) (struct file *file, void *fh,
323 int cmd, void *arg);
324
321 325
322#ifdef OBSOLETE_OWNER /* to be removed soon */ 326#ifdef OBSOLETE_OWNER /* to be removed soon */
323/* obsolete -- fops->owner is used instead */ 327/* obsolete -- fops->owner is used instead */
diff --git a/include/media/videobuf-core.h b/include/media/videobuf-core.h
index 99033945cdee..5b39a22533fe 100644
--- a/include/media/videobuf-core.h
+++ b/include/media/videobuf-core.h
@@ -13,6 +13,9 @@
13 * the Free Software Foundation; either version 2 13 * the Free Software Foundation; either version 2
14 */ 14 */
15 15
16#ifndef _VIDEOBUF_CORE_H
17#define _VIDEOBUF_CORE_H
18
16#include <linux/poll.h> 19#include <linux/poll.h>
17#ifdef CONFIG_VIDEO_V4L1_COMPAT 20#ifdef CONFIG_VIDEO_V4L1_COMPAT
18#include <linux/videodev.h> 21#include <linux/videodev.h>
@@ -123,7 +126,8 @@ struct videobuf_queue_ops {
123struct videobuf_qtype_ops { 126struct videobuf_qtype_ops {
124 u32 magic; 127 u32 magic;
125 128
126 void* (*alloc) (size_t size); 129 void *(*alloc) (size_t size);
130 void *(*vmalloc) (struct videobuf_buffer *buf);
127 int (*iolock) (struct videobuf_queue* q, 131 int (*iolock) (struct videobuf_queue* q,
128 struct videobuf_buffer *vb, 132 struct videobuf_buffer *vb,
129 struct v4l2_framebuffer *fbuf); 133 struct v4l2_framebuffer *fbuf);
@@ -151,7 +155,9 @@ struct videobuf_qtype_ops {
151struct videobuf_queue { 155struct videobuf_queue {
152 struct mutex vb_lock; 156 struct mutex vb_lock;
153 spinlock_t *irqlock; 157 spinlock_t *irqlock;
154 void *dev; /* on pci, points to struct pci_dev */ 158 struct device *dev;
159
160 wait_queue_head_t wait; /* wait if queue is empty */
155 161
156 enum v4l2_buf_type type; 162 enum v4l2_buf_type type;
157 unsigned int inputs; /* for V4L2_BUF_FLAG_INPUT */ 163 unsigned int inputs; /* for V4L2_BUF_FLAG_INPUT */
@@ -183,9 +189,13 @@ int videobuf_iolock(struct videobuf_queue* q, struct videobuf_buffer *vb,
183 189
184void *videobuf_alloc(struct videobuf_queue* q); 190void *videobuf_alloc(struct videobuf_queue* q);
185 191
192/* Used on videobuf-dvb */
193void *videobuf_queue_to_vmalloc (struct videobuf_queue* q,
194 struct videobuf_buffer *buf);
195
186void videobuf_queue_core_init(struct videobuf_queue *q, 196void videobuf_queue_core_init(struct videobuf_queue *q,
187 struct videobuf_queue_ops *ops, 197 struct videobuf_queue_ops *ops,
188 void *dev, 198 struct device *dev,
189 spinlock_t *irqlock, 199 spinlock_t *irqlock,
190 enum v4l2_buf_type type, 200 enum v4l2_buf_type type,
191 enum v4l2_field field, 201 enum v4l2_field field,
@@ -231,10 +241,4 @@ int videobuf_mmap_free(struct videobuf_queue *q);
231int videobuf_mmap_mapper(struct videobuf_queue *q, 241int videobuf_mmap_mapper(struct videobuf_queue *q,
232 struct vm_area_struct *vma); 242 struct vm_area_struct *vma);
233 243
234/* --------------------------------------------------------------------- */ 244#endif
235
236/*
237 * Local variables:
238 * c-basic-offset: 8
239 * End:
240 */
diff --git a/include/media/videobuf-dma-sg.h b/include/media/videobuf-dma-sg.h
index 38105031db23..be8da269ee33 100644
--- a/include/media/videobuf-dma-sg.h
+++ b/include/media/videobuf-dma-sg.h
@@ -1,5 +1,5 @@
1/* 1/*
2 * helper functions for PCI DMA video4linux capture buffers 2 * helper functions for SG DMA video4linux capture buffers
3 * 3 *
4 * The functions expect the hardware being able to scatter gatter 4 * The functions expect the hardware being able to scatter gatter
5 * (i.e. the buffers are not linear in physical memory, but fragmented 5 * (i.e. the buffers are not linear in physical memory, but fragmented
@@ -68,9 +68,6 @@ struct videobuf_dmabuf {
68 /* for kernel buffers */ 68 /* for kernel buffers */
69 void *vmalloc; 69 void *vmalloc;
70 70
71 /* Stores the userspace pointer to vmalloc area */
72 void *varea;
73
74 /* for overlay buffers (pci-pci dma) */ 71 /* for overlay buffers (pci-pci dma) */
75 dma_addr_t bus_addr; 72 dma_addr_t bus_addr;
76 73
@@ -81,7 +78,7 @@ struct videobuf_dmabuf {
81 int direction; 78 int direction;
82}; 79};
83 80
84struct videbuf_pci_sg_memory 81struct videobuf_dma_sg_memory
85{ 82{
86 u32 magic; 83 u32 magic;
87 84
@@ -103,11 +100,11 @@ int videobuf_dma_sync(struct videobuf_queue* q,struct videobuf_dmabuf *dma);
103int videobuf_dma_unmap(struct videobuf_queue* q,struct videobuf_dmabuf *dma); 100int videobuf_dma_unmap(struct videobuf_queue* q,struct videobuf_dmabuf *dma);
104struct videobuf_dmabuf *videobuf_to_dma (struct videobuf_buffer *buf); 101struct videobuf_dmabuf *videobuf_to_dma (struct videobuf_buffer *buf);
105 102
106void *videobuf_pci_alloc (size_t size); 103void *videobuf_sg_alloc(size_t size);
107 104
108void videobuf_queue_pci_init(struct videobuf_queue* q, 105void videobuf_queue_sg_init(struct videobuf_queue* q,
109 struct videobuf_queue_ops *ops, 106 struct videobuf_queue_ops *ops,
110 void *dev, 107 struct device *dev,
111 spinlock_t *irqlock, 108 spinlock_t *irqlock,
112 enum v4l2_buf_type type, 109 enum v4l2_buf_type type,
113 enum v4l2_field field, 110 enum v4l2_field field,
@@ -117,6 +114,6 @@ void videobuf_queue_pci_init(struct videobuf_queue* q,
117 /*FIXME: these variants are used only on *-alsa code, where videobuf is 114 /*FIXME: these variants are used only on *-alsa code, where videobuf is
118 * used without queue 115 * used without queue
119 */ 116 */
120int videobuf_pci_dma_map(struct pci_dev *pci,struct videobuf_dmabuf *dma); 117int videobuf_sg_dma_map(struct device *dev, struct videobuf_dmabuf *dma);
121int videobuf_pci_dma_unmap(struct pci_dev *pci,struct videobuf_dmabuf *dma); 118int videobuf_sg_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma);
122 119
diff --git a/include/media/videobuf-dvb.h b/include/media/videobuf-dvb.h
index 8233cafdeef6..b77748696329 100644
--- a/include/media/videobuf-dvb.h
+++ b/include/media/videobuf-dvb.h
@@ -27,7 +27,8 @@ struct videobuf_dvb {
27int videobuf_dvb_register(struct videobuf_dvb *dvb, 27int videobuf_dvb_register(struct videobuf_dvb *dvb,
28 struct module *module, 28 struct module *module,
29 void *adapter_priv, 29 void *adapter_priv,
30 struct device *device); 30 struct device *device,
31 short *adapter_nr);
31void videobuf_dvb_unregister(struct videobuf_dvb *dvb); 32void videobuf_dvb_unregister(struct videobuf_dvb *dvb);
32 33
33/* 34/*
diff --git a/include/media/videobuf-vmalloc.h b/include/media/videobuf-vmalloc.h
index ec63ab0fab93..aed39460c154 100644
--- a/include/media/videobuf-vmalloc.h
+++ b/include/media/videobuf-vmalloc.h
@@ -12,6 +12,8 @@
12 * it under the terms of the GNU General Public License as published by 12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 13 * the Free Software Foundation; either version 2
14 */ 14 */
15#ifndef _VIDEOBUF_VMALLOC_H
16#define _VIDEOBUF_VMALLOC_H
15 17
16#include <media/videobuf-core.h> 18#include <media/videobuf-core.h>
17 19
@@ -39,3 +41,5 @@ void videobuf_queue_vmalloc_init(struct videobuf_queue* q,
39void *videobuf_to_vmalloc (struct videobuf_buffer *buf); 41void *videobuf_to_vmalloc (struct videobuf_buffer *buf);
40 42
41void videobuf_vmalloc_free (struct videobuf_buffer *buf); 43void videobuf_vmalloc_free (struct videobuf_buffer *buf);
44
45#endif
diff --git a/include/net/ipv6.h b/include/net/ipv6.h
index 49c48983019f..e0a612bc9c4e 100644
--- a/include/net/ipv6.h
+++ b/include/net/ipv6.h
@@ -383,6 +383,15 @@ static inline int ipv6_addr_orchid(const struct in6_addr *a)
383 == htonl(0x20010010)); 383 == htonl(0x20010010));
384} 384}
385 385
386static inline void ipv6_addr_set_v4mapped(const __be32 addr,
387 struct in6_addr *v4mapped)
388{
389 ipv6_addr_set(v4mapped,
390 0, 0,
391 htonl(0x0000FFFF),
392 addr);
393}
394
386/* 395/*
387 * find the first different bit between two addresses 396 * find the first different bit between two addresses
388 * length of address must be a multiple of 32bits 397 * length of address must be a multiple of 32bits
diff --git a/include/sound/ac97_codec.h b/include/sound/ac97_codec.h
index 01480581f825..049edc5e6461 100644
--- a/include/sound/ac97_codec.h
+++ b/include/sound/ac97_codec.h
@@ -397,6 +397,7 @@
397#define AC97_HAS_NO_TONE (1<<16) /* no Tone volume */ 397#define AC97_HAS_NO_TONE (1<<16) /* no Tone volume */
398#define AC97_HAS_NO_STD_PCM (1<<17) /* no standard AC97 PCM volume and mute */ 398#define AC97_HAS_NO_STD_PCM (1<<17) /* no standard AC97 PCM volume and mute */
399#define AC97_HAS_NO_AUX (1<<18) /* no standard AC97 AUX volume and mute */ 399#define AC97_HAS_NO_AUX (1<<18) /* no standard AC97 AUX volume and mute */
400#define AC97_HAS_8CH (1<<19) /* supports 8-channel output */
400 401
401/* rates indexes */ 402/* rates indexes */
402#define AC97_RATES_FRONT_DAC 0 403#define AC97_RATES_FRONT_DAC 0
diff --git a/include/sound/ak4114.h b/include/sound/ak4114.h
index 4e80d3fe7381..d293d36a66b8 100644
--- a/include/sound/ak4114.h
+++ b/include/sound/ak4114.h
@@ -182,6 +182,7 @@ struct ak4114 {
182 unsigned char rcs0; 182 unsigned char rcs0;
183 unsigned char rcs1; 183 unsigned char rcs1;
184 struct delayed_work work; 184 struct delayed_work work;
185 unsigned int check_flags;
185 void *change_callback_private; 186 void *change_callback_private;
186 void (*change_callback)(struct ak4114 *ak4114, unsigned char c0, unsigned char c1); 187 void (*change_callback)(struct ak4114 *ak4114, unsigned char c0, unsigned char c1);
187}; 188};
diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
index 6153b91cdc3e..891cf1aea8b1 100644
--- a/include/sound/ak4xxx-adda.h
+++ b/include/sound/ak4xxx-adda.h
@@ -68,7 +68,7 @@ struct snd_akm4xxx {
68 enum { 68 enum {
69 SND_AK4524, SND_AK4528, SND_AK4529, 69 SND_AK4524, SND_AK4528, SND_AK4529,
70 SND_AK4355, SND_AK4358, SND_AK4381, 70 SND_AK4355, SND_AK4358, SND_AK4381,
71 SND_AK5365, NON_AKM 71 SND_AK5365
72 } type; 72 } type;
73 73
74 /* (array) information of combined codecs */ 74 /* (array) information of combined codecs */
diff --git a/include/sound/asoundef.h b/include/sound/asoundef.h
index 024ce62f7d16..a6e0facf8a37 100644
--- a/include/sound/asoundef.h
+++ b/include/sound/asoundef.h
@@ -112,6 +112,14 @@
112#define IEC958_AES3_CON_CLOCK_1000PPM (0<<4) /* 1000 ppm */ 112#define IEC958_AES3_CON_CLOCK_1000PPM (0<<4) /* 1000 ppm */
113#define IEC958_AES3_CON_CLOCK_50PPM (1<<4) /* 50 ppm */ 113#define IEC958_AES3_CON_CLOCK_50PPM (1<<4) /* 50 ppm */
114#define IEC958_AES3_CON_CLOCK_VARIABLE (2<<4) /* variable pitch */ 114#define IEC958_AES3_CON_CLOCK_VARIABLE (2<<4) /* variable pitch */
115#define IEC958_AES4_CON_MAX_WORDLEN_24 (1<<0) /* 0 = 20-bit, 1 = 24-bit */
116#define IEC958_AES4_CON_WORDLEN (7<<1) /* mask - sample word length */
117#define IEC958_AES4_CON_WORDLEN_NOTID (0<<1) /* not indicated */
118#define IEC958_AES4_CON_WORDLEN_20_16 (1<<1) /* 20-bit or 16-bit */
119#define IEC958_AES4_CON_WORDLEN_22_18 (2<<1) /* 22-bit or 18-bit */
120#define IEC958_AES4_CON_WORDLEN_23_19 (4<<1) /* 23-bit or 19-bit */
121#define IEC958_AES4_CON_WORDLEN_24_20 (5<<1) /* 24-bit or 20-bit */
122#define IEC958_AES4_CON_WORDLEN_21_17 (6<<1) /* 21-bit or 17-bit */
115 123
116/***************************************************************************** 124/*****************************************************************************
117 * * 125 * *
diff --git a/include/sound/control.h b/include/sound/control.h
index e79baa63912f..3dc1291f52db 100644
--- a/include/sound/control.h
+++ b/include/sound/control.h
@@ -169,4 +169,11 @@ int snd_ctl_boolean_mono_info(struct snd_kcontrol *kcontrol,
169int snd_ctl_boolean_stereo_info(struct snd_kcontrol *kcontrol, 169int snd_ctl_boolean_stereo_info(struct snd_kcontrol *kcontrol,
170 struct snd_ctl_elem_info *uinfo); 170 struct snd_ctl_elem_info *uinfo);
171 171
172/*
173 * virtual master control
174 */
175struct snd_kcontrol *snd_ctl_make_virtual_master(char *name,
176 const unsigned int *tlv);
177int snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave);
178
172#endif /* __SOUND_CONTROL_H */ 179#endif /* __SOUND_CONTROL_H */
diff --git a/include/sound/core.h b/include/sound/core.h
index 4fc0235ad784..695ee53488a3 100644
--- a/include/sound/core.h
+++ b/include/sound/core.h
@@ -277,8 +277,8 @@ int snd_minor_info_done(void);
277int snd_minor_info_oss_init(void); 277int snd_minor_info_oss_init(void);
278int snd_minor_info_oss_done(void); 278int snd_minor_info_oss_done(void);
279#else 279#else
280#define snd_minor_info_oss_init() /*NOP*/ 280static inline int snd_minor_info_oss_init(void) { return 0; }
281#define snd_minor_info_oss_done() /*NOP*/ 281static inline int snd_minor_info_oss_done(void) { return 0; }
282#endif 282#endif
283 283
284/* memory.c */ 284/* memory.c */
@@ -310,7 +310,7 @@ int snd_card_file_add(struct snd_card *card, struct file *file);
310int snd_card_file_remove(struct snd_card *card, struct file *file); 310int snd_card_file_remove(struct snd_card *card, struct file *file);
311 311
312#ifndef snd_card_set_dev 312#ifndef snd_card_set_dev
313#define snd_card_set_dev(card,devptr) ((card)->dev = (devptr)) 313#define snd_card_set_dev(card, devptr) ((card)->dev = (devptr))
314#endif 314#endif
315 315
316/* device.c */ 316/* device.c */
@@ -373,7 +373,7 @@ void snd_verbose_printd(const char *file, int line, const char *format, ...)
373 * snd_printd - debug printk 373 * snd_printd - debug printk
374 * @fmt: format string 374 * @fmt: format string
375 * 375 *
376 * Compiled only when Works like snd_printk() for debugging purpose. 376 * Works like snd_printk() for debugging purposes.
377 * Ignored when CONFIG_SND_DEBUG is not set. 377 * Ignored when CONFIG_SND_DEBUG is not set.
378 */ 378 */
379#define snd_printd(fmt, args...) \ 379#define snd_printd(fmt, args...) \
@@ -417,7 +417,7 @@ void snd_verbose_printd(const char *file, int line, const char *format, ...)
417 * snd_printdd - debug printk 417 * snd_printdd - debug printk
418 * @format: format string 418 * @format: format string
419 * 419 *
420 * Compiled only when Works like snd_printk() for debugging purpose. 420 * Works like snd_printk() for debugging purposes.
421 * Ignored when CONFIG_SND_DEBUG_DETECT is not set. 421 * Ignored when CONFIG_SND_DEBUG_DETECT is not set.
422 */ 422 */
423#define snd_printdd(format, args...) snd_printk(format, ##args) 423#define snd_printdd(format, args...) snd_printk(format, ##args)
diff --git a/include/sound/mpu401.h b/include/sound/mpu401.h
index d45218b44dfe..68b634b75068 100644
--- a/include/sound/mpu401.h
+++ b/include/sound/mpu401.h
@@ -103,6 +103,21 @@ struct snd_mpu401 {
103#define MPU401D(mpu) (mpu)->port 103#define MPU401D(mpu) (mpu)->port
104 104
105/* 105/*
106 * control register bits
107 */
108/* read MPU401C() */
109#define MPU401_RX_EMPTY 0x80
110#define MPU401_TX_FULL 0x40
111
112/* write MPU401C() */
113#define MPU401_RESET 0xff
114#define MPU401_ENTER_UART 0x3f
115
116/* read MPU401D() */
117#define MPU401_ACK 0xfe
118
119
120/*
106 121
107 */ 122 */
108 123
diff --git a/include/sound/version.h b/include/sound/version.h
index fac66c49445a..ed6fb2eb1eac 100644
--- a/include/sound/version.h
+++ b/include/sound/version.h
@@ -1,3 +1,3 @@
1/* include/version.h. Generated by alsa/ksync script. */ 1/* include/version.h. Generated by alsa/ksync script. */
2#define CONFIG_SND_VERSION "1.0.16rc2" 2#define CONFIG_SND_VERSION "1.0.16"
3#define CONFIG_SND_DATE " (Thu Jan 31 16:40:16 2008 UTC)" 3#define CONFIG_SND_DATE ""
diff --git a/lib/lmb.c b/lib/lmb.c
index 896e2832099e..207147ab25e4 100644
--- a/lib/lmb.c
+++ b/lib/lmb.c
@@ -346,7 +346,7 @@ u64 __init __lmb_alloc_base(u64 size, u64 align, u64 max_addr)
346 if (j < 0) { 346 if (j < 0) {
347 /* this area isn't reserved, take it */ 347 /* this area isn't reserved, take it */
348 if (lmb_add_region(&lmb.reserved, base, 348 if (lmb_add_region(&lmb.reserved, base,
349 size) < 0) 349 lmb_align_up(size, align)) < 0)
350 return 0; 350 return 0;
351 return base; 351 return base;
352 } 352 }
diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
index bc39e417694a..cf857c4dc7b1 100644
--- a/net/core/rtnetlink.c
+++ b/net/core/rtnetlink.c
@@ -82,6 +82,11 @@ int rtnl_trylock(void)
82 return mutex_trylock(&rtnl_mutex); 82 return mutex_trylock(&rtnl_mutex);
83} 83}
84 84
85int rtnl_is_locked(void)
86{
87 return mutex_is_locked(&rtnl_mutex);
88}
89
85static struct rtnl_link *rtnl_msg_handlers[NPROTO]; 90static struct rtnl_link *rtnl_msg_handlers[NPROTO];
86 91
87static inline int rtm_msgindex(int msgtype) 92static inline int rtm_msgindex(int msgtype)
@@ -1402,6 +1407,7 @@ EXPORT_SYMBOL(rtnetlink_put_metrics);
1402EXPORT_SYMBOL(rtnl_lock); 1407EXPORT_SYMBOL(rtnl_lock);
1403EXPORT_SYMBOL(rtnl_trylock); 1408EXPORT_SYMBOL(rtnl_trylock);
1404EXPORT_SYMBOL(rtnl_unlock); 1409EXPORT_SYMBOL(rtnl_unlock);
1410EXPORT_SYMBOL(rtnl_is_locked);
1405EXPORT_SYMBOL(rtnl_unicast); 1411EXPORT_SYMBOL(rtnl_unicast);
1406EXPORT_SYMBOL(rtnl_notify); 1412EXPORT_SYMBOL(rtnl_notify);
1407EXPORT_SYMBOL(rtnl_set_sk_err); 1413EXPORT_SYMBOL(rtnl_set_sk_err);
diff --git a/net/ipv4/fib_hash.c b/net/ipv4/fib_hash.c
index 02088deb0461..2e2fc3376ac9 100644
--- a/net/ipv4/fib_hash.c
+++ b/net/ipv4/fib_hash.c
@@ -1003,7 +1003,7 @@ static unsigned fib_flag_trans(int type, __be32 mask, struct fib_info *fi)
1003static int fib_seq_show(struct seq_file *seq, void *v) 1003static int fib_seq_show(struct seq_file *seq, void *v)
1004{ 1004{
1005 struct fib_iter_state *iter; 1005 struct fib_iter_state *iter;
1006 char bf[128]; 1006 int len;
1007 __be32 prefix, mask; 1007 __be32 prefix, mask;
1008 unsigned flags; 1008 unsigned flags;
1009 struct fib_node *f; 1009 struct fib_node *f;
@@ -1025,18 +1025,19 @@ static int fib_seq_show(struct seq_file *seq, void *v)
1025 mask = FZ_MASK(iter->zone); 1025 mask = FZ_MASK(iter->zone);
1026 flags = fib_flag_trans(fa->fa_type, mask, fi); 1026 flags = fib_flag_trans(fa->fa_type, mask, fi);
1027 if (fi) 1027 if (fi)
1028 snprintf(bf, sizeof(bf), 1028 seq_printf(seq,
1029 "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u", 1029 "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
1030 fi->fib_dev ? fi->fib_dev->name : "*", prefix, 1030 fi->fib_dev ? fi->fib_dev->name : "*", prefix,
1031 fi->fib_nh->nh_gw, flags, 0, 0, fi->fib_priority, 1031 fi->fib_nh->nh_gw, flags, 0, 0, fi->fib_priority,
1032 mask, (fi->fib_advmss ? fi->fib_advmss + 40 : 0), 1032 mask, (fi->fib_advmss ? fi->fib_advmss + 40 : 0),
1033 fi->fib_window, 1033 fi->fib_window,
1034 fi->fib_rtt >> 3); 1034 fi->fib_rtt >> 3, &len);
1035 else 1035 else
1036 snprintf(bf, sizeof(bf), 1036 seq_printf(seq,
1037 "*\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u", 1037 "*\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u%n",
1038 prefix, 0, flags, 0, 0, 0, mask, 0, 0, 0); 1038 prefix, 0, flags, 0, 0, 0, mask, 0, 0, 0, &len);
1039 seq_printf(seq, "%-127s\n", bf); 1039
1040 seq_printf(seq, "%*s\n", 127 - len, "");
1040out: 1041out:
1041 return 0; 1042 return 0;
1042} 1043}
diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c
index ea294fffb9ce..4b02d14e7ab9 100644
--- a/net/ipv4/fib_trie.c
+++ b/net/ipv4/fib_trie.c
@@ -2602,15 +2602,16 @@ static int fib_route_seq_show(struct seq_file *seq, void *v)
2602 list_for_each_entry_rcu(fa, &li->falh, fa_list) { 2602 list_for_each_entry_rcu(fa, &li->falh, fa_list) {
2603 const struct fib_info *fi = fa->fa_info; 2603 const struct fib_info *fi = fa->fa_info;
2604 unsigned flags = fib_flag_trans(fa->fa_type, mask, fi); 2604 unsigned flags = fib_flag_trans(fa->fa_type, mask, fi);
2605 char bf[128]; 2605 int len;
2606 2606
2607 if (fa->fa_type == RTN_BROADCAST 2607 if (fa->fa_type == RTN_BROADCAST
2608 || fa->fa_type == RTN_MULTICAST) 2608 || fa->fa_type == RTN_MULTICAST)
2609 continue; 2609 continue;
2610 2610
2611 if (fi) 2611 if (fi)
2612 snprintf(bf, sizeof(bf), 2612 seq_printf(seq,
2613 "%s\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u", 2613 "%s\t%08X\t%08X\t%04X\t%d\t%u\t"
2614 "%d\t%08X\t%d\t%u\t%u%n",
2614 fi->fib_dev ? fi->fib_dev->name : "*", 2615 fi->fib_dev ? fi->fib_dev->name : "*",
2615 prefix, 2616 prefix,
2616 fi->fib_nh->nh_gw, flags, 0, 0, 2617 fi->fib_nh->nh_gw, flags, 0, 0,
@@ -2619,14 +2620,15 @@ static int fib_route_seq_show(struct seq_file *seq, void *v)
2619 (fi->fib_advmss ? 2620 (fi->fib_advmss ?
2620 fi->fib_advmss + 40 : 0), 2621 fi->fib_advmss + 40 : 0),
2621 fi->fib_window, 2622 fi->fib_window,
2622 fi->fib_rtt >> 3); 2623 fi->fib_rtt >> 3, &len);
2623 else 2624 else
2624 snprintf(bf, sizeof(bf), 2625 seq_printf(seq,
2625 "*\t%08X\t%08X\t%04X\t%d\t%u\t%d\t%08X\t%d\t%u\t%u", 2626 "*\t%08X\t%08X\t%04X\t%d\t%u\t"
2627 "%d\t%08X\t%d\t%u\t%u%n",
2626 prefix, 0, flags, 0, 0, 0, 2628 prefix, 0, flags, 0, 0, 0,
2627 mask, 0, 0, 0); 2629 mask, 0, 0, 0, &len);
2628 2630
2629 seq_printf(seq, "%-127s\n", bf); 2631 seq_printf(seq, "%*s\n", 127 - len, "");
2630 } 2632 }
2631 } 2633 }
2632 2634
diff --git a/net/ipv4/route.c b/net/ipv4/route.c
index 780e9484c825..ce25a13f3430 100644
--- a/net/ipv4/route.c
+++ b/net/ipv4/route.c
@@ -367,10 +367,10 @@ static int rt_cache_seq_show(struct seq_file *seq, void *v)
367 "HHUptod\tSpecDst"); 367 "HHUptod\tSpecDst");
368 else { 368 else {
369 struct rtable *r = v; 369 struct rtable *r = v;
370 char temp[256]; 370 int len;
371 371
372 sprintf(temp, "%s\t%08lX\t%08lX\t%8X\t%d\t%u\t%d\t" 372 seq_printf(seq, "%s\t%08lX\t%08lX\t%8X\t%d\t%u\t%d\t"
373 "%08lX\t%d\t%u\t%u\t%02X\t%d\t%1d\t%08X", 373 "%08lX\t%d\t%u\t%u\t%02X\t%d\t%1d\t%08X%n",
374 r->u.dst.dev ? r->u.dst.dev->name : "*", 374 r->u.dst.dev ? r->u.dst.dev->name : "*",
375 (unsigned long)r->rt_dst, (unsigned long)r->rt_gateway, 375 (unsigned long)r->rt_dst, (unsigned long)r->rt_gateway,
376 r->rt_flags, atomic_read(&r->u.dst.__refcnt), 376 r->rt_flags, atomic_read(&r->u.dst.__refcnt),
@@ -384,8 +384,9 @@ static int rt_cache_seq_show(struct seq_file *seq, void *v)
384 r->u.dst.hh ? atomic_read(&r->u.dst.hh->hh_refcnt) : -1, 384 r->u.dst.hh ? atomic_read(&r->u.dst.hh->hh_refcnt) : -1,
385 r->u.dst.hh ? (r->u.dst.hh->hh_output == 385 r->u.dst.hh ? (r->u.dst.hh->hh_output ==
386 dev_queue_xmit) : 0, 386 dev_queue_xmit) : 0,
387 r->rt_spec_dst); 387 r->rt_spec_dst, &len);
388 seq_printf(seq, "%-127s\n", temp); 388
389 seq_printf(seq, "%*s\n", 127 - len, "");
389 } 390 }
390 return 0; 391 return 0;
391} 392}
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 776615180b93..0e9bc120707d 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -2255,13 +2255,13 @@ void tcp_proc_unregister(struct net *net, struct tcp_seq_afinfo *afinfo)
2255} 2255}
2256 2256
2257static void get_openreq4(struct sock *sk, struct request_sock *req, 2257static void get_openreq4(struct sock *sk, struct request_sock *req,
2258 char *tmpbuf, int i, int uid) 2258 struct seq_file *f, int i, int uid, int *len)
2259{ 2259{
2260 const struct inet_request_sock *ireq = inet_rsk(req); 2260 const struct inet_request_sock *ireq = inet_rsk(req);
2261 int ttd = req->expires - jiffies; 2261 int ttd = req->expires - jiffies;
2262 2262
2263 sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X" 2263 seq_printf(f, "%4d: %08X:%04X %08X:%04X"
2264 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p", 2264 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %u %d %p%n",
2265 i, 2265 i,
2266 ireq->loc_addr, 2266 ireq->loc_addr,
2267 ntohs(inet_sk(sk)->sport), 2267 ntohs(inet_sk(sk)->sport),
@@ -2276,10 +2276,11 @@ static void get_openreq4(struct sock *sk, struct request_sock *req,
2276 0, /* non standard timer */ 2276 0, /* non standard timer */
2277 0, /* open_requests have no inode */ 2277 0, /* open_requests have no inode */
2278 atomic_read(&sk->sk_refcnt), 2278 atomic_read(&sk->sk_refcnt),
2279 req); 2279 req,
2280 len);
2280} 2281}
2281 2282
2282static void get_tcp4_sock(struct sock *sk, char *tmpbuf, int i) 2283static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
2283{ 2284{
2284 int timer_active; 2285 int timer_active;
2285 unsigned long timer_expires; 2286 unsigned long timer_expires;
@@ -2305,8 +2306,8 @@ static void get_tcp4_sock(struct sock *sk, char *tmpbuf, int i)
2305 timer_expires = jiffies; 2306 timer_expires = jiffies;
2306 } 2307 }
2307 2308
2308 sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX " 2309 seq_printf(f, "%4d: %08X:%04X %08X:%04X %02X %08X:%08X %02X:%08lX "
2309 "%08X %5d %8d %lu %d %p %u %u %u %u %d", 2310 "%08X %5d %8d %lu %d %p %u %u %u %u %d%n",
2310 i, src, srcp, dest, destp, sk->sk_state, 2311 i, src, srcp, dest, destp, sk->sk_state,
2311 tp->write_seq - tp->snd_una, 2312 tp->write_seq - tp->snd_una,
2312 sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog : 2313 sk->sk_state == TCP_LISTEN ? sk->sk_ack_backlog :
@@ -2322,11 +2323,12 @@ static void get_tcp4_sock(struct sock *sk, char *tmpbuf, int i)
2322 icsk->icsk_ack.ato, 2323 icsk->icsk_ack.ato,
2323 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong, 2324 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
2324 tp->snd_cwnd, 2325 tp->snd_cwnd,
2325 tp->snd_ssthresh >= 0xFFFF ? -1 : tp->snd_ssthresh); 2326 tp->snd_ssthresh >= 0xFFFF ? -1 : tp->snd_ssthresh,
2327 len);
2326} 2328}
2327 2329
2328static void get_timewait4_sock(struct inet_timewait_sock *tw, 2330static void get_timewait4_sock(struct inet_timewait_sock *tw,
2329 char *tmpbuf, int i) 2331 struct seq_file *f, int i, int *len)
2330{ 2332{
2331 __be32 dest, src; 2333 __be32 dest, src;
2332 __u16 destp, srcp; 2334 __u16 destp, srcp;
@@ -2340,11 +2342,11 @@ static void get_timewait4_sock(struct inet_timewait_sock *tw,
2340 destp = ntohs(tw->tw_dport); 2342 destp = ntohs(tw->tw_dport);
2341 srcp = ntohs(tw->tw_sport); 2343 srcp = ntohs(tw->tw_sport);
2342 2344
2343 sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X" 2345 seq_printf(f, "%4d: %08X:%04X %08X:%04X"
2344 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p", 2346 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %p%n",
2345 i, src, srcp, dest, destp, tw->tw_substate, 0, 0, 2347 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
2346 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0, 2348 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
2347 atomic_read(&tw->tw_refcnt), tw); 2349 atomic_read(&tw->tw_refcnt), tw, len);
2348} 2350}
2349 2351
2350#define TMPSZ 150 2352#define TMPSZ 150
@@ -2352,7 +2354,7 @@ static void get_timewait4_sock(struct inet_timewait_sock *tw,
2352static int tcp4_seq_show(struct seq_file *seq, void *v) 2354static int tcp4_seq_show(struct seq_file *seq, void *v)
2353{ 2355{
2354 struct tcp_iter_state* st; 2356 struct tcp_iter_state* st;
2355 char tmpbuf[TMPSZ + 1]; 2357 int len;
2356 2358
2357 if (v == SEQ_START_TOKEN) { 2359 if (v == SEQ_START_TOKEN) {
2358 seq_printf(seq, "%-*s\n", TMPSZ - 1, 2360 seq_printf(seq, "%-*s\n", TMPSZ - 1,
@@ -2366,16 +2368,16 @@ static int tcp4_seq_show(struct seq_file *seq, void *v)
2366 switch (st->state) { 2368 switch (st->state) {
2367 case TCP_SEQ_STATE_LISTENING: 2369 case TCP_SEQ_STATE_LISTENING:
2368 case TCP_SEQ_STATE_ESTABLISHED: 2370 case TCP_SEQ_STATE_ESTABLISHED:
2369 get_tcp4_sock(v, tmpbuf, st->num); 2371 get_tcp4_sock(v, seq, st->num, &len);
2370 break; 2372 break;
2371 case TCP_SEQ_STATE_OPENREQ: 2373 case TCP_SEQ_STATE_OPENREQ:
2372 get_openreq4(st->syn_wait_sk, v, tmpbuf, st->num, st->uid); 2374 get_openreq4(st->syn_wait_sk, v, seq, st->num, st->uid, &len);
2373 break; 2375 break;
2374 case TCP_SEQ_STATE_TIME_WAIT: 2376 case TCP_SEQ_STATE_TIME_WAIT:
2375 get_timewait4_sock(v, tmpbuf, st->num); 2377 get_timewait4_sock(v, seq, st->num, &len);
2376 break; 2378 break;
2377 } 2379 }
2378 seq_printf(seq, "%-*s\n", TMPSZ - 1, tmpbuf); 2380 seq_printf(seq, "%*s\n", TMPSZ - 1 - len, "");
2379out: 2381out:
2380 return 0; 2382 return 0;
2381} 2383}
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index b053ac795275..1f535e315188 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -1619,7 +1619,8 @@ void udp_proc_unregister(struct net *net, struct udp_seq_afinfo *afinfo)
1619} 1619}
1620 1620
1621/* ------------------------------------------------------------------------ */ 1621/* ------------------------------------------------------------------------ */
1622static void udp4_format_sock(struct sock *sp, char *tmpbuf, int bucket) 1622static void udp4_format_sock(struct sock *sp, struct seq_file *f,
1623 int bucket, int *len)
1623{ 1624{
1624 struct inet_sock *inet = inet_sk(sp); 1625 struct inet_sock *inet = inet_sk(sp);
1625 __be32 dest = inet->daddr; 1626 __be32 dest = inet->daddr;
@@ -1627,13 +1628,13 @@ static void udp4_format_sock(struct sock *sp, char *tmpbuf, int bucket)
1627 __u16 destp = ntohs(inet->dport); 1628 __u16 destp = ntohs(inet->dport);
1628 __u16 srcp = ntohs(inet->sport); 1629 __u16 srcp = ntohs(inet->sport);
1629 1630
1630 sprintf(tmpbuf, "%4d: %08X:%04X %08X:%04X" 1631 seq_printf(f, "%4d: %08X:%04X %08X:%04X"
1631 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p", 1632 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %lu %d %p%n",
1632 bucket, src, srcp, dest, destp, sp->sk_state, 1633 bucket, src, srcp, dest, destp, sp->sk_state,
1633 atomic_read(&sp->sk_wmem_alloc), 1634 atomic_read(&sp->sk_wmem_alloc),
1634 atomic_read(&sp->sk_rmem_alloc), 1635 atomic_read(&sp->sk_rmem_alloc),
1635 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp), 1636 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
1636 atomic_read(&sp->sk_refcnt), sp); 1637 atomic_read(&sp->sk_refcnt), sp, len);
1637} 1638}
1638 1639
1639int udp4_seq_show(struct seq_file *seq, void *v) 1640int udp4_seq_show(struct seq_file *seq, void *v)
@@ -1644,11 +1645,11 @@ int udp4_seq_show(struct seq_file *seq, void *v)
1644 "rx_queue tr tm->when retrnsmt uid timeout " 1645 "rx_queue tr tm->when retrnsmt uid timeout "
1645 "inode"); 1646 "inode");
1646 else { 1647 else {
1647 char tmpbuf[129];
1648 struct udp_iter_state *state = seq->private; 1648 struct udp_iter_state *state = seq->private;
1649 int len;
1649 1650
1650 udp4_format_sock(v, tmpbuf, state->bucket); 1651 udp4_format_sock(v, seq, state->bucket, &len);
1651 seq_printf(seq, "%-127s\n", tmpbuf); 1652 seq_printf(seq, "%*s\n", 127 - len ,"");
1652 } 1653 }
1653 return 0; 1654 return 0;
1654} 1655}
diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c
index 6b75cb6c6300..a5e5c31c23ab 100644
--- a/net/mac80211/mlme.c
+++ b/net/mac80211/mlme.c
@@ -2248,10 +2248,13 @@ static void ieee80211_rx_bss_put(struct net_device *dev,
2248 struct ieee80211_sta_bss *bss) 2248 struct ieee80211_sta_bss *bss)
2249{ 2249{
2250 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr); 2250 struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
2251 if (!atomic_dec_and_test(&bss->users)) 2251
2252 local_bh_disable();
2253 if (!atomic_dec_and_lock(&bss->users, &local->sta_bss_lock)) {
2254 local_bh_enable();
2252 return; 2255 return;
2256 }
2253 2257
2254 spin_lock_bh(&local->sta_bss_lock);
2255 __ieee80211_rx_bss_hash_del(dev, bss); 2258 __ieee80211_rx_bss_hash_del(dev, bss);
2256 list_del(&bss->list); 2259 list_del(&bss->list);
2257 spin_unlock_bh(&local->sta_bss_lock); 2260 spin_unlock_bh(&local->sta_bss_lock);
@@ -2709,7 +2712,26 @@ static void ieee80211_rx_bss_info(struct net_device *dev,
2709 bss->wmm_ie_len = elems.wmm_param_len + 2; 2712 bss->wmm_ie_len = elems.wmm_param_len + 2;
2710 } else 2713 } else
2711 bss->wmm_ie_len = 0; 2714 bss->wmm_ie_len = 0;
2712 } else if (!elems.wmm_param && bss->wmm_ie) { 2715 } else if (elems.wmm_info &&
2716 (!bss->wmm_ie || bss->wmm_ie_len != elems.wmm_info_len ||
2717 memcmp(bss->wmm_ie, elems.wmm_info, elems.wmm_info_len))) {
2718 /* As for certain AP's Fifth bit is not set in WMM IE in
2719 * beacon frames.So while parsing the beacon frame the
2720 * wmm_info structure is used instead of wmm_param.
2721 * wmm_info structure was never used to set bss->wmm_ie.
2722 * This code fixes this problem by copying the WME
2723 * information from wmm_info to bss->wmm_ie and enabling
2724 * n-band association.
2725 */
2726 kfree(bss->wmm_ie);
2727 bss->wmm_ie = kmalloc(elems.wmm_info_len + 2, GFP_ATOMIC);
2728 if (bss->wmm_ie) {
2729 memcpy(bss->wmm_ie, elems.wmm_info - 2,
2730 elems.wmm_info_len + 2);
2731 bss->wmm_ie_len = elems.wmm_info_len + 2;
2732 } else
2733 bss->wmm_ie_len = 0;
2734 } else if (!elems.wmm_param && !elems.wmm_info && bss->wmm_ie) {
2713 kfree(bss->wmm_ie); 2735 kfree(bss->wmm_ie);
2714 bss->wmm_ie = NULL; 2736 bss->wmm_ie = NULL;
2715 bss->wmm_ie_len = 0; 2737 bss->wmm_ie_len = 0;
diff --git a/net/mac80211/rx.c b/net/mac80211/rx.c
index 52e4554fdde7..02f436a86061 100644
--- a/net/mac80211/rx.c
+++ b/net/mac80211/rx.c
@@ -2170,7 +2170,7 @@ void __ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb,
2170 struct ieee80211_supported_band *sband; 2170 struct ieee80211_supported_band *sband;
2171 2171
2172 if (status->band < 0 || 2172 if (status->band < 0 ||
2173 status->band > IEEE80211_NUM_BANDS) { 2173 status->band >= IEEE80211_NUM_BANDS) {
2174 WARN_ON(1); 2174 WARN_ON(1);
2175 return; 2175 return;
2176 } 2176 }
diff --git a/net/mac80211/wme.c b/net/mac80211/wme.c
index 4e94e4026e78..64faa3dc488f 100644
--- a/net/mac80211/wme.c
+++ b/net/mac80211/wme.c
@@ -709,7 +709,7 @@ void ieee80211_requeue(struct ieee80211_local *local, int queue)
709 struct ieee80211_sched_data *q = qdisc_priv(root_qd); 709 struct ieee80211_sched_data *q = qdisc_priv(root_qd);
710 struct Qdisc *qdisc = q->queues[queue]; 710 struct Qdisc *qdisc = q->queues[queue];
711 struct sk_buff *skb = NULL; 711 struct sk_buff *skb = NULL;
712 u32 len = qdisc->q.qlen; 712 u32 len;
713 713
714 if (!qdisc || !qdisc->dequeue) 714 if (!qdisc || !qdisc->dequeue)
715 return; 715 return;
diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
index 6d38a81b336d..ba3f6e49fddc 100644
--- a/net/rxrpc/rxkad.c
+++ b/net/rxrpc/rxkad.c
@@ -493,8 +493,8 @@ static int rxkad_verify_packet(const struct rxrpc_call *call,
493 __be32 x[2]; 493 __be32 x[2];
494 } tmpbuf __attribute__((aligned(8))); /* must all be in same page */ 494 } tmpbuf __attribute__((aligned(8))); /* must all be in same page */
495 __be32 x; 495 __be32 x;
496 u16 y;
497 __be16 cksum; 496 __be16 cksum;
497 u32 y;
498 int ret; 498 int ret;
499 499
500 sp = rxrpc_skb(skb); 500 sp = rxrpc_skb(skb);
diff --git a/net/sctp/objcnt.c b/net/sctp/objcnt.c
index cfeb07ea1b04..f73ec0ea93ba 100644
--- a/net/sctp/objcnt.c
+++ b/net/sctp/objcnt.c
@@ -83,13 +83,12 @@ static sctp_dbg_objcnt_entry_t sctp_dbg_objcnt[] = {
83 */ 83 */
84static int sctp_objcnt_seq_show(struct seq_file *seq, void *v) 84static int sctp_objcnt_seq_show(struct seq_file *seq, void *v)
85{ 85{
86 int i; 86 int i, len;
87 char temp[128];
88 87
89 i = (int)*(loff_t *)v; 88 i = (int)*(loff_t *)v;
90 sprintf(temp, "%s: %d", sctp_dbg_objcnt[i].label, 89 seq_printf(seq, "%s: %d%n", sctp_dbg_objcnt[i].label,
91 atomic_read(sctp_dbg_objcnt[i].counter)); 90 atomic_read(sctp_dbg_objcnt[i].counter), &len);
92 seq_printf(seq, "%-127s\n", temp); 91 seq_printf(seq, "%*s\n", 127 - len, "");
93 return 0; 92 return 0;
94} 93}
95 94
diff --git a/net/sunrpc/Makefile b/net/sunrpc/Makefile
index 92e1dbe50947..5369aa369b35 100644
--- a/net/sunrpc/Makefile
+++ b/net/sunrpc/Makefile
@@ -8,7 +8,7 @@ obj-$(CONFIG_SUNRPC_GSS) += auth_gss/
8obj-$(CONFIG_SUNRPC_XPRT_RDMA) += xprtrdma/ 8obj-$(CONFIG_SUNRPC_XPRT_RDMA) += xprtrdma/
9 9
10sunrpc-y := clnt.o xprt.o socklib.o xprtsock.o sched.o \ 10sunrpc-y := clnt.o xprt.o socklib.o xprtsock.o sched.o \
11 auth.o auth_null.o auth_unix.o \ 11 auth.o auth_null.o auth_unix.o auth_generic.o \
12 svc.o svcsock.o svcauth.o svcauth_unix.o \ 12 svc.o svcsock.o svcauth.o svcauth_unix.o \
13 rpcb_clnt.o timer.o xdr.o \ 13 rpcb_clnt.o timer.o xdr.o \
14 sunrpc_syms.o cache.o rpc_pipe.o \ 14 sunrpc_syms.o cache.o rpc_pipe.o \
diff --git a/net/sunrpc/auth.c b/net/sunrpc/auth.c
index eca941ce298b..6bfea9ed6869 100644
--- a/net/sunrpc/auth.c
+++ b/net/sunrpc/auth.c
@@ -11,6 +11,7 @@
11#include <linux/module.h> 11#include <linux/module.h>
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <linux/errno.h> 13#include <linux/errno.h>
14#include <linux/hash.h>
14#include <linux/sunrpc/clnt.h> 15#include <linux/sunrpc/clnt.h>
15#include <linux/spinlock.h> 16#include <linux/spinlock.h>
16 17
@@ -219,6 +220,9 @@ rpcauth_destroy_credcache(struct rpc_auth *auth)
219} 220}
220EXPORT_SYMBOL_GPL(rpcauth_destroy_credcache); 221EXPORT_SYMBOL_GPL(rpcauth_destroy_credcache);
221 222
223
224#define RPC_AUTH_EXPIRY_MORATORIUM (60 * HZ)
225
222/* 226/*
223 * Remove stale credentials. Avoid sleeping inside the loop. 227 * Remove stale credentials. Avoid sleeping inside the loop.
224 */ 228 */
@@ -227,6 +231,7 @@ rpcauth_prune_expired(struct list_head *free, int nr_to_scan)
227{ 231{
228 spinlock_t *cache_lock; 232 spinlock_t *cache_lock;
229 struct rpc_cred *cred; 233 struct rpc_cred *cred;
234 unsigned long expired = jiffies - RPC_AUTH_EXPIRY_MORATORIUM;
230 235
231 while (!list_empty(&cred_unused)) { 236 while (!list_empty(&cred_unused)) {
232 cred = list_entry(cred_unused.next, struct rpc_cred, cr_lru); 237 cred = list_entry(cred_unused.next, struct rpc_cred, cr_lru);
@@ -234,6 +239,10 @@ rpcauth_prune_expired(struct list_head *free, int nr_to_scan)
234 number_cred_unused--; 239 number_cred_unused--;
235 if (atomic_read(&cred->cr_count) != 0) 240 if (atomic_read(&cred->cr_count) != 0)
236 continue; 241 continue;
242 /* Enforce a 5 second garbage collection moratorium */
243 if (time_in_range(cred->cr_expire, expired, jiffies) &&
244 test_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags) != 0)
245 continue;
237 cache_lock = &cred->cr_auth->au_credcache->lock; 246 cache_lock = &cred->cr_auth->au_credcache->lock;
238 spin_lock(cache_lock); 247 spin_lock(cache_lock);
239 if (atomic_read(&cred->cr_count) == 0) { 248 if (atomic_read(&cred->cr_count) == 0) {
@@ -280,10 +289,9 @@ rpcauth_lookup_credcache(struct rpc_auth *auth, struct auth_cred * acred,
280 struct hlist_node *pos; 289 struct hlist_node *pos;
281 struct rpc_cred *cred = NULL, 290 struct rpc_cred *cred = NULL,
282 *entry, *new; 291 *entry, *new;
283 int nr = 0; 292 unsigned int nr;
284 293
285 if (!(flags & RPCAUTH_LOOKUP_ROOTCREDS)) 294 nr = hash_long(acred->uid, RPC_CREDCACHE_HASHBITS);
286 nr = acred->uid & RPC_CREDCACHE_MASK;
287 295
288 rcu_read_lock(); 296 rcu_read_lock();
289 hlist_for_each_entry_rcu(entry, pos, &cache->hashtable[nr], cr_hash) { 297 hlist_for_each_entry_rcu(entry, pos, &cache->hashtable[nr], cr_hash) {
@@ -356,7 +364,6 @@ rpcauth_lookupcred(struct rpc_auth *auth, int flags)
356 put_group_info(acred.group_info); 364 put_group_info(acred.group_info);
357 return ret; 365 return ret;
358} 366}
359EXPORT_SYMBOL_GPL(rpcauth_lookupcred);
360 367
361void 368void
362rpcauth_init_cred(struct rpc_cred *cred, const struct auth_cred *acred, 369rpcauth_init_cred(struct rpc_cred *cred, const struct auth_cred *acred,
@@ -375,41 +382,58 @@ rpcauth_init_cred(struct rpc_cred *cred, const struct auth_cred *acred,
375} 382}
376EXPORT_SYMBOL_GPL(rpcauth_init_cred); 383EXPORT_SYMBOL_GPL(rpcauth_init_cred);
377 384
378struct rpc_cred * 385void
379rpcauth_bindcred(struct rpc_task *task) 386rpcauth_generic_bind_cred(struct rpc_task *task, struct rpc_cred *cred)
387{
388 task->tk_msg.rpc_cred = get_rpccred(cred);
389 dprintk("RPC: %5u holding %s cred %p\n", task->tk_pid,
390 cred->cr_auth->au_ops->au_name, cred);
391}
392EXPORT_SYMBOL_GPL(rpcauth_generic_bind_cred);
393
394static void
395rpcauth_bind_root_cred(struct rpc_task *task)
380{ 396{
381 struct rpc_auth *auth = task->tk_client->cl_auth; 397 struct rpc_auth *auth = task->tk_client->cl_auth;
382 struct auth_cred acred = { 398 struct auth_cred acred = {
383 .uid = current->fsuid, 399 .uid = 0,
384 .gid = current->fsgid, 400 .gid = 0,
385 .group_info = current->group_info,
386 }; 401 };
387 struct rpc_cred *ret; 402 struct rpc_cred *ret;
388 int flags = 0;
389 403
390 dprintk("RPC: %5u looking up %s cred\n", 404 dprintk("RPC: %5u looking up %s cred\n",
391 task->tk_pid, task->tk_client->cl_auth->au_ops->au_name); 405 task->tk_pid, task->tk_client->cl_auth->au_ops->au_name);
392 get_group_info(acred.group_info); 406 ret = auth->au_ops->lookup_cred(auth, &acred, 0);
393 if (task->tk_flags & RPC_TASK_ROOTCREDS) 407 if (!IS_ERR(ret))
394 flags |= RPCAUTH_LOOKUP_ROOTCREDS; 408 task->tk_msg.rpc_cred = ret;
395 ret = auth->au_ops->lookup_cred(auth, &acred, flags); 409 else
410 task->tk_status = PTR_ERR(ret);
411}
412
413static void
414rpcauth_bind_new_cred(struct rpc_task *task)
415{
416 struct rpc_auth *auth = task->tk_client->cl_auth;
417 struct rpc_cred *ret;
418
419 dprintk("RPC: %5u looking up %s cred\n",
420 task->tk_pid, auth->au_ops->au_name);
421 ret = rpcauth_lookupcred(auth, 0);
396 if (!IS_ERR(ret)) 422 if (!IS_ERR(ret))
397 task->tk_msg.rpc_cred = ret; 423 task->tk_msg.rpc_cred = ret;
398 else 424 else
399 task->tk_status = PTR_ERR(ret); 425 task->tk_status = PTR_ERR(ret);
400 put_group_info(acred.group_info);
401 return ret;
402} 426}
403 427
404void 428void
405rpcauth_holdcred(struct rpc_task *task) 429rpcauth_bindcred(struct rpc_task *task, struct rpc_cred *cred, int flags)
406{ 430{
407 struct rpc_cred *cred = task->tk_msg.rpc_cred; 431 if (cred != NULL)
408 if (cred != NULL) { 432 cred->cr_ops->crbind(task, cred);
409 get_rpccred(cred); 433 else if (flags & RPC_TASK_ROOTCREDS)
410 dprintk("RPC: %5u holding %s cred %p\n", task->tk_pid, 434 rpcauth_bind_root_cred(task);
411 cred->cr_auth->au_ops->au_name, cred); 435 else
412 } 436 rpcauth_bind_new_cred(task);
413} 437}
414 438
415void 439void
@@ -550,6 +574,7 @@ static struct shrinker rpc_cred_shrinker = {
550void __init rpcauth_init_module(void) 574void __init rpcauth_init_module(void)
551{ 575{
552 rpc_init_authunix(); 576 rpc_init_authunix();
577 rpc_init_generic_auth();
553 register_shrinker(&rpc_cred_shrinker); 578 register_shrinker(&rpc_cred_shrinker);
554} 579}
555 580
diff --git a/net/sunrpc/auth_generic.c b/net/sunrpc/auth_generic.c
new file mode 100644
index 000000000000..d927d9f57412
--- /dev/null
+++ b/net/sunrpc/auth_generic.c
@@ -0,0 +1,177 @@
1/*
2 * Generic RPC credential
3 *
4 * Copyright (C) 2008, Trond Myklebust <Trond.Myklebust@netapp.com>
5 */
6
7#include <linux/err.h>
8#include <linux/types.h>
9#include <linux/module.h>
10#include <linux/sched.h>
11#include <linux/sunrpc/auth.h>
12#include <linux/sunrpc/clnt.h>
13#include <linux/sunrpc/debug.h>
14#include <linux/sunrpc/sched.h>
15
16#ifdef RPC_DEBUG
17# define RPCDBG_FACILITY RPCDBG_AUTH
18#endif
19
20#define RPC_ANONYMOUS_USERID ((uid_t)-2)
21#define RPC_ANONYMOUS_GROUPID ((gid_t)-2)
22
23struct generic_cred {
24 struct rpc_cred gc_base;
25 struct auth_cred acred;
26};
27
28static struct rpc_auth generic_auth;
29static struct rpc_cred_cache generic_cred_cache;
30static const struct rpc_credops generic_credops;
31
32/*
33 * Public call interface
34 */
35struct rpc_cred *rpc_lookup_cred(void)
36{
37 return rpcauth_lookupcred(&generic_auth, 0);
38}
39EXPORT_SYMBOL_GPL(rpc_lookup_cred);
40
41/*
42 * Public call interface for looking up machine creds.
43 */
44struct rpc_cred *rpc_lookup_machine_cred(void)
45{
46 struct auth_cred acred = {
47 .uid = RPC_ANONYMOUS_USERID,
48 .gid = RPC_ANONYMOUS_GROUPID,
49 .machine_cred = 1,
50 };
51
52 dprintk("RPC: looking up machine cred\n");
53 return generic_auth.au_ops->lookup_cred(&generic_auth, &acred, 0);
54}
55EXPORT_SYMBOL_GPL(rpc_lookup_machine_cred);
56
57static void
58generic_bind_cred(struct rpc_task *task, struct rpc_cred *cred)
59{
60 struct rpc_auth *auth = task->tk_client->cl_auth;
61 struct auth_cred *acred = &container_of(cred, struct generic_cred, gc_base)->acred;
62 struct rpc_cred *ret;
63
64 ret = auth->au_ops->lookup_cred(auth, acred, 0);
65 if (!IS_ERR(ret))
66 task->tk_msg.rpc_cred = ret;
67 else
68 task->tk_status = PTR_ERR(ret);
69}
70
71/*
72 * Lookup generic creds for current process
73 */
74static struct rpc_cred *
75generic_lookup_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags)
76{
77 return rpcauth_lookup_credcache(&generic_auth, acred, flags);
78}
79
80static struct rpc_cred *
81generic_create_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags)
82{
83 struct generic_cred *gcred;
84
85 gcred = kmalloc(sizeof(*gcred), GFP_KERNEL);
86 if (gcred == NULL)
87 return ERR_PTR(-ENOMEM);
88
89 rpcauth_init_cred(&gcred->gc_base, acred, &generic_auth, &generic_credops);
90 gcred->gc_base.cr_flags = 1UL << RPCAUTH_CRED_UPTODATE;
91
92 gcred->acred.uid = acred->uid;
93 gcred->acred.gid = acred->gid;
94 gcred->acred.group_info = acred->group_info;
95 if (gcred->acred.group_info != NULL)
96 get_group_info(gcred->acred.group_info);
97 gcred->acred.machine_cred = acred->machine_cred;
98
99 dprintk("RPC: allocated %s cred %p for uid %d gid %d\n",
100 gcred->acred.machine_cred ? "machine" : "generic",
101 gcred, acred->uid, acred->gid);
102 return &gcred->gc_base;
103}
104
105static void
106generic_free_cred(struct rpc_cred *cred)
107{
108 struct generic_cred *gcred = container_of(cred, struct generic_cred, gc_base);
109
110 dprintk("RPC: generic_free_cred %p\n", gcred);
111 if (gcred->acred.group_info != NULL)
112 put_group_info(gcred->acred.group_info);
113 kfree(gcred);
114}
115
116static void
117generic_free_cred_callback(struct rcu_head *head)
118{
119 struct rpc_cred *cred = container_of(head, struct rpc_cred, cr_rcu);
120 generic_free_cred(cred);
121}
122
123static void
124generic_destroy_cred(struct rpc_cred *cred)
125{
126 call_rcu(&cred->cr_rcu, generic_free_cred_callback);
127}
128
129/*
130 * Match credentials against current process creds.
131 */
132static int
133generic_match(struct auth_cred *acred, struct rpc_cred *cred, int flags)
134{
135 struct generic_cred *gcred = container_of(cred, struct generic_cred, gc_base);
136
137 if (gcred->acred.uid != acred->uid ||
138 gcred->acred.gid != acred->gid ||
139 gcred->acred.group_info != acred->group_info ||
140 gcred->acred.machine_cred != acred->machine_cred)
141 return 0;
142 return 1;
143}
144
145void __init rpc_init_generic_auth(void)
146{
147 spin_lock_init(&generic_cred_cache.lock);
148}
149
150void __exit rpc_destroy_generic_auth(void)
151{
152 rpcauth_clear_credcache(&generic_cred_cache);
153}
154
155static struct rpc_cred_cache generic_cred_cache = {
156 {{ NULL, },},
157};
158
159static const struct rpc_authops generic_auth_ops = {
160 .owner = THIS_MODULE,
161 .au_name = "Generic",
162 .lookup_cred = generic_lookup_cred,
163 .crcreate = generic_create_cred,
164};
165
166static struct rpc_auth generic_auth = {
167 .au_ops = &generic_auth_ops,
168 .au_count = ATOMIC_INIT(0),
169 .au_credcache = &generic_cred_cache,
170};
171
172static const struct rpc_credops generic_credops = {
173 .cr_name = "Generic cred",
174 .crdestroy = generic_destroy_cred,
175 .crbind = generic_bind_cred,
176 .crmatch = generic_match,
177};
diff --git a/net/sunrpc/auth_gss/auth_gss.c b/net/sunrpc/auth_gss/auth_gss.c
index 5828e5c060ca..cc12d5f5d5da 100644
--- a/net/sunrpc/auth_gss/auth_gss.c
+++ b/net/sunrpc/auth_gss/auth_gss.c
@@ -114,27 +114,14 @@ static void
114gss_cred_set_ctx(struct rpc_cred *cred, struct gss_cl_ctx *ctx) 114gss_cred_set_ctx(struct rpc_cred *cred, struct gss_cl_ctx *ctx)
115{ 115{
116 struct gss_cred *gss_cred = container_of(cred, struct gss_cred, gc_base); 116 struct gss_cred *gss_cred = container_of(cred, struct gss_cred, gc_base);
117 struct gss_cl_ctx *old;
118 117
119 old = gss_cred->gc_ctx; 118 if (!test_bit(RPCAUTH_CRED_NEW, &cred->cr_flags))
119 return;
120 gss_get_ctx(ctx);
120 rcu_assign_pointer(gss_cred->gc_ctx, ctx); 121 rcu_assign_pointer(gss_cred->gc_ctx, ctx);
121 set_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags); 122 set_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags);
123 smp_mb__before_clear_bit();
122 clear_bit(RPCAUTH_CRED_NEW, &cred->cr_flags); 124 clear_bit(RPCAUTH_CRED_NEW, &cred->cr_flags);
123 if (old)
124 gss_put_ctx(old);
125}
126
127static int
128gss_cred_is_uptodate_ctx(struct rpc_cred *cred)
129{
130 struct gss_cred *gss_cred = container_of(cred, struct gss_cred, gc_base);
131 int res = 0;
132
133 rcu_read_lock();
134 if (test_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags) && gss_cred->gc_ctx)
135 res = 1;
136 rcu_read_unlock();
137 return res;
138} 125}
139 126
140static const void * 127static const void *
@@ -266,6 +253,7 @@ gss_release_msg(struct gss_upcall_msg *gss_msg)
266 BUG_ON(!list_empty(&gss_msg->list)); 253 BUG_ON(!list_empty(&gss_msg->list));
267 if (gss_msg->ctx != NULL) 254 if (gss_msg->ctx != NULL)
268 gss_put_ctx(gss_msg->ctx); 255 gss_put_ctx(gss_msg->ctx);
256 rpc_destroy_wait_queue(&gss_msg->rpc_waitqueue);
269 kfree(gss_msg); 257 kfree(gss_msg);
270} 258}
271 259
@@ -339,7 +327,7 @@ gss_upcall_callback(struct rpc_task *task)
339 327
340 spin_lock(&inode->i_lock); 328 spin_lock(&inode->i_lock);
341 if (gss_msg->ctx) 329 if (gss_msg->ctx)
342 gss_cred_set_ctx(task->tk_msg.rpc_cred, gss_get_ctx(gss_msg->ctx)); 330 gss_cred_set_ctx(task->tk_msg.rpc_cred, gss_msg->ctx);
343 else 331 else
344 task->tk_status = gss_msg->msg.errno; 332 task->tk_status = gss_msg->msg.errno;
345 gss_cred->gc_upcall = NULL; 333 gss_cred->gc_upcall = NULL;
@@ -370,9 +358,16 @@ gss_alloc_msg(struct gss_auth *gss_auth, uid_t uid)
370static struct gss_upcall_msg * 358static struct gss_upcall_msg *
371gss_setup_upcall(struct rpc_clnt *clnt, struct gss_auth *gss_auth, struct rpc_cred *cred) 359gss_setup_upcall(struct rpc_clnt *clnt, struct gss_auth *gss_auth, struct rpc_cred *cred)
372{ 360{
361 struct gss_cred *gss_cred = container_of(cred,
362 struct gss_cred, gc_base);
373 struct gss_upcall_msg *gss_new, *gss_msg; 363 struct gss_upcall_msg *gss_new, *gss_msg;
364 uid_t uid = cred->cr_uid;
374 365
375 gss_new = gss_alloc_msg(gss_auth, cred->cr_uid); 366 /* Special case: rpc.gssd assumes that uid == 0 implies machine creds */
367 if (gss_cred->gc_machine_cred != 0)
368 uid = 0;
369
370 gss_new = gss_alloc_msg(gss_auth, uid);
376 if (gss_new == NULL) 371 if (gss_new == NULL)
377 return ERR_PTR(-ENOMEM); 372 return ERR_PTR(-ENOMEM);
378 gss_msg = gss_add_msg(gss_auth, gss_new); 373 gss_msg = gss_add_msg(gss_auth, gss_new);
@@ -408,13 +403,17 @@ gss_refresh_upcall(struct rpc_task *task)
408 } 403 }
409 spin_lock(&inode->i_lock); 404 spin_lock(&inode->i_lock);
410 if (gss_cred->gc_upcall != NULL) 405 if (gss_cred->gc_upcall != NULL)
411 rpc_sleep_on(&gss_cred->gc_upcall->rpc_waitqueue, task, NULL, NULL); 406 rpc_sleep_on(&gss_cred->gc_upcall->rpc_waitqueue, task, NULL);
412 else if (gss_msg->ctx == NULL && gss_msg->msg.errno >= 0) { 407 else if (gss_msg->ctx != NULL) {
408 gss_cred_set_ctx(task->tk_msg.rpc_cred, gss_msg->ctx);
409 gss_cred->gc_upcall = NULL;
410 rpc_wake_up_status(&gss_msg->rpc_waitqueue, gss_msg->msg.errno);
411 } else if (gss_msg->msg.errno >= 0) {
413 task->tk_timeout = 0; 412 task->tk_timeout = 0;
414 gss_cred->gc_upcall = gss_msg; 413 gss_cred->gc_upcall = gss_msg;
415 /* gss_upcall_callback will release the reference to gss_upcall_msg */ 414 /* gss_upcall_callback will release the reference to gss_upcall_msg */
416 atomic_inc(&gss_msg->count); 415 atomic_inc(&gss_msg->count);
417 rpc_sleep_on(&gss_msg->rpc_waitqueue, task, gss_upcall_callback, NULL); 416 rpc_sleep_on(&gss_msg->rpc_waitqueue, task, gss_upcall_callback);
418 } else 417 } else
419 err = gss_msg->msg.errno; 418 err = gss_msg->msg.errno;
420 spin_unlock(&inode->i_lock); 419 spin_unlock(&inode->i_lock);
@@ -454,7 +453,7 @@ gss_create_upcall(struct gss_auth *gss_auth, struct gss_cred *gss_cred)
454 schedule(); 453 schedule();
455 } 454 }
456 if (gss_msg->ctx) 455 if (gss_msg->ctx)
457 gss_cred_set_ctx(cred, gss_get_ctx(gss_msg->ctx)); 456 gss_cred_set_ctx(cred, gss_msg->ctx);
458 else 457 else
459 err = gss_msg->msg.errno; 458 err = gss_msg->msg.errno;
460 spin_unlock(&inode->i_lock); 459 spin_unlock(&inode->i_lock);
@@ -709,7 +708,7 @@ gss_destroying_context(struct rpc_cred *cred)
709 struct rpc_task *task; 708 struct rpc_task *task;
710 709
711 if (gss_cred->gc_ctx == NULL || 710 if (gss_cred->gc_ctx == NULL ||
712 gss_cred->gc_ctx->gc_proc == RPC_GSS_PROC_DESTROY) 711 test_and_clear_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags) == 0)
713 return 0; 712 return 0;
714 713
715 gss_cred->gc_ctx->gc_proc = RPC_GSS_PROC_DESTROY; 714 gss_cred->gc_ctx->gc_proc = RPC_GSS_PROC_DESTROY;
@@ -719,7 +718,7 @@ gss_destroying_context(struct rpc_cred *cred)
719 * by the RPC call or by the put_rpccred() below */ 718 * by the RPC call or by the put_rpccred() below */
720 get_rpccred(cred); 719 get_rpccred(cred);
721 720
722 task = rpc_call_null(gss_auth->client, cred, RPC_TASK_ASYNC); 721 task = rpc_call_null(gss_auth->client, cred, RPC_TASK_ASYNC|RPC_TASK_SOFT);
723 if (!IS_ERR(task)) 722 if (!IS_ERR(task))
724 rpc_put_task(task); 723 rpc_put_task(task);
725 724
@@ -817,6 +816,7 @@ gss_create_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags)
817 */ 816 */
818 cred->gc_base.cr_flags = 1UL << RPCAUTH_CRED_NEW; 817 cred->gc_base.cr_flags = 1UL << RPCAUTH_CRED_NEW;
819 cred->gc_service = gss_auth->service; 818 cred->gc_service = gss_auth->service;
819 cred->gc_machine_cred = acred->machine_cred;
820 kref_get(&gss_auth->kref); 820 kref_get(&gss_auth->kref);
821 return &cred->gc_base; 821 return &cred->gc_base;
822 822
@@ -843,17 +843,16 @@ gss_match(struct auth_cred *acred, struct rpc_cred *rc, int flags)
843{ 843{
844 struct gss_cred *gss_cred = container_of(rc, struct gss_cred, gc_base); 844 struct gss_cred *gss_cred = container_of(rc, struct gss_cred, gc_base);
845 845
846 /* 846 if (test_bit(RPCAUTH_CRED_NEW, &rc->cr_flags))
847 * If the searchflags have set RPCAUTH_LOOKUP_NEW, then
848 * we don't really care if the credential has expired or not,
849 * since the caller should be prepared to reinitialise it.
850 */
851 if ((flags & RPCAUTH_LOOKUP_NEW) && test_bit(RPCAUTH_CRED_NEW, &rc->cr_flags))
852 goto out; 847 goto out;
853 /* Don't match with creds that have expired. */ 848 /* Don't match with creds that have expired. */
854 if (gss_cred->gc_ctx && time_after(jiffies, gss_cred->gc_ctx->gc_expiry)) 849 if (time_after(jiffies, gss_cred->gc_ctx->gc_expiry))
850 return 0;
851 if (!test_bit(RPCAUTH_CRED_UPTODATE, &rc->cr_flags))
855 return 0; 852 return 0;
856out: 853out:
854 if (acred->machine_cred != gss_cred->gc_machine_cred)
855 return 0;
857 return (rc->cr_uid == acred->uid); 856 return (rc->cr_uid == acred->uid);
858} 857}
859 858
@@ -917,16 +916,48 @@ out_put_ctx:
917 return NULL; 916 return NULL;
918} 917}
919 918
919static int gss_renew_cred(struct rpc_task *task)
920{
921 struct rpc_cred *oldcred = task->tk_msg.rpc_cred;
922 struct gss_cred *gss_cred = container_of(oldcred,
923 struct gss_cred,
924 gc_base);
925 struct rpc_auth *auth = oldcred->cr_auth;
926 struct auth_cred acred = {
927 .uid = oldcred->cr_uid,
928 .machine_cred = gss_cred->gc_machine_cred,
929 };
930 struct rpc_cred *new;
931
932 new = gss_lookup_cred(auth, &acred, RPCAUTH_LOOKUP_NEW);
933 if (IS_ERR(new))
934 return PTR_ERR(new);
935 task->tk_msg.rpc_cred = new;
936 put_rpccred(oldcred);
937 return 0;
938}
939
920/* 940/*
921* Refresh credentials. XXX - finish 941* Refresh credentials. XXX - finish
922*/ 942*/
923static int 943static int
924gss_refresh(struct rpc_task *task) 944gss_refresh(struct rpc_task *task)
925{ 945{
946 struct rpc_cred *cred = task->tk_msg.rpc_cred;
947 int ret = 0;
948
949 if (!test_bit(RPCAUTH_CRED_NEW, &cred->cr_flags) &&
950 !test_bit(RPCAUTH_CRED_UPTODATE, &cred->cr_flags)) {
951 ret = gss_renew_cred(task);
952 if (ret < 0)
953 goto out;
954 cred = task->tk_msg.rpc_cred;
955 }
926 956
927 if (!gss_cred_is_uptodate_ctx(task->tk_msg.rpc_cred)) 957 if (test_bit(RPCAUTH_CRED_NEW, &cred->cr_flags))
928 return gss_refresh_upcall(task); 958 ret = gss_refresh_upcall(task);
929 return 0; 959out:
960 return ret;
930} 961}
931 962
932/* Dummy refresh routine: used only when destroying the context */ 963/* Dummy refresh routine: used only when destroying the context */
@@ -1286,9 +1317,7 @@ out:
1286static const struct rpc_authops authgss_ops = { 1317static const struct rpc_authops authgss_ops = {
1287 .owner = THIS_MODULE, 1318 .owner = THIS_MODULE,
1288 .au_flavor = RPC_AUTH_GSS, 1319 .au_flavor = RPC_AUTH_GSS,
1289#ifdef RPC_DEBUG
1290 .au_name = "RPCSEC_GSS", 1320 .au_name = "RPCSEC_GSS",
1291#endif
1292 .create = gss_create, 1321 .create = gss_create,
1293 .destroy = gss_destroy, 1322 .destroy = gss_destroy,
1294 .lookup_cred = gss_lookup_cred, 1323 .lookup_cred = gss_lookup_cred,
@@ -1299,6 +1328,7 @@ static const struct rpc_credops gss_credops = {
1299 .cr_name = "AUTH_GSS", 1328 .cr_name = "AUTH_GSS",
1300 .crdestroy = gss_destroy_cred, 1329 .crdestroy = gss_destroy_cred,
1301 .cr_init = gss_cred_init, 1330 .cr_init = gss_cred_init,
1331 .crbind = rpcauth_generic_bind_cred,
1302 .crmatch = gss_match, 1332 .crmatch = gss_match,
1303 .crmarshal = gss_marshal, 1333 .crmarshal = gss_marshal,
1304 .crrefresh = gss_refresh, 1334 .crrefresh = gss_refresh,
@@ -1310,6 +1340,7 @@ static const struct rpc_credops gss_credops = {
1310static const struct rpc_credops gss_nullops = { 1340static const struct rpc_credops gss_nullops = {
1311 .cr_name = "AUTH_GSS", 1341 .cr_name = "AUTH_GSS",
1312 .crdestroy = gss_destroy_cred, 1342 .crdestroy = gss_destroy_cred,
1343 .crbind = rpcauth_generic_bind_cred,
1313 .crmatch = gss_match, 1344 .crmatch = gss_match,
1314 .crmarshal = gss_marshal, 1345 .crmarshal = gss_marshal,
1315 .crrefresh = gss_refresh_null, 1346 .crrefresh = gss_refresh_null,
diff --git a/net/sunrpc/auth_gss/gss_generic_token.c b/net/sunrpc/auth_gss/gss_generic_token.c
index ea8c92ecdae5..d83b881685fe 100644
--- a/net/sunrpc/auth_gss/gss_generic_token.c
+++ b/net/sunrpc/auth_gss/gss_generic_token.c
@@ -148,7 +148,7 @@ int
148g_token_size(struct xdr_netobj *mech, unsigned int body_size) 148g_token_size(struct xdr_netobj *mech, unsigned int body_size)
149{ 149{
150 /* set body_size to sequence contents size */ 150 /* set body_size to sequence contents size */
151 body_size += 4 + (int) mech->len; /* NEED overflow check */ 151 body_size += 2 + (int) mech->len; /* NEED overflow check */
152 return(1 + der_length_size(body_size) + body_size); 152 return(1 + der_length_size(body_size) + body_size);
153} 153}
154 154
@@ -161,7 +161,7 @@ void
161g_make_token_header(struct xdr_netobj *mech, int body_size, unsigned char **buf) 161g_make_token_header(struct xdr_netobj *mech, int body_size, unsigned char **buf)
162{ 162{
163 *(*buf)++ = 0x60; 163 *(*buf)++ = 0x60;
164 der_write_length(buf, 4 + mech->len + body_size); 164 der_write_length(buf, 2 + mech->len + body_size);
165 *(*buf)++ = 0x06; 165 *(*buf)++ = 0x06;
166 *(*buf)++ = (unsigned char) mech->len; 166 *(*buf)++ = (unsigned char) mech->len;
167 TWRITE_STR(*buf, mech->data, ((int) mech->len)); 167 TWRITE_STR(*buf, mech->data, ((int) mech->len));
diff --git a/net/sunrpc/auth_gss/gss_krb5_crypto.c b/net/sunrpc/auth_gss/gss_krb5_crypto.c
index 0dd792338fa9..1d52308ca324 100644
--- a/net/sunrpc/auth_gss/gss_krb5_crypto.c
+++ b/net/sunrpc/auth_gss/gss_krb5_crypto.c
@@ -66,8 +66,8 @@ krb5_encrypt(
66 goto out; 66 goto out;
67 67
68 if (crypto_blkcipher_ivsize(tfm) > 16) { 68 if (crypto_blkcipher_ivsize(tfm) > 16) {
69 dprintk("RPC: gss_k5encrypt: tfm iv size to large %d\n", 69 dprintk("RPC: gss_k5encrypt: tfm iv size too large %d\n",
70 crypto_blkcipher_ivsize(tfm)); 70 crypto_blkcipher_ivsize(tfm));
71 goto out; 71 goto out;
72 } 72 }
73 73
@@ -102,7 +102,7 @@ krb5_decrypt(
102 goto out; 102 goto out;
103 103
104 if (crypto_blkcipher_ivsize(tfm) > 16) { 104 if (crypto_blkcipher_ivsize(tfm) > 16) {
105 dprintk("RPC: gss_k5decrypt: tfm iv size to large %d\n", 105 dprintk("RPC: gss_k5decrypt: tfm iv size too large %d\n",
106 crypto_blkcipher_ivsize(tfm)); 106 crypto_blkcipher_ivsize(tfm));
107 goto out; 107 goto out;
108 } 108 }
diff --git a/net/sunrpc/auth_gss/gss_krb5_seal.c b/net/sunrpc/auth_gss/gss_krb5_seal.c
index dedcbd6108f4..5f1d36dfbcf7 100644
--- a/net/sunrpc/auth_gss/gss_krb5_seal.c
+++ b/net/sunrpc/auth_gss/gss_krb5_seal.c
@@ -87,10 +87,10 @@ gss_get_mic_kerberos(struct gss_ctx *gss_ctx, struct xdr_buf *text,
87 87
88 now = get_seconds(); 88 now = get_seconds();
89 89
90 token->len = g_token_size(&ctx->mech_used, 22); 90 token->len = g_token_size(&ctx->mech_used, 24);
91 91
92 ptr = token->data; 92 ptr = token->data;
93 g_make_token_header(&ctx->mech_used, 22, &ptr); 93 g_make_token_header(&ctx->mech_used, 24, &ptr);
94 94
95 *ptr++ = (unsigned char) ((KG_TOK_MIC_MSG>>8)&0xff); 95 *ptr++ = (unsigned char) ((KG_TOK_MIC_MSG>>8)&0xff);
96 *ptr++ = (unsigned char) (KG_TOK_MIC_MSG&0xff); 96 *ptr++ = (unsigned char) (KG_TOK_MIC_MSG&0xff);
@@ -109,15 +109,14 @@ gss_get_mic_kerberos(struct gss_ctx *gss_ctx, struct xdr_buf *text,
109 md5cksum.data, md5cksum.len)) 109 md5cksum.data, md5cksum.len))
110 return GSS_S_FAILURE; 110 return GSS_S_FAILURE;
111 111
112 memcpy(krb5_hdr + 16, md5cksum.data + md5cksum.len - KRB5_CKSUM_LENGTH, 112 memcpy(krb5_hdr + 16, md5cksum.data + md5cksum.len - 8, 8);
113 KRB5_CKSUM_LENGTH);
114 113
115 spin_lock(&krb5_seq_lock); 114 spin_lock(&krb5_seq_lock);
116 seq_send = ctx->seq_send++; 115 seq_send = ctx->seq_send++;
117 spin_unlock(&krb5_seq_lock); 116 spin_unlock(&krb5_seq_lock);
118 117
119 if (krb5_make_seq_num(ctx->seq, ctx->initiate ? 0 : 0xff, 118 if (krb5_make_seq_num(ctx->seq, ctx->initiate ? 0 : 0xff,
120 ctx->seq_send, krb5_hdr + 16, krb5_hdr + 8)) 119 seq_send, krb5_hdr + 16, krb5_hdr + 8))
121 return GSS_S_FAILURE; 120 return GSS_S_FAILURE;
122 121
123 return (ctx->endtime < now) ? GSS_S_CONTEXT_EXPIRED : GSS_S_COMPLETE; 122 return (ctx->endtime < now) ? GSS_S_CONTEXT_EXPIRED : GSS_S_COMPLETE;
diff --git a/net/sunrpc/auth_gss/gss_krb5_seqnum.c b/net/sunrpc/auth_gss/gss_krb5_seqnum.c
index 43f3421f1e6a..f160be6c1a46 100644
--- a/net/sunrpc/auth_gss/gss_krb5_seqnum.c
+++ b/net/sunrpc/auth_gss/gss_krb5_seqnum.c
@@ -43,7 +43,7 @@
43s32 43s32
44krb5_make_seq_num(struct crypto_blkcipher *key, 44krb5_make_seq_num(struct crypto_blkcipher *key,
45 int direction, 45 int direction,
46 s32 seqnum, 46 u32 seqnum,
47 unsigned char *cksum, unsigned char *buf) 47 unsigned char *cksum, unsigned char *buf)
48{ 48{
49 unsigned char plain[8]; 49 unsigned char plain[8];
@@ -65,7 +65,7 @@ s32
65krb5_get_seq_num(struct crypto_blkcipher *key, 65krb5_get_seq_num(struct crypto_blkcipher *key,
66 unsigned char *cksum, 66 unsigned char *cksum,
67 unsigned char *buf, 67 unsigned char *buf,
68 int *direction, s32 * seqnum) 68 int *direction, u32 *seqnum)
69{ 69{
70 s32 code; 70 s32 code;
71 unsigned char plain[8]; 71 unsigned char plain[8];
diff --git a/net/sunrpc/auth_gss/gss_krb5_unseal.c b/net/sunrpc/auth_gss/gss_krb5_unseal.c
index e30a993466bc..d91a5d004803 100644
--- a/net/sunrpc/auth_gss/gss_krb5_unseal.c
+++ b/net/sunrpc/auth_gss/gss_krb5_unseal.c
@@ -82,7 +82,7 @@ gss_verify_mic_kerberos(struct gss_ctx *gss_ctx,
82 struct xdr_netobj md5cksum = {.len = 0, .data = cksumdata}; 82 struct xdr_netobj md5cksum = {.len = 0, .data = cksumdata};
83 s32 now; 83 s32 now;
84 int direction; 84 int direction;
85 s32 seqnum; 85 u32 seqnum;
86 unsigned char *ptr = (unsigned char *)read_token->data; 86 unsigned char *ptr = (unsigned char *)read_token->data;
87 int bodysize; 87 int bodysize;
88 88
diff --git a/net/sunrpc/auth_gss/gss_krb5_wrap.c b/net/sunrpc/auth_gss/gss_krb5_wrap.c
index 3bdc527ee64a..b00b1b426301 100644
--- a/net/sunrpc/auth_gss/gss_krb5_wrap.c
+++ b/net/sunrpc/auth_gss/gss_krb5_wrap.c
@@ -137,7 +137,7 @@ gss_wrap_kerberos(struct gss_ctx *ctx, int offset,
137 BUG_ON((buf->len - offset) % blocksize); 137 BUG_ON((buf->len - offset) % blocksize);
138 plainlen = blocksize + buf->len - offset; 138 plainlen = blocksize + buf->len - offset;
139 139
140 headlen = g_token_size(&kctx->mech_used, 22 + plainlen) - 140 headlen = g_token_size(&kctx->mech_used, 24 + plainlen) -
141 (buf->len - offset); 141 (buf->len - offset);
142 142
143 ptr = buf->head[0].iov_base + offset; 143 ptr = buf->head[0].iov_base + offset;
@@ -149,7 +149,7 @@ gss_wrap_kerberos(struct gss_ctx *ctx, int offset,
149 buf->len += headlen; 149 buf->len += headlen;
150 BUG_ON((buf->len - offset - headlen) % blocksize); 150 BUG_ON((buf->len - offset - headlen) % blocksize);
151 151
152 g_make_token_header(&kctx->mech_used, 22 + plainlen, &ptr); 152 g_make_token_header(&kctx->mech_used, 24 + plainlen, &ptr);
153 153
154 154
155 *ptr++ = (unsigned char) ((KG_TOK_WRAP_MSG>>8)&0xff); 155 *ptr++ = (unsigned char) ((KG_TOK_WRAP_MSG>>8)&0xff);
@@ -176,9 +176,7 @@ gss_wrap_kerberos(struct gss_ctx *ctx, int offset,
176 if (krb5_encrypt(kctx->seq, NULL, md5cksum.data, 176 if (krb5_encrypt(kctx->seq, NULL, md5cksum.data,
177 md5cksum.data, md5cksum.len)) 177 md5cksum.data, md5cksum.len))
178 return GSS_S_FAILURE; 178 return GSS_S_FAILURE;
179 memcpy(krb5_hdr + 16, 179 memcpy(krb5_hdr + 16, md5cksum.data + md5cksum.len - 8, 8);
180 md5cksum.data + md5cksum.len - KRB5_CKSUM_LENGTH,
181 KRB5_CKSUM_LENGTH);
182 180
183 spin_lock(&krb5_seq_lock); 181 spin_lock(&krb5_seq_lock);
184 seq_send = kctx->seq_send++; 182 seq_send = kctx->seq_send++;
diff --git a/net/sunrpc/auth_gss/gss_spkm3_seal.c b/net/sunrpc/auth_gss/gss_spkm3_seal.c
index abf17ce2e3b1..c832712f8d55 100644
--- a/net/sunrpc/auth_gss/gss_spkm3_seal.c
+++ b/net/sunrpc/auth_gss/gss_spkm3_seal.c
@@ -107,10 +107,10 @@ spkm3_make_token(struct spkm3_ctx *ctx,
107 tokenlen = 10 + ctxelen + 1 + md5elen + 1; 107 tokenlen = 10 + ctxelen + 1 + md5elen + 1;
108 108
109 /* Create token header using generic routines */ 109 /* Create token header using generic routines */
110 token->len = g_token_size(&ctx->mech_used, tokenlen); 110 token->len = g_token_size(&ctx->mech_used, tokenlen + 2);
111 111
112 ptr = token->data; 112 ptr = token->data;
113 g_make_token_header(&ctx->mech_used, tokenlen, &ptr); 113 g_make_token_header(&ctx->mech_used, tokenlen + 2, &ptr);
114 114
115 spkm3_make_mic_token(&ptr, tokenlen, &mic_hdr, &md5cksum, md5elen, md5zbit); 115 spkm3_make_mic_token(&ptr, tokenlen, &mic_hdr, &md5cksum, md5elen, md5zbit);
116 } else if (toktype == SPKM_WRAP_TOK) { /* Not Supported */ 116 } else if (toktype == SPKM_WRAP_TOK) { /* Not Supported */
diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
index 481f984e9a22..5905d56737d6 100644
--- a/net/sunrpc/auth_gss/svcauth_gss.c
+++ b/net/sunrpc/auth_gss/svcauth_gss.c
@@ -1146,7 +1146,7 @@ svcauth_gss_accept(struct svc_rqst *rqstp, __be32 *authp)
1146 case RPC_GSS_SVC_INTEGRITY: 1146 case RPC_GSS_SVC_INTEGRITY:
1147 if (unwrap_integ_data(&rqstp->rq_arg, 1147 if (unwrap_integ_data(&rqstp->rq_arg,
1148 gc->gc_seq, rsci->mechctx)) 1148 gc->gc_seq, rsci->mechctx))
1149 goto auth_err; 1149 goto garbage_args;
1150 /* placeholders for length and seq. number: */ 1150 /* placeholders for length and seq. number: */
1151 svc_putnl(resv, 0); 1151 svc_putnl(resv, 0);
1152 svc_putnl(resv, 0); 1152 svc_putnl(resv, 0);
@@ -1154,7 +1154,7 @@ svcauth_gss_accept(struct svc_rqst *rqstp, __be32 *authp)
1154 case RPC_GSS_SVC_PRIVACY: 1154 case RPC_GSS_SVC_PRIVACY:
1155 if (unwrap_priv_data(rqstp, &rqstp->rq_arg, 1155 if (unwrap_priv_data(rqstp, &rqstp->rq_arg,
1156 gc->gc_seq, rsci->mechctx)) 1156 gc->gc_seq, rsci->mechctx))
1157 goto auth_err; 1157 goto garbage_args;
1158 /* placeholders for length and seq. number: */ 1158 /* placeholders for length and seq. number: */
1159 svc_putnl(resv, 0); 1159 svc_putnl(resv, 0);
1160 svc_putnl(resv, 0); 1160 svc_putnl(resv, 0);
@@ -1169,6 +1169,11 @@ svcauth_gss_accept(struct svc_rqst *rqstp, __be32 *authp)
1169 ret = SVC_OK; 1169 ret = SVC_OK;
1170 goto out; 1170 goto out;
1171 } 1171 }
1172garbage_args:
1173 /* Restore write pointer to its original value: */
1174 xdr_ressize_check(rqstp, reject_stat);
1175 ret = SVC_GARBAGE;
1176 goto out;
1172auth_err: 1177auth_err:
1173 /* Restore write pointer to its original value: */ 1178 /* Restore write pointer to its original value: */
1174 xdr_ressize_check(rqstp, reject_stat); 1179 xdr_ressize_check(rqstp, reject_stat);
diff --git a/net/sunrpc/auth_null.c b/net/sunrpc/auth_null.c
index 537d0e8589dd..c70dd7f5258e 100644
--- a/net/sunrpc/auth_null.c
+++ b/net/sunrpc/auth_null.c
@@ -104,9 +104,7 @@ nul_validate(struct rpc_task *task, __be32 *p)
104const struct rpc_authops authnull_ops = { 104const struct rpc_authops authnull_ops = {
105 .owner = THIS_MODULE, 105 .owner = THIS_MODULE,
106 .au_flavor = RPC_AUTH_NULL, 106 .au_flavor = RPC_AUTH_NULL,
107#ifdef RPC_DEBUG
108 .au_name = "NULL", 107 .au_name = "NULL",
109#endif
110 .create = nul_create, 108 .create = nul_create,
111 .destroy = nul_destroy, 109 .destroy = nul_destroy,
112 .lookup_cred = nul_lookup_cred, 110 .lookup_cred = nul_lookup_cred,
@@ -125,6 +123,7 @@ static
125const struct rpc_credops null_credops = { 123const struct rpc_credops null_credops = {
126 .cr_name = "AUTH_NULL", 124 .cr_name = "AUTH_NULL",
127 .crdestroy = nul_destroy_cred, 125 .crdestroy = nul_destroy_cred,
126 .crbind = rpcauth_generic_bind_cred,
128 .crmatch = nul_match, 127 .crmatch = nul_match,
129 .crmarshal = nul_marshal, 128 .crmarshal = nul_marshal,
130 .crrefresh = nul_refresh, 129 .crrefresh = nul_refresh,
diff --git a/net/sunrpc/auth_unix.c b/net/sunrpc/auth_unix.c
index 5ed91e5bcee4..44920b90bdc4 100644
--- a/net/sunrpc/auth_unix.c
+++ b/net/sunrpc/auth_unix.c
@@ -60,7 +60,8 @@ static struct rpc_cred *
60unx_create_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags) 60unx_create_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags)
61{ 61{
62 struct unx_cred *cred; 62 struct unx_cred *cred;
63 int i; 63 unsigned int groups = 0;
64 unsigned int i;
64 65
65 dprintk("RPC: allocating UNIX cred for uid %d gid %d\n", 66 dprintk("RPC: allocating UNIX cred for uid %d gid %d\n",
66 acred->uid, acred->gid); 67 acred->uid, acred->gid);
@@ -70,21 +71,17 @@ unx_create_cred(struct rpc_auth *auth, struct auth_cred *acred, int flags)
70 71
71 rpcauth_init_cred(&cred->uc_base, acred, auth, &unix_credops); 72 rpcauth_init_cred(&cred->uc_base, acred, auth, &unix_credops);
72 cred->uc_base.cr_flags = 1UL << RPCAUTH_CRED_UPTODATE; 73 cred->uc_base.cr_flags = 1UL << RPCAUTH_CRED_UPTODATE;
73 if (flags & RPCAUTH_LOOKUP_ROOTCREDS) { 74
74 cred->uc_uid = 0; 75 if (acred->group_info != NULL)
75 cred->uc_gid = 0; 76 groups = acred->group_info->ngroups;
76 cred->uc_gids[0] = NOGROUP; 77 if (groups > NFS_NGROUPS)
77 } else { 78 groups = NFS_NGROUPS;
78 int groups = acred->group_info->ngroups; 79
79 if (groups > NFS_NGROUPS) 80 cred->uc_gid = acred->gid;
80 groups = NFS_NGROUPS; 81 for (i = 0; i < groups; i++)
81 82 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
82 cred->uc_gid = acred->gid; 83 if (i < NFS_NGROUPS)
83 for (i = 0; i < groups; i++) 84 cred->uc_gids[i] = NOGROUP;
84 cred->uc_gids[i] = GROUP_AT(acred->group_info, i);
85 if (i < NFS_NGROUPS)
86 cred->uc_gids[i] = NOGROUP;
87 }
88 85
89 return &cred->uc_base; 86 return &cred->uc_base;
90} 87}
@@ -118,26 +115,21 @@ static int
118unx_match(struct auth_cred *acred, struct rpc_cred *rcred, int flags) 115unx_match(struct auth_cred *acred, struct rpc_cred *rcred, int flags)
119{ 116{
120 struct unx_cred *cred = container_of(rcred, struct unx_cred, uc_base); 117 struct unx_cred *cred = container_of(rcred, struct unx_cred, uc_base);
121 int i; 118 unsigned int groups = 0;
119 unsigned int i;
122 120
123 if (!(flags & RPCAUTH_LOOKUP_ROOTCREDS)) {
124 int groups;
125 121
126 if (cred->uc_uid != acred->uid 122 if (cred->uc_uid != acred->uid || cred->uc_gid != acred->gid)
127 || cred->uc_gid != acred->gid) 123 return 0;
128 return 0;
129 124
125 if (acred->group_info != NULL)
130 groups = acred->group_info->ngroups; 126 groups = acred->group_info->ngroups;
131 if (groups > NFS_NGROUPS) 127 if (groups > NFS_NGROUPS)
132 groups = NFS_NGROUPS; 128 groups = NFS_NGROUPS;
133 for (i = 0; i < groups ; i++) 129 for (i = 0; i < groups ; i++)
134 if (cred->uc_gids[i] != GROUP_AT(acred->group_info, i)) 130 if (cred->uc_gids[i] != GROUP_AT(acred->group_info, i))
135 return 0; 131 return 0;
136 return 1; 132 return 1;
137 }
138 return (cred->uc_uid == 0
139 && cred->uc_gid == 0
140 && cred->uc_gids[0] == (gid_t) NOGROUP);
141} 133}
142 134
143/* 135/*
@@ -218,9 +210,7 @@ void __init rpc_init_authunix(void)
218const struct rpc_authops authunix_ops = { 210const struct rpc_authops authunix_ops = {
219 .owner = THIS_MODULE, 211 .owner = THIS_MODULE,
220 .au_flavor = RPC_AUTH_UNIX, 212 .au_flavor = RPC_AUTH_UNIX,
221#ifdef RPC_DEBUG
222 .au_name = "UNIX", 213 .au_name = "UNIX",
223#endif
224 .create = unx_create, 214 .create = unx_create,
225 .destroy = unx_destroy, 215 .destroy = unx_destroy,
226 .lookup_cred = unx_lookup_cred, 216 .lookup_cred = unx_lookup_cred,
@@ -245,6 +235,7 @@ static
245const struct rpc_credops unix_credops = { 235const struct rpc_credops unix_credops = {
246 .cr_name = "AUTH_UNIX", 236 .cr_name = "AUTH_UNIX",
247 .crdestroy = unx_destroy_cred, 237 .crdestroy = unx_destroy_cred,
238 .crbind = rpcauth_generic_bind_cred,
248 .crmatch = unx_match, 239 .crmatch = unx_match,
249 .crmarshal = unx_marshal, 240 .crmarshal = unx_marshal,
250 .crrefresh = unx_refresh, 241 .crrefresh = unx_refresh,
diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
index b5f2786251b9..d75530ff2a6d 100644
--- a/net/sunrpc/cache.c
+++ b/net/sunrpc/cache.c
@@ -571,7 +571,6 @@ static int cache_defer_req(struct cache_req *req, struct cache_head *item)
571 return -ETIMEDOUT; 571 return -ETIMEDOUT;
572 572
573 dreq->item = item; 573 dreq->item = item;
574 dreq->recv_time = get_seconds();
575 574
576 spin_lock(&cache_defer_lock); 575 spin_lock(&cache_defer_lock);
577 576
diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
index 7b96ff38002f..8945307556ec 100644
--- a/net/sunrpc/clnt.c
+++ b/net/sunrpc/clnt.c
@@ -544,7 +544,7 @@ EXPORT_SYMBOL_GPL(rpc_run_task);
544 * @msg: RPC call parameters 544 * @msg: RPC call parameters
545 * @flags: RPC call flags 545 * @flags: RPC call flags
546 */ 546 */
547int rpc_call_sync(struct rpc_clnt *clnt, struct rpc_message *msg, int flags) 547int rpc_call_sync(struct rpc_clnt *clnt, const struct rpc_message *msg, int flags)
548{ 548{
549 struct rpc_task *task; 549 struct rpc_task *task;
550 struct rpc_task_setup task_setup_data = { 550 struct rpc_task_setup task_setup_data = {
@@ -575,7 +575,7 @@ EXPORT_SYMBOL_GPL(rpc_call_sync);
575 * @data: user call data 575 * @data: user call data
576 */ 576 */
577int 577int
578rpc_call_async(struct rpc_clnt *clnt, struct rpc_message *msg, int flags, 578rpc_call_async(struct rpc_clnt *clnt, const struct rpc_message *msg, int flags,
579 const struct rpc_call_ops *tk_ops, void *data) 579 const struct rpc_call_ops *tk_ops, void *data)
580{ 580{
581 struct rpc_task *task; 581 struct rpc_task *task;
@@ -1062,7 +1062,7 @@ call_transmit(struct rpc_task *task)
1062 if (task->tk_msg.rpc_proc->p_decode != NULL) 1062 if (task->tk_msg.rpc_proc->p_decode != NULL)
1063 return; 1063 return;
1064 task->tk_action = rpc_exit_task; 1064 task->tk_action = rpc_exit_task;
1065 rpc_wake_up_task(task); 1065 rpc_wake_up_queued_task(&task->tk_xprt->pending, task);
1066} 1066}
1067 1067
1068/* 1068/*
@@ -1116,7 +1116,8 @@ call_status(struct rpc_task *task)
1116 case -ETIMEDOUT: 1116 case -ETIMEDOUT:
1117 task->tk_action = call_timeout; 1117 task->tk_action = call_timeout;
1118 if (task->tk_client->cl_discrtry) 1118 if (task->tk_client->cl_discrtry)
1119 xprt_force_disconnect(task->tk_xprt); 1119 xprt_conditional_disconnect(task->tk_xprt,
1120 req->rq_connect_cookie);
1120 break; 1121 break;
1121 case -ECONNREFUSED: 1122 case -ECONNREFUSED:
1122 case -ENOTCONN: 1123 case -ENOTCONN:
@@ -1168,6 +1169,11 @@ call_timeout(struct rpc_task *task)
1168 clnt->cl_protname, clnt->cl_server); 1169 clnt->cl_protname, clnt->cl_server);
1169 } 1170 }
1170 rpc_force_rebind(clnt); 1171 rpc_force_rebind(clnt);
1172 /*
1173 * Did our request time out due to an RPCSEC_GSS out-of-sequence
1174 * event? RFC2203 requires the server to drop all such requests.
1175 */
1176 rpcauth_invalcred(task);
1171 1177
1172retry: 1178retry:
1173 clnt->cl_stats->rpcretrans++; 1179 clnt->cl_stats->rpcretrans++;
@@ -1195,18 +1201,6 @@ call_decode(struct rpc_task *task)
1195 task->tk_flags &= ~RPC_CALL_MAJORSEEN; 1201 task->tk_flags &= ~RPC_CALL_MAJORSEEN;
1196 } 1202 }
1197 1203
1198 if (task->tk_status < 12) {
1199 if (!RPC_IS_SOFT(task)) {
1200 task->tk_action = call_bind;
1201 clnt->cl_stats->rpcretrans++;
1202 goto out_retry;
1203 }
1204 dprintk("RPC: %s: too small RPC reply size (%d bytes)\n",
1205 clnt->cl_protname, task->tk_status);
1206 task->tk_action = call_timeout;
1207 goto out_retry;
1208 }
1209
1210 /* 1204 /*
1211 * Ensure that we see all writes made by xprt_complete_rqst() 1205 * Ensure that we see all writes made by xprt_complete_rqst()
1212 * before it changed req->rq_received. 1206 * before it changed req->rq_received.
@@ -1218,6 +1212,18 @@ call_decode(struct rpc_task *task)
1218 WARN_ON(memcmp(&req->rq_rcv_buf, &req->rq_private_buf, 1212 WARN_ON(memcmp(&req->rq_rcv_buf, &req->rq_private_buf,
1219 sizeof(req->rq_rcv_buf)) != 0); 1213 sizeof(req->rq_rcv_buf)) != 0);
1220 1214
1215 if (req->rq_rcv_buf.len < 12) {
1216 if (!RPC_IS_SOFT(task)) {
1217 task->tk_action = call_bind;
1218 clnt->cl_stats->rpcretrans++;
1219 goto out_retry;
1220 }
1221 dprintk("RPC: %s: too small RPC reply size (%d bytes)\n",
1222 clnt->cl_protname, task->tk_status);
1223 task->tk_action = call_timeout;
1224 goto out_retry;
1225 }
1226
1221 /* Verify the RPC header */ 1227 /* Verify the RPC header */
1222 p = call_verify(task); 1228 p = call_verify(task);
1223 if (IS_ERR(p)) { 1229 if (IS_ERR(p)) {
@@ -1236,10 +1242,14 @@ call_decode(struct rpc_task *task)
1236 task->tk_status); 1242 task->tk_status);
1237 return; 1243 return;
1238out_retry: 1244out_retry:
1239 req->rq_received = req->rq_private_buf.len = 0;
1240 task->tk_status = 0; 1245 task->tk_status = 0;
1241 if (task->tk_client->cl_discrtry) 1246 /* Note: call_verify() may have freed the RPC slot */
1242 xprt_force_disconnect(task->tk_xprt); 1247 if (task->tk_rqstp == req) {
1248 req->rq_received = req->rq_rcv_buf.len = 0;
1249 if (task->tk_client->cl_discrtry)
1250 xprt_conditional_disconnect(task->tk_xprt,
1251 req->rq_connect_cookie);
1252 }
1243} 1253}
1244 1254
1245/* 1255/*
@@ -1531,7 +1541,7 @@ void rpc_show_tasks(void)
1531 proc = -1; 1541 proc = -1;
1532 1542
1533 if (RPC_IS_QUEUED(t)) 1543 if (RPC_IS_QUEUED(t))
1534 rpc_waitq = rpc_qname(t->u.tk_wait.rpc_waitq); 1544 rpc_waitq = rpc_qname(t->tk_waitqueue);
1535 1545
1536 printk("%5u %04d %04x %6d %8p %6d %8p %8ld %8s %8p %8p\n", 1546 printk("%5u %04d %04x %6d %8p %6d %8p %8ld %8s %8p %8p\n",
1537 t->tk_pid, proc, 1547 t->tk_pid, proc,
diff --git a/net/sunrpc/rpcb_clnt.c b/net/sunrpc/rpcb_clnt.c
index 56aa018dce3a..0517967a68bf 100644
--- a/net/sunrpc/rpcb_clnt.c
+++ b/net/sunrpc/rpcb_clnt.c
@@ -298,7 +298,7 @@ void rpcb_getport_async(struct rpc_task *task)
298 298
299 /* Put self on queue before sending rpcbind request, in case 299 /* Put self on queue before sending rpcbind request, in case
300 * rpcb_getport_done completes before we return from rpc_run_task */ 300 * rpcb_getport_done completes before we return from rpc_run_task */
301 rpc_sleep_on(&xprt->binding, task, NULL, NULL); 301 rpc_sleep_on(&xprt->binding, task, NULL);
302 302
303 /* Someone else may have bound if we slept */ 303 /* Someone else may have bound if we slept */
304 if (xprt_bound(xprt)) { 304 if (xprt_bound(xprt)) {
diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
index 4c669121e607..6eab9bf94baf 100644
--- a/net/sunrpc/sched.c
+++ b/net/sunrpc/sched.c
@@ -38,9 +38,9 @@ static struct kmem_cache *rpc_buffer_slabp __read_mostly;
38static mempool_t *rpc_task_mempool __read_mostly; 38static mempool_t *rpc_task_mempool __read_mostly;
39static mempool_t *rpc_buffer_mempool __read_mostly; 39static mempool_t *rpc_buffer_mempool __read_mostly;
40 40
41static void __rpc_default_timer(struct rpc_task *task);
42static void rpc_async_schedule(struct work_struct *); 41static void rpc_async_schedule(struct work_struct *);
43static void rpc_release_task(struct rpc_task *task); 42static void rpc_release_task(struct rpc_task *task);
43static void __rpc_queue_timer_fn(unsigned long ptr);
44 44
45/* 45/*
46 * RPC tasks sit here while waiting for conditions to improve. 46 * RPC tasks sit here while waiting for conditions to improve.
@@ -57,41 +57,30 @@ struct workqueue_struct *rpciod_workqueue;
57 * queue->lock and bh_disabled in order to avoid races within 57 * queue->lock and bh_disabled in order to avoid races within
58 * rpc_run_timer(). 58 * rpc_run_timer().
59 */ 59 */
60static inline void 60static void
61__rpc_disable_timer(struct rpc_task *task) 61__rpc_disable_timer(struct rpc_wait_queue *queue, struct rpc_task *task)
62{ 62{
63 if (task->tk_timeout == 0)
64 return;
63 dprintk("RPC: %5u disabling timer\n", task->tk_pid); 65 dprintk("RPC: %5u disabling timer\n", task->tk_pid);
64 task->tk_timeout_fn = NULL;
65 task->tk_timeout = 0; 66 task->tk_timeout = 0;
67 list_del(&task->u.tk_wait.timer_list);
68 if (list_empty(&queue->timer_list.list))
69 del_timer(&queue->timer_list.timer);
66} 70}
67 71
68/* 72static void
69 * Run a timeout function. 73rpc_set_queue_timer(struct rpc_wait_queue *queue, unsigned long expires)
70 * We use the callback in order to allow __rpc_wake_up_task()
71 * and friends to disable the timer synchronously on SMP systems
72 * without calling del_timer_sync(). The latter could cause a
73 * deadlock if called while we're holding spinlocks...
74 */
75static void rpc_run_timer(struct rpc_task *task)
76{ 74{
77 void (*callback)(struct rpc_task *); 75 queue->timer_list.expires = expires;
78 76 mod_timer(&queue->timer_list.timer, expires);
79 callback = task->tk_timeout_fn;
80 task->tk_timeout_fn = NULL;
81 if (callback && RPC_IS_QUEUED(task)) {
82 dprintk("RPC: %5u running timer\n", task->tk_pid);
83 callback(task);
84 }
85 smp_mb__before_clear_bit();
86 clear_bit(RPC_TASK_HAS_TIMER, &task->tk_runstate);
87 smp_mb__after_clear_bit();
88} 77}
89 78
90/* 79/*
91 * Set up a timer for the current task. 80 * Set up a timer for the current task.
92 */ 81 */
93static inline void 82static void
94__rpc_add_timer(struct rpc_task *task, rpc_action timer) 83__rpc_add_timer(struct rpc_wait_queue *queue, struct rpc_task *task)
95{ 84{
96 if (!task->tk_timeout) 85 if (!task->tk_timeout)
97 return; 86 return;
@@ -99,27 +88,10 @@ __rpc_add_timer(struct rpc_task *task, rpc_action timer)
99 dprintk("RPC: %5u setting alarm for %lu ms\n", 88 dprintk("RPC: %5u setting alarm for %lu ms\n",
100 task->tk_pid, task->tk_timeout * 1000 / HZ); 89 task->tk_pid, task->tk_timeout * 1000 / HZ);
101 90
102 if (timer) 91 task->u.tk_wait.expires = jiffies + task->tk_timeout;
103 task->tk_timeout_fn = timer; 92 if (list_empty(&queue->timer_list.list) || time_before(task->u.tk_wait.expires, queue->timer_list.expires))
104 else 93 rpc_set_queue_timer(queue, task->u.tk_wait.expires);
105 task->tk_timeout_fn = __rpc_default_timer; 94 list_add(&task->u.tk_wait.timer_list, &queue->timer_list.list);
106 set_bit(RPC_TASK_HAS_TIMER, &task->tk_runstate);
107 mod_timer(&task->tk_timer, jiffies + task->tk_timeout);
108}
109
110/*
111 * Delete any timer for the current task. Because we use del_timer_sync(),
112 * this function should never be called while holding queue->lock.
113 */
114static void
115rpc_delete_timer(struct rpc_task *task)
116{
117 if (RPC_IS_QUEUED(task))
118 return;
119 if (test_and_clear_bit(RPC_TASK_HAS_TIMER, &task->tk_runstate)) {
120 del_singleshot_timer_sync(&task->tk_timer);
121 dprintk("RPC: %5u deleting timer\n", task->tk_pid);
122 }
123} 95}
124 96
125/* 97/*
@@ -161,7 +133,7 @@ static void __rpc_add_wait_queue(struct rpc_wait_queue *queue, struct rpc_task *
161 list_add(&task->u.tk_wait.list, &queue->tasks[0]); 133 list_add(&task->u.tk_wait.list, &queue->tasks[0]);
162 else 134 else
163 list_add_tail(&task->u.tk_wait.list, &queue->tasks[0]); 135 list_add_tail(&task->u.tk_wait.list, &queue->tasks[0]);
164 task->u.tk_wait.rpc_waitq = queue; 136 task->tk_waitqueue = queue;
165 queue->qlen++; 137 queue->qlen++;
166 rpc_set_queued(task); 138 rpc_set_queued(task);
167 139
@@ -181,22 +153,18 @@ static void __rpc_remove_wait_queue_priority(struct rpc_task *task)
181 list_move(&t->u.tk_wait.list, &task->u.tk_wait.list); 153 list_move(&t->u.tk_wait.list, &task->u.tk_wait.list);
182 list_splice_init(&task->u.tk_wait.links, &t->u.tk_wait.links); 154 list_splice_init(&task->u.tk_wait.links, &t->u.tk_wait.links);
183 } 155 }
184 list_del(&task->u.tk_wait.list);
185} 156}
186 157
187/* 158/*
188 * Remove request from queue. 159 * Remove request from queue.
189 * Note: must be called with spin lock held. 160 * Note: must be called with spin lock held.
190 */ 161 */
191static void __rpc_remove_wait_queue(struct rpc_task *task) 162static void __rpc_remove_wait_queue(struct rpc_wait_queue *queue, struct rpc_task *task)
192{ 163{
193 struct rpc_wait_queue *queue; 164 __rpc_disable_timer(queue, task);
194 queue = task->u.tk_wait.rpc_waitq;
195
196 if (RPC_IS_PRIORITY(queue)) 165 if (RPC_IS_PRIORITY(queue))
197 __rpc_remove_wait_queue_priority(task); 166 __rpc_remove_wait_queue_priority(task);
198 else 167 list_del(&task->u.tk_wait.list);
199 list_del(&task->u.tk_wait.list);
200 queue->qlen--; 168 queue->qlen--;
201 dprintk("RPC: %5u removed from queue %p \"%s\"\n", 169 dprintk("RPC: %5u removed from queue %p \"%s\"\n",
202 task->tk_pid, queue, rpc_qname(queue)); 170 task->tk_pid, queue, rpc_qname(queue));
@@ -229,6 +197,9 @@ static void __rpc_init_priority_wait_queue(struct rpc_wait_queue *queue, const c
229 INIT_LIST_HEAD(&queue->tasks[i]); 197 INIT_LIST_HEAD(&queue->tasks[i]);
230 queue->maxpriority = nr_queues - 1; 198 queue->maxpriority = nr_queues - 1;
231 rpc_reset_waitqueue_priority(queue); 199 rpc_reset_waitqueue_priority(queue);
200 queue->qlen = 0;
201 setup_timer(&queue->timer_list.timer, __rpc_queue_timer_fn, (unsigned long)queue);
202 INIT_LIST_HEAD(&queue->timer_list.list);
232#ifdef RPC_DEBUG 203#ifdef RPC_DEBUG
233 queue->name = qname; 204 queue->name = qname;
234#endif 205#endif
@@ -245,6 +216,12 @@ void rpc_init_wait_queue(struct rpc_wait_queue *queue, const char *qname)
245} 216}
246EXPORT_SYMBOL_GPL(rpc_init_wait_queue); 217EXPORT_SYMBOL_GPL(rpc_init_wait_queue);
247 218
219void rpc_destroy_wait_queue(struct rpc_wait_queue *queue)
220{
221 del_timer_sync(&queue->timer_list.timer);
222}
223EXPORT_SYMBOL_GPL(rpc_destroy_wait_queue);
224
248static int rpc_wait_bit_killable(void *word) 225static int rpc_wait_bit_killable(void *word)
249{ 226{
250 if (fatal_signal_pending(current)) 227 if (fatal_signal_pending(current))
@@ -313,7 +290,6 @@ EXPORT_SYMBOL_GPL(__rpc_wait_for_completion_task);
313 */ 290 */
314static void rpc_make_runnable(struct rpc_task *task) 291static void rpc_make_runnable(struct rpc_task *task)
315{ 292{
316 BUG_ON(task->tk_timeout_fn);
317 rpc_clear_queued(task); 293 rpc_clear_queued(task);
318 if (rpc_test_and_set_running(task)) 294 if (rpc_test_and_set_running(task))
319 return; 295 return;
@@ -326,7 +302,7 @@ static void rpc_make_runnable(struct rpc_task *task)
326 int status; 302 int status;
327 303
328 INIT_WORK(&task->u.tk_work, rpc_async_schedule); 304 INIT_WORK(&task->u.tk_work, rpc_async_schedule);
329 status = queue_work(task->tk_workqueue, &task->u.tk_work); 305 status = queue_work(rpciod_workqueue, &task->u.tk_work);
330 if (status < 0) { 306 if (status < 0) {
331 printk(KERN_WARNING "RPC: failed to add task to queue: error: %d!\n", status); 307 printk(KERN_WARNING "RPC: failed to add task to queue: error: %d!\n", status);
332 task->tk_status = status; 308 task->tk_status = status;
@@ -343,7 +319,7 @@ static void rpc_make_runnable(struct rpc_task *task)
343 * as it's on a wait queue. 319 * as it's on a wait queue.
344 */ 320 */
345static void __rpc_sleep_on(struct rpc_wait_queue *q, struct rpc_task *task, 321static void __rpc_sleep_on(struct rpc_wait_queue *q, struct rpc_task *task,
346 rpc_action action, rpc_action timer) 322 rpc_action action)
347{ 323{
348 dprintk("RPC: %5u sleep_on(queue \"%s\" time %lu)\n", 324 dprintk("RPC: %5u sleep_on(queue \"%s\" time %lu)\n",
349 task->tk_pid, rpc_qname(q), jiffies); 325 task->tk_pid, rpc_qname(q), jiffies);
@@ -357,11 +333,11 @@ static void __rpc_sleep_on(struct rpc_wait_queue *q, struct rpc_task *task,
357 333
358 BUG_ON(task->tk_callback != NULL); 334 BUG_ON(task->tk_callback != NULL);
359 task->tk_callback = action; 335 task->tk_callback = action;
360 __rpc_add_timer(task, timer); 336 __rpc_add_timer(q, task);
361} 337}
362 338
363void rpc_sleep_on(struct rpc_wait_queue *q, struct rpc_task *task, 339void rpc_sleep_on(struct rpc_wait_queue *q, struct rpc_task *task,
364 rpc_action action, rpc_action timer) 340 rpc_action action)
365{ 341{
366 /* Mark the task as being activated if so needed */ 342 /* Mark the task as being activated if so needed */
367 rpc_set_active(task); 343 rpc_set_active(task);
@@ -370,18 +346,19 @@ void rpc_sleep_on(struct rpc_wait_queue *q, struct rpc_task *task,
370 * Protect the queue operations. 346 * Protect the queue operations.
371 */ 347 */
372 spin_lock_bh(&q->lock); 348 spin_lock_bh(&q->lock);
373 __rpc_sleep_on(q, task, action, timer); 349 __rpc_sleep_on(q, task, action);
374 spin_unlock_bh(&q->lock); 350 spin_unlock_bh(&q->lock);
375} 351}
376EXPORT_SYMBOL_GPL(rpc_sleep_on); 352EXPORT_SYMBOL_GPL(rpc_sleep_on);
377 353
378/** 354/**
379 * __rpc_do_wake_up_task - wake up a single rpc_task 355 * __rpc_do_wake_up_task - wake up a single rpc_task
356 * @queue: wait queue
380 * @task: task to be woken up 357 * @task: task to be woken up
381 * 358 *
382 * Caller must hold queue->lock, and have cleared the task queued flag. 359 * Caller must hold queue->lock, and have cleared the task queued flag.
383 */ 360 */
384static void __rpc_do_wake_up_task(struct rpc_task *task) 361static void __rpc_do_wake_up_task(struct rpc_wait_queue *queue, struct rpc_task *task)
385{ 362{
386 dprintk("RPC: %5u __rpc_wake_up_task (now %lu)\n", 363 dprintk("RPC: %5u __rpc_wake_up_task (now %lu)\n",
387 task->tk_pid, jiffies); 364 task->tk_pid, jiffies);
@@ -395,8 +372,7 @@ static void __rpc_do_wake_up_task(struct rpc_task *task)
395 return; 372 return;
396 } 373 }
397 374
398 __rpc_disable_timer(task); 375 __rpc_remove_wait_queue(queue, task);
399 __rpc_remove_wait_queue(task);
400 376
401 rpc_make_runnable(task); 377 rpc_make_runnable(task);
402 378
@@ -404,48 +380,32 @@ static void __rpc_do_wake_up_task(struct rpc_task *task)
404} 380}
405 381
406/* 382/*
407 * Wake up the specified task 383 * Wake up a queued task while the queue lock is being held
408 */ 384 */
409static void __rpc_wake_up_task(struct rpc_task *task) 385static void rpc_wake_up_task_queue_locked(struct rpc_wait_queue *queue, struct rpc_task *task)
410{ 386{
411 if (rpc_start_wakeup(task)) { 387 if (RPC_IS_QUEUED(task) && task->tk_waitqueue == queue)
412 if (RPC_IS_QUEUED(task)) 388 __rpc_do_wake_up_task(queue, task);
413 __rpc_do_wake_up_task(task);
414 rpc_finish_wakeup(task);
415 }
416} 389}
417 390
418/* 391/*
419 * Default timeout handler if none specified by user 392 * Wake up a task on a specific queue
420 */ 393 */
421static void 394void rpc_wake_up_queued_task(struct rpc_wait_queue *queue, struct rpc_task *task)
422__rpc_default_timer(struct rpc_task *task)
423{ 395{
424 dprintk("RPC: %5u timeout (default timer)\n", task->tk_pid); 396 spin_lock_bh(&queue->lock);
425 task->tk_status = -ETIMEDOUT; 397 rpc_wake_up_task_queue_locked(queue, task);
426 rpc_wake_up_task(task); 398 spin_unlock_bh(&queue->lock);
427} 399}
400EXPORT_SYMBOL_GPL(rpc_wake_up_queued_task);
428 401
429/* 402/*
430 * Wake up the specified task 403 * Wake up the specified task
431 */ 404 */
432void rpc_wake_up_task(struct rpc_task *task) 405static void rpc_wake_up_task(struct rpc_task *task)
433{ 406{
434 rcu_read_lock_bh(); 407 rpc_wake_up_queued_task(task->tk_waitqueue, task);
435 if (rpc_start_wakeup(task)) {
436 if (RPC_IS_QUEUED(task)) {
437 struct rpc_wait_queue *queue = task->u.tk_wait.rpc_waitq;
438
439 /* Note: we're already in a bh-safe context */
440 spin_lock(&queue->lock);
441 __rpc_do_wake_up_task(task);
442 spin_unlock(&queue->lock);
443 }
444 rpc_finish_wakeup(task);
445 }
446 rcu_read_unlock_bh();
447} 408}
448EXPORT_SYMBOL_GPL(rpc_wake_up_task);
449 409
450/* 410/*
451 * Wake up the next task on a priority queue. 411 * Wake up the next task on a priority queue.
@@ -495,7 +455,7 @@ new_queue:
495new_owner: 455new_owner:
496 rpc_set_waitqueue_owner(queue, task->tk_owner); 456 rpc_set_waitqueue_owner(queue, task->tk_owner);
497out: 457out:
498 __rpc_wake_up_task(task); 458 rpc_wake_up_task_queue_locked(queue, task);
499 return task; 459 return task;
500} 460}
501 461
@@ -508,16 +468,14 @@ struct rpc_task * rpc_wake_up_next(struct rpc_wait_queue *queue)
508 468
509 dprintk("RPC: wake_up_next(%p \"%s\")\n", 469 dprintk("RPC: wake_up_next(%p \"%s\")\n",
510 queue, rpc_qname(queue)); 470 queue, rpc_qname(queue));
511 rcu_read_lock_bh(); 471 spin_lock_bh(&queue->lock);
512 spin_lock(&queue->lock);
513 if (RPC_IS_PRIORITY(queue)) 472 if (RPC_IS_PRIORITY(queue))
514 task = __rpc_wake_up_next_priority(queue); 473 task = __rpc_wake_up_next_priority(queue);
515 else { 474 else {
516 task_for_first(task, &queue->tasks[0]) 475 task_for_first(task, &queue->tasks[0])
517 __rpc_wake_up_task(task); 476 rpc_wake_up_task_queue_locked(queue, task);
518 } 477 }
519 spin_unlock(&queue->lock); 478 spin_unlock_bh(&queue->lock);
520 rcu_read_unlock_bh();
521 479
522 return task; 480 return task;
523} 481}
@@ -534,18 +492,16 @@ void rpc_wake_up(struct rpc_wait_queue *queue)
534 struct rpc_task *task, *next; 492 struct rpc_task *task, *next;
535 struct list_head *head; 493 struct list_head *head;
536 494
537 rcu_read_lock_bh(); 495 spin_lock_bh(&queue->lock);
538 spin_lock(&queue->lock);
539 head = &queue->tasks[queue->maxpriority]; 496 head = &queue->tasks[queue->maxpriority];
540 for (;;) { 497 for (;;) {
541 list_for_each_entry_safe(task, next, head, u.tk_wait.list) 498 list_for_each_entry_safe(task, next, head, u.tk_wait.list)
542 __rpc_wake_up_task(task); 499 rpc_wake_up_task_queue_locked(queue, task);
543 if (head == &queue->tasks[0]) 500 if (head == &queue->tasks[0])
544 break; 501 break;
545 head--; 502 head--;
546 } 503 }
547 spin_unlock(&queue->lock); 504 spin_unlock_bh(&queue->lock);
548 rcu_read_unlock_bh();
549} 505}
550EXPORT_SYMBOL_GPL(rpc_wake_up); 506EXPORT_SYMBOL_GPL(rpc_wake_up);
551 507
@@ -561,26 +517,48 @@ void rpc_wake_up_status(struct rpc_wait_queue *queue, int status)
561 struct rpc_task *task, *next; 517 struct rpc_task *task, *next;
562 struct list_head *head; 518 struct list_head *head;
563 519
564 rcu_read_lock_bh(); 520 spin_lock_bh(&queue->lock);
565 spin_lock(&queue->lock);
566 head = &queue->tasks[queue->maxpriority]; 521 head = &queue->tasks[queue->maxpriority];
567 for (;;) { 522 for (;;) {
568 list_for_each_entry_safe(task, next, head, u.tk_wait.list) { 523 list_for_each_entry_safe(task, next, head, u.tk_wait.list) {
569 task->tk_status = status; 524 task->tk_status = status;
570 __rpc_wake_up_task(task); 525 rpc_wake_up_task_queue_locked(queue, task);
571 } 526 }
572 if (head == &queue->tasks[0]) 527 if (head == &queue->tasks[0])
573 break; 528 break;
574 head--; 529 head--;
575 } 530 }
576 spin_unlock(&queue->lock); 531 spin_unlock_bh(&queue->lock);
577 rcu_read_unlock_bh();
578} 532}
579EXPORT_SYMBOL_GPL(rpc_wake_up_status); 533EXPORT_SYMBOL_GPL(rpc_wake_up_status);
580 534
535static void __rpc_queue_timer_fn(unsigned long ptr)
536{
537 struct rpc_wait_queue *queue = (struct rpc_wait_queue *)ptr;
538 struct rpc_task *task, *n;
539 unsigned long expires, now, timeo;
540
541 spin_lock(&queue->lock);
542 expires = now = jiffies;
543 list_for_each_entry_safe(task, n, &queue->timer_list.list, u.tk_wait.timer_list) {
544 timeo = task->u.tk_wait.expires;
545 if (time_after_eq(now, timeo)) {
546 dprintk("RPC: %5u timeout\n", task->tk_pid);
547 task->tk_status = -ETIMEDOUT;
548 rpc_wake_up_task_queue_locked(queue, task);
549 continue;
550 }
551 if (expires == now || time_after(expires, timeo))
552 expires = timeo;
553 }
554 if (!list_empty(&queue->timer_list.list))
555 rpc_set_queue_timer(queue, expires);
556 spin_unlock(&queue->lock);
557}
558
581static void __rpc_atrun(struct rpc_task *task) 559static void __rpc_atrun(struct rpc_task *task)
582{ 560{
583 rpc_wake_up_task(task); 561 task->tk_status = 0;
584} 562}
585 563
586/* 564/*
@@ -589,7 +567,7 @@ static void __rpc_atrun(struct rpc_task *task)
589void rpc_delay(struct rpc_task *task, unsigned long delay) 567void rpc_delay(struct rpc_task *task, unsigned long delay)
590{ 568{
591 task->tk_timeout = delay; 569 task->tk_timeout = delay;
592 rpc_sleep_on(&delay_queue, task, NULL, __rpc_atrun); 570 rpc_sleep_on(&delay_queue, task, __rpc_atrun);
593} 571}
594EXPORT_SYMBOL_GPL(rpc_delay); 572EXPORT_SYMBOL_GPL(rpc_delay);
595 573
@@ -644,10 +622,6 @@ static void __rpc_execute(struct rpc_task *task)
644 BUG_ON(RPC_IS_QUEUED(task)); 622 BUG_ON(RPC_IS_QUEUED(task));
645 623
646 for (;;) { 624 for (;;) {
647 /*
648 * Garbage collection of pending timers...
649 */
650 rpc_delete_timer(task);
651 625
652 /* 626 /*
653 * Execute any pending callback. 627 * Execute any pending callback.
@@ -816,8 +790,6 @@ EXPORT_SYMBOL_GPL(rpc_free);
816static void rpc_init_task(struct rpc_task *task, const struct rpc_task_setup *task_setup_data) 790static void rpc_init_task(struct rpc_task *task, const struct rpc_task_setup *task_setup_data)
817{ 791{
818 memset(task, 0, sizeof(*task)); 792 memset(task, 0, sizeof(*task));
819 setup_timer(&task->tk_timer, (void (*)(unsigned long))rpc_run_timer,
820 (unsigned long)task);
821 atomic_set(&task->tk_count, 1); 793 atomic_set(&task->tk_count, 1);
822 task->tk_flags = task_setup_data->flags; 794 task->tk_flags = task_setup_data->flags;
823 task->tk_ops = task_setup_data->callback_ops; 795 task->tk_ops = task_setup_data->callback_ops;
@@ -832,7 +804,7 @@ static void rpc_init_task(struct rpc_task *task, const struct rpc_task_setup *ta
832 task->tk_owner = current->tgid; 804 task->tk_owner = current->tgid;
833 805
834 /* Initialize workqueue for async tasks */ 806 /* Initialize workqueue for async tasks */
835 task->tk_workqueue = rpciod_workqueue; 807 task->tk_workqueue = task_setup_data->workqueue;
836 808
837 task->tk_client = task_setup_data->rpc_client; 809 task->tk_client = task_setup_data->rpc_client;
838 if (task->tk_client != NULL) { 810 if (task->tk_client != NULL) {
@@ -845,12 +817,11 @@ static void rpc_init_task(struct rpc_task *task, const struct rpc_task_setup *ta
845 task->tk_action = rpc_prepare_task; 817 task->tk_action = rpc_prepare_task;
846 818
847 if (task_setup_data->rpc_message != NULL) { 819 if (task_setup_data->rpc_message != NULL) {
848 memcpy(&task->tk_msg, task_setup_data->rpc_message, sizeof(task->tk_msg)); 820 task->tk_msg.rpc_proc = task_setup_data->rpc_message->rpc_proc;
821 task->tk_msg.rpc_argp = task_setup_data->rpc_message->rpc_argp;
822 task->tk_msg.rpc_resp = task_setup_data->rpc_message->rpc_resp;
849 /* Bind the user cred */ 823 /* Bind the user cred */
850 if (task->tk_msg.rpc_cred != NULL) 824 rpcauth_bindcred(task, task_setup_data->rpc_message->rpc_cred, task_setup_data->flags);
851 rpcauth_holdcred(task);
852 else
853 rpcauth_bindcred(task);
854 if (task->tk_action == NULL) 825 if (task->tk_action == NULL)
855 rpc_call_start(task); 826 rpc_call_start(task);
856 } 827 }
@@ -868,13 +839,6 @@ rpc_alloc_task(void)
868 return (struct rpc_task *)mempool_alloc(rpc_task_mempool, GFP_NOFS); 839 return (struct rpc_task *)mempool_alloc(rpc_task_mempool, GFP_NOFS);
869} 840}
870 841
871static void rpc_free_task(struct rcu_head *rcu)
872{
873 struct rpc_task *task = container_of(rcu, struct rpc_task, u.tk_rcu);
874 dprintk("RPC: %5u freeing task\n", task->tk_pid);
875 mempool_free(task, rpc_task_mempool);
876}
877
878/* 842/*
879 * Create a new task for the specified client. 843 * Create a new task for the specified client.
880 */ 844 */
@@ -898,12 +862,25 @@ out:
898 return task; 862 return task;
899} 863}
900 864
901 865static void rpc_free_task(struct rpc_task *task)
902void rpc_put_task(struct rpc_task *task)
903{ 866{
904 const struct rpc_call_ops *tk_ops = task->tk_ops; 867 const struct rpc_call_ops *tk_ops = task->tk_ops;
905 void *calldata = task->tk_calldata; 868 void *calldata = task->tk_calldata;
906 869
870 if (task->tk_flags & RPC_TASK_DYNAMIC) {
871 dprintk("RPC: %5u freeing task\n", task->tk_pid);
872 mempool_free(task, rpc_task_mempool);
873 }
874 rpc_release_calldata(tk_ops, calldata);
875}
876
877static void rpc_async_release(struct work_struct *work)
878{
879 rpc_free_task(container_of(work, struct rpc_task, u.tk_work));
880}
881
882void rpc_put_task(struct rpc_task *task)
883{
907 if (!atomic_dec_and_test(&task->tk_count)) 884 if (!atomic_dec_and_test(&task->tk_count))
908 return; 885 return;
909 /* Release resources */ 886 /* Release resources */
@@ -915,9 +892,11 @@ void rpc_put_task(struct rpc_task *task)
915 rpc_release_client(task->tk_client); 892 rpc_release_client(task->tk_client);
916 task->tk_client = NULL; 893 task->tk_client = NULL;
917 } 894 }
918 if (task->tk_flags & RPC_TASK_DYNAMIC) 895 if (task->tk_workqueue != NULL) {
919 call_rcu_bh(&task->u.tk_rcu, rpc_free_task); 896 INIT_WORK(&task->u.tk_work, rpc_async_release);
920 rpc_release_calldata(tk_ops, calldata); 897 queue_work(task->tk_workqueue, &task->u.tk_work);
898 } else
899 rpc_free_task(task);
921} 900}
922EXPORT_SYMBOL_GPL(rpc_put_task); 901EXPORT_SYMBOL_GPL(rpc_put_task);
923 902
@@ -937,9 +916,6 @@ static void rpc_release_task(struct rpc_task *task)
937 } 916 }
938 BUG_ON (RPC_IS_QUEUED(task)); 917 BUG_ON (RPC_IS_QUEUED(task));
939 918
940 /* Synchronously delete any running timer */
941 rpc_delete_timer(task);
942
943#ifdef RPC_DEBUG 919#ifdef RPC_DEBUG
944 task->tk_magic = 0; 920 task->tk_magic = 0;
945#endif 921#endif
@@ -1029,11 +1005,20 @@ rpc_destroy_mempool(void)
1029 kmem_cache_destroy(rpc_task_slabp); 1005 kmem_cache_destroy(rpc_task_slabp);
1030 if (rpc_buffer_slabp) 1006 if (rpc_buffer_slabp)
1031 kmem_cache_destroy(rpc_buffer_slabp); 1007 kmem_cache_destroy(rpc_buffer_slabp);
1008 rpc_destroy_wait_queue(&delay_queue);
1032} 1009}
1033 1010
1034int 1011int
1035rpc_init_mempool(void) 1012rpc_init_mempool(void)
1036{ 1013{
1014 /*
1015 * The following is not strictly a mempool initialisation,
1016 * but there is no harm in doing it here
1017 */
1018 rpc_init_wait_queue(&delay_queue, "delayq");
1019 if (!rpciod_start())
1020 goto err_nomem;
1021
1037 rpc_task_slabp = kmem_cache_create("rpc_tasks", 1022 rpc_task_slabp = kmem_cache_create("rpc_tasks",
1038 sizeof(struct rpc_task), 1023 sizeof(struct rpc_task),
1039 0, SLAB_HWCACHE_ALIGN, 1024 0, SLAB_HWCACHE_ALIGN,
@@ -1054,13 +1039,6 @@ rpc_init_mempool(void)
1054 rpc_buffer_slabp); 1039 rpc_buffer_slabp);
1055 if (!rpc_buffer_mempool) 1040 if (!rpc_buffer_mempool)
1056 goto err_nomem; 1041 goto err_nomem;
1057 if (!rpciod_start())
1058 goto err_nomem;
1059 /*
1060 * The following is not strictly a mempool initialisation,
1061 * but there is no harm in doing it here
1062 */
1063 rpc_init_wait_queue(&delay_queue, "delayq");
1064 return 0; 1042 return 0;
1065err_nomem: 1043err_nomem:
1066 rpc_destroy_mempool(); 1044 rpc_destroy_mempool();
diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
index 090af78d68b5..d74c2d269539 100644
--- a/net/sunrpc/svc.c
+++ b/net/sunrpc/svc.c
@@ -510,8 +510,7 @@ EXPORT_SYMBOL(svc_destroy);
510static int 510static int
511svc_init_buffer(struct svc_rqst *rqstp, unsigned int size) 511svc_init_buffer(struct svc_rqst *rqstp, unsigned int size)
512{ 512{
513 int pages; 513 unsigned int pages, arghi;
514 int arghi;
515 514
516 pages = size / PAGE_SIZE + 1; /* extra page as we hold both request and reply. 515 pages = size / PAGE_SIZE + 1; /* extra page as we hold both request and reply.
517 * We assume one is at most one page 516 * We assume one is at most one page
@@ -525,7 +524,7 @@ svc_init_buffer(struct svc_rqst *rqstp, unsigned int size)
525 rqstp->rq_pages[arghi++] = p; 524 rqstp->rq_pages[arghi++] = p;
526 pages--; 525 pages--;
527 } 526 }
528 return ! pages; 527 return pages == 0;
529} 528}
530 529
531/* 530/*
@@ -534,8 +533,9 @@ svc_init_buffer(struct svc_rqst *rqstp, unsigned int size)
534static void 533static void
535svc_release_buffer(struct svc_rqst *rqstp) 534svc_release_buffer(struct svc_rqst *rqstp)
536{ 535{
537 int i; 536 unsigned int i;
538 for (i=0; i<ARRAY_SIZE(rqstp->rq_pages); i++) 537
538 for (i = 0; i < ARRAY_SIZE(rqstp->rq_pages); i++)
539 if (rqstp->rq_pages[i]) 539 if (rqstp->rq_pages[i])
540 put_page(rqstp->rq_pages[i]); 540 put_page(rqstp->rq_pages[i]);
541} 541}
@@ -590,7 +590,7 @@ __svc_create_thread(svc_thread_fn func, struct svc_serv *serv,
590 struct svc_rqst *rqstp; 590 struct svc_rqst *rqstp;
591 int error = -ENOMEM; 591 int error = -ENOMEM;
592 int have_oldmask = 0; 592 int have_oldmask = 0;
593 cpumask_t oldmask; 593 cpumask_t uninitialized_var(oldmask);
594 594
595 rqstp = svc_prepare_thread(serv, pool); 595 rqstp = svc_prepare_thread(serv, pool);
596 if (IS_ERR(rqstp)) { 596 if (IS_ERR(rqstp)) {
@@ -619,16 +619,6 @@ out_thread:
619} 619}
620 620
621/* 621/*
622 * Create a thread in the default pool. Caller must hold BKL.
623 */
624int
625svc_create_thread(svc_thread_fn func, struct svc_serv *serv)
626{
627 return __svc_create_thread(func, serv, &serv->sv_pools[0]);
628}
629EXPORT_SYMBOL(svc_create_thread);
630
631/*
632 * Choose a pool in which to create a new thread, for svc_set_num_threads 622 * Choose a pool in which to create a new thread, for svc_set_num_threads
633 */ 623 */
634static inline struct svc_pool * 624static inline struct svc_pool *
@@ -921,8 +911,7 @@ svc_process(struct svc_rqst *rqstp)
921 case SVC_OK: 911 case SVC_OK:
922 break; 912 break;
923 case SVC_GARBAGE: 913 case SVC_GARBAGE:
924 rpc_stat = rpc_garbage_args; 914 goto err_garbage;
925 goto err_bad;
926 case SVC_SYSERR: 915 case SVC_SYSERR:
927 rpc_stat = rpc_system_err; 916 rpc_stat = rpc_system_err;
928 goto err_bad; 917 goto err_bad;
diff --git a/net/sunrpc/svc_xprt.c b/net/sunrpc/svc_xprt.c
index 332eb47539e1..d8e8d79a8451 100644
--- a/net/sunrpc/svc_xprt.c
+++ b/net/sunrpc/svc_xprt.c
@@ -18,6 +18,7 @@
18#include <linux/skbuff.h> 18#include <linux/skbuff.h>
19#include <linux/file.h> 19#include <linux/file.h>
20#include <linux/freezer.h> 20#include <linux/freezer.h>
21#include <linux/kthread.h>
21#include <net/sock.h> 22#include <net/sock.h>
22#include <net/checksum.h> 23#include <net/checksum.h>
23#include <net/ip.h> 24#include <net/ip.h>
@@ -586,8 +587,12 @@ int svc_recv(struct svc_rqst *rqstp, long timeout)
586 while (rqstp->rq_pages[i] == NULL) { 587 while (rqstp->rq_pages[i] == NULL) {
587 struct page *p = alloc_page(GFP_KERNEL); 588 struct page *p = alloc_page(GFP_KERNEL);
588 if (!p) { 589 if (!p) {
589 int j = msecs_to_jiffies(500); 590 set_current_state(TASK_INTERRUPTIBLE);
590 schedule_timeout_uninterruptible(j); 591 if (signalled() || kthread_should_stop()) {
592 set_current_state(TASK_RUNNING);
593 return -EINTR;
594 }
595 schedule_timeout(msecs_to_jiffies(500));
591 } 596 }
592 rqstp->rq_pages[i] = p; 597 rqstp->rq_pages[i] = p;
593 } 598 }
@@ -607,7 +612,7 @@ int svc_recv(struct svc_rqst *rqstp, long timeout)
607 612
608 try_to_freeze(); 613 try_to_freeze();
609 cond_resched(); 614 cond_resched();
610 if (signalled()) 615 if (signalled() || kthread_should_stop())
611 return -EINTR; 616 return -EINTR;
612 617
613 spin_lock_bh(&pool->sp_lock); 618 spin_lock_bh(&pool->sp_lock);
@@ -626,6 +631,20 @@ int svc_recv(struct svc_rqst *rqstp, long timeout)
626 * to bring down the daemons ... 631 * to bring down the daemons ...
627 */ 632 */
628 set_current_state(TASK_INTERRUPTIBLE); 633 set_current_state(TASK_INTERRUPTIBLE);
634
635 /*
636 * checking kthread_should_stop() here allows us to avoid
637 * locking and signalling when stopping kthreads that call
638 * svc_recv. If the thread has already been woken up, then
639 * we can exit here without sleeping. If not, then it
640 * it'll be woken up quickly during the schedule_timeout
641 */
642 if (kthread_should_stop()) {
643 set_current_state(TASK_RUNNING);
644 spin_unlock_bh(&pool->sp_lock);
645 return -EINTR;
646 }
647
629 add_wait_queue(&rqstp->rq_wait, &wait); 648 add_wait_queue(&rqstp->rq_wait, &wait);
630 spin_unlock_bh(&pool->sp_lock); 649 spin_unlock_bh(&pool->sp_lock);
631 650
@@ -641,7 +660,10 @@ int svc_recv(struct svc_rqst *rqstp, long timeout)
641 svc_thread_dequeue(pool, rqstp); 660 svc_thread_dequeue(pool, rqstp);
642 spin_unlock_bh(&pool->sp_lock); 661 spin_unlock_bh(&pool->sp_lock);
643 dprintk("svc: server %p, no data yet\n", rqstp); 662 dprintk("svc: server %p, no data yet\n", rqstp);
644 return signalled()? -EINTR : -EAGAIN; 663 if (signalled() || kthread_should_stop())
664 return -EINTR;
665 else
666 return -EAGAIN;
645 } 667 }
646 } 668 }
647 spin_unlock_bh(&pool->sp_lock); 669 spin_unlock_bh(&pool->sp_lock);
diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
index 3c64051e4555..3f30ee6006ae 100644
--- a/net/sunrpc/svcauth_unix.c
+++ b/net/sunrpc/svcauth_unix.c
@@ -11,7 +11,8 @@
11#include <linux/hash.h> 11#include <linux/hash.h>
12#include <linux/string.h> 12#include <linux/string.h>
13#include <net/sock.h> 13#include <net/sock.h>
14 14#include <net/ipv6.h>
15#include <linux/kernel.h>
15#define RPCDBG_FACILITY RPCDBG_AUTH 16#define RPCDBG_FACILITY RPCDBG_AUTH
16 17
17 18
@@ -85,7 +86,7 @@ static void svcauth_unix_domain_release(struct auth_domain *dom)
85struct ip_map { 86struct ip_map {
86 struct cache_head h; 87 struct cache_head h;
87 char m_class[8]; /* e.g. "nfsd" */ 88 char m_class[8]; /* e.g. "nfsd" */
88 struct in_addr m_addr; 89 struct in6_addr m_addr;
89 struct unix_domain *m_client; 90 struct unix_domain *m_client;
90 int m_add_change; 91 int m_add_change;
91}; 92};
@@ -113,12 +114,19 @@ static inline int hash_ip(__be32 ip)
113 return (hash ^ (hash>>8)) & 0xff; 114 return (hash ^ (hash>>8)) & 0xff;
114} 115}
115#endif 116#endif
117static inline int hash_ip6(struct in6_addr ip)
118{
119 return (hash_ip(ip.s6_addr32[0]) ^
120 hash_ip(ip.s6_addr32[1]) ^
121 hash_ip(ip.s6_addr32[2]) ^
122 hash_ip(ip.s6_addr32[3]));
123}
116static int ip_map_match(struct cache_head *corig, struct cache_head *cnew) 124static int ip_map_match(struct cache_head *corig, struct cache_head *cnew)
117{ 125{
118 struct ip_map *orig = container_of(corig, struct ip_map, h); 126 struct ip_map *orig = container_of(corig, struct ip_map, h);
119 struct ip_map *new = container_of(cnew, struct ip_map, h); 127 struct ip_map *new = container_of(cnew, struct ip_map, h);
120 return strcmp(orig->m_class, new->m_class) == 0 128 return strcmp(orig->m_class, new->m_class) == 0
121 && orig->m_addr.s_addr == new->m_addr.s_addr; 129 && ipv6_addr_equal(&orig->m_addr, &new->m_addr);
122} 130}
123static void ip_map_init(struct cache_head *cnew, struct cache_head *citem) 131static void ip_map_init(struct cache_head *cnew, struct cache_head *citem)
124{ 132{
@@ -126,7 +134,7 @@ static void ip_map_init(struct cache_head *cnew, struct cache_head *citem)
126 struct ip_map *item = container_of(citem, struct ip_map, h); 134 struct ip_map *item = container_of(citem, struct ip_map, h);
127 135
128 strcpy(new->m_class, item->m_class); 136 strcpy(new->m_class, item->m_class);
129 new->m_addr.s_addr = item->m_addr.s_addr; 137 ipv6_addr_copy(&new->m_addr, &item->m_addr);
130} 138}
131static void update(struct cache_head *cnew, struct cache_head *citem) 139static void update(struct cache_head *cnew, struct cache_head *citem)
132{ 140{
@@ -150,22 +158,24 @@ static void ip_map_request(struct cache_detail *cd,
150 struct cache_head *h, 158 struct cache_head *h,
151 char **bpp, int *blen) 159 char **bpp, int *blen)
152{ 160{
153 char text_addr[20]; 161 char text_addr[40];
154 struct ip_map *im = container_of(h, struct ip_map, h); 162 struct ip_map *im = container_of(h, struct ip_map, h);
155 __be32 addr = im->m_addr.s_addr;
156
157 snprintf(text_addr, 20, "%u.%u.%u.%u",
158 ntohl(addr) >> 24 & 0xff,
159 ntohl(addr) >> 16 & 0xff,
160 ntohl(addr) >> 8 & 0xff,
161 ntohl(addr) >> 0 & 0xff);
162 163
164 if (ipv6_addr_v4mapped(&(im->m_addr))) {
165 snprintf(text_addr, 20, NIPQUAD_FMT,
166 ntohl(im->m_addr.s6_addr32[3]) >> 24 & 0xff,
167 ntohl(im->m_addr.s6_addr32[3]) >> 16 & 0xff,
168 ntohl(im->m_addr.s6_addr32[3]) >> 8 & 0xff,
169 ntohl(im->m_addr.s6_addr32[3]) >> 0 & 0xff);
170 } else {
171 snprintf(text_addr, 40, NIP6_FMT, NIP6(im->m_addr));
172 }
163 qword_add(bpp, blen, im->m_class); 173 qword_add(bpp, blen, im->m_class);
164 qword_add(bpp, blen, text_addr); 174 qword_add(bpp, blen, text_addr);
165 (*bpp)[-1] = '\n'; 175 (*bpp)[-1] = '\n';
166} 176}
167 177
168static struct ip_map *ip_map_lookup(char *class, struct in_addr addr); 178static struct ip_map *ip_map_lookup(char *class, struct in6_addr *addr);
169static int ip_map_update(struct ip_map *ipm, struct unix_domain *udom, time_t expiry); 179static int ip_map_update(struct ip_map *ipm, struct unix_domain *udom, time_t expiry);
170 180
171static int ip_map_parse(struct cache_detail *cd, 181static int ip_map_parse(struct cache_detail *cd,
@@ -176,10 +186,10 @@ static int ip_map_parse(struct cache_detail *cd,
176 * for scratch: */ 186 * for scratch: */
177 char *buf = mesg; 187 char *buf = mesg;
178 int len; 188 int len;
179 int b1,b2,b3,b4; 189 int b1, b2, b3, b4, b5, b6, b7, b8;
180 char c; 190 char c;
181 char class[8]; 191 char class[8];
182 struct in_addr addr; 192 struct in6_addr addr;
183 int err; 193 int err;
184 194
185 struct ip_map *ipmp; 195 struct ip_map *ipmp;
@@ -198,7 +208,23 @@ static int ip_map_parse(struct cache_detail *cd,
198 len = qword_get(&mesg, buf, mlen); 208 len = qword_get(&mesg, buf, mlen);
199 if (len <= 0) return -EINVAL; 209 if (len <= 0) return -EINVAL;
200 210
201 if (sscanf(buf, "%u.%u.%u.%u%c", &b1, &b2, &b3, &b4, &c) != 4) 211 if (sscanf(buf, NIPQUAD_FMT "%c", &b1, &b2, &b3, &b4, &c) == 4) {
212 addr.s6_addr32[0] = 0;
213 addr.s6_addr32[1] = 0;
214 addr.s6_addr32[2] = htonl(0xffff);
215 addr.s6_addr32[3] =
216 htonl((((((b1<<8)|b2)<<8)|b3)<<8)|b4);
217 } else if (sscanf(buf, NIP6_FMT "%c",
218 &b1, &b2, &b3, &b4, &b5, &b6, &b7, &b8, &c) == 8) {
219 addr.s6_addr16[0] = htons(b1);
220 addr.s6_addr16[1] = htons(b2);
221 addr.s6_addr16[2] = htons(b3);
222 addr.s6_addr16[3] = htons(b4);
223 addr.s6_addr16[4] = htons(b5);
224 addr.s6_addr16[5] = htons(b6);
225 addr.s6_addr16[6] = htons(b7);
226 addr.s6_addr16[7] = htons(b8);
227 } else
202 return -EINVAL; 228 return -EINVAL;
203 229
204 expiry = get_expiry(&mesg); 230 expiry = get_expiry(&mesg);
@@ -216,10 +242,7 @@ static int ip_map_parse(struct cache_detail *cd,
216 } else 242 } else
217 dom = NULL; 243 dom = NULL;
218 244
219 addr.s_addr = 245 ipmp = ip_map_lookup(class, &addr);
220 htonl((((((b1<<8)|b2)<<8)|b3)<<8)|b4);
221
222 ipmp = ip_map_lookup(class,addr);
223 if (ipmp) { 246 if (ipmp) {
224 err = ip_map_update(ipmp, 247 err = ip_map_update(ipmp,
225 container_of(dom, struct unix_domain, h), 248 container_of(dom, struct unix_domain, h),
@@ -239,7 +262,7 @@ static int ip_map_show(struct seq_file *m,
239 struct cache_head *h) 262 struct cache_head *h)
240{ 263{
241 struct ip_map *im; 264 struct ip_map *im;
242 struct in_addr addr; 265 struct in6_addr addr;
243 char *dom = "-no-domain-"; 266 char *dom = "-no-domain-";
244 267
245 if (h == NULL) { 268 if (h == NULL) {
@@ -248,20 +271,24 @@ static int ip_map_show(struct seq_file *m,
248 } 271 }
249 im = container_of(h, struct ip_map, h); 272 im = container_of(h, struct ip_map, h);
250 /* class addr domain */ 273 /* class addr domain */
251 addr = im->m_addr; 274 ipv6_addr_copy(&addr, &im->m_addr);
252 275
253 if (test_bit(CACHE_VALID, &h->flags) && 276 if (test_bit(CACHE_VALID, &h->flags) &&
254 !test_bit(CACHE_NEGATIVE, &h->flags)) 277 !test_bit(CACHE_NEGATIVE, &h->flags))
255 dom = im->m_client->h.name; 278 dom = im->m_client->h.name;
256 279
257 seq_printf(m, "%s %d.%d.%d.%d %s\n", 280 if (ipv6_addr_v4mapped(&addr)) {
258 im->m_class, 281 seq_printf(m, "%s" NIPQUAD_FMT "%s\n",
259 ntohl(addr.s_addr) >> 24 & 0xff, 282 im->m_class,
260 ntohl(addr.s_addr) >> 16 & 0xff, 283 ntohl(addr.s6_addr32[3]) >> 24 & 0xff,
261 ntohl(addr.s_addr) >> 8 & 0xff, 284 ntohl(addr.s6_addr32[3]) >> 16 & 0xff,
262 ntohl(addr.s_addr) >> 0 & 0xff, 285 ntohl(addr.s6_addr32[3]) >> 8 & 0xff,
263 dom 286 ntohl(addr.s6_addr32[3]) >> 0 & 0xff,
264 ); 287 dom);
288 } else {
289 seq_printf(m, "%s" NIP6_FMT "%s\n",
290 im->m_class, NIP6(addr), dom);
291 }
265 return 0; 292 return 0;
266} 293}
267 294
@@ -281,16 +308,16 @@ struct cache_detail ip_map_cache = {
281 .alloc = ip_map_alloc, 308 .alloc = ip_map_alloc,
282}; 309};
283 310
284static struct ip_map *ip_map_lookup(char *class, struct in_addr addr) 311static struct ip_map *ip_map_lookup(char *class, struct in6_addr *addr)
285{ 312{
286 struct ip_map ip; 313 struct ip_map ip;
287 struct cache_head *ch; 314 struct cache_head *ch;
288 315
289 strcpy(ip.m_class, class); 316 strcpy(ip.m_class, class);
290 ip.m_addr = addr; 317 ipv6_addr_copy(&ip.m_addr, addr);
291 ch = sunrpc_cache_lookup(&ip_map_cache, &ip.h, 318 ch = sunrpc_cache_lookup(&ip_map_cache, &ip.h,
292 hash_str(class, IP_HASHBITS) ^ 319 hash_str(class, IP_HASHBITS) ^
293 hash_ip(addr.s_addr)); 320 hash_ip6(*addr));
294 321
295 if (ch) 322 if (ch)
296 return container_of(ch, struct ip_map, h); 323 return container_of(ch, struct ip_map, h);
@@ -319,14 +346,14 @@ static int ip_map_update(struct ip_map *ipm, struct unix_domain *udom, time_t ex
319 ch = sunrpc_cache_update(&ip_map_cache, 346 ch = sunrpc_cache_update(&ip_map_cache,
320 &ip.h, &ipm->h, 347 &ip.h, &ipm->h,
321 hash_str(ipm->m_class, IP_HASHBITS) ^ 348 hash_str(ipm->m_class, IP_HASHBITS) ^
322 hash_ip(ipm->m_addr.s_addr)); 349 hash_ip6(ipm->m_addr));
323 if (!ch) 350 if (!ch)
324 return -ENOMEM; 351 return -ENOMEM;
325 cache_put(ch, &ip_map_cache); 352 cache_put(ch, &ip_map_cache);
326 return 0; 353 return 0;
327} 354}
328 355
329int auth_unix_add_addr(struct in_addr addr, struct auth_domain *dom) 356int auth_unix_add_addr(struct in6_addr *addr, struct auth_domain *dom)
330{ 357{
331 struct unix_domain *udom; 358 struct unix_domain *udom;
332 struct ip_map *ipmp; 359 struct ip_map *ipmp;
@@ -355,7 +382,7 @@ int auth_unix_forget_old(struct auth_domain *dom)
355} 382}
356EXPORT_SYMBOL(auth_unix_forget_old); 383EXPORT_SYMBOL(auth_unix_forget_old);
357 384
358struct auth_domain *auth_unix_lookup(struct in_addr addr) 385struct auth_domain *auth_unix_lookup(struct in6_addr *addr)
359{ 386{
360 struct ip_map *ipm; 387 struct ip_map *ipm;
361 struct auth_domain *rv; 388 struct auth_domain *rv;
@@ -650,9 +677,24 @@ static int unix_gid_find(uid_t uid, struct group_info **gip,
650int 677int
651svcauth_unix_set_client(struct svc_rqst *rqstp) 678svcauth_unix_set_client(struct svc_rqst *rqstp)
652{ 679{
653 struct sockaddr_in *sin = svc_addr_in(rqstp); 680 struct sockaddr_in *sin;
681 struct sockaddr_in6 *sin6, sin6_storage;
654 struct ip_map *ipm; 682 struct ip_map *ipm;
655 683
684 switch (rqstp->rq_addr.ss_family) {
685 case AF_INET:
686 sin = svc_addr_in(rqstp);
687 sin6 = &sin6_storage;
688 ipv6_addr_set(&sin6->sin6_addr, 0, 0,
689 htonl(0x0000FFFF), sin->sin_addr.s_addr);
690 break;
691 case AF_INET6:
692 sin6 = svc_addr_in6(rqstp);
693 break;
694 default:
695 BUG();
696 }
697
656 rqstp->rq_client = NULL; 698 rqstp->rq_client = NULL;
657 if (rqstp->rq_proc == 0) 699 if (rqstp->rq_proc == 0)
658 return SVC_OK; 700 return SVC_OK;
@@ -660,7 +702,7 @@ svcauth_unix_set_client(struct svc_rqst *rqstp)
660 ipm = ip_map_cached_get(rqstp); 702 ipm = ip_map_cached_get(rqstp);
661 if (ipm == NULL) 703 if (ipm == NULL)
662 ipm = ip_map_lookup(rqstp->rq_server->sv_program->pg_class, 704 ipm = ip_map_lookup(rqstp->rq_server->sv_program->pg_class,
663 sin->sin_addr); 705 &sin6->sin6_addr);
664 706
665 if (ipm == NULL) 707 if (ipm == NULL)
666 return SVC_DENIED; 708 return SVC_DENIED;
diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index c475977de05a..3e65719f1ef6 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -38,6 +38,7 @@
38#include <net/checksum.h> 38#include <net/checksum.h>
39#include <net/ip.h> 39#include <net/ip.h>
40#include <net/ipv6.h> 40#include <net/ipv6.h>
41#include <net/tcp.h>
41#include <net/tcp_states.h> 42#include <net/tcp_states.h>
42#include <asm/uaccess.h> 43#include <asm/uaccess.h>
43#include <asm/ioctls.h> 44#include <asm/ioctls.h>
@@ -45,6 +46,7 @@
45#include <linux/sunrpc/types.h> 46#include <linux/sunrpc/types.h>
46#include <linux/sunrpc/clnt.h> 47#include <linux/sunrpc/clnt.h>
47#include <linux/sunrpc/xdr.h> 48#include <linux/sunrpc/xdr.h>
49#include <linux/sunrpc/msg_prot.h>
48#include <linux/sunrpc/svcsock.h> 50#include <linux/sunrpc/svcsock.h>
49#include <linux/sunrpc/stats.h> 51#include <linux/sunrpc/stats.h>
50 52
@@ -822,8 +824,8 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp)
822 * the next four bytes. Otherwise try to gobble up as much as 824 * the next four bytes. Otherwise try to gobble up as much as
823 * possible up to the complete record length. 825 * possible up to the complete record length.
824 */ 826 */
825 if (svsk->sk_tcplen < 4) { 827 if (svsk->sk_tcplen < sizeof(rpc_fraghdr)) {
826 unsigned long want = 4 - svsk->sk_tcplen; 828 int want = sizeof(rpc_fraghdr) - svsk->sk_tcplen;
827 struct kvec iov; 829 struct kvec iov;
828 830
829 iov.iov_base = ((char *) &svsk->sk_reclen) + svsk->sk_tcplen; 831 iov.iov_base = ((char *) &svsk->sk_reclen) + svsk->sk_tcplen;
@@ -833,32 +835,31 @@ static int svc_tcp_recvfrom(struct svc_rqst *rqstp)
833 svsk->sk_tcplen += len; 835 svsk->sk_tcplen += len;
834 836
835 if (len < want) { 837 if (len < want) {
836 dprintk("svc: short recvfrom while reading record length (%d of %lu)\n", 838 dprintk("svc: short recvfrom while reading record "
837 len, want); 839 "length (%d of %d)\n", len, want);
838 svc_xprt_received(&svsk->sk_xprt); 840 svc_xprt_received(&svsk->sk_xprt);
839 return -EAGAIN; /* record header not complete */ 841 return -EAGAIN; /* record header not complete */
840 } 842 }
841 843
842 svsk->sk_reclen = ntohl(svsk->sk_reclen); 844 svsk->sk_reclen = ntohl(svsk->sk_reclen);
843 if (!(svsk->sk_reclen & 0x80000000)) { 845 if (!(svsk->sk_reclen & RPC_LAST_STREAM_FRAGMENT)) {
844 /* FIXME: technically, a record can be fragmented, 846 /* FIXME: technically, a record can be fragmented,
845 * and non-terminal fragments will not have the top 847 * and non-terminal fragments will not have the top
846 * bit set in the fragment length header. 848 * bit set in the fragment length header.
847 * But apparently no known nfs clients send fragmented 849 * But apparently no known nfs clients send fragmented
848 * records. */ 850 * records. */
849 if (net_ratelimit()) 851 if (net_ratelimit())
850 printk(KERN_NOTICE "RPC: bad TCP reclen 0x%08lx" 852 printk(KERN_NOTICE "RPC: multiple fragments "
851 " (non-terminal)\n", 853 "per record not supported\n");
852 (unsigned long) svsk->sk_reclen);
853 goto err_delete; 854 goto err_delete;
854 } 855 }
855 svsk->sk_reclen &= 0x7fffffff; 856 svsk->sk_reclen &= RPC_FRAGMENT_SIZE_MASK;
856 dprintk("svc: TCP record, %d bytes\n", svsk->sk_reclen); 857 dprintk("svc: TCP record, %d bytes\n", svsk->sk_reclen);
857 if (svsk->sk_reclen > serv->sv_max_mesg) { 858 if (svsk->sk_reclen > serv->sv_max_mesg) {
858 if (net_ratelimit()) 859 if (net_ratelimit())
859 printk(KERN_NOTICE "RPC: bad TCP reclen 0x%08lx" 860 printk(KERN_NOTICE "RPC: "
860 " (large)\n", 861 "fragment too large: 0x%08lx\n",
861 (unsigned long) svsk->sk_reclen); 862 (unsigned long)svsk->sk_reclen);
862 goto err_delete; 863 goto err_delete;
863 } 864 }
864 } 865 }
@@ -1045,7 +1046,6 @@ void svc_cleanup_xprt_sock(void)
1045static void svc_tcp_init(struct svc_sock *svsk, struct svc_serv *serv) 1046static void svc_tcp_init(struct svc_sock *svsk, struct svc_serv *serv)
1046{ 1047{
1047 struct sock *sk = svsk->sk_sk; 1048 struct sock *sk = svsk->sk_sk;
1048 struct tcp_sock *tp = tcp_sk(sk);
1049 1049
1050 svc_xprt_init(&svc_tcp_class, &svsk->sk_xprt, serv); 1050 svc_xprt_init(&svc_tcp_class, &svsk->sk_xprt, serv);
1051 set_bit(XPT_CACHE_AUTH, &svsk->sk_xprt.xpt_flags); 1051 set_bit(XPT_CACHE_AUTH, &svsk->sk_xprt.xpt_flags);
@@ -1063,7 +1063,7 @@ static void svc_tcp_init(struct svc_sock *svsk, struct svc_serv *serv)
1063 svsk->sk_reclen = 0; 1063 svsk->sk_reclen = 0;
1064 svsk->sk_tcplen = 0; 1064 svsk->sk_tcplen = 0;
1065 1065
1066 tp->nonagle = 1; /* disable Nagle's algorithm */ 1066 tcp_sk(sk)->nonagle |= TCP_NAGLE_OFF;
1067 1067
1068 /* initialise setting must have enough space to 1068 /* initialise setting must have enough space to
1069 * receive and respond to one request. 1069 * receive and respond to one request.
@@ -1101,6 +1101,7 @@ void svc_sock_update_bufs(struct svc_serv *serv)
1101 } 1101 }
1102 spin_unlock_bh(&serv->sv_lock); 1102 spin_unlock_bh(&serv->sv_lock);
1103} 1103}
1104EXPORT_SYMBOL(svc_sock_update_bufs);
1104 1105
1105/* 1106/*
1106 * Initialize socket for RPC use and create svc_sock struct 1107 * Initialize socket for RPC use and create svc_sock struct
diff --git a/net/sunrpc/xprt.c b/net/sunrpc/xprt.c
index d5553b8179f9..75d748eee0eb 100644
--- a/net/sunrpc/xprt.c
+++ b/net/sunrpc/xprt.c
@@ -188,9 +188,9 @@ out_sleep:
188 task->tk_timeout = 0; 188 task->tk_timeout = 0;
189 task->tk_status = -EAGAIN; 189 task->tk_status = -EAGAIN;
190 if (req && req->rq_ntrans) 190 if (req && req->rq_ntrans)
191 rpc_sleep_on(&xprt->resend, task, NULL, NULL); 191 rpc_sleep_on(&xprt->resend, task, NULL);
192 else 192 else
193 rpc_sleep_on(&xprt->sending, task, NULL, NULL); 193 rpc_sleep_on(&xprt->sending, task, NULL);
194 return 0; 194 return 0;
195} 195}
196EXPORT_SYMBOL_GPL(xprt_reserve_xprt); 196EXPORT_SYMBOL_GPL(xprt_reserve_xprt);
@@ -238,9 +238,9 @@ out_sleep:
238 task->tk_timeout = 0; 238 task->tk_timeout = 0;
239 task->tk_status = -EAGAIN; 239 task->tk_status = -EAGAIN;
240 if (req && req->rq_ntrans) 240 if (req && req->rq_ntrans)
241 rpc_sleep_on(&xprt->resend, task, NULL, NULL); 241 rpc_sleep_on(&xprt->resend, task, NULL);
242 else 242 else
243 rpc_sleep_on(&xprt->sending, task, NULL, NULL); 243 rpc_sleep_on(&xprt->sending, task, NULL);
244 return 0; 244 return 0;
245} 245}
246EXPORT_SYMBOL_GPL(xprt_reserve_xprt_cong); 246EXPORT_SYMBOL_GPL(xprt_reserve_xprt_cong);
@@ -447,13 +447,13 @@ EXPORT_SYMBOL_GPL(xprt_wake_pending_tasks);
447 * @task: task to be put to sleep 447 * @task: task to be put to sleep
448 * 448 *
449 */ 449 */
450void xprt_wait_for_buffer_space(struct rpc_task *task) 450void xprt_wait_for_buffer_space(struct rpc_task *task, rpc_action action)
451{ 451{
452 struct rpc_rqst *req = task->tk_rqstp; 452 struct rpc_rqst *req = task->tk_rqstp;
453 struct rpc_xprt *xprt = req->rq_xprt; 453 struct rpc_xprt *xprt = req->rq_xprt;
454 454
455 task->tk_timeout = req->rq_timeout; 455 task->tk_timeout = req->rq_timeout;
456 rpc_sleep_on(&xprt->pending, task, NULL, NULL); 456 rpc_sleep_on(&xprt->pending, task, action);
457} 457}
458EXPORT_SYMBOL_GPL(xprt_wait_for_buffer_space); 458EXPORT_SYMBOL_GPL(xprt_wait_for_buffer_space);
459 459
@@ -472,7 +472,7 @@ void xprt_write_space(struct rpc_xprt *xprt)
472 if (xprt->snd_task) { 472 if (xprt->snd_task) {
473 dprintk("RPC: write space: waking waiting task on " 473 dprintk("RPC: write space: waking waiting task on "
474 "xprt %p\n", xprt); 474 "xprt %p\n", xprt);
475 rpc_wake_up_task(xprt->snd_task); 475 rpc_wake_up_queued_task(&xprt->pending, xprt->snd_task);
476 } 476 }
477 spin_unlock_bh(&xprt->transport_lock); 477 spin_unlock_bh(&xprt->transport_lock);
478} 478}
@@ -602,11 +602,37 @@ void xprt_force_disconnect(struct rpc_xprt *xprt)
602 /* Try to schedule an autoclose RPC call */ 602 /* Try to schedule an autoclose RPC call */
603 if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0) 603 if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0)
604 queue_work(rpciod_workqueue, &xprt->task_cleanup); 604 queue_work(rpciod_workqueue, &xprt->task_cleanup);
605 else if (xprt->snd_task != NULL) 605 xprt_wake_pending_tasks(xprt, -ENOTCONN);
606 rpc_wake_up_task(xprt->snd_task); 606 spin_unlock_bh(&xprt->transport_lock);
607}
608
609/**
610 * xprt_conditional_disconnect - force a transport to disconnect
611 * @xprt: transport to disconnect
612 * @cookie: 'connection cookie'
613 *
614 * This attempts to break the connection if and only if 'cookie' matches
615 * the current transport 'connection cookie'. It ensures that we don't
616 * try to break the connection more than once when we need to retransmit
617 * a batch of RPC requests.
618 *
619 */
620void xprt_conditional_disconnect(struct rpc_xprt *xprt, unsigned int cookie)
621{
622 /* Don't race with the test_bit() in xprt_clear_locked() */
623 spin_lock_bh(&xprt->transport_lock);
624 if (cookie != xprt->connect_cookie)
625 goto out;
626 if (test_bit(XPRT_CLOSING, &xprt->state) || !xprt_connected(xprt))
627 goto out;
628 set_bit(XPRT_CLOSE_WAIT, &xprt->state);
629 /* Try to schedule an autoclose RPC call */
630 if (test_and_set_bit(XPRT_LOCKED, &xprt->state) == 0)
631 queue_work(rpciod_workqueue, &xprt->task_cleanup);
632 xprt_wake_pending_tasks(xprt, -ENOTCONN);
633out:
607 spin_unlock_bh(&xprt->transport_lock); 634 spin_unlock_bh(&xprt->transport_lock);
608} 635}
609EXPORT_SYMBOL_GPL(xprt_force_disconnect);
610 636
611static void 637static void
612xprt_init_autodisconnect(unsigned long data) 638xprt_init_autodisconnect(unsigned long data)
@@ -653,7 +679,7 @@ void xprt_connect(struct rpc_task *task)
653 task->tk_rqstp->rq_bytes_sent = 0; 679 task->tk_rqstp->rq_bytes_sent = 0;
654 680
655 task->tk_timeout = xprt->connect_timeout; 681 task->tk_timeout = xprt->connect_timeout;
656 rpc_sleep_on(&xprt->pending, task, xprt_connect_status, NULL); 682 rpc_sleep_on(&xprt->pending, task, xprt_connect_status);
657 xprt->stat.connect_start = jiffies; 683 xprt->stat.connect_start = jiffies;
658 xprt->ops->connect(task); 684 xprt->ops->connect(task);
659 } 685 }
@@ -749,18 +775,20 @@ EXPORT_SYMBOL_GPL(xprt_update_rtt);
749void xprt_complete_rqst(struct rpc_task *task, int copied) 775void xprt_complete_rqst(struct rpc_task *task, int copied)
750{ 776{
751 struct rpc_rqst *req = task->tk_rqstp; 777 struct rpc_rqst *req = task->tk_rqstp;
778 struct rpc_xprt *xprt = req->rq_xprt;
752 779
753 dprintk("RPC: %5u xid %08x complete (%d bytes received)\n", 780 dprintk("RPC: %5u xid %08x complete (%d bytes received)\n",
754 task->tk_pid, ntohl(req->rq_xid), copied); 781 task->tk_pid, ntohl(req->rq_xid), copied);
755 782
756 task->tk_xprt->stat.recvs++; 783 xprt->stat.recvs++;
757 task->tk_rtt = (long)jiffies - req->rq_xtime; 784 task->tk_rtt = (long)jiffies - req->rq_xtime;
758 785
759 list_del_init(&req->rq_list); 786 list_del_init(&req->rq_list);
787 req->rq_private_buf.len = copied;
760 /* Ensure all writes are done before we update req->rq_received */ 788 /* Ensure all writes are done before we update req->rq_received */
761 smp_wmb(); 789 smp_wmb();
762 req->rq_received = req->rq_private_buf.len = copied; 790 req->rq_received = copied;
763 rpc_wake_up_task(task); 791 rpc_wake_up_queued_task(&xprt->pending, task);
764} 792}
765EXPORT_SYMBOL_GPL(xprt_complete_rqst); 793EXPORT_SYMBOL_GPL(xprt_complete_rqst);
766 794
@@ -769,17 +797,17 @@ static void xprt_timer(struct rpc_task *task)
769 struct rpc_rqst *req = task->tk_rqstp; 797 struct rpc_rqst *req = task->tk_rqstp;
770 struct rpc_xprt *xprt = req->rq_xprt; 798 struct rpc_xprt *xprt = req->rq_xprt;
771 799
800 if (task->tk_status != -ETIMEDOUT)
801 return;
772 dprintk("RPC: %5u xprt_timer\n", task->tk_pid); 802 dprintk("RPC: %5u xprt_timer\n", task->tk_pid);
773 803
774 spin_lock(&xprt->transport_lock); 804 spin_lock_bh(&xprt->transport_lock);
775 if (!req->rq_received) { 805 if (!req->rq_received) {
776 if (xprt->ops->timer) 806 if (xprt->ops->timer)
777 xprt->ops->timer(task); 807 xprt->ops->timer(task);
778 task->tk_status = -ETIMEDOUT; 808 } else
779 } 809 task->tk_status = 0;
780 task->tk_timeout = 0; 810 spin_unlock_bh(&xprt->transport_lock);
781 rpc_wake_up_task(task);
782 spin_unlock(&xprt->transport_lock);
783} 811}
784 812
785/** 813/**
@@ -849,6 +877,7 @@ void xprt_transmit(struct rpc_task *task)
849 } else if (!req->rq_bytes_sent) 877 } else if (!req->rq_bytes_sent)
850 return; 878 return;
851 879
880 req->rq_connect_cookie = xprt->connect_cookie;
852 status = xprt->ops->send_request(task); 881 status = xprt->ops->send_request(task);
853 if (status == 0) { 882 if (status == 0) {
854 dprintk("RPC: %5u xmit complete\n", task->tk_pid); 883 dprintk("RPC: %5u xmit complete\n", task->tk_pid);
@@ -864,7 +893,7 @@ void xprt_transmit(struct rpc_task *task)
864 if (!xprt_connected(xprt)) 893 if (!xprt_connected(xprt))
865 task->tk_status = -ENOTCONN; 894 task->tk_status = -ENOTCONN;
866 else if (!req->rq_received) 895 else if (!req->rq_received)
867 rpc_sleep_on(&xprt->pending, task, NULL, xprt_timer); 896 rpc_sleep_on(&xprt->pending, task, xprt_timer);
868 spin_unlock_bh(&xprt->transport_lock); 897 spin_unlock_bh(&xprt->transport_lock);
869 return; 898 return;
870 } 899 }
@@ -875,7 +904,7 @@ void xprt_transmit(struct rpc_task *task)
875 */ 904 */
876 task->tk_status = status; 905 task->tk_status = status;
877 if (status == -ECONNREFUSED) 906 if (status == -ECONNREFUSED)
878 rpc_sleep_on(&xprt->sending, task, NULL, NULL); 907 rpc_sleep_on(&xprt->sending, task, NULL);
879} 908}
880 909
881static inline void do_xprt_reserve(struct rpc_task *task) 910static inline void do_xprt_reserve(struct rpc_task *task)
@@ -895,7 +924,7 @@ static inline void do_xprt_reserve(struct rpc_task *task)
895 dprintk("RPC: waiting for request slot\n"); 924 dprintk("RPC: waiting for request slot\n");
896 task->tk_status = -EAGAIN; 925 task->tk_status = -EAGAIN;
897 task->tk_timeout = 0; 926 task->tk_timeout = 0;
898 rpc_sleep_on(&xprt->backlog, task, NULL, NULL); 927 rpc_sleep_on(&xprt->backlog, task, NULL);
899} 928}
900 929
901/** 930/**
@@ -1052,6 +1081,11 @@ static void xprt_destroy(struct kref *kref)
1052 xprt->shutdown = 1; 1081 xprt->shutdown = 1;
1053 del_timer_sync(&xprt->timer); 1082 del_timer_sync(&xprt->timer);
1054 1083
1084 rpc_destroy_wait_queue(&xprt->binding);
1085 rpc_destroy_wait_queue(&xprt->pending);
1086 rpc_destroy_wait_queue(&xprt->sending);
1087 rpc_destroy_wait_queue(&xprt->resend);
1088 rpc_destroy_wait_queue(&xprt->backlog);
1055 /* 1089 /*
1056 * Tear down transport state and free the rpc_xprt 1090 * Tear down transport state and free the rpc_xprt
1057 */ 1091 */
diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
index 16fd3f6718ff..af408fc12634 100644
--- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
+++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
@@ -1036,6 +1036,8 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
1036 wait_event(xprt->sc_send_wait, 1036 wait_event(xprt->sc_send_wait,
1037 atomic_read(&xprt->sc_sq_count) < 1037 atomic_read(&xprt->sc_sq_count) <
1038 xprt->sc_sq_depth); 1038 xprt->sc_sq_depth);
1039 if (test_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags))
1040 return 0;
1039 continue; 1041 continue;
1040 } 1042 }
1041 /* Bumped used SQ WR count and post */ 1043 /* Bumped used SQ WR count and post */
diff --git a/net/sunrpc/xprtsock.c b/net/sunrpc/xprtsock.c
index 613daf8c1ff7..ddbe981ab516 100644
--- a/net/sunrpc/xprtsock.c
+++ b/net/sunrpc/xprtsock.c
@@ -136,12 +136,6 @@ static ctl_table sunrpc_table[] = {
136#endif 136#endif
137 137
138/* 138/*
139 * How many times to try sending a request on a socket before waiting
140 * for the socket buffer to clear.
141 */
142#define XS_SENDMSG_RETRY (10U)
143
144/*
145 * Time out for an RPC UDP socket connect. UDP socket connects are 139 * Time out for an RPC UDP socket connect. UDP socket connects are
146 * synchronous, but we set a timeout anyway in case of resource 140 * synchronous, but we set a timeout anyway in case of resource
147 * exhaustion on the local host. 141 * exhaustion on the local host.
@@ -516,6 +510,14 @@ out:
516 return sent; 510 return sent;
517} 511}
518 512
513static void xs_nospace_callback(struct rpc_task *task)
514{
515 struct sock_xprt *transport = container_of(task->tk_rqstp->rq_xprt, struct sock_xprt, xprt);
516
517 transport->inet->sk_write_pending--;
518 clear_bit(SOCK_ASYNC_NOSPACE, &transport->sock->flags);
519}
520
519/** 521/**
520 * xs_nospace - place task on wait queue if transmit was incomplete 522 * xs_nospace - place task on wait queue if transmit was incomplete
521 * @task: task to put to sleep 523 * @task: task to put to sleep
@@ -531,20 +533,27 @@ static void xs_nospace(struct rpc_task *task)
531 task->tk_pid, req->rq_slen - req->rq_bytes_sent, 533 task->tk_pid, req->rq_slen - req->rq_bytes_sent,
532 req->rq_slen); 534 req->rq_slen);
533 535
534 if (test_bit(SOCK_ASYNC_NOSPACE, &transport->sock->flags)) { 536 /* Protect against races with write_space */
535 /* Protect against races with write_space */ 537 spin_lock_bh(&xprt->transport_lock);
536 spin_lock_bh(&xprt->transport_lock); 538
537 539 /* Don't race with disconnect */
538 /* Don't race with disconnect */ 540 if (xprt_connected(xprt)) {
539 if (!xprt_connected(xprt)) 541 if (test_bit(SOCK_ASYNC_NOSPACE, &transport->sock->flags)) {
540 task->tk_status = -ENOTCONN; 542 /*
541 else if (test_bit(SOCK_NOSPACE, &transport->sock->flags)) 543 * Notify TCP that we're limited by the application
542 xprt_wait_for_buffer_space(task); 544 * window size
545 */
546 set_bit(SOCK_NOSPACE, &transport->sock->flags);
547 transport->inet->sk_write_pending++;
548 /* ...and wait for more buffer space */
549 xprt_wait_for_buffer_space(task, xs_nospace_callback);
550 }
551 } else {
552 clear_bit(SOCK_ASYNC_NOSPACE, &transport->sock->flags);
553 task->tk_status = -ENOTCONN;
554 }
543 555
544 spin_unlock_bh(&xprt->transport_lock); 556 spin_unlock_bh(&xprt->transport_lock);
545 } else
546 /* Keep holding the socket if it is blocked */
547 rpc_delay(task, HZ>>4);
548} 557}
549 558
550/** 559/**
@@ -588,19 +597,20 @@ static int xs_udp_send_request(struct rpc_task *task)
588 } 597 }
589 598
590 switch (status) { 599 switch (status) {
600 case -EAGAIN:
601 xs_nospace(task);
602 break;
591 case -ENETUNREACH: 603 case -ENETUNREACH:
592 case -EPIPE: 604 case -EPIPE:
593 case -ECONNREFUSED: 605 case -ECONNREFUSED:
594 /* When the server has died, an ICMP port unreachable message 606 /* When the server has died, an ICMP port unreachable message
595 * prompts ECONNREFUSED. */ 607 * prompts ECONNREFUSED. */
596 break; 608 clear_bit(SOCK_ASYNC_NOSPACE, &transport->sock->flags);
597 case -EAGAIN:
598 xs_nospace(task);
599 break; 609 break;
600 default: 610 default:
611 clear_bit(SOCK_ASYNC_NOSPACE, &transport->sock->flags);
601 dprintk("RPC: sendmsg returned unrecognized error %d\n", 612 dprintk("RPC: sendmsg returned unrecognized error %d\n",
602 -status); 613 -status);
603 break;
604 } 614 }
605 615
606 return status; 616 return status;
@@ -650,7 +660,6 @@ static int xs_tcp_send_request(struct rpc_task *task)
650 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt); 660 struct sock_xprt *transport = container_of(xprt, struct sock_xprt, xprt);
651 struct xdr_buf *xdr = &req->rq_snd_buf; 661 struct xdr_buf *xdr = &req->rq_snd_buf;
652 int status; 662 int status;
653 unsigned int retry = 0;
654 663
655 xs_encode_tcp_record_marker(&req->rq_snd_buf); 664 xs_encode_tcp_record_marker(&req->rq_snd_buf);
656 665
@@ -681,9 +690,10 @@ static int xs_tcp_send_request(struct rpc_task *task)
681 return 0; 690 return 0;
682 } 691 }
683 692
693 if (status != 0)
694 continue;
684 status = -EAGAIN; 695 status = -EAGAIN;
685 if (retry++ > XS_SENDMSG_RETRY) 696 break;
686 break;
687 } 697 }
688 698
689 switch (status) { 699 switch (status) {
@@ -695,12 +705,13 @@ static int xs_tcp_send_request(struct rpc_task *task)
695 case -ENOTCONN: 705 case -ENOTCONN:
696 case -EPIPE: 706 case -EPIPE:
697 status = -ENOTCONN; 707 status = -ENOTCONN;
708 clear_bit(SOCK_ASYNC_NOSPACE, &transport->sock->flags);
698 break; 709 break;
699 default: 710 default:
700 dprintk("RPC: sendmsg returned unrecognized error %d\n", 711 dprintk("RPC: sendmsg returned unrecognized error %d\n",
701 -status); 712 -status);
713 clear_bit(SOCK_ASYNC_NOSPACE, &transport->sock->flags);
702 xs_tcp_shutdown(xprt); 714 xs_tcp_shutdown(xprt);
703 break;
704 } 715 }
705 716
706 return status; 717 return status;
@@ -1073,6 +1084,7 @@ static void xs_tcp_data_ready(struct sock *sk, int bytes)
1073{ 1084{
1074 struct rpc_xprt *xprt; 1085 struct rpc_xprt *xprt;
1075 read_descriptor_t rd_desc; 1086 read_descriptor_t rd_desc;
1087 int read;
1076 1088
1077 dprintk("RPC: xs_tcp_data_ready...\n"); 1089 dprintk("RPC: xs_tcp_data_ready...\n");
1078 1090
@@ -1084,8 +1096,10 @@ static void xs_tcp_data_ready(struct sock *sk, int bytes)
1084 1096
1085 /* We use rd_desc to pass struct xprt to xs_tcp_data_recv */ 1097 /* We use rd_desc to pass struct xprt to xs_tcp_data_recv */
1086 rd_desc.arg.data = xprt; 1098 rd_desc.arg.data = xprt;
1087 rd_desc.count = 65536; 1099 do {
1088 tcp_read_sock(sk, &rd_desc, xs_tcp_data_recv); 1100 rd_desc.count = 65536;
1101 read = tcp_read_sock(sk, &rd_desc, xs_tcp_data_recv);
1102 } while (read > 0);
1089out: 1103out:
1090 read_unlock(&sk->sk_callback_lock); 1104 read_unlock(&sk->sk_callback_lock);
1091} 1105}
@@ -1128,6 +1142,7 @@ static void xs_tcp_state_change(struct sock *sk)
1128 break; 1142 break;
1129 case TCP_FIN_WAIT1: 1143 case TCP_FIN_WAIT1:
1130 /* The client initiated a shutdown of the socket */ 1144 /* The client initiated a shutdown of the socket */
1145 xprt->connect_cookie++;
1131 xprt->reestablish_timeout = 0; 1146 xprt->reestablish_timeout = 0;
1132 set_bit(XPRT_CLOSING, &xprt->state); 1147 set_bit(XPRT_CLOSING, &xprt->state);
1133 smp_mb__before_clear_bit(); 1148 smp_mb__before_clear_bit();
@@ -1140,6 +1155,7 @@ static void xs_tcp_state_change(struct sock *sk)
1140 set_bit(XPRT_CLOSING, &xprt->state); 1155 set_bit(XPRT_CLOSING, &xprt->state);
1141 xprt_force_disconnect(xprt); 1156 xprt_force_disconnect(xprt);
1142 case TCP_SYN_SENT: 1157 case TCP_SYN_SENT:
1158 xprt->connect_cookie++;
1143 case TCP_CLOSING: 1159 case TCP_CLOSING:
1144 /* 1160 /*
1145 * If the server closed down the connection, make sure that 1161 * If the server closed down the connection, make sure that
@@ -1186,9 +1202,11 @@ static void xs_udp_write_space(struct sock *sk)
1186 1202
1187 if (unlikely(!(sock = sk->sk_socket))) 1203 if (unlikely(!(sock = sk->sk_socket)))
1188 goto out; 1204 goto out;
1205 clear_bit(SOCK_NOSPACE, &sock->flags);
1206
1189 if (unlikely(!(xprt = xprt_from_sock(sk)))) 1207 if (unlikely(!(xprt = xprt_from_sock(sk))))
1190 goto out; 1208 goto out;
1191 if (unlikely(!test_and_clear_bit(SOCK_NOSPACE, &sock->flags))) 1209 if (test_and_clear_bit(SOCK_ASYNC_NOSPACE, &sock->flags) == 0)
1192 goto out; 1210 goto out;
1193 1211
1194 xprt_write_space(xprt); 1212 xprt_write_space(xprt);
@@ -1219,9 +1237,11 @@ static void xs_tcp_write_space(struct sock *sk)
1219 1237
1220 if (unlikely(!(sock = sk->sk_socket))) 1238 if (unlikely(!(sock = sk->sk_socket)))
1221 goto out; 1239 goto out;
1240 clear_bit(SOCK_NOSPACE, &sock->flags);
1241
1222 if (unlikely(!(xprt = xprt_from_sock(sk)))) 1242 if (unlikely(!(xprt = xprt_from_sock(sk))))
1223 goto out; 1243 goto out;
1224 if (unlikely(!test_and_clear_bit(SOCK_NOSPACE, &sock->flags))) 1244 if (test_and_clear_bit(SOCK_ASYNC_NOSPACE, &sock->flags) == 0)
1225 goto out; 1245 goto out;
1226 1246
1227 xprt_write_space(xprt); 1247 xprt_write_space(xprt);
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index 1454afcc06c4..e18cd3628db4 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -2197,7 +2197,11 @@ static void __exit af_unix_exit(void)
2197 unregister_pernet_subsys(&unix_net_ops); 2197 unregister_pernet_subsys(&unix_net_ops);
2198} 2198}
2199 2199
2200module_init(af_unix_init); 2200/* Earlier than device_initcall() so that other drivers invoking
2201 request_module() don't end up in a loop when modprobe tries
2202 to use a UNIX socket. But later than subsys_initcall() because
2203 we depend on stuff initialised there */
2204fs_initcall(af_unix_init);
2201module_exit(af_unix_exit); 2205module_exit(af_unix_exit);
2202 2206
2203MODULE_LICENSE("GPL"); 2207MODULE_LICENSE("GPL");
diff --git a/sound/arm/pxa2xx-ac97.c b/sound/arm/pxa2xx-ac97.c
index 8704e2825b10..5b3274b465eb 100644
--- a/sound/arm/pxa2xx-ac97.c
+++ b/sound/arm/pxa2xx-ac97.c
@@ -72,7 +72,7 @@ static unsigned short pxa2xx_ac97_read(struct snd_ac97 *ac97, unsigned short reg
72 if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1) <= 0 && 72 if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1) <= 0 &&
73 !((GSR | gsr_bits) & GSR_SDONE)) { 73 !((GSR | gsr_bits) & GSR_SDONE)) {
74 printk(KERN_ERR "%s: read error (ac97_reg=%d GSR=%#lx)\n", 74 printk(KERN_ERR "%s: read error (ac97_reg=%d GSR=%#lx)\n",
75 __FUNCTION__, reg, GSR | gsr_bits); 75 __func__, reg, GSR | gsr_bits);
76 val = -1; 76 val = -1;
77 goto out; 77 goto out;
78 } 78 }
@@ -104,7 +104,7 @@ static void pxa2xx_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigne
104 if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_CDONE, 1) <= 0 && 104 if (wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_CDONE, 1) <= 0 &&
105 !((GSR | gsr_bits) & GSR_CDONE)) 105 !((GSR | gsr_bits) & GSR_CDONE))
106 printk(KERN_ERR "%s: write error (ac97_reg=%d GSR=%#lx)\n", 106 printk(KERN_ERR "%s: write error (ac97_reg=%d GSR=%#lx)\n",
107 __FUNCTION__, reg, GSR | gsr_bits); 107 __func__, reg, GSR | gsr_bits);
108 108
109 mutex_unlock(&car_mutex); 109 mutex_unlock(&car_mutex);
110} 110}
@@ -112,6 +112,16 @@ static void pxa2xx_ac97_write(struct snd_ac97 *ac97, unsigned short reg, unsigne
112static void pxa2xx_ac97_reset(struct snd_ac97 *ac97) 112static void pxa2xx_ac97_reset(struct snd_ac97 *ac97)
113{ 113{
114 /* First, try cold reset */ 114 /* First, try cold reset */
115#ifdef CONFIG_PXA3xx
116 int timeout;
117
118 /* Hold CLKBPB for 100us */
119 GCR = 0;
120 GCR = GCR_CLKBPB;
121 udelay(100);
122 GCR = 0;
123#endif
124
115 GCR &= GCR_COLD_RST; /* clear everything but nCRST */ 125 GCR &= GCR_COLD_RST; /* clear everything but nCRST */
116 GCR &= ~GCR_COLD_RST; /* then assert nCRST */ 126 GCR &= ~GCR_COLD_RST; /* then assert nCRST */
117 127
@@ -123,6 +133,14 @@ static void pxa2xx_ac97_reset(struct snd_ac97 *ac97)
123 clk_disable(ac97conf_clk); 133 clk_disable(ac97conf_clk);
124 GCR = GCR_COLD_RST; 134 GCR = GCR_COLD_RST;
125 udelay(50); 135 udelay(50);
136#elif defined(CONFIG_PXA3xx)
137 timeout = 1000;
138 /* Can't use interrupts on PXA3xx */
139 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
140
141 GCR = GCR_WARM_RST | GCR_COLD_RST;
142 while (!(GSR & (GSR_PCR | GSR_SCR)) && timeout--)
143 mdelay(10);
126#else 144#else
127 GCR = GCR_COLD_RST; 145 GCR = GCR_COLD_RST;
128 GCR |= GCR_CDONE_IE|GCR_SDONE_IE; 146 GCR |= GCR_CDONE_IE|GCR_SDONE_IE;
@@ -131,7 +149,7 @@ static void pxa2xx_ac97_reset(struct snd_ac97 *ac97)
131 149
132 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR))) { 150 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR))) {
133 printk(KERN_INFO "%s: cold reset timeout (GSR=%#lx)\n", 151 printk(KERN_INFO "%s: cold reset timeout (GSR=%#lx)\n",
134 __FUNCTION__, gsr_bits); 152 __func__, gsr_bits);
135 153
136 /* let's try warm reset */ 154 /* let's try warm reset */
137 gsr_bits = 0; 155 gsr_bits = 0;
@@ -143,6 +161,12 @@ static void pxa2xx_ac97_reset(struct snd_ac97 *ac97)
143 GCR |= GCR_WARM_RST; 161 GCR |= GCR_WARM_RST;
144 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT); 162 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT);
145 udelay(500); 163 udelay(500);
164#elif defined(CONFIG_PXA3xx)
165 timeout = 100;
166 /* Can't use interrupts */
167 GCR |= GCR_WARM_RST;
168 while (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)) && timeout--)
169 mdelay(1);
146#else 170#else
147 GCR |= GCR_WARM_RST|GCR_PRIRDY_IEN|GCR_SECRDY_IEN; 171 GCR |= GCR_WARM_RST|GCR_PRIRDY_IEN|GCR_SECRDY_IEN;
148 wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1); 172 wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1);
@@ -150,7 +174,7 @@ static void pxa2xx_ac97_reset(struct snd_ac97 *ac97)
150 174
151 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR))) 175 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)))
152 printk(KERN_INFO "%s: warm reset timeout (GSR=%#lx)\n", 176 printk(KERN_INFO "%s: warm reset timeout (GSR=%#lx)\n",
153 __FUNCTION__, gsr_bits); 177 __func__, gsr_bits);
154 } 178 }
155 179
156 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN); 180 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
@@ -424,6 +448,7 @@ static struct platform_driver pxa2xx_ac97_driver = {
424 .resume = pxa2xx_ac97_resume, 448 .resume = pxa2xx_ac97_resume,
425 .driver = { 449 .driver = {
426 .name = "pxa2xx-ac97", 450 .name = "pxa2xx-ac97",
451 .owner = THIS_MODULE,
427 }, 452 },
428}; 453};
429 454
@@ -443,3 +468,4 @@ module_exit(pxa2xx_ac97_exit);
443MODULE_AUTHOR("Nicolas Pitre"); 468MODULE_AUTHOR("Nicolas Pitre");
444MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip"); 469MODULE_DESCRIPTION("AC97 driver for the Intel PXA2xx chip");
445MODULE_LICENSE("GPL"); 470MODULE_LICENSE("GPL");
471MODULE_ALIAS("platform:pxa2xx-ac97");
diff --git a/sound/core/Kconfig b/sound/core/Kconfig
index 829ca38b595e..a8d71c6c8e75 100644
--- a/sound/core/Kconfig
+++ b/sound/core/Kconfig
@@ -181,3 +181,7 @@ config SND_PCM_XRUN_DEBUG
181 It is usually not required, but if you have trouble with 181 It is usually not required, but if you have trouble with
182 sound clicking when system is loaded, it may help to determine 182 sound clicking when system is loaded, it may help to determine
183 the process or driver which causes the scheduling gaps. 183 the process or driver which causes the scheduling gaps.
184
185config SND_VMASTER
186 bool
187 depends on SND
diff --git a/sound/core/Makefile b/sound/core/Makefile
index 267039a97bd5..da8e685eef9c 100644
--- a/sound/core/Makefile
+++ b/sound/core/Makefile
@@ -6,6 +6,7 @@
6snd-y := sound.o init.o memory.o info.o control.o misc.o device.o 6snd-y := sound.o init.o memory.o info.o control.o misc.o device.o
7snd-$(CONFIG_ISA_DMA_API) += isadma.o 7snd-$(CONFIG_ISA_DMA_API) += isadma.o
8snd-$(CONFIG_SND_OSSEMUL) += sound_oss.o info_oss.o 8snd-$(CONFIG_SND_OSSEMUL) += sound_oss.o info_oss.o
9snd-$(CONFIG_SND_VMASTER) += vmaster.o
9 10
10snd-pcm-objs := pcm.o pcm_native.o pcm_lib.o pcm_timer.o pcm_misc.o \ 11snd-pcm-objs := pcm.o pcm_native.o pcm_lib.o pcm_timer.o pcm_misc.o \
11 pcm_memory.o 12 pcm_memory.o
diff --git a/sound/core/init.c b/sound/core/init.c
index e3338d6071ef..ac0573416130 100644
--- a/sound/core/init.c
+++ b/sound/core/init.c
@@ -254,7 +254,7 @@ static int snd_disconnect_release(struct inode *inode, struct file *file)
254 if (likely(df)) 254 if (likely(df))
255 return df->disconnected_f_op->release(inode, file); 255 return df->disconnected_f_op->release(inode, file);
256 256
257 panic("%s(%p, %p) failed!", __FUNCTION__, inode, file); 257 panic("%s(%p, %p) failed!", __func__, inode, file);
258} 258}
259 259
260static unsigned int snd_disconnect_poll(struct file * file, poll_table * wait) 260static unsigned int snd_disconnect_poll(struct file * file, poll_table * wait)
@@ -311,6 +311,9 @@ int snd_card_disconnect(struct snd_card *card)
311 struct file *file; 311 struct file *file;
312 int err; 312 int err;
313 313
314 if (!card)
315 return -EINVAL;
316
314 spin_lock(&card->files_lock); 317 spin_lock(&card->files_lock);
315 if (card->shutdown) { 318 if (card->shutdown) {
316 spin_unlock(&card->files_lock); 319 spin_unlock(&card->files_lock);
@@ -322,6 +325,7 @@ int snd_card_disconnect(struct snd_card *card)
322 /* phase 1: disable fops (user space) operations for ALSA API */ 325 /* phase 1: disable fops (user space) operations for ALSA API */
323 mutex_lock(&snd_card_mutex); 326 mutex_lock(&snd_card_mutex);
324 snd_cards[card->number] = NULL; 327 snd_cards[card->number] = NULL;
328 snd_cards_lock &= ~(1 << card->number);
325 mutex_unlock(&snd_card_mutex); 329 mutex_unlock(&snd_card_mutex);
326 330
327 /* phase 2: replace file->f_op with special dummy operations */ 331 /* phase 2: replace file->f_op with special dummy operations */
@@ -360,6 +364,15 @@ int snd_card_disconnect(struct snd_card *card)
360 snd_printk(KERN_ERR "not all devices for card %i can be disconnected\n", card->number); 364 snd_printk(KERN_ERR "not all devices for card %i can be disconnected\n", card->number);
361 365
362 snd_info_card_disconnect(card); 366 snd_info_card_disconnect(card);
367#ifndef CONFIG_SYSFS_DEPRECATED
368 if (card->card_dev) {
369 device_unregister(card->card_dev);
370 card->card_dev = NULL;
371 }
372#endif
373#ifdef CONFIG_PM
374 wake_up(&card->power_sleep);
375#endif
363 return 0; 376 return 0;
364} 377}
365 378
@@ -401,33 +414,14 @@ static int snd_card_do_free(struct snd_card *card)
401 snd_printk(KERN_WARNING "unable to free card info\n"); 414 snd_printk(KERN_WARNING "unable to free card info\n");
402 /* Not fatal error */ 415 /* Not fatal error */
403 } 416 }
404#ifndef CONFIG_SYSFS_DEPRECATED
405 if (card->card_dev)
406 device_unregister(card->card_dev);
407#endif
408 kfree(card); 417 kfree(card);
409 return 0; 418 return 0;
410} 419}
411 420
412static int snd_card_free_prepare(struct snd_card *card)
413{
414 if (card == NULL)
415 return -EINVAL;
416 (void) snd_card_disconnect(card);
417 mutex_lock(&snd_card_mutex);
418 snd_cards[card->number] = NULL;
419 snd_cards_lock &= ~(1 << card->number);
420 mutex_unlock(&snd_card_mutex);
421#ifdef CONFIG_PM
422 wake_up(&card->power_sleep);
423#endif
424 return 0;
425}
426
427int snd_card_free_when_closed(struct snd_card *card) 421int snd_card_free_when_closed(struct snd_card *card)
428{ 422{
429 int free_now = 0; 423 int free_now = 0;
430 int ret = snd_card_free_prepare(card); 424 int ret = snd_card_disconnect(card);
431 if (ret) 425 if (ret)
432 return ret; 426 return ret;
433 427
@@ -447,7 +441,7 @@ EXPORT_SYMBOL(snd_card_free_when_closed);
447 441
448int snd_card_free(struct snd_card *card) 442int snd_card_free(struct snd_card *card)
449{ 443{
450 int ret = snd_card_free_prepare(card); 444 int ret = snd_card_disconnect(card);
451 if (ret) 445 if (ret)
452 return ret; 446 return ret;
453 447
diff --git a/sound/core/misc.c b/sound/core/misc.c
index 102d1c36cf26..38524f615d94 100644
--- a/sound/core/misc.c
+++ b/sound/core/misc.c
@@ -39,7 +39,7 @@ void snd_verbose_printk(const char *file, int line, const char *format, ...)
39{ 39{
40 va_list args; 40 va_list args;
41 41
42 if (format[0] == '<' && format[1] >= '0' && format[1] <= '9' && format[2] == '>') { 42 if (format[0] == '<' && format[1] >= '0' && format[1] <= '7' && format[2] == '>') {
43 char tmp[] = "<0>"; 43 char tmp[] = "<0>";
44 tmp[1] = format[1]; 44 tmp[1] = format[1];
45 printk("%sALSA %s:%d: ", tmp, file, line); 45 printk("%sALSA %s:%d: ", tmp, file, line);
@@ -60,7 +60,7 @@ void snd_verbose_printd(const char *file, int line, const char *format, ...)
60{ 60{
61 va_list args; 61 va_list args;
62 62
63 if (format[0] == '<' && format[1] >= '0' && format[1] <= '9' && format[2] == '>') { 63 if (format[0] == '<' && format[1] >= '0' && format[1] <= '7' && format[2] == '>') {
64 char tmp[] = "<0>"; 64 char tmp[] = "<0>";
65 tmp[1] = format[1]; 65 tmp[1] = format[1];
66 printk("%sALSA %s:%d: ", tmp, file, line); 66 printk("%sALSA %s:%d: ", tmp, file, line);
diff --git a/sound/core/oss/mixer_oss.c b/sound/core/oss/mixer_oss.c
index 75daed298a15..581aa2c60e65 100644
--- a/sound/core/oss/mixer_oss.c
+++ b/sound/core/oss/mixer_oss.c
@@ -1257,6 +1257,8 @@ static void snd_mixer_oss_build(struct snd_mixer_oss *mixer)
1257 { SOUND_MIXER_DIGITAL3, "Digital", 2 }, 1257 { SOUND_MIXER_DIGITAL3, "Digital", 2 },
1258 { SOUND_MIXER_PHONEIN, "Phone", 0 }, 1258 { SOUND_MIXER_PHONEIN, "Phone", 0 },
1259 { SOUND_MIXER_PHONEOUT, "Master Mono", 0 }, 1259 { SOUND_MIXER_PHONEOUT, "Master Mono", 0 },
1260 { SOUND_MIXER_PHONEOUT, "Speaker", 0 }, /*fallback*/
1261 { SOUND_MIXER_PHONEOUT, "Mono", 0 }, /*fallback*/
1260 { SOUND_MIXER_PHONEOUT, "Phone", 0 }, /* fallback */ 1262 { SOUND_MIXER_PHONEOUT, "Phone", 0 }, /* fallback */
1261 { SOUND_MIXER_VIDEO, "Video", 0 }, 1263 { SOUND_MIXER_VIDEO, "Video", 0 },
1262 { SOUND_MIXER_RADIO, "Radio", 0 }, 1264 { SOUND_MIXER_RADIO, "Radio", 0 },
diff --git a/sound/core/seq/oss/seq_oss_synth.c b/sound/core/seq/oss/seq_oss_synth.c
index ab570a0a6183..558dadbf45f1 100644
--- a/sound/core/seq/oss/seq_oss_synth.c
+++ b/sound/core/seq/oss/seq_oss_synth.c
@@ -245,8 +245,13 @@ snd_seq_oss_synth_setup(struct seq_oss_devinfo *dp)
245 info->nr_voices = rec->nr_voices; 245 info->nr_voices = rec->nr_voices;
246 if (info->nr_voices > 0) { 246 if (info->nr_voices > 0) {
247 info->ch = kcalloc(info->nr_voices, sizeof(struct seq_oss_chinfo), GFP_KERNEL); 247 info->ch = kcalloc(info->nr_voices, sizeof(struct seq_oss_chinfo), GFP_KERNEL);
248 if (!info->ch) 248 if (!info->ch) {
249 BUG(); 249 snd_printk(KERN_ERR "Cannot malloc\n");
250 rec->oper.close(&info->arg);
251 module_put(rec->oper.owner);
252 snd_use_lock_free(&rec->use_lock);
253 continue;
254 }
250 reset_channels(info); 255 reset_channels(info);
251 } 256 }
252 debug_printk(("synth %d assigned\n", i)); 257 debug_printk(("synth %d assigned\n", i));
diff --git a/sound/pci/hda/vmaster.c b/sound/core/vmaster.c
index 2da49d20a1fc..4cc57f902e2c 100644
--- a/sound/pci/hda/vmaster.c
+++ b/sound/core/vmaster.c
@@ -12,6 +12,7 @@
12#include <linux/slab.h> 12#include <linux/slab.h>
13#include <sound/core.h> 13#include <sound/core.h>
14#include <sound/control.h> 14#include <sound/control.h>
15#include <sound/tlv.h>
15 16
16/* 17/*
17 * a subset of information returned via ctl info callback 18 * a subset of information returned via ctl info callback
@@ -34,6 +35,7 @@ struct link_master {
34 struct list_head slaves; 35 struct list_head slaves;
35 struct link_ctl_info info; 36 struct link_ctl_info info;
36 int val; /* the master value */ 37 int val; /* the master value */
38 unsigned int tlv[4];
37}; 39};
38 40
39/* 41/*
@@ -253,6 +255,8 @@ int snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave)
253 return 0; 255 return 0;
254} 256}
255 257
258EXPORT_SYMBOL(snd_ctl_add_slave);
259
256/* 260/*
257 * ctl callbacks for master controls 261 * ctl callbacks for master controls
258 */ 262 */
@@ -355,10 +359,13 @@ struct snd_kcontrol *snd_ctl_make_virtual_master(char *name,
355 kctl->private_free = master_free; 359 kctl->private_free = master_free;
356 360
357 /* additional (constant) TLV read */ 361 /* additional (constant) TLV read */
358 if (tlv) { 362 if (tlv && tlv[0] == SNDRV_CTL_TLVT_DB_SCALE) {
359 /* FIXME: this assumes that the max volume is 0 dB */
360 kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ; 363 kctl->vd[0].access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
361 kctl->tlv.p = tlv; 364 memcpy(master->tlv, tlv, sizeof(master->tlv));
365 kctl->tlv.p = master->tlv;
362 } 366 }
367
363 return kctl; 368 return kctl;
364} 369}
370
371EXPORT_SYMBOL(snd_ctl_make_virtual_master);
diff --git a/sound/drivers/Kconfig b/sound/drivers/Kconfig
index 75d4fe09fdf3..fe85af1c5693 100644
--- a/sound/drivers/Kconfig
+++ b/sound/drivers/Kconfig
@@ -4,6 +4,24 @@ menu "Generic devices"
4 depends on SND!=n 4 depends on SND!=n
5 5
6 6
7config SND_PCSP
8 tristate "Internal PC speaker support"
9 depends on X86_PC && HIGH_RES_TIMERS
10 depends on INPUT
11 help
12 If you don't have a sound card in your computer, you can include a
13 driver for the PC speaker which allows it to act like a primitive
14 sound card.
15 This driver also replaces the pcspkr driver for beeps.
16
17 You can compile this as a module which will be called snd-pcsp.
18
19 You don't need this driver if you only want your pc-speaker to beep.
20 You don't need this driver if you have a tablet piezo beeper
21 in your PC instead of the real speaker.
22
23 It should not hurt to say Y or M here in all other cases.
24
7config SND_MPU401_UART 25config SND_MPU401_UART
8 tristate 26 tristate
9 select SND_RAWMIDI 27 select SND_RAWMIDI
diff --git a/sound/drivers/Makefile b/sound/drivers/Makefile
index 8e5530006e1f..d4a07f9ff2c7 100644
--- a/sound/drivers/Makefile
+++ b/sound/drivers/Makefile
@@ -20,4 +20,4 @@ obj-$(CONFIG_SND_MTS64) += snd-mts64.o
20obj-$(CONFIG_SND_PORTMAN2X4) += snd-portman2x4.o 20obj-$(CONFIG_SND_PORTMAN2X4) += snd-portman2x4.o
21obj-$(CONFIG_SND_ML403_AC97CR) += snd-ml403-ac97cr.o 21obj-$(CONFIG_SND_ML403_AC97CR) += snd-ml403-ac97cr.o
22 22
23obj-$(CONFIG_SND) += opl3/ opl4/ mpu401/ vx/ 23obj-$(CONFIG_SND) += opl3/ opl4/ mpu401/ vx/ pcsp/
diff --git a/sound/drivers/dummy.c b/sound/drivers/dummy.c
index a240eaeb5c62..4e4c69e6cb4c 100644
--- a/sound/drivers/dummy.c
+++ b/sound/drivers/dummy.c
@@ -181,10 +181,10 @@ struct snd_dummy_pcm {
181 struct snd_dummy *dummy; 181 struct snd_dummy *dummy;
182 spinlock_t lock; 182 spinlock_t lock;
183 struct timer_list timer; 183 struct timer_list timer;
184 unsigned int pcm_size; 184 unsigned int pcm_buffer_size;
185 unsigned int pcm_count; 185 unsigned int pcm_period_size;
186 unsigned int pcm_bps; /* bytes per second */ 186 unsigned int pcm_bps; /* bytes per second */
187 unsigned int pcm_jiffie; /* bytes per one jiffie */ 187 unsigned int pcm_hz; /* HZ */
188 unsigned int pcm_irq_pos; /* IRQ position */ 188 unsigned int pcm_irq_pos; /* IRQ position */
189 unsigned int pcm_buf_pos; /* position in buffer */ 189 unsigned int pcm_buf_pos; /* position in buffer */
190 struct snd_pcm_substream *substream; 190 struct snd_pcm_substream *substream;
@@ -230,19 +230,24 @@ static int snd_card_dummy_pcm_prepare(struct snd_pcm_substream *substream)
230{ 230{
231 struct snd_pcm_runtime *runtime = substream->runtime; 231 struct snd_pcm_runtime *runtime = substream->runtime;
232 struct snd_dummy_pcm *dpcm = runtime->private_data; 232 struct snd_dummy_pcm *dpcm = runtime->private_data;
233 unsigned int bps; 233 int bps;
234
235 bps = snd_pcm_format_width(runtime->format) * runtime->rate *
236 runtime->channels / 8;
234 237
235 bps = runtime->rate * runtime->channels;
236 bps *= snd_pcm_format_width(runtime->format);
237 bps /= 8;
238 if (bps <= 0) 238 if (bps <= 0)
239 return -EINVAL; 239 return -EINVAL;
240
240 dpcm->pcm_bps = bps; 241 dpcm->pcm_bps = bps;
241 dpcm->pcm_jiffie = bps / HZ; 242 dpcm->pcm_hz = HZ;
242 dpcm->pcm_size = snd_pcm_lib_buffer_bytes(substream); 243 dpcm->pcm_buffer_size = snd_pcm_lib_buffer_bytes(substream);
243 dpcm->pcm_count = snd_pcm_lib_period_bytes(substream); 244 dpcm->pcm_period_size = snd_pcm_lib_period_bytes(substream);
244 dpcm->pcm_irq_pos = 0; 245 dpcm->pcm_irq_pos = 0;
245 dpcm->pcm_buf_pos = 0; 246 dpcm->pcm_buf_pos = 0;
247
248 snd_pcm_format_set_silence(runtime->format, runtime->dma_area,
249 bytes_to_samples(runtime, runtime->dma_bytes));
250
246 return 0; 251 return 0;
247} 252}
248 253
@@ -254,11 +259,11 @@ static void snd_card_dummy_pcm_timer_function(unsigned long data)
254 spin_lock_irqsave(&dpcm->lock, flags); 259 spin_lock_irqsave(&dpcm->lock, flags);
255 dpcm->timer.expires = 1 + jiffies; 260 dpcm->timer.expires = 1 + jiffies;
256 add_timer(&dpcm->timer); 261 add_timer(&dpcm->timer);
257 dpcm->pcm_irq_pos += dpcm->pcm_jiffie; 262 dpcm->pcm_irq_pos += dpcm->pcm_bps;
258 dpcm->pcm_buf_pos += dpcm->pcm_jiffie; 263 dpcm->pcm_buf_pos += dpcm->pcm_bps;
259 dpcm->pcm_buf_pos %= dpcm->pcm_size; 264 dpcm->pcm_buf_pos %= dpcm->pcm_buffer_size * dpcm->pcm_hz;
260 if (dpcm->pcm_irq_pos >= dpcm->pcm_count) { 265 if (dpcm->pcm_irq_pos >= dpcm->pcm_period_size * dpcm->pcm_hz) {
261 dpcm->pcm_irq_pos %= dpcm->pcm_count; 266 dpcm->pcm_irq_pos %= dpcm->pcm_period_size * dpcm->pcm_hz;
262 spin_unlock_irqrestore(&dpcm->lock, flags); 267 spin_unlock_irqrestore(&dpcm->lock, flags);
263 snd_pcm_period_elapsed(dpcm->substream); 268 snd_pcm_period_elapsed(dpcm->substream);
264 } else 269 } else
@@ -270,7 +275,7 @@ static snd_pcm_uframes_t snd_card_dummy_pcm_pointer(struct snd_pcm_substream *su
270 struct snd_pcm_runtime *runtime = substream->runtime; 275 struct snd_pcm_runtime *runtime = substream->runtime;
271 struct snd_dummy_pcm *dpcm = runtime->private_data; 276 struct snd_dummy_pcm *dpcm = runtime->private_data;
272 277
273 return bytes_to_frames(runtime, dpcm->pcm_buf_pos); 278 return bytes_to_frames(runtime, dpcm->pcm_buf_pos / dpcm->pcm_hz);
274} 279}
275 280
276static struct snd_pcm_hardware snd_card_dummy_playback = 281static struct snd_pcm_hardware snd_card_dummy_playback =
diff --git a/sound/drivers/ml403-ac97cr.c b/sound/drivers/ml403-ac97cr.c
index 05a871aa7b81..ecdbeb6d3603 100644
--- a/sound/drivers/ml403-ac97cr.c
+++ b/sound/drivers/ml403-ac97cr.c
@@ -1191,8 +1191,6 @@ snd_ml403_ac97cr_create(struct snd_card *card, struct platform_device *pfdev,
1191 return err; 1191 return err;
1192 } 1192 }
1193 1193
1194 snd_card_set_dev(card, &pfdev->dev);
1195
1196 *rml403_ac97cr = ml403_ac97cr; 1194 *rml403_ac97cr = ml403_ac97cr;
1197 return 0; 1195 return 0;
1198} 1196}
@@ -1330,11 +1328,15 @@ static int snd_ml403_ac97cr_remove(struct platform_device *pfdev)
1330 return 0; 1328 return 0;
1331} 1329}
1332 1330
1331/* work with hotplug and coldplug */
1332MODULE_ALIAS("platform:" SND_ML403_AC97CR_DRIVER);
1333
1333static struct platform_driver snd_ml403_ac97cr_driver = { 1334static struct platform_driver snd_ml403_ac97cr_driver = {
1334 .probe = snd_ml403_ac97cr_probe, 1335 .probe = snd_ml403_ac97cr_probe,
1335 .remove = snd_ml403_ac97cr_remove, 1336 .remove = snd_ml403_ac97cr_remove,
1336 .driver = { 1337 .driver = {
1337 .name = SND_ML403_AC97CR_DRIVER, 1338 .name = SND_ML403_AC97CR_DRIVER,
1339 .owner = THIS_MODULE,
1338 }, 1340 },
1339}; 1341};
1340 1342
diff --git a/sound/drivers/mpu401/mpu401_uart.c b/sound/drivers/mpu401/mpu401_uart.c
index 5993864acbd3..18cca2457d44 100644
--- a/sound/drivers/mpu401/mpu401_uart.c
+++ b/sound/drivers/mpu401/mpu401_uart.c
@@ -49,12 +49,10 @@ static void snd_mpu401_uart_output_write(struct snd_mpu401 * mpu);
49 49
50 */ 50 */
51 51
52#define snd_mpu401_input_avail(mpu) (!(mpu->read(mpu, MPU401C(mpu)) & 0x80)) 52#define snd_mpu401_input_avail(mpu) \
53#define snd_mpu401_output_ready(mpu) (!(mpu->read(mpu, MPU401C(mpu)) & 0x40)) 53 (!(mpu->read(mpu, MPU401C(mpu)) & MPU401_RX_EMPTY))
54 54#define snd_mpu401_output_ready(mpu) \
55#define MPU401_RESET 0xff 55 (!(mpu->read(mpu, MPU401C(mpu)) & MPU401_TX_FULL))
56#define MPU401_ENTER_UART 0x3f
57#define MPU401_ACK 0xfe
58 56
59/* Build in lowlevel io */ 57/* Build in lowlevel io */
60static void mpu401_write_port(struct snd_mpu401 *mpu, unsigned char data, 58static void mpu401_write_port(struct snd_mpu401 *mpu, unsigned char data,
@@ -425,16 +423,17 @@ static void snd_mpu401_uart_input_read(struct snd_mpu401 * mpu)
425static void snd_mpu401_uart_output_write(struct snd_mpu401 * mpu) 423static void snd_mpu401_uart_output_write(struct snd_mpu401 * mpu)
426{ 424{
427 unsigned char byte; 425 unsigned char byte;
428 int max = 256, timeout; 426 int max = 256;
429 427
430 do { 428 do {
431 if (snd_rawmidi_transmit_peek(mpu->substream_output, 429 if (snd_rawmidi_transmit_peek(mpu->substream_output,
432 &byte, 1) == 1) { 430 &byte, 1) == 1) {
433 for (timeout = 100; timeout > 0; timeout--) { 431 /*
434 if (snd_mpu401_output_ready(mpu)) 432 * Try twice because there is hardware that insists on
435 break; 433 * setting the output busy bit after each write.
436 } 434 */
437 if (timeout == 0) 435 if (!snd_mpu401_output_ready(mpu) &&
436 !snd_mpu401_output_ready(mpu))
438 break; /* Tx FIFO full - try again later */ 437 break; /* Tx FIFO full - try again later */
439 mpu->write(mpu, byte, MPU401D(mpu)); 438 mpu->write(mpu, byte, MPU401D(mpu));
440 snd_rawmidi_transmit_ack(mpu->substream_output, 1); 439 snd_rawmidi_transmit_ack(mpu->substream_output, 1);
diff --git a/sound/drivers/pcsp/Makefile b/sound/drivers/pcsp/Makefile
new file mode 100644
index 000000000000..b19555b440da
--- /dev/null
+++ b/sound/drivers/pcsp/Makefile
@@ -0,0 +1,2 @@
1snd-pcsp-objs := pcsp.o pcsp_lib.o pcsp_mixer.o pcsp_input.o
2obj-$(CONFIG_SND_PCSP) += snd-pcsp.o
diff --git a/sound/drivers/pcsp/pcsp.c b/sound/drivers/pcsp/pcsp.c
new file mode 100644
index 000000000000..59203511e77d
--- /dev/null
+++ b/sound/drivers/pcsp/pcsp.c
@@ -0,0 +1,235 @@
1/*
2 * PC-Speaker driver for Linux
3 *
4 * Copyright (C) 1997-2001 David Woodhouse
5 * Copyright (C) 2001-2008 Stas Sergeev
6 */
7
8#include <linux/init.h>
9#include <linux/moduleparam.h>
10#include <linux/platform_device.h>
11#include <sound/core.h>
12#include <sound/initval.h>
13#include <sound/pcm.h>
14#include <linux/input.h>
15#include <linux/delay.h>
16#include <asm/bitops.h>
17#include "pcsp_input.h"
18#include "pcsp.h"
19
20MODULE_AUTHOR("Stas Sergeev <stsp@users.sourceforge.net>");
21MODULE_DESCRIPTION("PC-Speaker driver");
22MODULE_LICENSE("GPL");
23MODULE_SUPPORTED_DEVICE("{{PC-Speaker, pcsp}}");
24MODULE_ALIAS("platform:pcspkr");
25
26static int index = SNDRV_DEFAULT_IDX1; /* Index 0-MAX */
27static char *id = SNDRV_DEFAULT_STR1; /* ID for this card */
28static int enable = SNDRV_DEFAULT_ENABLE1; /* Enable this card */
29
30module_param(index, int, 0444);
31MODULE_PARM_DESC(index, "Index value for pcsp soundcard.");
32module_param(id, charp, 0444);
33MODULE_PARM_DESC(id, "ID string for pcsp soundcard.");
34module_param(enable, bool, 0444);
35MODULE_PARM_DESC(enable, "Enable PC-Speaker sound.");
36
37struct snd_pcsp pcsp_chip;
38
39static int __devinit snd_pcsp_create(struct snd_card *card)
40{
41 static struct snd_device_ops ops = { };
42 struct timespec tp;
43 int err;
44 int div, min_div, order;
45
46 hrtimer_get_res(CLOCK_MONOTONIC, &tp);
47 if (tp.tv_sec || tp.tv_nsec > PCSP_MAX_PERIOD_NS) {
48 printk(KERN_ERR "PCSP: Timer resolution is not sufficient "
49 "(%linS)\n", tp.tv_nsec);
50 printk(KERN_ERR "PCSP: Make sure you have HPET and ACPI "
51 "enabled.\n");
52 return -EIO;
53 }
54
55 if (loops_per_jiffy >= PCSP_MIN_LPJ && tp.tv_nsec <= PCSP_MIN_PERIOD_NS)
56 min_div = MIN_DIV;
57 else
58 min_div = MAX_DIV;
59#if PCSP_DEBUG
60 printk("PCSP: lpj=%li, min_div=%i, res=%li\n",
61 loops_per_jiffy, min_div, tp.tv_nsec);
62#endif
63
64 div = MAX_DIV / min_div;
65 order = fls(div) - 1;
66
67 pcsp_chip.max_treble = min(order, PCSP_MAX_TREBLE);
68 pcsp_chip.treble = min(pcsp_chip.max_treble, PCSP_DEFAULT_TREBLE);
69 pcsp_chip.playback_ptr = 0;
70 pcsp_chip.period_ptr = 0;
71 atomic_set(&pcsp_chip.timer_active, 0);
72 pcsp_chip.enable = 1;
73 pcsp_chip.pcspkr = 1;
74
75 spin_lock_init(&pcsp_chip.substream_lock);
76
77 pcsp_chip.card = card;
78 pcsp_chip.port = 0x61;
79 pcsp_chip.irq = -1;
80 pcsp_chip.dma = -1;
81
82 /* Register device */
83 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, &pcsp_chip, &ops);
84 if (err < 0)
85 return err;
86
87 return 0;
88}
89
90static int __devinit snd_card_pcsp_probe(int devnum, struct device *dev)
91{
92 struct snd_card *card;
93 int err;
94
95 if (devnum != 0)
96 return -EINVAL;
97
98 hrtimer_init(&pcsp_chip.timer, CLOCK_MONOTONIC, HRTIMER_MODE_REL);
99 pcsp_chip.timer.cb_mode = HRTIMER_CB_IRQSAFE;
100 pcsp_chip.timer.function = pcsp_do_timer;
101
102 card = snd_card_new(index, id, THIS_MODULE, 0);
103 if (!card)
104 return -ENOMEM;
105
106 err = snd_pcsp_create(card);
107 if (err < 0) {
108 snd_card_free(card);
109 return err;
110 }
111 err = snd_pcsp_new_pcm(&pcsp_chip);
112 if (err < 0) {
113 snd_card_free(card);
114 return err;
115 }
116 err = snd_pcsp_new_mixer(&pcsp_chip);
117 if (err < 0) {
118 snd_card_free(card);
119 return err;
120 }
121
122 snd_card_set_dev(pcsp_chip.card, dev);
123
124 strcpy(card->driver, "PC-Speaker");
125 strcpy(card->shortname, "pcsp");
126 sprintf(card->longname, "Internal PC-Speaker at port 0x%x",
127 pcsp_chip.port);
128
129 err = snd_card_register(card);
130 if (err < 0) {
131 snd_card_free(card);
132 return err;
133 }
134
135 return 0;
136}
137
138static int __devinit alsa_card_pcsp_init(struct device *dev)
139{
140 int err;
141
142 err = snd_card_pcsp_probe(0, dev);
143 if (err) {
144 printk(KERN_ERR "PC-Speaker initialization failed.\n");
145 return err;
146 }
147
148#ifdef CONFIG_DEBUG_PAGEALLOC
149 /* Well, CONFIG_DEBUG_PAGEALLOC makes the sound horrible. Lets alert */
150 printk(KERN_WARNING "PCSP: CONFIG_DEBUG_PAGEALLOC is enabled, "
151 "which may make the sound noisy.\n");
152#endif
153
154 return 0;
155}
156
157static void __devexit alsa_card_pcsp_exit(struct snd_pcsp *chip)
158{
159 snd_card_free(chip->card);
160}
161
162static int __devinit pcsp_probe(struct platform_device *dev)
163{
164 int err;
165
166 err = pcspkr_input_init(&pcsp_chip.input_dev, &dev->dev);
167 if (err < 0)
168 return err;
169
170 err = alsa_card_pcsp_init(&dev->dev);
171 if (err < 0) {
172 pcspkr_input_remove(pcsp_chip.input_dev);
173 return err;
174 }
175
176 platform_set_drvdata(dev, &pcsp_chip);
177 return 0;
178}
179
180static int __devexit pcsp_remove(struct platform_device *dev)
181{
182 struct snd_pcsp *chip = platform_get_drvdata(dev);
183 alsa_card_pcsp_exit(chip);
184 pcspkr_input_remove(chip->input_dev);
185 platform_set_drvdata(dev, NULL);
186 return 0;
187}
188
189static void pcsp_stop_beep(struct snd_pcsp *chip)
190{
191 spin_lock_irq(&chip->substream_lock);
192 if (!chip->playback_substream)
193 pcspkr_stop_sound();
194 spin_unlock_irq(&chip->substream_lock);
195}
196
197static int pcsp_suspend(struct platform_device *dev, pm_message_t state)
198{
199 struct snd_pcsp *chip = platform_get_drvdata(dev);
200 pcsp_stop_beep(chip);
201 snd_pcm_suspend_all(chip->pcm);
202 return 0;
203}
204
205static void pcsp_shutdown(struct platform_device *dev)
206{
207 struct snd_pcsp *chip = platform_get_drvdata(dev);
208 pcsp_stop_beep(chip);
209}
210
211static struct platform_driver pcsp_platform_driver = {
212 .driver = {
213 .name = "pcspkr",
214 .owner = THIS_MODULE,
215 },
216 .probe = pcsp_probe,
217 .remove = __devexit_p(pcsp_remove),
218 .suspend = pcsp_suspend,
219 .shutdown = pcsp_shutdown,
220};
221
222static int __init pcsp_init(void)
223{
224 if (!enable)
225 return -ENODEV;
226 return platform_driver_register(&pcsp_platform_driver);
227}
228
229static void __exit pcsp_exit(void)
230{
231 platform_driver_unregister(&pcsp_platform_driver);
232}
233
234module_init(pcsp_init);
235module_exit(pcsp_exit);
diff --git a/sound/drivers/pcsp/pcsp.h b/sound/drivers/pcsp/pcsp.h
new file mode 100644
index 000000000000..f07cc1ee1fe7
--- /dev/null
+++ b/sound/drivers/pcsp/pcsp.h
@@ -0,0 +1,82 @@
1/*
2 * PC-Speaker driver for Linux
3 *
4 * Copyright (C) 1993-1997 Michael Beck
5 * Copyright (C) 1997-2001 David Woodhouse
6 * Copyright (C) 2001-2008 Stas Sergeev
7 */
8
9#ifndef __PCSP_H__
10#define __PCSP_H__
11
12#include <linux/hrtimer.h>
13#if defined(CONFIG_MIPS) || defined(CONFIG_X86)
14/* Use the global PIT lock ! */
15#include <asm/i8253.h>
16#else
17#include <asm/8253pit.h>
18static DEFINE_SPINLOCK(i8253_lock);
19#endif
20
21#define PCSP_SOUND_VERSION 0x400 /* read 4.00 */
22#define PCSP_DEBUG 0
23
24/* default timer freq for PC-Speaker: 18643 Hz */
25#define DIV_18KHZ 64
26#define MAX_DIV DIV_18KHZ
27#define CUR_DIV() (MAX_DIV >> chip->treble)
28#define PCSP_MAX_TREBLE 1
29
30/* unfortunately, with hrtimers 37KHz does not work very well :( */
31#define PCSP_DEFAULT_TREBLE 0
32#define MIN_DIV (MAX_DIV >> PCSP_MAX_TREBLE)
33
34/* wild guess */
35#define PCSP_MIN_LPJ 1000000
36#define PCSP_DEFAULT_SDIV (DIV_18KHZ >> 1)
37#define PCSP_DEFAULT_SRATE (PIT_TICK_RATE / PCSP_DEFAULT_SDIV)
38#define PCSP_INDEX_INC() (1 << (PCSP_MAX_TREBLE - chip->treble))
39#define PCSP_RATE() (PIT_TICK_RATE / CUR_DIV())
40#define PCSP_MIN_RATE__1 MAX_DIV/PIT_TICK_RATE
41#define PCSP_MAX_RATE__1 MIN_DIV/PIT_TICK_RATE
42#define PCSP_MAX_PERIOD_NS (1000000000ULL * PCSP_MIN_RATE__1)
43#define PCSP_MIN_PERIOD_NS (1000000000ULL * PCSP_MAX_RATE__1)
44#define PCSP_CALC_NS(div) ({ \
45 u64 __val = 1000000000ULL * (div); \
46 do_div(__val, PIT_TICK_RATE); \
47 __val; \
48})
49#define PCSP_PERIOD_NS() PCSP_CALC_NS(CUR_DIV())
50
51#define PCSP_MAX_PERIOD_SIZE (64*1024)
52#define PCSP_MAX_PERIODS 512
53#define PCSP_BUFFER_SIZE (128*1024)
54
55struct snd_pcsp {
56 struct snd_card *card;
57 struct snd_pcm *pcm;
58 struct input_dev *input_dev;
59 struct hrtimer timer;
60 unsigned short port, irq, dma;
61 spinlock_t substream_lock;
62 struct snd_pcm_substream *playback_substream;
63 size_t playback_ptr;
64 size_t period_ptr;
65 atomic_t timer_active;
66 int thalf;
67 u64 ns_rem;
68 unsigned char val61;
69 int enable;
70 int max_treble;
71 int treble;
72 int pcspkr;
73};
74
75extern struct snd_pcsp pcsp_chip;
76
77extern enum hrtimer_restart pcsp_do_timer(struct hrtimer *handle);
78
79extern int snd_pcsp_new_pcm(struct snd_pcsp *chip);
80extern int snd_pcsp_new_mixer(struct snd_pcsp *chip);
81
82#endif
diff --git a/sound/drivers/pcsp/pcsp_input.c b/sound/drivers/pcsp/pcsp_input.c
new file mode 100644
index 000000000000..cd9b83e7f7d1
--- /dev/null
+++ b/sound/drivers/pcsp/pcsp_input.c
@@ -0,0 +1,116 @@
1/*
2 * PC Speaker beeper driver for Linux
3 *
4 * Copyright (c) 2002 Vojtech Pavlik
5 * Copyright (c) 1992 Orest Zborowski
6 *
7 */
8
9/*
10 * This program is free software; you can redistribute it and/or modify it
11 * under the terms of the GNU General Public License version 2 as published by
12 * the Free Software Foundation
13 */
14
15#include <linux/init.h>
16#include <linux/input.h>
17#include <asm/io.h>
18#include "pcsp.h"
19
20static void pcspkr_do_sound(unsigned int count)
21{
22 unsigned long flags;
23
24 spin_lock_irqsave(&i8253_lock, flags);
25
26 if (count) {
27 /* enable counter 2 */
28 outb_p(inb_p(0x61) | 3, 0x61);
29 /* set command for counter 2, 2 byte write */
30 outb_p(0xB6, 0x43);
31 /* select desired HZ */
32 outb_p(count & 0xff, 0x42);
33 outb((count >> 8) & 0xff, 0x42);
34 } else {
35 /* disable counter 2 */
36 outb(inb_p(0x61) & 0xFC, 0x61);
37 }
38
39 spin_unlock_irqrestore(&i8253_lock, flags);
40}
41
42void pcspkr_stop_sound(void)
43{
44 pcspkr_do_sound(0);
45}
46
47static int pcspkr_input_event(struct input_dev *dev, unsigned int type,
48 unsigned int code, int value)
49{
50 unsigned int count = 0;
51
52 if (atomic_read(&pcsp_chip.timer_active) || !pcsp_chip.pcspkr)
53 return 0;
54
55 switch (type) {
56 case EV_SND:
57 switch (code) {
58 case SND_BELL:
59 if (value)
60 value = 1000;
61 case SND_TONE:
62 break;
63 default:
64 return -1;
65 }
66 break;
67
68 default:
69 return -1;
70 }
71
72 if (value > 20 && value < 32767)
73 count = PIT_TICK_RATE / value;
74
75 pcspkr_do_sound(count);
76
77 return 0;
78}
79
80int __devinit pcspkr_input_init(struct input_dev **rdev, struct device *dev)
81{
82 int err;
83
84 struct input_dev *input_dev = input_allocate_device();
85 if (!input_dev)
86 return -ENOMEM;
87
88 input_dev->name = "PC Speaker";
89 input_dev->phys = "isa0061/input0";
90 input_dev->id.bustype = BUS_ISA;
91 input_dev->id.vendor = 0x001f;
92 input_dev->id.product = 0x0001;
93 input_dev->id.version = 0x0100;
94 input_dev->dev.parent = dev;
95
96 input_dev->evbit[0] = BIT(EV_SND);
97 input_dev->sndbit[0] = BIT(SND_BELL) | BIT(SND_TONE);
98 input_dev->event = pcspkr_input_event;
99
100 err = input_register_device(input_dev);
101 if (err) {
102 input_free_device(input_dev);
103 return err;
104 }
105
106 *rdev = input_dev;
107 return 0;
108}
109
110int pcspkr_input_remove(struct input_dev *dev)
111{
112 pcspkr_stop_sound();
113 input_unregister_device(dev); /* this also does kfree() */
114
115 return 0;
116}
diff --git a/sound/drivers/pcsp/pcsp_input.h b/sound/drivers/pcsp/pcsp_input.h
new file mode 100644
index 000000000000..e66738c78333
--- /dev/null
+++ b/sound/drivers/pcsp/pcsp_input.h
@@ -0,0 +1,14 @@
1/*
2 * PC-Speaker driver for Linux
3 *
4 * Copyright (C) 2001-2008 Stas Sergeev
5 */
6
7#ifndef __PCSP_INPUT_H__
8#define __PCSP_INPUT_H__
9
10int __devinit pcspkr_input_init(struct input_dev **rdev, struct device *dev);
11int pcspkr_input_remove(struct input_dev *dev);
12void pcspkr_stop_sound(void);
13
14#endif
diff --git a/sound/drivers/pcsp/pcsp_lib.c b/sound/drivers/pcsp/pcsp_lib.c
new file mode 100644
index 000000000000..ac6238e93513
--- /dev/null
+++ b/sound/drivers/pcsp/pcsp_lib.c
@@ -0,0 +1,338 @@
1/*
2 * PC-Speaker driver for Linux
3 *
4 * Copyright (C) 1993-1997 Michael Beck
5 * Copyright (C) 1997-2001 David Woodhouse
6 * Copyright (C) 2001-2008 Stas Sergeev
7 */
8
9#include <linux/module.h>
10#include <linux/moduleparam.h>
11#include <sound/pcm.h>
12#include <linux/interrupt.h>
13#include <asm/io.h>
14#include "pcsp.h"
15
16static int nforce_wa;
17module_param(nforce_wa, bool, 0444);
18MODULE_PARM_DESC(nforce_wa, "Apply NForce chipset workaround "
19 "(expect bad sound)");
20
21static void pcsp_start_timer(unsigned long dummy)
22{
23 hrtimer_start(&pcsp_chip.timer, ktime_set(0, 0), HRTIMER_MODE_REL);
24}
25
26/*
27 * We need the hrtimer_start as a tasklet to avoid
28 * the nasty locking problem. :(
29 * The problem:
30 * - The timer handler is called with the cpu_base->lock
31 * already held by hrtimer code.
32 * - snd_pcm_period_elapsed() takes the
33 * substream->self_group.lock.
34 * So far so good.
35 * But the snd_pcsp_trigger() is called with the
36 * substream->self_group.lock held, and it calls
37 * hrtimer_start(), which takes the cpu_base->lock.
38 * You see the problem. We have the code pathes
39 * which take two locks in a reverse order. This
40 * can deadlock and the lock validator complains.
41 * The only solution I could find was to move the
42 * hrtimer_start() into a tasklet. -stsp
43 */
44static DECLARE_TASKLET(pcsp_start_timer_tasklet, pcsp_start_timer, 0);
45
46enum hrtimer_restart pcsp_do_timer(struct hrtimer *handle)
47{
48 unsigned long flags;
49 unsigned char timer_cnt, val;
50 int periods_elapsed;
51 u64 ns;
52 size_t period_bytes, buffer_bytes;
53 struct snd_pcm_substream *substream;
54 struct snd_pcm_runtime *runtime;
55 struct snd_pcsp *chip = container_of(handle, struct snd_pcsp, timer);
56
57 if (chip->thalf) {
58 outb(chip->val61, 0x61);
59 chip->thalf = 0;
60 if (!atomic_read(&chip->timer_active))
61 return HRTIMER_NORESTART;
62 hrtimer_forward(&chip->timer, chip->timer.expires,
63 ktime_set(0, chip->ns_rem));
64 return HRTIMER_RESTART;
65 }
66
67 /* hrtimer calls us from both hardirq and softirq contexts,
68 * so irqsave :( */
69 spin_lock_irqsave(&chip->substream_lock, flags);
70 /* Takashi Iwai says regarding this extra lock:
71
72 If the irq handler handles some data on the DMA buffer, it should
73 do snd_pcm_stream_lock().
74 That protects basically against all races among PCM callbacks, yes.
75 However, there are two remaining issues:
76 1. The substream pointer you try to lock isn't protected _before_
77 this lock yet.
78 2. snd_pcm_period_elapsed() itself acquires the lock.
79 The requirement of another lock is because of 1. When you get
80 chip->playback_substream, it's not protected.
81 Keeping this lock while snd_pcm_period_elapsed() assures the substream
82 is still protected (at least, not released). And the other status is
83 handled properly inside snd_pcm_stream_lock() in
84 snd_pcm_period_elapsed().
85
86 */
87 if (!chip->playback_substream)
88 goto exit_nr_unlock1;
89 substream = chip->playback_substream;
90 snd_pcm_stream_lock(substream);
91 if (!atomic_read(&chip->timer_active))
92 goto exit_nr_unlock2;
93
94 runtime = substream->runtime;
95 /* assume it is u8 mono */
96 val = runtime->dma_area[chip->playback_ptr];
97 timer_cnt = val * CUR_DIV() / 256;
98
99 if (timer_cnt && chip->enable) {
100 spin_lock(&i8253_lock);
101 if (!nforce_wa) {
102 outb_p(chip->val61, 0x61);
103 outb_p(timer_cnt, 0x42);
104 outb(chip->val61 ^ 1, 0x61);
105 } else {
106 outb(chip->val61 ^ 2, 0x61);
107 chip->thalf = 1;
108 }
109 spin_unlock(&i8253_lock);
110 }
111
112 period_bytes = snd_pcm_lib_period_bytes(substream);
113 buffer_bytes = snd_pcm_lib_buffer_bytes(substream);
114 chip->playback_ptr += PCSP_INDEX_INC();
115 periods_elapsed = chip->playback_ptr - chip->period_ptr;
116 if (periods_elapsed < 0) {
117 printk(KERN_WARNING "PCSP: playback_ptr inconsistent "
118 "(%zi %zi %zi)\n",
119 chip->playback_ptr, period_bytes, buffer_bytes);
120 periods_elapsed += buffer_bytes;
121 }
122 periods_elapsed /= period_bytes;
123 /* wrap the pointer _before_ calling snd_pcm_period_elapsed(),
124 * or ALSA will BUG on us. */
125 chip->playback_ptr %= buffer_bytes;
126
127 snd_pcm_stream_unlock(substream);
128
129 if (periods_elapsed) {
130 snd_pcm_period_elapsed(substream);
131 chip->period_ptr += periods_elapsed * period_bytes;
132 chip->period_ptr %= buffer_bytes;
133 }
134
135 spin_unlock_irqrestore(&chip->substream_lock, flags);
136
137 if (!atomic_read(&chip->timer_active))
138 return HRTIMER_NORESTART;
139
140 chip->ns_rem = PCSP_PERIOD_NS();
141 ns = (chip->thalf ? PCSP_CALC_NS(timer_cnt) : chip->ns_rem);
142 chip->ns_rem -= ns;
143 hrtimer_forward(&chip->timer, chip->timer.expires, ktime_set(0, ns));
144 return HRTIMER_RESTART;
145
146exit_nr_unlock2:
147 snd_pcm_stream_unlock(substream);
148exit_nr_unlock1:
149 spin_unlock_irqrestore(&chip->substream_lock, flags);
150 return HRTIMER_NORESTART;
151}
152
153static void pcsp_start_playing(struct snd_pcsp *chip)
154{
155#if PCSP_DEBUG
156 printk(KERN_INFO "PCSP: start_playing called\n");
157#endif
158 if (atomic_read(&chip->timer_active)) {
159 printk(KERN_ERR "PCSP: Timer already active\n");
160 return;
161 }
162
163 spin_lock(&i8253_lock);
164 chip->val61 = inb(0x61) | 0x03;
165 outb_p(0x92, 0x43); /* binary, mode 1, LSB only, ch 2 */
166 spin_unlock(&i8253_lock);
167 atomic_set(&chip->timer_active, 1);
168 chip->thalf = 0;
169
170 tasklet_schedule(&pcsp_start_timer_tasklet);
171}
172
173static void pcsp_stop_playing(struct snd_pcsp *chip)
174{
175#if PCSP_DEBUG
176 printk(KERN_INFO "PCSP: stop_playing called\n");
177#endif
178 if (!atomic_read(&chip->timer_active))
179 return;
180
181 atomic_set(&chip->timer_active, 0);
182 spin_lock(&i8253_lock);
183 /* restore the timer */
184 outb_p(0xb6, 0x43); /* binary, mode 3, LSB/MSB, ch 2 */
185 outb(chip->val61 & 0xFC, 0x61);
186 spin_unlock(&i8253_lock);
187}
188
189static int snd_pcsp_playback_close(struct snd_pcm_substream *substream)
190{
191 struct snd_pcsp *chip = snd_pcm_substream_chip(substream);
192#if PCSP_DEBUG
193 printk(KERN_INFO "PCSP: close called\n");
194#endif
195 if (atomic_read(&chip->timer_active)) {
196 printk(KERN_ERR "PCSP: timer still active\n");
197 pcsp_stop_playing(chip);
198 }
199 spin_lock_irq(&chip->substream_lock);
200 chip->playback_substream = NULL;
201 spin_unlock_irq(&chip->substream_lock);
202 return 0;
203}
204
205static int snd_pcsp_playback_hw_params(struct snd_pcm_substream *substream,
206 struct snd_pcm_hw_params *hw_params)
207{
208 int err;
209 err = snd_pcm_lib_malloc_pages(substream,
210 params_buffer_bytes(hw_params));
211 if (err < 0)
212 return err;
213 return 0;
214}
215
216static int snd_pcsp_playback_hw_free(struct snd_pcm_substream *substream)
217{
218#if PCSP_DEBUG
219 printk(KERN_INFO "PCSP: hw_free called\n");
220#endif
221 return snd_pcm_lib_free_pages(substream);
222}
223
224static int snd_pcsp_playback_prepare(struct snd_pcm_substream *substream)
225{
226 struct snd_pcsp *chip = snd_pcm_substream_chip(substream);
227#if PCSP_DEBUG
228 printk(KERN_INFO "PCSP: prepare called, "
229 "size=%zi psize=%zi f=%zi f1=%i\n",
230 snd_pcm_lib_buffer_bytes(substream),
231 snd_pcm_lib_period_bytes(substream),
232 snd_pcm_lib_buffer_bytes(substream) /
233 snd_pcm_lib_period_bytes(substream),
234 substream->runtime->periods);
235#endif
236 chip->playback_ptr = 0;
237 chip->period_ptr = 0;
238 return 0;
239}
240
241static int snd_pcsp_trigger(struct snd_pcm_substream *substream, int cmd)
242{
243 struct snd_pcsp *chip = snd_pcm_substream_chip(substream);
244#if PCSP_DEBUG
245 printk(KERN_INFO "PCSP: trigger called\n");
246#endif
247 switch (cmd) {
248 case SNDRV_PCM_TRIGGER_START:
249 case SNDRV_PCM_TRIGGER_RESUME:
250 pcsp_start_playing(chip);
251 break;
252 case SNDRV_PCM_TRIGGER_STOP:
253 case SNDRV_PCM_TRIGGER_SUSPEND:
254 pcsp_stop_playing(chip);
255 break;
256 default:
257 return -EINVAL;
258 }
259 return 0;
260}
261
262static snd_pcm_uframes_t snd_pcsp_playback_pointer(struct snd_pcm_substream
263 *substream)
264{
265 struct snd_pcsp *chip = snd_pcm_substream_chip(substream);
266 return bytes_to_frames(substream->runtime, chip->playback_ptr);
267}
268
269static struct snd_pcm_hardware snd_pcsp_playback = {
270 .info = (SNDRV_PCM_INFO_INTERLEAVED |
271 SNDRV_PCM_INFO_HALF_DUPLEX |
272 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID),
273 .formats = SNDRV_PCM_FMTBIT_U8,
274 .rates = SNDRV_PCM_RATE_KNOT,
275 .rate_min = PCSP_DEFAULT_SRATE,
276 .rate_max = PCSP_DEFAULT_SRATE,
277 .channels_min = 1,
278 .channels_max = 1,
279 .buffer_bytes_max = PCSP_BUFFER_SIZE,
280 .period_bytes_min = 64,
281 .period_bytes_max = PCSP_MAX_PERIOD_SIZE,
282 .periods_min = 2,
283 .periods_max = PCSP_MAX_PERIODS,
284 .fifo_size = 0,
285};
286
287static int snd_pcsp_playback_open(struct snd_pcm_substream *substream)
288{
289 struct snd_pcsp *chip = snd_pcm_substream_chip(substream);
290 struct snd_pcm_runtime *runtime = substream->runtime;
291#if PCSP_DEBUG
292 printk(KERN_INFO "PCSP: open called\n");
293#endif
294 if (atomic_read(&chip->timer_active)) {
295 printk(KERN_ERR "PCSP: still active!!\n");
296 return -EBUSY;
297 }
298 runtime->hw = snd_pcsp_playback;
299 spin_lock_irq(&chip->substream_lock);
300 chip->playback_substream = substream;
301 spin_unlock_irq(&chip->substream_lock);
302 return 0;
303}
304
305static struct snd_pcm_ops snd_pcsp_playback_ops = {
306 .open = snd_pcsp_playback_open,
307 .close = snd_pcsp_playback_close,
308 .ioctl = snd_pcm_lib_ioctl,
309 .hw_params = snd_pcsp_playback_hw_params,
310 .hw_free = snd_pcsp_playback_hw_free,
311 .prepare = snd_pcsp_playback_prepare,
312 .trigger = snd_pcsp_trigger,
313 .pointer = snd_pcsp_playback_pointer,
314};
315
316int __devinit snd_pcsp_new_pcm(struct snd_pcsp *chip)
317{
318 int err;
319
320 err = snd_pcm_new(chip->card, "pcspeaker", 0, 1, 0, &chip->pcm);
321 if (err < 0)
322 return err;
323
324 snd_pcm_set_ops(chip->pcm, SNDRV_PCM_STREAM_PLAYBACK,
325 &snd_pcsp_playback_ops);
326
327 chip->pcm->private_data = chip;
328 chip->pcm->info_flags = SNDRV_PCM_INFO_HALF_DUPLEX;
329 strcpy(chip->pcm->name, "pcsp");
330
331 snd_pcm_lib_preallocate_pages_for_all(chip->pcm,
332 SNDRV_DMA_TYPE_CONTINUOUS,
333 snd_dma_continuous_data
334 (GFP_KERNEL), PCSP_BUFFER_SIZE,
335 PCSP_BUFFER_SIZE);
336
337 return 0;
338}
diff --git a/sound/drivers/pcsp/pcsp_mixer.c b/sound/drivers/pcsp/pcsp_mixer.c
new file mode 100644
index 000000000000..64a695fef74e
--- /dev/null
+++ b/sound/drivers/pcsp/pcsp_mixer.c
@@ -0,0 +1,143 @@
1/*
2 * PC-Speaker driver for Linux
3 *
4 * Mixer implementation.
5 * Copyright (C) 2001-2008 Stas Sergeev
6 */
7
8#include <sound/core.h>
9#include <sound/control.h>
10#include "pcsp.h"
11
12
13static int pcsp_enable_info(struct snd_kcontrol *kcontrol,
14 struct snd_ctl_elem_info *uinfo)
15{
16 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
17 uinfo->count = 1;
18 uinfo->value.integer.min = 0;
19 uinfo->value.integer.max = 1;
20 return 0;
21}
22
23static int pcsp_enable_get(struct snd_kcontrol *kcontrol,
24 struct snd_ctl_elem_value *ucontrol)
25{
26 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
27 ucontrol->value.integer.value[0] = chip->enable;
28 return 0;
29}
30
31static int pcsp_enable_put(struct snd_kcontrol *kcontrol,
32 struct snd_ctl_elem_value *ucontrol)
33{
34 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
35 int changed = 0;
36 int enab = ucontrol->value.integer.value[0];
37 if (enab != chip->enable) {
38 chip->enable = enab;
39 changed = 1;
40 }
41 return changed;
42}
43
44static int pcsp_treble_info(struct snd_kcontrol *kcontrol,
45 struct snd_ctl_elem_info *uinfo)
46{
47 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
48 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
49 uinfo->count = 1;
50 uinfo->value.enumerated.items = chip->max_treble + 1;
51 if (uinfo->value.enumerated.item > chip->max_treble)
52 uinfo->value.enumerated.item = chip->max_treble;
53 sprintf(uinfo->value.enumerated.name, "%d", PCSP_RATE());
54 return 0;
55}
56
57static int pcsp_treble_get(struct snd_kcontrol *kcontrol,
58 struct snd_ctl_elem_value *ucontrol)
59{
60 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
61 ucontrol->value.enumerated.item[0] = chip->treble;
62 return 0;
63}
64
65static int pcsp_treble_put(struct snd_kcontrol *kcontrol,
66 struct snd_ctl_elem_value *ucontrol)
67{
68 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
69 int changed = 0;
70 int treble = ucontrol->value.enumerated.item[0];
71 if (treble != chip->treble) {
72 chip->treble = treble;
73#if PCSP_DEBUG
74 printk(KERN_INFO "PCSP: rate set to %i\n", PCSP_RATE());
75#endif
76 changed = 1;
77 }
78 return changed;
79}
80
81static int pcsp_pcspkr_info(struct snd_kcontrol *kcontrol,
82 struct snd_ctl_elem_info *uinfo)
83{
84 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
85 uinfo->count = 1;
86 uinfo->value.integer.min = 0;
87 uinfo->value.integer.max = 1;
88 return 0;
89}
90
91static int pcsp_pcspkr_get(struct snd_kcontrol *kcontrol,
92 struct snd_ctl_elem_value *ucontrol)
93{
94 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
95 ucontrol->value.integer.value[0] = chip->pcspkr;
96 return 0;
97}
98
99static int pcsp_pcspkr_put(struct snd_kcontrol *kcontrol,
100 struct snd_ctl_elem_value *ucontrol)
101{
102 struct snd_pcsp *chip = snd_kcontrol_chip(kcontrol);
103 int changed = 0;
104 int spkr = ucontrol->value.integer.value[0];
105 if (spkr != chip->pcspkr) {
106 chip->pcspkr = spkr;
107 changed = 1;
108 }
109 return changed;
110}
111
112#define PCSP_MIXER_CONTROL(ctl_type, ctl_name) \
113{ \
114 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
115 .name = ctl_name, \
116 .info = pcsp_##ctl_type##_info, \
117 .get = pcsp_##ctl_type##_get, \
118 .put = pcsp_##ctl_type##_put, \
119}
120
121static struct snd_kcontrol_new __devinitdata snd_pcsp_controls[] = {
122 PCSP_MIXER_CONTROL(enable, "Master Playback Switch"),
123 PCSP_MIXER_CONTROL(treble, "BaseFRQ Playback Volume"),
124 PCSP_MIXER_CONTROL(pcspkr, "PC Speaker Playback Switch"),
125};
126
127int __devinit snd_pcsp_new_mixer(struct snd_pcsp *chip)
128{
129 struct snd_card *card = chip->card;
130 int i, err;
131
132 for (i = 0; i < ARRAY_SIZE(snd_pcsp_controls); i++) {
133 err = snd_ctl_add(card,
134 snd_ctl_new1(snd_pcsp_controls + i,
135 chip));
136 if (err < 0)
137 return err;
138 }
139
140 strcpy(card->mixername, "PC-Speaker");
141
142 return 0;
143}
diff --git a/sound/i2c/other/ak4114.c b/sound/i2c/other/ak4114.c
index 15061bd72776..d20d893b3b60 100644
--- a/sound/i2c/other/ak4114.c
+++ b/sound/i2c/other/ak4114.c
@@ -27,6 +27,7 @@
27#include <sound/pcm.h> 27#include <sound/pcm.h>
28#include <sound/ak4114.h> 28#include <sound/ak4114.h>
29#include <sound/asoundef.h> 29#include <sound/asoundef.h>
30#include <sound/info.h>
30 31
31MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); 32MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
32MODULE_DESCRIPTION("AK4114 IEC958 (S/PDIF) receiver by Asahi Kasei"); 33MODULE_DESCRIPTION("AK4114 IEC958 (S/PDIF) receiver by Asahi Kasei");
@@ -446,6 +447,26 @@ static struct snd_kcontrol_new snd_ak4114_iec958_controls[] = {
446} 447}
447}; 448};
448 449
450
451static void snd_ak4114_proc_regs_read(struct snd_info_entry *entry,
452 struct snd_info_buffer *buffer)
453{
454 struct ak4114 *ak4114 = entry->private_data;
455 int reg, val;
456 /* all ak4114 registers 0x00 - 0x1f */
457 for (reg = 0; reg < 0x20; reg++) {
458 val = reg_read(ak4114, reg);
459 snd_iprintf(buffer, "0x%02x = 0x%02x\n", reg, val);
460 }
461}
462
463static void snd_ak4114_proc_init(struct ak4114 *ak4114)
464{
465 struct snd_info_entry *entry;
466 if (!snd_card_proc_new(ak4114->card, "ak4114", &entry))
467 snd_info_set_text_ops(entry, ak4114, snd_ak4114_proc_regs_read);
468}
469
449int snd_ak4114_build(struct ak4114 *ak4114, 470int snd_ak4114_build(struct ak4114 *ak4114,
450 struct snd_pcm_substream *ply_substream, 471 struct snd_pcm_substream *ply_substream,
451 struct snd_pcm_substream *cap_substream) 472 struct snd_pcm_substream *cap_substream)
@@ -478,6 +499,7 @@ int snd_ak4114_build(struct ak4114 *ak4114,
478 return err; 499 return err;
479 ak4114->kctls[idx] = kctl; 500 ak4114->kctls[idx] = kctl;
480 } 501 }
502 snd_ak4114_proc_init(ak4114);
481 /* trigger workq */ 503 /* trigger workq */
482 schedule_delayed_work(&ak4114->work, HZ / 10); 504 schedule_delayed_work(&ak4114->work, HZ / 10);
483 return 0; 505 return 0;
@@ -590,7 +612,7 @@ static void ak4114_stats(struct work_struct *work)
590 struct ak4114 *chip = container_of(work, struct ak4114, work.work); 612 struct ak4114 *chip = container_of(work, struct ak4114, work.work);
591 613
592 if (!chip->init) 614 if (!chip->init)
593 snd_ak4114_check_rate_and_errors(chip, 0); 615 snd_ak4114_check_rate_and_errors(chip, chip->check_flags);
594 616
595 schedule_delayed_work(&chip->work, HZ / 10); 617 schedule_delayed_work(&chip->work, HZ / 10);
596} 618}
diff --git a/sound/i2c/other/ak4xxx-adda.c b/sound/i2c/other/ak4xxx-adda.c
index 35fbbf2cb9fa..288926d2e205 100644
--- a/sound/i2c/other/ak4xxx-adda.c
+++ b/sound/i2c/other/ak4xxx-adda.c
@@ -70,7 +70,8 @@ static void ak4524_reset(struct snd_akm4xxx *ak, int state)
70} 70}
71 71
72/* reset procedure for AK4355 and AK4358 */ 72/* reset procedure for AK4355 and AK4358 */
73static void ak4355_reset(struct snd_akm4xxx *ak, int state) 73static void ak435X_reset(struct snd_akm4xxx *ak, int state,
74 unsigned char total_regs)
74{ 75{
75 unsigned char reg; 76 unsigned char reg;
76 77
@@ -78,7 +79,7 @@ static void ak4355_reset(struct snd_akm4xxx *ak, int state)
78 snd_akm4xxx_write(ak, 0, 0x01, 0x02); /* reset and soft-mute */ 79 snd_akm4xxx_write(ak, 0, 0x01, 0x02); /* reset and soft-mute */
79 return; 80 return;
80 } 81 }
81 for (reg = 0x00; reg < 0x0b; reg++) 82 for (reg = 0x00; reg < total_regs; reg++)
82 if (reg != 0x01) 83 if (reg != 0x01)
83 snd_akm4xxx_write(ak, 0, reg, 84 snd_akm4xxx_write(ak, 0, reg,
84 snd_akm4xxx_get(ak, 0, reg)); 85 snd_akm4xxx_get(ak, 0, reg));
@@ -118,8 +119,10 @@ void snd_akm4xxx_reset(struct snd_akm4xxx *ak, int state)
118 /* FIXME: needed for ak4529? */ 119 /* FIXME: needed for ak4529? */
119 break; 120 break;
120 case SND_AK4355: 121 case SND_AK4355:
122 ak435X_reset(ak, state, 0x0b);
123 break;
121 case SND_AK4358: 124 case SND_AK4358:
122 ak4355_reset(ak, state); 125 ak435X_reset(ak, state, 0x10);
123 break; 126 break;
124 case SND_AK4381: 127 case SND_AK4381:
125 ak4381_reset(ak, state); 128 ak4381_reset(ak, state);
@@ -292,11 +295,6 @@ void snd_akm4xxx_init(struct snd_akm4xxx *ak)
292 case SND_AK5365: 295 case SND_AK5365:
293 /* FIXME: any init sequence? */ 296 /* FIXME: any init sequence? */
294 return; 297 return;
295 case NON_AKM:
296 /* fake value for non-akm codecs using akm infrastructure
297 * (e.g. of ice1724) - certainly FIXME
298 */
299 return;
300 default: 298 default:
301 snd_BUG(); 299 snd_BUG();
302 return; 300 return;
@@ -374,6 +372,8 @@ static int put_ak_reg(struct snd_kcontrol *kcontrol, int addr,
374 nval = mask - nval; 372 nval = mask - nval;
375 if (AK_GET_NEEDSMSB(kcontrol->private_value)) 373 if (AK_GET_NEEDSMSB(kcontrol->private_value))
376 nval |= 0x80; 374 nval |= 0x80;
375 /* printk(KERN_DEBUG "DEBUG - AK writing reg: chip %x addr %x,
376 nval %x\n", chip, addr, nval); */
377 snd_akm4xxx_write(ak, chip, addr, nval); 377 snd_akm4xxx_write(ak, chip, addr, nval);
378 return 1; 378 return 1;
379} 379}
diff --git a/sound/isa/sb/sb16_csp.c b/sound/isa/sb/sb16_csp.c
index bed29ca22239..f3fd7b4f4668 100644
--- a/sound/isa/sb/sb16_csp.c
+++ b/sound/isa/sb/sb16_csp.c
@@ -331,7 +331,7 @@ static int snd_sb_csp_riff_load(struct snd_sb_csp * p,
331 return -EFAULT; 331 return -EFAULT;
332 if ((file_h.name != RIFF_HEADER) || 332 if ((file_h.name != RIFF_HEADER) ||
333 (le32_to_cpu(file_h.len) >= SNDRV_SB_CSP_MAX_MICROCODE_FILE_SIZE - sizeof(file_h))) { 333 (le32_to_cpu(file_h.len) >= SNDRV_SB_CSP_MAX_MICROCODE_FILE_SIZE - sizeof(file_h))) {
334 snd_printd("%s: Invalid RIFF header\n", __FUNCTION__); 334 snd_printd("%s: Invalid RIFF header\n", __func__);
335 return -EINVAL; 335 return -EINVAL;
336 } 336 }
337 data_ptr += sizeof(file_h); 337 data_ptr += sizeof(file_h);
@@ -340,7 +340,7 @@ static int snd_sb_csp_riff_load(struct snd_sb_csp * p,
340 if (copy_from_user(&item_type, data_ptr, sizeof(item_type))) 340 if (copy_from_user(&item_type, data_ptr, sizeof(item_type)))
341 return -EFAULT; 341 return -EFAULT;
342 if (item_type != CSP__HEADER) { 342 if (item_type != CSP__HEADER) {
343 snd_printd("%s: Invalid RIFF file type\n", __FUNCTION__); 343 snd_printd("%s: Invalid RIFF file type\n", __func__);
344 return -EINVAL; 344 return -EINVAL;
345 } 345 }
346 data_ptr += sizeof (item_type); 346 data_ptr += sizeof (item_type);
@@ -395,7 +395,7 @@ static int snd_sb_csp_riff_load(struct snd_sb_csp * p,
395 return -EFAULT; 395 return -EFAULT;
396 396
397 if (code_h.name != MAIN_HEADER) { 397 if (code_h.name != MAIN_HEADER) {
398 snd_printd("%s: Missing 'main' microcode\n", __FUNCTION__); 398 snd_printd("%s: Missing 'main' microcode\n", __func__);
399 return -EINVAL; 399 return -EINVAL;
400 } 400 }
401 data_ptr += sizeof(code_h); 401 data_ptr += sizeof(code_h);
@@ -439,7 +439,7 @@ static int snd_sb_csp_riff_load(struct snd_sb_csp * p,
439 p->acc_format = p->acc_width = p->acc_rates = 0; 439 p->acc_format = p->acc_width = p->acc_rates = 0;
440 p->mode = 0; 440 p->mode = 0;
441 snd_printd("%s: Unsupported CSP codec type: 0x%04x\n", 441 snd_printd("%s: Unsupported CSP codec type: 0x%04x\n",
442 __FUNCTION__, 442 __func__,
443 le16_to_cpu(funcdesc_h.VOC_type)); 443 le16_to_cpu(funcdesc_h.VOC_type));
444 return -EINVAL; 444 return -EINVAL;
445 } 445 }
@@ -458,7 +458,7 @@ static int snd_sb_csp_riff_load(struct snd_sb_csp * p,
458 return 0; 458 return 0;
459 } 459 }
460 } 460 }
461 snd_printd("%s: Function #%d not found\n", __FUNCTION__, info.func_req); 461 snd_printd("%s: Function #%d not found\n", __func__, info.func_req);
462 return -EINVAL; 462 return -EINVAL;
463} 463}
464 464
@@ -612,7 +612,7 @@ static int get_version(struct snd_sb *chip)
612static int snd_sb_csp_check_version(struct snd_sb_csp * p) 612static int snd_sb_csp_check_version(struct snd_sb_csp * p)
613{ 613{
614 if (p->version < 0x10 || p->version > 0x1f) { 614 if (p->version < 0x10 || p->version > 0x1f) {
615 snd_printd("%s: Invalid CSP version: 0x%x\n", __FUNCTION__, p->version); 615 snd_printd("%s: Invalid CSP version: 0x%x\n", __func__, p->version);
616 return 1; 616 return 1;
617 } 617 }
618 return 0; 618 return 0;
@@ -631,7 +631,7 @@ static int snd_sb_csp_load(struct snd_sb_csp * p, const unsigned char *buf, int
631 spin_lock_irqsave(&p->chip->reg_lock, flags); 631 spin_lock_irqsave(&p->chip->reg_lock, flags);
632 snd_sbdsp_command(p->chip, 0x01); /* CSP download command */ 632 snd_sbdsp_command(p->chip, 0x01); /* CSP download command */
633 if (snd_sbdsp_get_byte(p->chip)) { 633 if (snd_sbdsp_get_byte(p->chip)) {
634 snd_printd("%s: Download command failed\n", __FUNCTION__); 634 snd_printd("%s: Download command failed\n", __func__);
635 goto __fail; 635 goto __fail;
636 } 636 }
637 /* Send CSP low byte (size - 1) */ 637 /* Send CSP low byte (size - 1) */
@@ -658,7 +658,7 @@ static int snd_sb_csp_load(struct snd_sb_csp * p, const unsigned char *buf, int
658 udelay (10); 658 udelay (10);
659 } 659 }
660 if (status != 0x55) { 660 if (status != 0x55) {
661 snd_printd("%s: Microcode initialization failed\n", __FUNCTION__); 661 snd_printd("%s: Microcode initialization failed\n", __func__);
662 goto __fail; 662 goto __fail;
663 } 663 }
664 } else { 664 } else {
@@ -824,19 +824,19 @@ static int snd_sb_csp_start(struct snd_sb_csp * p, int sample_width, int channel
824 unsigned long flags; 824 unsigned long flags;
825 825
826 if (!(p->running & (SNDRV_SB_CSP_ST_LOADED | SNDRV_SB_CSP_ST_AUTO))) { 826 if (!(p->running & (SNDRV_SB_CSP_ST_LOADED | SNDRV_SB_CSP_ST_AUTO))) {
827 snd_printd("%s: Microcode not loaded\n", __FUNCTION__); 827 snd_printd("%s: Microcode not loaded\n", __func__);
828 return -ENXIO; 828 return -ENXIO;
829 } 829 }
830 if (p->running & SNDRV_SB_CSP_ST_RUNNING) { 830 if (p->running & SNDRV_SB_CSP_ST_RUNNING) {
831 snd_printd("%s: CSP already running\n", __FUNCTION__); 831 snd_printd("%s: CSP already running\n", __func__);
832 return -EBUSY; 832 return -EBUSY;
833 } 833 }
834 if (!(sample_width & p->acc_width)) { 834 if (!(sample_width & p->acc_width)) {
835 snd_printd("%s: Unsupported PCM sample width\n", __FUNCTION__); 835 snd_printd("%s: Unsupported PCM sample width\n", __func__);
836 return -EINVAL; 836 return -EINVAL;
837 } 837 }
838 if (!(channels & p->acc_channels)) { 838 if (!(channels & p->acc_channels)) {
839 snd_printd("%s: Invalid number of channels\n", __FUNCTION__); 839 snd_printd("%s: Invalid number of channels\n", __func__);
840 return -EINVAL; 840 return -EINVAL;
841 } 841 }
842 842
@@ -858,11 +858,11 @@ static int snd_sb_csp_start(struct snd_sb_csp * p, int sample_width, int channel
858 s_type |= 0x22; /* 00dX 00dX (d = 1 if 8 bit samples) */ 858 s_type |= 0x22; /* 00dX 00dX (d = 1 if 8 bit samples) */
859 859
860 if (set_codec_parameter(p->chip, 0x81, s_type)) { 860 if (set_codec_parameter(p->chip, 0x81, s_type)) {
861 snd_printd("%s: Set sample type command failed\n", __FUNCTION__); 861 snd_printd("%s: Set sample type command failed\n", __func__);
862 goto __fail; 862 goto __fail;
863 } 863 }
864 if (set_codec_parameter(p->chip, 0x80, 0x00)) { 864 if (set_codec_parameter(p->chip, 0x80, 0x00)) {
865 snd_printd("%s: Codec start command failed\n", __FUNCTION__); 865 snd_printd("%s: Codec start command failed\n", __func__);
866 goto __fail; 866 goto __fail;
867 } 867 }
868 p->run_width = sample_width; 868 p->run_width = sample_width;
diff --git a/sound/isa/sb/sb_common.c b/sound/isa/sb/sb_common.c
index d63c1af550de..b432d9ae874b 100644
--- a/sound/isa/sb/sb_common.c
+++ b/sound/isa/sb/sb_common.c
@@ -51,7 +51,7 @@ int snd_sbdsp_command(struct snd_sb *chip, unsigned char val)
51 outb(val, SBP(chip, COMMAND)); 51 outb(val, SBP(chip, COMMAND));
52 return 1; 52 return 1;
53 } 53 }
54 snd_printd("%s [0x%lx]: timeout (0x%x)\n", __FUNCTION__, chip->port, val); 54 snd_printd("%s [0x%lx]: timeout (0x%x)\n", __func__, chip->port, val);
55 return 0; 55 return 0;
56} 56}
57 57
@@ -68,7 +68,7 @@ int snd_sbdsp_get_byte(struct snd_sb *chip)
68 return val; 68 return val;
69 } 69 }
70 } 70 }
71 snd_printd("%s [0x%lx]: timeout\n", __FUNCTION__, chip->port); 71 snd_printd("%s [0x%lx]: timeout\n", __func__, chip->port);
72 return -ENODEV; 72 return -ENODEV;
73} 73}
74 74
@@ -87,7 +87,7 @@ int snd_sbdsp_reset(struct snd_sb *chip)
87 else 87 else
88 break; 88 break;
89 } 89 }
90 snd_printdd("%s [0x%lx] failed...\n", __FUNCTION__, chip->port); 90 snd_printdd("%s [0x%lx] failed...\n", __func__, chip->port);
91 return -ENODEV; 91 return -ENODEV;
92} 92}
93 93
diff --git a/sound/oss/dmabuf.c b/sound/oss/dmabuf.c
index eaf69971bf92..1e90d769b62e 100644
--- a/sound/oss/dmabuf.c
+++ b/sound/oss/dmabuf.c
@@ -795,9 +795,9 @@ static int find_output_space(int dev, char **buf, int *size)
795#ifdef BE_CONSERVATIVE 795#ifdef BE_CONSERVATIVE
796 active_offs = dmap->byte_counter + dmap->qhead * dmap->fragment_size; 796 active_offs = dmap->byte_counter + dmap->qhead * dmap->fragment_size;
797#else 797#else
798 active_offs = DMAbuf_get_buffer_pointer(dev, dmap, DMODE_OUTPUT); 798 active_offs = max(DMAbuf_get_buffer_pointer(dev, dmap, DMODE_OUTPUT), 0);
799 /* Check for pointer wrapping situation */ 799 /* Check for pointer wrapping situation */
800 if (active_offs < 0 || active_offs >= dmap->bytes_in_use) 800 if (active_offs >= dmap->bytes_in_use)
801 active_offs = 0; 801 active_offs = 0;
802 active_offs += dmap->byte_counter; 802 active_offs += dmap->byte_counter;
803#endif 803#endif
diff --git a/sound/oss/trident.c b/sound/oss/trident.c
index d6af9065d1c0..f43f91ef86c7 100644
--- a/sound/oss/trident.c
+++ b/sound/oss/trident.c
@@ -3076,8 +3076,7 @@ ali_ac97_get(struct trident_card *card, int secondary, u8 reg)
3076 u16 wcontrol; 3076 u16 wcontrol;
3077 unsigned long flags; 3077 unsigned long flags;
3078 3078
3079 if (!card) 3079 BUG_ON(!card);
3080 BUG();
3081 3080
3082 address = ALI_AC97_READ; 3081 address = ALI_AC97_READ;
3083 if (card->revision == ALI_5451_V02) { 3082 if (card->revision == ALI_5451_V02) {
@@ -3148,8 +3147,7 @@ ali_ac97_set(struct trident_card *card, int secondary, u8 reg, u16 val)
3148 3147
3149 data = ((u32) val) << 16; 3148 data = ((u32) val) << 16;
3150 3149
3151 if (!card) 3150 BUG_ON(!card);
3152 BUG();
3153 3151
3154 address = ALI_AC97_WRITE; 3152 address = ALI_AC97_WRITE;
3155 mask = ALI_AC97_WRITE_ACTION | ALI_AC97_AUDIO_BUSY; 3153 mask = ALI_AC97_WRITE_ACTION | ALI_AC97_AUDIO_BUSY;
@@ -3213,8 +3211,7 @@ ali_ac97_read(struct ac97_codec *codec, u8 reg)
3213 struct trident_card *card = NULL; 3211 struct trident_card *card = NULL;
3214 3212
3215 /* Added by Matt Wu */ 3213 /* Added by Matt Wu */
3216 if (!codec) 3214 BUG_ON(!codec);
3217 BUG();
3218 3215
3219 card = (struct trident_card *) codec->private_data; 3216 card = (struct trident_card *) codec->private_data;
3220 3217
@@ -3240,8 +3237,7 @@ ali_ac97_write(struct ac97_codec *codec, u8 reg, u16 val)
3240 struct trident_card *card; 3237 struct trident_card *card;
3241 3238
3242 /* Added by Matt Wu */ 3239 /* Added by Matt Wu */
3243 if (!codec) 3240 BUG_ON(!codec);
3244 BUG();
3245 3241
3246 card = (struct trident_card *) codec->private_data; 3242 card = (struct trident_card *) codec->private_data;
3247 3243
diff --git a/sound/oss/trident.h b/sound/oss/trident.h
index 4713b49fc91d..ff30a1d7c2f1 100644
--- a/sound/oss/trident.h
+++ b/sound/oss/trident.h
@@ -322,7 +322,7 @@ enum miscint_bits {
322#define VALIDATE_MAGIC(FOO,MAG) \ 322#define VALIDATE_MAGIC(FOO,MAG) \
323({ \ 323({ \
324 if (!(FOO) || (FOO)->magic != MAG) { \ 324 if (!(FOO) || (FOO)->magic != MAG) { \
325 printk(invalid_magic,__FUNCTION__); \ 325 printk(invalid_magic,__func__); \
326 return -ENXIO; \ 326 return -ENXIO; \
327 } \ 327 } \
328}) 328})
diff --git a/sound/oss/vwsnd.c b/sound/oss/vwsnd.c
index d25249a932bf..2c5aaa58046d 100644
--- a/sound/oss/vwsnd.c
+++ b/sound/oss/vwsnd.c
@@ -194,11 +194,11 @@ static void dbgassert(const char *fcn, int line, const char *expr)
194 * DBGRV - debug print function return when verbose 194 * DBGRV - debug print function return when verbose
195 */ 195 */
196 196
197#define ASSERT(e) ((e) ? (void) 0 : dbgassert(__FUNCTION__, __LINE__, #e)) 197#define ASSERT(e) ((e) ? (void) 0 : dbgassert(__func__, __LINE__, #e))
198#define DBGDO(x) x 198#define DBGDO(x) x
199#define DBGX(fmt, args...) (in_interrupt() ? 0 : printk(KERN_ERR fmt, ##args)) 199#define DBGX(fmt, args...) (in_interrupt() ? 0 : printk(KERN_ERR fmt, ##args))
200#define DBGP(fmt, args...) (DBGX("%s: " fmt, __FUNCTION__ , ##args)) 200#define DBGP(fmt, args...) (DBGX("%s: " fmt, __func__ , ##args))
201#define DBGE(fmt, args...) (DBGX("%s" fmt, __FUNCTION__ , ##args)) 201#define DBGE(fmt, args...) (DBGX("%s" fmt, __func__ , ##args))
202#define DBGC(rtn) (DBGP("calling %s\n", rtn)) 202#define DBGC(rtn) (DBGP("calling %s\n", rtn))
203#define DBGR() (DBGP("returning\n")) 203#define DBGR() (DBGP("returning\n"))
204#define DBGXV(fmt, args...) (shut_up ? 0 : DBGX(fmt, ##args)) 204#define DBGXV(fmt, args...) (shut_up ? 0 : DBGX(fmt, ##args))
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
index 812085d521f1..581debf37dcb 100644
--- a/sound/pci/Kconfig
+++ b/sound/pci/Kconfig
@@ -122,6 +122,21 @@ config SND_AU8830
122 To compile this driver as a module, choose M here: the module 122 To compile this driver as a module, choose M here: the module
123 will be called snd-au8830. 123 will be called snd-au8830.
124 124
125config SND_AW2
126 tristate "Emagic Audiowerk 2"
127 depends on SND
128 help
129 Say Y here to include support for Emagic Audiowerk 2 soundcards.
130
131 Supported features: Analog and SPDIF output. Analog or SPDIF input.
132 Note: Switch between analog and digital input does not always work.
133 It can produce continuous noise. The workaround is to switch again
134 (and again) between digital and analog input until it works.
135
136 To compile this driver as a module, choose M here: the module
137 will be called snd-aw2.
138
139
125config SND_AZT3328 140config SND_AZT3328
126 tristate "Aztech AZF3328 / PCI168 (EXPERIMENTAL)" 141 tristate "Aztech AZF3328 / PCI168 (EXPERIMENTAL)"
127 depends on SND && EXPERIMENTAL 142 depends on SND && EXPERIMENTAL
@@ -162,6 +177,7 @@ config SND_CA0106
162 depends on SND 177 depends on SND
163 select SND_AC97_CODEC 178 select SND_AC97_CODEC
164 select SND_RAWMIDI 179 select SND_RAWMIDI
180 select SND_VMASTER
165 help 181 help
166 Say Y here to include support for the Sound Blaster Audigy LS 182 Say Y here to include support for the Sound Blaster Audigy LS
167 and Live 24bit. 183 and Live 24bit.
@@ -517,6 +533,7 @@ config SND_HDA_INTEL
517 tristate "Intel HD Audio" 533 tristate "Intel HD Audio"
518 depends on SND 534 depends on SND
519 select SND_PCM 535 select SND_PCM
536 select SND_VMASTER
520 help 537 help
521 Say Y here to include support for Intel "High Definition 538 Say Y here to include support for Intel "High Definition
522 Audio" (Azalia) motherboard devices. 539 Audio" (Azalia) motherboard devices.
@@ -680,6 +697,7 @@ config SND_ICE1724
680 depends on SND 697 depends on SND
681 select SND_MPU401_UART 698 select SND_MPU401_UART
682 select SND_AC97_CODEC 699 select SND_AC97_CODEC
700 select SND_VMASTER
683 help 701 help
684 Say Y here to include support for soundcards based on 702 Say Y here to include support for soundcards based on
685 ICE/VT1724/1720 (Envy24HT/PT) chips. 703 ICE/VT1724/1720 (Envy24HT/PT) chips.
@@ -896,12 +914,12 @@ config SND_VIA82XX_MODEM
896 will be called snd-via82xx-modem. 914 will be called snd-via82xx-modem.
897 915
898config SND_VIRTUOSO 916config SND_VIRTUOSO
899 tristate "Asus Virtuoso 200 (Xonar)" 917 tristate "Asus Virtuoso 100/200 (Xonar)"
900 depends on SND 918 depends on SND
901 select SND_OXYGEN_LIB 919 select SND_OXYGEN_LIB
902 help 920 help
903 Say Y here to include support for sound cards based on the 921 Say Y here to include support for sound cards based on the
904 Asus AV200 chip, i.e., Xonar D2 and Xonar D2X. 922 Asus AV100/AV200 chips, i.e., Xonar D2, DX and D2X.
905 923
906 To compile this driver as a module, choose M here: the module 924 To compile this driver as a module, choose M here: the module
907 will be called snd-virtuoso. 925 will be called snd-virtuoso.
diff --git a/sound/pci/Makefile b/sound/pci/Makefile
index 2d42fd28f4e7..85ef14bc8056 100644
--- a/sound/pci/Makefile
+++ b/sound/pci/Makefile
@@ -58,6 +58,7 @@ obj-$(CONFIG_SND) += \
58 ac97/ \ 58 ac97/ \
59 ali5451/ \ 59 ali5451/ \
60 au88x0/ \ 60 au88x0/ \
61 aw2/ \
61 ca0106/ \ 62 ca0106/ \
62 cs46xx/ \ 63 cs46xx/ \
63 cs5535audio/ \ 64 cs5535audio/ \
diff --git a/sound/pci/ac97/ac97_patch.c b/sound/pci/ac97/ac97_patch.c
index 50c637e55ffa..39198e505b12 100644
--- a/sound/pci/ac97/ac97_patch.c
+++ b/sound/pci/ac97/ac97_patch.c
@@ -114,10 +114,9 @@ static int ac97_surround_jack_mode_put(struct snd_kcontrol *kcontrol, struct snd
114 114
115static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo) 115static int ac97_channel_mode_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
116{ 116{
117 static const char *texts[] = { "2ch", "4ch", "6ch" }; 117 static const char *texts[] = { "2ch", "4ch", "6ch", "8ch" };
118 if (kcontrol->private_value) 118 return ac97_enum_text_info(kcontrol, uinfo, texts,
119 return ac97_enum_text_info(kcontrol, uinfo, texts, 2); /* 4ch only */ 119 kcontrol->private_value);
120 return ac97_enum_text_info(kcontrol, uinfo, texts, 3);
121} 120}
122 121
123static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 122static int ac97_channel_mode_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -133,13 +132,8 @@ static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
133 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol); 132 struct snd_ac97 *ac97 = snd_kcontrol_chip(kcontrol);
134 unsigned char mode = ucontrol->value.enumerated.item[0]; 133 unsigned char mode = ucontrol->value.enumerated.item[0];
135 134
136 if (kcontrol->private_value) { 135 if (mode >= kcontrol->private_value)
137 if (mode >= 2) 136 return -EINVAL;
138 return -EINVAL;
139 } else {
140 if (mode >= 3)
141 return -EINVAL;
142 }
143 137
144 if (mode != ac97->channel_mode) { 138 if (mode != ac97->channel_mode) {
145 ac97->channel_mode = mode; 139 ac97->channel_mode = mode;
@@ -158,6 +152,7 @@ static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
158 .get = ac97_surround_jack_mode_get, \ 152 .get = ac97_surround_jack_mode_get, \
159 .put = ac97_surround_jack_mode_put, \ 153 .put = ac97_surround_jack_mode_put, \
160 } 154 }
155/* 6ch */
161#define AC97_CHANNEL_MODE_CTL \ 156#define AC97_CHANNEL_MODE_CTL \
162 { \ 157 { \
163 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 158 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
@@ -165,7 +160,9 @@ static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
165 .info = ac97_channel_mode_info, \ 160 .info = ac97_channel_mode_info, \
166 .get = ac97_channel_mode_get, \ 161 .get = ac97_channel_mode_get, \
167 .put = ac97_channel_mode_put, \ 162 .put = ac97_channel_mode_put, \
163 .private_value = 3, \
168 } 164 }
165/* 4ch */
169#define AC97_CHANNEL_MODE_4CH_CTL \ 166#define AC97_CHANNEL_MODE_4CH_CTL \
170 { \ 167 { \
171 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 168 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
@@ -173,7 +170,17 @@ static int ac97_channel_mode_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
173 .info = ac97_channel_mode_info, \ 170 .info = ac97_channel_mode_info, \
174 .get = ac97_channel_mode_get, \ 171 .get = ac97_channel_mode_get, \
175 .put = ac97_channel_mode_put, \ 172 .put = ac97_channel_mode_put, \
176 .private_value = 1, \ 173 .private_value = 2, \
174 }
175/* 8ch */
176#define AC97_CHANNEL_MODE_8CH_CTL \
177 { \
178 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
179 .name = "Channel Mode", \
180 .info = ac97_channel_mode_info, \
181 .get = ac97_channel_mode_get, \
182 .put = ac97_channel_mode_put, \
183 .private_value = 4, \
177 } 184 }
178 185
179static inline int is_surround_on(struct snd_ac97 *ac97) 186static inline int is_surround_on(struct snd_ac97 *ac97)
@@ -210,6 +217,10 @@ static inline int is_shared_micin(struct snd_ac97 *ac97)
210 return !ac97->indep_surround && !is_clfe_on(ac97); 217 return !ac97->indep_surround && !is_clfe_on(ac97);
211} 218}
212 219
220static inline int alc850_is_aux_back_surround(struct snd_ac97 *ac97)
221{
222 return is_surround_on(ac97);
223}
213 224
214/* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */ 225/* The following snd_ac97_ymf753_... items added by David Shust (dshust@shustring.com) */
215/* Modified for YMF743 by Keita Maehara <maehara@debian.org> */ 226/* Modified for YMF743 by Keita Maehara <maehara@debian.org> */
@@ -2816,10 +2827,12 @@ static int patch_alc655(struct snd_ac97 * ac97)
2816 2827
2817#define AC97_ALC850_JACK_SELECT 0x76 2828#define AC97_ALC850_JACK_SELECT 0x76
2818#define AC97_ALC850_MISC1 0x7a 2829#define AC97_ALC850_MISC1 0x7a
2830#define AC97_ALC850_MULTICH 0x6a
2819 2831
2820static void alc850_update_jacks(struct snd_ac97 *ac97) 2832static void alc850_update_jacks(struct snd_ac97 *ac97)
2821{ 2833{
2822 int shared; 2834 int shared;
2835 int aux_is_back_surround;
2823 2836
2824 /* shared Line-In / Surround Out */ 2837 /* shared Line-In / Surround Out */
2825 shared = is_shared_surrout(ac97); 2838 shared = is_shared_surrout(ac97);
@@ -2837,13 +2850,18 @@ static void alc850_update_jacks(struct snd_ac97 *ac97)
2837 /* MIC-IN = 1, CENTER-LFE = 5 */ 2850 /* MIC-IN = 1, CENTER-LFE = 5 */
2838 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4, 2851 snd_ac97_update_bits(ac97, AC97_ALC850_JACK_SELECT, 7 << 4,
2839 shared ? (5<<4) : (1<<4)); 2852 shared ? (5<<4) : (1<<4));
2853
2854 aux_is_back_surround = alc850_is_aux_back_surround(ac97);
2855 /* Aux is Back Surround */
2856 snd_ac97_update_bits(ac97, AC97_ALC850_MULTICH, 1 << 10,
2857 aux_is_back_surround ? (1<<10) : (0<<10));
2840} 2858}
2841 2859
2842static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = { 2860static const struct snd_kcontrol_new snd_ac97_controls_alc850[] = {
2843 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0), 2861 AC97_PAGE_SINGLE("Duplicate Front", AC97_ALC650_MULTICH, 0, 1, 0, 0),
2844 AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1), 2862 AC97_SINGLE("Mic Front Input Switch", AC97_ALC850_JACK_SELECT, 15, 1, 1),
2845 AC97_SURROUND_JACK_MODE_CTL, 2863 AC97_SURROUND_JACK_MODE_CTL,
2846 AC97_CHANNEL_MODE_CTL, 2864 AC97_CHANNEL_MODE_8CH_CTL,
2847}; 2865};
2848 2866
2849static int patch_alc850_specific(struct snd_ac97 *ac97) 2867static int patch_alc850_specific(struct snd_ac97 *ac97)
@@ -2869,6 +2887,7 @@ static int patch_alc850(struct snd_ac97 *ac97)
2869 ac97->build_ops = &patch_alc850_ops; 2887 ac97->build_ops = &patch_alc850_ops;
2870 2888
2871 ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */ 2889 ac97->spec.dev_flags = 0; /* for IEC958 playback route - ALC655 compatible */
2890 ac97->flags |= AC97_HAS_8CH;
2872 2891
2873 /* assume only page 0 for writing cache */ 2892 /* assume only page 0 for writing cache */
2874 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR); 2893 snd_ac97_update_bits(ac97, AC97_INT_PAGING, AC97_PAGE_MASK, AC97_PAGE_VENDOR);
@@ -2878,6 +2897,7 @@ static int patch_alc850(struct snd_ac97 *ac97)
2878 spdif-in monitor off, spdif-in PCM off 2897 spdif-in monitor off, spdif-in PCM off
2879 center on mic off, surround on line-in off 2898 center on mic off, surround on line-in off
2880 duplicate front off 2899 duplicate front off
2900 NB default bit 10=0 = Aux is Capture, not Back Surround
2881 */ 2901 */
2882 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15); 2902 snd_ac97_write_cache(ac97, AC97_ALC650_MULTICH, 1<<15);
2883 /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off 2903 /* SURR_OUT: on, Surr 1kOhm: on, Surr Amp: off, Front 1kOhm: off
diff --git a/sound/pci/ac97/ac97_pcm.c b/sound/pci/ac97/ac97_pcm.c
index 3674f35c4a79..48cbda9378c5 100644
--- a/sound/pci/ac97/ac97_pcm.c
+++ b/sound/pci/ac97/ac97_pcm.c
@@ -574,7 +574,6 @@ int snd_ac97_pcm_open(struct ac97_pcm *pcm, unsigned int rate,
574 r = rate > 48000; 574 r = rate > 48000;
575 bus = pcm->bus; 575 bus = pcm->bus;
576 if (cfg == AC97_PCM_CFG_SPDIF) { 576 if (cfg == AC97_PCM_CFG_SPDIF) {
577 int err;
578 for (cidx = 0; cidx < 4; cidx++) 577 for (cidx = 0; cidx < 4; cidx++)
579 if (bus->codec[cidx] && (bus->codec[cidx]->ext_id & AC97_EI_SPDIF)) { 578 if (bus->codec[cidx] && (bus->codec[cidx]->ext_id & AC97_EI_SPDIF)) {
580 err = set_spdif_rate(bus->codec[cidx], rate); 579 err = set_spdif_rate(bus->codec[cidx], rate);
diff --git a/sound/pci/ad1889.c b/sound/pci/ad1889.c
index a66d5150bb7a..39ec55b57b1e 100644
--- a/sound/pci/ad1889.c
+++ b/sound/pci/ad1889.c
@@ -264,10 +264,10 @@ snd_ad1889_ac97_ready(struct snd_ad1889 *chip)
264 mdelay(1); 264 mdelay(1);
265 if (!retry) { 265 if (!retry) {
266 snd_printk(KERN_ERR PFX "[%s] Link is not ready.\n", 266 snd_printk(KERN_ERR PFX "[%s] Link is not ready.\n",
267 __FUNCTION__); 267 __func__);
268 return -EIO; 268 return -EIO;
269 } 269 }
270 ad1889_debug("[%s] ready after %d ms\n", __FUNCTION__, 400 - retry); 270 ad1889_debug("[%s] ready after %d ms\n", __func__, 400 - retry);
271 271
272 return 0; 272 return 0;
273} 273}
@@ -854,8 +854,6 @@ snd_ad1889_free(struct snd_ad1889 *chip)
854 854
855 spin_unlock_irq(&chip->lock); 855 spin_unlock_irq(&chip->lock);
856 856
857 synchronize_irq(chip->irq);
858
859 if (chip->irq >= 0) 857 if (chip->irq >= 0)
860 free_irq(chip->irq, chip); 858 free_irq(chip->irq, chip);
861 859
diff --git a/sound/pci/ali5451/ali5451.c b/sound/pci/ali5451/ali5451.c
index 6a905ed9cbd6..1a0fd65ec280 100644
--- a/sound/pci/ali5451/ali5451.c
+++ b/sound/pci/ali5451/ali5451.c
@@ -1809,26 +1809,26 @@ static int snd_ali5451_spdif_get(struct snd_kcontrol *kcontrol,
1809 struct snd_ctl_elem_value *ucontrol) 1809 struct snd_ctl_elem_value *ucontrol)
1810{ 1810{
1811 struct snd_ali *codec = kcontrol->private_data; 1811 struct snd_ali *codec = kcontrol->private_data;
1812 unsigned int enable; 1812 unsigned int spdif_enable;
1813 1813
1814 enable = ucontrol->value.integer.value[0] ? 1 : 0; 1814 spdif_enable = ucontrol->value.integer.value[0] ? 1 : 0;
1815 1815
1816 spin_lock_irq(&codec->reg_lock); 1816 spin_lock_irq(&codec->reg_lock);
1817 switch (kcontrol->private_value) { 1817 switch (kcontrol->private_value) {
1818 case 0: 1818 case 0:
1819 enable = (codec->spdif_mask & 0x02) ? 1 : 0; 1819 spdif_enable = (codec->spdif_mask & 0x02) ? 1 : 0;
1820 break; 1820 break;
1821 case 1: 1821 case 1:
1822 enable = ((codec->spdif_mask & 0x02) && 1822 spdif_enable = ((codec->spdif_mask & 0x02) &&
1823 (codec->spdif_mask & 0x04)) ? 1 : 0; 1823 (codec->spdif_mask & 0x04)) ? 1 : 0;
1824 break; 1824 break;
1825 case 2: 1825 case 2:
1826 enable = (codec->spdif_mask & 0x01) ? 1 : 0; 1826 spdif_enable = (codec->spdif_mask & 0x01) ? 1 : 0;
1827 break; 1827 break;
1828 default: 1828 default:
1829 break; 1829 break;
1830 } 1830 }
1831 ucontrol->value.integer.value[0] = enable; 1831 ucontrol->value.integer.value[0] = spdif_enable;
1832 spin_unlock_irq(&codec->reg_lock); 1832 spin_unlock_irq(&codec->reg_lock);
1833 return 0; 1833 return 0;
1834} 1834}
@@ -1837,17 +1837,17 @@ static int snd_ali5451_spdif_put(struct snd_kcontrol *kcontrol,
1837 struct snd_ctl_elem_value *ucontrol) 1837 struct snd_ctl_elem_value *ucontrol)
1838{ 1838{
1839 struct snd_ali *codec = kcontrol->private_data; 1839 struct snd_ali *codec = kcontrol->private_data;
1840 unsigned int change = 0, enable = 0; 1840 unsigned int change = 0, spdif_enable = 0;
1841 1841
1842 enable = ucontrol->value.integer.value[0] ? 1 : 0; 1842 spdif_enable = ucontrol->value.integer.value[0] ? 1 : 0;
1843 1843
1844 spin_lock_irq(&codec->reg_lock); 1844 spin_lock_irq(&codec->reg_lock);
1845 switch (kcontrol->private_value) { 1845 switch (kcontrol->private_value) {
1846 case 0: 1846 case 0:
1847 change = (codec->spdif_mask & 0x02) ? 1 : 0; 1847 change = (codec->spdif_mask & 0x02) ? 1 : 0;
1848 change = change ^ enable; 1848 change = change ^ spdif_enable;
1849 if (change) { 1849 if (change) {
1850 if (enable) { 1850 if (spdif_enable) {
1851 codec->spdif_mask |= 0x02; 1851 codec->spdif_mask |= 0x02;
1852 snd_ali_enable_spdif_out(codec); 1852 snd_ali_enable_spdif_out(codec);
1853 } else { 1853 } else {
@@ -1859,9 +1859,9 @@ static int snd_ali5451_spdif_put(struct snd_kcontrol *kcontrol,
1859 break; 1859 break;
1860 case 1: 1860 case 1:
1861 change = (codec->spdif_mask & 0x04) ? 1 : 0; 1861 change = (codec->spdif_mask & 0x04) ? 1 : 0;
1862 change = change ^ enable; 1862 change = change ^ spdif_enable;
1863 if (change && (codec->spdif_mask & 0x02)) { 1863 if (change && (codec->spdif_mask & 0x02)) {
1864 if (enable) { 1864 if (spdif_enable) {
1865 codec->spdif_mask |= 0x04; 1865 codec->spdif_mask |= 0x04;
1866 snd_ali_enable_spdif_chnout(codec); 1866 snd_ali_enable_spdif_chnout(codec);
1867 } else { 1867 } else {
@@ -1872,9 +1872,9 @@ static int snd_ali5451_spdif_put(struct snd_kcontrol *kcontrol,
1872 break; 1872 break;
1873 case 2: 1873 case 2:
1874 change = (codec->spdif_mask & 0x01) ? 1 : 0; 1874 change = (codec->spdif_mask & 0x01) ? 1 : 0;
1875 change = change ^ enable; 1875 change = change ^ spdif_enable;
1876 if (change) { 1876 if (change) {
1877 if (enable) { 1877 if (spdif_enable) {
1878 codec->spdif_mask |= 0x01; 1878 codec->spdif_mask |= 0x01;
1879 snd_ali_enable_spdif_in(codec); 1879 snd_ali_enable_spdif_in(codec);
1880 } else { 1880 } else {
@@ -2047,10 +2047,8 @@ static int snd_ali_free(struct snd_ali * codec)
2047{ 2047{
2048 if (codec->hw_initialized) 2048 if (codec->hw_initialized)
2049 snd_ali_disable_address_interrupt(codec); 2049 snd_ali_disable_address_interrupt(codec);
2050 if (codec->irq >= 0) { 2050 if (codec->irq >= 0)
2051 synchronize_irq(codec->irq);
2052 free_irq(codec->irq, codec); 2051 free_irq(codec->irq, codec);
2053 }
2054 if (codec->port) 2052 if (codec->port)
2055 pci_release_regions(codec->pci); 2053 pci_release_regions(codec->pci);
2056 pci_disable_device(codec->pci); 2054 pci_disable_device(codec->pci);
diff --git a/sound/pci/als300.c b/sound/pci/als300.c
index 0e990a735821..8df6824b51cd 100644
--- a/sound/pci/als300.c
+++ b/sound/pci/als300.c
@@ -92,8 +92,8 @@
92 92
93#if DEBUG_CALLS 93#if DEBUG_CALLS
94#define snd_als300_dbgcalls(format, args...) printk(format, ##args) 94#define snd_als300_dbgcalls(format, args...) printk(format, ##args)
95#define snd_als300_dbgcallenter() printk(KERN_ERR "--> %s\n", __FUNCTION__) 95#define snd_als300_dbgcallenter() printk(KERN_ERR "--> %s\n", __func__)
96#define snd_als300_dbgcallleave() printk(KERN_ERR "<-- %s\n", __FUNCTION__) 96#define snd_als300_dbgcallleave() printk(KERN_ERR "<-- %s\n", __func__)
97#else 97#else
98#define snd_als300_dbgcalls(format, args...) 98#define snd_als300_dbgcalls(format, args...)
99#define snd_als300_dbgcallenter() 99#define snd_als300_dbgcallenter()
diff --git a/sound/pci/atiixp.c b/sound/pci/atiixp.c
index 4594186b83ee..457228fb22aa 100644
--- a/sound/pci/atiixp.c
+++ b/sound/pci/atiixp.c
@@ -1553,7 +1553,7 @@ static int snd_atiixp_free(struct atiixp *chip)
1553 if (chip->irq < 0) 1553 if (chip->irq < 0)
1554 goto __hw_end; 1554 goto __hw_end;
1555 snd_atiixp_chip_stop(chip); 1555 snd_atiixp_chip_stop(chip);
1556 synchronize_irq(chip->irq); 1556
1557 __hw_end: 1557 __hw_end:
1558 if (chip->irq >= 0) 1558 if (chip->irq >= 0)
1559 free_irq(chip->irq, chip); 1559 free_irq(chip->irq, chip);
diff --git a/sound/pci/atiixp_modem.c b/sound/pci/atiixp_modem.c
index a67a869180d4..d457a32a7939 100644
--- a/sound/pci/atiixp_modem.c
+++ b/sound/pci/atiixp_modem.c
@@ -1197,7 +1197,7 @@ static int snd_atiixp_free(struct atiixp_modem *chip)
1197 if (chip->irq < 0) 1197 if (chip->irq < 0)
1198 goto __hw_end; 1198 goto __hw_end;
1199 snd_atiixp_chip_stop(chip); 1199 snd_atiixp_chip_stop(chip);
1200 synchronize_irq(chip->irq); 1200
1201 __hw_end: 1201 __hw_end:
1202 if (chip->irq >= 0) 1202 if (chip->irq >= 0)
1203 free_irq(chip->irq, chip); 1203 free_irq(chip->irq, chip);
diff --git a/sound/pci/au88x0/au88x0.c b/sound/pci/au88x0/au88x0.c
index 26819e2f5761..68368e490074 100644
--- a/sound/pci/au88x0/au88x0.c
+++ b/sound/pci/au88x0/au88x0.c
@@ -126,7 +126,6 @@ static int snd_vortex_dev_free(struct snd_device *device)
126 vortex_gameport_unregister(vortex); 126 vortex_gameport_unregister(vortex);
127 vortex_core_shutdown(vortex); 127 vortex_core_shutdown(vortex);
128 // Take down PCI interface. 128 // Take down PCI interface.
129 synchronize_irq(vortex->irq);
130 free_irq(vortex->irq, vortex); 129 free_irq(vortex->irq, vortex);
131 iounmap(vortex->mmio); 130 iounmap(vortex->mmio);
132 pci_release_regions(vortex->pci_dev); 131 pci_release_regions(vortex->pci_dev);
@@ -220,7 +219,6 @@ snd_vortex_create(struct snd_card *card, struct pci_dev *pci, vortex_t ** rchip)
220 return 0; 219 return 0;
221 220
222 alloc_out: 221 alloc_out:
223 synchronize_irq(chip->irq);
224 free_irq(chip->irq, chip); 222 free_irq(chip->irq, chip);
225 irq_out: 223 irq_out:
226 vortex_core_shutdown(chip); 224 vortex_core_shutdown(chip);
diff --git a/sound/pci/au88x0/au88x0_pcm.c b/sound/pci/au88x0/au88x0_pcm.c
index 526c6c5ecf7b..f9a58b4a30eb 100644
--- a/sound/pci/au88x0/au88x0_pcm.c
+++ b/sound/pci/au88x0/au88x0_pcm.c
@@ -498,14 +498,14 @@ static struct snd_kcontrol_new snd_vortex_mixer_spdif[] __devinitdata = {
498}; 498};
499 499
500/* create a pcm device */ 500/* create a pcm device */
501static int __devinit snd_vortex_new_pcm(vortex_t * chip, int idx, int nr) 501static int __devinit snd_vortex_new_pcm(vortex_t *chip, int idx, int nr)
502{ 502{
503 struct snd_pcm *pcm; 503 struct snd_pcm *pcm;
504 struct snd_kcontrol *kctl; 504 struct snd_kcontrol *kctl;
505 int i; 505 int i;
506 int err, nr_capt; 506 int err, nr_capt;
507 507
508 if ((chip == 0) || (idx < 0) || (idx >= VORTEX_PCM_LAST)) 508 if (!chip || idx < 0 || idx >= VORTEX_PCM_LAST)
509 return -ENODEV; 509 return -ENODEV;
510 510
511 /* idx indicates which kind of PCM device. ADB, SPDIF, I2S and A3D share the 511 /* idx indicates which kind of PCM device. ADB, SPDIF, I2S and A3D share the
@@ -514,9 +514,9 @@ static int __devinit snd_vortex_new_pcm(vortex_t * chip, int idx, int nr)
514 nr_capt = nr; 514 nr_capt = nr;
515 else 515 else
516 nr_capt = 0; 516 nr_capt = 0;
517 if ((err = 517 err = snd_pcm_new(chip->card, vortex_pcm_prettyname[idx], idx, nr,
518 snd_pcm_new(chip->card, vortex_pcm_prettyname[idx], idx, nr, 518 nr_capt, &pcm);
519 nr_capt, &pcm)) < 0) 519 if (err < 0)
520 return err; 520 return err;
521 strcpy(pcm->name, vortex_pcm_name[idx]); 521 strcpy(pcm->name, vortex_pcm_name[idx]);
522 chip->pcm[idx] = pcm; 522 chip->pcm[idx] = pcm;
diff --git a/sound/pci/aw2/Makefile b/sound/pci/aw2/Makefile
new file mode 100644
index 000000000000..842335d3b735
--- /dev/null
+++ b/sound/pci/aw2/Makefile
@@ -0,0 +1,3 @@
1snd-aw2-objs := aw2-alsa.o aw2-saa7146.o
2
3obj-$(CONFIG_SND_AW2) += snd-aw2.o
diff --git a/sound/pci/aw2/aw2-alsa.c b/sound/pci/aw2/aw2-alsa.c
new file mode 100644
index 000000000000..56f87cd33c19
--- /dev/null
+++ b/sound/pci/aw2/aw2-alsa.c
@@ -0,0 +1,794 @@
1/*****************************************************************************
2 *
3 * Copyright (C) 2008 Cedric Bregardis <cedric.bregardis@free.fr> and
4 * Jean-Christian Hassler <jhassler@free.fr>
5 *
6 * This file is part of the Audiowerk2 ALSA driver
7 *
8 * The Audiowerk2 ALSA driver is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2.
11 *
12 * The Audiowerk2 ALSA driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with the Audiowerk2 ALSA driver; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 * USA.
21 *
22 *****************************************************************************/
23#include <linux/init.h>
24#include <linux/pci.h>
25#include <linux/dma-mapping.h>
26#include <linux/slab.h>
27#include <linux/interrupt.h>
28#include <linux/delay.h>
29#include <asm/io.h>
30#include <sound/core.h>
31#include <sound/initval.h>
32#include <sound/pcm.h>
33#include <sound/pcm_params.h>
34#include <sound/control.h>
35
36#include "saa7146.h"
37#include "aw2-saa7146.h"
38
39MODULE_AUTHOR("Cedric Bregardis <cedric.bregardis@free.fr>, "
40 "Jean-Christian Hassler <jhassler@free.fr>");
41MODULE_DESCRIPTION("Emagic Audiowerk 2 sound driver");
42MODULE_LICENSE("GPL");
43
44/*********************************
45 * DEFINES
46 ********************************/
47#define PCI_VENDOR_ID_SAA7146 0x1131
48#define PCI_DEVICE_ID_SAA7146 0x7146
49
50#define CTL_ROUTE_ANALOG 0
51#define CTL_ROUTE_DIGITAL 1
52
53/*********************************
54 * TYPEDEFS
55 ********************************/
56 /* hardware definition */
57static struct snd_pcm_hardware snd_aw2_playback_hw = {
58 .info = (SNDRV_PCM_INFO_MMAP |
59 SNDRV_PCM_INFO_INTERLEAVED |
60 SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID),
61 .formats = SNDRV_PCM_FMTBIT_S16_LE,
62 .rates = SNDRV_PCM_RATE_44100,
63 .rate_min = 44100,
64 .rate_max = 44100,
65 .channels_min = 2,
66 .channels_max = 4,
67 .buffer_bytes_max = 32768,
68 .period_bytes_min = 4096,
69 .period_bytes_max = 32768,
70 .periods_min = 1,
71 .periods_max = 1024,
72};
73
74static struct snd_pcm_hardware snd_aw2_capture_hw = {
75 .info = (SNDRV_PCM_INFO_MMAP |
76 SNDRV_PCM_INFO_INTERLEAVED |
77 SNDRV_PCM_INFO_BLOCK_TRANSFER | SNDRV_PCM_INFO_MMAP_VALID),
78 .formats = SNDRV_PCM_FMTBIT_S16_LE,
79 .rates = SNDRV_PCM_RATE_44100,
80 .rate_min = 44100,
81 .rate_max = 44100,
82 .channels_min = 2,
83 .channels_max = 2,
84 .buffer_bytes_max = 32768,
85 .period_bytes_min = 4096,
86 .period_bytes_max = 32768,
87 .periods_min = 1,
88 .periods_max = 1024,
89};
90
91struct aw2_pcm_device {
92 struct snd_pcm *pcm;
93 unsigned int stream_number;
94 struct aw2 *chip;
95};
96
97struct aw2 {
98 struct snd_aw2_saa7146 saa7146;
99
100 struct pci_dev *pci;
101 int irq;
102 spinlock_t reg_lock;
103 struct mutex mtx;
104
105 unsigned long iobase_phys;
106 void __iomem *iobase_virt;
107
108 struct snd_card *card;
109
110 struct aw2_pcm_device device_playback[NB_STREAM_PLAYBACK];
111 struct aw2_pcm_device device_capture[NB_STREAM_CAPTURE];
112};
113
114/*********************************
115 * FUNCTION DECLARATIONS
116 ********************************/
117static int __init alsa_card_aw2_init(void);
118static void __exit alsa_card_aw2_exit(void);
119static int snd_aw2_dev_free(struct snd_device *device);
120static int __devinit snd_aw2_create(struct snd_card *card,
121 struct pci_dev *pci, struct aw2 **rchip);
122static int __devinit snd_aw2_probe(struct pci_dev *pci,
123 const struct pci_device_id *pci_id);
124static void __devexit snd_aw2_remove(struct pci_dev *pci);
125static int snd_aw2_pcm_playback_open(struct snd_pcm_substream *substream);
126static int snd_aw2_pcm_playback_close(struct snd_pcm_substream *substream);
127static int snd_aw2_pcm_capture_open(struct snd_pcm_substream *substream);
128static int snd_aw2_pcm_capture_close(struct snd_pcm_substream *substream);
129static int snd_aw2_pcm_hw_params(struct snd_pcm_substream *substream,
130 struct snd_pcm_hw_params *hw_params);
131static int snd_aw2_pcm_hw_free(struct snd_pcm_substream *substream);
132static int snd_aw2_pcm_prepare_playback(struct snd_pcm_substream *substream);
133static int snd_aw2_pcm_prepare_capture(struct snd_pcm_substream *substream);
134static int snd_aw2_pcm_trigger_playback(struct snd_pcm_substream *substream,
135 int cmd);
136static int snd_aw2_pcm_trigger_capture(struct snd_pcm_substream *substream,
137 int cmd);
138static snd_pcm_uframes_t snd_aw2_pcm_pointer_playback(struct snd_pcm_substream
139 *substream);
140static snd_pcm_uframes_t snd_aw2_pcm_pointer_capture(struct snd_pcm_substream
141 *substream);
142static int __devinit snd_aw2_new_pcm(struct aw2 *chip);
143
144static int snd_aw2_control_switch_capture_info(struct snd_kcontrol *kcontrol,
145 struct snd_ctl_elem_info *uinfo);
146static int snd_aw2_control_switch_capture_get(struct snd_kcontrol *kcontrol,
147 struct snd_ctl_elem_value
148 *ucontrol);
149static int snd_aw2_control_switch_capture_put(struct snd_kcontrol *kcontrol,
150 struct snd_ctl_elem_value
151 *ucontrol);
152
153/*********************************
154 * VARIABLES
155 ********************************/
156static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
157static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
158static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;
159
160module_param_array(index, int, NULL, 0444);
161MODULE_PARM_DESC(index, "Index value for Audiowerk2 soundcard.");
162module_param_array(id, charp, NULL, 0444);
163MODULE_PARM_DESC(id, "ID string for the Audiowerk2 soundcard.");
164module_param_array(enable, bool, NULL, 0444);
165MODULE_PARM_DESC(enable, "Enable Audiowerk2 soundcard.");
166
167static struct pci_device_id snd_aw2_ids[] = {
168 {PCI_VENDOR_ID_SAA7146, PCI_DEVICE_ID_SAA7146, PCI_ANY_ID, PCI_ANY_ID,
169 0, 0, 0},
170 {0}
171};
172
173MODULE_DEVICE_TABLE(pci, snd_aw2_ids);
174
175/* pci_driver definition */
176static struct pci_driver driver = {
177 .name = "Emagic Audiowerk 2",
178 .id_table = snd_aw2_ids,
179 .probe = snd_aw2_probe,
180 .remove = __devexit_p(snd_aw2_remove),
181};
182
183/* operators for playback PCM alsa interface */
184static struct snd_pcm_ops snd_aw2_playback_ops = {
185 .open = snd_aw2_pcm_playback_open,
186 .close = snd_aw2_pcm_playback_close,
187 .ioctl = snd_pcm_lib_ioctl,
188 .hw_params = snd_aw2_pcm_hw_params,
189 .hw_free = snd_aw2_pcm_hw_free,
190 .prepare = snd_aw2_pcm_prepare_playback,
191 .trigger = snd_aw2_pcm_trigger_playback,
192 .pointer = snd_aw2_pcm_pointer_playback,
193};
194
195/* operators for capture PCM alsa interface */
196static struct snd_pcm_ops snd_aw2_capture_ops = {
197 .open = snd_aw2_pcm_capture_open,
198 .close = snd_aw2_pcm_capture_close,
199 .ioctl = snd_pcm_lib_ioctl,
200 .hw_params = snd_aw2_pcm_hw_params,
201 .hw_free = snd_aw2_pcm_hw_free,
202 .prepare = snd_aw2_pcm_prepare_capture,
203 .trigger = snd_aw2_pcm_trigger_capture,
204 .pointer = snd_aw2_pcm_pointer_capture,
205};
206
207static struct snd_kcontrol_new aw2_control __devinitdata = {
208 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
209 .name = "PCM Capture Route",
210 .index = 0,
211 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE,
212 .private_value = 0xffff,
213 .info = snd_aw2_control_switch_capture_info,
214 .get = snd_aw2_control_switch_capture_get,
215 .put = snd_aw2_control_switch_capture_put
216};
217
218/*********************************
219 * FUNCTION IMPLEMENTATIONS
220 ********************************/
221
222/* initialization of the module */
223static int __init alsa_card_aw2_init(void)
224{
225 snd_printdd(KERN_DEBUG "aw2: Load aw2 module\n");
226 return pci_register_driver(&driver);
227}
228
229/* clean up the module */
230static void __exit alsa_card_aw2_exit(void)
231{
232 snd_printdd(KERN_DEBUG "aw2: Unload aw2 module\n");
233 pci_unregister_driver(&driver);
234}
235
236module_init(alsa_card_aw2_init);
237module_exit(alsa_card_aw2_exit);
238
239/* component-destructor */
240static int snd_aw2_dev_free(struct snd_device *device)
241{
242 struct aw2 *chip = device->device_data;
243
244 /* Free hardware */
245 snd_aw2_saa7146_free(&chip->saa7146);
246
247 /* release the irq */
248 if (chip->irq >= 0)
249 free_irq(chip->irq, (void *)chip);
250 /* release the i/o ports & memory */
251 if (chip->iobase_virt)
252 iounmap(chip->iobase_virt);
253
254 pci_release_regions(chip->pci);
255 /* disable the PCI entry */
256 pci_disable_device(chip->pci);
257 /* release the data */
258 kfree(chip);
259
260 return 0;
261}
262
263/* chip-specific constructor */
264static int __devinit snd_aw2_create(struct snd_card *card,
265 struct pci_dev *pci, struct aw2 **rchip)
266{
267 struct aw2 *chip;
268 int err;
269 static struct snd_device_ops ops = {
270 .dev_free = snd_aw2_dev_free,
271 };
272
273 *rchip = NULL;
274
275 /* initialize the PCI entry */
276 err = pci_enable_device(pci);
277 if (err < 0)
278 return err;
279 pci_set_master(pci);
280
281 /* check PCI availability (32bit DMA) */
282 if ((pci_set_dma_mask(pci, DMA_32BIT_MASK) < 0) ||
283 (pci_set_consistent_dma_mask(pci, DMA_32BIT_MASK) < 0)) {
284 printk(KERN_ERR "aw2: Impossible to set 32bit mask DMA\n");
285 pci_disable_device(pci);
286 return -ENXIO;
287 }
288 chip = kzalloc(sizeof(*chip), GFP_KERNEL);
289 if (chip == NULL) {
290 pci_disable_device(pci);
291 return -ENOMEM;
292 }
293
294 /* initialize the stuff */
295 chip->card = card;
296 chip->pci = pci;
297 chip->irq = -1;
298
299 /* (1) PCI resource allocation */
300 err = pci_request_regions(pci, "Audiowerk2");
301 if (err < 0) {
302 pci_disable_device(pci);
303 kfree(chip);
304 return err;
305 }
306 chip->iobase_phys = pci_resource_start(pci, 0);
307 chip->iobase_virt =
308 ioremap_nocache(chip->iobase_phys,
309 pci_resource_len(pci, 0));
310
311 if (chip->iobase_virt == NULL) {
312 printk(KERN_ERR "aw2: unable to remap memory region");
313 pci_release_regions(pci);
314 pci_disable_device(pci);
315 kfree(chip);
316 return -ENOMEM;
317 }
318
319
320 if (request_irq(pci->irq, snd_aw2_saa7146_interrupt,
321 IRQF_SHARED, "Audiowerk2", chip)) {
322 printk(KERN_ERR "aw2: Cannot grab irq %d\n", pci->irq);
323
324 iounmap(chip->iobase_virt);
325 pci_release_regions(chip->pci);
326 pci_disable_device(chip->pci);
327 kfree(chip);
328 return -EBUSY;
329 }
330 chip->irq = pci->irq;
331
332 /* (2) initialization of the chip hardware */
333 snd_aw2_saa7146_setup(&chip->saa7146, chip->iobase_virt);
334 err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
335 if (err < 0) {
336 free_irq(chip->irq, (void *)chip);
337 iounmap(chip->iobase_virt);
338 pci_release_regions(chip->pci);
339 pci_disable_device(chip->pci);
340 kfree(chip);
341 return err;
342 }
343
344 snd_card_set_dev(card, &pci->dev);
345 *rchip = chip;
346
347 printk(KERN_INFO
348 "Audiowerk 2 sound card (saa7146 chipset) detected and "
349 "managed\n");
350 return 0;
351}
352
353/* constructor */
354static int __devinit snd_aw2_probe(struct pci_dev *pci,
355 const struct pci_device_id *pci_id)
356{
357 static int dev;
358 struct snd_card *card;
359 struct aw2 *chip;
360 int err;
361
362 /* (1) Continue if device is not enabled, else inc dev */
363 if (dev >= SNDRV_CARDS)
364 return -ENODEV;
365 if (!enable[dev]) {
366 dev++;
367 return -ENOENT;
368 }
369
370 /* (2) Create card instance */
371 card = snd_card_new(index[dev], id[dev], THIS_MODULE, 0);
372 if (card == NULL)
373 return -ENOMEM;
374
375 /* (3) Create main component */
376 err = snd_aw2_create(card, pci, &chip);
377 if (err < 0) {
378 snd_card_free(card);
379 return err;
380 }
381
382 /* initialize mutex */
383 mutex_init(&chip->mtx);
384 /* init spinlock */
385 spin_lock_init(&chip->reg_lock);
386 /* (4) Define driver ID and name string */
387 strcpy(card->driver, "aw2");
388 strcpy(card->shortname, "Audiowerk2");
389
390 sprintf(card->longname, "%s with SAA7146 irq %i",
391 card->shortname, chip->irq);
392
393 /* (5) Create other components */
394 snd_aw2_new_pcm(chip);
395
396 /* (6) Register card instance */
397 err = snd_card_register(card);
398 if (err < 0) {
399 snd_card_free(card);
400 return err;
401 }
402
403 /* (7) Set PCI driver data */
404 pci_set_drvdata(pci, card);
405
406 dev++;
407 return 0;
408}
409
410/* destructor */
411static void __devexit snd_aw2_remove(struct pci_dev *pci)
412{
413 snd_card_free(pci_get_drvdata(pci));
414 pci_set_drvdata(pci, NULL);
415}
416
417/* open callback */
418static int snd_aw2_pcm_playback_open(struct snd_pcm_substream *substream)
419{
420 struct snd_pcm_runtime *runtime = substream->runtime;
421
422 snd_printdd(KERN_DEBUG "aw2: Playback_open \n");
423 runtime->hw = snd_aw2_playback_hw;
424 return 0;
425}
426
427/* close callback */
428static int snd_aw2_pcm_playback_close(struct snd_pcm_substream *substream)
429{
430 return 0;
431
432}
433
434static int snd_aw2_pcm_capture_open(struct snd_pcm_substream *substream)
435{
436 struct snd_pcm_runtime *runtime = substream->runtime;
437
438 snd_printdd(KERN_DEBUG "aw2: Capture_open \n");
439 runtime->hw = snd_aw2_capture_hw;
440 return 0;
441}
442
443/* close callback */
444static int snd_aw2_pcm_capture_close(struct snd_pcm_substream *substream)
445{
446 /* TODO: something to do ? */
447 return 0;
448}
449
450 /* hw_params callback */
451static int snd_aw2_pcm_hw_params(struct snd_pcm_substream *substream,
452 struct snd_pcm_hw_params *hw_params)
453{
454 return snd_pcm_lib_malloc_pages(substream,
455 params_buffer_bytes(hw_params));
456}
457
458/* hw_free callback */
459static int snd_aw2_pcm_hw_free(struct snd_pcm_substream *substream)
460{
461 return snd_pcm_lib_free_pages(substream);
462}
463
464/* prepare callback for playback */
465static int snd_aw2_pcm_prepare_playback(struct snd_pcm_substream *substream)
466{
467 struct aw2_pcm_device *pcm_device = snd_pcm_substream_chip(substream);
468 struct aw2 *chip = pcm_device->chip;
469 struct snd_pcm_runtime *runtime = substream->runtime;
470 unsigned long period_size, buffer_size;
471
472 mutex_lock(&chip->mtx);
473
474 period_size = snd_pcm_lib_period_bytes(substream);
475 buffer_size = snd_pcm_lib_buffer_bytes(substream);
476
477 snd_aw2_saa7146_pcm_init_playback(&chip->saa7146,
478 pcm_device->stream_number,
479 runtime->dma_addr, period_size,
480 buffer_size);
481
482 /* Define Interrupt callback */
483 snd_aw2_saa7146_define_it_playback_callback(pcm_device->stream_number,
484 (snd_aw2_saa7146_it_cb)
485 snd_pcm_period_elapsed,
486 (void *)substream);
487
488 mutex_unlock(&chip->mtx);
489
490 return 0;
491}
492
493/* prepare callback for capture */
494static int snd_aw2_pcm_prepare_capture(struct snd_pcm_substream *substream)
495{
496 struct aw2_pcm_device *pcm_device = snd_pcm_substream_chip(substream);
497 struct aw2 *chip = pcm_device->chip;
498 struct snd_pcm_runtime *runtime = substream->runtime;
499 unsigned long period_size, buffer_size;
500
501 mutex_lock(&chip->mtx);
502
503 period_size = snd_pcm_lib_period_bytes(substream);
504 buffer_size = snd_pcm_lib_buffer_bytes(substream);
505
506 snd_aw2_saa7146_pcm_init_capture(&chip->saa7146,
507 pcm_device->stream_number,
508 runtime->dma_addr, period_size,
509 buffer_size);
510
511 /* Define Interrupt callback */
512 snd_aw2_saa7146_define_it_capture_callback(pcm_device->stream_number,
513 (snd_aw2_saa7146_it_cb)
514 snd_pcm_period_elapsed,
515 (void *)substream);
516
517 mutex_unlock(&chip->mtx);
518
519 return 0;
520}
521
522/* playback trigger callback */
523static int snd_aw2_pcm_trigger_playback(struct snd_pcm_substream *substream,
524 int cmd)
525{
526 int status = 0;
527 struct aw2_pcm_device *pcm_device = snd_pcm_substream_chip(substream);
528 struct aw2 *chip = pcm_device->chip;
529 spin_lock(&chip->reg_lock);
530 switch (cmd) {
531 case SNDRV_PCM_TRIGGER_START:
532 snd_aw2_saa7146_pcm_trigger_start_playback(&chip->saa7146,
533 pcm_device->
534 stream_number);
535 break;
536 case SNDRV_PCM_TRIGGER_STOP:
537 snd_aw2_saa7146_pcm_trigger_stop_playback(&chip->saa7146,
538 pcm_device->
539 stream_number);
540 break;
541 default:
542 status = -EINVAL;
543 }
544 spin_unlock(&chip->reg_lock);
545 return status;
546}
547
548/* capture trigger callback */
549static int snd_aw2_pcm_trigger_capture(struct snd_pcm_substream *substream,
550 int cmd)
551{
552 int status = 0;
553 struct aw2_pcm_device *pcm_device = snd_pcm_substream_chip(substream);
554 struct aw2 *chip = pcm_device->chip;
555 spin_lock(&chip->reg_lock);
556 switch (cmd) {
557 case SNDRV_PCM_TRIGGER_START:
558 snd_aw2_saa7146_pcm_trigger_start_capture(&chip->saa7146,
559 pcm_device->
560 stream_number);
561 break;
562 case SNDRV_PCM_TRIGGER_STOP:
563 snd_aw2_saa7146_pcm_trigger_stop_capture(&chip->saa7146,
564 pcm_device->
565 stream_number);
566 break;
567 default:
568 status = -EINVAL;
569 }
570 spin_unlock(&chip->reg_lock);
571 return status;
572}
573
574/* playback pointer callback */
575static snd_pcm_uframes_t snd_aw2_pcm_pointer_playback(struct snd_pcm_substream
576 *substream)
577{
578 struct aw2_pcm_device *pcm_device = snd_pcm_substream_chip(substream);
579 struct aw2 *chip = pcm_device->chip;
580 unsigned int current_ptr;
581
582 /* get the current hardware pointer */
583 struct snd_pcm_runtime *runtime = substream->runtime;
584 current_ptr =
585 snd_aw2_saa7146_get_hw_ptr_playback(&chip->saa7146,
586 pcm_device->stream_number,
587 runtime->dma_area,
588 runtime->buffer_size);
589
590 return bytes_to_frames(substream->runtime, current_ptr);
591}
592
593/* capture pointer callback */
594static snd_pcm_uframes_t snd_aw2_pcm_pointer_capture(struct snd_pcm_substream
595 *substream)
596{
597 struct aw2_pcm_device *pcm_device = snd_pcm_substream_chip(substream);
598 struct aw2 *chip = pcm_device->chip;
599 unsigned int current_ptr;
600
601 /* get the current hardware pointer */
602 struct snd_pcm_runtime *runtime = substream->runtime;
603 current_ptr =
604 snd_aw2_saa7146_get_hw_ptr_capture(&chip->saa7146,
605 pcm_device->stream_number,
606 runtime->dma_area,
607 runtime->buffer_size);
608
609 return bytes_to_frames(substream->runtime, current_ptr);
610}
611
612/* create a pcm device */
613static int __devinit snd_aw2_new_pcm(struct aw2 *chip)
614{
615 struct snd_pcm *pcm_playback_ana;
616 struct snd_pcm *pcm_playback_num;
617 struct snd_pcm *pcm_capture;
618 struct aw2_pcm_device *pcm_device;
619 int err = 0;
620
621 /* Create new Alsa PCM device */
622
623 err = snd_pcm_new(chip->card, "Audiowerk2 analog playback", 0, 1, 0,
624 &pcm_playback_ana);
625 if (err < 0) {
626 printk(KERN_ERR "aw2: snd_pcm_new error (0x%X)\n", err);
627 return err;
628 }
629
630 /* Creation ok */
631 pcm_device = &chip->device_playback[NUM_STREAM_PLAYBACK_ANA];
632
633 /* Set PCM device name */
634 strcpy(pcm_playback_ana->name, "Analog playback");
635 /* Associate private data to PCM device */
636 pcm_playback_ana->private_data = pcm_device;
637 /* set operators of PCM device */
638 snd_pcm_set_ops(pcm_playback_ana, SNDRV_PCM_STREAM_PLAYBACK,
639 &snd_aw2_playback_ops);
640 /* store PCM device */
641 pcm_device->pcm = pcm_playback_ana;
642 /* give base chip pointer to our internal pcm device
643 structure */
644 pcm_device->chip = chip;
645 /* Give stream number to PCM device */
646 pcm_device->stream_number = NUM_STREAM_PLAYBACK_ANA;
647
648 /* pre-allocation of buffers */
649 /* Preallocate continuous pages. */
650 err = snd_pcm_lib_preallocate_pages_for_all(pcm_playback_ana,
651 SNDRV_DMA_TYPE_DEV,
652 snd_dma_pci_data
653 (chip->pci),
654 64 * 1024, 64 * 1024);
655 if (err)
656 printk(KERN_ERR "aw2: snd_pcm_lib_preallocate_pages_for_all "
657 "error (0x%X)\n", err);
658
659 err = snd_pcm_new(chip->card, "Audiowerk2 digital playback", 1, 1, 0,
660 &pcm_playback_num);
661
662 if (err < 0) {
663 printk(KERN_ERR "aw2: snd_pcm_new error (0x%X)\n", err);
664 return err;
665 }
666 /* Creation ok */
667 pcm_device = &chip->device_playback[NUM_STREAM_PLAYBACK_DIG];
668
669 /* Set PCM device name */
670 strcpy(pcm_playback_num->name, "Digital playback");
671 /* Associate private data to PCM device */
672 pcm_playback_num->private_data = pcm_device;
673 /* set operators of PCM device */
674 snd_pcm_set_ops(pcm_playback_num, SNDRV_PCM_STREAM_PLAYBACK,
675 &snd_aw2_playback_ops);
676 /* store PCM device */
677 pcm_device->pcm = pcm_playback_num;
678 /* give base chip pointer to our internal pcm device
679 structure */
680 pcm_device->chip = chip;
681 /* Give stream number to PCM device */
682 pcm_device->stream_number = NUM_STREAM_PLAYBACK_DIG;
683
684 /* pre-allocation of buffers */
685 /* Preallocate continuous pages. */
686 err = snd_pcm_lib_preallocate_pages_for_all(pcm_playback_num,
687 SNDRV_DMA_TYPE_DEV,
688 snd_dma_pci_data
689 (chip->pci),
690 64 * 1024, 64 * 1024);
691 if (err)
692 printk(KERN_ERR
693 "aw2: snd_pcm_lib_preallocate_pages_for_all error "
694 "(0x%X)\n", err);
695
696
697
698 err = snd_pcm_new(chip->card, "Audiowerk2 capture", 2, 0, 1,
699 &pcm_capture);
700
701 if (err < 0) {
702 printk(KERN_ERR "aw2: snd_pcm_new error (0x%X)\n", err);
703 return err;
704 }
705
706 /* Creation ok */
707 pcm_device = &chip->device_capture[NUM_STREAM_CAPTURE_ANA];
708
709 /* Set PCM device name */
710 strcpy(pcm_capture->name, "Capture");
711 /* Associate private data to PCM device */
712 pcm_capture->private_data = pcm_device;
713 /* set operators of PCM device */
714 snd_pcm_set_ops(pcm_capture, SNDRV_PCM_STREAM_CAPTURE,
715 &snd_aw2_capture_ops);
716 /* store PCM device */
717 pcm_device->pcm = pcm_capture;
718 /* give base chip pointer to our internal pcm device
719 structure */
720 pcm_device->chip = chip;
721 /* Give stream number to PCM device */
722 pcm_device->stream_number = NUM_STREAM_CAPTURE_ANA;
723
724 /* pre-allocation of buffers */
725 /* Preallocate continuous pages. */
726 err = snd_pcm_lib_preallocate_pages_for_all(pcm_capture,
727 SNDRV_DMA_TYPE_DEV,
728 snd_dma_pci_data
729 (chip->pci),
730 64 * 1024, 64 * 1024);
731 if (err)
732 printk(KERN_ERR
733 "aw2: snd_pcm_lib_preallocate_pages_for_all error "
734 "(0x%X)\n", err);
735
736
737 /* Create control */
738 err = snd_ctl_add(chip->card, snd_ctl_new1(&aw2_control, chip));
739 if (err < 0) {
740 printk(KERN_ERR "aw2: snd_ctl_add error (0x%X)\n", err);
741 return err;
742 }
743
744 return 0;
745}
746
747static int snd_aw2_control_switch_capture_info(struct snd_kcontrol *kcontrol,
748 struct snd_ctl_elem_info *uinfo)
749{
750 static char *texts[2] = {
751 "Analog", "Digital"
752 };
753 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
754 uinfo->count = 1;
755 uinfo->value.enumerated.items = 2;
756 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) {
757 uinfo->value.enumerated.item =
758 uinfo->value.enumerated.items - 1;
759 }
760 strcpy(uinfo->value.enumerated.name,
761 texts[uinfo->value.enumerated.item]);
762 return 0;
763}
764
765static int snd_aw2_control_switch_capture_get(struct snd_kcontrol *kcontrol,
766 struct snd_ctl_elem_value
767 *ucontrol)
768{
769 struct aw2 *chip = snd_kcontrol_chip(kcontrol);
770 if (snd_aw2_saa7146_is_using_digital_input(&chip->saa7146))
771 ucontrol->value.enumerated.item[0] = CTL_ROUTE_DIGITAL;
772 else
773 ucontrol->value.enumerated.item[0] = CTL_ROUTE_ANALOG;
774 return 0;
775}
776
777static int snd_aw2_control_switch_capture_put(struct snd_kcontrol *kcontrol,
778 struct snd_ctl_elem_value
779 *ucontrol)
780{
781 struct aw2 *chip = snd_kcontrol_chip(kcontrol);
782 int changed = 0;
783 int is_disgital =
784 snd_aw2_saa7146_is_using_digital_input(&chip->saa7146);
785
786 if (((ucontrol->value.integer.value[0] == CTL_ROUTE_DIGITAL)
787 && !is_disgital)
788 || ((ucontrol->value.integer.value[0] == CTL_ROUTE_ANALOG)
789 && is_disgital)) {
790 snd_aw2_saa7146_use_digital_input(&chip->saa7146, !is_disgital);
791 changed = 1;
792 }
793 return changed;
794}
diff --git a/sound/pci/aw2/aw2-saa7146.c b/sound/pci/aw2/aw2-saa7146.c
new file mode 100644
index 000000000000..6a3891ab69dd
--- /dev/null
+++ b/sound/pci/aw2/aw2-saa7146.c
@@ -0,0 +1,465 @@
1/*****************************************************************************
2 *
3 * Copyright (C) 2008 Cedric Bregardis <cedric.bregardis@free.fr> and
4 * Jean-Christian Hassler <jhassler@free.fr>
5 *
6 * This file is part of the Audiowerk2 ALSA driver
7 *
8 * The Audiowerk2 ALSA driver is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2.
11 *
12 * The Audiowerk2 ALSA driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with the Audiowerk2 ALSA driver; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 * USA.
21 *
22 *****************************************************************************/
23
24#define AW2_SAA7146_M
25
26#include <linux/init.h>
27#include <linux/pci.h>
28#include <linux/slab.h>
29#include <linux/interrupt.h>
30#include <linux/delay.h>
31#include <asm/system.h>
32#include <asm/io.h>
33#include <sound/core.h>
34#include <sound/initval.h>
35#include <sound/pcm.h>
36#include <sound/pcm_params.h>
37
38#include "saa7146.h"
39#include "aw2-saa7146.h"
40
41#include "aw2-tsl.c"
42
43#define WRITEREG(value, addr) writel((value), chip->base_addr + (addr))
44#define READREG(addr) readl(chip->base_addr + (addr))
45
46static struct snd_aw2_saa7146_cb_param
47 arr_substream_it_playback_cb[NB_STREAM_PLAYBACK];
48static struct snd_aw2_saa7146_cb_param
49 arr_substream_it_capture_cb[NB_STREAM_CAPTURE];
50
51static int snd_aw2_saa7146_get_limit(int size);
52
53/* chip-specific destructor */
54int snd_aw2_saa7146_free(struct snd_aw2_saa7146 *chip)
55{
56 /* disable all irqs */
57 WRITEREG(0, IER);
58
59 /* reset saa7146 */
60 WRITEREG((MRST_N << 16), MC1);
61
62 /* Unset base addr */
63 chip->base_addr = NULL;
64
65 return 0;
66}
67
68void snd_aw2_saa7146_setup(struct snd_aw2_saa7146 *chip,
69 void __iomem *pci_base_addr)
70{
71 /* set PCI burst/threshold
72
73 Burst length definition
74 VALUE BURST LENGTH
75 000 1 Dword
76 001 2 Dwords
77 010 4 Dwords
78 011 8 Dwords
79 100 16 Dwords
80 101 32 Dwords
81 110 64 Dwords
82 111 128 Dwords
83
84 Threshold definition
85 VALUE WRITE MODE READ MODE
86 00 1 Dword of valid data 1 empty Dword
87 01 4 Dwords of valid data 4 empty Dwords
88 10 8 Dwords of valid data 8 empty Dwords
89 11 16 Dwords of valid data 16 empty Dwords */
90
91 unsigned int acon2;
92 unsigned int acon1 = 0;
93 int i;
94
95 /* Set base addr */
96 chip->base_addr = pci_base_addr;
97
98 /* disable all irqs */
99 WRITEREG(0, IER);
100
101 /* reset saa7146 */
102 WRITEREG((MRST_N << 16), MC1);
103
104 /* enable audio interface */
105#ifdef __BIG_ENDIAN
106 acon1 |= A1_SWAP;
107 acon1 |= A2_SWAP;
108#endif
109 /* WS0_CTRL, WS0_SYNC: input TSL1, I2S */
110
111 /* At initialization WS1 and WS2 are disbaled (configured as input */
112 acon1 |= 0 * WS1_CTRL;
113 acon1 |= 0 * WS2_CTRL;
114
115 /* WS4 is not used. So it must not restart A2.
116 This is why it is configured as output (force to low) */
117 acon1 |= 3 * WS4_CTRL;
118
119 /* WS3_CTRL, WS3_SYNC: output TSL2, I2S */
120 acon1 |= 2 * WS3_CTRL;
121
122 /* A1 and A2 are active and asynchronous */
123 acon1 |= 3 * AUDIO_MODE;
124 WRITEREG(acon1, ACON1);
125
126 /* The following comes from original windows driver.
127 It is needed to have a correct behavior of input and output
128 simultenously, but I don't know why ! */
129 WRITEREG(3 * (BurstA1_in) + 3 * (ThreshA1_in) +
130 3 * (BurstA1_out) + 3 * (ThreshA1_out) +
131 3 * (BurstA2_out) + 3 * (ThreshA2_out), PCI_BT_A);
132
133 /* enable audio port pins */
134 WRITEREG((EAP << 16) | EAP, MC1);
135
136 /* enable I2C */
137 WRITEREG((EI2C << 16) | EI2C, MC1);
138 /* enable interrupts */
139 WRITEREG(A1_out | A2_out | A1_in | IIC_S | IIC_E, IER);
140
141 /* audio configuration */
142 acon2 = A2_CLKSRC | BCLK1_OEN;
143 WRITEREG(acon2, ACON2);
144
145 /* By default use analog input */
146 snd_aw2_saa7146_use_digital_input(chip, 0);
147
148 /* TSL setup */
149 for (i = 0; i < 8; ++i) {
150 WRITEREG(tsl1[i], TSL1 + (i * 4));
151 WRITEREG(tsl2[i], TSL2 + (i * 4));
152 }
153
154}
155
156void snd_aw2_saa7146_pcm_init_playback(struct snd_aw2_saa7146 *chip,
157 int stream_number,
158 unsigned long dma_addr,
159 unsigned long period_size,
160 unsigned long buffer_size)
161{
162 unsigned long dw_page, dw_limit;
163
164 /* Configure DMA for substream
165 Configuration informations: ALSA has allocated continuous memory
166 pages. So we don't need to use MMU of saa7146.
167 */
168
169 /* No MMU -> nothing to do with PageA1, we only configure the limit of
170 PageAx_out register */
171 /* Disable MMU */
172 dw_page = (0L << 11);
173
174 /* Configure Limit for DMA access.
175 The limit register defines an address limit, which generates
176 an interrupt if passed by the actual PCI address pointer.
177 '0001' means an interrupt will be generated if the lower
178 6 bits (64 bytes) of the PCI address are zero. '0010'
179 defines a limit of 128 bytes, '0011' one of 256 bytes, and
180 so on up to 1 Mbyte defined by '1111'. This interrupt range
181 can be calculated as follows:
182 Range = 2^(5 + Limit) bytes.
183 */
184 dw_limit = snd_aw2_saa7146_get_limit(period_size);
185 dw_page |= (dw_limit << 4);
186
187 if (stream_number == 0) {
188 WRITEREG(dw_page, PageA2_out);
189
190 /* Base address for DMA transfert. */
191 /* This address has been reserved by ALSA. */
192 /* This is a physical address */
193 WRITEREG(dma_addr, BaseA2_out);
194
195 /* Define upper limit for DMA access */
196 WRITEREG(dma_addr + buffer_size, ProtA2_out);
197
198 } else if (stream_number == 1) {
199 WRITEREG(dw_page, PageA1_out);
200
201 /* Base address for DMA transfert. */
202 /* This address has been reserved by ALSA. */
203 /* This is a physical address */
204 WRITEREG(dma_addr, BaseA1_out);
205
206 /* Define upper limit for DMA access */
207 WRITEREG(dma_addr + buffer_size, ProtA1_out);
208 } else {
209 printk(KERN_ERR
210 "aw2: snd_aw2_saa7146_pcm_init_playback: "
211 "Substream number is not 0 or 1 -> not managed\n");
212 }
213}
214
215void snd_aw2_saa7146_pcm_init_capture(struct snd_aw2_saa7146 *chip,
216 int stream_number, unsigned long dma_addr,
217 unsigned long period_size,
218 unsigned long buffer_size)
219{
220 unsigned long dw_page, dw_limit;
221
222 /* Configure DMA for substream
223 Configuration informations: ALSA has allocated continuous memory
224 pages. So we don't need to use MMU of saa7146.
225 */
226
227 /* No MMU -> nothing to do with PageA1, we only configure the limit of
228 PageAx_out register */
229 /* Disable MMU */
230 dw_page = (0L << 11);
231
232 /* Configure Limit for DMA access.
233 The limit register defines an address limit, which generates
234 an interrupt if passed by the actual PCI address pointer.
235 '0001' means an interrupt will be generated if the lower
236 6 bits (64 bytes) of the PCI address are zero. '0010'
237 defines a limit of 128 bytes, '0011' one of 256 bytes, and
238 so on up to 1 Mbyte defined by '1111'. This interrupt range
239 can be calculated as follows:
240 Range = 2^(5 + Limit) bytes.
241 */
242 dw_limit = snd_aw2_saa7146_get_limit(period_size);
243 dw_page |= (dw_limit << 4);
244
245 if (stream_number == 0) {
246 WRITEREG(dw_page, PageA1_in);
247
248 /* Base address for DMA transfert. */
249 /* This address has been reserved by ALSA. */
250 /* This is a physical address */
251 WRITEREG(dma_addr, BaseA1_in);
252
253 /* Define upper limit for DMA access */
254 WRITEREG(dma_addr + buffer_size, ProtA1_in);
255 } else {
256 printk(KERN_ERR
257 "aw2: snd_aw2_saa7146_pcm_init_capture: "
258 "Substream number is not 0 -> not managed\n");
259 }
260}
261
262void snd_aw2_saa7146_define_it_playback_callback(unsigned int stream_number,
263 snd_aw2_saa7146_it_cb
264 p_it_callback,
265 void *p_callback_param)
266{
267 if (stream_number < NB_STREAM_PLAYBACK) {
268 arr_substream_it_playback_cb[stream_number].p_it_callback =
269 (snd_aw2_saa7146_it_cb) p_it_callback;
270 arr_substream_it_playback_cb[stream_number].p_callback_param =
271 (void *)p_callback_param;
272 }
273}
274
275void snd_aw2_saa7146_define_it_capture_callback(unsigned int stream_number,
276 snd_aw2_saa7146_it_cb
277 p_it_callback,
278 void *p_callback_param)
279{
280 if (stream_number < NB_STREAM_CAPTURE) {
281 arr_substream_it_capture_cb[stream_number].p_it_callback =
282 (snd_aw2_saa7146_it_cb) p_it_callback;
283 arr_substream_it_capture_cb[stream_number].p_callback_param =
284 (void *)p_callback_param;
285 }
286}
287
288void snd_aw2_saa7146_pcm_trigger_start_playback(struct snd_aw2_saa7146 *chip,
289 int stream_number)
290{
291 unsigned int acon1 = 0;
292 /* In aw8 driver, dma transfert is always active. It is
293 started and stopped in a larger "space" */
294 acon1 = READREG(ACON1);
295 if (stream_number == 0) {
296 WRITEREG((TR_E_A2_OUT << 16) | TR_E_A2_OUT, MC1);
297
298 /* WS2_CTRL, WS2_SYNC: output TSL2, I2S */
299 acon1 |= 2 * WS2_CTRL;
300 WRITEREG(acon1, ACON1);
301
302 } else if (stream_number == 1) {
303 WRITEREG((TR_E_A1_OUT << 16) | TR_E_A1_OUT, MC1);
304
305 /* WS1_CTRL, WS1_SYNC: output TSL1, I2S */
306 acon1 |= 1 * WS1_CTRL;
307 WRITEREG(acon1, ACON1);
308 }
309}
310
311void snd_aw2_saa7146_pcm_trigger_stop_playback(struct snd_aw2_saa7146 *chip,
312 int stream_number)
313{
314 unsigned int acon1 = 0;
315 acon1 = READREG(ACON1);
316 if (stream_number == 0) {
317 /* WS2_CTRL, WS2_SYNC: output TSL2, I2S */
318 acon1 &= ~(3 * WS2_CTRL);
319 WRITEREG(acon1, ACON1);
320
321 WRITEREG((TR_E_A2_OUT << 16), MC1);
322 } else if (stream_number == 1) {
323 /* WS1_CTRL, WS1_SYNC: output TSL1, I2S */
324 acon1 &= ~(3 * WS1_CTRL);
325 WRITEREG(acon1, ACON1);
326
327 WRITEREG((TR_E_A1_OUT << 16), MC1);
328 }
329}
330
331void snd_aw2_saa7146_pcm_trigger_start_capture(struct snd_aw2_saa7146 *chip,
332 int stream_number)
333{
334 /* In aw8 driver, dma transfert is always active. It is
335 started and stopped in a larger "space" */
336 if (stream_number == 0)
337 WRITEREG((TR_E_A1_IN << 16) | TR_E_A1_IN, MC1);
338}
339
340void snd_aw2_saa7146_pcm_trigger_stop_capture(struct snd_aw2_saa7146 *chip,
341 int stream_number)
342{
343 if (stream_number == 0)
344 WRITEREG((TR_E_A1_IN << 16), MC1);
345}
346
347irqreturn_t snd_aw2_saa7146_interrupt(int irq, void *dev_id)
348{
349 unsigned int isr;
350 unsigned int iicsta;
351 struct snd_aw2_saa7146 *chip = dev_id;
352
353 isr = READREG(ISR);
354 if (!isr)
355 return IRQ_NONE;
356
357 WRITEREG(isr, ISR);
358
359 if (isr & (IIC_S | IIC_E)) {
360 iicsta = READREG(IICSTA);
361 WRITEREG(0x100, IICSTA);
362 }
363
364 if (isr & A1_out) {
365 if (arr_substream_it_playback_cb[1].p_it_callback != NULL) {
366 arr_substream_it_playback_cb[1].
367 p_it_callback(arr_substream_it_playback_cb[1].
368 p_callback_param);
369 }
370 }
371 if (isr & A2_out) {
372 if (arr_substream_it_playback_cb[0].p_it_callback != NULL) {
373 arr_substream_it_playback_cb[0].
374 p_it_callback(arr_substream_it_playback_cb[0].
375 p_callback_param);
376 }
377
378 }
379 if (isr & A1_in) {
380 if (arr_substream_it_capture_cb[0].p_it_callback != NULL) {
381 arr_substream_it_capture_cb[0].
382 p_it_callback(arr_substream_it_capture_cb[0].
383 p_callback_param);
384 }
385 }
386 return IRQ_HANDLED;
387}
388
389unsigned int snd_aw2_saa7146_get_hw_ptr_playback(struct snd_aw2_saa7146 *chip,
390 int stream_number,
391 unsigned char *start_addr,
392 unsigned int buffer_size)
393{
394 long pci_adp = 0;
395 size_t ptr = 0;
396
397 if (stream_number == 0) {
398 pci_adp = READREG(PCI_ADP3);
399 ptr = pci_adp - (long)start_addr;
400
401 if (ptr == buffer_size)
402 ptr = 0;
403 }
404 if (stream_number == 1) {
405 pci_adp = READREG(PCI_ADP1);
406 ptr = pci_adp - (size_t) start_addr;
407
408 if (ptr == buffer_size)
409 ptr = 0;
410 }
411 return ptr;
412}
413
414unsigned int snd_aw2_saa7146_get_hw_ptr_capture(struct snd_aw2_saa7146 *chip,
415 int stream_number,
416 unsigned char *start_addr,
417 unsigned int buffer_size)
418{
419 size_t pci_adp = 0;
420 size_t ptr = 0;
421 if (stream_number == 0) {
422 pci_adp = READREG(PCI_ADP2);
423 ptr = pci_adp - (size_t) start_addr;
424
425 if (ptr == buffer_size)
426 ptr = 0;
427 }
428 return ptr;
429}
430
431void snd_aw2_saa7146_use_digital_input(struct snd_aw2_saa7146 *chip,
432 int use_digital)
433{
434 /* FIXME: switch between analog and digital input does not always work.
435 It can produce a kind of white noise. It seams that received data
436 are inverted sometime (endian inversion). Why ? I don't know, maybe
437 a problem of synchronization... However for the time being I have
438 not found the problem. Workaround: switch again (and again) between
439 digital and analog input until it works. */
440 if (use_digital)
441 WRITEREG(0x40, GPIO_CTRL);
442 else
443 WRITEREG(0x50, GPIO_CTRL);
444}
445
446int snd_aw2_saa7146_is_using_digital_input(struct snd_aw2_saa7146 *chip)
447{
448 unsigned int reg_val = READREG(GPIO_CTRL);
449 if ((reg_val & 0xFF) == 0x40)
450 return 1;
451 else
452 return 0;
453}
454
455
456static int snd_aw2_saa7146_get_limit(int size)
457{
458 int limitsize = 32;
459 int limit = 0;
460 while (limitsize < size) {
461 limitsize *= 2;
462 limit++;
463 }
464 return limit;
465}
diff --git a/sound/pci/aw2/aw2-saa7146.h b/sound/pci/aw2/aw2-saa7146.h
new file mode 100644
index 000000000000..5b35e358937f
--- /dev/null
+++ b/sound/pci/aw2/aw2-saa7146.h
@@ -0,0 +1,105 @@
1/*****************************************************************************
2 *
3 * Copyright (C) 2008 Cedric Bregardis <cedric.bregardis@free.fr> and
4 * Jean-Christian Hassler <jhassler@free.fr>
5 *
6 * This file is part of the Audiowerk2 ALSA driver
7 *
8 * The Audiowerk2 ALSA driver is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2.
11 *
12 * The Audiowerk2 ALSA driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with the Audiowerk2 ALSA driver; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 * USA.
21 *
22 *****************************************************************************/
23
24#ifndef AW2_SAA7146_H
25#define AW2_SAA7146_H
26
27#define NB_STREAM_PLAYBACK 2
28#define NB_STREAM_CAPTURE 1
29
30#define NUM_STREAM_PLAYBACK_ANA 0
31#define NUM_STREAM_PLAYBACK_DIG 1
32
33#define NUM_STREAM_CAPTURE_ANA 0
34
35typedef void (*snd_aw2_saa7146_it_cb) (void *);
36
37struct snd_aw2_saa7146_cb_param {
38 snd_aw2_saa7146_it_cb p_it_callback;
39 void *p_callback_param;
40};
41
42/* definition of the chip-specific record */
43
44struct snd_aw2_saa7146 {
45 void __iomem *base_addr;
46};
47
48extern void snd_aw2_saa7146_setup(struct snd_aw2_saa7146 *chip,
49 void __iomem *pci_base_addr);
50extern int snd_aw2_saa7146_free(struct snd_aw2_saa7146 *chip);
51
52extern void snd_aw2_saa7146_pcm_init_playback(struct snd_aw2_saa7146 *chip,
53 int stream_number,
54 unsigned long dma_addr,
55 unsigned long period_size,
56 unsigned long buffer_size);
57extern void snd_aw2_saa7146_pcm_init_capture(struct snd_aw2_saa7146 *chip,
58 int stream_number,
59 unsigned long dma_addr,
60 unsigned long period_size,
61 unsigned long buffer_size);
62extern void snd_aw2_saa7146_define_it_playback_callback(unsigned int
63 stream_number,
64 snd_aw2_saa7146_it_cb
65 p_it_callback,
66 void *p_callback_param);
67extern void snd_aw2_saa7146_define_it_capture_callback(unsigned int
68 stream_number,
69 snd_aw2_saa7146_it_cb
70 p_it_callback,
71 void *p_callback_param);
72extern void snd_aw2_saa7146_pcm_trigger_start_capture(struct snd_aw2_saa7146
73 *chip, int stream_number);
74extern void snd_aw2_saa7146_pcm_trigger_stop_capture(struct snd_aw2_saa7146
75 *chip, int stream_number);
76
77extern void snd_aw2_saa7146_pcm_trigger_start_playback(struct snd_aw2_saa7146
78 *chip,
79 int stream_number);
80extern void snd_aw2_saa7146_pcm_trigger_stop_playback(struct snd_aw2_saa7146
81 *chip, int stream_number);
82
83extern irqreturn_t snd_aw2_saa7146_interrupt(int irq, void *dev_id);
84extern unsigned int snd_aw2_saa7146_get_hw_ptr_playback(struct snd_aw2_saa7146
85 *chip,
86 int stream_number,
87 unsigned char
88 *start_addr,
89 unsigned int
90 buffer_size);
91extern unsigned int snd_aw2_saa7146_get_hw_ptr_capture(struct snd_aw2_saa7146
92 *chip,
93 int stream_number,
94 unsigned char
95 *start_addr,
96 unsigned int
97 buffer_size);
98
99extern void snd_aw2_saa7146_use_digital_input(struct snd_aw2_saa7146 *chip,
100 int use_digital);
101
102extern int snd_aw2_saa7146_is_using_digital_input(struct snd_aw2_saa7146
103 *chip);
104
105#endif
diff --git a/sound/pci/aw2/aw2-tsl.c b/sound/pci/aw2/aw2-tsl.c
new file mode 100644
index 000000000000..459b0311ea31
--- /dev/null
+++ b/sound/pci/aw2/aw2-tsl.c
@@ -0,0 +1,110 @@
1/*****************************************************************************
2 *
3 * Copyright (C) 2008 Cedric Bregardis <cedric.bregardis@free.fr> and
4 * Jean-Christian Hassler <jhassler@free.fr>
5 * Copyright 1998 Emagic Soft- und Hardware GmbH
6 * Copyright 2002 Martijn Sipkema
7 *
8 * This file is part of the Audiowerk2 ALSA driver
9 *
10 * The Audiowerk2 ALSA driver is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; version 2.
13 *
14 * The Audiowerk2 ALSA driver is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with the Audiowerk2 ALSA driver; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22 * USA.
23 *
24 *****************************************************************************/
25
26#define TSL_WS0 (1UL << 31)
27#define TSL_WS1 (1UL << 30)
28#define TSL_WS2 (1UL << 29)
29#define TSL_WS3 (1UL << 28)
30#define TSL_WS4 (1UL << 27)
31#define TSL_DIS_A1 (1UL << 24)
32#define TSL_SDW_A1 (1UL << 23)
33#define TSL_SIB_A1 (1UL << 22)
34#define TSL_SF_A1 (1UL << 21)
35#define TSL_LF_A1 (1UL << 20)
36#define TSL_BSEL_A1 (1UL << 17)
37#define TSL_DOD_A1 (1UL << 15)
38#define TSL_LOW_A1 (1UL << 14)
39#define TSL_DIS_A2 (1UL << 11)
40#define TSL_SDW_A2 (1UL << 10)
41#define TSL_SIB_A2 (1UL << 9)
42#define TSL_SF_A2 (1UL << 8)
43#define TSL_LF_A2 (1UL << 7)
44#define TSL_BSEL_A2 (1UL << 4)
45#define TSL_DOD_A2 (1UL << 2)
46#define TSL_LOW_A2 (1UL << 1)
47#define TSL_EOS (1UL << 0)
48
49 /* Audiowerk8 hardware setup: */
50 /* WS0, SD4, TSL1 - Analog/ digital in */
51 /* WS1, SD0, TSL1 - Analog out #1, digital out */
52 /* WS2, SD2, TSL1 - Analog out #2 */
53 /* WS3, SD1, TSL2 - Analog out #3 */
54 /* WS4, SD3, TSL2 - Analog out #4 */
55
56 /* Audiowerk8 timing: */
57 /* Timeslot: | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | ... */
58
59 /* A1_INPUT: */
60 /* SD4: <_ADC-L_>-------<_ADC-R_>-------< */
61 /* WS0: _______________/---------------\_ */
62
63 /* A1_OUTPUT: */
64 /* SD0: <_1-L___>-------<_1-R___>-------< */
65 /* WS1: _______________/---------------\_ */
66 /* SD2: >-------<_2-L___>-------<_2-R___> */
67 /* WS2: -------\_______________/--------- */
68
69 /* A2_OUTPUT: */
70 /* SD1: <_3-L___>-------<_3-R___>-------< */
71 /* WS3: _______________/---------------\_ */
72 /* SD3: >-------<_4-L___>-------<_4-R___> */
73 /* WS4: -------\_______________/--------- */
74
75static int tsl1[8] = {
76 1 * TSL_SDW_A1 | 3 * TSL_BSEL_A1 |
77 0 * TSL_DIS_A1 | 0 * TSL_DOD_A1 | TSL_LF_A1,
78
79 1 * TSL_SDW_A1 | 2 * TSL_BSEL_A1 |
80 0 * TSL_DIS_A1 | 0 * TSL_DOD_A1,
81
82 0 * TSL_SDW_A1 | 3 * TSL_BSEL_A1 |
83 0 * TSL_DIS_A1 | 0 * TSL_DOD_A1,
84
85 0 * TSL_SDW_A1 | 2 * TSL_BSEL_A1 |
86 0 * TSL_DIS_A1 | 0 * TSL_DOD_A1,
87
88 1 * TSL_SDW_A1 | 1 * TSL_BSEL_A1 |
89 0 * TSL_DIS_A1 | 0 * TSL_DOD_A1 | TSL_WS1 | TSL_WS0,
90
91 1 * TSL_SDW_A1 | 0 * TSL_BSEL_A1 |
92 0 * TSL_DIS_A1 | 0 * TSL_DOD_A1 | TSL_WS1 | TSL_WS0,
93
94 0 * TSL_SDW_A1 | 1 * TSL_BSEL_A1 |
95 0 * TSL_DIS_A1 | 0 * TSL_DOD_A1 | TSL_WS1 | TSL_WS0,
96
97 0 * TSL_SDW_A1 | 0 * TSL_BSEL_A1 | 0 * TSL_DIS_A1 |
98 0 * TSL_DOD_A1 | TSL_WS1 | TSL_WS0 | TSL_SF_A1 | TSL_EOS,
99};
100
101static int tsl2[8] = {
102 0 * TSL_SDW_A2 | 3 * TSL_BSEL_A2 | 2 * TSL_DOD_A2 | TSL_LF_A2,
103 0 * TSL_SDW_A2 | 2 * TSL_BSEL_A2 | 2 * TSL_DOD_A2,
104 0 * TSL_SDW_A2 | 3 * TSL_BSEL_A2 | 2 * TSL_DOD_A2,
105 0 * TSL_SDW_A2 | 2 * TSL_BSEL_A2 | 2 * TSL_DOD_A2,
106 0 * TSL_SDW_A2 | 1 * TSL_BSEL_A2 | 2 * TSL_DOD_A2 | TSL_WS2,
107 0 * TSL_SDW_A2 | 0 * TSL_BSEL_A2 | 2 * TSL_DOD_A2 | TSL_WS2,
108 0 * TSL_SDW_A2 | 1 * TSL_BSEL_A2 | 2 * TSL_DOD_A2 | TSL_WS2,
109 0 * TSL_SDW_A2 | 0 * TSL_BSEL_A2 | 2 * TSL_DOD_A2 | TSL_WS2 | TSL_EOS
110};
diff --git a/sound/pci/aw2/saa7146.h b/sound/pci/aw2/saa7146.h
new file mode 100644
index 000000000000..ce0ab5f9ee9c
--- /dev/null
+++ b/sound/pci/aw2/saa7146.h
@@ -0,0 +1,168 @@
1/*****************************************************************************
2 *
3 * Copyright (C) 2008 Cedric Bregardis <cedric.bregardis@free.fr> and
4 * Jean-Christian Hassler <jhassler@free.fr>
5 *
6 * This file is part of the Audiowerk2 ALSA driver
7 *
8 * The Audiowerk2 ALSA driver is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2.
11 *
12 * The Audiowerk2 ALSA driver is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with the Audiowerk2 ALSA driver; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20 * USA.
21 *
22 *****************************************************************************/
23
24/* SAA7146 registers */
25#define PCI_BT_A 0x4C
26#define IICTFR 0x8C
27#define IICSTA 0x90
28#define BaseA1_in 0x94
29#define ProtA1_in 0x98
30#define PageA1_in 0x9C
31#define BaseA1_out 0xA0
32#define ProtA1_out 0xA4
33#define PageA1_out 0xA8
34#define BaseA2_in 0xAC
35#define ProtA2_in 0xB0
36#define PageA2_in 0xB4
37#define BaseA2_out 0xB8
38#define ProtA2_out 0xBC
39#define PageA2_out 0xC0
40#define IER 0xDC
41#define GPIO_CTRL 0xE0
42#define ACON1 0xF4
43#define ACON2 0xF8
44#define MC1 0xFC
45#define MC2 0x100
46#define ISR 0x10C
47#define PSR 0x110
48#define SSR 0x114
49#define PCI_ADP1 0x12C
50#define PCI_ADP2 0x130
51#define PCI_ADP3 0x134
52#define PCI_ADP4 0x138
53#define LEVEL_REP 0x140
54#define FB_BUFFER1 0x144
55#define FB_BUFFER2 0x148
56#define TSL1 0x180
57#define TSL2 0x1C0
58
59#define ME (1UL << 11)
60#define LIMIT (1UL << 4)
61#define PV (1UL << 3)
62
63/* PSR/ISR/IER */
64#define PPEF (1UL << 31)
65#define PABO (1UL << 30)
66#define IIC_S (1UL << 17)
67#define IIC_E (1UL << 16)
68#define A2_in (1UL << 15)
69#define A2_out (1UL << 14)
70#define A1_in (1UL << 13)
71#define A1_out (1UL << 12)
72#define AFOU (1UL << 11)
73#define PIN3 (1UL << 6)
74#define PIN2 (1UL << 5)
75#define PIN1 (1UL << 4)
76#define PIN0 (1UL << 3)
77#define ECS (1UL << 2)
78#define EC3S (1UL << 1)
79#define EC0S (1UL << 0)
80
81/* SSR */
82#define PRQ (1UL << 31)
83#define PMA (1UL << 30)
84#define IIC_EA (1UL << 21)
85#define IIC_EW (1UL << 20)
86#define IIC_ER (1UL << 19)
87#define IIC_EL (1UL << 18)
88#define IIC_EF (1UL << 17)
89#define AF2_in (1UL << 10)
90#define AF2_out (1UL << 9)
91#define AF1_in (1UL << 8)
92#define AF1_out (1UL << 7)
93#define EC5S (1UL << 3)
94#define EC4S (1UL << 2)
95#define EC2S (1UL << 1)
96#define EC1S (1UL << 0)
97
98/* PCI_BT_A */
99#define BurstA1_in (1UL << 26)
100#define ThreshA1_in (1UL << 24)
101#define BurstA1_out (1UL << 18)
102#define ThreshA1_out (1UL << 16)
103#define BurstA2_in (1UL << 10)
104#define ThreshA2_in (1UL << 8)
105#define BurstA2_out (1UL << 2)
106#define ThreshA2_out (1UL << 0)
107
108/* MC1 */
109#define MRST_N (1UL << 15)
110#define EAP (1UL << 9)
111#define EI2C (1UL << 8)
112#define TR_E_A2_OUT (1UL << 3)
113#define TR_E_A2_IN (1UL << 2)
114#define TR_E_A1_OUT (1UL << 1)
115#define TR_E_A1_IN (1UL << 0)
116
117/* MC2 */
118#define UPLD_IIC (1UL << 0)
119
120/* ACON1 */
121#define AUDIO_MODE (1UL << 29)
122#define MAXLEVEL (1UL << 22)
123#define A1_SWAP (1UL << 21)
124#define A2_SWAP (1UL << 20)
125#define WS0_CTRL (1UL << 18)
126#define WS0_SYNC (1UL << 16)
127#define WS1_CTRL (1UL << 14)
128#define WS1_SYNC (1UL << 12)
129#define WS2_CTRL (1UL << 10)
130#define WS2_SYNC (1UL << 8)
131#define WS3_CTRL (1UL << 6)
132#define WS3_SYNC (1UL << 4)
133#define WS4_CTRL (1UL << 2)
134#define WS4_SYNC (1UL << 0)
135
136/* ACON2 */
137#define A1_CLKSRC (1UL << 27)
138#define A2_CLKSRC (1UL << 22)
139#define INVERT_BCLK1 (1UL << 21)
140#define INVERT_BCLK2 (1UL << 20)
141#define BCLK1_OEN (1UL << 19)
142#define BCLK2_OEN (1UL << 18)
143
144/* IICSTA */
145#define IICCC (1UL << 8)
146#define ABORT (1UL << 7)
147#define SPERR (1UL << 6)
148#define APERR (1UL << 5)
149#define DTERR (1UL << 4)
150#define DRERR (1UL << 3)
151#define AL (1UL << 2)
152#define ERR (1UL << 1)
153#define BUSY (1UL << 0)
154
155/* IICTFR */
156#define BYTE2 (1UL << 24)
157#define BYTE1 (1UL << 16)
158#define BYTE0 (1UL << 8)
159#define ATRR2 (1UL << 6)
160#define ATRR1 (1UL << 4)
161#define ATRR0 (1UL << 2)
162#define ERR (1UL << 1)
163#define BUSY (1UL << 0)
164
165#define START 3
166#define CONT 2
167#define STOP 1
168#define NOP 0
diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c
index 4e71a55120a0..5f63af6b88a2 100644
--- a/sound/pci/azt3328.c
+++ b/sound/pci/azt3328.c
@@ -157,8 +157,8 @@ MODULE_SUPPORTED_DEVICE("{{Aztech,AZF3328}}");
157 157
158#if DEBUG_CALLS 158#if DEBUG_CALLS
159#define snd_azf3328_dbgcalls(format, args...) printk(format, ##args) 159#define snd_azf3328_dbgcalls(format, args...) printk(format, ##args)
160#define snd_azf3328_dbgcallenter() printk(KERN_ERR "--> %s\n", __FUNCTION__) 160#define snd_azf3328_dbgcallenter() printk(KERN_ERR "--> %s\n", __func__)
161#define snd_azf3328_dbgcallleave() printk(KERN_ERR "<-- %s\n", __FUNCTION__) 161#define snd_azf3328_dbgcallleave() printk(KERN_ERR "<-- %s\n", __func__)
162#else 162#else
163#define snd_azf3328_dbgcalls(format, args...) 163#define snd_azf3328_dbgcalls(format, args...)
164#define snd_azf3328_dbgcallenter() 164#define snd_azf3328_dbgcallenter()
@@ -1514,7 +1514,8 @@ snd_azf3328_free(struct snd_azf3328 *chip)
1514 /* well, at least we know how to disable the timer IRQ */ 1514 /* well, at least we know how to disable the timer IRQ */
1515 snd_azf3328_codec_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x00); 1515 snd_azf3328_codec_outb(chip, IDX_IO_TIMER_VALUE + 3, 0x00);
1516 1516
1517 synchronize_irq(chip->irq); 1517 if (chip->irq >= 0)
1518 synchronize_irq(chip->irq);
1518__end_hw: 1519__end_hw:
1519 snd_azf3328_free_joystick(chip); 1520 snd_azf3328_free_joystick(chip);
1520 if (chip->irq >= 0) 1521 if (chip->irq >= 0)
diff --git a/sound/pci/ca0106/ca0106_main.c b/sound/pci/ca0106/ca0106_main.c
index 176e0f0e8058..ecbe79b67e43 100644
--- a/sound/pci/ca0106/ca0106_main.c
+++ b/sound/pci/ca0106/ca0106_main.c
@@ -435,22 +435,22 @@ int snd_ca0106_i2c_write(struct snd_ca0106 *emu,
435static void snd_ca0106_intr_enable(struct snd_ca0106 *emu, unsigned int intrenb) 435static void snd_ca0106_intr_enable(struct snd_ca0106 *emu, unsigned int intrenb)
436{ 436{
437 unsigned long flags; 437 unsigned long flags;
438 unsigned int enable; 438 unsigned int intr_enable;
439 439
440 spin_lock_irqsave(&emu->emu_lock, flags); 440 spin_lock_irqsave(&emu->emu_lock, flags);
441 enable = inl(emu->port + INTE) | intrenb; 441 intr_enable = inl(emu->port + INTE) | intrenb;
442 outl(enable, emu->port + INTE); 442 outl(intr_enable, emu->port + INTE);
443 spin_unlock_irqrestore(&emu->emu_lock, flags); 443 spin_unlock_irqrestore(&emu->emu_lock, flags);
444} 444}
445 445
446static void snd_ca0106_intr_disable(struct snd_ca0106 *emu, unsigned int intrenb) 446static void snd_ca0106_intr_disable(struct snd_ca0106 *emu, unsigned int intrenb)
447{ 447{
448 unsigned long flags; 448 unsigned long flags;
449 unsigned int enable; 449 unsigned int intr_enable;
450 450
451 spin_lock_irqsave(&emu->emu_lock, flags); 451 spin_lock_irqsave(&emu->emu_lock, flags);
452 enable = inl(emu->port + INTE) & ~intrenb; 452 intr_enable = inl(emu->port + INTE) & ~intrenb;
453 outl(enable, emu->port + INTE); 453 outl(intr_enable, emu->port + INTE);
454 spin_unlock_irqrestore(&emu->emu_lock, flags); 454 spin_unlock_irqrestore(&emu->emu_lock, flags);
455} 455}
456 456
@@ -1114,6 +1114,8 @@ static int snd_ca0106_free(struct snd_ca0106 *chip)
1114 * So we can fix: snd-malloc: Memory leak? pages not freed = 8 1114 * So we can fix: snd-malloc: Memory leak? pages not freed = 8
1115 */ 1115 */
1116 } 1116 }
1117 if (chip->irq >= 0)
1118 free_irq(chip->irq, chip);
1117 // release the data 1119 // release the data
1118#if 1 1120#if 1
1119 if (chip->buffer.area) 1121 if (chip->buffer.area)
@@ -1123,9 +1125,6 @@ static int snd_ca0106_free(struct snd_ca0106 *chip)
1123 // release the i/o port 1125 // release the i/o port
1124 release_and_free_resource(chip->res_port); 1126 release_and_free_resource(chip->res_port);
1125 1127
1126 // release the irq
1127 if (chip->irq >= 0)
1128 free_irq(chip->irq, chip);
1129 pci_disable_device(chip->pci); 1128 pci_disable_device(chip->pci);
1130 kfree(chip); 1129 kfree(chip);
1131 return 0; 1130 return 0;
diff --git a/sound/pci/ca0106/ca0106_mixer.c b/sound/pci/ca0106/ca0106_mixer.c
index af736869d9b1..3025ed1b6e1e 100644
--- a/sound/pci/ca0106/ca0106_mixer.c
+++ b/sound/pci/ca0106/ca0106_mixer.c
@@ -650,19 +650,55 @@ static int __devinit rename_ctl(struct snd_card *card, const char *src, const ch
650 650
651#define ADD_CTLS(emu, ctls) \ 651#define ADD_CTLS(emu, ctls) \
652 do { \ 652 do { \
653 int i, err; \ 653 int i, _err; \
654 for (i = 0; i < ARRAY_SIZE(ctls); i++) { \ 654 for (i = 0; i < ARRAY_SIZE(ctls); i++) { \
655 err = snd_ctl_add(card, snd_ctl_new1(&ctls[i], emu)); \ 655 _err = snd_ctl_add(card, snd_ctl_new1(&ctls[i], emu)); \
656 if (err < 0) \ 656 if (_err < 0) \
657 return err; \ 657 return _err; \
658 } \ 658 } \
659 } while (0) 659 } while (0)
660 660
661static __devinitdata
662DECLARE_TLV_DB_SCALE(snd_ca0106_master_db_scale, -6375, 50, 1);
663
664static char *slave_vols[] __devinitdata = {
665 "Analog Front Playback Volume",
666 "Analog Rear Playback Volume",
667 "Analog Center/LFE Playback Volume",
668 "Analog Side Playback Volume",
669 "IEC958 Front Playback Volume",
670 "IEC958 Rear Playback Volume",
671 "IEC958 Center/LFE Playback Volume",
672 "IEC958 Unknown Playback Volume",
673 "CAPTURE feedback Playback Volume",
674 NULL
675};
676
677static char *slave_sws[] __devinitdata = {
678 "Analog Front Playback Switch",
679 "Analog Rear Playback Switch",
680 "Analog Center/LFE Playback Switch",
681 "Analog Side Playback Switch",
682 "IEC958 Playback Switch",
683 NULL
684};
685
686static void __devinit add_slaves(struct snd_card *card,
687 struct snd_kcontrol *master, char **list)
688{
689 for (; *list; list++) {
690 struct snd_kcontrol *slave = ctl_find(card, *list);
691 if (slave)
692 snd_ctl_add_slave(master, slave);
693 }
694}
695
661int __devinit snd_ca0106_mixer(struct snd_ca0106 *emu) 696int __devinit snd_ca0106_mixer(struct snd_ca0106 *emu)
662{ 697{
663 int err; 698 int err;
664 struct snd_card *card = emu->card; 699 struct snd_card *card = emu->card;
665 char **c; 700 char **c;
701 struct snd_kcontrol *vmaster;
666 static char *ca0106_remove_ctls[] = { 702 static char *ca0106_remove_ctls[] = {
667 "Master Mono Playback Switch", 703 "Master Mono Playback Switch",
668 "Master Mono Playback Volume", 704 "Master Mono Playback Volume",
@@ -719,6 +755,21 @@ int __devinit snd_ca0106_mixer(struct snd_ca0106 *emu)
719 } 755 }
720 if (emu->details->spi_dac == 1) 756 if (emu->details->spi_dac == 1)
721 ADD_CTLS(emu, snd_ca0106_volume_spi_dac_ctls); 757 ADD_CTLS(emu, snd_ca0106_volume_spi_dac_ctls);
758
759 /* Create virtual master controls */
760 vmaster = snd_ctl_make_virtual_master("Master Playback Volume",
761 snd_ca0106_master_db_scale);
762 if (!vmaster)
763 return -ENOMEM;
764 add_slaves(card, vmaster, slave_vols);
765
766 if (emu->details->spi_dac == 1) {
767 vmaster = snd_ctl_make_virtual_master("Master Playback Switch",
768 NULL);
769 if (!vmaster)
770 return -ENOMEM;
771 add_slaves(card, vmaster, slave_sws);
772 }
722 return 0; 773 return 0;
723} 774}
724 775
diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
index 135f30860753..9971b5b7735b 100644
--- a/sound/pci/cmipci.c
+++ b/sound/pci/cmipci.c
@@ -2744,12 +2744,13 @@ static int __devinit snd_cmipci_mixer_new(struct cmipci *cm, int pcm_spdif_devic
2744 } 2744 }
2745 2745
2746 for (idx = 0; idx < CM_SAVED_MIXERS; idx++) { 2746 for (idx = 0; idx < CM_SAVED_MIXERS; idx++) {
2747 struct snd_ctl_elem_id id; 2747 struct snd_ctl_elem_id elem_id;
2748 struct snd_kcontrol *ctl; 2748 struct snd_kcontrol *ctl;
2749 memset(&id, 0, sizeof(id)); 2749 memset(&elem_id, 0, sizeof(elem_id));
2750 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 2750 elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2751 strcpy(id.name, cm_saved_mixer[idx].name); 2751 strcpy(elem_id.name, cm_saved_mixer[idx].name);
2752 if ((ctl = snd_ctl_find_id(cm->card, &id)) != NULL) 2752 ctl = snd_ctl_find_id(cm->card, &elem_id);
2753 if (ctl)
2753 cm->mixer_res_ctl[idx] = ctl; 2754 cm->mixer_res_ctl[idx] = ctl;
2754 } 2755 }
2755 2756
@@ -2932,8 +2933,6 @@ static int snd_cmipci_free(struct cmipci *cm)
2932 /* reset mixer */ 2933 /* reset mixer */
2933 snd_cmipci_mixer_write(cm, 0, 0); 2934 snd_cmipci_mixer_write(cm, 0, 0);
2934 2935
2935 synchronize_irq(cm->irq);
2936
2937 free_irq(cm->irq, cm); 2936 free_irq(cm->irq, cm);
2938 } 2937 }
2939 2938
diff --git a/sound/pci/cs46xx/cs46xx_lib.c b/sound/pci/cs46xx/cs46xx_lib.c
index 87ddffcd9d89..e214e567dec8 100644
--- a/sound/pci/cs46xx/cs46xx_lib.c
+++ b/sound/pci/cs46xx/cs46xx_lib.c
@@ -2772,6 +2772,9 @@ static int snd_cs46xx_free(struct snd_cs46xx *chip)
2772 if (chip->irq >= 0) 2772 if (chip->irq >= 0)
2773 free_irq(chip->irq, chip); 2773 free_irq(chip->irq, chip);
2774 2774
2775 if (chip->active_ctrl)
2776 chip->active_ctrl(chip, -chip->amplifier);
2777
2775 for (idx = 0; idx < 5; idx++) { 2778 for (idx = 0; idx < 5; idx++) {
2776 struct snd_cs46xx_region *region = &chip->region.idx[idx]; 2779 struct snd_cs46xx_region *region = &chip->region.idx[idx];
2777 if (region->remap_addr) 2780 if (region->remap_addr)
@@ -2779,9 +2782,6 @@ static int snd_cs46xx_free(struct snd_cs46xx *chip)
2779 release_and_free_resource(region->resource); 2782 release_and_free_resource(region->resource);
2780 } 2783 }
2781 2784
2782 if (chip->active_ctrl)
2783 chip->active_ctrl(chip, -chip->amplifier);
2784
2785#ifdef CONFIG_SND_CS46XX_NEW_DSP 2785#ifdef CONFIG_SND_CS46XX_NEW_DSP
2786 if (chip->dsp_spos_instance) { 2786 if (chip->dsp_spos_instance) {
2787 cs46xx_dsp_spos_destroy(chip); 2787 cs46xx_dsp_spos_destroy(chip);
diff --git a/sound/pci/echoaudio/echoaudio.c b/sound/pci/echoaudio/echoaudio.c
index 90ec090792ba..e16dc92e82fb 100644
--- a/sound/pci/echoaudio/echoaudio.c
+++ b/sound/pci/echoaudio/echoaudio.c
@@ -1852,15 +1852,16 @@ static irqreturn_t snd_echo_interrupt(int irq, void *dev_id)
1852static int snd_echo_free(struct echoaudio *chip) 1852static int snd_echo_free(struct echoaudio *chip)
1853{ 1853{
1854 DE_INIT(("Stop DSP...\n")); 1854 DE_INIT(("Stop DSP...\n"));
1855 if (chip->comm_page) { 1855 if (chip->comm_page)
1856 rest_in_peace(chip); 1856 rest_in_peace(chip);
1857 snd_dma_free_pages(&chip->commpage_dma_buf);
1858 }
1859 DE_INIT(("Stopped.\n")); 1857 DE_INIT(("Stopped.\n"));
1860 1858
1861 if (chip->irq >= 0) 1859 if (chip->irq >= 0)
1862 free_irq(chip->irq, chip); 1860 free_irq(chip->irq, chip);
1863 1861
1862 if (chip->comm_page)
1863 snd_dma_free_pages(&chip->commpage_dma_buf);
1864
1864 if (chip->dsp_registers) 1865 if (chip->dsp_registers)
1865 iounmap(chip->dsp_registers); 1866 iounmap(chip->dsp_registers);
1866 1867
diff --git a/sound/pci/emu10k1/emu10k1_main.c b/sound/pci/emu10k1/emu10k1_main.c
index 9a9b977d3cf1..abde5b901884 100644
--- a/sound/pci/emu10k1/emu10k1_main.c
+++ b/sound/pci/emu10k1/emu10k1_main.c
@@ -1249,11 +1249,6 @@ static int snd_emu10k1_free(struct snd_emu10k1 *emu)
1249 if (emu->port) { /* avoid access to already used hardware */ 1249 if (emu->port) { /* avoid access to already used hardware */
1250 snd_emu10k1_fx8010_tram_setup(emu, 0); 1250 snd_emu10k1_fx8010_tram_setup(emu, 0);
1251 snd_emu10k1_done(emu); 1251 snd_emu10k1_done(emu);
1252 /* remove reserved page */
1253 if (emu->reserved_page) {
1254 snd_emu10k1_synth_free(emu, (struct snd_util_memblk *)emu->reserved_page);
1255 emu->reserved_page = NULL;
1256 }
1257 snd_emu10k1_free_efx(emu); 1252 snd_emu10k1_free_efx(emu);
1258 } 1253 }
1259 if (emu->card_capabilities->emu_model == EMU_MODEL_EMU1010) { 1254 if (emu->card_capabilities->emu_model == EMU_MODEL_EMU1010) {
@@ -1262,6 +1257,14 @@ static int snd_emu10k1_free(struct snd_emu10k1 *emu)
1262 } 1257 }
1263 if (emu->emu1010.firmware_thread) 1258 if (emu->emu1010.firmware_thread)
1264 kthread_stop(emu->emu1010.firmware_thread); 1259 kthread_stop(emu->emu1010.firmware_thread);
1260 if (emu->irq >= 0)
1261 free_irq(emu->irq, emu);
1262 /* remove reserved page */
1263 if (emu->reserved_page) {
1264 snd_emu10k1_synth_free(emu,
1265 (struct snd_util_memblk *)emu->reserved_page);
1266 emu->reserved_page = NULL;
1267 }
1265 if (emu->memhdr) 1268 if (emu->memhdr)
1266 snd_util_memhdr_free(emu->memhdr); 1269 snd_util_memhdr_free(emu->memhdr);
1267 if (emu->silent_page.area) 1270 if (emu->silent_page.area)
@@ -1273,8 +1276,6 @@ static int snd_emu10k1_free(struct snd_emu10k1 *emu)
1273#ifdef CONFIG_PM 1276#ifdef CONFIG_PM
1274 free_pm_buffer(emu); 1277 free_pm_buffer(emu);
1275#endif 1278#endif
1276 if (emu->irq >= 0)
1277 free_irq(emu->irq, emu);
1278 if (emu->port) 1279 if (emu->port)
1279 pci_release_regions(emu->pci); 1280 pci_release_regions(emu->pci);
1280 if (emu->card_capabilities->ca0151_chip) /* P16V */ 1281 if (emu->card_capabilities->ca0151_chip) /* P16V */
diff --git a/sound/pci/emu10k1/emu10k1x.c b/sound/pci/emu10k1/emu10k1x.c
index 5512abd98bd9..491a4a50f869 100644
--- a/sound/pci/emu10k1/emu10k1x.c
+++ b/sound/pci/emu10k1/emu10k1x.c
@@ -327,22 +327,22 @@ static void snd_emu10k1x_ptr_write(struct emu10k1x *emu,
327static void snd_emu10k1x_intr_enable(struct emu10k1x *emu, unsigned int intrenb) 327static void snd_emu10k1x_intr_enable(struct emu10k1x *emu, unsigned int intrenb)
328{ 328{
329 unsigned long flags; 329 unsigned long flags;
330 unsigned int enable; 330 unsigned int intr_enable;
331 331
332 spin_lock_irqsave(&emu->emu_lock, flags); 332 spin_lock_irqsave(&emu->emu_lock, flags);
333 enable = inl(emu->port + INTE) | intrenb; 333 intr_enable = inl(emu->port + INTE) | intrenb;
334 outl(enable, emu->port + INTE); 334 outl(intr_enable, emu->port + INTE);
335 spin_unlock_irqrestore(&emu->emu_lock, flags); 335 spin_unlock_irqrestore(&emu->emu_lock, flags);
336} 336}
337 337
338static void snd_emu10k1x_intr_disable(struct emu10k1x *emu, unsigned int intrenb) 338static void snd_emu10k1x_intr_disable(struct emu10k1x *emu, unsigned int intrenb)
339{ 339{
340 unsigned long flags; 340 unsigned long flags;
341 unsigned int enable; 341 unsigned int intr_enable;
342 342
343 spin_lock_irqsave(&emu->emu_lock, flags); 343 spin_lock_irqsave(&emu->emu_lock, flags);
344 enable = inl(emu->port + INTE) & ~intrenb; 344 intr_enable = inl(emu->port + INTE) & ~intrenb;
345 outl(enable, emu->port + INTE); 345 outl(intr_enable, emu->port + INTE);
346 spin_unlock_irqrestore(&emu->emu_lock, flags); 346 spin_unlock_irqrestore(&emu->emu_lock, flags);
347} 347}
348 348
@@ -754,13 +754,13 @@ static int snd_emu10k1x_free(struct emu10k1x *chip)
754 // disable audio 754 // disable audio
755 outl(HCFG_LOCKSOUNDCACHE, chip->port + HCFG); 755 outl(HCFG_LOCKSOUNDCACHE, chip->port + HCFG);
756 756
757 // release the i/o port 757 /* release the irq */
758 release_and_free_resource(chip->res_port);
759
760 // release the irq
761 if (chip->irq >= 0) 758 if (chip->irq >= 0)
762 free_irq(chip->irq, chip); 759 free_irq(chip->irq, chip);
763 760
761 // release the i/o port
762 release_and_free_resource(chip->res_port);
763
764 // release the DMA 764 // release the DMA
765 if (chip->dma_buffer.area) { 765 if (chip->dma_buffer.area) {
766 snd_dma_free_pages(&chip->dma_buffer); 766 snd_dma_free_pages(&chip->dma_buffer);
@@ -795,9 +795,9 @@ static irqreturn_t snd_emu10k1x_interrupt(int irq, void *dev_id)
795 795
796 // capture interrupt 796 // capture interrupt
797 if (status & (IPR_CAP_0_LOOP | IPR_CAP_0_HALF_LOOP)) { 797 if (status & (IPR_CAP_0_LOOP | IPR_CAP_0_HALF_LOOP)) {
798 struct emu10k1x_voice *pvoice = &chip->capture_voice; 798 struct emu10k1x_voice *cap_voice = &chip->capture_voice;
799 if (pvoice->use) 799 if (cap_voice->use)
800 snd_emu10k1x_pcm_interrupt(chip, pvoice); 800 snd_emu10k1x_pcm_interrupt(chip, cap_voice);
801 else 801 else
802 snd_emu10k1x_intr_disable(chip, 802 snd_emu10k1x_intr_disable(chip,
803 INTE_CAP_0_LOOP | 803 INTE_CAP_0_LOOP |
diff --git a/sound/pci/emu10k1/emuproc.c b/sound/pci/emu10k1/emuproc.c
index f3caa3f890c6..216f9748aff5 100644
--- a/sound/pci/emu10k1/emuproc.c
+++ b/sound/pci/emu10k1/emuproc.c
@@ -412,7 +412,7 @@ static void snd_emu_proc_emu1010_reg_read(struct snd_info_entry *entry,
412 struct snd_info_buffer *buffer) 412 struct snd_info_buffer *buffer)
413{ 413{
414 struct snd_emu10k1 *emu = entry->private_data; 414 struct snd_emu10k1 *emu = entry->private_data;
415 int value; 415 u32 value;
416 unsigned long flags; 416 unsigned long flags;
417 int i; 417 int i;
418 snd_iprintf(buffer, "EMU1010 Registers:\n\n"); 418 snd_iprintf(buffer, "EMU1010 Registers:\n\n");
diff --git a/sound/pci/ens1370.c b/sound/pci/ens1370.c
index 72d85a5ae6a0..fbf1124f7c79 100644
--- a/sound/pci/ens1370.c
+++ b/sound/pci/ens1370.c
@@ -1635,20 +1635,20 @@ static int __devinit snd_ensoniq_1371_mixer(struct ensoniq *ensoniq,
1635 if (has_spdif > 0 || 1635 if (has_spdif > 0 ||
1636 (!has_spdif && es1371_quirk_lookup(ensoniq, es1371_spdif_present))) { 1636 (!has_spdif && es1371_quirk_lookup(ensoniq, es1371_spdif_present))) {
1637 struct snd_kcontrol *kctl; 1637 struct snd_kcontrol *kctl;
1638 int i, index = 0; 1638 int i, is_spdif = 0;
1639 1639
1640 ensoniq->spdif_default = ensoniq->spdif_stream = 1640 ensoniq->spdif_default = ensoniq->spdif_stream =
1641 SNDRV_PCM_DEFAULT_CON_SPDIF; 1641 SNDRV_PCM_DEFAULT_CON_SPDIF;
1642 outl(ensoniq->spdif_default, ES_REG(ensoniq, CHANNEL_STATUS)); 1642 outl(ensoniq->spdif_default, ES_REG(ensoniq, CHANNEL_STATUS));
1643 1643
1644 if (ensoniq->u.es1371.ac97->ext_id & AC97_EI_SPDIF) 1644 if (ensoniq->u.es1371.ac97->ext_id & AC97_EI_SPDIF)
1645 index++; 1645 is_spdif++;
1646 1646
1647 for (i = 0; i < ARRAY_SIZE(snd_es1371_mixer_spdif); i++) { 1647 for (i = 0; i < ARRAY_SIZE(snd_es1371_mixer_spdif); i++) {
1648 kctl = snd_ctl_new1(&snd_es1371_mixer_spdif[i], ensoniq); 1648 kctl = snd_ctl_new1(&snd_es1371_mixer_spdif[i], ensoniq);
1649 if (!kctl) 1649 if (!kctl)
1650 return -ENOMEM; 1650 return -ENOMEM;
1651 kctl->id.index = index; 1651 kctl->id.index = is_spdif;
1652 err = snd_ctl_add(card, kctl); 1652 err = snd_ctl_add(card, kctl);
1653 if (err < 0) 1653 if (err < 0)
1654 return err; 1654 return err;
@@ -1910,7 +1910,8 @@ static int snd_ensoniq_free(struct ensoniq *ensoniq)
1910 outl(0, ES_REG(ensoniq, CONTROL)); /* switch everything off */ 1910 outl(0, ES_REG(ensoniq, CONTROL)); /* switch everything off */
1911 outl(0, ES_REG(ensoniq, SERIAL)); /* clear serial interface */ 1911 outl(0, ES_REG(ensoniq, SERIAL)); /* clear serial interface */
1912#endif 1912#endif
1913 synchronize_irq(ensoniq->irq); 1913 if (ensoniq->irq >= 0)
1914 synchronize_irq(ensoniq->irq);
1914 pci_set_power_state(ensoniq->pci, 3); 1915 pci_set_power_state(ensoniq->pci, 3);
1915 __hw_end: 1916 __hw_end:
1916#ifdef CHIP1370 1917#ifdef CHIP1370
diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c
index 1a314fa99c45..84fac1fbf103 100644
--- a/sound/pci/es1938.c
+++ b/sound/pci/es1938.c
@@ -1488,7 +1488,6 @@ static int es1938_suspend(struct pci_dev *pci, pm_message_t state)
1488 1488
1489 outb(0x00, SLIO_REG(chip, IRQCONTROL)); /* disable irqs */ 1489 outb(0x00, SLIO_REG(chip, IRQCONTROL)); /* disable irqs */
1490 if (chip->irq >= 0) { 1490 if (chip->irq >= 0) {
1491 synchronize_irq(chip->irq);
1492 free_irq(chip->irq, chip); 1491 free_irq(chip->irq, chip);
1493 chip->irq = -1; 1492 chip->irq = -1;
1494 } 1493 }
@@ -1578,10 +1577,8 @@ static int snd_es1938_free(struct es1938 *chip)
1578 1577
1579 snd_es1938_free_gameport(chip); 1578 snd_es1938_free_gameport(chip);
1580 1579
1581 if (chip->irq >= 0) { 1580 if (chip->irq >= 0)
1582 synchronize_irq(chip->irq);
1583 free_irq(chip->irq, chip); 1581 free_irq(chip->irq, chip);
1584 }
1585 pci_release_regions(chip->pci); 1582 pci_release_regions(chip->pci);
1586 pci_disable_device(chip->pci); 1583 pci_disable_device(chip->pci);
1587 kfree(chip); 1584 kfree(chip);
diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c
index 7d911a18c082..1bf298d214b9 100644
--- a/sound/pci/es1968.c
+++ b/sound/pci/es1968.c
@@ -1827,6 +1827,22 @@ snd_es1968_pcm(struct es1968 *chip, int device)
1827 1827
1828 return 0; 1828 return 0;
1829} 1829}
1830/*
1831 * suppress jitter on some maestros when playing stereo
1832 */
1833static void snd_es1968_suppress_jitter(struct es1968 *chip, struct esschan *es)
1834{
1835 unsigned int cp1;
1836 unsigned int cp2;
1837 unsigned int diff;
1838
1839 cp1 = __apu_get_register(chip, 0, 5);
1840 cp2 = __apu_get_register(chip, 1, 5);
1841 diff = (cp1 > cp2 ? cp1 - cp2 : cp2 - cp1);
1842
1843 if (diff > 1)
1844 __maestro_write(chip, IDR0_DATA_PORT, cp1);
1845}
1830 1846
1831/* 1847/*
1832 * update pointer 1848 * update pointer
@@ -1948,8 +1964,11 @@ static irqreturn_t snd_es1968_interrupt(int irq, void *dev_id)
1948 struct esschan *es; 1964 struct esschan *es;
1949 spin_lock(&chip->substream_lock); 1965 spin_lock(&chip->substream_lock);
1950 list_for_each_entry(es, &chip->substream_list, list) { 1966 list_for_each_entry(es, &chip->substream_list, list) {
1951 if (es->running) 1967 if (es->running) {
1952 snd_es1968_update_pcm(chip, es); 1968 snd_es1968_update_pcm(chip, es);
1969 if (es->fmt & ESS_FMT_STEREO)
1970 snd_es1968_suppress_jitter(chip, es);
1971 }
1953 } 1972 }
1954 spin_unlock(&chip->substream_lock); 1973 spin_unlock(&chip->substream_lock);
1955 if (chip->in_measurement) { 1974 if (chip->in_measurement) {
@@ -1972,7 +1991,7 @@ snd_es1968_mixer(struct es1968 *chip)
1972{ 1991{
1973 struct snd_ac97_bus *pbus; 1992 struct snd_ac97_bus *pbus;
1974 struct snd_ac97_template ac97; 1993 struct snd_ac97_template ac97;
1975 struct snd_ctl_elem_id id; 1994 struct snd_ctl_elem_id elem_id;
1976 int err; 1995 int err;
1977 static struct snd_ac97_bus_ops ops = { 1996 static struct snd_ac97_bus_ops ops = {
1978 .write = snd_es1968_ac97_write, 1997 .write = snd_es1968_ac97_write,
@@ -1989,14 +2008,14 @@ snd_es1968_mixer(struct es1968 *chip)
1989 return err; 2008 return err;
1990 2009
1991 /* attach master switch / volumes for h/w volume control */ 2010 /* attach master switch / volumes for h/w volume control */
1992 memset(&id, 0, sizeof(id)); 2011 memset(&elem_id, 0, sizeof(elem_id));
1993 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 2012 elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1994 strcpy(id.name, "Master Playback Switch"); 2013 strcpy(elem_id.name, "Master Playback Switch");
1995 chip->master_switch = snd_ctl_find_id(chip->card, &id); 2014 chip->master_switch = snd_ctl_find_id(chip->card, &elem_id);
1996 memset(&id, 0, sizeof(id)); 2015 memset(&elem_id, 0, sizeof(elem_id));
1997 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 2016 elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1998 strcpy(id.name, "Master Playback Volume"); 2017 strcpy(elem_id.name, "Master Playback Volume");
1999 chip->master_volume = snd_ctl_find_id(chip->card, &id); 2018 chip->master_volume = snd_ctl_find_id(chip->card, &elem_id);
2000 2019
2001 return 0; 2020 return 0;
2002} 2021}
@@ -2456,7 +2475,8 @@ static inline void snd_es1968_free_gameport(struct es1968 *chip) { }
2456static int snd_es1968_free(struct es1968 *chip) 2475static int snd_es1968_free(struct es1968 *chip)
2457{ 2476{
2458 if (chip->io_port) { 2477 if (chip->io_port) {
2459 synchronize_irq(chip->irq); 2478 if (chip->irq >= 0)
2479 synchronize_irq(chip->irq);
2460 outw(1, chip->io_port + 0x04); /* clear WP interrupts */ 2480 outw(1, chip->io_port + 0x04); /* clear WP interrupts */
2461 outw(0, chip->io_port + ESM_PORT_HOST_IRQ); /* disable IRQ */ 2481 outw(0, chip->io_port + ESM_PORT_HOST_IRQ); /* disable IRQ */
2462 } 2482 }
diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c
index 4c300e6149fc..c129f9e2072c 100644
--- a/sound/pci/fm801.c
+++ b/sound/pci/fm801.c
@@ -1285,7 +1285,6 @@ static int wait_for_codec(struct fm801 *chip, unsigned int codec_id,
1285 1285
1286static int snd_fm801_chip_init(struct fm801 *chip, int resume) 1286static int snd_fm801_chip_init(struct fm801 *chip, int resume)
1287{ 1287{
1288 int id;
1289 unsigned short cmdw; 1288 unsigned short cmdw;
1290 1289
1291 if (chip->tea575x_tuner & 0x0010) 1290 if (chip->tea575x_tuner & 0x0010)
@@ -1310,13 +1309,14 @@ static int snd_fm801_chip_init(struct fm801 *chip, int resume)
1310 } else { 1309 } else {
1311 /* my card has the secondary codec */ 1310 /* my card has the secondary codec */
1312 /* at address #3, so the loop is inverted */ 1311 /* at address #3, so the loop is inverted */
1313 for (id = 3; id > 0; id--) { 1312 int i;
1314 if (! wait_for_codec(chip, id, AC97_VENDOR_ID1, 1313 for (i = 3; i > 0; i--) {
1314 if (!wait_for_codec(chip, i, AC97_VENDOR_ID1,
1315 msecs_to_jiffies(50))) { 1315 msecs_to_jiffies(50))) {
1316 cmdw = inw(FM801_REG(chip, AC97_DATA)); 1316 cmdw = inw(FM801_REG(chip, AC97_DATA));
1317 if (cmdw != 0xffff && cmdw != 0) { 1317 if (cmdw != 0xffff && cmdw != 0) {
1318 chip->secondary = 1; 1318 chip->secondary = 1;
1319 chip->secondary_addr = id; 1319 chip->secondary_addr = i;
1320 break; 1320 break;
1321 } 1321 }
1322 } 1322 }
diff --git a/sound/pci/hda/Makefile b/sound/pci/hda/Makefile
index 9e0d8a1268aa..ab0c726d648e 100644
--- a/sound/pci/hda/Makefile
+++ b/sound/pci/hda/Makefile
@@ -2,7 +2,7 @@ snd-hda-intel-y := hda_intel.o
2# since snd-hda-intel is the only driver using hda-codec, 2# since snd-hda-intel is the only driver using hda-codec,
3# merge it into a single module although it was originally 3# merge it into a single module although it was originally
4# designed to be individual modules 4# designed to be individual modules
5snd-hda-intel-y += hda_codec.o vmaster.o 5snd-hda-intel-y += hda_codec.o
6snd-hda-intel-$(CONFIG_PROC_FS) += hda_proc.o 6snd-hda-intel-$(CONFIG_PROC_FS) += hda_proc.o
7snd-hda-intel-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o 7snd-hda-intel-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o
8snd-hda-intel-$(CONFIG_SND_HDA_GENERIC) += hda_generic.o 8snd-hda-intel-$(CONFIG_SND_HDA_GENERIC) += hda_generic.o
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 37c413923db8..a6be6e3e8716 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -31,6 +31,7 @@
31#include <sound/initval.h> 31#include <sound/initval.h>
32#include "hda_local.h" 32#include "hda_local.h"
33#include <sound/hda_hwdep.h> 33#include <sound/hda_hwdep.h>
34#include "hda_patch.h" /* codec presets */
34 35
35#ifdef CONFIG_SND_HDA_POWER_SAVE 36#ifdef CONFIG_SND_HDA_POWER_SAVE
36/* define this option here to hide as static */ 37/* define this option here to hide as static */
@@ -51,21 +52,50 @@ struct hda_vendor_id {
51 52
52/* codec vendor labels */ 53/* codec vendor labels */
53static struct hda_vendor_id hda_vendor_ids[] = { 54static struct hda_vendor_id hda_vendor_ids[] = {
54 { 0x10ec, "Realtek" }, 55 { 0x1002, "ATI" },
55 { 0x1057, "Motorola" }, 56 { 0x1057, "Motorola" },
57 { 0x1095, "Silicon Image" },
58 { 0x10ec, "Realtek" },
56 { 0x1106, "VIA" }, 59 { 0x1106, "VIA" },
57 { 0x111d, "IDT" }, 60 { 0x111d, "IDT" },
61 { 0x11c1, "LSI" },
58 { 0x11d4, "Analog Devices" }, 62 { 0x11d4, "Analog Devices" },
59 { 0x13f6, "C-Media" }, 63 { 0x13f6, "C-Media" },
60 { 0x14f1, "Conexant" }, 64 { 0x14f1, "Conexant" },
65 { 0x17e8, "Chrontel" },
66 { 0x1854, "LG" },
61 { 0x434d, "C-Media" }, 67 { 0x434d, "C-Media" },
62 { 0x8384, "SigmaTel" }, 68 { 0x8384, "SigmaTel" },
63 {} /* terminator */ 69 {} /* terminator */
64}; 70};
65 71
66/* codec presets */ 72static const struct hda_codec_preset *hda_preset_tables[] = {
67#include "hda_patch.h" 73#ifdef CONFIG_SND_HDA_CODEC_REALTEK
68 74 snd_hda_preset_realtek,
75#endif
76#ifdef CONFIG_SND_HDA_CODEC_CMEDIA
77 snd_hda_preset_cmedia,
78#endif
79#ifdef CONFIG_SND_HDA_CODEC_ANALOG
80 snd_hda_preset_analog,
81#endif
82#ifdef CONFIG_SND_HDA_CODEC_SIGMATEL
83 snd_hda_preset_sigmatel,
84#endif
85#ifdef CONFIG_SND_HDA_CODEC_SI3054
86 snd_hda_preset_si3054,
87#endif
88#ifdef CONFIG_SND_HDA_CODEC_ATIHDMI
89 snd_hda_preset_atihdmi,
90#endif
91#ifdef CONFIG_SND_HDA_CODEC_CONEXANT
92 snd_hda_preset_conexant,
93#endif
94#ifdef CONFIG_SND_HDA_CODEC_VIA
95 snd_hda_preset_via,
96#endif
97 NULL
98};
69 99
70#ifdef CONFIG_SND_HDA_POWER_SAVE 100#ifdef CONFIG_SND_HDA_POWER_SAVE
71static void hda_power_work(struct work_struct *work); 101static void hda_power_work(struct work_struct *work);
@@ -690,6 +720,19 @@ void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
690 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, format); 720 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, format);
691} 721}
692 722
723void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid)
724{
725 if (!nid)
726 return;
727
728 snd_printdd("hda_codec_cleanup_stream: NID=0x%x\n", nid);
729 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
730#if 0 /* keep the format */
731 msleep(1);
732 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0);
733#endif
734}
735
693/* 736/*
694 * amp access functions 737 * amp access functions
695 */ 738 */
@@ -1037,16 +1080,24 @@ void snd_hda_set_vmaster_tlv(struct hda_codec *codec, hda_nid_t nid, int dir,
1037} 1080}
1038 1081
1039/* find a mixer control element with the given name */ 1082/* find a mixer control element with the given name */
1040struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec, 1083static struct snd_kcontrol *
1041 const char *name) 1084_snd_hda_find_mixer_ctl(struct hda_codec *codec,
1085 const char *name, int idx)
1042{ 1086{
1043 struct snd_ctl_elem_id id; 1087 struct snd_ctl_elem_id id;
1044 memset(&id, 0, sizeof(id)); 1088 memset(&id, 0, sizeof(id));
1045 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 1089 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
1090 id.index = idx;
1046 strcpy(id.name, name); 1091 strcpy(id.name, name);
1047 return snd_ctl_find_id(codec->bus->card, &id); 1092 return snd_ctl_find_id(codec->bus->card, &id);
1048} 1093}
1049 1094
1095struct snd_kcontrol *snd_hda_find_mixer_ctl(struct hda_codec *codec,
1096 const char *name)
1097{
1098 return _snd_hda_find_mixer_ctl(codec, name, 0);
1099}
1100
1050/* create a virtual master control and add slaves */ 1101/* create a virtual master control and add slaves */
1051int snd_hda_add_vmaster(struct hda_codec *codec, char *name, 1102int snd_hda_add_vmaster(struct hda_codec *codec, char *name,
1052 unsigned int *tlv, const char **slaves) 1103 unsigned int *tlv, const char **slaves)
@@ -1481,6 +1532,8 @@ static struct snd_kcontrol_new dig_mixes[] = {
1481 { } /* end */ 1532 { } /* end */
1482}; 1533};
1483 1534
1535#define SPDIF_MAX_IDX 4 /* 4 instances should be enough to probe */
1536
1484/** 1537/**
1485 * snd_hda_create_spdif_out_ctls - create Output SPDIF-related controls 1538 * snd_hda_create_spdif_out_ctls - create Output SPDIF-related controls
1486 * @codec: the HDA codec 1539 * @codec: the HDA codec
@@ -1496,9 +1549,20 @@ int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid)
1496 int err; 1549 int err;
1497 struct snd_kcontrol *kctl; 1550 struct snd_kcontrol *kctl;
1498 struct snd_kcontrol_new *dig_mix; 1551 struct snd_kcontrol_new *dig_mix;
1552 int idx;
1499 1553
1554 for (idx = 0; idx < SPDIF_MAX_IDX; idx++) {
1555 if (!_snd_hda_find_mixer_ctl(codec, "IEC958 Playback Switch",
1556 idx))
1557 break;
1558 }
1559 if (idx >= SPDIF_MAX_IDX) {
1560 printk(KERN_ERR "hda_codec: too many IEC958 outputs\n");
1561 return -EBUSY;
1562 }
1500 for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) { 1563 for (dig_mix = dig_mixes; dig_mix->name; dig_mix++) {
1501 kctl = snd_ctl_new1(dig_mix, codec); 1564 kctl = snd_ctl_new1(dig_mix, codec);
1565 kctl->id.index = idx;
1502 kctl->private_value = nid; 1566 kctl->private_value = nid;
1503 err = snd_ctl_add(codec->bus->card, kctl); 1567 err = snd_ctl_add(codec->bus->card, kctl);
1504 if (err < 0) 1568 if (err < 0)
@@ -1512,6 +1576,43 @@ int snd_hda_create_spdif_out_ctls(struct hda_codec *codec, hda_nid_t nid)
1512} 1576}
1513 1577
1514/* 1578/*
1579 * SPDIF sharing with analog output
1580 */
1581static int spdif_share_sw_get(struct snd_kcontrol *kcontrol,
1582 struct snd_ctl_elem_value *ucontrol)
1583{
1584 struct hda_multi_out *mout = snd_kcontrol_chip(kcontrol);
1585 ucontrol->value.integer.value[0] = mout->share_spdif;
1586 return 0;
1587}
1588
1589static int spdif_share_sw_put(struct snd_kcontrol *kcontrol,
1590 struct snd_ctl_elem_value *ucontrol)
1591{
1592 struct hda_multi_out *mout = snd_kcontrol_chip(kcontrol);
1593 mout->share_spdif = !!ucontrol->value.integer.value[0];
1594 return 0;
1595}
1596
1597static struct snd_kcontrol_new spdif_share_sw = {
1598 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
1599 .name = "IEC958 Default PCM Playback Switch",
1600 .info = snd_ctl_boolean_mono_info,
1601 .get = spdif_share_sw_get,
1602 .put = spdif_share_sw_put,
1603};
1604
1605int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
1606 struct hda_multi_out *mout)
1607{
1608 if (!mout->dig_out_nid)
1609 return 0;
1610 /* ATTENTION: here mout is passed as private_data, instead of codec */
1611 return snd_ctl_add(codec->bus->card,
1612 snd_ctl_new1(&spdif_share_sw, mout));
1613}
1614
1615/*
1515 * SPDIF input 1616 * SPDIF input
1516 */ 1617 */
1517 1618
@@ -1595,7 +1696,17 @@ int snd_hda_create_spdif_in_ctls(struct hda_codec *codec, hda_nid_t nid)
1595 int err; 1696 int err;
1596 struct snd_kcontrol *kctl; 1697 struct snd_kcontrol *kctl;
1597 struct snd_kcontrol_new *dig_mix; 1698 struct snd_kcontrol_new *dig_mix;
1699 int idx;
1598 1700
1701 for (idx = 0; idx < SPDIF_MAX_IDX; idx++) {
1702 if (!_snd_hda_find_mixer_ctl(codec, "IEC958 Capture Switch",
1703 idx))
1704 break;
1705 }
1706 if (idx >= SPDIF_MAX_IDX) {
1707 printk(KERN_ERR "hda_codec: too many IEC958 inputs\n");
1708 return -EBUSY;
1709 }
1599 for (dig_mix = dig_in_ctls; dig_mix->name; dig_mix++) { 1710 for (dig_mix = dig_in_ctls; dig_mix->name; dig_mix++) {
1600 kctl = snd_ctl_new1(dig_mix, codec); 1711 kctl = snd_ctl_new1(dig_mix, codec);
1601 kctl->private_value = nid; 1712 kctl->private_value = nid;
@@ -2106,7 +2217,7 @@ static int hda_pcm_default_cleanup(struct hda_pcm_stream *hinfo,
2106 struct hda_codec *codec, 2217 struct hda_codec *codec,
2107 struct snd_pcm_substream *substream) 2218 struct snd_pcm_substream *substream)
2108{ 2219{
2109 snd_hda_codec_setup_stream(codec, hinfo->nid, 0, 0, 0); 2220 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
2110 return 0; 2221 return 0;
2111} 2222}
2112 2223
@@ -2491,7 +2602,7 @@ int snd_hda_multi_out_dig_open(struct hda_codec *codec,
2491 mutex_lock(&codec->spdif_mutex); 2602 mutex_lock(&codec->spdif_mutex);
2492 if (mout->dig_out_used == HDA_DIG_ANALOG_DUP) 2603 if (mout->dig_out_used == HDA_DIG_ANALOG_DUP)
2493 /* already opened as analog dup; reset it once */ 2604 /* already opened as analog dup; reset it once */
2494 snd_hda_codec_setup_stream(codec, mout->dig_out_nid, 0, 0, 0); 2605 snd_hda_codec_cleanup_stream(codec, mout->dig_out_nid);
2495 mout->dig_out_used = HDA_DIG_EXCLUSIVE; 2606 mout->dig_out_used = HDA_DIG_EXCLUSIVE;
2496 mutex_unlock(&codec->spdif_mutex); 2607 mutex_unlock(&codec->spdif_mutex);
2497 return 0; 2608 return 0;
@@ -2526,9 +2637,36 @@ int snd_hda_multi_out_dig_close(struct hda_codec *codec,
2526 */ 2637 */
2527int snd_hda_multi_out_analog_open(struct hda_codec *codec, 2638int snd_hda_multi_out_analog_open(struct hda_codec *codec,
2528 struct hda_multi_out *mout, 2639 struct hda_multi_out *mout,
2529 struct snd_pcm_substream *substream) 2640 struct snd_pcm_substream *substream,
2530{ 2641 struct hda_pcm_stream *hinfo)
2531 substream->runtime->hw.channels_max = mout->max_channels; 2642{
2643 struct snd_pcm_runtime *runtime = substream->runtime;
2644 runtime->hw.channels_max = mout->max_channels;
2645 if (mout->dig_out_nid) {
2646 if (!mout->analog_rates) {
2647 mout->analog_rates = hinfo->rates;
2648 mout->analog_formats = hinfo->formats;
2649 mout->analog_maxbps = hinfo->maxbps;
2650 } else {
2651 runtime->hw.rates = mout->analog_rates;
2652 runtime->hw.formats = mout->analog_formats;
2653 hinfo->maxbps = mout->analog_maxbps;
2654 }
2655 if (!mout->spdif_rates) {
2656 snd_hda_query_supported_pcm(codec, mout->dig_out_nid,
2657 &mout->spdif_rates,
2658 &mout->spdif_formats,
2659 &mout->spdif_maxbps);
2660 }
2661 mutex_lock(&codec->spdif_mutex);
2662 if (mout->share_spdif) {
2663 runtime->hw.rates &= mout->spdif_rates;
2664 runtime->hw.formats &= mout->spdif_formats;
2665 if (mout->spdif_maxbps < hinfo->maxbps)
2666 hinfo->maxbps = mout->spdif_maxbps;
2667 }
2668 mutex_unlock(&codec->spdif_mutex);
2669 }
2532 return snd_pcm_hw_constraint_step(substream->runtime, 0, 2670 return snd_pcm_hw_constraint_step(substream->runtime, 0,
2533 SNDRV_PCM_HW_PARAM_CHANNELS, 2); 2671 SNDRV_PCM_HW_PARAM_CHANNELS, 2);
2534} 2672}
@@ -2548,7 +2686,8 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
2548 int i; 2686 int i;
2549 2687
2550 mutex_lock(&codec->spdif_mutex); 2688 mutex_lock(&codec->spdif_mutex);
2551 if (mout->dig_out_nid && mout->dig_out_used != HDA_DIG_EXCLUSIVE) { 2689 if (mout->dig_out_nid && mout->share_spdif &&
2690 mout->dig_out_used != HDA_DIG_EXCLUSIVE) {
2552 if (chs == 2 && 2691 if (chs == 2 &&
2553 snd_hda_is_supported_format(codec, mout->dig_out_nid, 2692 snd_hda_is_supported_format(codec, mout->dig_out_nid,
2554 format) && 2693 format) &&
@@ -2558,8 +2697,7 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
2558 stream_tag, format); 2697 stream_tag, format);
2559 } else { 2698 } else {
2560 mout->dig_out_used = 0; 2699 mout->dig_out_used = 0;
2561 snd_hda_codec_setup_stream(codec, mout->dig_out_nid, 2700 snd_hda_codec_cleanup_stream(codec, mout->dig_out_nid);
2562 0, 0, 0);
2563 } 2701 }
2564 } 2702 }
2565 mutex_unlock(&codec->spdif_mutex); 2703 mutex_unlock(&codec->spdif_mutex);
@@ -2601,17 +2739,16 @@ int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
2601 int i; 2739 int i;
2602 2740
2603 for (i = 0; i < mout->num_dacs; i++) 2741 for (i = 0; i < mout->num_dacs; i++)
2604 snd_hda_codec_setup_stream(codec, nids[i], 0, 0, 0); 2742 snd_hda_codec_cleanup_stream(codec, nids[i]);
2605 if (mout->hp_nid) 2743 if (mout->hp_nid)
2606 snd_hda_codec_setup_stream(codec, mout->hp_nid, 0, 0, 0); 2744 snd_hda_codec_cleanup_stream(codec, mout->hp_nid);
2607 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) 2745 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
2608 if (mout->extra_out_nid[i]) 2746 if (mout->extra_out_nid[i])
2609 snd_hda_codec_setup_stream(codec, 2747 snd_hda_codec_cleanup_stream(codec,
2610 mout->extra_out_nid[i], 2748 mout->extra_out_nid[i]);
2611 0, 0, 0);
2612 mutex_lock(&codec->spdif_mutex); 2749 mutex_lock(&codec->spdif_mutex);
2613 if (mout->dig_out_nid && mout->dig_out_used == HDA_DIG_ANALOG_DUP) { 2750 if (mout->dig_out_nid && mout->dig_out_used == HDA_DIG_ANALOG_DUP) {
2614 snd_hda_codec_setup_stream(codec, mout->dig_out_nid, 0, 0, 0); 2751 snd_hda_codec_cleanup_stream(codec, mout->dig_out_nid);
2615 mout->dig_out_used = 0; 2752 mout->dig_out_used = 0;
2616 } 2753 }
2617 mutex_unlock(&codec->spdif_mutex); 2754 mutex_unlock(&codec->spdif_mutex);
@@ -2790,6 +2927,30 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
2790 } 2927 }
2791 } 2928 }
2792 2929
2930 /* FIX-UP:
2931 * If no line-out is defined but multiple HPs are found,
2932 * some of them might be the real line-outs.
2933 */
2934 if (!cfg->line_outs && cfg->hp_outs > 1) {
2935 int i = 0;
2936 while (i < cfg->hp_outs) {
2937 /* The real HPs should have the sequence 0x0f */
2938 if ((sequences_hp[i] & 0x0f) == 0x0f) {
2939 i++;
2940 continue;
2941 }
2942 /* Move it to the line-out table */
2943 cfg->line_out_pins[cfg->line_outs] = cfg->hp_pins[i];
2944 sequences_line_out[cfg->line_outs] = sequences_hp[i];
2945 cfg->line_outs++;
2946 cfg->hp_outs--;
2947 memmove(cfg->hp_pins + i, cfg->hp_pins + i + 1,
2948 sizeof(cfg->hp_pins[0]) * (cfg->hp_outs - i));
2949 memmove(sequences_hp + i - 1, sequences_hp + i,
2950 sizeof(sequences_hp[0]) * (cfg->hp_outs - i));
2951 }
2952 }
2953
2793 /* sort by sequence */ 2954 /* sort by sequence */
2794 sort_pins_by_sequence(cfg->line_out_pins, sequences_line_out, 2955 sort_pins_by_sequence(cfg->line_out_pins, sequences_line_out,
2795 cfg->line_outs); 2956 cfg->line_outs);
diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
index f14871151be9..dcd390b2bbaa 100644
--- a/sound/pci/hda/hda_codec.h
+++ b/sound/pci/hda/hda_codec.h
@@ -590,11 +590,21 @@ struct hda_pcm_stream {
590 struct hda_pcm_ops ops; 590 struct hda_pcm_ops ops;
591}; 591};
592 592
593/* PCM types */
594enum {
595 HDA_PCM_TYPE_AUDIO,
596 HDA_PCM_TYPE_SPDIF,
597 HDA_PCM_TYPE_HDMI,
598 HDA_PCM_TYPE_MODEM,
599 HDA_PCM_NTYPES
600};
601
593/* for PCM creation */ 602/* for PCM creation */
594struct hda_pcm { 603struct hda_pcm {
595 char *name; 604 char *name;
596 struct hda_pcm_stream stream[2]; 605 struct hda_pcm_stream stream[2];
597 unsigned int is_modem; /* modem codec? */ 606 unsigned int pcm_type; /* HDA_PCM_TYPE_XXX */
607 int device; /* assigned device number */
598}; 608};
599 609
600/* codec information */ 610/* codec information */
@@ -712,6 +722,7 @@ int snd_hda_build_pcms(struct hda_bus *bus);
712void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid, 722void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
713 u32 stream_tag, 723 u32 stream_tag,
714 int channel_id, int format); 724 int channel_id, int format);
725void snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid);
715unsigned int snd_hda_calc_stream_format(unsigned int rate, 726unsigned int snd_hda_calc_stream_format(unsigned int rate,
716 unsigned int channels, 727 unsigned int channels,
717 unsigned int format, 728 unsigned int format,
diff --git a/sound/pci/hda/hda_generic.c b/sound/pci/hda/hda_generic.c
index f9de7c467c25..59e4389c94a4 100644
--- a/sound/pci/hda/hda_generic.c
+++ b/sound/pci/hda/hda_generic.c
@@ -1007,8 +1007,8 @@ static int generic_pcm2_cleanup(struct hda_pcm_stream *hinfo,
1007{ 1007{
1008 struct hda_gspec *spec = codec->spec; 1008 struct hda_gspec *spec = codec->spec;
1009 1009
1010 snd_hda_codec_setup_stream(codec, hinfo->nid, 0, 0, 0); 1010 snd_hda_codec_cleanup_stream(codec, hinfo->nid);
1011 snd_hda_codec_setup_stream(codec, spec->dac_node[1]->nid, 0, 0, 0); 1011 snd_hda_codec_cleanup_stream(codec, spec->dac_node[1]->nid);
1012 return 0; 1012 return 0;
1013} 1013}
1014 1014
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index 4be36c84b36c..b3a618eb42cd 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -39,6 +39,7 @@
39#include <linux/interrupt.h> 39#include <linux/interrupt.h>
40#include <linux/kernel.h> 40#include <linux/kernel.h>
41#include <linux/module.h> 41#include <linux/module.h>
42#include <linux/dma-mapping.h>
42#include <linux/moduleparam.h> 43#include <linux/moduleparam.h>
43#include <linux/init.h> 44#include <linux/init.h>
44#include <linux/slab.h> 45#include <linux/slab.h>
@@ -185,35 +186,28 @@ enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
185 186
186/* max number of SDs */ 187/* max number of SDs */
187/* ICH, ATI and VIA have 4 playback and 4 capture */ 188/* ICH, ATI and VIA have 4 playback and 4 capture */
188#define ICH6_CAPTURE_INDEX 0
189#define ICH6_NUM_CAPTURE 4 189#define ICH6_NUM_CAPTURE 4
190#define ICH6_PLAYBACK_INDEX 4
191#define ICH6_NUM_PLAYBACK 4 190#define ICH6_NUM_PLAYBACK 4
192 191
193/* ULI has 6 playback and 5 capture */ 192/* ULI has 6 playback and 5 capture */
194#define ULI_CAPTURE_INDEX 0
195#define ULI_NUM_CAPTURE 5 193#define ULI_NUM_CAPTURE 5
196#define ULI_PLAYBACK_INDEX 5
197#define ULI_NUM_PLAYBACK 6 194#define ULI_NUM_PLAYBACK 6
198 195
199/* ATI HDMI has 1 playback and 0 capture */ 196/* ATI HDMI has 1 playback and 0 capture */
200#define ATIHDMI_CAPTURE_INDEX 0
201#define ATIHDMI_NUM_CAPTURE 0 197#define ATIHDMI_NUM_CAPTURE 0
202#define ATIHDMI_PLAYBACK_INDEX 0
203#define ATIHDMI_NUM_PLAYBACK 1 198#define ATIHDMI_NUM_PLAYBACK 1
204 199
205/* this number is statically defined for simplicity */ 200/* this number is statically defined for simplicity */
206#define MAX_AZX_DEV 16 201#define MAX_AZX_DEV 16
207 202
208/* max number of fragments - we may use more if allocating more pages for BDL */ 203/* max number of fragments - we may use more if allocating more pages for BDL */
209#define BDL_SIZE PAGE_ALIGN(8192) 204#define BDL_SIZE 4096
210#define AZX_MAX_FRAG (BDL_SIZE / (MAX_AZX_DEV * 16)) 205#define AZX_MAX_BDL_ENTRIES (BDL_SIZE / 16)
206#define AZX_MAX_FRAG 32
211/* max buffer size - no h/w limit, you can increase as you like */ 207/* max buffer size - no h/w limit, you can increase as you like */
212#define AZX_MAX_BUF_SIZE (1024*1024*1024) 208#define AZX_MAX_BUF_SIZE (1024*1024*1024)
213/* max number of PCM devics per card */ 209/* max number of PCM devics per card */
214#define AZX_MAX_AUDIO_PCMS 6 210#define AZX_MAX_PCMS 8
215#define AZX_MAX_MODEM_PCMS 2
216#define AZX_MAX_PCMS (AZX_MAX_AUDIO_PCMS + AZX_MAX_MODEM_PCMS)
217 211
218/* RIRB int mask: overrun[2], response[0] */ 212/* RIRB int mask: overrun[2], response[0] */
219#define RIRB_INT_RESPONSE 0x01 213#define RIRB_INT_RESPONSE 0x01
@@ -227,6 +221,9 @@ enum { SDI0, SDI1, SDI2, SDI3, SDO0, SDO1, SDO2, SDO3 };
227/* SD_CTL bits */ 221/* SD_CTL bits */
228#define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */ 222#define SD_CTL_STREAM_RESET 0x01 /* stream reset bit */
229#define SD_CTL_DMA_START 0x02 /* stream DMA start bit */ 223#define SD_CTL_DMA_START 0x02 /* stream DMA start bit */
224#define SD_CTL_STRIPE (3 << 16) /* stripe control */
225#define SD_CTL_TRAFFIC_PRIO (1 << 18) /* traffic priority */
226#define SD_CTL_DIR (1 << 19) /* bi-directional stream */
230#define SD_CTL_STREAM_TAG_MASK (0xf << 20) 227#define SD_CTL_STREAM_TAG_MASK (0xf << 20)
231#define SD_CTL_STREAM_TAG_SHIFT 20 228#define SD_CTL_STREAM_TAG_SHIFT 20
232 229
@@ -284,12 +281,10 @@ enum {
284 */ 281 */
285 282
286struct azx_dev { 283struct azx_dev {
287 u32 *bdl; /* virtual address of the BDL */ 284 struct snd_dma_buffer bdl; /* BDL buffer */
288 dma_addr_t bdl_addr; /* physical address of the BDL */
289 u32 *posbuf; /* position buffer pointer */ 285 u32 *posbuf; /* position buffer pointer */
290 286
291 unsigned int bufsize; /* size of the play buffer in bytes */ 287 unsigned int bufsize; /* size of the play buffer in bytes */
292 unsigned int fragsize; /* size of each period in bytes */
293 unsigned int frags; /* number for period in the play buffer */ 288 unsigned int frags; /* number for period in the play buffer */
294 unsigned int fifo_size; /* FIFO size */ 289 unsigned int fifo_size; /* FIFO size */
295 290
@@ -350,7 +345,6 @@ struct azx {
350 struct azx_dev *azx_dev; 345 struct azx_dev *azx_dev;
351 346
352 /* PCM */ 347 /* PCM */
353 unsigned int pcm_devs;
354 struct snd_pcm *pcm[AZX_MAX_PCMS]; 348 struct snd_pcm *pcm[AZX_MAX_PCMS];
355 349
356 /* HD codec */ 350 /* HD codec */
@@ -361,8 +355,7 @@ struct azx {
361 struct azx_rb corb; 355 struct azx_rb corb;
362 struct azx_rb rirb; 356 struct azx_rb rirb;
363 357
364 /* BDL, CORB/RIRB and position buffers */ 358 /* CORB/RIRB and position buffers */
365 struct snd_dma_buffer bdl;
366 struct snd_dma_buffer rb; 359 struct snd_dma_buffer rb;
367 struct snd_dma_buffer posbuf; 360 struct snd_dma_buffer posbuf;
368 361
@@ -546,8 +539,9 @@ static void azx_update_rirb(struct azx *chip)
546 if (res_ex & ICH6_RIRB_EX_UNSOL_EV) 539 if (res_ex & ICH6_RIRB_EX_UNSOL_EV)
547 snd_hda_queue_unsol_event(chip->bus, res, res_ex); 540 snd_hda_queue_unsol_event(chip->bus, res, res_ex);
548 else if (chip->rirb.cmds) { 541 else if (chip->rirb.cmds) {
549 chip->rirb.cmds--;
550 chip->rirb.res = res; 542 chip->rirb.res = res;
543 smp_wmb();
544 chip->rirb.cmds--;
551 } 545 }
552 } 546 }
553} 547}
@@ -566,8 +560,10 @@ static unsigned int azx_rirb_get_response(struct hda_codec *codec)
566 azx_update_rirb(chip); 560 azx_update_rirb(chip);
567 spin_unlock_irq(&chip->reg_lock); 561 spin_unlock_irq(&chip->reg_lock);
568 } 562 }
569 if (!chip->rirb.cmds) 563 if (!chip->rirb.cmds) {
564 smp_rmb();
570 return chip->rirb.res; /* the last value */ 565 return chip->rirb.res; /* the last value */
566 }
571 if (time_after(jiffies, timeout)) 567 if (time_after(jiffies, timeout))
572 break; 568 break;
573 if (codec->bus->needs_damn_long_delay) 569 if (codec->bus->needs_damn_long_delay)
@@ -965,30 +961,57 @@ static irqreturn_t azx_interrupt(int irq, void *dev_id)
965/* 961/*
966 * set up BDL entries 962 * set up BDL entries
967 */ 963 */
968static void azx_setup_periods(struct azx_dev *azx_dev) 964static int azx_setup_periods(struct snd_pcm_substream *substream,
965 struct azx_dev *azx_dev)
969{ 966{
970 u32 *bdl = azx_dev->bdl; 967 struct snd_sg_buf *sgbuf = snd_pcm_substream_sgbuf(substream);
971 dma_addr_t dma_addr = azx_dev->substream->runtime->dma_addr; 968 u32 *bdl;
972 int idx; 969 int i, ofs, periods, period_bytes;
973 970
974 /* reset BDL address */ 971 /* reset BDL address */
975 azx_sd_writel(azx_dev, SD_BDLPL, 0); 972 azx_sd_writel(azx_dev, SD_BDLPL, 0);
976 azx_sd_writel(azx_dev, SD_BDLPU, 0); 973 azx_sd_writel(azx_dev, SD_BDLPU, 0);
977 974
975 period_bytes = snd_pcm_lib_period_bytes(substream);
976 periods = azx_dev->bufsize / period_bytes;
977
978 /* program the initial BDL entries */ 978 /* program the initial BDL entries */
979 for (idx = 0; idx < azx_dev->frags; idx++) { 979 bdl = (u32 *)azx_dev->bdl.area;
980 unsigned int off = idx << 2; /* 4 dword step */ 980 ofs = 0;
981 dma_addr_t addr = dma_addr + idx * azx_dev->fragsize; 981 azx_dev->frags = 0;
982 /* program the address field of the BDL entry */ 982 for (i = 0; i < periods; i++) {
983 bdl[off] = cpu_to_le32((u32)addr); 983 int size, rest;
984 bdl[off+1] = cpu_to_le32(upper_32bit(addr)); 984 if (i >= AZX_MAX_BDL_ENTRIES) {
985 985 snd_printk(KERN_ERR "Too many BDL entries: "
986 /* program the size field of the BDL entry */ 986 "buffer=%d, period=%d\n",
987 bdl[off+2] = cpu_to_le32(azx_dev->fragsize); 987 azx_dev->bufsize, period_bytes);
988 988 /* reset */
989 /* program the IOC to enable interrupt when buffer completes */ 989 azx_sd_writel(azx_dev, SD_BDLPL, 0);
990 bdl[off+3] = cpu_to_le32(0x01); 990 azx_sd_writel(azx_dev, SD_BDLPU, 0);
991 return -EINVAL;
992 }
993 rest = period_bytes;
994 do {
995 dma_addr_t addr = snd_pcm_sgbuf_get_addr(sgbuf, ofs);
996 /* program the address field of the BDL entry */
997 bdl[0] = cpu_to_le32((u32)addr);
998 bdl[1] = cpu_to_le32(upper_32bit(addr));
999 /* program the size field of the BDL entry */
1000 size = PAGE_SIZE - (ofs % PAGE_SIZE);
1001 if (rest < size)
1002 size = rest;
1003 bdl[2] = cpu_to_le32(size);
1004 /* program the IOC to enable interrupt
1005 * only when the whole fragment is processed
1006 */
1007 rest -= size;
1008 bdl[3] = rest ? 0 : cpu_to_le32(0x01);
1009 bdl += 4;
1010 azx_dev->frags++;
1011 ofs += size;
1012 } while (rest > 0);
991 } 1013 }
1014 return 0;
992} 1015}
993 1016
994/* 1017/*
@@ -1037,14 +1060,17 @@ static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
1037 1060
1038 /* program the BDL address */ 1061 /* program the BDL address */
1039 /* lower BDL address */ 1062 /* lower BDL address */
1040 azx_sd_writel(azx_dev, SD_BDLPL, (u32)azx_dev->bdl_addr); 1063 azx_sd_writel(azx_dev, SD_BDLPL, (u32)azx_dev->bdl.addr);
1041 /* upper BDL address */ 1064 /* upper BDL address */
1042 azx_sd_writel(azx_dev, SD_BDLPU, upper_32bit(azx_dev->bdl_addr)); 1065 azx_sd_writel(azx_dev, SD_BDLPU, upper_32bit(azx_dev->bdl.addr));
1043 1066
1044 /* enable the position buffer */ 1067 /* enable the position buffer */
1045 if (!(azx_readl(chip, DPLBASE) & ICH6_DPLBASE_ENABLE)) 1068 if (chip->position_fix == POS_FIX_POSBUF ||
1046 azx_writel(chip, DPLBASE, 1069 chip->position_fix == POS_FIX_AUTO) {
1047 (u32)chip->posbuf.addr |ICH6_DPLBASE_ENABLE); 1070 if (!(azx_readl(chip, DPLBASE) & ICH6_DPLBASE_ENABLE))
1071 azx_writel(chip, DPLBASE,
1072 (u32)chip->posbuf.addr | ICH6_DPLBASE_ENABLE);
1073 }
1048 1074
1049 /* set the interrupt enable bits in the descriptor control register */ 1075 /* set the interrupt enable bits in the descriptor control register */
1050 azx_sd_writel(azx_dev, SD_CTL, 1076 azx_sd_writel(azx_dev, SD_CTL,
@@ -1157,7 +1183,8 @@ static struct snd_pcm_hardware azx_pcm_hw = {
1157 SNDRV_PCM_INFO_MMAP_VALID | 1183 SNDRV_PCM_INFO_MMAP_VALID |
1158 /* No full-resume yet implemented */ 1184 /* No full-resume yet implemented */
1159 /* SNDRV_PCM_INFO_RESUME |*/ 1185 /* SNDRV_PCM_INFO_RESUME |*/
1160 SNDRV_PCM_INFO_PAUSE), 1186 SNDRV_PCM_INFO_PAUSE |
1187 SNDRV_PCM_INFO_SYNC_START),
1161 .formats = SNDRV_PCM_FMTBIT_S16_LE, 1188 .formats = SNDRV_PCM_FMTBIT_S16_LE,
1162 .rates = SNDRV_PCM_RATE_48000, 1189 .rates = SNDRV_PCM_RATE_48000,
1163 .rate_min = 48000, 1190 .rate_min = 48000,
@@ -1219,6 +1246,7 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
1219 spin_unlock_irqrestore(&chip->reg_lock, flags); 1246 spin_unlock_irqrestore(&chip->reg_lock, flags);
1220 1247
1221 runtime->private_data = azx_dev; 1248 runtime->private_data = azx_dev;
1249 snd_pcm_set_sync(substream);
1222 mutex_unlock(&chip->open_mutex); 1250 mutex_unlock(&chip->open_mutex);
1223 return 0; 1251 return 0;
1224} 1252}
@@ -1275,8 +1303,6 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
1275 struct snd_pcm_runtime *runtime = substream->runtime; 1303 struct snd_pcm_runtime *runtime = substream->runtime;
1276 1304
1277 azx_dev->bufsize = snd_pcm_lib_buffer_bytes(substream); 1305 azx_dev->bufsize = snd_pcm_lib_buffer_bytes(substream);
1278 azx_dev->fragsize = snd_pcm_lib_period_bytes(substream);
1279 azx_dev->frags = azx_dev->bufsize / azx_dev->fragsize;
1280 azx_dev->format_val = snd_hda_calc_stream_format(runtime->rate, 1306 azx_dev->format_val = snd_hda_calc_stream_format(runtime->rate,
1281 runtime->channels, 1307 runtime->channels,
1282 runtime->format, 1308 runtime->format,
@@ -1288,10 +1314,10 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
1288 return -EINVAL; 1314 return -EINVAL;
1289 } 1315 }
1290 1316
1291 snd_printdd("azx_pcm_prepare: bufsize=0x%x, fragsize=0x%x, " 1317 snd_printdd("azx_pcm_prepare: bufsize=0x%x, format=0x%x\n",
1292 "format=0x%x\n", 1318 azx_dev->bufsize, azx_dev->format_val);
1293 azx_dev->bufsize, azx_dev->fragsize, azx_dev->format_val); 1319 if (azx_setup_periods(substream, azx_dev) < 0)
1294 azx_setup_periods(azx_dev); 1320 return -EINVAL;
1295 azx_setup_controller(chip, azx_dev); 1321 azx_setup_controller(chip, azx_dev);
1296 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 1322 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
1297 azx_dev->fifo_size = azx_sd_readw(azx_dev, SD_FIFOSIZE) + 1; 1323 azx_dev->fifo_size = azx_sd_readw(azx_dev, SD_FIFOSIZE) + 1;
@@ -1305,37 +1331,94 @@ static int azx_pcm_prepare(struct snd_pcm_substream *substream)
1305static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd) 1331static int azx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
1306{ 1332{
1307 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 1333 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
1308 struct azx_dev *azx_dev = get_azx_dev(substream);
1309 struct azx *chip = apcm->chip; 1334 struct azx *chip = apcm->chip;
1310 int err = 0; 1335 struct azx_dev *azx_dev;
1336 struct snd_pcm_substream *s;
1337 int start, nsync = 0, sbits = 0;
1338 int nwait, timeout;
1311 1339
1312 spin_lock(&chip->reg_lock);
1313 switch (cmd) { 1340 switch (cmd) {
1314 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 1341 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
1315 case SNDRV_PCM_TRIGGER_RESUME: 1342 case SNDRV_PCM_TRIGGER_RESUME:
1316 case SNDRV_PCM_TRIGGER_START: 1343 case SNDRV_PCM_TRIGGER_START:
1317 azx_stream_start(chip, azx_dev); 1344 start = 1;
1318 azx_dev->running = 1;
1319 break; 1345 break;
1320 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 1346 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
1321 case SNDRV_PCM_TRIGGER_SUSPEND: 1347 case SNDRV_PCM_TRIGGER_SUSPEND:
1322 case SNDRV_PCM_TRIGGER_STOP: 1348 case SNDRV_PCM_TRIGGER_STOP:
1323 azx_stream_stop(chip, azx_dev); 1349 start = 0;
1324 azx_dev->running = 0;
1325 break; 1350 break;
1326 default: 1351 default:
1327 err = -EINVAL; 1352 return -EINVAL;
1353 }
1354
1355 snd_pcm_group_for_each_entry(s, substream) {
1356 if (s->pcm->card != substream->pcm->card)
1357 continue;
1358 azx_dev = get_azx_dev(s);
1359 sbits |= 1 << azx_dev->index;
1360 nsync++;
1361 snd_pcm_trigger_done(s, substream);
1362 }
1363
1364 spin_lock(&chip->reg_lock);
1365 if (nsync > 1) {
1366 /* first, set SYNC bits of corresponding streams */
1367 azx_writel(chip, SYNC, azx_readl(chip, SYNC) | sbits);
1368 }
1369 snd_pcm_group_for_each_entry(s, substream) {
1370 if (s->pcm->card != substream->pcm->card)
1371 continue;
1372 azx_dev = get_azx_dev(s);
1373 if (start)
1374 azx_stream_start(chip, azx_dev);
1375 else
1376 azx_stream_stop(chip, azx_dev);
1377 azx_dev->running = start;
1328 } 1378 }
1329 spin_unlock(&chip->reg_lock); 1379 spin_unlock(&chip->reg_lock);
1330 if (cmd == SNDRV_PCM_TRIGGER_PAUSE_PUSH || 1380 if (start) {
1331 cmd == SNDRV_PCM_TRIGGER_SUSPEND || 1381 if (nsync == 1)
1332 cmd == SNDRV_PCM_TRIGGER_STOP) { 1382 return 0;
1333 int timeout = 5000; 1383 /* wait until all FIFOs get ready */
1334 while ((azx_sd_readb(azx_dev, SD_CTL) & SD_CTL_DMA_START) && 1384 for (timeout = 5000; timeout; timeout--) {
1335 --timeout) 1385 nwait = 0;
1336 ; 1386 snd_pcm_group_for_each_entry(s, substream) {
1387 if (s->pcm->card != substream->pcm->card)
1388 continue;
1389 azx_dev = get_azx_dev(s);
1390 if (!(azx_sd_readb(azx_dev, SD_STS) &
1391 SD_STS_FIFO_READY))
1392 nwait++;
1393 }
1394 if (!nwait)
1395 break;
1396 cpu_relax();
1397 }
1398 } else {
1399 /* wait until all RUN bits are cleared */
1400 for (timeout = 5000; timeout; timeout--) {
1401 nwait = 0;
1402 snd_pcm_group_for_each_entry(s, substream) {
1403 if (s->pcm->card != substream->pcm->card)
1404 continue;
1405 azx_dev = get_azx_dev(s);
1406 if (azx_sd_readb(azx_dev, SD_CTL) &
1407 SD_CTL_DMA_START)
1408 nwait++;
1409 }
1410 if (!nwait)
1411 break;
1412 cpu_relax();
1413 }
1337 } 1414 }
1338 return err; 1415 if (nsync > 1) {
1416 spin_lock(&chip->reg_lock);
1417 /* reset SYNC bits */
1418 azx_writel(chip, SYNC, azx_readl(chip, SYNC) & ~sbits);
1419 spin_unlock(&chip->reg_lock);
1420 }
1421 return 0;
1339} 1422}
1340 1423
1341static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream) 1424static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream)
@@ -1378,6 +1461,7 @@ static struct snd_pcm_ops azx_pcm_ops = {
1378 .prepare = azx_pcm_prepare, 1461 .prepare = azx_pcm_prepare,
1379 .trigger = azx_pcm_trigger, 1462 .trigger = azx_pcm_trigger,
1380 .pointer = azx_pcm_pointer, 1463 .pointer = azx_pcm_pointer,
1464 .page = snd_pcm_sgbuf_ops_page,
1381}; 1465};
1382 1466
1383static void azx_pcm_free(struct snd_pcm *pcm) 1467static void azx_pcm_free(struct snd_pcm *pcm)
@@ -1386,7 +1470,7 @@ static void azx_pcm_free(struct snd_pcm *pcm)
1386} 1470}
1387 1471
1388static int __devinit create_codec_pcm(struct azx *chip, struct hda_codec *codec, 1472static int __devinit create_codec_pcm(struct azx *chip, struct hda_codec *codec,
1389 struct hda_pcm *cpcm, int pcm_dev) 1473 struct hda_pcm *cpcm)
1390{ 1474{
1391 int err; 1475 int err;
1392 struct snd_pcm *pcm; 1476 struct snd_pcm *pcm;
@@ -1400,7 +1484,7 @@ static int __devinit create_codec_pcm(struct azx *chip, struct hda_codec *codec,
1400 1484
1401 snd_assert(cpcm->name, return -EINVAL); 1485 snd_assert(cpcm->name, return -EINVAL);
1402 1486
1403 err = snd_pcm_new(chip->card, cpcm->name, pcm_dev, 1487 err = snd_pcm_new(chip->card, cpcm->name, cpcm->device,
1404 cpcm->stream[0].substreams, 1488 cpcm->stream[0].substreams,
1405 cpcm->stream[1].substreams, 1489 cpcm->stream[1].substreams,
1406 &pcm); 1490 &pcm);
@@ -1420,62 +1504,70 @@ static int __devinit create_codec_pcm(struct azx *chip, struct hda_codec *codec,
1420 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &azx_pcm_ops); 1504 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &azx_pcm_ops);
1421 if (cpcm->stream[1].substreams) 1505 if (cpcm->stream[1].substreams)
1422 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &azx_pcm_ops); 1506 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &azx_pcm_ops);
1423 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, 1507 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG,
1424 snd_dma_pci_data(chip->pci), 1508 snd_dma_pci_data(chip->pci),
1425 1024 * 64, 1024 * 1024); 1509 1024 * 64, 1024 * 1024);
1426 chip->pcm[pcm_dev] = pcm; 1510 chip->pcm[cpcm->device] = pcm;
1427 if (chip->pcm_devs < pcm_dev + 1)
1428 chip->pcm_devs = pcm_dev + 1;
1429
1430 return 0; 1511 return 0;
1431} 1512}
1432 1513
1433static int __devinit azx_pcm_create(struct azx *chip) 1514static int __devinit azx_pcm_create(struct azx *chip)
1434{ 1515{
1516 static const char *dev_name[HDA_PCM_NTYPES] = {
1517 "Audio", "SPDIF", "HDMI", "Modem"
1518 };
1519 /* starting device index for each PCM type */
1520 static int dev_idx[HDA_PCM_NTYPES] = {
1521 [HDA_PCM_TYPE_AUDIO] = 0,
1522 [HDA_PCM_TYPE_SPDIF] = 1,
1523 [HDA_PCM_TYPE_HDMI] = 3,
1524 [HDA_PCM_TYPE_MODEM] = 6
1525 };
1526 /* normal audio device indices; not linear to keep compatibility */
1527 static int audio_idx[4] = { 0, 2, 4, 5 };
1435 struct hda_codec *codec; 1528 struct hda_codec *codec;
1436 int c, err; 1529 int c, err;
1437 int pcm_dev; 1530 int num_devs[HDA_PCM_NTYPES];
1438 1531
1439 err = snd_hda_build_pcms(chip->bus); 1532 err = snd_hda_build_pcms(chip->bus);
1440 if (err < 0) 1533 if (err < 0)
1441 return err; 1534 return err;
1442 1535
1443 /* create audio PCMs */ 1536 /* create audio PCMs */
1444 pcm_dev = 0; 1537 memset(num_devs, 0, sizeof(num_devs));
1445 list_for_each_entry(codec, &chip->bus->codec_list, list) {
1446 for (c = 0; c < codec->num_pcms; c++) {
1447 if (codec->pcm_info[c].is_modem)
1448 continue; /* create later */
1449 if (pcm_dev >= AZX_MAX_AUDIO_PCMS) {
1450 snd_printk(KERN_ERR SFX
1451 "Too many audio PCMs\n");
1452 return -EINVAL;
1453 }
1454 err = create_codec_pcm(chip, codec,
1455 &codec->pcm_info[c], pcm_dev);
1456 if (err < 0)
1457 return err;
1458 pcm_dev++;
1459 }
1460 }
1461
1462 /* create modem PCMs */
1463 pcm_dev = AZX_MAX_AUDIO_PCMS;
1464 list_for_each_entry(codec, &chip->bus->codec_list, list) { 1538 list_for_each_entry(codec, &chip->bus->codec_list, list) {
1465 for (c = 0; c < codec->num_pcms; c++) { 1539 for (c = 0; c < codec->num_pcms; c++) {
1466 if (!codec->pcm_info[c].is_modem) 1540 struct hda_pcm *cpcm = &codec->pcm_info[c];
1467 continue; /* already created */ 1541 int type = cpcm->pcm_type;
1468 if (pcm_dev >= AZX_MAX_PCMS) { 1542 switch (type) {
1469 snd_printk(KERN_ERR SFX 1543 case HDA_PCM_TYPE_AUDIO:
1470 "Too many modem PCMs\n"); 1544 if (num_devs[type] >= ARRAY_SIZE(audio_idx)) {
1471 return -EINVAL; 1545 snd_printk(KERN_WARNING
1546 "Too many audio devices\n");
1547 continue;
1548 }
1549 cpcm->device = audio_idx[num_devs[type]];
1550 break;
1551 case HDA_PCM_TYPE_SPDIF:
1552 case HDA_PCM_TYPE_HDMI:
1553 case HDA_PCM_TYPE_MODEM:
1554 if (num_devs[type]) {
1555 snd_printk(KERN_WARNING
1556 "%s already defined\n",
1557 dev_name[type]);
1558 continue;
1559 }
1560 cpcm->device = dev_idx[type];
1561 break;
1562 default:
1563 snd_printk(KERN_WARNING
1564 "Invalid PCM type %d\n", type);
1565 continue;
1472 } 1566 }
1473 err = create_codec_pcm(chip, codec, 1567 num_devs[type]++;
1474 &codec->pcm_info[c], pcm_dev); 1568 err = create_codec_pcm(chip, codec, cpcm);
1475 if (err < 0) 1569 if (err < 0)
1476 return err; 1570 return err;
1477 chip->pcm[pcm_dev]->dev_class = SNDRV_PCM_CLASS_MODEM;
1478 pcm_dev++;
1479 } 1571 }
1480 } 1572 }
1481 return 0; 1573 return 0;
@@ -1502,10 +1594,7 @@ static int __devinit azx_init_stream(struct azx *chip)
1502 * and initialize 1594 * and initialize
1503 */ 1595 */
1504 for (i = 0; i < chip->num_streams; i++) { 1596 for (i = 0; i < chip->num_streams; i++) {
1505 unsigned int off = sizeof(u32) * (i * AZX_MAX_FRAG * 4);
1506 struct azx_dev *azx_dev = &chip->azx_dev[i]; 1597 struct azx_dev *azx_dev = &chip->azx_dev[i];
1507 azx_dev->bdl = (u32 *)(chip->bdl.area + off);
1508 azx_dev->bdl_addr = chip->bdl.addr + off;
1509 azx_dev->posbuf = (u32 __iomem *)(chip->posbuf.area + i * 8); 1598 azx_dev->posbuf = (u32 __iomem *)(chip->posbuf.area + i * 8);
1510 /* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */ 1599 /* offset: SDI0=0x80, SDI1=0xa0, ... SDO3=0x160 */
1511 azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80); 1600 azx_dev->sd_addr = chip->remap_addr + (0x20 * i + 0x80);
@@ -1587,13 +1676,12 @@ static int azx_suspend(struct pci_dev *pci, pm_message_t state)
1587 int i; 1676 int i;
1588 1677
1589 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot); 1678 snd_power_change_state(card, SNDRV_CTL_POWER_D3hot);
1590 for (i = 0; i < chip->pcm_devs; i++) 1679 for (i = 0; i < AZX_MAX_PCMS; i++)
1591 snd_pcm_suspend_all(chip->pcm[i]); 1680 snd_pcm_suspend_all(chip->pcm[i]);
1592 if (chip->initialized) 1681 if (chip->initialized)
1593 snd_hda_suspend(chip->bus, state); 1682 snd_hda_suspend(chip->bus, state);
1594 azx_stop_chip(chip); 1683 azx_stop_chip(chip);
1595 if (chip->irq >= 0) { 1684 if (chip->irq >= 0) {
1596 synchronize_irq(chip->irq);
1597 free_irq(chip->irq, chip); 1685 free_irq(chip->irq, chip);
1598 chip->irq = -1; 1686 chip->irq = -1;
1599 } 1687 }
@@ -1641,24 +1729,26 @@ static int azx_resume(struct pci_dev *pci)
1641 */ 1729 */
1642static int azx_free(struct azx *chip) 1730static int azx_free(struct azx *chip)
1643{ 1731{
1732 int i;
1733
1644 if (chip->initialized) { 1734 if (chip->initialized) {
1645 int i;
1646 for (i = 0; i < chip->num_streams; i++) 1735 for (i = 0; i < chip->num_streams; i++)
1647 azx_stream_stop(chip, &chip->azx_dev[i]); 1736 azx_stream_stop(chip, &chip->azx_dev[i]);
1648 azx_stop_chip(chip); 1737 azx_stop_chip(chip);
1649 } 1738 }
1650 1739
1651 if (chip->irq >= 0) { 1740 if (chip->irq >= 0)
1652 synchronize_irq(chip->irq);
1653 free_irq(chip->irq, (void*)chip); 1741 free_irq(chip->irq, (void*)chip);
1654 }
1655 if (chip->msi) 1742 if (chip->msi)
1656 pci_disable_msi(chip->pci); 1743 pci_disable_msi(chip->pci);
1657 if (chip->remap_addr) 1744 if (chip->remap_addr)
1658 iounmap(chip->remap_addr); 1745 iounmap(chip->remap_addr);
1659 1746
1660 if (chip->bdl.area) 1747 if (chip->azx_dev) {
1661 snd_dma_free_pages(&chip->bdl); 1748 for (i = 0; i < chip->num_streams; i++)
1749 if (chip->azx_dev[i].bdl.area)
1750 snd_dma_free_pages(&chip->azx_dev[i].bdl);
1751 }
1662 if (chip->rb.area) 1752 if (chip->rb.area)
1663 snd_dma_free_pages(&chip->rb); 1753 snd_dma_free_pages(&chip->rb);
1664 if (chip->posbuf.area) 1754 if (chip->posbuf.area)
@@ -1682,6 +1772,7 @@ static int azx_dev_free(struct snd_device *device)
1682static struct snd_pci_quirk position_fix_list[] __devinitdata = { 1772static struct snd_pci_quirk position_fix_list[] __devinitdata = {
1683 SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_NONE), 1773 SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_NONE),
1684 SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_NONE), 1774 SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_NONE),
1775 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_NONE),
1685 {} 1776 {}
1686}; 1777};
1687 1778
@@ -1740,7 +1831,7 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
1740 struct azx **rchip) 1831 struct azx **rchip)
1741{ 1832{
1742 struct azx *chip; 1833 struct azx *chip;
1743 int err; 1834 int i, err;
1744 unsigned short gcap; 1835 unsigned short gcap;
1745 static struct snd_device_ops ops = { 1836 static struct snd_device_ops ops = {
1746 .dev_free = azx_dev_free, 1837 .dev_free = azx_dev_free,
@@ -1812,38 +1903,35 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
1812 gcap = azx_readw(chip, GCAP); 1903 gcap = azx_readw(chip, GCAP);
1813 snd_printdd("chipset global capabilities = 0x%x\n", gcap); 1904 snd_printdd("chipset global capabilities = 0x%x\n", gcap);
1814 1905
1815 if (gcap) { 1906 /* allow 64bit DMA address if supported by H/W */
1816 /* read number of streams from GCAP register instead of using 1907 if ((gcap & 0x01) && !pci_set_dma_mask(pci, DMA_64BIT_MASK))
1817 * hardcoded value 1908 pci_set_consistent_dma_mask(pci, DMA_64BIT_MASK);
1818 */ 1909
1819 chip->playback_streams = (gcap & (0xF << 12)) >> 12; 1910 /* read number of streams from GCAP register instead of using
1820 chip->capture_streams = (gcap & (0xF << 8)) >> 8; 1911 * hardcoded value
1821 chip->playback_index_offset = chip->capture_streams; 1912 */
1822 chip->capture_index_offset = 0; 1913 chip->capture_streams = (gcap >> 8) & 0x0f;
1823 } else { 1914 chip->playback_streams = (gcap >> 12) & 0x0f;
1915 if (!chip->playback_streams && !chip->capture_streams) {
1824 /* gcap didn't give any info, switching to old method */ 1916 /* gcap didn't give any info, switching to old method */
1825 1917
1826 switch (chip->driver_type) { 1918 switch (chip->driver_type) {
1827 case AZX_DRIVER_ULI: 1919 case AZX_DRIVER_ULI:
1828 chip->playback_streams = ULI_NUM_PLAYBACK; 1920 chip->playback_streams = ULI_NUM_PLAYBACK;
1829 chip->capture_streams = ULI_NUM_CAPTURE; 1921 chip->capture_streams = ULI_NUM_CAPTURE;
1830 chip->playback_index_offset = ULI_PLAYBACK_INDEX;
1831 chip->capture_index_offset = ULI_CAPTURE_INDEX;
1832 break; 1922 break;
1833 case AZX_DRIVER_ATIHDMI: 1923 case AZX_DRIVER_ATIHDMI:
1834 chip->playback_streams = ATIHDMI_NUM_PLAYBACK; 1924 chip->playback_streams = ATIHDMI_NUM_PLAYBACK;
1835 chip->capture_streams = ATIHDMI_NUM_CAPTURE; 1925 chip->capture_streams = ATIHDMI_NUM_CAPTURE;
1836 chip->playback_index_offset = ATIHDMI_PLAYBACK_INDEX;
1837 chip->capture_index_offset = ATIHDMI_CAPTURE_INDEX;
1838 break; 1926 break;
1839 default: 1927 default:
1840 chip->playback_streams = ICH6_NUM_PLAYBACK; 1928 chip->playback_streams = ICH6_NUM_PLAYBACK;
1841 chip->capture_streams = ICH6_NUM_CAPTURE; 1929 chip->capture_streams = ICH6_NUM_CAPTURE;
1842 chip->playback_index_offset = ICH6_PLAYBACK_INDEX;
1843 chip->capture_index_offset = ICH6_CAPTURE_INDEX;
1844 break; 1930 break;
1845 } 1931 }
1846 } 1932 }
1933 chip->capture_index_offset = 0;
1934 chip->playback_index_offset = chip->capture_streams;
1847 chip->num_streams = chip->playback_streams + chip->capture_streams; 1935 chip->num_streams = chip->playback_streams + chip->capture_streams;
1848 chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev), 1936 chip->azx_dev = kcalloc(chip->num_streams, sizeof(*chip->azx_dev),
1849 GFP_KERNEL); 1937 GFP_KERNEL);
@@ -1852,13 +1940,15 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
1852 goto errout; 1940 goto errout;
1853 } 1941 }
1854 1942
1855 /* allocate memory for the BDL for each stream */ 1943 for (i = 0; i < chip->num_streams; i++) {
1856 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, 1944 /* allocate memory for the BDL for each stream */
1857 snd_dma_pci_data(chip->pci), 1945 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
1858 BDL_SIZE, &chip->bdl); 1946 snd_dma_pci_data(chip->pci),
1859 if (err < 0) { 1947 BDL_SIZE, &chip->azx_dev[i].bdl);
1860 snd_printk(KERN_ERR SFX "cannot allocate BDL\n"); 1948 if (err < 0) {
1861 goto errout; 1949 snd_printk(KERN_ERR SFX "cannot allocate BDL\n");
1950 goto errout;
1951 }
1862 } 1952 }
1863 /* allocate memory for the position buffer */ 1953 /* allocate memory for the position buffer */
1864 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, 1954 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
@@ -1994,48 +2084,63 @@ static void __devexit azx_remove(struct pci_dev *pci)
1994 2084
1995/* PCI IDs */ 2085/* PCI IDs */
1996static struct pci_device_id azx_ids[] = { 2086static struct pci_device_id azx_ids[] = {
1997 { 0x8086, 0x2668, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ICH6 */ 2087 /* ICH 6..10 */
1998 { 0x8086, 0x27d8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ICH7 */ 2088 { PCI_DEVICE(0x8086, 0x2668), .driver_data = AZX_DRIVER_ICH },
1999 { 0x8086, 0x269a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ESB2 */ 2089 { PCI_DEVICE(0x8086, 0x27d8), .driver_data = AZX_DRIVER_ICH },
2000 { 0x8086, 0x284b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ICH8 */ 2090 { PCI_DEVICE(0x8086, 0x269a), .driver_data = AZX_DRIVER_ICH },
2001 { 0x8086, 0x293e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ICH9 */ 2091 { PCI_DEVICE(0x8086, 0x284b), .driver_data = AZX_DRIVER_ICH },
2002 { 0x8086, 0x293f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ICH9 */ 2092 { PCI_DEVICE(0x8086, 0x293e), .driver_data = AZX_DRIVER_ICH },
2003 { 0x8086, 0x3a3e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ICH10 */ 2093 { PCI_DEVICE(0x8086, 0x293f), .driver_data = AZX_DRIVER_ICH },
2004 { 0x8086, 0x3a6e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ICH }, /* ICH10 */ 2094 { PCI_DEVICE(0x8086, 0x3a3e), .driver_data = AZX_DRIVER_ICH },
2005 { 0x8086, 0x811b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_SCH }, /* SCH*/ 2095 { PCI_DEVICE(0x8086, 0x3a6e), .driver_data = AZX_DRIVER_ICH },
2006 { 0x1002, 0x437b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATI }, /* ATI SB450 */ 2096 /* SCH */
2007 { 0x1002, 0x4383, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATI }, /* ATI SB600 */ 2097 { PCI_DEVICE(0x8086, 0x811b), .driver_data = AZX_DRIVER_SCH },
2008 { 0x1002, 0x793b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RS600 HDMI */ 2098 /* ATI SB 450/600 */
2009 { 0x1002, 0x7919, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RS690 HDMI */ 2099 { PCI_DEVICE(0x1002, 0x437b), .driver_data = AZX_DRIVER_ATI },
2010 { 0x1002, 0x960f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RS780 HDMI */ 2100 { PCI_DEVICE(0x1002, 0x4383), .driver_data = AZX_DRIVER_ATI },
2011 { 0x1002, 0xaa00, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI R600 HDMI */ 2101 /* ATI HDMI */
2012 { 0x1002, 0xaa08, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RV630 HDMI */ 2102 { PCI_DEVICE(0x1002, 0x793b), .driver_data = AZX_DRIVER_ATIHDMI },
2013 { 0x1002, 0xaa10, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RV610 HDMI */ 2103 { PCI_DEVICE(0x1002, 0x7919), .driver_data = AZX_DRIVER_ATIHDMI },
2014 { 0x1002, 0xaa18, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RV670 HDMI */ 2104 { PCI_DEVICE(0x1002, 0x960f), .driver_data = AZX_DRIVER_ATIHDMI },
2015 { 0x1002, 0xaa20, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RV635 HDMI */ 2105 { PCI_DEVICE(0x1002, 0xaa00), .driver_data = AZX_DRIVER_ATIHDMI },
2016 { 0x1002, 0xaa28, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RV620 HDMI */ 2106 { PCI_DEVICE(0x1002, 0xaa08), .driver_data = AZX_DRIVER_ATIHDMI },
2017 { 0x1002, 0xaa30, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ATIHDMI }, /* ATI RV770 HDMI */ 2107 { PCI_DEVICE(0x1002, 0xaa10), .driver_data = AZX_DRIVER_ATIHDMI },
2018 { 0x1106, 0x3288, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_VIA }, /* VIA VT8251/VT8237A */ 2108 { PCI_DEVICE(0x1002, 0xaa18), .driver_data = AZX_DRIVER_ATIHDMI },
2019 { 0x1039, 0x7502, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_SIS }, /* SIS966 */ 2109 { PCI_DEVICE(0x1002, 0xaa20), .driver_data = AZX_DRIVER_ATIHDMI },
2020 { 0x10b9, 0x5461, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_ULI }, /* ULI M5461 */ 2110 { PCI_DEVICE(0x1002, 0xaa28), .driver_data = AZX_DRIVER_ATIHDMI },
2021 { 0x10de, 0x026c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP51 */ 2111 { PCI_DEVICE(0x1002, 0xaa30), .driver_data = AZX_DRIVER_ATIHDMI },
2022 { 0x10de, 0x0371, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP55 */ 2112 { PCI_DEVICE(0x1002, 0xaa38), .driver_data = AZX_DRIVER_ATIHDMI },
2023 { 0x10de, 0x03e4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP61 */ 2113 { PCI_DEVICE(0x1002, 0xaa40), .driver_data = AZX_DRIVER_ATIHDMI },
2024 { 0x10de, 0x03f0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP61 */ 2114 { PCI_DEVICE(0x1002, 0xaa48), .driver_data = AZX_DRIVER_ATIHDMI },
2025 { 0x10de, 0x044a, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP65 */ 2115 /* VIA VT8251/VT8237A */
2026 { 0x10de, 0x044b, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP65 */ 2116 { PCI_DEVICE(0x1106, 0x3288), .driver_data = AZX_DRIVER_VIA },
2027 { 0x10de, 0x055c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP67 */ 2117 /* SIS966 */
2028 { 0x10de, 0x055d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP67 */ 2118 { PCI_DEVICE(0x1039, 0x7502), .driver_data = AZX_DRIVER_SIS },
2029 { 0x10de, 0x07fc, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP73 */ 2119 /* ULI M5461 */
2030 { 0x10de, 0x07fd, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP73 */ 2120 { PCI_DEVICE(0x10b9, 0x5461), .driver_data = AZX_DRIVER_ULI },
2031 { 0x10de, 0x0774, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP77 */ 2121 /* NVIDIA MCP */
2032 { 0x10de, 0x0775, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP77 */ 2122 { PCI_DEVICE(0x10de, 0x026c), .driver_data = AZX_DRIVER_NVIDIA },
2033 { 0x10de, 0x0776, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP77 */ 2123 { PCI_DEVICE(0x10de, 0x0371), .driver_data = AZX_DRIVER_NVIDIA },
2034 { 0x10de, 0x0777, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP77 */ 2124 { PCI_DEVICE(0x10de, 0x03e4), .driver_data = AZX_DRIVER_NVIDIA },
2035 { 0x10de, 0x0ac0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP79 */ 2125 { PCI_DEVICE(0x10de, 0x03f0), .driver_data = AZX_DRIVER_NVIDIA },
2036 { 0x10de, 0x0ac1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP79 */ 2126 { PCI_DEVICE(0x10de, 0x044a), .driver_data = AZX_DRIVER_NVIDIA },
2037 { 0x10de, 0x0ac2, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP79 */ 2127 { PCI_DEVICE(0x10de, 0x044b), .driver_data = AZX_DRIVER_NVIDIA },
2038 { 0x10de, 0x0ac3, PCI_ANY_ID, PCI_ANY_ID, 0, 0, AZX_DRIVER_NVIDIA }, /* NVIDIA MCP79 */ 2128 { PCI_DEVICE(0x10de, 0x055c), .driver_data = AZX_DRIVER_NVIDIA },
2129 { PCI_DEVICE(0x10de, 0x055d), .driver_data = AZX_DRIVER_NVIDIA },
2130 { PCI_DEVICE(0x10de, 0x0774), .driver_data = AZX_DRIVER_NVIDIA },
2131 { PCI_DEVICE(0x10de, 0x0775), .driver_data = AZX_DRIVER_NVIDIA },
2132 { PCI_DEVICE(0x10de, 0x0776), .driver_data = AZX_DRIVER_NVIDIA },
2133 { PCI_DEVICE(0x10de, 0x0777), .driver_data = AZX_DRIVER_NVIDIA },
2134 { PCI_DEVICE(0x10de, 0x07fc), .driver_data = AZX_DRIVER_NVIDIA },
2135 { PCI_DEVICE(0x10de, 0x07fd), .driver_data = AZX_DRIVER_NVIDIA },
2136 { PCI_DEVICE(0x10de, 0x0ac0), .driver_data = AZX_DRIVER_NVIDIA },
2137 { PCI_DEVICE(0x10de, 0x0ac1), .driver_data = AZX_DRIVER_NVIDIA },
2138 { PCI_DEVICE(0x10de, 0x0ac2), .driver_data = AZX_DRIVER_NVIDIA },
2139 { PCI_DEVICE(0x10de, 0x0ac3), .driver_data = AZX_DRIVER_NVIDIA },
2140 { PCI_DEVICE(0x10de, 0x0bd4), .driver_data = AZX_DRIVER_NVIDIA },
2141 { PCI_DEVICE(0x10de, 0x0bd5), .driver_data = AZX_DRIVER_NVIDIA },
2142 { PCI_DEVICE(0x10de, 0x0bd6), .driver_data = AZX_DRIVER_NVIDIA },
2143 { PCI_DEVICE(0x10de, 0x0bd7), .driver_data = AZX_DRIVER_NVIDIA },
2039 { 0, } 2144 { 0, }
2040}; 2145};
2041MODULE_DEVICE_TABLE(pci, azx_ids); 2146MODULE_DEVICE_TABLE(pci, azx_ids);
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index ad0014ab71f9..5c9e578f7f2d 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -228,8 +228,18 @@ struct hda_multi_out {
228 int max_channels; /* currently supported analog channels */ 228 int max_channels; /* currently supported analog channels */
229 int dig_out_used; /* current usage of digital out (HDA_DIG_XXX) */ 229 int dig_out_used; /* current usage of digital out (HDA_DIG_XXX) */
230 int no_share_stream; /* don't share a stream with multiple pins */ 230 int no_share_stream; /* don't share a stream with multiple pins */
231 int share_spdif; /* share SPDIF pin */
232 /* PCM information for both analog and SPDIF DACs */
233 unsigned int analog_rates;
234 unsigned int analog_maxbps;
235 u64 analog_formats;
236 unsigned int spdif_rates;
237 unsigned int spdif_maxbps;
238 u64 spdif_formats;
231}; 239};
232 240
241int snd_hda_create_spdif_share_sw(struct hda_codec *codec,
242 struct hda_multi_out *mout);
233int snd_hda_multi_out_dig_open(struct hda_codec *codec, 243int snd_hda_multi_out_dig_open(struct hda_codec *codec,
234 struct hda_multi_out *mout); 244 struct hda_multi_out *mout);
235int snd_hda_multi_out_dig_close(struct hda_codec *codec, 245int snd_hda_multi_out_dig_close(struct hda_codec *codec,
@@ -241,7 +251,8 @@ int snd_hda_multi_out_dig_prepare(struct hda_codec *codec,
241 struct snd_pcm_substream *substream); 251 struct snd_pcm_substream *substream);
242int snd_hda_multi_out_analog_open(struct hda_codec *codec, 252int snd_hda_multi_out_analog_open(struct hda_codec *codec,
243 struct hda_multi_out *mout, 253 struct hda_multi_out *mout,
244 struct snd_pcm_substream *substream); 254 struct snd_pcm_substream *substream,
255 struct hda_pcm_stream *hinfo);
245int snd_hda_multi_out_analog_prepare(struct hda_codec *codec, 256int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
246 struct hda_multi_out *mout, 257 struct hda_multi_out *mout,
247 unsigned int stream_tag, 258 unsigned int stream_tag,
@@ -407,11 +418,4 @@ int snd_hda_check_amp_list_power(struct hda_codec *codec,
407 hda_nid_t nid); 418 hda_nid_t nid);
408#endif /* CONFIG_SND_HDA_POWER_SAVE */ 419#endif /* CONFIG_SND_HDA_POWER_SAVE */
409 420
410/*
411 * virtual master control
412 */
413struct snd_kcontrol *snd_ctl_make_virtual_master(char *name,
414 const unsigned int *tlv);
415int snd_ctl_add_slave(struct snd_kcontrol *master, struct snd_kcontrol *slave);
416
417#endif /* __SOUND_HDA_LOCAL_H */ 421#endif /* __SOUND_HDA_LOCAL_H */
diff --git a/sound/pci/hda/hda_patch.h b/sound/pci/hda/hda_patch.h
index f5c23bb16d7e..2fdf2358dbc2 100644
--- a/sound/pci/hda/hda_patch.h
+++ b/sound/pci/hda/hda_patch.h
@@ -18,31 +18,3 @@ extern struct hda_codec_preset snd_hda_preset_atihdmi[];
18extern struct hda_codec_preset snd_hda_preset_conexant[]; 18extern struct hda_codec_preset snd_hda_preset_conexant[];
19/* VIA codecs */ 19/* VIA codecs */
20extern struct hda_codec_preset snd_hda_preset_via[]; 20extern struct hda_codec_preset snd_hda_preset_via[];
21
22static const struct hda_codec_preset *hda_preset_tables[] = {
23#ifdef CONFIG_SND_HDA_CODEC_REALTEK
24 snd_hda_preset_realtek,
25#endif
26#ifdef CONFIG_SND_HDA_CODEC_CMEDIA
27 snd_hda_preset_cmedia,
28#endif
29#ifdef CONFIG_SND_HDA_CODEC_ANALOG
30 snd_hda_preset_analog,
31#endif
32#ifdef CONFIG_SND_HDA_CODEC_SIGMATEL
33 snd_hda_preset_sigmatel,
34#endif
35#ifdef CONFIG_SND_HDA_CODEC_SI3054
36 snd_hda_preset_si3054,
37#endif
38#ifdef CONFIG_SND_HDA_CODEC_ATIHDMI
39 snd_hda_preset_atihdmi,
40#endif
41#ifdef CONFIG_SND_HDA_CODEC_CONEXANT
42 snd_hda_preset_conexant,
43#endif
44#ifdef CONFIG_SND_HDA_CODEC_VIA
45 snd_hda_preset_via,
46#endif
47 NULL
48};
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index c8649282c2cf..e0a605adde42 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -28,6 +28,7 @@
28#include <sound/core.h> 28#include <sound/core.h>
29#include "hda_codec.h" 29#include "hda_codec.h"
30#include "hda_local.h" 30#include "hda_local.h"
31#include "hda_patch.h"
31 32
32struct ad198x_spec { 33struct ad198x_spec {
33 struct snd_kcontrol_new *mixers[5]; 34 struct snd_kcontrol_new *mixers[5];
@@ -80,7 +81,6 @@ struct ad198x_spec {
80#endif 81#endif
81 /* for virtual master */ 82 /* for virtual master */
82 hda_nid_t vmaster_nid; 83 hda_nid_t vmaster_nid;
83 u32 vmaster_tlv[4];
84 const char **slave_vols; 84 const char **slave_vols;
85 const char **slave_sws; 85 const char **slave_sws;
86}; 86};
@@ -171,6 +171,11 @@ static int ad198x_build_controls(struct hda_codec *codec)
171 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid); 171 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
172 if (err < 0) 172 if (err < 0)
173 return err; 173 return err;
174 err = snd_hda_create_spdif_share_sw(codec,
175 &spec->multiout);
176 if (err < 0)
177 return err;
178 spec->multiout.share_spdif = 1;
174 } 179 }
175 if (spec->dig_in_nid) { 180 if (spec->dig_in_nid) {
176 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); 181 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
@@ -180,10 +185,11 @@ static int ad198x_build_controls(struct hda_codec *codec)
180 185
181 /* if we have no master control, let's create it */ 186 /* if we have no master control, let's create it */
182 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 187 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
188 unsigned int vmaster_tlv[4];
183 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, 189 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
184 HDA_OUTPUT, spec->vmaster_tlv); 190 HDA_OUTPUT, vmaster_tlv);
185 err = snd_hda_add_vmaster(codec, "Master Playback Volume", 191 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
186 spec->vmaster_tlv, 192 vmaster_tlv,
187 (spec->slave_vols ? 193 (spec->slave_vols ?
188 spec->slave_vols : ad_slave_vols)); 194 spec->slave_vols : ad_slave_vols));
189 if (err < 0) 195 if (err < 0)
@@ -217,7 +223,8 @@ static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
217 struct snd_pcm_substream *substream) 223 struct snd_pcm_substream *substream)
218{ 224{
219 struct ad198x_spec *spec = codec->spec; 225 struct ad198x_spec *spec = codec->spec;
220 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream); 226 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
227 hinfo);
221} 228}
222 229
223static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 230static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
@@ -289,8 +296,7 @@ static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
289 struct snd_pcm_substream *substream) 296 struct snd_pcm_substream *substream)
290{ 297{
291 struct ad198x_spec *spec = codec->spec; 298 struct ad198x_spec *spec = codec->spec;
292 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 299 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
293 0, 0, 0);
294 return 0; 300 return 0;
295} 301}
296 302
@@ -359,6 +365,7 @@ static int ad198x_build_pcms(struct hda_codec *codec)
359 info++; 365 info++;
360 codec->num_pcms++; 366 codec->num_pcms++;
361 info->name = "AD198x Digital"; 367 info->name = "AD198x Digital";
368 info->pcm_type = HDA_PCM_TYPE_SPDIF;
362 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback; 369 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = ad198x_pcm_digital_playback;
363 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; 370 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
364 if (spec->dig_in_nid) { 371 if (spec->dig_in_nid) {
@@ -611,13 +618,19 @@ static struct hda_input_mux ad1986a_laptop_eapd_capture_source = {
611 }, 618 },
612}; 619};
613 620
621static struct hda_input_mux ad1986a_automic_capture_source = {
622 .num_items = 2,
623 .items = {
624 { "Mic", 0x0 },
625 { "Mix", 0x5 },
626 },
627};
628
614static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = { 629static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
615 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol), 630 HDA_BIND_VOL("Master Playback Volume", &ad1986a_laptop_master_vol),
616 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw), 631 HDA_BIND_SW("Master Playback Switch", &ad1986a_laptop_master_sw),
617 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT), 632 HDA_CODEC_VOLUME("PCM Playback Volume", 0x03, 0x0, HDA_OUTPUT),
618 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT), 633 HDA_CODEC_MUTE("PCM Playback Switch", 0x03, 0x0, HDA_OUTPUT),
619 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x17, 0x0, HDA_OUTPUT),
620 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x17, 0x0, HDA_OUTPUT),
621 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT), 634 HDA_CODEC_VOLUME("Mic Playback Volume", 0x13, 0x0, HDA_OUTPUT),
622 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT), 635 HDA_CODEC_MUTE("Mic Playback Switch", 0x13, 0x0, HDA_OUTPUT),
623 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT), 636 HDA_CODEC_VOLUME("Mic Boost", 0x0f, 0x0, HDA_OUTPUT),
@@ -641,6 +654,33 @@ static struct snd_kcontrol_new ad1986a_laptop_eapd_mixers[] = {
641 { } /* end */ 654 { } /* end */
642}; 655};
643 656
657/* re-connect the mic boost input according to the jack sensing */
658static void ad1986a_automic(struct hda_codec *codec)
659{
660 unsigned int present;
661 present = snd_hda_codec_read(codec, 0x1f, 0, AC_VERB_GET_PIN_SENSE, 0);
662 /* 0 = 0x1f, 2 = 0x1d, 4 = mixed */
663 snd_hda_codec_write(codec, 0x0f, 0, AC_VERB_SET_CONNECT_SEL,
664 (present & AC_PINSENSE_PRESENCE) ? 0 : 2);
665}
666
667#define AD1986A_MIC_EVENT 0x36
668
669static void ad1986a_automic_unsol_event(struct hda_codec *codec,
670 unsigned int res)
671{
672 if ((res >> 26) != AD1986A_MIC_EVENT)
673 return;
674 ad1986a_automic(codec);
675}
676
677static int ad1986a_automic_init(struct hda_codec *codec)
678{
679 ad198x_init(codec);
680 ad1986a_automic(codec);
681 return 0;
682}
683
644/* laptop-automute - 2ch only */ 684/* laptop-automute - 2ch only */
645 685
646static void ad1986a_update_hp(struct hda_codec *codec) 686static void ad1986a_update_hp(struct hda_codec *codec)
@@ -844,6 +884,15 @@ static struct hda_verb ad1986a_eapd_init_verbs[] = {
844 {} 884 {}
845}; 885};
846 886
887static struct hda_verb ad1986a_automic_verbs[] = {
888 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
889 {0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
890 /*{0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},*/
891 {0x0f, AC_VERB_SET_CONNECT_SEL, 0x0},
892 {0x1f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1986A_MIC_EVENT},
893 {}
894};
895
847/* Ultra initialization */ 896/* Ultra initialization */
848static struct hda_verb ad1986a_ultra_init[] = { 897static struct hda_verb ad1986a_ultra_init[] = {
849 /* eapd initialization */ 898 /* eapd initialization */
@@ -986,14 +1035,17 @@ static int patch_ad1986a(struct hda_codec *codec)
986 break; 1035 break;
987 case AD1986A_LAPTOP_EAPD: 1036 case AD1986A_LAPTOP_EAPD:
988 spec->mixers[0] = ad1986a_laptop_eapd_mixers; 1037 spec->mixers[0] = ad1986a_laptop_eapd_mixers;
989 spec->num_init_verbs = 2; 1038 spec->num_init_verbs = 3;
990 spec->init_verbs[1] = ad1986a_eapd_init_verbs; 1039 spec->init_verbs[1] = ad1986a_eapd_init_verbs;
1040 spec->init_verbs[2] = ad1986a_automic_verbs;
991 spec->multiout.max_channels = 2; 1041 spec->multiout.max_channels = 2;
992 spec->multiout.num_dacs = 1; 1042 spec->multiout.num_dacs = 1;
993 spec->multiout.dac_nids = ad1986a_laptop_dac_nids; 1043 spec->multiout.dac_nids = ad1986a_laptop_dac_nids;
994 if (!is_jack_available(codec, 0x25)) 1044 if (!is_jack_available(codec, 0x25))
995 spec->multiout.dig_out_nid = 0; 1045 spec->multiout.dig_out_nid = 0;
996 spec->input_mux = &ad1986a_laptop_eapd_capture_source; 1046 spec->input_mux = &ad1986a_automic_capture_source;
1047 codec->patch_ops.unsol_event = ad1986a_automic_unsol_event;
1048 codec->patch_ops.init = ad1986a_automic_init;
997 break; 1049 break;
998 case AD1986A_LAPTOP_AUTOMUTE: 1050 case AD1986A_LAPTOP_AUTOMUTE:
999 spec->mixers[0] = ad1986a_laptop_automute_mixers; 1051 spec->mixers[0] = ad1986a_laptop_automute_mixers;
@@ -1365,7 +1417,10 @@ static int ad1981_hp_master_sw_put(struct snd_kcontrol *kcontrol,
1365 1417
1366 if (! ad198x_eapd_put(kcontrol, ucontrol)) 1418 if (! ad198x_eapd_put(kcontrol, ucontrol))
1367 return 0; 1419 return 0;
1368 1420 /* change speaker pin appropriately */
1421 snd_hda_codec_write(codec, 0x05, 0,
1422 AC_VERB_SET_PIN_WIDGET_CONTROL,
1423 spec->cur_eapd ? PIN_OUT : 0);
1369 /* toggle HP mute appropriately */ 1424 /* toggle HP mute appropriately */
1370 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0, 1425 snd_hda_codec_amp_stereo(codec, 0x06, HDA_OUTPUT, 0,
1371 HDA_AMP_MUTE, 1426 HDA_AMP_MUTE,
@@ -2087,6 +2142,10 @@ static struct snd_kcontrol_new ad1988_spdif_in_mixers[] = {
2087 { } /* end */ 2142 { } /* end */
2088}; 2143};
2089 2144
2145static struct snd_kcontrol_new ad1989_spdif_out_mixers[] = {
2146 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
2147 { } /* end */
2148};
2090 2149
2091/* 2150/*
2092 * initialization verbs 2151 * initialization verbs
@@ -2187,6 +2246,13 @@ static struct hda_verb ad1988_spdif_init_verbs[] = {
2187 { } 2246 { }
2188}; 2247};
2189 2248
2249/* AD1989 has no ADC -> SPDIF route */
2250static struct hda_verb ad1989_spdif_init_verbs[] = {
2251 /* SPDIF out pin */
2252 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
2253 { }
2254};
2255
2190/* 2256/*
2191 * verbs for 3stack (+dig) 2257 * verbs for 3stack (+dig)
2192 */ 2258 */
@@ -2894,10 +2960,19 @@ static int patch_ad1988(struct hda_codec *codec)
2894 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers; 2960 spec->mixers[spec->num_mixers++] = ad1988_capture_mixers;
2895 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs; 2961 spec->init_verbs[spec->num_init_verbs++] = ad1988_capture_init_verbs;
2896 if (spec->multiout.dig_out_nid) { 2962 if (spec->multiout.dig_out_nid) {
2897 spec->mixers[spec->num_mixers++] = ad1988_spdif_out_mixers; 2963 if (codec->vendor_id >= 0x11d4989a) {
2898 spec->init_verbs[spec->num_init_verbs++] = ad1988_spdif_init_verbs; 2964 spec->mixers[spec->num_mixers++] =
2965 ad1989_spdif_out_mixers;
2966 spec->init_verbs[spec->num_init_verbs++] =
2967 ad1989_spdif_init_verbs;
2968 } else {
2969 spec->mixers[spec->num_mixers++] =
2970 ad1988_spdif_out_mixers;
2971 spec->init_verbs[spec->num_init_verbs++] =
2972 ad1988_spdif_init_verbs;
2973 }
2899 } 2974 }
2900 if (spec->dig_in_nid) 2975 if (spec->dig_in_nid && codec->vendor_id < 0x11d4989a)
2901 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers; 2976 spec->mixers[spec->num_mixers++] = ad1988_spdif_in_mixers;
2902 2977
2903 codec->patch_ops = ad198x_patch_ops; 2978 codec->patch_ops = ad198x_patch_ops;
@@ -3133,11 +3208,12 @@ static int patch_ad1884(struct hda_codec *codec)
3133 * Lenovo Thinkpad T61/X61 3208 * Lenovo Thinkpad T61/X61
3134 */ 3209 */
3135static struct hda_input_mux ad1984_thinkpad_capture_source = { 3210static struct hda_input_mux ad1984_thinkpad_capture_source = {
3136 .num_items = 3, 3211 .num_items = 4,
3137 .items = { 3212 .items = {
3138 { "Mic", 0x0 }, 3213 { "Mic", 0x0 },
3139 { "Internal Mic", 0x1 }, 3214 { "Internal Mic", 0x1 },
3140 { "Mix", 0x3 }, 3215 { "Mix", 0x3 },
3216 { "Docking-Station", 0x4 },
3141 }, 3217 },
3142}; 3218};
3143 3219
@@ -3268,8 +3344,7 @@ static int ad1984_pcm_dmic_cleanup(struct hda_pcm_stream *hinfo,
3268 struct hda_codec *codec, 3344 struct hda_codec *codec,
3269 struct snd_pcm_substream *substream) 3345 struct snd_pcm_substream *substream)
3270{ 3346{
3271 snd_hda_codec_setup_stream(codec, 0x05 + substream->number, 3347 snd_hda_codec_cleanup_stream(codec, 0x05 + substream->number);
3272 0, 0, 0);
3273 return 0; 3348 return 0;
3274} 3349}
3275 3350
@@ -3356,6 +3431,472 @@ static int patch_ad1984(struct hda_codec *codec)
3356 3431
3357 3432
3358/* 3433/*
3434 * AD1883 / AD1884A / AD1984A / AD1984B
3435 *
3436 * port-B (0x14) - front mic-in
3437 * port-E (0x1c) - rear mic-in
3438 * port-F (0x16) - CD / ext out
3439 * port-C (0x15) - rear line-in
3440 * port-D (0x12) - rear line-out
3441 * port-A (0x11) - front hp-out
3442 *
3443 * AD1984A = AD1884A + digital-mic
3444 * AD1883 = equivalent with AD1984A
3445 * AD1984B = AD1984A + extra SPDIF-out
3446 *
3447 * FIXME:
3448 * We share the single DAC for both HP and line-outs (see AD1884/1984).
3449 */
3450
3451static hda_nid_t ad1884a_dac_nids[1] = {
3452 0x03,
3453};
3454
3455#define ad1884a_adc_nids ad1884_adc_nids
3456#define ad1884a_capsrc_nids ad1884_capsrc_nids
3457
3458#define AD1884A_SPDIF_OUT 0x02
3459
3460static struct hda_input_mux ad1884a_capture_source = {
3461 .num_items = 5,
3462 .items = {
3463 { "Front Mic", 0x0 },
3464 { "Mic", 0x4 },
3465 { "Line", 0x1 },
3466 { "CD", 0x2 },
3467 { "Mix", 0x3 },
3468 },
3469};
3470
3471static struct snd_kcontrol_new ad1884a_base_mixers[] = {
3472 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3473 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3474 HDA_CODEC_MUTE("Headphone Playback Switch", 0x11, 0x0, HDA_OUTPUT),
3475 HDA_CODEC_MUTE("Front Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3476 HDA_CODEC_VOLUME_MONO("Mono Playback Volume", 0x13, 1, 0x0, HDA_OUTPUT),
3477 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x13, 1, 0x0, HDA_OUTPUT),
3478 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3479 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3480 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3481 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3482 HDA_CODEC_VOLUME("Line Playback Volume", 0x20, 0x01, HDA_INPUT),
3483 HDA_CODEC_MUTE("Line Playback Switch", 0x20, 0x01, HDA_INPUT),
3484 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3485 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3486 HDA_CODEC_VOLUME("CD Playback Volume", 0x20, 0x02, HDA_INPUT),
3487 HDA_CODEC_MUTE("CD Playback Switch", 0x20, 0x02, HDA_INPUT),
3488 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3489 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3490 HDA_CODEC_VOLUME("Front Mic Boost", 0x14, 0x0, HDA_INPUT),
3491 HDA_CODEC_VOLUME("Line Boost", 0x15, 0x0, HDA_INPUT),
3492 HDA_CODEC_VOLUME("Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3493 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3494 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3495 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3496 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3497 {
3498 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3499 /* The multiple "Capture Source" controls confuse alsamixer
3500 * So call somewhat different..
3501 */
3502 /* .name = "Capture Source", */
3503 .name = "Input Source",
3504 .count = 2,
3505 .info = ad198x_mux_enum_info,
3506 .get = ad198x_mux_enum_get,
3507 .put = ad198x_mux_enum_put,
3508 },
3509 /* SPDIF controls */
3510 HDA_CODEC_VOLUME("IEC958 Playback Volume", 0x1b, 0x0, HDA_OUTPUT),
3511 {
3512 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3513 .name = SNDRV_CTL_NAME_IEC958("",PLAYBACK,NONE) "Source",
3514 /* identical with ad1983 */
3515 .info = ad1983_spdif_route_info,
3516 .get = ad1983_spdif_route_get,
3517 .put = ad1983_spdif_route_put,
3518 },
3519 { } /* end */
3520};
3521
3522/*
3523 * initialization verbs
3524 */
3525static struct hda_verb ad1884a_init_verbs[] = {
3526 /* DACs; unmute as default */
3527 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3528 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x27}, /* 0dB */
3529 /* Port-A (HP) mixer - route only from analog mixer */
3530 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3531 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3532 /* Port-A pin */
3533 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3534 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3535 /* Port-D (Line-out) mixer - route only from analog mixer */
3536 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3537 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3538 /* Port-D pin */
3539 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3540 {0x12, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3541 /* Mono-out mixer - route only from analog mixer */
3542 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3543 {0x1e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3544 /* Mono-out pin */
3545 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3546 {0x13, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3547 /* Port-B (front mic) pin */
3548 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3549 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3550 /* Port-C (rear line-in) pin */
3551 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3552 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3553 /* Port-E (rear mic) pin */
3554 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
3555 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3556 {0x25, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO}, /* no boost */
3557 /* Port-F (CD) pin */
3558 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3559 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3560 /* Analog mixer; mute as default */
3561 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3562 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
3563 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
3564 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
3565 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)}, /* aux */
3566 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
3567 /* Analog Mix output amp */
3568 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3569 /* capture sources */
3570 {0x0c, AC_VERB_SET_CONNECT_SEL, 0x0},
3571 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3572 {0x0d, AC_VERB_SET_CONNECT_SEL, 0x0},
3573 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3574 /* SPDIF output amp */
3575 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE | 0x27}, /* 0dB */
3576 { } /* end */
3577};
3578
3579#ifdef CONFIG_SND_HDA_POWER_SAVE
3580static struct hda_amp_list ad1884a_loopbacks[] = {
3581 { 0x20, HDA_INPUT, 0 }, /* Front Mic */
3582 { 0x20, HDA_INPUT, 1 }, /* Mic */
3583 { 0x20, HDA_INPUT, 2 }, /* CD */
3584 { 0x20, HDA_INPUT, 4 }, /* Docking */
3585 { } /* end */
3586};
3587#endif
3588
3589/*
3590 * Laptop model
3591 *
3592 * Port A: Headphone jack
3593 * Port B: MIC jack
3594 * Port C: Internal MIC
3595 * Port D: Dock Line Out (if enabled)
3596 * Port E: Dock Line In (if enabled)
3597 * Port F: Internal speakers
3598 */
3599
3600static struct hda_input_mux ad1884a_laptop_capture_source = {
3601 .num_items = 4,
3602 .items = {
3603 { "Mic", 0x0 }, /* port-B */
3604 { "Internal Mic", 0x1 }, /* port-C */
3605 { "Dock Mic", 0x4 }, /* port-E */
3606 { "Mix", 0x3 },
3607 },
3608};
3609
3610static struct snd_kcontrol_new ad1884a_laptop_mixers[] = {
3611 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3612 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3613 HDA_CODEC_MUTE("Dock Playback Switch", 0x12, 0x0, HDA_OUTPUT),
3614 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3615 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3616 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3617 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3618 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3619 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3620 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x20, 0x04, HDA_INPUT),
3621 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x20, 0x04, HDA_INPUT),
3622 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3623 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3624 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3625 HDA_CODEC_VOLUME("Internal Mic Boost", 0x15, 0x0, HDA_INPUT),
3626 HDA_CODEC_VOLUME("Dock Mic Boost", 0x25, 0x0, HDA_OUTPUT),
3627 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3628 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3629 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x0d, 0x0, HDA_OUTPUT),
3630 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x0d, 0x0, HDA_OUTPUT),
3631 {
3632 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3633 /* The multiple "Capture Source" controls confuse alsamixer
3634 * So call somewhat different..
3635 */
3636 /* .name = "Capture Source", */
3637 .name = "Input Source",
3638 .count = 2,
3639 .info = ad198x_mux_enum_info,
3640 .get = ad198x_mux_enum_get,
3641 .put = ad198x_mux_enum_put,
3642 },
3643 { } /* end */
3644};
3645
3646static struct hda_input_mux ad1884a_mobile_capture_source = {
3647 .num_items = 2,
3648 .items = {
3649 { "Mic", 0x1 }, /* port-C */
3650 { "Mix", 0x3 },
3651 },
3652};
3653
3654static struct snd_kcontrol_new ad1884a_mobile_mixers[] = {
3655 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3656 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3657 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3658 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3659 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x01, HDA_INPUT),
3660 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x01, HDA_INPUT),
3661 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3662 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3663 HDA_CODEC_VOLUME("Mic Boost", 0x15, 0x0, HDA_INPUT),
3664 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3665 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3666 {
3667 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3668 .name = "Capture Source",
3669 .info = ad198x_mux_enum_info,
3670 .get = ad198x_mux_enum_get,
3671 .put = ad198x_mux_enum_put,
3672 },
3673 { } /* end */
3674};
3675
3676/* mute internal speaker if HP is plugged */
3677static void ad1884a_hp_automute(struct hda_codec *codec)
3678{
3679 unsigned int present;
3680
3681 present = snd_hda_codec_read(codec, 0x11, 0,
3682 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
3683 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
3684 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3685 snd_hda_codec_write(codec, 0x16, 0, AC_VERB_SET_EAPD_BTLENABLE,
3686 present ? 0x00 : 0x02);
3687}
3688
3689#define AD1884A_HP_EVENT 0x37
3690
3691/* unsolicited event for HP jack sensing */
3692static void ad1884a_hp_unsol_event(struct hda_codec *codec, unsigned int res)
3693{
3694 if ((res >> 26) != AD1884A_HP_EVENT)
3695 return;
3696 ad1884a_hp_automute(codec);
3697}
3698
3699/* initialize jack-sensing, too */
3700static int ad1884a_hp_init(struct hda_codec *codec)
3701{
3702 ad198x_init(codec);
3703 ad1884a_hp_automute(codec);
3704 return 0;
3705}
3706
3707/* additional verbs for laptop model */
3708static struct hda_verb ad1884a_laptop_verbs[] = {
3709 /* Port-A (HP) pin - always unmuted */
3710 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3711 /* Port-F (int speaker) mixer - route only from analog mixer */
3712 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
3713 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
3714 /* Port-F pin */
3715 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
3716 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
3717 /* analog mix */
3718 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3719 /* unsolicited event for pin-sense */
3720 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3721 { } /* end */
3722};
3723
3724/*
3725 * Thinkpad X300
3726 * 0x11 - HP
3727 * 0x12 - speaker
3728 * 0x14 - mic-in
3729 * 0x17 - built-in mic
3730 */
3731
3732static struct hda_verb ad1984a_thinkpad_verbs[] = {
3733 /* HP unmute */
3734 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
3735 /* analog mix */
3736 {0x20, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
3737 /* turn on EAPD */
3738 {0x12, AC_VERB_SET_EAPD_BTLENABLE, 0x02},
3739 /* unsolicited event for pin-sense */
3740 {0x11, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | AD1884A_HP_EVENT},
3741 /* internal mic - dmic */
3742 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
3743 /* set magic COEFs for dmic */
3744 {0x01, AC_VERB_SET_COEF_INDEX, 0x13f7},
3745 {0x01, AC_VERB_SET_PROC_COEF, 0x08},
3746 { } /* end */
3747};
3748
3749static struct snd_kcontrol_new ad1984a_thinkpad_mixers[] = {
3750 HDA_CODEC_VOLUME("Master Playback Volume", 0x21, 0x0, HDA_OUTPUT),
3751 HDA_CODEC_MUTE("Master Playback Switch", 0x21, 0x0, HDA_OUTPUT),
3752 HDA_CODEC_VOLUME("PCM Playback Volume", 0x20, 0x5, HDA_INPUT),
3753 HDA_CODEC_MUTE("PCM Playback Switch", 0x20, 0x5, HDA_INPUT),
3754 HDA_CODEC_VOLUME("Mic Playback Volume", 0x20, 0x00, HDA_INPUT),
3755 HDA_CODEC_MUTE("Mic Playback Switch", 0x20, 0x00, HDA_INPUT),
3756 HDA_CODEC_VOLUME("Beep Playback Volume", 0x20, 0x03, HDA_INPUT),
3757 HDA_CODEC_MUTE("Beep Playback Switch", 0x20, 0x03, HDA_INPUT),
3758 HDA_CODEC_VOLUME("Mic Boost", 0x14, 0x0, HDA_INPUT),
3759 HDA_CODEC_VOLUME("Internal Mic Boost", 0x17, 0x0, HDA_INPUT),
3760 HDA_CODEC_VOLUME("Capture Volume", 0x0c, 0x0, HDA_OUTPUT),
3761 HDA_CODEC_MUTE("Capture Switch", 0x0c, 0x0, HDA_OUTPUT),
3762 {
3763 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
3764 .name = "Capture Source",
3765 .info = ad198x_mux_enum_info,
3766 .get = ad198x_mux_enum_get,
3767 .put = ad198x_mux_enum_put,
3768 },
3769 { } /* end */
3770};
3771
3772static struct hda_input_mux ad1984a_thinkpad_capture_source = {
3773 .num_items = 3,
3774 .items = {
3775 { "Mic", 0x0 },
3776 { "Internal Mic", 0x5 },
3777 { "Mix", 0x3 },
3778 },
3779};
3780
3781/* mute internal speaker if HP is plugged */
3782static void ad1984a_thinkpad_automute(struct hda_codec *codec)
3783{
3784 unsigned int present;
3785
3786 present = snd_hda_codec_read(codec, 0x11, 0, AC_VERB_GET_PIN_SENSE, 0)
3787 & AC_PINSENSE_PRESENCE;
3788 snd_hda_codec_amp_stereo(codec, 0x12, HDA_OUTPUT, 0,
3789 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
3790}
3791
3792/* unsolicited event for HP jack sensing */
3793static void ad1984a_thinkpad_unsol_event(struct hda_codec *codec,
3794 unsigned int res)
3795{
3796 if ((res >> 26) != AD1884A_HP_EVENT)
3797 return;
3798 ad1984a_thinkpad_automute(codec);
3799}
3800
3801/* initialize jack-sensing, too */
3802static int ad1984a_thinkpad_init(struct hda_codec *codec)
3803{
3804 ad198x_init(codec);
3805 ad1984a_thinkpad_automute(codec);
3806 return 0;
3807}
3808
3809/*
3810 */
3811
3812enum {
3813 AD1884A_DESKTOP,
3814 AD1884A_LAPTOP,
3815 AD1884A_MOBILE,
3816 AD1884A_THINKPAD,
3817 AD1884A_MODELS
3818};
3819
3820static const char *ad1884a_models[AD1884A_MODELS] = {
3821 [AD1884A_DESKTOP] = "desktop",
3822 [AD1884A_LAPTOP] = "laptop",
3823 [AD1884A_MOBILE] = "mobile",
3824 [AD1884A_THINKPAD] = "thinkpad",
3825};
3826
3827static struct snd_pci_quirk ad1884a_cfg_tbl[] = {
3828 SND_PCI_QUIRK(0x103c, 0x3030, "HP", AD1884A_MOBILE),
3829 SND_PCI_QUIRK(0x17aa, 0x20ac, "Thinkpad X300", AD1884A_THINKPAD),
3830 {}
3831};
3832
3833static int patch_ad1884a(struct hda_codec *codec)
3834{
3835 struct ad198x_spec *spec;
3836 int board_config;
3837
3838 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
3839 if (spec == NULL)
3840 return -ENOMEM;
3841
3842 mutex_init(&spec->amp_mutex);
3843 codec->spec = spec;
3844
3845 spec->multiout.max_channels = 2;
3846 spec->multiout.num_dacs = ARRAY_SIZE(ad1884a_dac_nids);
3847 spec->multiout.dac_nids = ad1884a_dac_nids;
3848 spec->multiout.dig_out_nid = AD1884A_SPDIF_OUT;
3849 spec->num_adc_nids = ARRAY_SIZE(ad1884a_adc_nids);
3850 spec->adc_nids = ad1884a_adc_nids;
3851 spec->capsrc_nids = ad1884a_capsrc_nids;
3852 spec->input_mux = &ad1884a_capture_source;
3853 spec->num_mixers = 1;
3854 spec->mixers[0] = ad1884a_base_mixers;
3855 spec->num_init_verbs = 1;
3856 spec->init_verbs[0] = ad1884a_init_verbs;
3857 spec->spdif_route = 0;
3858#ifdef CONFIG_SND_HDA_POWER_SAVE
3859 spec->loopback.amplist = ad1884a_loopbacks;
3860#endif
3861 codec->patch_ops = ad198x_patch_ops;
3862
3863 /* override some parameters */
3864 board_config = snd_hda_check_board_config(codec, AD1884A_MODELS,
3865 ad1884a_models,
3866 ad1884a_cfg_tbl);
3867 switch (board_config) {
3868 case AD1884A_LAPTOP:
3869 spec->mixers[0] = ad1884a_laptop_mixers;
3870 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
3871 spec->multiout.dig_out_nid = 0;
3872 spec->input_mux = &ad1884a_laptop_capture_source;
3873 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
3874 codec->patch_ops.init = ad1884a_hp_init;
3875 break;
3876 case AD1884A_MOBILE:
3877 spec->mixers[0] = ad1884a_mobile_mixers;
3878 spec->init_verbs[spec->num_init_verbs++] = ad1884a_laptop_verbs;
3879 spec->multiout.dig_out_nid = 0;
3880 spec->input_mux = &ad1884a_mobile_capture_source;
3881 codec->patch_ops.unsol_event = ad1884a_hp_unsol_event;
3882 codec->patch_ops.init = ad1884a_hp_init;
3883 break;
3884 case AD1884A_THINKPAD:
3885 spec->mixers[0] = ad1984a_thinkpad_mixers;
3886 spec->init_verbs[spec->num_init_verbs++] =
3887 ad1984a_thinkpad_verbs;
3888 spec->multiout.dig_out_nid = 0;
3889 spec->input_mux = &ad1984a_thinkpad_capture_source;
3890 codec->patch_ops.unsol_event = ad1984a_thinkpad_unsol_event;
3891 codec->patch_ops.init = ad1984a_thinkpad_init;
3892 break;
3893 }
3894
3895 return 0;
3896}
3897
3898
3899/*
3359 * AD1882 3900 * AD1882
3360 * 3901 *
3361 * port-A - front hp-out 3902 * port-A - front hp-out
@@ -3654,13 +4195,19 @@ static int patch_ad1882(struct hda_codec *codec)
3654 * patch entries 4195 * patch entries
3655 */ 4196 */
3656struct hda_codec_preset snd_hda_preset_analog[] = { 4197struct hda_codec_preset snd_hda_preset_analog[] = {
4198 { .id = 0x11d4184a, .name = "AD1884A", .patch = patch_ad1884a },
3657 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 }, 4199 { .id = 0x11d41882, .name = "AD1882", .patch = patch_ad1882 },
4200 { .id = 0x11d41883, .name = "AD1883", .patch = patch_ad1884a },
3658 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 }, 4201 { .id = 0x11d41884, .name = "AD1884", .patch = patch_ad1884 },
4202 { .id = 0x11d4194a, .name = "AD1984A", .patch = patch_ad1884a },
4203 { .id = 0x11d4194b, .name = "AD1984B", .patch = patch_ad1884a },
3659 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 }, 4204 { .id = 0x11d41981, .name = "AD1981", .patch = patch_ad1981 },
3660 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 }, 4205 { .id = 0x11d41983, .name = "AD1983", .patch = patch_ad1983 },
3661 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 }, 4206 { .id = 0x11d41984, .name = "AD1984", .patch = patch_ad1984 },
3662 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a }, 4207 { .id = 0x11d41986, .name = "AD1986A", .patch = patch_ad1986a },
3663 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 }, 4208 { .id = 0x11d41988, .name = "AD1988", .patch = patch_ad1988 },
3664 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 }, 4209 { .id = 0x11d4198b, .name = "AD1988B", .patch = patch_ad1988 },
4210 { .id = 0x11d4989a, .name = "AD1989A", .patch = patch_ad1988 },
4211 { .id = 0x11d4989b, .name = "AD1989B", .patch = patch_ad1988 },
3665 {} /* terminator */ 4212 {} /* terminator */
3666}; 4213};
diff --git a/sound/pci/hda/patch_atihdmi.c b/sound/pci/hda/patch_atihdmi.c
index 9a8bb4ce3f8d..12272508b112 100644
--- a/sound/pci/hda/patch_atihdmi.c
+++ b/sound/pci/hda/patch_atihdmi.c
@@ -27,6 +27,7 @@
27#include <sound/core.h> 27#include <sound/core.h>
28#include "hda_codec.h" 28#include "hda_codec.h"
29#include "hda_local.h" 29#include "hda_local.h"
30#include "hda_patch.h"
30 31
31struct atihdmi_spec { 32struct atihdmi_spec {
32 struct hda_multi_out multiout; 33 struct hda_multi_out multiout;
@@ -58,6 +59,10 @@ static int atihdmi_build_controls(struct hda_codec *codec)
58static int atihdmi_init(struct hda_codec *codec) 59static int atihdmi_init(struct hda_codec *codec)
59{ 60{
60 snd_hda_sequence_write(codec, atihdmi_basic_init); 61 snd_hda_sequence_write(codec, atihdmi_basic_init);
62 /* SI codec requires to unmute the pin */
63 if (get_wcaps(codec, 0x03) & AC_WCAP_OUT_AMP)
64 snd_hda_codec_write(codec, 0x03, 0, AC_VERB_SET_AMP_GAIN_MUTE,
65 AMP_OUT_UNMUTE);
61 return 0; 66 return 0;
62} 67}
63 68
@@ -112,6 +117,7 @@ static int atihdmi_build_pcms(struct hda_codec *codec)
112 codec->pcm_info = info; 117 codec->pcm_info = info;
113 118
114 info->name = "ATI HDMI"; 119 info->name = "ATI HDMI";
120 info->pcm_type = HDA_PCM_TYPE_HDMI;
115 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = atihdmi_pcm_digital_playback; 121 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = atihdmi_pcm_digital_playback;
116 122
117 return 0; 123 return 0;
@@ -158,5 +164,7 @@ struct hda_codec_preset snd_hda_preset_atihdmi[] = {
158 { .id = 0x10027919, .name = "ATI RS600 HDMI", .patch = patch_atihdmi }, 164 { .id = 0x10027919, .name = "ATI RS600 HDMI", .patch = patch_atihdmi },
159 { .id = 0x1002791a, .name = "ATI RS690/780 HDMI", .patch = patch_atihdmi }, 165 { .id = 0x1002791a, .name = "ATI RS690/780 HDMI", .patch = patch_atihdmi },
160 { .id = 0x1002aa01, .name = "ATI R6xx HDMI", .patch = patch_atihdmi }, 166 { .id = 0x1002aa01, .name = "ATI R6xx HDMI", .patch = patch_atihdmi },
167 { .id = 0x10951392, .name = "SiI1392 HDMI", .patch = patch_atihdmi },
168 { .id = 0x17e80047, .name = "Chrontel HDMI", .patch = patch_atihdmi },
161 {} /* terminator */ 169 {} /* terminator */
162}; 170};
diff --git a/sound/pci/hda/patch_cmedia.c b/sound/pci/hda/patch_cmedia.c
index 3d6097ba1d68..c73ce074a6ea 100644
--- a/sound/pci/hda/patch_cmedia.c
+++ b/sound/pci/hda/patch_cmedia.c
@@ -28,6 +28,7 @@
28#include <sound/core.h> 28#include <sound/core.h>
29#include "hda_codec.h" 29#include "hda_codec.h"
30#include "hda_local.h" 30#include "hda_local.h"
31#include "hda_patch.h"
31#define NUM_PINS 11 32#define NUM_PINS 11
32 33
33 34
@@ -329,6 +330,11 @@ static int cmi9880_build_controls(struct hda_codec *codec)
329 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid); 330 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
330 if (err < 0) 331 if (err < 0)
331 return err; 332 return err;
333 err = snd_hda_create_spdif_share_sw(codec,
334 &spec->multiout);
335 if (err < 0)
336 return err;
337 spec->multiout.share_spdif = 1;
332 } 338 }
333 if (spec->dig_in_nid) { 339 if (spec->dig_in_nid) {
334 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); 340 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
@@ -432,7 +438,8 @@ static int cmi9880_playback_pcm_open(struct hda_pcm_stream *hinfo,
432 struct snd_pcm_substream *substream) 438 struct snd_pcm_substream *substream)
433{ 439{
434 struct cmi_spec *spec = codec->spec; 440 struct cmi_spec *spec = codec->spec;
435 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream); 441 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
442 hinfo);
436} 443}
437 444
438static int cmi9880_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 445static int cmi9880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
@@ -506,7 +513,7 @@ static int cmi9880_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
506{ 513{
507 struct cmi_spec *spec = codec->spec; 514 struct cmi_spec *spec = codec->spec;
508 515
509 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0); 516 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
510 return 0; 517 return 0;
511} 518}
512 519
@@ -571,6 +578,7 @@ static int cmi9880_build_pcms(struct hda_codec *codec)
571 codec->num_pcms++; 578 codec->num_pcms++;
572 info++; 579 info++;
573 info->name = "CMI9880 Digital"; 580 info->name = "CMI9880 Digital";
581 info->pcm_type = HDA_PCM_TYPE_SPDIF;
574 if (spec->multiout.dig_out_nid) { 582 if (spec->multiout.dig_out_nid) {
575 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cmi9880_pcm_digital_playback; 583 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = cmi9880_pcm_digital_playback;
576 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; 584 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
@@ -603,6 +611,7 @@ static const char *cmi9880_models[CMI_MODELS] = {
603 611
604static struct snd_pci_quirk cmi9880_cfg_tbl[] = { 612static struct snd_pci_quirk cmi9880_cfg_tbl[] = {
605 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", CMI_FULL_DIG), 613 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", CMI_FULL_DIG),
614 SND_PCI_QUIRK(0x1854, 0x0032, "LG", CMI_FULL_DIG),
606 {} /* terminator */ 615 {} /* terminator */
607}; 616};
608 617
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index 7206b30cbf94..36fd85260035 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -27,6 +27,7 @@
27#include <sound/core.h> 27#include <sound/core.h>
28#include "hda_codec.h" 28#include "hda_codec.h"
29#include "hda_local.h" 29#include "hda_local.h"
30#include "hda_patch.h"
30 31
31#define CXT_PIN_DIR_IN 0x00 32#define CXT_PIN_DIR_IN 0x00
32#define CXT_PIN_DIR_OUT 0x01 33#define CXT_PIN_DIR_OUT 0x01
@@ -98,7 +99,8 @@ static int conexant_playback_pcm_open(struct hda_pcm_stream *hinfo,
98 struct snd_pcm_substream *substream) 99 struct snd_pcm_substream *substream)
99{ 100{
100 struct conexant_spec *spec = codec->spec; 101 struct conexant_spec *spec = codec->spec;
101 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream); 102 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
103 hinfo);
102} 104}
103 105
104static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 106static int conexant_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
@@ -172,8 +174,7 @@ static int conexant_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
172 struct snd_pcm_substream *substream) 174 struct snd_pcm_substream *substream)
173{ 175{
174 struct conexant_spec *spec = codec->spec; 176 struct conexant_spec *spec = codec->spec;
175 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 177 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
176 0, 0, 0);
177 return 0; 178 return 0;
178} 179}
179 180
@@ -241,7 +242,7 @@ static int cx5051_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
241 struct snd_pcm_substream *substream) 242 struct snd_pcm_substream *substream)
242{ 243{
243 struct conexant_spec *spec = codec->spec; 244 struct conexant_spec *spec = codec->spec;
244 snd_hda_codec_setup_stream(codec, spec->cur_adc, 0, 0, 0); 245 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
245 spec->cur_adc = 0; 246 spec->cur_adc = 0;
246 return 0; 247 return 0;
247} 248}
@@ -284,6 +285,7 @@ static int conexant_build_pcms(struct hda_codec *codec)
284 info++; 285 info++;
285 codec->num_pcms++; 286 codec->num_pcms++;
286 info->name = "Conexant Digital"; 287 info->name = "Conexant Digital";
288 info->pcm_type = HDA_PCM_TYPE_SPDIF;
287 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 289 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
288 conexant_pcm_digital_playback; 290 conexant_pcm_digital_playback;
289 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 291 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
@@ -371,6 +373,11 @@ static int conexant_build_controls(struct hda_codec *codec)
371 spec->multiout.dig_out_nid); 373 spec->multiout.dig_out_nid);
372 if (err < 0) 374 if (err < 0)
373 return err; 375 return err;
376 err = snd_hda_create_spdif_share_sw(codec,
377 &spec->multiout);
378 if (err < 0)
379 return err;
380 spec->multiout.share_spdif = 1;
374 } 381 }
375 if (spec->dig_in_nid) { 382 if (spec->dig_in_nid) {
376 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid); 383 err = snd_hda_create_spdif_in_ctls(codec,spec->dig_in_nid);
@@ -511,6 +518,14 @@ static struct hda_input_mux cxt5045_capture_source_benq = {
511 } 518 }
512}; 519};
513 520
521static struct hda_input_mux cxt5045_capture_source_hp530 = {
522 .num_items = 2,
523 .items = {
524 { "ExtMic", 0x1 },
525 { "IntMic", 0x2 },
526 }
527};
528
514/* turn on/off EAPD (+ mute HP) as a master switch */ 529/* turn on/off EAPD (+ mute HP) as a master switch */
515static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol, 530static int cxt5045_hp_master_sw_put(struct snd_kcontrol *kcontrol,
516 struct snd_ctl_elem_value *ucontrol) 531 struct snd_ctl_elem_value *ucontrol)
@@ -639,6 +654,37 @@ static struct snd_kcontrol_new cxt5045_benq_mixers[] = {
639 {} 654 {}
640}; 655};
641 656
657static struct snd_kcontrol_new cxt5045_mixers_hp530[] = {
658 {
659 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
660 .name = "Capture Source",
661 .info = conexant_mux_enum_info,
662 .get = conexant_mux_enum_get,
663 .put = conexant_mux_enum_put
664 },
665 HDA_CODEC_VOLUME("Int Mic Capture Volume", 0x1a, 0x02, HDA_INPUT),
666 HDA_CODEC_MUTE("Int Mic Capture Switch", 0x1a, 0x02, HDA_INPUT),
667 HDA_CODEC_VOLUME("Ext Mic Capture Volume", 0x1a, 0x01, HDA_INPUT),
668 HDA_CODEC_MUTE("Ext Mic Capture Switch", 0x1a, 0x01, HDA_INPUT),
669 HDA_CODEC_VOLUME("PCM Playback Volume", 0x17, 0x0, HDA_INPUT),
670 HDA_CODEC_MUTE("PCM Playback Switch", 0x17, 0x0, HDA_INPUT),
671 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x17, 0x2, HDA_INPUT),
672 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x17, 0x2, HDA_INPUT),
673 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x17, 0x1, HDA_INPUT),
674 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x17, 0x1, HDA_INPUT),
675 HDA_BIND_VOL("Master Playback Volume", &cxt5045_hp_bind_master_vol),
676 {
677 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
678 .name = "Master Playback Switch",
679 .info = cxt_eapd_info,
680 .get = cxt_eapd_get,
681 .put = cxt5045_hp_master_sw_put,
682 .private_value = 0x10,
683 },
684
685 {}
686};
687
642static struct hda_verb cxt5045_init_verbs[] = { 688static struct hda_verb cxt5045_init_verbs[] = {
643 /* Line in, Mic */ 689 /* Line in, Mic */
644 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, 690 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
@@ -833,6 +879,7 @@ enum {
833 CXT5045_LAPTOP_MICSENSE, 879 CXT5045_LAPTOP_MICSENSE,
834 CXT5045_LAPTOP_HPMICSENSE, 880 CXT5045_LAPTOP_HPMICSENSE,
835 CXT5045_BENQ, 881 CXT5045_BENQ,
882 CXT5045_LAPTOP_HP530,
836#ifdef CONFIG_SND_DEBUG 883#ifdef CONFIG_SND_DEBUG
837 CXT5045_TEST, 884 CXT5045_TEST,
838#endif 885#endif
@@ -844,6 +891,7 @@ static const char *cxt5045_models[CXT5045_MODELS] = {
844 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense", 891 [CXT5045_LAPTOP_MICSENSE] = "laptop-micsense",
845 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense", 892 [CXT5045_LAPTOP_HPMICSENSE] = "laptop-hpmicsense",
846 [CXT5045_BENQ] = "benq", 893 [CXT5045_BENQ] = "benq",
894 [CXT5045_LAPTOP_HP530] = "laptop-hp530",
847#ifdef CONFIG_SND_DEBUG 895#ifdef CONFIG_SND_DEBUG
848 [CXT5045_TEST] = "test", 896 [CXT5045_TEST] = "test",
849#endif 897#endif
@@ -857,7 +905,7 @@ static struct snd_pci_quirk cxt5045_cfg_tbl[] = {
857 SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE), 905 SND_PCI_QUIRK(0x103c, 0x30bb, "HP DV8000", CXT5045_LAPTOP_HPSENSE),
858 SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE), 906 SND_PCI_QUIRK(0x103c, 0x30cd, "HP DV Series", CXT5045_LAPTOP_HPSENSE),
859 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE), 907 SND_PCI_QUIRK(0x103c, 0x30cf, "HP DV9533EG", CXT5045_LAPTOP_HPSENSE),
860 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HPSENSE), 908 SND_PCI_QUIRK(0x103c, 0x30d5, "HP 530", CXT5045_LAPTOP_HP530),
861 SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE), 909 SND_PCI_QUIRK(0x103c, 0x30d9, "HP Spartan", CXT5045_LAPTOP_HPSENSE),
862 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ), 910 SND_PCI_QUIRK(0x152d, 0x0753, "Benq R55E", CXT5045_BENQ),
863 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE), 911 SND_PCI_QUIRK(0x1734, 0x10ad, "Fujitsu Si1520", CXT5045_LAPTOP_MICSENSE),
@@ -941,6 +989,14 @@ static int patch_cxt5045(struct hda_codec *codec)
941 spec->num_mixers = 2; 989 spec->num_mixers = 2;
942 codec->patch_ops.init = cxt5045_init; 990 codec->patch_ops.init = cxt5045_init;
943 break; 991 break;
992 case CXT5045_LAPTOP_HP530:
993 codec->patch_ops.unsol_event = cxt5045_hp_unsol_event;
994 spec->input_mux = &cxt5045_capture_source_hp530;
995 spec->num_init_verbs = 2;
996 spec->init_verbs[1] = cxt5045_hp_sense_init_verbs;
997 spec->mixers[0] = cxt5045_mixers_hp530;
998 codec->patch_ops.init = cxt5045_init;
999 break;
944#ifdef CONFIG_SND_DEBUG 1000#ifdef CONFIG_SND_DEBUG
945 case CXT5045_TEST: 1001 case CXT5045_TEST:
946 spec->input_mux = &cxt5045_test_capture_source; 1002 spec->input_mux = &cxt5045_test_capture_source;
@@ -1537,7 +1593,7 @@ static void cxt5051_portc_automic(struct hda_codec *codec)
1537 new_adc = spec->adc_nids[spec->cur_adc_idx]; 1593 new_adc = spec->adc_nids[spec->cur_adc_idx];
1538 if (spec->cur_adc && spec->cur_adc != new_adc) { 1594 if (spec->cur_adc && spec->cur_adc != new_adc) {
1539 /* stream is running, let's swap the current ADC */ 1595 /* stream is running, let's swap the current ADC */
1540 snd_hda_codec_setup_stream(codec, spec->cur_adc, 0, 0, 0); 1596 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
1541 spec->cur_adc = new_adc; 1597 spec->cur_adc = new_adc;
1542 snd_hda_codec_setup_stream(codec, new_adc, 1598 snd_hda_codec_setup_stream(codec, new_adc,
1543 spec->cur_adc_stream_tag, 0, 1599 spec->cur_adc_stream_tag, 0,
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 33282f9c01c7..cdda64b02f46 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -30,6 +30,7 @@
30#include <sound/core.h> 30#include <sound/core.h>
31#include "hda_codec.h" 31#include "hda_codec.h"
32#include "hda_local.h" 32#include "hda_local.h"
33#include "hda_patch.h"
33 34
34#define ALC880_FRONT_EVENT 0x01 35#define ALC880_FRONT_EVENT 0x01
35#define ALC880_DCVOL_EVENT 0x02 36#define ALC880_DCVOL_EVENT 0x02
@@ -97,16 +98,19 @@ enum {
97 ALC262_SONY_ASSAMD, 98 ALC262_SONY_ASSAMD,
98 ALC262_BENQ_T31, 99 ALC262_BENQ_T31,
99 ALC262_ULTRA, 100 ALC262_ULTRA,
101 ALC262_LENOVO_3000,
100 ALC262_AUTO, 102 ALC262_AUTO,
101 ALC262_MODEL_LAST /* last tag */ 103 ALC262_MODEL_LAST /* last tag */
102}; 104};
103 105
104/* ALC268 models */ 106/* ALC268 models */
105enum { 107enum {
108 ALC267_QUANTA_IL1,
106 ALC268_3ST, 109 ALC268_3ST,
107 ALC268_TOSHIBA, 110 ALC268_TOSHIBA,
108 ALC268_ACER, 111 ALC268_ACER,
109 ALC268_DELL, 112 ALC268_DELL,
113 ALC268_ZEPTO,
110#ifdef CONFIG_SND_DEBUG 114#ifdef CONFIG_SND_DEBUG
111 ALC268_TEST, 115 ALC268_TEST,
112#endif 116#endif
@@ -195,10 +199,11 @@ enum {
195 ALC883_LENOVO_NB0763, 199 ALC883_LENOVO_NB0763,
196 ALC888_LENOVO_MS7195_DIG, 200 ALC888_LENOVO_MS7195_DIG,
197 ALC883_HAIER_W66, 201 ALC883_HAIER_W66,
198 ALC888_6ST_HP,
199 ALC888_3ST_HP, 202 ALC888_3ST_HP,
200 ALC888_6ST_DELL, 203 ALC888_6ST_DELL,
201 ALC883_MITAC, 204 ALC883_MITAC,
205 ALC883_CLEVO_M720,
206 ALC883_FUJITSU_PI2515,
202 ALC883_AUTO, 207 ALC883_AUTO,
203 ALC883_MODEL_LAST, 208 ALC883_MODEL_LAST,
204}; 209};
@@ -237,6 +242,7 @@ struct alc_spec {
237 /* capture */ 242 /* capture */
238 unsigned int num_adc_nids; 243 unsigned int num_adc_nids;
239 hda_nid_t *adc_nids; 244 hda_nid_t *adc_nids;
245 hda_nid_t *capsrc_nids;
240 hda_nid_t dig_in_nid; /* digital-in NID; optional */ 246 hda_nid_t dig_in_nid; /* digital-in NID; optional */
241 247
242 /* capture source */ 248 /* capture source */
@@ -270,7 +276,6 @@ struct alc_spec {
270 276
271 /* for virtual master */ 277 /* for virtual master */
272 hda_nid_t vmaster_nid; 278 hda_nid_t vmaster_nid;
273 u32 vmaster_tlv[4];
274#ifdef CONFIG_SND_HDA_POWER_SAVE 279#ifdef CONFIG_SND_HDA_POWER_SAVE
275 struct hda_loopback_check loopback; 280 struct hda_loopback_check loopback;
276#endif 281#endif
@@ -290,6 +295,7 @@ struct alc_config_preset {
290 hda_nid_t hp_nid; /* optional */ 295 hda_nid_t hp_nid; /* optional */
291 unsigned int num_adc_nids; 296 unsigned int num_adc_nids;
292 hda_nid_t *adc_nids; 297 hda_nid_t *adc_nids;
298 hda_nid_t *capsrc_nids;
293 hda_nid_t dig_in_nid; 299 hda_nid_t dig_in_nid;
294 unsigned int num_channel_mode; 300 unsigned int num_channel_mode;
295 const struct hda_channel_mode *channel_mode; 301 const struct hda_channel_mode *channel_mode;
@@ -336,9 +342,10 @@ static int alc_mux_enum_put(struct snd_kcontrol *kcontrol,
336 struct alc_spec *spec = codec->spec; 342 struct alc_spec *spec = codec->spec;
337 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 343 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
338 unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx; 344 unsigned int mux_idx = adc_idx >= spec->num_mux_defs ? 0 : adc_idx;
345 hda_nid_t nid = spec->capsrc_nids ?
346 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
339 return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol, 347 return snd_hda_input_mux_put(codec, &spec->input_mux[mux_idx], ucontrol,
340 spec->adc_nids[adc_idx], 348 nid, &spec->cur_mux[adc_idx]);
341 &spec->cur_mux[adc_idx]);
342} 349}
343 350
344 351
@@ -707,6 +714,7 @@ static void setup_preset(struct alc_spec *spec,
707 714
708 spec->num_adc_nids = preset->num_adc_nids; 715 spec->num_adc_nids = preset->num_adc_nids;
709 spec->adc_nids = preset->adc_nids; 716 spec->adc_nids = preset->adc_nids;
717 spec->capsrc_nids = preset->capsrc_nids;
710 spec->dig_in_nid = preset->dig_in_nid; 718 spec->dig_in_nid = preset->dig_in_nid;
711 719
712 spec->unsol_event = preset->unsol_event; 720 spec->unsol_event = preset->unsol_event;
@@ -741,7 +749,6 @@ static struct hda_verb alc_gpio3_init_verbs[] = {
741static void alc_sku_automute(struct hda_codec *codec) 749static void alc_sku_automute(struct hda_codec *codec)
742{ 750{
743 struct alc_spec *spec = codec->spec; 751 struct alc_spec *spec = codec->spec;
744 unsigned int mute;
745 unsigned int present; 752 unsigned int present;
746 unsigned int hp_nid = spec->autocfg.hp_pins[0]; 753 unsigned int hp_nid = spec->autocfg.hp_pins[0];
747 unsigned int sp_nid = spec->autocfg.speaker_pins[0]; 754 unsigned int sp_nid = spec->autocfg.speaker_pins[0];
@@ -751,16 +758,8 @@ static void alc_sku_automute(struct hda_codec *codec)
751 present = snd_hda_codec_read(codec, hp_nid, 0, 758 present = snd_hda_codec_read(codec, hp_nid, 0,
752 AC_VERB_GET_PIN_SENSE, 0); 759 AC_VERB_GET_PIN_SENSE, 0);
753 spec->jack_present = (present & 0x80000000) != 0; 760 spec->jack_present = (present & 0x80000000) != 0;
754 if (spec->jack_present) { 761 snd_hda_codec_write(codec, sp_nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
755 /* mute internal speaker */ 762 spec->jack_present ? 0 : PIN_OUT);
756 snd_hda_codec_amp_stereo(codec, sp_nid, HDA_OUTPUT, 0,
757 HDA_AMP_MUTE, HDA_AMP_MUTE);
758 } else {
759 /* unmute internal speaker if necessary */
760 mute = snd_hda_codec_amp_read(codec, hp_nid, 0, HDA_OUTPUT, 0);
761 snd_hda_codec_amp_stereo(codec, sp_nid, HDA_OUTPUT, 0,
762 HDA_AMP_MUTE, mute);
763 }
764} 763}
765 764
766/* unsolicited event for HP jack sensing */ 765/* unsolicited event for HP jack sensing */
@@ -1319,11 +1318,19 @@ static struct snd_kcontrol_new alc880_f1734_mixer[] = {
1319 HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT), 1318 HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
1320 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 1319 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
1321 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 1320 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
1322 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 1321 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
1323 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 1322 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
1324 { } /* end */ 1323 { } /* end */
1325}; 1324};
1326 1325
1326static struct hda_input_mux alc880_f1734_capture_source = {
1327 .num_items = 2,
1328 .items = {
1329 { "Mic", 0x1 },
1330 { "CD", 0x4 },
1331 },
1332};
1333
1327 1334
1328/* 1335/*
1329 * ALC880 ASUS model 1336 * ALC880 ASUS model
@@ -1516,6 +1523,11 @@ static int alc_build_controls(struct hda_codec *codec)
1516 spec->multiout.dig_out_nid); 1523 spec->multiout.dig_out_nid);
1517 if (err < 0) 1524 if (err < 0)
1518 return err; 1525 return err;
1526 err = snd_hda_create_spdif_share_sw(codec,
1527 &spec->multiout);
1528 if (err < 0)
1529 return err;
1530 spec->multiout.share_spdif = 1;
1519 } 1531 }
1520 if (spec->dig_in_nid) { 1532 if (spec->dig_in_nid) {
1521 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); 1533 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
@@ -1525,10 +1537,11 @@ static int alc_build_controls(struct hda_codec *codec)
1525 1537
1526 /* if we have no master control, let's create it */ 1538 /* if we have no master control, let's create it */
1527 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 1539 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
1540 unsigned int vmaster_tlv[4];
1528 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid, 1541 snd_hda_set_vmaster_tlv(codec, spec->vmaster_nid,
1529 HDA_OUTPUT, spec->vmaster_tlv); 1542 HDA_OUTPUT, vmaster_tlv);
1530 err = snd_hda_add_vmaster(codec, "Master Playback Volume", 1543 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
1531 spec->vmaster_tlv, alc_slave_vols); 1544 vmaster_tlv, alc_slave_vols);
1532 if (err < 0) 1545 if (err < 0)
1533 return err; 1546 return err;
1534 } 1547 }
@@ -1882,7 +1895,7 @@ static void alc880_uniwill_p53_hp_automute(struct hda_codec *codec)
1882 present = snd_hda_codec_read(codec, 0x14, 0, 1895 present = snd_hda_codec_read(codec, 0x14, 0,
1883 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000; 1896 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
1884 bits = present ? HDA_AMP_MUTE : 0; 1897 bits = present ? HDA_AMP_MUTE : 0;
1885 snd_hda_codec_amp_stereo(codec, 0x15, HDA_INPUT, 0, HDA_AMP_MUTE, bits); 1898 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0, HDA_AMP_MUTE, bits);
1886} 1899}
1887 1900
1888static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec) 1901static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
@@ -1915,6 +1928,7 @@ static void alc880_uniwill_p53_unsol_event(struct hda_codec *codec,
1915 * HP = 0x14, speaker-out = 0x15, mic = 0x18 1928 * HP = 0x14, speaker-out = 0x15, mic = 0x18
1916 */ 1929 */
1917static struct hda_verb alc880_pin_f1734_init_verbs[] = { 1930static struct hda_verb alc880_pin_f1734_init_verbs[] = {
1931 {0x07, AC_VERB_SET_CONNECT_SEL, 0x01},
1918 {0x10, AC_VERB_SET_CONNECT_SEL, 0x02}, 1932 {0x10, AC_VERB_SET_CONNECT_SEL, 0x02},
1919 {0x11, AC_VERB_SET_CONNECT_SEL, 0x00}, 1933 {0x11, AC_VERB_SET_CONNECT_SEL, 0x00},
1920 {0x12, AC_VERB_SET_CONNECT_SEL, 0x01}, 1934 {0x12, AC_VERB_SET_CONNECT_SEL, 0x01},
@@ -1927,7 +1941,7 @@ static struct hda_verb alc880_pin_f1734_init_verbs[] = {
1927 1941
1928 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1942 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1929 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 1943 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1930 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80}, 1944 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
1931 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 1945 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
1932 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 1946 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1933 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1947 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
@@ -1935,6 +1949,9 @@ static struct hda_verb alc880_pin_f1734_init_verbs[] = {
1935 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 1949 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1936 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, 1950 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1937 1951
1952 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_HP_EVENT},
1953 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC880_DCVOL_EVENT},
1954
1938 { } 1955 { }
1939}; 1956};
1940 1957
@@ -2318,7 +2335,8 @@ static int alc880_playback_pcm_open(struct hda_pcm_stream *hinfo,
2318 struct snd_pcm_substream *substream) 2335 struct snd_pcm_substream *substream)
2319{ 2336{
2320 struct alc_spec *spec = codec->spec; 2337 struct alc_spec *spec = codec->spec;
2321 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream); 2338 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
2339 hinfo);
2322} 2340}
2323 2341
2324static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 2342static int alc880_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
@@ -2392,8 +2410,8 @@ static int alc880_alt_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
2392{ 2410{
2393 struct alc_spec *spec = codec->spec; 2411 struct alc_spec *spec = codec->spec;
2394 2412
2395 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number + 1], 2413 snd_hda_codec_cleanup_stream(codec,
2396 0, 0, 0); 2414 spec->adc_nids[substream->number + 1]);
2397 return 0; 2415 return 0;
2398} 2416}
2399 2417
@@ -2498,6 +2516,7 @@ static int alc_build_pcms(struct hda_codec *codec)
2498 codec->num_pcms = 2; 2516 codec->num_pcms = 2;
2499 info = spec->pcm_rec + 1; 2517 info = spec->pcm_rec + 1;
2500 info->name = spec->stream_name_digital; 2518 info->name = spec->stream_name_digital;
2519 info->pcm_type = HDA_PCM_TYPE_SPDIF;
2501 if (spec->multiout.dig_out_nid && 2520 if (spec->multiout.dig_out_nid &&
2502 spec->stream_digital_playback) { 2521 spec->stream_digital_playback) {
2503 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback); 2522 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = *(spec->stream_digital_playback);
@@ -2560,6 +2579,7 @@ static void alc_free(struct hda_codec *codec)
2560 kfree(spec->kctl_alloc); 2579 kfree(spec->kctl_alloc);
2561 } 2580 }
2562 kfree(spec); 2581 kfree(spec);
2582 codec->spec = NULL; /* to be sure */
2563} 2583}
2564 2584
2565/* 2585/*
@@ -3057,7 +3077,9 @@ static struct alc_config_preset alc880_presets[] = {
3057 .hp_nid = 0x02, 3077 .hp_nid = 0x02,
3058 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes), 3078 .num_channel_mode = ARRAY_SIZE(alc880_2_jack_modes),
3059 .channel_mode = alc880_2_jack_modes, 3079 .channel_mode = alc880_2_jack_modes,
3060 .input_mux = &alc880_capture_source, 3080 .input_mux = &alc880_f1734_capture_source,
3081 .unsol_event = alc880_uniwill_p53_unsol_event,
3082 .init_hook = alc880_uniwill_p53_hp_automute,
3061 }, 3083 },
3062 [ALC880_ASUS] = { 3084 [ALC880_ASUS] = {
3063 .mixers = { alc880_asus_mixer }, 3085 .mixers = { alc880_asus_mixer },
@@ -3467,15 +3489,21 @@ static int alc880_auto_create_analog_input_ctls(struct alc_spec *spec,
3467 return 0; 3489 return 0;
3468} 3490}
3469 3491
3470static void alc880_auto_set_output_and_unmute(struct hda_codec *codec, 3492static void alc_set_pin_output(struct hda_codec *codec, hda_nid_t nid,
3471 hda_nid_t nid, int pin_type, 3493 unsigned int pin_type)
3472 int dac_idx)
3473{ 3494{
3474 /* set as output */
3475 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, 3495 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
3476 pin_type); 3496 pin_type);
3497 /* unmute pin */
3477 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, 3498 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
3478 AMP_OUT_UNMUTE); 3499 AMP_OUT_UNMUTE);
3500}
3501
3502static void alc880_auto_set_output_and_unmute(struct hda_codec *codec,
3503 hda_nid_t nid, int pin_type,
3504 int dac_idx)
3505{
3506 alc_set_pin_output(codec, nid, pin_type);
3479 /* need the manual connection? */ 3507 /* need the manual connection? */
3480 if (alc880_is_multi_pin(nid)) { 3508 if (alc880_is_multi_pin(nid)) {
3481 struct alc_spec *spec = codec->spec; 3509 struct alc_spec *spec = codec->spec;
@@ -3597,9 +3625,12 @@ static int alc880_parse_auto_config(struct hda_codec *codec)
3597/* additional initialization for auto-configuration model */ 3625/* additional initialization for auto-configuration model */
3598static void alc880_auto_init(struct hda_codec *codec) 3626static void alc880_auto_init(struct hda_codec *codec)
3599{ 3627{
3628 struct alc_spec *spec = codec->spec;
3600 alc880_auto_init_multi_out(codec); 3629 alc880_auto_init_multi_out(codec);
3601 alc880_auto_init_extra_out(codec); 3630 alc880_auto_init_extra_out(codec);
3602 alc880_auto_init_analog_input(codec); 3631 alc880_auto_init_analog_input(codec);
3632 if (spec->unsol_event)
3633 alc_sku_automute(codec);
3603} 3634}
3604 3635
3605/* 3636/*
@@ -4795,11 +4826,7 @@ static void alc260_auto_set_output_and_unmute(struct hda_codec *codec,
4795 hda_nid_t nid, int pin_type, 4826 hda_nid_t nid, int pin_type,
4796 int sel_idx) 4827 int sel_idx)
4797{ 4828{
4798 /* set as output */ 4829 alc_set_pin_output(codec, nid, pin_type);
4799 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
4800 pin_type);
4801 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
4802 AMP_OUT_UNMUTE);
4803 /* need the manual connection? */ 4830 /* need the manual connection? */
4804 if (nid >= 0x12) { 4831 if (nid >= 0x12) {
4805 int idx = nid - 0x12; 4832 int idx = nid - 0x12;
@@ -4929,7 +4956,7 @@ static int alc260_parse_auto_config(struct hda_codec *codec)
4929 /* check whether NID 0x04 is valid */ 4956 /* check whether NID 0x04 is valid */
4930 wcap = get_wcaps(codec, 0x04); 4957 wcap = get_wcaps(codec, 0x04);
4931 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */ 4958 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; /* get type */
4932 if (wcap != AC_WID_AUD_IN) { 4959 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
4933 spec->adc_nids = alc260_adc_nids_alt; 4960 spec->adc_nids = alc260_adc_nids_alt;
4934 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt); 4961 spec->num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt);
4935 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer; 4962 spec->mixers[spec->num_mixers] = alc260_capture_alt_mixer;
@@ -4946,8 +4973,11 @@ static int alc260_parse_auto_config(struct hda_codec *codec)
4946/* additional initialization for auto-configuration model */ 4973/* additional initialization for auto-configuration model */
4947static void alc260_auto_init(struct hda_codec *codec) 4974static void alc260_auto_init(struct hda_codec *codec)
4948{ 4975{
4976 struct alc_spec *spec = codec->spec;
4949 alc260_auto_init_multi_out(codec); 4977 alc260_auto_init_multi_out(codec);
4950 alc260_auto_init_analog_input(codec); 4978 alc260_auto_init_analog_input(codec);
4979 if (spec->unsol_event)
4980 alc_sku_automute(codec);
4951} 4981}
4952 4982
4953#ifdef CONFIG_SND_HDA_POWER_SAVE 4983#ifdef CONFIG_SND_HDA_POWER_SAVE
@@ -5204,6 +5234,9 @@ static hda_nid_t alc882_dac_nids[4] = {
5204#define alc882_adc_nids alc880_adc_nids 5234#define alc882_adc_nids alc880_adc_nids
5205#define alc882_adc_nids_alt alc880_adc_nids_alt 5235#define alc882_adc_nids_alt alc880_adc_nids_alt
5206 5236
5237static hda_nid_t alc882_capsrc_nids[3] = { 0x24, 0x23, 0x22 };
5238static hda_nid_t alc882_capsrc_nids_alt[2] = { 0x23, 0x22 };
5239
5207/* input MUX */ 5240/* input MUX */
5208/* FIXME: should be a matrix-type input source selection */ 5241/* FIXME: should be a matrix-type input source selection */
5209 5242
@@ -5226,15 +5259,11 @@ static int alc882_mux_enum_put(struct snd_kcontrol *kcontrol,
5226 struct alc_spec *spec = codec->spec; 5259 struct alc_spec *spec = codec->spec;
5227 const struct hda_input_mux *imux = spec->input_mux; 5260 const struct hda_input_mux *imux = spec->input_mux;
5228 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id); 5261 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
5229 static hda_nid_t capture_mixers[3] = { 0x24, 0x23, 0x22 }; 5262 hda_nid_t nid = spec->capsrc_nids ?
5230 hda_nid_t nid; 5263 spec->capsrc_nids[adc_idx] : spec->adc_nids[adc_idx];
5231 unsigned int *cur_val = &spec->cur_mux[adc_idx]; 5264 unsigned int *cur_val = &spec->cur_mux[adc_idx];
5232 unsigned int i, idx; 5265 unsigned int i, idx;
5233 5266
5234 if (spec->num_adc_nids < 3)
5235 nid = capture_mixers[adc_idx + 1];
5236 else
5237 nid = capture_mixers[adc_idx];
5238 idx = ucontrol->value.enumerated.item[0]; 5267 idx = ucontrol->value.enumerated.item[0];
5239 if (idx >= imux->num_items) 5268 if (idx >= imux->num_items)
5240 idx = imux->num_items - 1; 5269 idx = imux->num_items - 1;
@@ -6111,6 +6140,7 @@ static struct alc_config_preset alc882_presets[] = {
6111 .dig_out_nid = ALC882_DIGOUT_NID, 6140 .dig_out_nid = ALC882_DIGOUT_NID,
6112 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids), 6141 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6113 .adc_nids = alc882_adc_nids, 6142 .adc_nids = alc882_adc_nids,
6143 .capsrc_nids = alc882_capsrc_nids,
6114 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes), 6144 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6115 .channel_mode = alc882_3ST_6ch_modes, 6145 .channel_mode = alc882_3ST_6ch_modes,
6116 .need_dac_fix = 1, 6146 .need_dac_fix = 1,
@@ -6127,6 +6157,7 @@ static struct alc_config_preset alc882_presets[] = {
6127 .dig_out_nid = ALC882_DIGOUT_NID, 6157 .dig_out_nid = ALC882_DIGOUT_NID,
6128 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids), 6158 .num_adc_nids = ARRAY_SIZE(alc882_adc_nids),
6129 .adc_nids = alc882_adc_nids, 6159 .adc_nids = alc882_adc_nids,
6160 .capsrc_nids = alc882_capsrc_nids,
6130 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes), 6161 .num_channel_mode = ARRAY_SIZE(alc882_3ST_6ch_modes),
6131 .channel_mode = alc882_3ST_6ch_modes, 6162 .channel_mode = alc882_3ST_6ch_modes,
6132 .need_dac_fix = 1, 6163 .need_dac_fix = 1,
@@ -6182,15 +6213,11 @@ static void alc882_auto_set_output_and_unmute(struct hda_codec *codec,
6182 struct alc_spec *spec = codec->spec; 6213 struct alc_spec *spec = codec->spec;
6183 int idx; 6214 int idx;
6184 6215
6216 alc_set_pin_output(codec, nid, pin_type);
6185 if (spec->multiout.dac_nids[dac_idx] == 0x25) 6217 if (spec->multiout.dac_nids[dac_idx] == 0x25)
6186 idx = 4; 6218 idx = 4;
6187 else 6219 else
6188 idx = spec->multiout.dac_nids[dac_idx] - 2; 6220 idx = spec->multiout.dac_nids[dac_idx] - 2;
6189
6190 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
6191 pin_type);
6192 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
6193 AMP_OUT_UNMUTE);
6194 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx); 6221 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
6195 6222
6196} 6223}
@@ -6219,6 +6246,9 @@ static void alc882_auto_init_hp_out(struct hda_codec *codec)
6219 if (pin) /* connect to front */ 6246 if (pin) /* connect to front */
6220 /* use dac 0 */ 6247 /* use dac 0 */
6221 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); 6248 alc882_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
6249 pin = spec->autocfg.speaker_pins[0];
6250 if (pin)
6251 alc882_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
6222} 6252}
6223 6253
6224#define alc882_is_input_pin(nid) alc880_is_input_pin(nid) 6254#define alc882_is_input_pin(nid) alc880_is_input_pin(nid)
@@ -6231,16 +6261,21 @@ static void alc882_auto_init_analog_input(struct hda_codec *codec)
6231 6261
6232 for (i = 0; i < AUTO_PIN_LAST; i++) { 6262 for (i = 0; i < AUTO_PIN_LAST; i++) {
6233 hda_nid_t nid = spec->autocfg.input_pins[i]; 6263 hda_nid_t nid = spec->autocfg.input_pins[i];
6234 if (alc882_is_input_pin(nid)) { 6264 unsigned int vref;
6235 snd_hda_codec_write(codec, nid, 0, 6265 if (!nid)
6236 AC_VERB_SET_PIN_WIDGET_CONTROL, 6266 continue;
6237 i <= AUTO_PIN_FRONT_MIC ? 6267 vref = PIN_IN;
6238 PIN_VREF80 : PIN_IN); 6268 if (1 /*i <= AUTO_PIN_FRONT_MIC*/) {
6239 if (nid != ALC882_PIN_CD_NID) 6269 if (snd_hda_param_read(codec, nid, AC_PAR_PIN_CAP) &
6240 snd_hda_codec_write(codec, nid, 0, 6270 AC_PINCAP_VREF_80)
6241 AC_VERB_SET_AMP_GAIN_MUTE, 6271 vref = PIN_VREF80;
6242 AMP_OUT_MUTE);
6243 } 6272 }
6273 snd_hda_codec_write(codec, nid, 0,
6274 AC_VERB_SET_PIN_WIDGET_CONTROL, vref);
6275 if (get_wcaps(codec, nid) & AC_WCAP_OUT_AMP)
6276 snd_hda_codec_write(codec, nid, 0,
6277 AC_VERB_SET_AMP_GAIN_MUTE,
6278 AMP_OUT_MUTE);
6244 } 6279 }
6245} 6280}
6246 6281
@@ -6294,11 +6329,16 @@ static int alc882_parse_auto_config(struct hda_codec *codec)
6294/* additional initialization for auto-configuration model */ 6329/* additional initialization for auto-configuration model */
6295static void alc882_auto_init(struct hda_codec *codec) 6330static void alc882_auto_init(struct hda_codec *codec)
6296{ 6331{
6332 struct alc_spec *spec = codec->spec;
6297 alc882_auto_init_multi_out(codec); 6333 alc882_auto_init_multi_out(codec);
6298 alc882_auto_init_hp_out(codec); 6334 alc882_auto_init_hp_out(codec);
6299 alc882_auto_init_analog_input(codec); 6335 alc882_auto_init_analog_input(codec);
6336 if (spec->unsol_event)
6337 alc_sku_automute(codec);
6300} 6338}
6301 6339
6340static int patch_alc883(struct hda_codec *codec); /* called in patch_alc882() */
6341
6302static int patch_alc882(struct hda_codec *codec) 6342static int patch_alc882(struct hda_codec *codec)
6303{ 6343{
6304 struct alc_spec *spec; 6344 struct alc_spec *spec;
@@ -6328,6 +6368,11 @@ static int patch_alc882(struct hda_codec *codec)
6328 board_config = ALC885_MBP3; 6368 board_config = ALC885_MBP3;
6329 break; 6369 break;
6330 default: 6370 default:
6371 /* ALC889A is handled better as ALC888-compatible */
6372 if (codec->revision_id == 0x100103) {
6373 alc_free(codec);
6374 return patch_alc883(codec);
6375 }
6331 printk(KERN_INFO "hda_codec: Unknown model for ALC882, " 6376 printk(KERN_INFO "hda_codec: Unknown model for ALC882, "
6332 "trying auto-probe from BIOS...\n"); 6377 "trying auto-probe from BIOS...\n");
6333 board_config = ALC882_AUTO; 6378 board_config = ALC882_AUTO;
@@ -6372,12 +6417,14 @@ static int patch_alc882(struct hda_codec *codec)
6372 if (wcap != AC_WID_AUD_IN) { 6417 if (wcap != AC_WID_AUD_IN) {
6373 spec->adc_nids = alc882_adc_nids_alt; 6418 spec->adc_nids = alc882_adc_nids_alt;
6374 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt); 6419 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids_alt);
6420 spec->capsrc_nids = alc882_capsrc_nids_alt;
6375 spec->mixers[spec->num_mixers] = 6421 spec->mixers[spec->num_mixers] =
6376 alc882_capture_alt_mixer; 6422 alc882_capture_alt_mixer;
6377 spec->num_mixers++; 6423 spec->num_mixers++;
6378 } else { 6424 } else {
6379 spec->adc_nids = alc882_adc_nids; 6425 spec->adc_nids = alc882_adc_nids;
6380 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids); 6426 spec->num_adc_nids = ARRAY_SIZE(alc882_adc_nids);
6427 spec->capsrc_nids = alc882_capsrc_nids;
6381 spec->mixers[spec->num_mixers] = alc882_capture_mixer; 6428 spec->mixers[spec->num_mixers] = alc882_capture_mixer;
6382 spec->num_mixers++; 6429 spec->num_mixers++;
6383 } 6430 }
@@ -6412,7 +6459,7 @@ static int patch_alc882(struct hda_codec *codec)
6412 6459
6413static hda_nid_t alc883_dac_nids[4] = { 6460static hda_nid_t alc883_dac_nids[4] = {
6414 /* front, rear, clfe, rear_surr */ 6461 /* front, rear, clfe, rear_surr */
6415 0x02, 0x04, 0x03, 0x05 6462 0x02, 0x03, 0x04, 0x05
6416}; 6463};
6417 6464
6418static hda_nid_t alc883_adc_nids[2] = { 6465static hda_nid_t alc883_adc_nids[2] = {
@@ -6420,6 +6467,8 @@ static hda_nid_t alc883_adc_nids[2] = {
6420 0x08, 0x09, 6467 0x08, 0x09,
6421}; 6468};
6422 6469
6470static hda_nid_t alc883_capsrc_nids[2] = { 0x23, 0x22 };
6471
6423/* input MUX */ 6472/* input MUX */
6424/* FIXME: should be a matrix-type input source selection */ 6473/* FIXME: should be a matrix-type input source selection */
6425 6474
@@ -6451,35 +6500,18 @@ static struct hda_input_mux alc883_lenovo_nb0763_capture_source = {
6451 }, 6500 },
6452}; 6501};
6453 6502
6503static struct hda_input_mux alc883_fujitsu_pi2515_capture_source = {
6504 .num_items = 2,
6505 .items = {
6506 { "Mic", 0x0 },
6507 { "Int Mic", 0x1 },
6508 },
6509};
6510
6454#define alc883_mux_enum_info alc_mux_enum_info 6511#define alc883_mux_enum_info alc_mux_enum_info
6455#define alc883_mux_enum_get alc_mux_enum_get 6512#define alc883_mux_enum_get alc_mux_enum_get
6456 6513/* ALC883 has the ALC882-type input selection */
6457static int alc883_mux_enum_put(struct snd_kcontrol *kcontrol, 6514#define alc883_mux_enum_put alc882_mux_enum_put
6458 struct snd_ctl_elem_value *ucontrol)
6459{
6460 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
6461 struct alc_spec *spec = codec->spec;
6462 const struct hda_input_mux *imux = spec->input_mux;
6463 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
6464 static hda_nid_t capture_mixers[2] = { 0x23, 0x22 };
6465 hda_nid_t nid = capture_mixers[adc_idx];
6466 unsigned int *cur_val = &spec->cur_mux[adc_idx];
6467 unsigned int i, idx;
6468
6469 idx = ucontrol->value.enumerated.item[0];
6470 if (idx >= imux->num_items)
6471 idx = imux->num_items - 1;
6472 if (*cur_val == idx)
6473 return 0;
6474 for (i = 0; i < imux->num_items; i++) {
6475 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
6476 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
6477 imux->items[i].index,
6478 HDA_AMP_MUTE, v);
6479 }
6480 *cur_val = idx;
6481 return 1;
6482}
6483 6515
6484/* 6516/*
6485 * 2ch mode 6517 * 2ch mode
@@ -6638,6 +6670,60 @@ static struct snd_kcontrol_new alc883_mitac_mixer[] = {
6638 { } /* end */ 6670 { } /* end */
6639}; 6671};
6640 6672
6673static struct snd_kcontrol_new alc883_clevo_m720_mixer[] = {
6674 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6675 HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
6676 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6677 HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
6678 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6679 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6680 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6681 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6682 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
6683 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6684 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6685 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6686 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6687 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6688 {
6689 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6690 /* .name = "Capture Source", */
6691 .name = "Input Source",
6692 .count = 2,
6693 .info = alc883_mux_enum_info,
6694 .get = alc883_mux_enum_get,
6695 .put = alc883_mux_enum_put,
6696 },
6697 { } /* end */
6698};
6699
6700static struct snd_kcontrol_new alc883_2ch_fujitsu_pi2515_mixer[] = {
6701 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6702 HDA_BIND_MUTE("Headphone Playback Switch", 0x0c, 2, HDA_INPUT),
6703 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
6704 HDA_BIND_MUTE("Speaker Playback Switch", 0x0d, 2, HDA_INPUT),
6705 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6706 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6707 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6708 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6709 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
6710 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6711 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6712 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6713 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6714 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6715 {
6716 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6717 /* .name = "Capture Source", */
6718 .name = "Input Source",
6719 .count = 2,
6720 .info = alc883_mux_enum_info,
6721 .get = alc883_mux_enum_get,
6722 .put = alc883_mux_enum_put,
6723 },
6724 { } /* end */
6725};
6726
6641static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = { 6727static struct snd_kcontrol_new alc883_3ST_2ch_mixer[] = {
6642 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 6728 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6643 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 6729 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
@@ -6787,6 +6873,9 @@ static struct snd_kcontrol_new alc883_tagra_2ch_mixer[] = {
6787 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 6873 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6788 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 6874 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6789 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 6875 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6876 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6877 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
6878 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6790 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT), 6879 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6791 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT), 6880 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6792 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT), 6881 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
@@ -6878,124 +6967,6 @@ static struct snd_kcontrol_new alc883_medion_md2_mixer[] = {
6878 { } /* end */ 6967 { } /* end */
6879}; 6968};
6880 6969
6881static struct snd_kcontrol_new alc888_6st_hp_mixer[] = {
6882 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6883 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6884 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
6885 HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
6886 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
6887 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
6888 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
6889 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
6890 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6891 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6892 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6893 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6894 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6895 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6896 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6897 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6898 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6899 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6900 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6901 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6902 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6903 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6904 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6905 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6906 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6907 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6908 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6909 {
6910 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6911 /* .name = "Capture Source", */
6912 .name = "Input Source",
6913 .count = 2,
6914 .info = alc883_mux_enum_info,
6915 .get = alc883_mux_enum_get,
6916 .put = alc883_mux_enum_put,
6917 },
6918 { } /* end */
6919};
6920
6921static struct snd_kcontrol_new alc888_3st_hp_mixer[] = {
6922 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6923 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6924 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
6925 HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
6926 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
6927 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
6928 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
6929 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
6930 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6931 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6932 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6933 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6934 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6935 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6936 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6937 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6938 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6939 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6940 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6941 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6942 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6943 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6944 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6945 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6946 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6947 {
6948 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6949 /* .name = "Capture Source", */
6950 .name = "Input Source",
6951 .count = 2,
6952 .info = alc883_mux_enum_info,
6953 .get = alc883_mux_enum_get,
6954 .put = alc883_mux_enum_put,
6955 },
6956 { } /* end */
6957};
6958
6959static struct snd_kcontrol_new alc888_6st_dell_mixer[] = {
6960 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
6961 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
6962 HDA_CODEC_VOLUME("Surround Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
6963 HDA_BIND_MUTE("Surround Playback Switch", 0x0e, 2, HDA_INPUT),
6964 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x0d, 1, 0x0, HDA_OUTPUT),
6965 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x0d, 2, 0x0, HDA_OUTPUT),
6966 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0d, 1, 2, HDA_INPUT),
6967 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0d, 2, 2, HDA_INPUT),
6968 HDA_CODEC_VOLUME("Side Playback Volume", 0x0f, 0x0, HDA_OUTPUT),
6969 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
6970 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
6971 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
6972 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
6973 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
6974 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
6975 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
6976 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
6977 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
6978 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
6979 HDA_CODEC_VOLUME("Front Mic Boost", 0x19, 0, HDA_INPUT),
6980 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
6981 HDA_CODEC_VOLUME("PC Speaker Playback Volume", 0x0b, 0x05, HDA_INPUT),
6982 HDA_CODEC_MUTE("PC Speaker Playback Switch", 0x0b, 0x05, HDA_INPUT),
6983 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
6984 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
6985 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x09, 0x0, HDA_INPUT),
6986 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x09, 0x0, HDA_INPUT),
6987 {
6988 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
6989 /* .name = "Capture Source", */
6990 .name = "Input Source",
6991 .count = 2,
6992 .info = alc883_mux_enum_info,
6993 .get = alc883_mux_enum_get,
6994 .put = alc883_mux_enum_put,
6995 },
6996 { } /* end */
6997};
6998
6999static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = { 6970static struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
7000 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 6971 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
7001 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 6972 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
@@ -7171,6 +7142,35 @@ static struct hda_verb alc883_mitac_verbs[] = {
7171 { } /* end */ 7142 { } /* end */
7172}; 7143};
7173 7144
7145static struct hda_verb alc883_clevo_m720_verbs[] = {
7146 /* HP */
7147 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
7148 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7149 /* Int speaker */
7150 {0x14, AC_VERB_SET_CONNECT_SEL, 0x01},
7151 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7152
7153 /* enable unsolicited event */
7154 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7155 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
7156
7157 { } /* end */
7158};
7159
7160static struct hda_verb alc883_2ch_fujitsu_pi2515_verbs[] = {
7161 /* HP */
7162 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
7163 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
7164 /* Subwoofer */
7165 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
7166 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
7167
7168 /* enable unsolicited event */
7169 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7170
7171 { } /* end */
7172};
7173
7174static struct hda_verb alc883_tagra_verbs[] = { 7174static struct hda_verb alc883_tagra_verbs[] = {
7175 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, 7175 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
7176 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)}, 7176 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
@@ -7227,26 +7227,14 @@ static struct hda_verb alc883_haier_w66_verbs[] = {
7227 { } /* end */ 7227 { } /* end */
7228}; 7228};
7229 7229
7230static struct hda_verb alc888_6st_hp_verbs[] = {
7231 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front: output 0 (0x0c) */
7232 {0x15, AC_VERB_SET_CONNECT_SEL, 0x02}, /* Rear : output 2 (0x0e) */
7233 {0x16, AC_VERB_SET_CONNECT_SEL, 0x01}, /* CLFE : output 1 (0x0d) */
7234 {0x17, AC_VERB_SET_CONNECT_SEL, 0x03}, /* Side : output 3 (0x0f) */
7235 { }
7236};
7237
7238static struct hda_verb alc888_3st_hp_verbs[] = { 7230static struct hda_verb alc888_3st_hp_verbs[] = {
7239 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front: output 0 (0x0c) */ 7231 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front: output 0 (0x0c) */
7240 {0x18, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Rear : output 1 (0x0d) */ 7232 {0x16, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Rear : output 1 (0x0d) */
7241 {0x16, AC_VERB_SET_CONNECT_SEL, 0x02}, /* CLFE : output 2 (0x0e) */ 7233 {0x18, AC_VERB_SET_CONNECT_SEL, 0x02}, /* CLFE : output 2 (0x0e) */
7242 { } 7234 { }
7243}; 7235};
7244 7236
7245static struct hda_verb alc888_6st_dell_verbs[] = { 7237static struct hda_verb alc888_6st_dell_verbs[] = {
7246 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Front: output 0 (0x0c) */
7247 {0x15, AC_VERB_SET_CONNECT_SEL, 0x02}, /* Rear : output 1 (0x0e) */
7248 {0x16, AC_VERB_SET_CONNECT_SEL, 0x01}, /* CLFE : output 2 (0x0d) */
7249 {0x17, AC_VERB_SET_CONNECT_SEL, 0x03}, /* Side : output 3 (0x0f) */
7250 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN}, 7238 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
7251 { } 7239 { }
7252}; 7240};
@@ -7354,6 +7342,68 @@ static void alc883_tagra_unsol_event(struct hda_codec *codec, unsigned int res)
7354 alc883_tagra_automute(codec); 7342 alc883_tagra_automute(codec);
7355} 7343}
7356 7344
7345/* toggle speaker-output according to the hp-jack state */
7346static void alc883_clevo_m720_hp_automute(struct hda_codec *codec)
7347{
7348 unsigned int present;
7349 unsigned char bits;
7350
7351 present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
7352 & AC_PINSENSE_PRESENCE;
7353 bits = present ? HDA_AMP_MUTE : 0;
7354 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
7355 HDA_AMP_MUTE, bits);
7356}
7357
7358static void alc883_clevo_m720_mic_automute(struct hda_codec *codec)
7359{
7360 unsigned int present;
7361
7362 present = snd_hda_codec_read(codec, 0x18, 0,
7363 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
7364 snd_hda_codec_amp_stereo(codec, 0x0b, HDA_INPUT, 1,
7365 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
7366}
7367
7368static void alc883_clevo_m720_automute(struct hda_codec *codec)
7369{
7370 alc883_clevo_m720_hp_automute(codec);
7371 alc883_clevo_m720_mic_automute(codec);
7372}
7373
7374static void alc883_clevo_m720_unsol_event(struct hda_codec *codec,
7375 unsigned int res)
7376{
7377 switch (res >> 26) {
7378 case ALC880_HP_EVENT:
7379 alc883_clevo_m720_hp_automute(codec);
7380 break;
7381 case ALC880_MIC_EVENT:
7382 alc883_clevo_m720_mic_automute(codec);
7383 break;
7384 }
7385}
7386
7387/* toggle speaker-output according to the hp-jack state */
7388static void alc883_2ch_fujitsu_pi2515_automute(struct hda_codec *codec)
7389{
7390 unsigned int present;
7391 unsigned char bits;
7392
7393 present = snd_hda_codec_read(codec, 0x14, 0, AC_VERB_GET_PIN_SENSE, 0)
7394 & AC_PINSENSE_PRESENCE;
7395 bits = present ? HDA_AMP_MUTE : 0;
7396 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
7397 HDA_AMP_MUTE, bits);
7398}
7399
7400static void alc883_2ch_fujitsu_pi2515_unsol_event(struct hda_codec *codec,
7401 unsigned int res)
7402{
7403 if ((res >> 26) == ALC880_HP_EVENT)
7404 alc883_2ch_fujitsu_pi2515_automute(codec);
7405}
7406
7357static void alc883_haier_w66_automute(struct hda_codec *codec) 7407static void alc883_haier_w66_automute(struct hda_codec *codec)
7358{ 7408{
7359 unsigned int present; 7409 unsigned int present;
@@ -7587,10 +7637,11 @@ static const char *alc883_models[ALC883_MODEL_LAST] = {
7587 [ALC883_LENOVO_NB0763] = "lenovo-nb0763", 7637 [ALC883_LENOVO_NB0763] = "lenovo-nb0763",
7588 [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig", 7638 [ALC888_LENOVO_MS7195_DIG] = "lenovo-ms7195-dig",
7589 [ALC883_HAIER_W66] = "haier-w66", 7639 [ALC883_HAIER_W66] = "haier-w66",
7590 [ALC888_6ST_HP] = "6stack-hp",
7591 [ALC888_3ST_HP] = "3stack-hp", 7640 [ALC888_3ST_HP] = "3stack-hp",
7592 [ALC888_6ST_DELL] = "6stack-dell", 7641 [ALC888_6ST_DELL] = "6stack-dell",
7593 [ALC883_MITAC] = "mitac", 7642 [ALC883_MITAC] = "mitac",
7643 [ALC883_CLEVO_M720] = "clevo-m720",
7644 [ALC883_FUJITSU_PI2515] = "fujitsu-pi2515",
7594 [ALC883_AUTO] = "auto", 7645 [ALC883_AUTO] = "auto",
7595}; 7646};
7596 7647
@@ -7604,7 +7655,7 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
7604 SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG), 7655 SND_PCI_QUIRK(0x103c, 0x2a3d, "HP Pavillion", ALC883_6ST_DIG),
7605 SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP), 7656 SND_PCI_QUIRK(0x103c, 0x2a4f, "HP Samba", ALC888_3ST_HP),
7606 SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP), 7657 SND_PCI_QUIRK(0x103c, 0x2a60, "HP Lucknow", ALC888_3ST_HP),
7607 SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC888_6ST_HP), 7658 SND_PCI_QUIRK(0x103c, 0x2a61, "HP Nettle", ALC883_6ST_DIG),
7608 SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG), 7659 SND_PCI_QUIRK(0x1043, 0x8249, "Asus M2A-VM HDMI", ALC883_3ST_6ch_DIG),
7609 SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG), 7660 SND_PCI_QUIRK(0x105b, 0x6668, "Foxconn", ALC883_6ST_DIG),
7610 SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC), 7661 SND_PCI_QUIRK(0x1071, 0x8253, "Mitac 8252d", ALC883_MITAC),
@@ -7614,7 +7665,9 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
7614 SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG), 7665 SND_PCI_QUIRK(0x1462, 0x0349, "MSI", ALC883_TARGA_2ch_DIG),
7615 SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG), 7666 SND_PCI_QUIRK(0x1462, 0x040d, "MSI", ALC883_TARGA_2ch_DIG),
7616 SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG), 7667 SND_PCI_QUIRK(0x1462, 0x0579, "MSI", ALC883_TARGA_2ch_DIG),
7668 SND_PCI_QUIRK(0x1462, 0x2fb3, "MSI", ALC883_TARGA_2ch_DIG),
7617 SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG), 7669 SND_PCI_QUIRK(0x1462, 0x3729, "MSI S420", ALC883_TARGA_DIG),
7670 SND_PCI_QUIRK(0x1462, 0x3783, "NEC S970", ALC883_TARGA_DIG),
7618 SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG), 7671 SND_PCI_QUIRK(0x1462, 0x3b7f, "MSI", ALC883_TARGA_2ch_DIG),
7619 SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG), 7672 SND_PCI_QUIRK(0x1462, 0x3ef9, "MSI", ALC883_TARGA_DIG),
7620 SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG), 7673 SND_PCI_QUIRK(0x1462, 0x3fc1, "MSI", ALC883_TARGA_DIG),
@@ -7627,13 +7680,17 @@ static struct snd_pci_quirk alc883_cfg_tbl[] = {
7627 SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG), 7680 SND_PCI_QUIRK(0x1462, 0x6668, "MSI", ALC883_6ST_DIG),
7628 SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG), 7681 SND_PCI_QUIRK(0x1462, 0x7187, "MSI", ALC883_6ST_DIG),
7629 SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG), 7682 SND_PCI_QUIRK(0x1462, 0x7250, "MSI", ALC883_6ST_DIG),
7683 SND_PCI_QUIRK(0x1462, 0x7267, "MSI", ALC883_3ST_6ch_DIG),
7630 SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG), 7684 SND_PCI_QUIRK(0x1462, 0x7280, "MSI", ALC883_6ST_DIG),
7631 SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG), 7685 SND_PCI_QUIRK(0x1462, 0x7327, "MSI", ALC883_6ST_DIG),
7632 SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG), 7686 SND_PCI_QUIRK(0x1462, 0xa422, "MSI", ALC883_TARGA_2ch_DIG),
7633 SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG), 7687 SND_PCI_QUIRK(0x147b, 0x1083, "Abit IP35-PRO", ALC883_6ST_DIG),
7688 SND_PCI_QUIRK(0x1558, 0x0721, "Clevo laptop M720R", ALC883_CLEVO_M720),
7689 SND_PCI_QUIRK(0x1558, 0x0722, "Clevo laptop M720SR", ALC883_CLEVO_M720),
7634 SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD), 7690 SND_PCI_QUIRK(0x1558, 0, "Clevo laptop", ALC883_LAPTOP_EAPD),
7635 SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch), 7691 SND_PCI_QUIRK(0x15d9, 0x8780, "Supermicro PDSBA", ALC883_3ST_6ch),
7636 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION), 7692 SND_PCI_QUIRK(0x161f, 0x2054, "Medion laptop", ALC883_MEDION),
7693 SND_PCI_QUIRK(0x1734, 0x1108, "Fujitsu AMILO Pi2515", ALC883_FUJITSU_PI2515),
7637 SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch), 7694 SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo 101e", ALC883_LENOVO_101E_2ch),
7638 SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763), 7695 SND_PCI_QUIRK(0x17aa, 0x2085, "Lenovo NB0763", ALC883_LENOVO_NB0763),
7639 SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763), 7696 SND_PCI_QUIRK(0x17aa, 0x3bfc, "Lenovo NB0763", ALC883_LENOVO_NB0763),
@@ -7652,8 +7709,6 @@ static struct alc_config_preset alc883_presets[] = {
7652 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7709 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7653 .dac_nids = alc883_dac_nids, 7710 .dac_nids = alc883_dac_nids,
7654 .dig_out_nid = ALC883_DIGOUT_NID, 7711 .dig_out_nid = ALC883_DIGOUT_NID,
7655 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7656 .adc_nids = alc883_adc_nids,
7657 .dig_in_nid = ALC883_DIGIN_NID, 7712 .dig_in_nid = ALC883_DIGIN_NID,
7658 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7713 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7659 .channel_mode = alc883_3ST_2ch_modes, 7714 .channel_mode = alc883_3ST_2ch_modes,
@@ -7665,8 +7720,6 @@ static struct alc_config_preset alc883_presets[] = {
7665 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7720 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7666 .dac_nids = alc883_dac_nids, 7721 .dac_nids = alc883_dac_nids,
7667 .dig_out_nid = ALC883_DIGOUT_NID, 7722 .dig_out_nid = ALC883_DIGOUT_NID,
7668 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7669 .adc_nids = alc883_adc_nids,
7670 .dig_in_nid = ALC883_DIGIN_NID, 7723 .dig_in_nid = ALC883_DIGIN_NID,
7671 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes), 7724 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7672 .channel_mode = alc883_3ST_6ch_modes, 7725 .channel_mode = alc883_3ST_6ch_modes,
@@ -7678,8 +7731,6 @@ static struct alc_config_preset alc883_presets[] = {
7678 .init_verbs = { alc883_init_verbs }, 7731 .init_verbs = { alc883_init_verbs },
7679 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7732 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7680 .dac_nids = alc883_dac_nids, 7733 .dac_nids = alc883_dac_nids,
7681 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7682 .adc_nids = alc883_adc_nids,
7683 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes), 7734 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7684 .channel_mode = alc883_3ST_6ch_modes, 7735 .channel_mode = alc883_3ST_6ch_modes,
7685 .need_dac_fix = 1, 7736 .need_dac_fix = 1,
@@ -7691,8 +7742,6 @@ static struct alc_config_preset alc883_presets[] = {
7691 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7742 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7692 .dac_nids = alc883_dac_nids, 7743 .dac_nids = alc883_dac_nids,
7693 .dig_out_nid = ALC883_DIGOUT_NID, 7744 .dig_out_nid = ALC883_DIGOUT_NID,
7694 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7695 .adc_nids = alc883_adc_nids,
7696 .dig_in_nid = ALC883_DIGIN_NID, 7745 .dig_in_nid = ALC883_DIGIN_NID,
7697 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes), 7746 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7698 .channel_mode = alc883_sixstack_modes, 7747 .channel_mode = alc883_sixstack_modes,
@@ -7704,8 +7753,6 @@ static struct alc_config_preset alc883_presets[] = {
7704 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7753 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7705 .dac_nids = alc883_dac_nids, 7754 .dac_nids = alc883_dac_nids,
7706 .dig_out_nid = ALC883_DIGOUT_NID, 7755 .dig_out_nid = ALC883_DIGOUT_NID,
7707 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7708 .adc_nids = alc883_adc_nids,
7709 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes), 7756 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7710 .channel_mode = alc883_3ST_6ch_modes, 7757 .channel_mode = alc883_3ST_6ch_modes,
7711 .need_dac_fix = 1, 7758 .need_dac_fix = 1,
@@ -7719,8 +7766,6 @@ static struct alc_config_preset alc883_presets[] = {
7719 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7766 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7720 .dac_nids = alc883_dac_nids, 7767 .dac_nids = alc883_dac_nids,
7721 .dig_out_nid = ALC883_DIGOUT_NID, 7768 .dig_out_nid = ALC883_DIGOUT_NID,
7722 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7723 .adc_nids = alc883_adc_nids,
7724 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7769 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7725 .channel_mode = alc883_3ST_2ch_modes, 7770 .channel_mode = alc883_3ST_2ch_modes,
7726 .input_mux = &alc883_capture_source, 7771 .input_mux = &alc883_capture_source,
@@ -7737,8 +7782,6 @@ static struct alc_config_preset alc883_presets[] = {
7737 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs }, 7782 .init_verbs = { alc883_init_verbs, alc880_gpio1_init_verbs },
7738 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7783 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7739 .dac_nids = alc883_dac_nids, 7784 .dac_nids = alc883_dac_nids,
7740 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7741 .adc_nids = alc883_adc_nids,
7742 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7785 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7743 .channel_mode = alc883_3ST_2ch_modes, 7786 .channel_mode = alc883_3ST_2ch_modes,
7744 .input_mux = &alc883_capture_source, 7787 .input_mux = &alc883_capture_source,
@@ -7749,8 +7792,6 @@ static struct alc_config_preset alc883_presets[] = {
7749 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7792 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7750 .dac_nids = alc883_dac_nids, 7793 .dac_nids = alc883_dac_nids,
7751 .dig_out_nid = ALC883_DIGOUT_NID, 7794 .dig_out_nid = ALC883_DIGOUT_NID,
7752 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7753 .adc_nids = alc883_adc_nids,
7754 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7795 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7755 .channel_mode = alc883_3ST_2ch_modes, 7796 .channel_mode = alc883_3ST_2ch_modes,
7756 .input_mux = &alc883_capture_source, 7797 .input_mux = &alc883_capture_source,
@@ -7764,8 +7805,6 @@ static struct alc_config_preset alc883_presets[] = {
7764 alc883_medion_eapd_verbs }, 7805 alc883_medion_eapd_verbs },
7765 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7806 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7766 .dac_nids = alc883_dac_nids, 7807 .dac_nids = alc883_dac_nids,
7767 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7768 .adc_nids = alc883_adc_nids,
7769 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes), 7808 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7770 .channel_mode = alc883_sixstack_modes, 7809 .channel_mode = alc883_sixstack_modes,
7771 .input_mux = &alc883_capture_source, 7810 .input_mux = &alc883_capture_source,
@@ -7776,8 +7815,6 @@ static struct alc_config_preset alc883_presets[] = {
7776 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7815 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7777 .dac_nids = alc883_dac_nids, 7816 .dac_nids = alc883_dac_nids,
7778 .dig_out_nid = ALC883_DIGOUT_NID, 7817 .dig_out_nid = ALC883_DIGOUT_NID,
7779 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7780 .adc_nids = alc883_adc_nids,
7781 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7818 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7782 .channel_mode = alc883_3ST_2ch_modes, 7819 .channel_mode = alc883_3ST_2ch_modes,
7783 .input_mux = &alc883_capture_source, 7820 .input_mux = &alc883_capture_source,
@@ -7789,19 +7826,27 @@ static struct alc_config_preset alc883_presets[] = {
7789 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs }, 7826 .init_verbs = { alc883_init_verbs, alc882_eapd_verbs },
7790 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7827 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7791 .dac_nids = alc883_dac_nids, 7828 .dac_nids = alc883_dac_nids,
7792 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7793 .adc_nids = alc883_adc_nids,
7794 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7829 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7795 .channel_mode = alc883_3ST_2ch_modes, 7830 .channel_mode = alc883_3ST_2ch_modes,
7796 .input_mux = &alc883_capture_source, 7831 .input_mux = &alc883_capture_source,
7797 }, 7832 },
7833 [ALC883_CLEVO_M720] = {
7834 .mixers = { alc883_clevo_m720_mixer },
7835 .init_verbs = { alc883_init_verbs, alc883_clevo_m720_verbs },
7836 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7837 .dac_nids = alc883_dac_nids,
7838 .dig_out_nid = ALC883_DIGOUT_NID,
7839 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7840 .channel_mode = alc883_3ST_2ch_modes,
7841 .input_mux = &alc883_capture_source,
7842 .unsol_event = alc883_clevo_m720_unsol_event,
7843 .init_hook = alc883_clevo_m720_automute,
7844 },
7798 [ALC883_LENOVO_101E_2ch] = { 7845 [ALC883_LENOVO_101E_2ch] = {
7799 .mixers = { alc883_lenovo_101e_2ch_mixer}, 7846 .mixers = { alc883_lenovo_101e_2ch_mixer},
7800 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs}, 7847 .init_verbs = { alc883_init_verbs, alc883_lenovo_101e_verbs},
7801 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7848 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7802 .dac_nids = alc883_dac_nids, 7849 .dac_nids = alc883_dac_nids,
7803 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7804 .adc_nids = alc883_adc_nids,
7805 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7850 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7806 .channel_mode = alc883_3ST_2ch_modes, 7851 .channel_mode = alc883_3ST_2ch_modes,
7807 .input_mux = &alc883_lenovo_101e_capture_source, 7852 .input_mux = &alc883_lenovo_101e_capture_source,
@@ -7813,8 +7858,6 @@ static struct alc_config_preset alc883_presets[] = {
7813 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs}, 7858 .init_verbs = { alc883_init_verbs, alc883_lenovo_nb0763_verbs},
7814 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7859 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7815 .dac_nids = alc883_dac_nids, 7860 .dac_nids = alc883_dac_nids,
7816 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7817 .adc_nids = alc883_adc_nids,
7818 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7861 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7819 .channel_mode = alc883_3ST_2ch_modes, 7862 .channel_mode = alc883_3ST_2ch_modes,
7820 .need_dac_fix = 1, 7863 .need_dac_fix = 1,
@@ -7828,8 +7871,6 @@ static struct alc_config_preset alc883_presets[] = {
7828 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7871 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7829 .dac_nids = alc883_dac_nids, 7872 .dac_nids = alc883_dac_nids,
7830 .dig_out_nid = ALC883_DIGOUT_NID, 7873 .dig_out_nid = ALC883_DIGOUT_NID,
7831 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7832 .adc_nids = alc883_adc_nids,
7833 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes), 7874 .num_channel_mode = ARRAY_SIZE(alc883_3ST_6ch_modes),
7834 .channel_mode = alc883_3ST_6ch_modes, 7875 .channel_mode = alc883_3ST_6ch_modes,
7835 .need_dac_fix = 1, 7876 .need_dac_fix = 1,
@@ -7843,47 +7884,28 @@ static struct alc_config_preset alc883_presets[] = {
7843 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7884 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7844 .dac_nids = alc883_dac_nids, 7885 .dac_nids = alc883_dac_nids,
7845 .dig_out_nid = ALC883_DIGOUT_NID, 7886 .dig_out_nid = ALC883_DIGOUT_NID,
7846 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7847 .adc_nids = alc883_adc_nids,
7848 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7887 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7849 .channel_mode = alc883_3ST_2ch_modes, 7888 .channel_mode = alc883_3ST_2ch_modes,
7850 .input_mux = &alc883_capture_source, 7889 .input_mux = &alc883_capture_source,
7851 .unsol_event = alc883_haier_w66_unsol_event, 7890 .unsol_event = alc883_haier_w66_unsol_event,
7852 .init_hook = alc883_haier_w66_automute, 7891 .init_hook = alc883_haier_w66_automute,
7853 },
7854 [ALC888_6ST_HP] = {
7855 .mixers = { alc888_6st_hp_mixer, alc883_chmode_mixer },
7856 .init_verbs = { alc883_init_verbs, alc888_6st_hp_verbs },
7857 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7858 .dac_nids = alc883_dac_nids,
7859 .dig_out_nid = ALC883_DIGOUT_NID,
7860 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7861 .adc_nids = alc883_adc_nids,
7862 .dig_in_nid = ALC883_DIGIN_NID,
7863 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7864 .channel_mode = alc883_sixstack_modes,
7865 .input_mux = &alc883_capture_source,
7866 }, 7892 },
7867 [ALC888_3ST_HP] = { 7893 [ALC888_3ST_HP] = {
7868 .mixers = { alc888_3st_hp_mixer, alc883_chmode_mixer }, 7894 .mixers = { alc883_3ST_6ch_mixer, alc883_chmode_mixer },
7869 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs }, 7895 .init_verbs = { alc883_init_verbs, alc888_3st_hp_verbs },
7870 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7896 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7871 .dac_nids = alc883_dac_nids, 7897 .dac_nids = alc883_dac_nids,
7872 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7873 .adc_nids = alc883_adc_nids,
7874 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes), 7898 .num_channel_mode = ARRAY_SIZE(alc888_3st_hp_modes),
7875 .channel_mode = alc888_3st_hp_modes, 7899 .channel_mode = alc888_3st_hp_modes,
7876 .need_dac_fix = 1, 7900 .need_dac_fix = 1,
7877 .input_mux = &alc883_capture_source, 7901 .input_mux = &alc883_capture_source,
7878 }, 7902 },
7879 [ALC888_6ST_DELL] = { 7903 [ALC888_6ST_DELL] = {
7880 .mixers = { alc888_6st_dell_mixer, alc883_chmode_mixer }, 7904 .mixers = { alc883_base_mixer, alc883_chmode_mixer },
7881 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs }, 7905 .init_verbs = { alc883_init_verbs, alc888_6st_dell_verbs },
7882 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7906 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7883 .dac_nids = alc883_dac_nids, 7907 .dac_nids = alc883_dac_nids,
7884 .dig_out_nid = ALC883_DIGOUT_NID, 7908 .dig_out_nid = ALC883_DIGOUT_NID,
7885 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7886 .adc_nids = alc883_adc_nids,
7887 .dig_in_nid = ALC883_DIGIN_NID, 7909 .dig_in_nid = ALC883_DIGIN_NID,
7888 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes), 7910 .num_channel_mode = ARRAY_SIZE(alc883_sixstack_modes),
7889 .channel_mode = alc883_sixstack_modes, 7911 .channel_mode = alc883_sixstack_modes,
@@ -7896,14 +7918,25 @@ static struct alc_config_preset alc883_presets[] = {
7896 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs }, 7918 .init_verbs = { alc883_init_verbs, alc883_mitac_verbs },
7897 .num_dacs = ARRAY_SIZE(alc883_dac_nids), 7919 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7898 .dac_nids = alc883_dac_nids, 7920 .dac_nids = alc883_dac_nids,
7899 .num_adc_nids = ARRAY_SIZE(alc883_adc_nids),
7900 .adc_nids = alc883_adc_nids,
7901 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes), 7921 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7902 .channel_mode = alc883_3ST_2ch_modes, 7922 .channel_mode = alc883_3ST_2ch_modes,
7903 .input_mux = &alc883_capture_source, 7923 .input_mux = &alc883_capture_source,
7904 .unsol_event = alc883_mitac_unsol_event, 7924 .unsol_event = alc883_mitac_unsol_event,
7905 .init_hook = alc883_mitac_automute, 7925 .init_hook = alc883_mitac_automute,
7906 }, 7926 },
7927 [ALC883_FUJITSU_PI2515] = {
7928 .mixers = { alc883_2ch_fujitsu_pi2515_mixer },
7929 .init_verbs = { alc883_init_verbs,
7930 alc883_2ch_fujitsu_pi2515_verbs},
7931 .num_dacs = ARRAY_SIZE(alc883_dac_nids),
7932 .dac_nids = alc883_dac_nids,
7933 .dig_out_nid = ALC883_DIGOUT_NID,
7934 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
7935 .channel_mode = alc883_3ST_2ch_modes,
7936 .input_mux = &alc883_fujitsu_pi2515_capture_source,
7937 .unsol_event = alc883_2ch_fujitsu_pi2515_unsol_event,
7938 .init_hook = alc883_2ch_fujitsu_pi2515_automute,
7939 },
7907}; 7940};
7908 7941
7909 7942
@@ -7918,15 +7951,11 @@ static void alc883_auto_set_output_and_unmute(struct hda_codec *codec,
7918 struct alc_spec *spec = codec->spec; 7951 struct alc_spec *spec = codec->spec;
7919 int idx; 7952 int idx;
7920 7953
7954 alc_set_pin_output(codec, nid, pin_type);
7921 if (spec->multiout.dac_nids[dac_idx] == 0x25) 7955 if (spec->multiout.dac_nids[dac_idx] == 0x25)
7922 idx = 4; 7956 idx = 4;
7923 else 7957 else
7924 idx = spec->multiout.dac_nids[dac_idx] - 2; 7958 idx = spec->multiout.dac_nids[dac_idx] - 2;
7925
7926 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
7927 pin_type);
7928 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE,
7929 AMP_OUT_UNMUTE);
7930 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx); 7959 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CONNECT_SEL, idx);
7931 7960
7932} 7961}
@@ -7955,6 +7984,9 @@ static void alc883_auto_init_hp_out(struct hda_codec *codec)
7955 if (pin) /* connect to front */ 7984 if (pin) /* connect to front */
7956 /* use dac 0 */ 7985 /* use dac 0 */
7957 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); 7986 alc883_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
7987 pin = spec->autocfg.speaker_pins[0];
7988 if (pin)
7989 alc883_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
7958} 7990}
7959 7991
7960#define alc883_is_input_pin(nid) alc880_is_input_pin(nid) 7992#define alc883_is_input_pin(nid) alc880_is_input_pin(nid)
@@ -8006,9 +8038,12 @@ static int alc883_parse_auto_config(struct hda_codec *codec)
8006/* additional initialization for auto-configuration model */ 8038/* additional initialization for auto-configuration model */
8007static void alc883_auto_init(struct hda_codec *codec) 8039static void alc883_auto_init(struct hda_codec *codec)
8008{ 8040{
8041 struct alc_spec *spec = codec->spec;
8009 alc883_auto_init_multi_out(codec); 8042 alc883_auto_init_multi_out(codec);
8010 alc883_auto_init_hp_out(codec); 8043 alc883_auto_init_hp_out(codec);
8011 alc883_auto_init_analog_input(codec); 8044 alc883_auto_init_analog_input(codec);
8045 if (spec->unsol_event)
8046 alc_sku_automute(codec);
8012} 8047}
8013 8048
8014static int patch_alc883(struct hda_codec *codec) 8049static int patch_alc883(struct hda_codec *codec)
@@ -8057,10 +8092,9 @@ static int patch_alc883(struct hda_codec *codec)
8057 spec->stream_digital_playback = &alc883_pcm_digital_playback; 8092 spec->stream_digital_playback = &alc883_pcm_digital_playback;
8058 spec->stream_digital_capture = &alc883_pcm_digital_capture; 8093 spec->stream_digital_capture = &alc883_pcm_digital_capture;
8059 8094
8060 if (!spec->adc_nids && spec->input_mux) { 8095 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids);
8061 spec->adc_nids = alc883_adc_nids; 8096 spec->adc_nids = alc883_adc_nids;
8062 spec->num_adc_nids = ARRAY_SIZE(alc883_adc_nids); 8097 spec->capsrc_nids = alc883_capsrc_nids;
8063 }
8064 8098
8065 spec->vmaster_nid = 0x0c; 8099 spec->vmaster_nid = 0x0c;
8066 8100
@@ -8085,6 +8119,8 @@ static int patch_alc883(struct hda_codec *codec)
8085#define alc262_dac_nids alc260_dac_nids 8119#define alc262_dac_nids alc260_dac_nids
8086#define alc262_adc_nids alc882_adc_nids 8120#define alc262_adc_nids alc882_adc_nids
8087#define alc262_adc_nids_alt alc882_adc_nids_alt 8121#define alc262_adc_nids_alt alc882_adc_nids_alt
8122#define alc262_capsrc_nids alc882_capsrc_nids
8123#define alc262_capsrc_nids_alt alc882_capsrc_nids_alt
8088 8124
8089#define alc262_modes alc260_modes 8125#define alc262_modes alc260_modes
8090#define alc262_capture_source alc882_capture_source 8126#define alc262_capture_source alc882_capture_source
@@ -8585,7 +8621,8 @@ static void alc262_hippo1_unsol_event(struct hda_codec *codec,
8585 8621
8586/* 8622/*
8587 * fujitsu model 8623 * fujitsu model
8588 * 0x14 = headphone/spdif-out, 0x15 = internal speaker 8624 * 0x14 = headphone/spdif-out, 0x15 = internal speaker,
8625 * 0x1b = port replicator headphone out
8589 */ 8626 */
8590 8627
8591#define ALC_HP_EVENT 0x37 8628#define ALC_HP_EVENT 0x37
@@ -8593,6 +8630,14 @@ static void alc262_hippo1_unsol_event(struct hda_codec *codec,
8593static struct hda_verb alc262_fujitsu_unsol_verbs[] = { 8630static struct hda_verb alc262_fujitsu_unsol_verbs[] = {
8594 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT}, 8631 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8595 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 8632 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8633 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8634 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8635 {}
8636};
8637
8638static struct hda_verb alc262_lenovo_3000_unsol_verbs[] = {
8639 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
8640 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8596 {} 8641 {}
8597}; 8642};
8598 8643
@@ -8633,12 +8678,16 @@ static void alc262_fujitsu_automute(struct hda_codec *codec, int force)
8633 unsigned int mute; 8678 unsigned int mute;
8634 8679
8635 if (force || !spec->sense_updated) { 8680 if (force || !spec->sense_updated) {
8636 unsigned int present; 8681 unsigned int present_int_hp, present_dock_hp;
8637 /* need to execute and sync at first */ 8682 /* need to execute and sync at first */
8638 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0); 8683 snd_hda_codec_read(codec, 0x14, 0, AC_VERB_SET_PIN_SENSE, 0);
8639 present = snd_hda_codec_read(codec, 0x14, 0, 8684 present_int_hp = snd_hda_codec_read(codec, 0x14, 0,
8640 AC_VERB_GET_PIN_SENSE, 0); 8685 AC_VERB_GET_PIN_SENSE, 0);
8641 spec->jack_present = (present & 0x80000000) != 0; 8686 snd_hda_codec_read(codec, 0x1B, 0, AC_VERB_SET_PIN_SENSE, 0);
8687 present_dock_hp = snd_hda_codec_read(codec, 0x1b, 0,
8688 AC_VERB_GET_PIN_SENSE, 0);
8689 spec->jack_present = (present_int_hp & 0x80000000) != 0;
8690 spec->jack_present |= (present_dock_hp & 0x80000000) != 0;
8642 spec->sense_updated = 1; 8691 spec->sense_updated = 1;
8643 } 8692 }
8644 if (spec->jack_present) { 8693 if (spec->jack_present) {
@@ -8672,6 +8721,46 @@ static struct hda_bind_ctls alc262_fujitsu_bind_master_vol = {
8672 }, 8721 },
8673}; 8722};
8674 8723
8724/* mute/unmute internal speaker according to the hp jack and mute state */
8725static void alc262_lenovo_3000_automute(struct hda_codec *codec, int force)
8726{
8727 struct alc_spec *spec = codec->spec;
8728 unsigned int mute;
8729
8730 if (force || !spec->sense_updated) {
8731 unsigned int present_int_hp;
8732 /* need to execute and sync at first */
8733 snd_hda_codec_read(codec, 0x1b, 0, AC_VERB_SET_PIN_SENSE, 0);
8734 present_int_hp = snd_hda_codec_read(codec, 0x1b, 0,
8735 AC_VERB_GET_PIN_SENSE, 0);
8736 spec->jack_present = (present_int_hp & 0x80000000) != 0;
8737 spec->sense_updated = 1;
8738 }
8739 if (spec->jack_present) {
8740 /* mute internal speaker */
8741 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8742 HDA_AMP_MUTE, HDA_AMP_MUTE);
8743 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8744 HDA_AMP_MUTE, HDA_AMP_MUTE);
8745 } else {
8746 /* unmute internal speaker if necessary */
8747 mute = snd_hda_codec_amp_read(codec, 0x1b, 0, HDA_OUTPUT, 0);
8748 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8749 HDA_AMP_MUTE, mute);
8750 snd_hda_codec_amp_stereo(codec, 0x16, HDA_OUTPUT, 0,
8751 HDA_AMP_MUTE, mute);
8752 }
8753}
8754
8755/* unsolicited event for HP jack sensing */
8756static void alc262_lenovo_3000_unsol_event(struct hda_codec *codec,
8757 unsigned int res)
8758{
8759 if ((res >> 26) != ALC_HP_EVENT)
8760 return;
8761 alc262_lenovo_3000_automute(codec, 1);
8762}
8763
8675/* bind hp and internal speaker mute (with plug check) */ 8764/* bind hp and internal speaker mute (with plug check) */
8676static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol, 8765static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
8677 struct snd_ctl_elem_value *ucontrol) 8766 struct snd_ctl_elem_value *ucontrol)
@@ -8680,12 +8769,13 @@ static int alc262_fujitsu_master_sw_put(struct snd_kcontrol *kcontrol,
8680 long *valp = ucontrol->value.integer.value; 8769 long *valp = ucontrol->value.integer.value;
8681 int change; 8770 int change;
8682 8771
8683 change = snd_hda_codec_amp_update(codec, 0x14, 0, HDA_OUTPUT, 0, 8772 change = snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8684 HDA_AMP_MUTE, 8773 HDA_AMP_MUTE,
8685 valp[0] ? 0 : HDA_AMP_MUTE); 8774 valp ? 0 : HDA_AMP_MUTE);
8686 change |= snd_hda_codec_amp_update(codec, 0x14, 1, HDA_OUTPUT, 0, 8775 change |= snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
8687 HDA_AMP_MUTE, 8776 HDA_AMP_MUTE,
8688 valp[1] ? 0 : HDA_AMP_MUTE); 8777 valp ? 0 : HDA_AMP_MUTE);
8778
8689 if (change) 8779 if (change)
8690 alc262_fujitsu_automute(codec, 0); 8780 alc262_fujitsu_automute(codec, 0);
8691 return change; 8781 return change;
@@ -8703,6 +8793,46 @@ static struct snd_kcontrol_new alc262_fujitsu_mixer[] = {
8703 }, 8793 },
8704 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 8794 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8705 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 8795 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8796 HDA_CODEC_VOLUME("PC Speaker Volume", 0x0b, 0x05, HDA_INPUT),
8797 HDA_CODEC_MUTE("PC Speaker Switch", 0x0b, 0x05, HDA_INPUT),
8798 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8799 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8800 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
8801 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
8802 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
8803 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
8804 { } /* end */
8805};
8806
8807/* bind hp and internal speaker mute (with plug check) */
8808static int alc262_lenovo_3000_master_sw_put(struct snd_kcontrol *kcontrol,
8809 struct snd_ctl_elem_value *ucontrol)
8810{
8811 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8812 long *valp = ucontrol->value.integer.value;
8813 int change;
8814
8815 change = snd_hda_codec_amp_stereo(codec, 0x1b, HDA_OUTPUT, 0,
8816 HDA_AMP_MUTE,
8817 valp ? 0 : HDA_AMP_MUTE);
8818
8819 if (change)
8820 alc262_lenovo_3000_automute(codec, 0);
8821 return change;
8822}
8823
8824static struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
8825 HDA_BIND_VOL("Master Playback Volume", &alc262_fujitsu_bind_master_vol),
8826 {
8827 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8828 .name = "Master Playback Switch",
8829 .info = snd_hda_mixer_amp_switch_info,
8830 .get = snd_hda_mixer_amp_switch_get,
8831 .put = alc262_lenovo_3000_master_sw_put,
8832 .private_value = HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
8833 },
8834 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
8835 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
8706 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT), 8836 HDA_CODEC_VOLUME("Mic Boost", 0x18, 0, HDA_INPUT),
8707 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 8837 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
8708 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 8838 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
@@ -8730,59 +8860,72 @@ static struct hda_verb alc262_benq_t31_EAPD_verbs[] = {
8730 8860
8731/* Samsung Q1 Ultra Vista model setup */ 8861/* Samsung Q1 Ultra Vista model setup */
8732static struct snd_kcontrol_new alc262_ultra_mixer[] = { 8862static struct snd_kcontrol_new alc262_ultra_mixer[] = {
8733 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 8863 HDA_CODEC_VOLUME("Master Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
8734 HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT), 8864 HDA_BIND_MUTE("Master Playback Switch", 0x0c, 2, HDA_INPUT),
8735 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
8736 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT), 8865 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
8737 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT), 8866 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
8738 HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT), 8867 HDA_CODEC_VOLUME("Mic Boost", 0x19, 0, HDA_INPUT),
8868 HDA_CODEC_VOLUME("Headphone Mic Boost", 0x15, 0, HDA_INPUT),
8739 { } /* end */ 8869 { } /* end */
8740}; 8870};
8741 8871
8742static struct hda_verb alc262_ultra_verbs[] = { 8872static struct hda_verb alc262_ultra_verbs[] = {
8743 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT}, 8873 /* output mixer */
8874 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8875 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8876 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
8877 /* speaker */
8878 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
8879 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8880 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8881 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
8882 /* HP */
8744 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 8883 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
8745 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40}, 8884 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
8746 /* Mic is on Node 0x19 */ 8885 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
8747 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24}, 8886 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
8748 {0x22, AC_VERB_SET_CONNECT_SEL, 0x01}, 8887 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC880_HP_EVENT},
8749 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, 8888 /* internal mic */
8750 {0x23, AC_VERB_SET_CONNECT_SEL, 0x01}, 8889 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
8751 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, 8890 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
8752 {0x24, AC_VERB_SET_CONNECT_SEL, 0x01}, 8891 /* ADC, choose mic */
8753 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, 8892 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8893 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
8894 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
8895 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
8896 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
8897 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
8898 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
8899 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
8900 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
8901 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(8)},
8754 {} 8902 {}
8755}; 8903};
8756 8904
8757static struct hda_input_mux alc262_ultra_capture_source = {
8758 .num_items = 1,
8759 .items = {
8760 { "Mic", 0x1 },
8761 },
8762};
8763
8764/* mute/unmute internal speaker according to the hp jack and mute state */ 8905/* mute/unmute internal speaker according to the hp jack and mute state */
8765static void alc262_ultra_automute(struct hda_codec *codec) 8906static void alc262_ultra_automute(struct hda_codec *codec)
8766{ 8907{
8767 struct alc_spec *spec = codec->spec; 8908 struct alc_spec *spec = codec->spec;
8768 unsigned int mute; 8909 unsigned int mute;
8769 unsigned int present;
8770 8910
8771 /* need to execute and sync at first */ 8911 mute = 0;
8772 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0); 8912 /* auto-mute only when HP is used as HP */
8773 present = snd_hda_codec_read(codec, 0x15, 0, 8913 if (!spec->cur_mux[0]) {
8774 AC_VERB_GET_PIN_SENSE, 0); 8914 unsigned int present;
8775 spec->jack_present = (present & 0x80000000) != 0; 8915 /* need to execute and sync at first */
8776 if (spec->jack_present) { 8916 snd_hda_codec_read(codec, 0x15, 0, AC_VERB_SET_PIN_SENSE, 0);
8777 /* mute internal speaker */ 8917 present = snd_hda_codec_read(codec, 0x15, 0,
8778 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0, 8918 AC_VERB_GET_PIN_SENSE, 0);
8779 HDA_AMP_MUTE, HDA_AMP_MUTE); 8919 spec->jack_present = (present & AC_PINSENSE_PRESENCE) != 0;
8780 } else { 8920 if (spec->jack_present)
8781 /* unmute internal speaker if necessary */ 8921 mute = HDA_AMP_MUTE;
8782 mute = snd_hda_codec_amp_read(codec, 0x15, 0, HDA_OUTPUT, 0);
8783 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8784 HDA_AMP_MUTE, mute);
8785 } 8922 }
8923 /* mute/unmute internal speaker */
8924 snd_hda_codec_amp_stereo(codec, 0x14, HDA_OUTPUT, 0,
8925 HDA_AMP_MUTE, mute);
8926 /* mute/unmute HP */
8927 snd_hda_codec_amp_stereo(codec, 0x15, HDA_OUTPUT, 0,
8928 HDA_AMP_MUTE, mute ? 0 : HDA_AMP_MUTE);
8786} 8929}
8787 8930
8788/* unsolicited event for HP jack sensing */ 8931/* unsolicited event for HP jack sensing */
@@ -8794,6 +8937,45 @@ static void alc262_ultra_unsol_event(struct hda_codec *codec,
8794 alc262_ultra_automute(codec); 8937 alc262_ultra_automute(codec);
8795} 8938}
8796 8939
8940static struct hda_input_mux alc262_ultra_capture_source = {
8941 .num_items = 2,
8942 .items = {
8943 { "Mic", 0x1 },
8944 { "Headphone", 0x7 },
8945 },
8946};
8947
8948static int alc262_ultra_mux_enum_put(struct snd_kcontrol *kcontrol,
8949 struct snd_ctl_elem_value *ucontrol)
8950{
8951 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
8952 struct alc_spec *spec = codec->spec;
8953 int ret;
8954
8955 ret = alc882_mux_enum_put(kcontrol, ucontrol);
8956 if (!ret)
8957 return 0;
8958 /* reprogram the HP pin as mic or HP according to the input source */
8959 snd_hda_codec_write_cache(codec, 0x15, 0,
8960 AC_VERB_SET_PIN_WIDGET_CONTROL,
8961 spec->cur_mux[0] ? PIN_VREF80 : PIN_HP);
8962 alc262_ultra_automute(codec); /* mute/unmute HP */
8963 return ret;
8964}
8965
8966static struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
8967 HDA_CODEC_VOLUME("Capture Volume", 0x07, 0x0, HDA_INPUT),
8968 HDA_CODEC_MUTE("Capture Switch", 0x07, 0x0, HDA_INPUT),
8969 {
8970 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
8971 .name = "Capture Source",
8972 .info = alc882_mux_enum_info,
8973 .get = alc882_mux_enum_get,
8974 .put = alc262_ultra_mux_enum_put,
8975 },
8976 { } /* end */
8977};
8978
8797/* add playback controls from the parsed DAC table */ 8979/* add playback controls from the parsed DAC table */
8798static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec, 8980static int alc262_auto_create_multi_out_ctls(struct alc_spec *spec,
8799 const struct auto_pin_cfg *cfg) 8981 const struct auto_pin_cfg *cfg)
@@ -9185,9 +9367,12 @@ static int alc262_parse_auto_config(struct hda_codec *codec)
9185/* init callback for auto-configuration model -- overriding the default init */ 9367/* init callback for auto-configuration model -- overriding the default init */
9186static void alc262_auto_init(struct hda_codec *codec) 9368static void alc262_auto_init(struct hda_codec *codec)
9187{ 9369{
9370 struct alc_spec *spec = codec->spec;
9188 alc262_auto_init_multi_out(codec); 9371 alc262_auto_init_multi_out(codec);
9189 alc262_auto_init_hp_out(codec); 9372 alc262_auto_init_hp_out(codec);
9190 alc262_auto_init_analog_input(codec); 9373 alc262_auto_init_analog_input(codec);
9374 if (spec->unsol_event)
9375 alc_sku_automute(codec);
9191} 9376}
9192 9377
9193/* 9378/*
@@ -9206,6 +9391,7 @@ static const char *alc262_models[ALC262_MODEL_LAST] = {
9206 [ALC262_BENQ_T31] = "benq-t31", 9391 [ALC262_BENQ_T31] = "benq-t31",
9207 [ALC262_SONY_ASSAMD] = "sony-assamd", 9392 [ALC262_SONY_ASSAMD] = "sony-assamd",
9208 [ALC262_ULTRA] = "ultra", 9393 [ALC262_ULTRA] = "ultra",
9394 [ALC262_LENOVO_3000] = "lenovo-3000",
9209 [ALC262_AUTO] = "auto", 9395 [ALC262_AUTO] = "auto",
9210}; 9396};
9211 9397
@@ -9241,6 +9427,8 @@ static struct snd_pci_quirk alc262_cfg_tbl[] = {
9241 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU), 9427 SND_PCI_QUIRK(0x10cf, 0x1397, "Fujitsu", ALC262_FUJITSU),
9242 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU), 9428 SND_PCI_QUIRK(0x10cf, 0x142d, "Fujitsu Lifebook E8410", ALC262_FUJITSU),
9243 SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA), 9429 SND_PCI_QUIRK(0x144d, 0xc032, "Samsung Q1 Ultra", ALC262_ULTRA),
9430 SND_PCI_QUIRK(0x144d, 0xc039, "Samsung Q1U EL", ALC262_ULTRA),
9431 SND_PCI_QUIRK(0x17aa, 0x384e, "Lenovo 3000 y410", ALC262_LENOVO_3000),
9244 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8), 9432 SND_PCI_QUIRK(0x17ff, 0x0560, "Benq ED8", ALC262_BENQ_ED8),
9245 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31), 9433 SND_PCI_QUIRK(0x17ff, 0x058d, "Benq T31-16", ALC262_BENQ_T31),
9246 SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1), 9434 SND_PCI_QUIRK(0x17ff, 0x058f, "Benq Hippo", ALC262_HIPPO_1),
@@ -9390,18 +9578,32 @@ static struct alc_config_preset alc262_presets[] = {
9390 .init_hook = alc262_hippo_automute, 9578 .init_hook = alc262_hippo_automute,
9391 }, 9579 },
9392 [ALC262_ULTRA] = { 9580 [ALC262_ULTRA] = {
9393 .mixers = { alc262_ultra_mixer }, 9581 .mixers = { alc262_ultra_mixer, alc262_ultra_capture_mixer },
9394 .init_verbs = { alc262_init_verbs, alc262_ultra_verbs }, 9582 .init_verbs = { alc262_ultra_verbs },
9395 .num_dacs = ARRAY_SIZE(alc262_dac_nids), 9583 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9396 .dac_nids = alc262_dac_nids, 9584 .dac_nids = alc262_dac_nids,
9397 .hp_nid = 0x03,
9398 .dig_out_nid = ALC262_DIGOUT_NID,
9399 .num_channel_mode = ARRAY_SIZE(alc262_modes), 9585 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9400 .channel_mode = alc262_modes, 9586 .channel_mode = alc262_modes,
9401 .input_mux = &alc262_ultra_capture_source, 9587 .input_mux = &alc262_ultra_capture_source,
9588 .adc_nids = alc262_adc_nids, /* ADC0 */
9589 .capsrc_nids = alc262_capsrc_nids,
9590 .num_adc_nids = 1, /* single ADC */
9402 .unsol_event = alc262_ultra_unsol_event, 9591 .unsol_event = alc262_ultra_unsol_event,
9403 .init_hook = alc262_ultra_automute, 9592 .init_hook = alc262_ultra_automute,
9404 }, 9593 },
9594 [ALC262_LENOVO_3000] = {
9595 .mixers = { alc262_lenovo_3000_mixer },
9596 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs,
9597 alc262_lenovo_3000_unsol_verbs },
9598 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
9599 .dac_nids = alc262_dac_nids,
9600 .hp_nid = 0x03,
9601 .dig_out_nid = ALC262_DIGOUT_NID,
9602 .num_channel_mode = ARRAY_SIZE(alc262_modes),
9603 .channel_mode = alc262_modes,
9604 .input_mux = &alc262_fujitsu_capture_source,
9605 .unsol_event = alc262_lenovo_3000_unsol_event,
9606 },
9405}; 9607};
9406 9608
9407static int patch_alc262(struct hda_codec *codec) 9609static int patch_alc262(struct hda_codec *codec)
@@ -9472,12 +9674,14 @@ static int patch_alc262(struct hda_codec *codec)
9472 if (wcap != AC_WID_AUD_IN) { 9674 if (wcap != AC_WID_AUD_IN) {
9473 spec->adc_nids = alc262_adc_nids_alt; 9675 spec->adc_nids = alc262_adc_nids_alt;
9474 spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt); 9676 spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids_alt);
9677 spec->capsrc_nids = alc262_capsrc_nids_alt;
9475 spec->mixers[spec->num_mixers] = 9678 spec->mixers[spec->num_mixers] =
9476 alc262_capture_alt_mixer; 9679 alc262_capture_alt_mixer;
9477 spec->num_mixers++; 9680 spec->num_mixers++;
9478 } else { 9681 } else {
9479 spec->adc_nids = alc262_adc_nids; 9682 spec->adc_nids = alc262_adc_nids;
9480 spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids); 9683 spec->num_adc_nids = ARRAY_SIZE(alc262_adc_nids);
9684 spec->capsrc_nids = alc262_capsrc_nids;
9481 spec->mixers[spec->num_mixers] = alc262_capture_mixer; 9685 spec->mixers[spec->num_mixers] = alc262_capture_mixer;
9482 spec->num_mixers++; 9686 spec->num_mixers++;
9483 } 9687 }
@@ -9517,6 +9721,8 @@ static hda_nid_t alc268_adc_nids_alt[1] = {
9517 0x08 9721 0x08
9518}; 9722};
9519 9723
9724static hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
9725
9520static struct snd_kcontrol_new alc268_base_mixer[] = { 9726static struct snd_kcontrol_new alc268_base_mixer[] = {
9521 /* output mixer control */ 9727 /* output mixer control */
9522 HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT), 9728 HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
@@ -9529,6 +9735,22 @@ static struct snd_kcontrol_new alc268_base_mixer[] = {
9529 { } 9735 { }
9530}; 9736};
9531 9737
9738/* bind Beep switches of both NID 0x0f and 0x10 */
9739static struct hda_bind_ctls alc268_bind_beep_sw = {
9740 .ops = &snd_hda_bind_sw,
9741 .values = {
9742 HDA_COMPOSE_AMP_VAL(0x0f, 3, 1, HDA_INPUT),
9743 HDA_COMPOSE_AMP_VAL(0x10, 3, 1, HDA_INPUT),
9744 0
9745 },
9746};
9747
9748static struct snd_kcontrol_new alc268_beep_mixer[] = {
9749 HDA_CODEC_VOLUME("Beep Playback Volume", 0x1d, 0x0, HDA_INPUT),
9750 HDA_BIND_SW("Beep Playback Switch", &alc268_bind_beep_sw),
9751 { }
9752};
9753
9532static struct hda_verb alc268_eapd_verbs[] = { 9754static struct hda_verb alc268_eapd_verbs[] = {
9533 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2}, 9755 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
9534 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2}, 9756 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
@@ -9613,8 +9835,12 @@ static struct snd_kcontrol_new alc268_acer_mixer[] = {
9613}; 9835};
9614 9836
9615static struct hda_verb alc268_acer_verbs[] = { 9837static struct hda_verb alc268_acer_verbs[] = {
9838 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
9839 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
9616 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP}, 9840 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
9617 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, 9841 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
9842 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9843 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
9618 9844
9619 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN}, 9845 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9620 { } 9846 { }
@@ -9685,6 +9911,64 @@ static void alc268_dell_unsol_event(struct hda_codec *codec,
9685 9911
9686#define alc268_dell_init_hook alc268_dell_automute 9912#define alc268_dell_init_hook alc268_dell_automute
9687 9913
9914static struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
9915 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
9916 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9917 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
9918 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9919 HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
9920 HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
9921 HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
9922 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
9923 { }
9924};
9925
9926static struct hda_verb alc267_quanta_il1_verbs[] = {
9927 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_HP_EVENT | AC_USRSP_EN},
9928 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC880_MIC_EVENT | AC_USRSP_EN},
9929 { }
9930};
9931
9932static void alc267_quanta_il1_hp_automute(struct hda_codec *codec)
9933{
9934 unsigned int present;
9935
9936 present = snd_hda_codec_read(codec, 0x15, 0, AC_VERB_GET_PIN_SENSE, 0)
9937 & AC_PINSENSE_PRESENCE;
9938 snd_hda_codec_write(codec, 0x14, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
9939 present ? 0 : PIN_OUT);
9940}
9941
9942static void alc267_quanta_il1_mic_automute(struct hda_codec *codec)
9943{
9944 unsigned int present;
9945
9946 present = snd_hda_codec_read(codec, 0x18, 0,
9947 AC_VERB_GET_PIN_SENSE, 0) & 0x80000000;
9948 snd_hda_codec_write(codec, 0x23, 0,
9949 AC_VERB_SET_CONNECT_SEL,
9950 present ? 0x00 : 0x01);
9951}
9952
9953static void alc267_quanta_il1_automute(struct hda_codec *codec)
9954{
9955 alc267_quanta_il1_hp_automute(codec);
9956 alc267_quanta_il1_mic_automute(codec);
9957}
9958
9959static void alc267_quanta_il1_unsol_event(struct hda_codec *codec,
9960 unsigned int res)
9961{
9962 switch (res >> 26) {
9963 case ALC880_HP_EVENT:
9964 alc267_quanta_il1_hp_automute(codec);
9965 break;
9966 case ALC880_MIC_EVENT:
9967 alc267_quanta_il1_mic_automute(codec);
9968 break;
9969 }
9970}
9971
9688/* 9972/*
9689 * generic initialization of ADC, input mixers and output mixers 9973 * generic initialization of ADC, input mixers and output mixers
9690 */ 9974 */
@@ -9725,7 +10009,11 @@ static struct hda_verb alc268_base_init_verbs[] = {
9725 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 10009 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9726 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 10010 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9727 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 10011 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9728 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, 10012
10013 /* set PCBEEP vol = 0, mute connections */
10014 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10015 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10016 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9729 10017
9730 /* Unmute Selector 23h,24h and set the default input to mic-in */ 10018 /* Unmute Selector 23h,24h and set the default input to mic-in */
9731 10019
@@ -9764,29 +10052,17 @@ static struct hda_verb alc268_volume_init_verbs[] = {
9764 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 10052 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9765 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, 10053 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
9766 10054
9767 /* set PCBEEP vol = 0 */ 10055 /* set PCBEEP vol = 0, mute connections */
9768 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, (0xb000 | (0x00 << 8))}, 10056 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
10057 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
10058 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
9769 10059
9770 { } 10060 { }
9771}; 10061};
9772 10062
9773#define alc268_mux_enum_info alc_mux_enum_info 10063#define alc268_mux_enum_info alc_mux_enum_info
9774#define alc268_mux_enum_get alc_mux_enum_get 10064#define alc268_mux_enum_get alc_mux_enum_get
9775 10065#define alc268_mux_enum_put alc_mux_enum_put
9776static int alc268_mux_enum_put(struct snd_kcontrol *kcontrol,
9777 struct snd_ctl_elem_value *ucontrol)
9778{
9779 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
9780 struct alc_spec *spec = codec->spec;
9781
9782 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
9783 static hda_nid_t capture_mixers[3] = { 0x23, 0x24 };
9784 hda_nid_t nid = capture_mixers[adc_idx];
9785
9786 return snd_hda_input_mux_put(codec, spec->input_mux, ucontrol,
9787 nid,
9788 &spec->cur_mux[adc_idx]);
9789}
9790 10066
9791static struct snd_kcontrol_new alc268_capture_alt_mixer[] = { 10067static struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
9792 HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT), 10068 HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
@@ -9836,13 +10112,17 @@ static struct hda_input_mux alc268_capture_source = {
9836 }, 10112 },
9837}; 10113};
9838 10114
10115static struct hda_input_mux alc268_acer_capture_source = {
10116 .num_items = 3,
10117 .items = {
10118 { "Mic", 0x0 },
10119 { "Internal Mic", 0x6 },
10120 { "Line", 0x2 },
10121 },
10122};
10123
9839#ifdef CONFIG_SND_DEBUG 10124#ifdef CONFIG_SND_DEBUG
9840static struct snd_kcontrol_new alc268_test_mixer[] = { 10125static struct snd_kcontrol_new alc268_test_mixer[] = {
9841 HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
9842 HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
9843 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
9844 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
9845
9846 /* Volume widgets */ 10126 /* Volume widgets */
9847 HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT), 10127 HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
9848 HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT), 10128 HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
@@ -9981,6 +10261,10 @@ static int alc268_auto_create_analog_input_ctls(struct alc_spec *spec,
9981 case 0x1c: 10261 case 0x1c:
9982 idx1 = 3; /* CD */ 10262 idx1 = 3; /* CD */
9983 break; 10263 break;
10264 case 0x12:
10265 case 0x13:
10266 idx1 = 6; /* digital mics */
10267 break;
9984 default: 10268 default:
9985 continue; 10269 continue;
9986 } 10270 }
@@ -10073,6 +10357,9 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
10073 if (spec->kctl_alloc) 10357 if (spec->kctl_alloc)
10074 spec->mixers[spec->num_mixers++] = spec->kctl_alloc; 10358 spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
10075 10359
10360 if (spec->autocfg.speaker_pins[0] != 0x1d)
10361 spec->mixers[spec->num_mixers++] = alc268_beep_mixer;
10362
10076 spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs; 10363 spec->init_verbs[spec->num_init_verbs++] = alc268_volume_init_verbs;
10077 spec->num_mux_defs = 1; 10364 spec->num_mux_defs = 1;
10078 spec->input_mux = &spec->private_imux; 10365 spec->input_mux = &spec->private_imux;
@@ -10091,20 +10378,25 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
10091/* init callback for auto-configuration model -- overriding the default init */ 10378/* init callback for auto-configuration model -- overriding the default init */
10092static void alc268_auto_init(struct hda_codec *codec) 10379static void alc268_auto_init(struct hda_codec *codec)
10093{ 10380{
10381 struct alc_spec *spec = codec->spec;
10094 alc268_auto_init_multi_out(codec); 10382 alc268_auto_init_multi_out(codec);
10095 alc268_auto_init_hp_out(codec); 10383 alc268_auto_init_hp_out(codec);
10096 alc268_auto_init_mono_speaker_out(codec); 10384 alc268_auto_init_mono_speaker_out(codec);
10097 alc268_auto_init_analog_input(codec); 10385 alc268_auto_init_analog_input(codec);
10386 if (spec->unsol_event)
10387 alc_sku_automute(codec);
10098} 10388}
10099 10389
10100/* 10390/*
10101 * configuration and preset 10391 * configuration and preset
10102 */ 10392 */
10103static const char *alc268_models[ALC268_MODEL_LAST] = { 10393static const char *alc268_models[ALC268_MODEL_LAST] = {
10394 [ALC267_QUANTA_IL1] = "quanta-il1",
10104 [ALC268_3ST] = "3stack", 10395 [ALC268_3ST] = "3stack",
10105 [ALC268_TOSHIBA] = "toshiba", 10396 [ALC268_TOSHIBA] = "toshiba",
10106 [ALC268_ACER] = "acer", 10397 [ALC268_ACER] = "acer",
10107 [ALC268_DELL] = "dell", 10398 [ALC268_DELL] = "dell",
10399 [ALC268_ZEPTO] = "zepto",
10108#ifdef CONFIG_SND_DEBUG 10400#ifdef CONFIG_SND_DEBUG
10109 [ALC268_TEST] = "test", 10401 [ALC268_TEST] = "test",
10110#endif 10402#endif
@@ -10112,6 +10404,7 @@ static const char *alc268_models[ALC268_MODEL_LAST] = {
10112}; 10404};
10113 10405
10114static struct snd_pci_quirk alc268_cfg_tbl[] = { 10406static struct snd_pci_quirk alc268_cfg_tbl[] = {
10407 SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
10115 SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER), 10408 SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
10116 SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER), 10409 SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
10117 SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER), 10410 SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
@@ -10122,17 +10415,36 @@ static struct snd_pci_quirk alc268_cfg_tbl[] = {
10122 SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA), 10415 SND_PCI_QUIRK(0x1179, 0xff10, "TOSHIBA A205", ALC268_TOSHIBA),
10123 SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA), 10416 SND_PCI_QUIRK(0x1179, 0xff50, "TOSHIBA A305", ALC268_TOSHIBA),
10124 SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER), 10417 SND_PCI_QUIRK(0x152d, 0x0763, "Diverse (CPR2000)", ALC268_ACER),
10418 SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
10419 SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
10125 {} 10420 {}
10126}; 10421};
10127 10422
10128static struct alc_config_preset alc268_presets[] = { 10423static struct alc_config_preset alc268_presets[] = {
10424 [ALC267_QUANTA_IL1] = {
10425 .mixers = { alc267_quanta_il1_mixer },
10426 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10427 alc267_quanta_il1_verbs },
10428 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10429 .dac_nids = alc268_dac_nids,
10430 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10431 .adc_nids = alc268_adc_nids_alt,
10432 .hp_nid = 0x03,
10433 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10434 .channel_mode = alc268_modes,
10435 .input_mux = &alc268_capture_source,
10436 .unsol_event = alc267_quanta_il1_unsol_event,
10437 .init_hook = alc267_quanta_il1_automute,
10438 },
10129 [ALC268_3ST] = { 10439 [ALC268_3ST] = {
10130 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer }, 10440 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10441 alc268_beep_mixer },
10131 .init_verbs = { alc268_base_init_verbs }, 10442 .init_verbs = { alc268_base_init_verbs },
10132 .num_dacs = ARRAY_SIZE(alc268_dac_nids), 10443 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10133 .dac_nids = alc268_dac_nids, 10444 .dac_nids = alc268_dac_nids,
10134 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt), 10445 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10135 .adc_nids = alc268_adc_nids_alt, 10446 .adc_nids = alc268_adc_nids_alt,
10447 .capsrc_nids = alc268_capsrc_nids,
10136 .hp_nid = 0x03, 10448 .hp_nid = 0x03,
10137 .dig_out_nid = ALC268_DIGOUT_NID, 10449 .dig_out_nid = ALC268_DIGOUT_NID,
10138 .num_channel_mode = ARRAY_SIZE(alc268_modes), 10450 .num_channel_mode = ARRAY_SIZE(alc268_modes),
@@ -10140,13 +10452,15 @@ static struct alc_config_preset alc268_presets[] = {
10140 .input_mux = &alc268_capture_source, 10452 .input_mux = &alc268_capture_source,
10141 }, 10453 },
10142 [ALC268_TOSHIBA] = { 10454 [ALC268_TOSHIBA] = {
10143 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer }, 10455 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10456 alc268_beep_mixer },
10144 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs, 10457 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10145 alc268_toshiba_verbs }, 10458 alc268_toshiba_verbs },
10146 .num_dacs = ARRAY_SIZE(alc268_dac_nids), 10459 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10147 .dac_nids = alc268_dac_nids, 10460 .dac_nids = alc268_dac_nids,
10148 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt), 10461 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10149 .adc_nids = alc268_adc_nids_alt, 10462 .adc_nids = alc268_adc_nids_alt,
10463 .capsrc_nids = alc268_capsrc_nids,
10150 .hp_nid = 0x03, 10464 .hp_nid = 0x03,
10151 .num_channel_mode = ARRAY_SIZE(alc268_modes), 10465 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10152 .channel_mode = alc268_modes, 10466 .channel_mode = alc268_modes,
@@ -10155,22 +10469,24 @@ static struct alc_config_preset alc268_presets[] = {
10155 .init_hook = alc268_toshiba_automute, 10469 .init_hook = alc268_toshiba_automute,
10156 }, 10470 },
10157 [ALC268_ACER] = { 10471 [ALC268_ACER] = {
10158 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer }, 10472 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
10473 alc268_beep_mixer },
10159 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs, 10474 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10160 alc268_acer_verbs }, 10475 alc268_acer_verbs },
10161 .num_dacs = ARRAY_SIZE(alc268_dac_nids), 10476 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10162 .dac_nids = alc268_dac_nids, 10477 .dac_nids = alc268_dac_nids,
10163 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt), 10478 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10164 .adc_nids = alc268_adc_nids_alt, 10479 .adc_nids = alc268_adc_nids_alt,
10480 .capsrc_nids = alc268_capsrc_nids,
10165 .hp_nid = 0x02, 10481 .hp_nid = 0x02,
10166 .num_channel_mode = ARRAY_SIZE(alc268_modes), 10482 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10167 .channel_mode = alc268_modes, 10483 .channel_mode = alc268_modes,
10168 .input_mux = &alc268_capture_source, 10484 .input_mux = &alc268_acer_capture_source,
10169 .unsol_event = alc268_acer_unsol_event, 10485 .unsol_event = alc268_acer_unsol_event,
10170 .init_hook = alc268_acer_init_hook, 10486 .init_hook = alc268_acer_init_hook,
10171 }, 10487 },
10172 [ALC268_DELL] = { 10488 [ALC268_DELL] = {
10173 .mixers = { alc268_dell_mixer }, 10489 .mixers = { alc268_dell_mixer, alc268_beep_mixer },
10174 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs, 10490 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10175 alc268_dell_verbs }, 10491 alc268_dell_verbs },
10176 .num_dacs = ARRAY_SIZE(alc268_dac_nids), 10492 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
@@ -10182,6 +10498,24 @@ static struct alc_config_preset alc268_presets[] = {
10182 .init_hook = alc268_dell_init_hook, 10498 .init_hook = alc268_dell_init_hook,
10183 .input_mux = &alc268_capture_source, 10499 .input_mux = &alc268_capture_source,
10184 }, 10500 },
10501 [ALC268_ZEPTO] = {
10502 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
10503 alc268_beep_mixer },
10504 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
10505 alc268_toshiba_verbs },
10506 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
10507 .dac_nids = alc268_dac_nids,
10508 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10509 .adc_nids = alc268_adc_nids_alt,
10510 .capsrc_nids = alc268_capsrc_nids,
10511 .hp_nid = 0x03,
10512 .dig_out_nid = ALC268_DIGOUT_NID,
10513 .num_channel_mode = ARRAY_SIZE(alc268_modes),
10514 .channel_mode = alc268_modes,
10515 .input_mux = &alc268_capture_source,
10516 .unsol_event = alc268_toshiba_unsol_event,
10517 .init_hook = alc268_toshiba_automute
10518 },
10185#ifdef CONFIG_SND_DEBUG 10519#ifdef CONFIG_SND_DEBUG
10186 [ALC268_TEST] = { 10520 [ALC268_TEST] = {
10187 .mixers = { alc268_test_mixer, alc268_capture_mixer }, 10521 .mixers = { alc268_test_mixer, alc268_capture_mixer },
@@ -10191,6 +10525,7 @@ static struct alc_config_preset alc268_presets[] = {
10191 .dac_nids = alc268_dac_nids, 10525 .dac_nids = alc268_dac_nids,
10192 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt), 10526 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
10193 .adc_nids = alc268_adc_nids_alt, 10527 .adc_nids = alc268_adc_nids_alt,
10528 .capsrc_nids = alc268_capsrc_nids,
10194 .hp_nid = 0x03, 10529 .hp_nid = 0x03,
10195 .dig_out_nid = ALC268_DIGOUT_NID, 10530 .dig_out_nid = ALC268_DIGOUT_NID,
10196 .num_channel_mode = ARRAY_SIZE(alc268_modes), 10531 .num_channel_mode = ARRAY_SIZE(alc268_modes),
@@ -10247,13 +10582,22 @@ static int patch_alc268(struct hda_codec *codec)
10247 spec->stream_name_digital = "ALC268 Digital"; 10582 spec->stream_name_digital = "ALC268 Digital";
10248 spec->stream_digital_playback = &alc268_pcm_digital_playback; 10583 spec->stream_digital_playback = &alc268_pcm_digital_playback;
10249 10584
10585 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
10586 /* override the amp caps for beep generator */
10587 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
10588 (0x0c << AC_AMPCAP_OFFSET_SHIFT) |
10589 (0x0c << AC_AMPCAP_NUM_STEPS_SHIFT) |
10590 (0x07 << AC_AMPCAP_STEP_SIZE_SHIFT) |
10591 (0 << AC_AMPCAP_MUTE_SHIFT));
10592
10250 if (!spec->adc_nids && spec->input_mux) { 10593 if (!spec->adc_nids && spec->input_mux) {
10251 /* check whether NID 0x07 is valid */ 10594 /* check whether NID 0x07 is valid */
10252 unsigned int wcap = get_wcaps(codec, 0x07); 10595 unsigned int wcap = get_wcaps(codec, 0x07);
10596 int i;
10253 10597
10254 /* get type */ 10598 /* get type */
10255 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT; 10599 wcap = (wcap & AC_WCAP_TYPE) >> AC_WCAP_TYPE_SHIFT;
10256 if (wcap != AC_WID_AUD_IN) { 10600 if (wcap != AC_WID_AUD_IN || spec->input_mux->num_items == 1) {
10257 spec->adc_nids = alc268_adc_nids_alt; 10601 spec->adc_nids = alc268_adc_nids_alt;
10258 spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt); 10602 spec->num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt);
10259 spec->mixers[spec->num_mixers] = 10603 spec->mixers[spec->num_mixers] =
@@ -10266,6 +10610,12 @@ static int patch_alc268(struct hda_codec *codec)
10266 alc268_capture_mixer; 10610 alc268_capture_mixer;
10267 spec->num_mixers++; 10611 spec->num_mixers++;
10268 } 10612 }
10613 spec->capsrc_nids = alc268_capsrc_nids;
10614 /* set default input source */
10615 for (i = 0; i < spec->num_adc_nids; i++)
10616 snd_hda_codec_write_cache(codec, alc268_capsrc_nids[i],
10617 0, AC_VERB_SET_CONNECT_SEL,
10618 spec->input_mux->items[0].index);
10269 } 10619 }
10270 10620
10271 spec->vmaster_nid = 0x02; 10621 spec->vmaster_nid = 0x02;
@@ -10539,9 +10889,12 @@ static int alc269_parse_auto_config(struct hda_codec *codec)
10539/* init callback for auto-configuration model -- overriding the default init */ 10889/* init callback for auto-configuration model -- overriding the default init */
10540static void alc269_auto_init(struct hda_codec *codec) 10890static void alc269_auto_init(struct hda_codec *codec)
10541{ 10891{
10892 struct alc_spec *spec = codec->spec;
10542 alc269_auto_init_multi_out(codec); 10893 alc269_auto_init_multi_out(codec);
10543 alc269_auto_init_hp_out(codec); 10894 alc269_auto_init_hp_out(codec);
10544 alc269_auto_init_analog_input(codec); 10895 alc269_auto_init_analog_input(codec);
10896 if (spec->unsol_event)
10897 alc_sku_automute(codec);
10545} 10898}
10546 10899
10547/* 10900/*
@@ -11463,13 +11816,7 @@ static void alc861_auto_set_output_and_unmute(struct hda_codec *codec,
11463 hda_nid_t nid, 11816 hda_nid_t nid,
11464 int pin_type, int dac_idx) 11817 int pin_type, int dac_idx)
11465{ 11818{
11466 /* set as output */ 11819 alc_set_pin_output(codec, nid, pin_type);
11467
11468 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL,
11469 pin_type);
11470 snd_hda_codec_write(codec, dac_idx, 0, AC_VERB_SET_AMP_GAIN_MUTE,
11471 AMP_OUT_UNMUTE);
11472
11473} 11820}
11474 11821
11475static void alc861_auto_init_multi_out(struct hda_codec *codec) 11822static void alc861_auto_init_multi_out(struct hda_codec *codec)
@@ -11496,6 +11843,9 @@ static void alc861_auto_init_hp_out(struct hda_codec *codec)
11496 if (pin) /* connect to front */ 11843 if (pin) /* connect to front */
11497 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP, 11844 alc861_auto_set_output_and_unmute(codec, pin, PIN_HP,
11498 spec->multiout.dac_nids[0]); 11845 spec->multiout.dac_nids[0]);
11846 pin = spec->autocfg.speaker_pins[0];
11847 if (pin)
11848 alc861_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
11499} 11849}
11500 11850
11501static void alc861_auto_init_analog_input(struct hda_codec *codec) 11851static void alc861_auto_init_analog_input(struct hda_codec *codec)
@@ -11568,9 +11918,12 @@ static int alc861_parse_auto_config(struct hda_codec *codec)
11568/* additional initialization for auto-configuration model */ 11918/* additional initialization for auto-configuration model */
11569static void alc861_auto_init(struct hda_codec *codec) 11919static void alc861_auto_init(struct hda_codec *codec)
11570{ 11920{
11921 struct alc_spec *spec = codec->spec;
11571 alc861_auto_init_multi_out(codec); 11922 alc861_auto_init_multi_out(codec);
11572 alc861_auto_init_hp_out(codec); 11923 alc861_auto_init_hp_out(codec);
11573 alc861_auto_init_analog_input(codec); 11924 alc861_auto_init_analog_input(codec);
11925 if (spec->unsol_event)
11926 alc_sku_automute(codec);
11574} 11927}
11575 11928
11576#ifdef CONFIG_SND_HDA_POWER_SAVE 11929#ifdef CONFIG_SND_HDA_POWER_SAVE
@@ -11822,6 +12175,8 @@ static hda_nid_t alc861vd_adc_nids[1] = {
11822 0x09, 12175 0x09,
11823}; 12176};
11824 12177
12178static hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
12179
11825/* input MUX */ 12180/* input MUX */
11826/* FIXME: should be a matrix-type input source selection */ 12181/* FIXME: should be a matrix-type input source selection */
11827static struct hda_input_mux alc861vd_capture_source = { 12182static struct hda_input_mux alc861vd_capture_source = {
@@ -11835,11 +12190,10 @@ static struct hda_input_mux alc861vd_capture_source = {
11835}; 12190};
11836 12191
11837static struct hda_input_mux alc861vd_dallas_capture_source = { 12192static struct hda_input_mux alc861vd_dallas_capture_source = {
11838 .num_items = 3, 12193 .num_items = 2,
11839 .items = { 12194 .items = {
11840 { "Front Mic", 0x0 }, 12195 { "Ext Mic", 0x0 },
11841 { "ATAPI Mic", 0x1 }, 12196 { "Int Mic", 0x1 },
11842 { "Line In", 0x5 },
11843 }, 12197 },
11844}; 12198};
11845 12199
@@ -11853,33 +12207,8 @@ static struct hda_input_mux alc861vd_hp_capture_source = {
11853 12207
11854#define alc861vd_mux_enum_info alc_mux_enum_info 12208#define alc861vd_mux_enum_info alc_mux_enum_info
11855#define alc861vd_mux_enum_get alc_mux_enum_get 12209#define alc861vd_mux_enum_get alc_mux_enum_get
11856 12210/* ALC861VD has the ALC882-type input selection (but has only one ADC) */
11857static int alc861vd_mux_enum_put(struct snd_kcontrol *kcontrol, 12211#define alc861vd_mux_enum_put alc882_mux_enum_put
11858 struct snd_ctl_elem_value *ucontrol)
11859{
11860 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
11861 struct alc_spec *spec = codec->spec;
11862 const struct hda_input_mux *imux = spec->input_mux;
11863 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
11864 static hda_nid_t capture_mixers[1] = { 0x22 };
11865 hda_nid_t nid = capture_mixers[adc_idx];
11866 unsigned int *cur_val = &spec->cur_mux[adc_idx];
11867 unsigned int i, idx;
11868
11869 idx = ucontrol->value.enumerated.item[0];
11870 if (idx >= imux->num_items)
11871 idx = imux->num_items - 1;
11872 if (*cur_val == idx)
11873 return 0;
11874 for (i = 0; i < imux->num_items; i++) {
11875 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
11876 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
11877 imux->items[i].index,
11878 HDA_AMP_MUTE, v);
11879 }
11880 *cur_val = idx;
11881 return 1;
11882}
11883 12212
11884/* 12213/*
11885 * 2ch mode 12214 * 2ch mode
@@ -12034,20 +12363,22 @@ static struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
12034 { } /* end */ 12363 { } /* end */
12035}; 12364};
12036 12365
12037/* Pin assignment: Front=0x14, HP = 0x15, 12366/* Pin assignment: Speaker=0x14, HP = 0x15,
12038 * Front Mic=0x18, ATAPI Mic = 0x19, Line In = 0x1d 12367 * Ext Mic=0x18, Int Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
12039 */ 12368 */
12040static struct snd_kcontrol_new alc861vd_dallas_mixer[] = { 12369static struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
12041 HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT), 12370 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12042 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT), 12371 HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
12043 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT), 12372 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12044 HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT), 12373 HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
12045 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT), 12374 HDA_CODEC_VOLUME("Ext Mic Boost", 0x18, 0, HDA_INPUT),
12046 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT), 12375 HDA_CODEC_VOLUME("Ext Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
12047 HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT), 12376 HDA_CODEC_MUTE("Ext Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
12048 HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT), 12377 HDA_CODEC_VOLUME("Int Mic Boost", 0x19, 0, HDA_INPUT),
12049 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x05, HDA_INPUT), 12378 HDA_CODEC_VOLUME("Int Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
12050 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x05, HDA_INPUT), 12379 HDA_CODEC_MUTE("Int Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
12380 HDA_CODEC_VOLUME("PC Beep Volume", 0x0b, 0x05, HDA_INPUT),
12381 HDA_CODEC_MUTE("PC Beep Switch", 0x0b, 0x05, HDA_INPUT),
12051 { } /* end */ 12382 { } /* end */
12052}; 12383};
12053 12384
@@ -12348,6 +12679,7 @@ static struct snd_pci_quirk alc861vd_cfg_tbl[] = {
12348 /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/ 12679 /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
12349 SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS), 12680 SND_PCI_QUIRK(0x1179, 0xff01, "DALLAS", ALC861VD_DALLAS),
12350 SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO), 12681 SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
12682 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
12351 SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG), 12683 SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
12352 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO), 12684 SND_PCI_QUIRK(0x17aa, 0x2066, "Lenovo", ALC861VD_LENOVO),
12353 SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO), 12685 SND_PCI_QUIRK(0x17aa, 0x3802, "Lenovo 3000 C200", ALC861VD_LENOVO),
@@ -12362,8 +12694,6 @@ static struct alc_config_preset alc861vd_presets[] = {
12362 alc861vd_3stack_init_verbs }, 12694 alc861vd_3stack_init_verbs },
12363 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids), 12695 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
12364 .dac_nids = alc660vd_dac_nids, 12696 .dac_nids = alc660vd_dac_nids,
12365 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
12366 .adc_nids = alc861vd_adc_nids,
12367 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes), 12697 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12368 .channel_mode = alc861vd_3stack_2ch_modes, 12698 .channel_mode = alc861vd_3stack_2ch_modes,
12369 .input_mux = &alc861vd_capture_source, 12699 .input_mux = &alc861vd_capture_source,
@@ -12375,8 +12705,6 @@ static struct alc_config_preset alc861vd_presets[] = {
12375 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids), 12705 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
12376 .dac_nids = alc660vd_dac_nids, 12706 .dac_nids = alc660vd_dac_nids,
12377 .dig_out_nid = ALC861VD_DIGOUT_NID, 12707 .dig_out_nid = ALC861VD_DIGOUT_NID,
12378 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
12379 .adc_nids = alc861vd_adc_nids,
12380 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes), 12708 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12381 .channel_mode = alc861vd_3stack_2ch_modes, 12709 .channel_mode = alc861vd_3stack_2ch_modes,
12382 .input_mux = &alc861vd_capture_source, 12710 .input_mux = &alc861vd_capture_source,
@@ -12421,8 +12749,6 @@ static struct alc_config_preset alc861vd_presets[] = {
12421 alc861vd_lenovo_unsol_verbs }, 12749 alc861vd_lenovo_unsol_verbs },
12422 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids), 12750 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
12423 .dac_nids = alc660vd_dac_nids, 12751 .dac_nids = alc660vd_dac_nids,
12424 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
12425 .adc_nids = alc861vd_adc_nids,
12426 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes), 12752 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12427 .channel_mode = alc861vd_3stack_2ch_modes, 12753 .channel_mode = alc861vd_3stack_2ch_modes,
12428 .input_mux = &alc861vd_capture_source, 12754 .input_mux = &alc861vd_capture_source,
@@ -12434,8 +12760,6 @@ static struct alc_config_preset alc861vd_presets[] = {
12434 .init_verbs = { alc861vd_dallas_verbs }, 12760 .init_verbs = { alc861vd_dallas_verbs },
12435 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids), 12761 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12436 .dac_nids = alc861vd_dac_nids, 12762 .dac_nids = alc861vd_dac_nids,
12437 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
12438 .adc_nids = alc861vd_adc_nids,
12439 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes), 12763 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12440 .channel_mode = alc861vd_3stack_2ch_modes, 12764 .channel_mode = alc861vd_3stack_2ch_modes,
12441 .input_mux = &alc861vd_dallas_capture_source, 12765 .input_mux = &alc861vd_dallas_capture_source,
@@ -12447,9 +12771,7 @@ static struct alc_config_preset alc861vd_presets[] = {
12447 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs }, 12771 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
12448 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids), 12772 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
12449 .dac_nids = alc861vd_dac_nids, 12773 .dac_nids = alc861vd_dac_nids,
12450 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
12451 .dig_out_nid = ALC861VD_DIGOUT_NID, 12774 .dig_out_nid = ALC861VD_DIGOUT_NID,
12452 .adc_nids = alc861vd_adc_nids,
12453 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes), 12775 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
12454 .channel_mode = alc861vd_3stack_2ch_modes, 12776 .channel_mode = alc861vd_3stack_2ch_modes,
12455 .input_mux = &alc861vd_hp_capture_source, 12777 .input_mux = &alc861vd_hp_capture_source,
@@ -12464,11 +12786,7 @@ static struct alc_config_preset alc861vd_presets[] = {
12464static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec, 12786static void alc861vd_auto_set_output_and_unmute(struct hda_codec *codec,
12465 hda_nid_t nid, int pin_type, int dac_idx) 12787 hda_nid_t nid, int pin_type, int dac_idx)
12466{ 12788{
12467 /* set as output */ 12789 alc_set_pin_output(codec, nid, pin_type);
12468 snd_hda_codec_write(codec, nid, 0,
12469 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
12470 snd_hda_codec_write(codec, nid, 0,
12471 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
12472} 12790}
12473 12791
12474static void alc861vd_auto_init_multi_out(struct hda_codec *codec) 12792static void alc861vd_auto_init_multi_out(struct hda_codec *codec)
@@ -12495,6 +12813,9 @@ static void alc861vd_auto_init_hp_out(struct hda_codec *codec)
12495 pin = spec->autocfg.hp_pins[0]; 12813 pin = spec->autocfg.hp_pins[0];
12496 if (pin) /* connect to front and use dac 0 */ 12814 if (pin) /* connect to front and use dac 0 */
12497 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); 12815 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
12816 pin = spec->autocfg.speaker_pins[0];
12817 if (pin)
12818 alc861vd_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
12498} 12819}
12499 12820
12500#define alc861vd_is_input_pin(nid) alc880_is_input_pin(nid) 12821#define alc861vd_is_input_pin(nid) alc880_is_input_pin(nid)
@@ -12698,9 +13019,12 @@ static int alc861vd_parse_auto_config(struct hda_codec *codec)
12698/* additional initialization for auto-configuration model */ 13019/* additional initialization for auto-configuration model */
12699static void alc861vd_auto_init(struct hda_codec *codec) 13020static void alc861vd_auto_init(struct hda_codec *codec)
12700{ 13021{
13022 struct alc_spec *spec = codec->spec;
12701 alc861vd_auto_init_multi_out(codec); 13023 alc861vd_auto_init_multi_out(codec);
12702 alc861vd_auto_init_hp_out(codec); 13024 alc861vd_auto_init_hp_out(codec);
12703 alc861vd_auto_init_analog_input(codec); 13025 alc861vd_auto_init_analog_input(codec);
13026 if (spec->unsol_event)
13027 alc_sku_automute(codec);
12704} 13028}
12705 13029
12706static int patch_alc861vd(struct hda_codec *codec) 13030static int patch_alc861vd(struct hda_codec *codec)
@@ -12751,6 +13075,7 @@ static int patch_alc861vd(struct hda_codec *codec)
12751 13075
12752 spec->adc_nids = alc861vd_adc_nids; 13076 spec->adc_nids = alc861vd_adc_nids;
12753 spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids); 13077 spec->num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids);
13078 spec->capsrc_nids = alc861vd_capsrc_nids;
12754 13079
12755 spec->mixers[spec->num_mixers] = alc861vd_capture_mixer; 13080 spec->mixers[spec->num_mixers] = alc861vd_capture_mixer;
12756 spec->num_mixers++; 13081 spec->num_mixers++;
@@ -12792,9 +13117,11 @@ static hda_nid_t alc662_adc_nids[1] = {
12792 /* ADC1-2 */ 13117 /* ADC1-2 */
12793 0x09, 13118 0x09,
12794}; 13119};
13120
13121static hda_nid_t alc662_capsrc_nids[1] = { 0x22 };
13122
12795/* input MUX */ 13123/* input MUX */
12796/* FIXME: should be a matrix-type input source selection */ 13124/* FIXME: should be a matrix-type input source selection */
12797
12798static struct hda_input_mux alc662_capture_source = { 13125static struct hda_input_mux alc662_capture_source = {
12799 .num_items = 4, 13126 .num_items = 4,
12800 .items = { 13127 .items = {
@@ -12823,33 +13150,8 @@ static struct hda_input_mux alc662_eeepc_capture_source = {
12823 13150
12824#define alc662_mux_enum_info alc_mux_enum_info 13151#define alc662_mux_enum_info alc_mux_enum_info
12825#define alc662_mux_enum_get alc_mux_enum_get 13152#define alc662_mux_enum_get alc_mux_enum_get
13153#define alc662_mux_enum_put alc882_mux_enum_put
12826 13154
12827static int alc662_mux_enum_put(struct snd_kcontrol *kcontrol,
12828 struct snd_ctl_elem_value *ucontrol)
12829{
12830 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
12831 struct alc_spec *spec = codec->spec;
12832 const struct hda_input_mux *imux = spec->input_mux;
12833 unsigned int adc_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id);
12834 static hda_nid_t capture_mixers[2] = { 0x23, 0x22 };
12835 hda_nid_t nid = capture_mixers[adc_idx];
12836 unsigned int *cur_val = &spec->cur_mux[adc_idx];
12837 unsigned int i, idx;
12838
12839 idx = ucontrol->value.enumerated.item[0];
12840 if (idx >= imux->num_items)
12841 idx = imux->num_items - 1;
12842 if (*cur_val == idx)
12843 return 0;
12844 for (i = 0; i < imux->num_items; i++) {
12845 unsigned int v = (i == idx) ? 0 : HDA_AMP_MUTE;
12846 snd_hda_codec_amp_stereo(codec, nid, HDA_INPUT,
12847 imux->items[i].index,
12848 HDA_AMP_MUTE, v);
12849 }
12850 *cur_val = idx;
12851 return 1;
12852}
12853/* 13155/*
12854 * 2ch mode 13156 * 2ch mode
12855 */ 13157 */
@@ -12918,13 +13220,13 @@ static struct hda_channel_mode alc662_5stack_modes[2] = {
12918static struct snd_kcontrol_new alc662_base_mixer[] = { 13220static struct snd_kcontrol_new alc662_base_mixer[] = {
12919 /* output mixer control */ 13221 /* output mixer control */
12920 HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT), 13222 HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
12921 HDA_CODEC_MUTE("Front Playback Switch", 0x02, 0x0, HDA_OUTPUT), 13223 HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
12922 HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT), 13224 HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
12923 HDA_CODEC_MUTE("Surround Playback Switch", 0x03, 0x0, HDA_OUTPUT), 13225 HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
12924 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT), 13226 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
12925 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT), 13227 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
12926 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT), 13228 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
12927 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT), 13229 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
12928 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT), 13230 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12929 13231
12930 /*Input mixer control */ 13232 /*Input mixer control */
@@ -12941,7 +13243,7 @@ static struct snd_kcontrol_new alc662_base_mixer[] = {
12941 13243
12942static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = { 13244static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
12943 HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT), 13245 HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12944 HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT), 13246 HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
12945 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT), 13247 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12946 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 13248 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12947 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 13249 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
@@ -12958,13 +13260,13 @@ static struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
12958 13260
12959static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = { 13261static struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
12960 HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT), 13262 HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
12961 HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT), 13263 HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
12962 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT), 13264 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
12963 HDA_BIND_MUTE("Surround Playback Switch", 0x03, 2, HDA_INPUT), 13265 HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
12964 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT), 13266 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
12965 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT), 13267 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
12966 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x04, 1, 2, HDA_INPUT), 13268 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
12967 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x04, 2, 2, HDA_INPUT), 13269 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
12968 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT), 13270 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
12969 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT), 13271 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
12970 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT), 13272 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
@@ -13313,6 +13615,7 @@ static const char *alc662_models[ALC662_MODEL_LAST] = {
13313}; 13615};
13314 13616
13315static struct snd_pci_quirk alc662_cfg_tbl[] = { 13617static struct snd_pci_quirk alc662_cfg_tbl[] = {
13618 SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
13316 SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701), 13619 SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
13317 SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20), 13620 SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
13318 SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E), 13621 SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
@@ -13326,8 +13629,6 @@ static struct alc_config_preset alc662_presets[] = {
13326 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 13629 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13327 .dac_nids = alc662_dac_nids, 13630 .dac_nids = alc662_dac_nids,
13328 .dig_out_nid = ALC662_DIGOUT_NID, 13631 .dig_out_nid = ALC662_DIGOUT_NID,
13329 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
13330 .adc_nids = alc662_adc_nids,
13331 .dig_in_nid = ALC662_DIGIN_NID, 13632 .dig_in_nid = ALC662_DIGIN_NID,
13332 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 13633 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
13333 .channel_mode = alc662_3ST_2ch_modes, 13634 .channel_mode = alc662_3ST_2ch_modes,
@@ -13340,8 +13641,6 @@ static struct alc_config_preset alc662_presets[] = {
13340 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 13641 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13341 .dac_nids = alc662_dac_nids, 13642 .dac_nids = alc662_dac_nids,
13342 .dig_out_nid = ALC662_DIGOUT_NID, 13643 .dig_out_nid = ALC662_DIGOUT_NID,
13343 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
13344 .adc_nids = alc662_adc_nids,
13345 .dig_in_nid = ALC662_DIGIN_NID, 13644 .dig_in_nid = ALC662_DIGIN_NID,
13346 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes), 13645 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
13347 .channel_mode = alc662_3ST_6ch_modes, 13646 .channel_mode = alc662_3ST_6ch_modes,
@@ -13354,8 +13653,6 @@ static struct alc_config_preset alc662_presets[] = {
13354 .init_verbs = { alc662_init_verbs }, 13653 .init_verbs = { alc662_init_verbs },
13355 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 13654 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13356 .dac_nids = alc662_dac_nids, 13655 .dac_nids = alc662_dac_nids,
13357 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
13358 .adc_nids = alc662_adc_nids,
13359 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes), 13656 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
13360 .channel_mode = alc662_3ST_6ch_modes, 13657 .channel_mode = alc662_3ST_6ch_modes,
13361 .need_dac_fix = 1, 13658 .need_dac_fix = 1,
@@ -13368,8 +13665,6 @@ static struct alc_config_preset alc662_presets[] = {
13368 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 13665 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13369 .dac_nids = alc662_dac_nids, 13666 .dac_nids = alc662_dac_nids,
13370 .dig_out_nid = ALC662_DIGOUT_NID, 13667 .dig_out_nid = ALC662_DIGOUT_NID,
13371 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
13372 .adc_nids = alc662_adc_nids,
13373 .dig_in_nid = ALC662_DIGIN_NID, 13668 .dig_in_nid = ALC662_DIGIN_NID,
13374 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes), 13669 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
13375 .channel_mode = alc662_5stack_modes, 13670 .channel_mode = alc662_5stack_modes,
@@ -13380,8 +13675,6 @@ static struct alc_config_preset alc662_presets[] = {
13380 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs }, 13675 .init_verbs = { alc662_init_verbs, alc662_sue_init_verbs },
13381 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 13676 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13382 .dac_nids = alc662_dac_nids, 13677 .dac_nids = alc662_dac_nids,
13383 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
13384 .adc_nids = alc662_adc_nids,
13385 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 13678 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
13386 .channel_mode = alc662_3ST_2ch_modes, 13679 .channel_mode = alc662_3ST_2ch_modes,
13387 .input_mux = &alc662_lenovo_101e_capture_source, 13680 .input_mux = &alc662_lenovo_101e_capture_source,
@@ -13394,8 +13687,6 @@ static struct alc_config_preset alc662_presets[] = {
13394 alc662_eeepc_sue_init_verbs }, 13687 alc662_eeepc_sue_init_verbs },
13395 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 13688 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13396 .dac_nids = alc662_dac_nids, 13689 .dac_nids = alc662_dac_nids,
13397 .num_adc_nids = ARRAY_SIZE(alc861vd_adc_nids),
13398 .adc_nids = alc662_adc_nids,
13399 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes), 13690 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
13400 .channel_mode = alc662_3ST_2ch_modes, 13691 .channel_mode = alc662_3ST_2ch_modes,
13401 .input_mux = &alc662_eeepc_capture_source, 13692 .input_mux = &alc662_eeepc_capture_source,
@@ -13409,8 +13700,6 @@ static struct alc_config_preset alc662_presets[] = {
13409 alc662_eeepc_ep20_sue_init_verbs }, 13700 alc662_eeepc_ep20_sue_init_verbs },
13410 .num_dacs = ARRAY_SIZE(alc662_dac_nids), 13701 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
13411 .dac_nids = alc662_dac_nids, 13702 .dac_nids = alc662_dac_nids,
13412 .num_adc_nids = ARRAY_SIZE(alc662_adc_nids),
13413 .adc_nids = alc662_adc_nids,
13414 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes), 13703 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
13415 .channel_mode = alc662_3ST_6ch_modes, 13704 .channel_mode = alc662_3ST_6ch_modes,
13416 .input_mux = &alc662_lenovo_101e_capture_source, 13705 .input_mux = &alc662_lenovo_101e_capture_source,
@@ -13556,11 +13845,7 @@ static void alc662_auto_set_output_and_unmute(struct hda_codec *codec,
13556 hda_nid_t nid, int pin_type, 13845 hda_nid_t nid, int pin_type,
13557 int dac_idx) 13846 int dac_idx)
13558{ 13847{
13559 /* set as output */ 13848 alc_set_pin_output(codec, nid, pin_type);
13560 snd_hda_codec_write(codec, nid, 0,
13561 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
13562 snd_hda_codec_write(codec, nid, 0,
13563 AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
13564 /* need the manual connection? */ 13849 /* need the manual connection? */
13565 if (alc880_is_multi_pin(nid)) { 13850 if (alc880_is_multi_pin(nid)) {
13566 struct alc_spec *spec = codec->spec; 13851 struct alc_spec *spec = codec->spec;
@@ -13595,6 +13880,9 @@ static void alc662_auto_init_hp_out(struct hda_codec *codec)
13595 if (pin) /* connect to front */ 13880 if (pin) /* connect to front */
13596 /* use dac 0 */ 13881 /* use dac 0 */
13597 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0); 13882 alc662_auto_set_output_and_unmute(codec, pin, PIN_HP, 0);
13883 pin = spec->autocfg.speaker_pins[0];
13884 if (pin)
13885 alc662_auto_set_output_and_unmute(codec, pin, PIN_OUT, 0);
13598} 13886}
13599 13887
13600#define alc662_is_input_pin(nid) alc880_is_input_pin(nid) 13888#define alc662_is_input_pin(nid) alc880_is_input_pin(nid)
@@ -13672,9 +13960,12 @@ static int alc662_parse_auto_config(struct hda_codec *codec)
13672/* additional initialization for auto-configuration model */ 13960/* additional initialization for auto-configuration model */
13673static void alc662_auto_init(struct hda_codec *codec) 13961static void alc662_auto_init(struct hda_codec *codec)
13674{ 13962{
13963 struct alc_spec *spec = codec->spec;
13675 alc662_auto_init_multi_out(codec); 13964 alc662_auto_init_multi_out(codec);
13676 alc662_auto_init_hp_out(codec); 13965 alc662_auto_init_hp_out(codec);
13677 alc662_auto_init_analog_input(codec); 13966 alc662_auto_init_analog_input(codec);
13967 if (spec->unsol_event)
13968 alc_sku_automute(codec);
13678} 13969}
13679 13970
13680static int patch_alc662(struct hda_codec *codec) 13971static int patch_alc662(struct hda_codec *codec)
@@ -13722,10 +14013,9 @@ static int patch_alc662(struct hda_codec *codec)
13722 spec->stream_digital_playback = &alc662_pcm_digital_playback; 14013 spec->stream_digital_playback = &alc662_pcm_digital_playback;
13723 spec->stream_digital_capture = &alc662_pcm_digital_capture; 14014 spec->stream_digital_capture = &alc662_pcm_digital_capture;
13724 14015
13725 if (!spec->adc_nids && spec->input_mux) { 14016 spec->adc_nids = alc662_adc_nids;
13726 spec->adc_nids = alc662_adc_nids; 14017 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids);
13727 spec->num_adc_nids = ARRAY_SIZE(alc662_adc_nids); 14018 spec->capsrc_nids = alc662_capsrc_nids;
13728 }
13729 14019
13730 spec->vmaster_nid = 0x02; 14020 spec->vmaster_nid = 0x02;
13731 14021
@@ -13761,6 +14051,8 @@ struct hda_codec_preset snd_hda_preset_realtek[] = {
13761 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 }, 14051 { .id = 0x10ec0880, .name = "ALC880", .patch = patch_alc880 },
13762 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 }, 14052 { .id = 0x10ec0882, .name = "ALC882", .patch = patch_alc882 },
13763 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 }, 14053 { .id = 0x10ec0883, .name = "ALC883", .patch = patch_alc883 },
14054 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
14055 .patch = patch_alc882 }, /* should be patch_alc883() in future */
13764 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 }, 14056 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
13765 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 }, 14057 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc883 },
13766 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 }, 14058 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc883 },
diff --git a/sound/pci/hda/patch_si3054.c b/sound/pci/hda/patch_si3054.c
index d22f5a6b850f..9332b63e406c 100644
--- a/sound/pci/hda/patch_si3054.c
+++ b/sound/pci/hda/patch_si3054.c
@@ -28,7 +28,7 @@
28#include <sound/core.h> 28#include <sound/core.h>
29#include "hda_codec.h" 29#include "hda_codec.h"
30#include "hda_local.h" 30#include "hda_local.h"
31 31#include "hda_patch.h"
32 32
33/* si3054 verbs */ 33/* si3054 verbs */
34#define SI3054_VERB_READ_NODE 0x900 34#define SI3054_VERB_READ_NODE 0x900
@@ -206,7 +206,7 @@ static int si3054_build_pcms(struct hda_codec *codec)
206 info->name = "Si3054 Modem"; 206 info->name = "Si3054 Modem";
207 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = si3054_pcm; 207 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = si3054_pcm;
208 info->stream[SNDRV_PCM_STREAM_CAPTURE] = si3054_pcm; 208 info->stream[SNDRV_PCM_STREAM_CAPTURE] = si3054_pcm;
209 info->is_modem = 1; 209 info->pcm_type = HDA_PCM_TYPE_MODEM;
210 return 0; 210 return 0;
211} 211}
212 212
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index caf48edaa921..b3a15d616873 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -32,6 +32,7 @@
32#include <sound/asoundef.h> 32#include <sound/asoundef.h>
33#include "hda_codec.h" 33#include "hda_codec.h"
34#include "hda_local.h" 34#include "hda_local.h"
35#include "hda_patch.h"
35 36
36#define NUM_CONTROL_ALLOC 32 37#define NUM_CONTROL_ALLOC 32
37#define STAC_PWR_EVENT 0x20 38#define STAC_PWR_EVENT 0x20
@@ -39,6 +40,7 @@
39 40
40enum { 41enum {
41 STAC_REF, 42 STAC_REF,
43 STAC_9200_OQO,
42 STAC_9200_DELL_D21, 44 STAC_9200_DELL_D21,
43 STAC_9200_DELL_D22, 45 STAC_9200_DELL_D22,
44 STAC_9200_DELL_D23, 46 STAC_9200_DELL_D23,
@@ -50,6 +52,7 @@ enum {
50 STAC_9200_DELL_M26, 52 STAC_9200_DELL_M26,
51 STAC_9200_DELL_M27, 53 STAC_9200_DELL_M27,
52 STAC_9200_GATEWAY, 54 STAC_9200_GATEWAY,
55 STAC_9200_PANASONIC,
53 STAC_9200_MODELS 56 STAC_9200_MODELS
54}; 57};
55 58
@@ -63,11 +66,14 @@ enum {
63 66
64enum { 67enum {
65 STAC_92HD73XX_REF, 68 STAC_92HD73XX_REF,
69 STAC_DELL_M6,
66 STAC_92HD73XX_MODELS 70 STAC_92HD73XX_MODELS
67}; 71};
68 72
69enum { 73enum {
70 STAC_92HD71BXX_REF, 74 STAC_92HD71BXX_REF,
75 STAC_DELL_M4_1,
76 STAC_DELL_M4_2,
71 STAC_92HD71BXX_MODELS 77 STAC_92HD71BXX_MODELS
72}; 78};
73 79
@@ -123,6 +129,7 @@ struct sigmatel_spec {
123 unsigned int hp_detect: 1; 129 unsigned int hp_detect: 1;
124 130
125 /* gpio lines */ 131 /* gpio lines */
132 unsigned int eapd_mask;
126 unsigned int gpio_mask; 133 unsigned int gpio_mask;
127 unsigned int gpio_dir; 134 unsigned int gpio_dir;
128 unsigned int gpio_data; 135 unsigned int gpio_data;
@@ -135,6 +142,7 @@ struct sigmatel_spec {
135 /* power management */ 142 /* power management */
136 unsigned int num_pwrs; 143 unsigned int num_pwrs;
137 hda_nid_t *pwr_nids; 144 hda_nid_t *pwr_nids;
145 hda_nid_t *dac_list;
138 146
139 /* playback */ 147 /* playback */
140 struct hda_input_mux *mono_mux; 148 struct hda_input_mux *mono_mux;
@@ -173,6 +181,7 @@ struct sigmatel_spec {
173 /* i/o switches */ 181 /* i/o switches */
174 unsigned int io_switch[2]; 182 unsigned int io_switch[2];
175 unsigned int clfe_swap; 183 unsigned int clfe_swap;
184 unsigned int hp_switch;
176 unsigned int aloopback; 185 unsigned int aloopback;
177 186
178 struct hda_pcm pcm_rec[2]; /* PCM information */ 187 struct hda_pcm pcm_rec[2]; /* PCM information */
@@ -184,9 +193,6 @@ struct sigmatel_spec {
184 struct hda_input_mux private_dimux; 193 struct hda_input_mux private_dimux;
185 struct hda_input_mux private_imux; 194 struct hda_input_mux private_imux;
186 struct hda_input_mux private_mono_mux; 195 struct hda_input_mux private_mono_mux;
187
188 /* virtual master */
189 unsigned int vmaster_tlv[4];
190}; 196};
191 197
192static hda_nid_t stac9200_adc_nids[1] = { 198static hda_nid_t stac9200_adc_nids[1] = {
@@ -244,7 +250,7 @@ static hda_nid_t stac92hd71bxx_dmux_nids[1] = {
244 0x1c, 250 0x1c,
245}; 251};
246 252
247static hda_nid_t stac92hd71bxx_dac_nids[2] = { 253static hda_nid_t stac92hd71bxx_dac_nids[1] = {
248 0x10, /*0x11, */ 254 0x10, /*0x11, */
249}; 255};
250 256
@@ -290,6 +296,10 @@ static hda_nid_t stac927x_mux_nids[3] = {
290 0x15, 0x16, 0x17 296 0x15, 0x16, 0x17
291}; 297};
292 298
299static hda_nid_t stac927x_dac_nids[6] = {
300 0x02, 0x03, 0x04, 0x05, 0x06, 0
301};
302
293static hda_nid_t stac927x_dmux_nids[1] = { 303static hda_nid_t stac927x_dmux_nids[1] = {
294 0x1b, 304 0x1b,
295}; 305};
@@ -331,10 +341,10 @@ static hda_nid_t stac922x_pin_nids[10] = {
331 0x0f, 0x10, 0x11, 0x15, 0x1b, 341 0x0f, 0x10, 0x11, 0x15, 0x1b,
332}; 342};
333 343
334static hda_nid_t stac92hd73xx_pin_nids[12] = { 344static hda_nid_t stac92hd73xx_pin_nids[13] = {
335 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 345 0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
336 0x0f, 0x10, 0x11, 0x12, 0x13, 346 0x0f, 0x10, 0x11, 0x12, 0x13,
337 0x14, 0x22 347 0x14, 0x1e, 0x22
338}; 348};
339 349
340static hda_nid_t stac92hd71bxx_pin_nids[10] = { 350static hda_nid_t stac92hd71bxx_pin_nids[10] = {
@@ -527,6 +537,43 @@ static struct hda_verb stac92hd73xx_6ch_core_init[] = {
527 {} 537 {}
528}; 538};
529 539
540static struct hda_verb dell_eq_core_init[] = {
541 /* set master volume to max value without distortion
542 * and direct control */
543 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xec},
544 /* setup audio connections */
545 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
546 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
547 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x02},
548 /* setup adcs to point to mixer */
549 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
550 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
551 /* setup import muxs */
552 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
553 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
554 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
555 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
556 {}
557};
558
559static struct hda_verb dell_m6_core_init[] = {
560 /* set master volume and direct control */
561 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
562 /* setup audio connections */
563 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00},
564 { 0x0a, AC_VERB_SET_CONNECT_SEL, 0x01},
565 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x02},
566 /* setup adcs to point to mixer */
567 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x0b},
568 { 0x21, AC_VERB_SET_CONNECT_SEL, 0x0b},
569 /* setup import muxs */
570 { 0x28, AC_VERB_SET_CONNECT_SEL, 0x01},
571 { 0x29, AC_VERB_SET_CONNECT_SEL, 0x01},
572 { 0x2a, AC_VERB_SET_CONNECT_SEL, 0x01},
573 { 0x2b, AC_VERB_SET_CONNECT_SEL, 0x00},
574 {}
575};
576
530static struct hda_verb stac92hd73xx_8ch_core_init[] = { 577static struct hda_verb stac92hd73xx_8ch_core_init[] = {
531 /* set master volume and direct control */ 578 /* set master volume and direct control */
532 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff}, 579 { 0x1f, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
@@ -910,6 +957,11 @@ static int stac92xx_build_controls(struct hda_codec *codec)
910 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid); 957 err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
911 if (err < 0) 958 if (err < 0)
912 return err; 959 return err;
960 err = snd_hda_create_spdif_share_sw(codec,
961 &spec->multiout);
962 if (err < 0)
963 return err;
964 spec->multiout.share_spdif = 1;
913 } 965 }
914 if (spec->dig_in_nid) { 966 if (spec->dig_in_nid) {
915 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); 967 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
@@ -919,10 +971,11 @@ static int stac92xx_build_controls(struct hda_codec *codec)
919 971
920 /* if we have no master control, let's create it */ 972 /* if we have no master control, let's create it */
921 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) { 973 if (!snd_hda_find_mixer_ctl(codec, "Master Playback Volume")) {
974 unsigned int vmaster_tlv[4];
922 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0], 975 snd_hda_set_vmaster_tlv(codec, spec->multiout.dac_nids[0],
923 HDA_OUTPUT, spec->vmaster_tlv); 976 HDA_OUTPUT, vmaster_tlv);
924 err = snd_hda_add_vmaster(codec, "Master Playback Volume", 977 err = snd_hda_add_vmaster(codec, "Master Playback Volume",
925 spec->vmaster_tlv, slave_vols); 978 vmaster_tlv, slave_vols);
926 if (err < 0) 979 if (err < 0)
927 return err; 980 return err;
928 } 981 }
@@ -1052,9 +1105,15 @@ static unsigned int dell9200_m27_pin_configs[8] = {
1052 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc, 1105 0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
1053}; 1106};
1054 1107
1108static unsigned int oqo9200_pin_configs[8] = {
1109 0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
1110 0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
1111};
1112
1055 1113
1056static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = { 1114static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1057 [STAC_REF] = ref9200_pin_configs, 1115 [STAC_REF] = ref9200_pin_configs,
1116 [STAC_9200_OQO] = oqo9200_pin_configs,
1058 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs, 1117 [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
1059 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs, 1118 [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
1060 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs, 1119 [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
@@ -1065,10 +1124,12 @@ static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
1065 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs, 1124 [STAC_9200_DELL_M25] = dell9200_m25_pin_configs,
1066 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs, 1125 [STAC_9200_DELL_M26] = dell9200_m26_pin_configs,
1067 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs, 1126 [STAC_9200_DELL_M27] = dell9200_m27_pin_configs,
1127 [STAC_9200_PANASONIC] = ref9200_pin_configs,
1068}; 1128};
1069 1129
1070static const char *stac9200_models[STAC_9200_MODELS] = { 1130static const char *stac9200_models[STAC_9200_MODELS] = {
1071 [STAC_REF] = "ref", 1131 [STAC_REF] = "ref",
1132 [STAC_9200_OQO] = "oqo",
1072 [STAC_9200_DELL_D21] = "dell-d21", 1133 [STAC_9200_DELL_D21] = "dell-d21",
1073 [STAC_9200_DELL_D22] = "dell-d22", 1134 [STAC_9200_DELL_D22] = "dell-d22",
1074 [STAC_9200_DELL_D23] = "dell-d23", 1135 [STAC_9200_DELL_D23] = "dell-d23",
@@ -1080,6 +1141,7 @@ static const char *stac9200_models[STAC_9200_MODELS] = {
1080 [STAC_9200_DELL_M26] = "dell-m26", 1141 [STAC_9200_DELL_M26] = "dell-m26",
1081 [STAC_9200_DELL_M27] = "dell-m27", 1142 [STAC_9200_DELL_M27] = "dell-m27",
1082 [STAC_9200_GATEWAY] = "gateway", 1143 [STAC_9200_GATEWAY] = "gateway",
1144 [STAC_9200_PANASONIC] = "panasonic",
1083}; 1145};
1084 1146
1085static struct snd_pci_quirk stac9200_cfg_tbl[] = { 1147static struct snd_pci_quirk stac9200_cfg_tbl[] = {
@@ -1146,13 +1208,15 @@ static struct snd_pci_quirk stac9200_cfg_tbl[] = {
1146 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6, 1208 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x01f6,
1147 "unknown Dell", STAC_9200_DELL_M26), 1209 "unknown Dell", STAC_9200_DELL_M26),
1148 /* Panasonic */ 1210 /* Panasonic */
1149 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_REF), 1211 SND_PCI_QUIRK(0x10f7, 0x8338, "Panasonic CF-74", STAC_9200_PANASONIC),
1150 /* Gateway machines needs EAPD to be set on resume */ 1212 /* Gateway machines needs EAPD to be set on resume */
1151 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY), 1213 SND_PCI_QUIRK(0x107b, 0x0205, "Gateway S-7110M", STAC_9200_GATEWAY),
1152 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*", 1214 SND_PCI_QUIRK(0x107b, 0x0317, "Gateway MT3423, MX341*",
1153 STAC_9200_GATEWAY), 1215 STAC_9200_GATEWAY),
1154 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707", 1216 SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
1155 STAC_9200_GATEWAY), 1217 STAC_9200_GATEWAY),
1218 /* OQO Mobile */
1219 SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
1156 {} /* terminator */ 1220 {} /* terminator */
1157}; 1221};
1158 1222
@@ -1202,24 +1266,48 @@ static struct snd_pci_quirk stac925x_cfg_tbl[] = {
1202 {} /* terminator */ 1266 {} /* terminator */
1203}; 1267};
1204 1268
1205static unsigned int ref92hd73xx_pin_configs[12] = { 1269static unsigned int ref92hd73xx_pin_configs[13] = {
1206 0x02214030, 0x02a19040, 0x01a19020, 0x02214030, 1270 0x02214030, 0x02a19040, 0x01a19020, 0x02214030,
1207 0x0181302e, 0x01014010, 0x01014020, 0x01014030, 1271 0x0181302e, 0x01014010, 0x01014020, 0x01014030,
1208 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050, 1272 0x02319040, 0x90a000f0, 0x90a000f0, 0x01452050,
1273 0x01452050,
1274};
1275
1276static unsigned int dell_m6_pin_configs[13] = {
1277 0x0321101f, 0x4f00000f, 0x4f0000f0, 0x90170110,
1278 0x03a11020, 0x0321101f, 0x4f0000f0, 0x4f0000f0,
1279 0x4f0000f0, 0x90a60160, 0x4f0000f0, 0x4f0000f0,
1280 0x4f0000f0,
1209}; 1281};
1210 1282
1211static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = { 1283static unsigned int *stac92hd73xx_brd_tbl[STAC_92HD73XX_MODELS] = {
1212 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs, 1284 [STAC_92HD73XX_REF] = ref92hd73xx_pin_configs,
1285 [STAC_DELL_M6] = dell_m6_pin_configs,
1213}; 1286};
1214 1287
1215static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = { 1288static const char *stac92hd73xx_models[STAC_92HD73XX_MODELS] = {
1216 [STAC_92HD73XX_REF] = "ref", 1289 [STAC_92HD73XX_REF] = "ref",
1290 [STAC_DELL_M6] = "dell-m6",
1217}; 1291};
1218 1292
1219static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = { 1293static struct snd_pci_quirk stac92hd73xx_cfg_tbl[] = {
1220 /* SigmaTel reference board */ 1294 /* SigmaTel reference board */
1221 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, 1295 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1222 "DFI LanParty", STAC_92HD73XX_REF), 1296 "DFI LanParty", STAC_92HD73XX_REF),
1297 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0254,
1298 "unknown Dell", STAC_DELL_M6),
1299 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0255,
1300 "unknown Dell", STAC_DELL_M6),
1301 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0256,
1302 "unknown Dell", STAC_DELL_M6),
1303 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0257,
1304 "unknown Dell", STAC_DELL_M6),
1305 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025e,
1306 "unknown Dell", STAC_DELL_M6),
1307 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x025f,
1308 "unknown Dell", STAC_DELL_M6),
1309 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0271,
1310 "unknown Dell", STAC_DELL_M6),
1223 {} /* terminator */ 1311 {} /* terminator */
1224}; 1312};
1225 1313
@@ -1229,18 +1317,56 @@ static unsigned int ref92hd71bxx_pin_configs[10] = {
1229 0x90a000f0, 0x01452050, 1317 0x90a000f0, 0x01452050,
1230}; 1318};
1231 1319
1320static unsigned int dell_m4_1_pin_configs[13] = {
1321 0x0421101f, 0x04a11221, 0x40f000f0, 0x90170110,
1322 0x23a1902e, 0x23014250, 0x40f000f0, 0x90a000f0,
1323 0x40f000f0, 0x4f0000f0,
1324};
1325
1326static unsigned int dell_m4_2_pin_configs[13] = {
1327 0x0421101f, 0x04a11221, 0x90a70330, 0x90170110,
1328 0x23a1902e, 0x23014250, 0x40f000f0, 0x40f000f0,
1329 0x40f000f0, 0x044413b0,
1330};
1331
1232static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = { 1332static unsigned int *stac92hd71bxx_brd_tbl[STAC_92HD71BXX_MODELS] = {
1233 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs, 1333 [STAC_92HD71BXX_REF] = ref92hd71bxx_pin_configs,
1334 [STAC_DELL_M4_1] = dell_m4_1_pin_configs,
1335 [STAC_DELL_M4_2] = dell_m4_2_pin_configs,
1234}; 1336};
1235 1337
1236static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = { 1338static const char *stac92hd71bxx_models[STAC_92HD71BXX_MODELS] = {
1237 [STAC_92HD71BXX_REF] = "ref", 1339 [STAC_92HD71BXX_REF] = "ref",
1340 [STAC_DELL_M4_1] = "dell-m4-1",
1341 [STAC_DELL_M4_2] = "dell-m4-2",
1238}; 1342};
1239 1343
1240static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = { 1344static struct snd_pci_quirk stac92hd71bxx_cfg_tbl[] = {
1241 /* SigmaTel reference board */ 1345 /* SigmaTel reference board */
1242 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668, 1346 SND_PCI_QUIRK(PCI_VENDOR_ID_INTEL, 0x2668,
1243 "DFI LanParty", STAC_92HD71BXX_REF), 1347 "DFI LanParty", STAC_92HD71BXX_REF),
1348 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0233,
1349 "unknown Dell", STAC_DELL_M4_1),
1350 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0234,
1351 "unknown Dell", STAC_DELL_M4_1),
1352 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0250,
1353 "unknown Dell", STAC_DELL_M4_1),
1354 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024f,
1355 "unknown Dell", STAC_DELL_M4_1),
1356 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x024d,
1357 "unknown Dell", STAC_DELL_M4_1),
1358 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0251,
1359 "unknown Dell", STAC_DELL_M4_1),
1360 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0277,
1361 "unknown Dell", STAC_DELL_M4_1),
1362 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0263,
1363 "unknown Dell", STAC_DELL_M4_2),
1364 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0265,
1365 "unknown Dell", STAC_DELL_M4_2),
1366 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0262,
1367 "unknown Dell", STAC_DELL_M4_2),
1368 SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0264,
1369 "unknown Dell", STAC_DELL_M4_2),
1244 {} /* terminator */ 1370 {} /* terminator */
1245}; 1371};
1246 1372
@@ -1733,7 +1859,8 @@ static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
1733 struct snd_pcm_substream *substream) 1859 struct snd_pcm_substream *substream)
1734{ 1860{
1735 struct sigmatel_spec *spec = codec->spec; 1861 struct sigmatel_spec *spec = codec->spec;
1736 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream); 1862 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
1863 hinfo);
1737} 1864}
1738 1865
1739static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 1866static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
@@ -1807,7 +1934,7 @@ static int stac92xx_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
1807{ 1934{
1808 struct sigmatel_spec *spec = codec->spec; 1935 struct sigmatel_spec *spec = codec->spec;
1809 1936
1810 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 0, 0, 0); 1937 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
1811 return 0; 1938 return 0;
1812} 1939}
1813 1940
@@ -1889,6 +2016,7 @@ static int stac92xx_build_pcms(struct hda_codec *codec)
1889 codec->num_pcms++; 2016 codec->num_pcms++;
1890 info++; 2017 info++;
1891 info->name = "STAC92xx Digital"; 2018 info->name = "STAC92xx Digital";
2019 info->pcm_type = HDA_PCM_TYPE_SPDIF;
1892 if (spec->multiout.dig_out_nid) { 2020 if (spec->multiout.dig_out_nid) {
1893 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback; 2021 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
1894 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid; 2022 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
@@ -1925,6 +2053,34 @@ static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int
1925 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type); 2053 AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
1926} 2054}
1927 2055
2056#define stac92xx_hp_switch_info snd_ctl_boolean_mono_info
2057
2058static int stac92xx_hp_switch_get(struct snd_kcontrol *kcontrol,
2059 struct snd_ctl_elem_value *ucontrol)
2060{
2061 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2062 struct sigmatel_spec *spec = codec->spec;
2063
2064 ucontrol->value.integer.value[0] = spec->hp_switch;
2065 return 0;
2066}
2067
2068static int stac92xx_hp_switch_put(struct snd_kcontrol *kcontrol,
2069 struct snd_ctl_elem_value *ucontrol)
2070{
2071 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
2072 struct sigmatel_spec *spec = codec->spec;
2073
2074 spec->hp_switch = ucontrol->value.integer.value[0];
2075
2076 /* check to be sure that the ports are upto date with
2077 * switch changes
2078 */
2079 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
2080
2081 return 1;
2082}
2083
1928#define stac92xx_io_switch_info snd_ctl_boolean_mono_info 2084#define stac92xx_io_switch_info snd_ctl_boolean_mono_info
1929 2085
1930static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 2086static int stac92xx_io_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
@@ -1996,6 +2152,15 @@ static int stac92xx_clfe_switch_put(struct snd_kcontrol *kcontrol,
1996 return 1; 2152 return 1;
1997} 2153}
1998 2154
2155#define STAC_CODEC_HP_SWITCH(xname) \
2156 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2157 .name = xname, \
2158 .index = 0, \
2159 .info = stac92xx_hp_switch_info, \
2160 .get = stac92xx_hp_switch_get, \
2161 .put = stac92xx_hp_switch_put, \
2162 }
2163
1999#define STAC_CODEC_IO_SWITCH(xname, xpval) \ 2164#define STAC_CODEC_IO_SWITCH(xname, xpval) \
2000 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 2165 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
2001 .name = xname, \ 2166 .name = xname, \
@@ -2020,6 +2185,7 @@ enum {
2020 STAC_CTL_WIDGET_VOL, 2185 STAC_CTL_WIDGET_VOL,
2021 STAC_CTL_WIDGET_MUTE, 2186 STAC_CTL_WIDGET_MUTE,
2022 STAC_CTL_WIDGET_MONO_MUX, 2187 STAC_CTL_WIDGET_MONO_MUX,
2188 STAC_CTL_WIDGET_HP_SWITCH,
2023 STAC_CTL_WIDGET_IO_SWITCH, 2189 STAC_CTL_WIDGET_IO_SWITCH,
2024 STAC_CTL_WIDGET_CLFE_SWITCH 2190 STAC_CTL_WIDGET_CLFE_SWITCH
2025}; 2191};
@@ -2028,6 +2194,7 @@ static struct snd_kcontrol_new stac92xx_control_templates[] = {
2028 HDA_CODEC_VOLUME(NULL, 0, 0, 0), 2194 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2029 HDA_CODEC_MUTE(NULL, 0, 0, 0), 2195 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2030 STAC_MONO_MUX, 2196 STAC_MONO_MUX,
2197 STAC_CODEC_HP_SWITCH(NULL),
2031 STAC_CODEC_IO_SWITCH(NULL, 0), 2198 STAC_CODEC_IO_SWITCH(NULL, 0),
2032 STAC_CODEC_CLFE_SWITCH(NULL, 0), 2199 STAC_CODEC_CLFE_SWITCH(NULL, 0),
2033}; 2200};
@@ -2222,6 +2389,29 @@ static int create_controls(struct sigmatel_spec *spec, const char *pfx, hda_nid_
2222 return 0; 2389 return 0;
2223} 2390}
2224 2391
2392static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
2393{
2394 if (!spec->multiout.hp_nid)
2395 spec->multiout.hp_nid = nid;
2396 else if (spec->multiout.num_dacs > 4) {
2397 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
2398 return 1;
2399 } else {
2400 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
2401 spec->multiout.num_dacs++;
2402 }
2403 return 0;
2404}
2405
2406static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2407{
2408 if (is_in_dac_nids(spec, nid))
2409 return 1;
2410 if (spec->multiout.hp_nid == nid)
2411 return 1;
2412 return 0;
2413}
2414
2225/* add playback controls from the parsed DAC table */ 2415/* add playback controls from the parsed DAC table */
2226static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec, 2416static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
2227 const struct auto_pin_cfg *cfg) 2417 const struct auto_pin_cfg *cfg)
@@ -2236,7 +2426,7 @@ static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
2236 unsigned int wid_caps, pincap; 2426 unsigned int wid_caps, pincap;
2237 2427
2238 2428
2239 for (i = 0; i < cfg->line_outs; i++) { 2429 for (i = 0; i < cfg->line_outs && i < spec->multiout.num_dacs; i++) {
2240 if (!spec->multiout.dac_nids[i]) 2430 if (!spec->multiout.dac_nids[i])
2241 continue; 2431 continue;
2242 2432
@@ -2269,6 +2459,14 @@ static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
2269 } 2459 }
2270 } 2460 }
2271 2461
2462 if (cfg->hp_outs > 1) {
2463 err = stac92xx_add_control(spec,
2464 STAC_CTL_WIDGET_HP_SWITCH,
2465 "Headphone as Line Out Switch", 0);
2466 if (err < 0)
2467 return err;
2468 }
2469
2272 if (spec->line_switch) { 2470 if (spec->line_switch) {
2273 nid = cfg->input_pins[AUTO_PIN_LINE]; 2471 nid = cfg->input_pins[AUTO_PIN_LINE];
2274 pincap = snd_hda_param_read(codec, nid, 2472 pincap = snd_hda_param_read(codec, nid,
@@ -2284,10 +2482,11 @@ static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
2284 2482
2285 if (spec->mic_switch) { 2483 if (spec->mic_switch) {
2286 unsigned int def_conf; 2484 unsigned int def_conf;
2287 nid = cfg->input_pins[AUTO_PIN_MIC]; 2485 unsigned int mic_pin = AUTO_PIN_MIC;
2486again:
2487 nid = cfg->input_pins[mic_pin];
2288 def_conf = snd_hda_codec_read(codec, nid, 0, 2488 def_conf = snd_hda_codec_read(codec, nid, 0,
2289 AC_VERB_GET_CONFIG_DEFAULT, 0); 2489 AC_VERB_GET_CONFIG_DEFAULT, 0);
2290
2291 /* some laptops have an internal analog microphone 2490 /* some laptops have an internal analog microphone
2292 * which can't be used as a output */ 2491 * which can't be used as a output */
2293 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) { 2492 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
@@ -2297,38 +2496,22 @@ static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
2297 err = stac92xx_add_control(spec, 2496 err = stac92xx_add_control(spec,
2298 STAC_CTL_WIDGET_IO_SWITCH, 2497 STAC_CTL_WIDGET_IO_SWITCH,
2299 "Mic as Output Switch", (nid << 8) | 1); 2498 "Mic as Output Switch", (nid << 8) | 1);
2499 nid = snd_hda_codec_read(codec, nid, 0,
2500 AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
2501 if (!check_in_dac_nids(spec, nid))
2502 add_spec_dacs(spec, nid);
2300 if (err < 0) 2503 if (err < 0)
2301 return err; 2504 return err;
2302 } 2505 }
2506 } else if (mic_pin == AUTO_PIN_MIC) {
2507 mic_pin = AUTO_PIN_FRONT_MIC;
2508 goto again;
2303 } 2509 }
2304 } 2510 }
2305 2511
2306 return 0; 2512 return 0;
2307} 2513}
2308 2514
2309static int check_in_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2310{
2311 if (is_in_dac_nids(spec, nid))
2312 return 1;
2313 if (spec->multiout.hp_nid == nid)
2314 return 1;
2315 return 0;
2316}
2317
2318static int add_spec_dacs(struct sigmatel_spec *spec, hda_nid_t nid)
2319{
2320 if (!spec->multiout.hp_nid)
2321 spec->multiout.hp_nid = nid;
2322 else if (spec->multiout.num_dacs > 4) {
2323 printk(KERN_WARNING "stac92xx: No space for DAC 0x%x\n", nid);
2324 return 1;
2325 } else {
2326 spec->multiout.dac_nids[spec->multiout.num_dacs] = nid;
2327 spec->multiout.num_dacs++;
2328 }
2329 return 0;
2330}
2331
2332/* add playback controls for Speaker and HP outputs */ 2515/* add playback controls for Speaker and HP outputs */
2333static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, 2516static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
2334 struct auto_pin_cfg *cfg) 2517 struct auto_pin_cfg *cfg)
@@ -2378,12 +2561,8 @@ static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec,
2378 return err; 2561 return err;
2379 } 2562 }
2380 if (spec->multiout.hp_nid) { 2563 if (spec->multiout.hp_nid) {
2381 const char *pfx; 2564 err = create_controls(spec, "Headphone",
2382 if (old_num_dacs == spec->multiout.num_dacs) 2565 spec->multiout.hp_nid, 3);
2383 pfx = "Master";
2384 else
2385 pfx = "Headphone";
2386 err = create_controls(spec, pfx, spec->multiout.hp_nid, 3);
2387 if (err < 0) 2566 if (err < 0)
2388 return err; 2567 return err;
2389 } 2568 }
@@ -2745,7 +2924,7 @@ static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
2745 */ 2924 */
2746 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) { 2925 for (i = 0; i < spec->autocfg.speaker_outs && lfe_pin == 0x0; i++) {
2747 hda_nid_t pin = spec->autocfg.speaker_pins[i]; 2926 hda_nid_t pin = spec->autocfg.speaker_pins[i];
2748 unsigned long wcaps = get_wcaps(codec, pin); 2927 unsigned int wcaps = get_wcaps(codec, pin);
2749 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP); 2928 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2750 if (wcaps == AC_WCAP_OUT_AMP) 2929 if (wcaps == AC_WCAP_OUT_AMP)
2751 /* found a mono speaker with an amp, must be lfe */ 2930 /* found a mono speaker with an amp, must be lfe */
@@ -2756,12 +2935,12 @@ static int stac9200_auto_create_lfe_ctls(struct hda_codec *codec,
2756 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) { 2935 if (lfe_pin == 0 && spec->autocfg.speaker_outs == 0) {
2757 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) { 2936 for (i = 0; i < spec->autocfg.line_outs && lfe_pin == 0x0; i++) {
2758 hda_nid_t pin = spec->autocfg.line_out_pins[i]; 2937 hda_nid_t pin = spec->autocfg.line_out_pins[i];
2759 unsigned long cfg; 2938 unsigned int defcfg;
2760 cfg = snd_hda_codec_read(codec, pin, 0, 2939 defcfg = snd_hda_codec_read(codec, pin, 0,
2761 AC_VERB_GET_CONFIG_DEFAULT, 2940 AC_VERB_GET_CONFIG_DEFAULT,
2762 0x00); 2941 0x00);
2763 if (get_defcfg_device(cfg) == AC_JACK_SPEAKER) { 2942 if (get_defcfg_device(defcfg) == AC_JACK_SPEAKER) {
2764 unsigned long wcaps = get_wcaps(codec, pin); 2943 unsigned int wcaps = get_wcaps(codec, pin);
2765 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP); 2944 wcaps &= (AC_WCAP_STEREO | AC_WCAP_OUT_AMP);
2766 if (wcaps == AC_WCAP_OUT_AMP) 2945 if (wcaps == AC_WCAP_OUT_AMP)
2767 /* found a mono speaker with an amp, 2946 /* found a mono speaker with an amp,
@@ -2866,6 +3045,19 @@ static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
2866 return 0; /* nid is not a HP-Out */ 3045 return 0; /* nid is not a HP-Out */
2867}; 3046};
2868 3047
3048static void stac92xx_power_down(struct hda_codec *codec)
3049{
3050 struct sigmatel_spec *spec = codec->spec;
3051
3052 /* power down inactive DACs */
3053 hda_nid_t *dac;
3054 for (dac = spec->dac_list; *dac; dac++)
3055 if (!is_in_dac_nids(spec, *dac) &&
3056 spec->multiout.hp_nid != *dac)
3057 snd_hda_codec_write_cache(codec, *dac, 0,
3058 AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
3059}
3060
2869static int stac92xx_init(struct hda_codec *codec) 3061static int stac92xx_init(struct hda_codec *codec)
2870{ 3062{
2871 struct sigmatel_spec *spec = codec->spec; 3063 struct sigmatel_spec *spec = codec->spec;
@@ -2909,16 +3101,21 @@ static int stac92xx_init(struct hda_codec *codec)
2909 ? STAC_HP_EVENT : STAC_PWR_EVENT; 3101 ? STAC_HP_EVENT : STAC_PWR_EVENT;
2910 int pinctl = snd_hda_codec_read(codec, spec->pwr_nids[i], 3102 int pinctl = snd_hda_codec_read(codec, spec->pwr_nids[i],
2911 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0); 3103 0, AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
3104 int def_conf = snd_hda_codec_read(codec, spec->pwr_nids[i],
3105 0, AC_VERB_GET_CONFIG_DEFAULT, 0);
2912 /* outputs are only ports capable of power management 3106 /* outputs are only ports capable of power management
2913 * any attempts on powering down a input port cause the 3107 * any attempts on powering down a input port cause the
2914 * referenced VREF to act quirky. 3108 * referenced VREF to act quirky.
2915 */ 3109 */
2916 if (pinctl & AC_PINCTL_IN_EN) 3110 if (pinctl & AC_PINCTL_IN_EN)
2917 continue; 3111 continue;
3112 if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED)
3113 continue;
2918 enable_pin_detect(codec, spec->pwr_nids[i], event | i); 3114 enable_pin_detect(codec, spec->pwr_nids[i], event | i);
2919 codec->patch_ops.unsol_event(codec, (event | i) << 26); 3115 codec->patch_ops.unsol_event(codec, (event | i) << 26);
2920 } 3116 }
2921 3117 if (spec->dac_list)
3118 stac92xx_power_down(codec);
2922 if (cfg->dig_out_pin) 3119 if (cfg->dig_out_pin)
2923 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin, 3120 stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
2924 AC_PINCTL_OUT_EN); 3121 AC_PINCTL_OUT_EN);
@@ -3014,6 +3211,7 @@ static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
3014{ 3211{
3015 struct sigmatel_spec *spec = codec->spec; 3212 struct sigmatel_spec *spec = codec->spec;
3016 struct auto_pin_cfg *cfg = &spec->autocfg; 3213 struct auto_pin_cfg *cfg = &spec->autocfg;
3214 int nid = cfg->hp_pins[cfg->hp_outs - 1];
3017 int i, presence; 3215 int i, presence;
3018 3216
3019 presence = 0; 3217 presence = 0;
@@ -3024,26 +3222,42 @@ static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
3024 for (i = 0; i < cfg->hp_outs; i++) { 3222 for (i = 0; i < cfg->hp_outs; i++) {
3025 if (presence) 3223 if (presence)
3026 break; 3224 break;
3225 if (spec->hp_switch && cfg->hp_pins[i] == nid)
3226 break;
3027 presence = get_hp_pin_presence(codec, cfg->hp_pins[i]); 3227 presence = get_hp_pin_presence(codec, cfg->hp_pins[i]);
3028 } 3228 }
3029 3229
3030 if (presence) { 3230 if (presence) {
3031 /* disable lineouts, enable hp */ 3231 /* disable lineouts, enable hp */
3232 if (spec->hp_switch)
3233 stac92xx_reset_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3032 for (i = 0; i < cfg->line_outs; i++) 3234 for (i = 0; i < cfg->line_outs; i++)
3033 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i], 3235 stac92xx_reset_pinctl(codec, cfg->line_out_pins[i],
3034 AC_PINCTL_OUT_EN); 3236 AC_PINCTL_OUT_EN);
3035 for (i = 0; i < cfg->speaker_outs; i++) 3237 for (i = 0; i < cfg->speaker_outs; i++)
3036 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i], 3238 stac92xx_reset_pinctl(codec, cfg->speaker_pins[i],
3037 AC_PINCTL_OUT_EN); 3239 AC_PINCTL_OUT_EN);
3240 if (spec->eapd_mask)
3241 stac_gpio_set(codec, spec->gpio_mask,
3242 spec->gpio_dir, spec->gpio_data &
3243 ~spec->eapd_mask);
3038 } else { 3244 } else {
3039 /* enable lineouts, disable hp */ 3245 /* enable lineouts, disable hp */
3246 if (spec->hp_switch)
3247 stac92xx_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3040 for (i = 0; i < cfg->line_outs; i++) 3248 for (i = 0; i < cfg->line_outs; i++)
3041 stac92xx_set_pinctl(codec, cfg->line_out_pins[i], 3249 stac92xx_set_pinctl(codec, cfg->line_out_pins[i],
3042 AC_PINCTL_OUT_EN); 3250 AC_PINCTL_OUT_EN);
3043 for (i = 0; i < cfg->speaker_outs; i++) 3251 for (i = 0; i < cfg->speaker_outs; i++)
3044 stac92xx_set_pinctl(codec, cfg->speaker_pins[i], 3252 stac92xx_set_pinctl(codec, cfg->speaker_pins[i],
3045 AC_PINCTL_OUT_EN); 3253 AC_PINCTL_OUT_EN);
3254 if (spec->eapd_mask)
3255 stac_gpio_set(codec, spec->gpio_mask,
3256 spec->gpio_dir, spec->gpio_data |
3257 spec->eapd_mask);
3046 } 3258 }
3259 if (!spec->hp_switch && cfg->hp_outs > 1 && presence)
3260 stac92xx_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
3047} 3261}
3048 3262
3049static void stac92xx_pin_sense(struct hda_codec *codec, int idx) 3263static void stac92xx_pin_sense(struct hda_codec *codec, int idx)
@@ -3091,6 +3305,9 @@ static int stac92xx_resume(struct hda_codec *codec)
3091 spec->gpio_dir, spec->gpio_data); 3305 spec->gpio_dir, spec->gpio_data);
3092 snd_hda_codec_resume_amp(codec); 3306 snd_hda_codec_resume_amp(codec);
3093 snd_hda_codec_resume_cache(codec); 3307 snd_hda_codec_resume_cache(codec);
3308 /* power down inactive DACs */
3309 if (spec->dac_list)
3310 stac92xx_power_down(codec);
3094 /* invoke unsolicited event to reset the HP state */ 3311 /* invoke unsolicited event to reset the HP state */
3095 if (spec->hp_detect) 3312 if (spec->hp_detect)
3096 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26); 3313 codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
@@ -3147,12 +3364,18 @@ static int patch_stac9200(struct hda_codec *codec)
3147 spec->num_adcs = 1; 3364 spec->num_adcs = 1;
3148 spec->num_pwrs = 0; 3365 spec->num_pwrs = 0;
3149 3366
3150 if (spec->board_config == STAC_9200_GATEWAY) 3367 if (spec->board_config == STAC_9200_GATEWAY ||
3368 spec->board_config == STAC_9200_OQO)
3151 spec->init = stac9200_eapd_init; 3369 spec->init = stac9200_eapd_init;
3152 else 3370 else
3153 spec->init = stac9200_core_init; 3371 spec->init = stac9200_core_init;
3154 spec->mixer = stac9200_mixer; 3372 spec->mixer = stac9200_mixer;
3155 3373
3374 if (spec->board_config == STAC_9200_PANASONIC) {
3375 spec->gpio_mask = spec->gpio_dir = 0x09;
3376 spec->gpio_data = 0x00;
3377 }
3378
3156 err = stac9200_parse_auto_config(codec); 3379 err = stac9200_parse_auto_config(codec);
3157 if (err < 0) { 3380 if (err < 0) {
3158 stac92xx_free(codec); 3381 stac92xx_free(codec);
@@ -3293,6 +3516,7 @@ again:
3293 3516
3294 switch (spec->multiout.num_dacs) { 3517 switch (spec->multiout.num_dacs) {
3295 case 0x3: /* 6 Channel */ 3518 case 0x3: /* 6 Channel */
3519 spec->multiout.hp_nid = 0x17;
3296 spec->mixer = stac92hd73xx_6ch_mixer; 3520 spec->mixer = stac92hd73xx_6ch_mixer;
3297 spec->init = stac92hd73xx_6ch_core_init; 3521 spec->init = stac92hd73xx_6ch_core_init;
3298 break; 3522 break;
@@ -3318,13 +3542,42 @@ again:
3318 3542
3319 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids); 3543 spec->num_muxes = ARRAY_SIZE(stac92hd73xx_mux_nids);
3320 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids); 3544 spec->num_adcs = ARRAY_SIZE(stac92hd73xx_adc_nids);
3321 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
3322 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids); 3545 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
3323 spec->dinput_mux = &stac92hd73xx_dmux; 3546 spec->dinput_mux = &stac92hd73xx_dmux;
3324 /* GPIO0 High = Enable EAPD */ 3547 /* GPIO0 High = Enable EAPD */
3325 spec->gpio_mask = spec->gpio_dir = 0x1; 3548 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
3326 spec->gpio_data = 0x01; 3549 spec->gpio_data = 0x01;
3327 3550
3551 switch (spec->board_config) {
3552 case STAC_DELL_M6:
3553 spec->init = dell_eq_core_init;
3554 switch (codec->subsystem_id) {
3555 case 0x1028025e: /* Analog Mics */
3556 case 0x1028025f:
3557 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
3558 spec->num_dmics = 0;
3559 break;
3560 case 0x10280271: /* Digital Mics */
3561 case 0x10280272:
3562 spec->init = dell_m6_core_init;
3563 /* fall-through */
3564 case 0x10280254:
3565 case 0x10280255:
3566 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
3567 spec->num_dmics = 1;
3568 break;
3569 case 0x10280256: /* Both */
3570 case 0x10280057:
3571 stac92xx_set_config_reg(codec, 0x0b, 0x90A70170);
3572 stac92xx_set_config_reg(codec, 0x13, 0x90A60160);
3573 spec->num_dmics = 1;
3574 break;
3575 }
3576 break;
3577 default:
3578 spec->num_dmics = STAC92HD73XX_NUM_DMICS;
3579 }
3580
3328 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids); 3581 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
3329 spec->pwr_nids = stac92hd73xx_pwr_nids; 3582 spec->pwr_nids = stac92hd73xx_pwr_nids;
3330 3583
@@ -3398,7 +3651,10 @@ again:
3398 spec->aloopback_shift = 0; 3651 spec->aloopback_shift = 0;
3399 3652
3400 /* GPIO0 High = EAPD */ 3653 /* GPIO0 High = EAPD */
3401 spec->gpio_mask = spec->gpio_dir = spec->gpio_data = 0x1; 3654 spec->gpio_mask = 0x01;
3655 spec->gpio_dir = 0x01;
3656 spec->gpio_mask = 0x01;
3657 spec->gpio_data = 0x01;
3402 3658
3403 spec->mux_nids = stac92hd71bxx_mux_nids; 3659 spec->mux_nids = stac92hd71bxx_mux_nids;
3404 spec->adc_nids = stac92hd71bxx_adc_nids; 3660 spec->adc_nids = stac92hd71bxx_adc_nids;
@@ -3413,7 +3669,7 @@ again:
3413 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids); 3669 spec->num_pwrs = ARRAY_SIZE(stac92hd71bxx_pwr_nids);
3414 spec->pwr_nids = stac92hd71bxx_pwr_nids; 3670 spec->pwr_nids = stac92hd71bxx_pwr_nids;
3415 3671
3416 spec->multiout.num_dacs = 2; 3672 spec->multiout.num_dacs = 1;
3417 spec->multiout.hp_nid = 0x11; 3673 spec->multiout.hp_nid = 0x11;
3418 spec->multiout.dac_nids = stac92hd71bxx_dac_nids; 3674 spec->multiout.dac_nids = stac92hd71bxx_dac_nids;
3419 3675
@@ -3577,13 +3833,14 @@ static int patch_stac927x(struct hda_codec *codec)
3577 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids); 3833 spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
3578 spec->mux_nids = stac927x_mux_nids; 3834 spec->mux_nids = stac927x_mux_nids;
3579 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids); 3835 spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
3836 spec->dac_list = stac927x_dac_nids;
3580 spec->multiout.dac_nids = spec->dac_nids; 3837 spec->multiout.dac_nids = spec->dac_nids;
3581 3838
3582 switch (spec->board_config) { 3839 switch (spec->board_config) {
3583 case STAC_D965_3ST: 3840 case STAC_D965_3ST:
3584 case STAC_D965_5ST: 3841 case STAC_D965_5ST:
3585 /* GPIO0 High = Enable EAPD */ 3842 /* GPIO0 High = Enable EAPD */
3586 spec->gpio_mask = spec->gpio_dir = 0x01; 3843 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x01;
3587 spec->gpio_data = 0x01; 3844 spec->gpio_data = 0x01;
3588 spec->num_dmics = 0; 3845 spec->num_dmics = 0;
3589 3846
@@ -3591,14 +3848,23 @@ static int patch_stac927x(struct hda_codec *codec)
3591 spec->mixer = stac927x_mixer; 3848 spec->mixer = stac927x_mixer;
3592 break; 3849 break;
3593 case STAC_DELL_BIOS: 3850 case STAC_DELL_BIOS:
3851 switch (codec->subsystem_id) {
3852 case 0x10280209:
3853 case 0x1028022e:
3854 /* correct the device field to SPDIF out */
3855 stac92xx_set_config_reg(codec, 0x21, 0x01442070);
3856 break;
3857 };
3858 /* configure the analog microphone on some laptops */
3859 stac92xx_set_config_reg(codec, 0x0c, 0x90a79130);
3594 /* correct the front output jack as a hp out */ 3860 /* correct the front output jack as a hp out */
3595 stac92xx_set_config_reg(codec, 0x0f, 0x02270110); 3861 stac92xx_set_config_reg(codec, 0x0f, 0x0227011f);
3596 /* correct the front input jack as a mic */ 3862 /* correct the front input jack as a mic */
3597 stac92xx_set_config_reg(codec, 0x0e, 0x02a79130); 3863 stac92xx_set_config_reg(codec, 0x0e, 0x02a79130);
3598 /* fallthru */ 3864 /* fallthru */
3599 case STAC_DELL_3ST: 3865 case STAC_DELL_3ST:
3600 /* GPIO2 High = Enable EAPD */ 3866 /* GPIO2 High = Enable EAPD */
3601 spec->gpio_mask = spec->gpio_dir = 0x04; 3867 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x04;
3602 spec->gpio_data = 0x04; 3868 spec->gpio_data = 0x04;
3603 spec->dmic_nids = stac927x_dmic_nids; 3869 spec->dmic_nids = stac927x_dmic_nids;
3604 spec->num_dmics = STAC927X_NUM_DMICS; 3870 spec->num_dmics = STAC927X_NUM_DMICS;
@@ -3610,7 +3876,7 @@ static int patch_stac927x(struct hda_codec *codec)
3610 break; 3876 break;
3611 default: 3877 default:
3612 /* GPIO0 High = Enable EAPD */ 3878 /* GPIO0 High = Enable EAPD */
3613 spec->gpio_mask = spec->gpio_dir = 0x1; 3879 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
3614 spec->gpio_data = 0x01; 3880 spec->gpio_data = 0x01;
3615 spec->num_dmics = 0; 3881 spec->num_dmics = 0;
3616 3882
@@ -3714,6 +3980,7 @@ static int patch_stac9205(struct hda_codec *codec)
3714 (AC_USRSP_EN | STAC_HP_EVENT)); 3980 (AC_USRSP_EN | STAC_HP_EVENT));
3715 3981
3716 spec->gpio_dir = 0x0b; 3982 spec->gpio_dir = 0x0b;
3983 spec->eapd_mask = 0x01;
3717 spec->gpio_mask = 0x1b; 3984 spec->gpio_mask = 0x1b;
3718 spec->gpio_mute = 0x10; 3985 spec->gpio_mute = 0x10;
3719 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute, 3986 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
@@ -3723,7 +3990,7 @@ static int patch_stac9205(struct hda_codec *codec)
3723 break; 3990 break;
3724 default: 3991 default:
3725 /* GPIO0 High = EAPD */ 3992 /* GPIO0 High = EAPD */
3726 spec->gpio_mask = spec->gpio_dir = 0x1; 3993 spec->eapd_mask = spec->gpio_mask = spec->gpio_dir = 0x1;
3727 spec->gpio_data = 0x01; 3994 spec->gpio_data = 0x01;
3728 break; 3995 break;
3729 } 3996 }
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index 4e5dd4cf36f5..52b1d81a26f7 100644
--- a/sound/pci/hda/patch_via.c
+++ b/sound/pci/hda/patch_via.c
@@ -39,7 +39,7 @@
39#include <sound/core.h> 39#include <sound/core.h>
40#include "hda_codec.h" 40#include "hda_codec.h"
41#include "hda_local.h" 41#include "hda_local.h"
42 42#include "hda_patch.h"
43 43
44/* amp values */ 44/* amp values */
45#define AMP_VAL_IDX_SHIFT 19 45#define AMP_VAL_IDX_SHIFT 19
@@ -357,7 +357,8 @@ static int via_playback_pcm_open(struct hda_pcm_stream *hinfo,
357 struct snd_pcm_substream *substream) 357 struct snd_pcm_substream *substream)
358{ 358{
359 struct via_spec *spec = codec->spec; 359 struct via_spec *spec = codec->spec;
360 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream); 360 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
361 hinfo);
361} 362}
362 363
363static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 364static int via_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
@@ -430,8 +431,7 @@ static int via_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
430 struct snd_pcm_substream *substream) 431 struct snd_pcm_substream *substream)
431{ 432{
432 struct via_spec *spec = codec->spec; 433 struct via_spec *spec = codec->spec;
433 snd_hda_codec_setup_stream(codec, spec->adc_nids[substream->number], 434 snd_hda_codec_cleanup_stream(codec, spec->adc_nids[substream->number]);
434 0, 0, 0);
435 return 0; 435 return 0;
436} 436}
437 437
@@ -493,6 +493,11 @@ static int via_build_controls(struct hda_codec *codec)
493 spec->multiout.dig_out_nid); 493 spec->multiout.dig_out_nid);
494 if (err < 0) 494 if (err < 0)
495 return err; 495 return err;
496 err = snd_hda_create_spdif_share_sw(codec,
497 &spec->multiout);
498 if (err < 0)
499 return err;
500 spec->multiout.share_spdif = 1;
496 } 501 }
497 if (spec->dig_in_nid) { 502 if (spec->dig_in_nid) {
498 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid); 503 err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
@@ -523,6 +528,7 @@ static int via_build_pcms(struct hda_codec *codec)
523 codec->num_pcms++; 528 codec->num_pcms++;
524 info++; 529 info++;
525 info->name = spec->stream_name_digital; 530 info->name = spec->stream_name_digital;
531 info->pcm_type = HDA_PCM_TYPE_SPDIF;
526 if (spec->multiout.dig_out_nid) { 532 if (spec->multiout.dig_out_nid) {
527 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 533 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
528 *(spec->stream_digital_playback); 534 *(spec->stream_digital_playback);
diff --git a/sound/pci/ice1712/delta.c b/sound/pci/ice1712/delta.c
index efd180b40e56..0ed96c178059 100644
--- a/sound/pci/ice1712/delta.c
+++ b/sound/pci/ice1712/delta.c
@@ -1,8 +1,8 @@
1/* 1/*
2 * ALSA driver for ICEnsemble ICE1712 (Envy24) 2 * ALSA driver for ICEnsemble ICE1712 (Envy24)
3 * 3 *
4 * Lowlevel functions for M-Audio Delta 1010, 44, 66, Dio2496, Audiophile 4 * Lowlevel functions for M-Audio Delta 1010, 1010E, 44, 66, 66E, Dio2496,
5 * Digigram VX442 5 * Audiophile, Digigram VX442
6 * 6 *
7 * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz> 7 * Copyright (c) 2000 Jaroslav Kysela <perex@perex.cz>
8 * 8 *
@@ -86,6 +86,7 @@ static unsigned char ap_cs8427_codec_select(struct snd_ice1712 *ice)
86 unsigned char tmp; 86 unsigned char tmp;
87 tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA); 87 tmp = snd_ice1712_read(ice, ICE1712_IREG_GPIO_DATA);
88 switch (ice->eeprom.subvendor) { 88 switch (ice->eeprom.subvendor) {
89 case ICE1712_SUBDEVICE_DELTA1010E:
89 case ICE1712_SUBDEVICE_DELTA1010LT: 90 case ICE1712_SUBDEVICE_DELTA1010LT:
90 tmp &= ~ICE1712_DELTA_1010LT_CS; 91 tmp &= ~ICE1712_DELTA_1010LT_CS;
91 tmp |= ICE1712_DELTA_1010LT_CCLK | ICE1712_DELTA_1010LT_CS_CS8427; 92 tmp |= ICE1712_DELTA_1010LT_CCLK | ICE1712_DELTA_1010LT_CS_CS8427;
@@ -109,6 +110,7 @@ static unsigned char ap_cs8427_codec_select(struct snd_ice1712 *ice)
109static void ap_cs8427_codec_deassert(struct snd_ice1712 *ice, unsigned char tmp) 110static void ap_cs8427_codec_deassert(struct snd_ice1712 *ice, unsigned char tmp)
110{ 111{
111 switch (ice->eeprom.subvendor) { 112 switch (ice->eeprom.subvendor) {
113 case ICE1712_SUBDEVICE_DELTA1010E:
112 case ICE1712_SUBDEVICE_DELTA1010LT: 114 case ICE1712_SUBDEVICE_DELTA1010LT:
113 tmp &= ~ICE1712_DELTA_1010LT_CS; 115 tmp &= ~ICE1712_DELTA_1010LT_CS;
114 tmp |= ICE1712_DELTA_1010LT_CS_NONE; 116 tmp |= ICE1712_DELTA_1010LT_CS_NONE;
@@ -534,6 +536,14 @@ static int __devinit snd_ice1712_delta_init(struct snd_ice1712 *ice)
534 int err; 536 int err;
535 struct snd_akm4xxx *ak; 537 struct snd_akm4xxx *ak;
536 538
539 if (ice->eeprom.subvendor == ICE1712_SUBDEVICE_DELTA1010 &&
540 ice->eeprom.gpiodir == 0x7b)
541 ice->eeprom.subvendor = ICE1712_SUBDEVICE_DELTA1010E;
542
543 if (ice->eeprom.subvendor == ICE1712_SUBDEVICE_DELTA66 &&
544 ice->eeprom.gpiodir == 0xfb)
545 ice->eeprom.subvendor = ICE1712_SUBDEVICE_DELTA66E;
546
537 /* determine I2C, DACs and ADCs */ 547 /* determine I2C, DACs and ADCs */
538 switch (ice->eeprom.subvendor) { 548 switch (ice->eeprom.subvendor) {
539 case ICE1712_SUBDEVICE_AUDIOPHILE: 549 case ICE1712_SUBDEVICE_AUDIOPHILE:
@@ -550,6 +560,7 @@ static int __devinit snd_ice1712_delta_init(struct snd_ice1712 *ice)
550 ice->num_total_adcs = ice->omni ? 8 : 4; 560 ice->num_total_adcs = ice->omni ? 8 : 4;
551 break; 561 break;
552 case ICE1712_SUBDEVICE_DELTA1010: 562 case ICE1712_SUBDEVICE_DELTA1010:
563 case ICE1712_SUBDEVICE_DELTA1010E:
553 case ICE1712_SUBDEVICE_DELTA1010LT: 564 case ICE1712_SUBDEVICE_DELTA1010LT:
554 case ICE1712_SUBDEVICE_MEDIASTATION: 565 case ICE1712_SUBDEVICE_MEDIASTATION:
555 ice->num_total_dacs = 8; 566 ice->num_total_dacs = 8;
@@ -559,6 +570,7 @@ static int __devinit snd_ice1712_delta_init(struct snd_ice1712 *ice)
559 ice->num_total_dacs = 4; /* two AK4324 codecs */ 570 ice->num_total_dacs = 4; /* two AK4324 codecs */
560 break; 571 break;
561 case ICE1712_SUBDEVICE_VX442: 572 case ICE1712_SUBDEVICE_VX442:
573 case ICE1712_SUBDEVICE_DELTA66E: /* omni not suported yet */
562 ice->num_total_dacs = 4; 574 ice->num_total_dacs = 4;
563 ice->num_total_adcs = 4; 575 ice->num_total_adcs = 4;
564 break; 576 break;
@@ -568,8 +580,10 @@ static int __devinit snd_ice1712_delta_init(struct snd_ice1712 *ice)
568 switch (ice->eeprom.subvendor) { 580 switch (ice->eeprom.subvendor) {
569 case ICE1712_SUBDEVICE_AUDIOPHILE: 581 case ICE1712_SUBDEVICE_AUDIOPHILE:
570 case ICE1712_SUBDEVICE_DELTA410: 582 case ICE1712_SUBDEVICE_DELTA410:
583 case ICE1712_SUBDEVICE_DELTA1010E:
571 case ICE1712_SUBDEVICE_DELTA1010LT: 584 case ICE1712_SUBDEVICE_DELTA1010LT:
572 case ICE1712_SUBDEVICE_VX442: 585 case ICE1712_SUBDEVICE_VX442:
586 case ICE1712_SUBDEVICE_DELTA66E:
573 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) { 587 if ((err = snd_i2c_bus_create(ice->card, "ICE1712 GPIO 1", NULL, &ice->i2c)) < 0) {
574 snd_printk(KERN_ERR "unable to create I2C bus\n"); 588 snd_printk(KERN_ERR "unable to create I2C bus\n");
575 return err; 589 return err;
@@ -601,6 +615,7 @@ static int __devinit snd_ice1712_delta_init(struct snd_ice1712 *ice)
601 /* no analog? */ 615 /* no analog? */
602 switch (ice->eeprom.subvendor) { 616 switch (ice->eeprom.subvendor) {
603 case ICE1712_SUBDEVICE_DELTA1010: 617 case ICE1712_SUBDEVICE_DELTA1010:
618 case ICE1712_SUBDEVICE_DELTA1010E:
604 case ICE1712_SUBDEVICE_DELTADIO2496: 619 case ICE1712_SUBDEVICE_DELTADIO2496:
605 case ICE1712_SUBDEVICE_MEDIASTATION: 620 case ICE1712_SUBDEVICE_MEDIASTATION:
606 return 0; 621 return 0;
@@ -627,6 +642,7 @@ static int __devinit snd_ice1712_delta_init(struct snd_ice1712 *ice)
627 err = snd_ice1712_akm4xxx_init(ak, &akm_delta44, &akm_delta44_priv, ice); 642 err = snd_ice1712_akm4xxx_init(ak, &akm_delta44, &akm_delta44_priv, ice);
628 break; 643 break;
629 case ICE1712_SUBDEVICE_VX442: 644 case ICE1712_SUBDEVICE_VX442:
645 case ICE1712_SUBDEVICE_DELTA66E:
630 err = snd_ice1712_akm4xxx_init(ak, &akm_vx442, &akm_vx442_priv, ice); 646 err = snd_ice1712_akm4xxx_init(ak, &akm_vx442, &akm_vx442_priv, ice);
631 break; 647 break;
632 default: 648 default:
@@ -674,6 +690,7 @@ static int __devinit snd_ice1712_delta_add_controls(struct snd_ice1712 *ice)
674 if (err < 0) 690 if (err < 0)
675 return err; 691 return err;
676 break; 692 break;
693 case ICE1712_SUBDEVICE_DELTA1010E:
677 case ICE1712_SUBDEVICE_DELTA1010LT: 694 case ICE1712_SUBDEVICE_DELTA1010LT:
678 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010lt_wordclock_select, ice)); 695 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_delta1010lt_wordclock_select, ice));
679 if (err < 0) 696 if (err < 0)
@@ -716,6 +733,7 @@ static int __devinit snd_ice1712_delta_add_controls(struct snd_ice1712 *ice)
716 case ICE1712_SUBDEVICE_DELTA44: 733 case ICE1712_SUBDEVICE_DELTA44:
717 case ICE1712_SUBDEVICE_DELTA66: 734 case ICE1712_SUBDEVICE_DELTA66:
718 case ICE1712_SUBDEVICE_VX442: 735 case ICE1712_SUBDEVICE_VX442:
736 case ICE1712_SUBDEVICE_DELTA66E:
719 err = snd_ice1712_akm4xxx_build_controls(ice); 737 err = snd_ice1712_akm4xxx_build_controls(ice);
720 if (err < 0) 738 if (err < 0)
721 return err; 739 return err;
diff --git a/sound/pci/ice1712/delta.h b/sound/pci/ice1712/delta.h
index 26ea05a32f56..ea7116c304c0 100644
--- a/sound/pci/ice1712/delta.h
+++ b/sound/pci/ice1712/delta.h
@@ -36,8 +36,10 @@
36 "{Lionstracs,Mediastation}," 36 "{Lionstracs,Mediastation},"
37 37
38#define ICE1712_SUBDEVICE_DELTA1010 0x121430d6 38#define ICE1712_SUBDEVICE_DELTA1010 0x121430d6
39#define ICE1712_SUBDEVICE_DELTA1010E 0xff1430d6
39#define ICE1712_SUBDEVICE_DELTADIO2496 0x121431d6 40#define ICE1712_SUBDEVICE_DELTADIO2496 0x121431d6
40#define ICE1712_SUBDEVICE_DELTA66 0x121432d6 41#define ICE1712_SUBDEVICE_DELTA66 0x121432d6
42#define ICE1712_SUBDEVICE_DELTA66E 0xff1432d6
41#define ICE1712_SUBDEVICE_DELTA44 0x121433d6 43#define ICE1712_SUBDEVICE_DELTA44 0x121433d6
42#define ICE1712_SUBDEVICE_AUDIOPHILE 0x121434d6 44#define ICE1712_SUBDEVICE_AUDIOPHILE 0x121434d6
43#define ICE1712_SUBDEVICE_DELTA410 0x121438d6 45#define ICE1712_SUBDEVICE_DELTA410 0x121438d6
diff --git a/sound/pci/ice1712/ews.c b/sound/pci/ice1712/ews.c
index 064760d2a027..013fc4f04822 100644
--- a/sound/pci/ice1712/ews.c
+++ b/sound/pci/ice1712/ews.c
@@ -238,6 +238,7 @@ static void snd_ice1712_ews_cs8404_spdif_write(struct snd_ice1712 *ice, unsigned
238 case ICE1712_SUBDEVICE_EWS88MT: 238 case ICE1712_SUBDEVICE_EWS88MT:
239 case ICE1712_SUBDEVICE_EWS88MT_NEW: 239 case ICE1712_SUBDEVICE_EWS88MT_NEW:
240 case ICE1712_SUBDEVICE_PHASE88: 240 case ICE1712_SUBDEVICE_PHASE88:
241 case ICE1712_SUBDEVICE_TS88:
241 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_CS8404], &bits, 1) 242 if (snd_i2c_sendbytes(spec->i2cdevs[EWS_I2C_CS8404], &bits, 1)
242 != 1) 243 != 1)
243 goto _error; 244 goto _error;
@@ -433,6 +434,7 @@ static int __devinit snd_ice1712_ews_init(struct snd_ice1712 *ice)
433 case ICE1712_SUBDEVICE_EWS88MT: 434 case ICE1712_SUBDEVICE_EWS88MT:
434 case ICE1712_SUBDEVICE_EWS88MT_NEW: 435 case ICE1712_SUBDEVICE_EWS88MT_NEW:
435 case ICE1712_SUBDEVICE_PHASE88: 436 case ICE1712_SUBDEVICE_PHASE88:
437 case ICE1712_SUBDEVICE_TS88:
436 ice->num_total_dacs = 8; 438 ice->num_total_dacs = 8;
437 ice->num_total_adcs = 8; 439 ice->num_total_adcs = 8;
438 break; 440 break;
@@ -475,6 +477,8 @@ static int __devinit snd_ice1712_ews_init(struct snd_ice1712 *ice)
475 case ICE1712_SUBDEVICE_EWS88MT: 477 case ICE1712_SUBDEVICE_EWS88MT:
476 case ICE1712_SUBDEVICE_EWS88MT_NEW: 478 case ICE1712_SUBDEVICE_EWS88MT_NEW:
477 case ICE1712_SUBDEVICE_PHASE88: 479 case ICE1712_SUBDEVICE_PHASE88:
480 case ICE1712_SUBDEVICE_TS88:
481
478 err = snd_i2c_device_create(ice->i2c, "CS8404", 482 err = snd_i2c_device_create(ice->i2c, "CS8404",
479 ICE1712_EWS88MT_CS8404_ADDR, 483 ICE1712_EWS88MT_CS8404_ADDR,
480 &spec->i2cdevs[EWS_I2C_CS8404]); 484 &spec->i2cdevs[EWS_I2C_CS8404]);
@@ -518,6 +522,7 @@ static int __devinit snd_ice1712_ews_init(struct snd_ice1712 *ice)
518 case ICE1712_SUBDEVICE_EWS88MT: 522 case ICE1712_SUBDEVICE_EWS88MT:
519 case ICE1712_SUBDEVICE_EWS88MT_NEW: 523 case ICE1712_SUBDEVICE_EWS88MT_NEW:
520 case ICE1712_SUBDEVICE_PHASE88: 524 case ICE1712_SUBDEVICE_PHASE88:
525 case ICE1712_SUBDEVICE_TS88:
521 case ICE1712_SUBDEVICE_EWS88D: 526 case ICE1712_SUBDEVICE_EWS88D:
522 /* set up CS8404 */ 527 /* set up CS8404 */
523 ice->spdif.ops.open = ews88_open_spdif; 528 ice->spdif.ops.open = ews88_open_spdif;
@@ -547,6 +552,7 @@ static int __devinit snd_ice1712_ews_init(struct snd_ice1712 *ice)
547 case ICE1712_SUBDEVICE_EWS88MT: 552 case ICE1712_SUBDEVICE_EWS88MT:
548 case ICE1712_SUBDEVICE_EWS88MT_NEW: 553 case ICE1712_SUBDEVICE_EWS88MT_NEW:
549 case ICE1712_SUBDEVICE_PHASE88: 554 case ICE1712_SUBDEVICE_PHASE88:
555 case ICE1712_SUBDEVICE_TS88:
550 err = snd_ice1712_akm4xxx_init(ak, &akm_ews88mt, &akm_ews88mt_priv, ice); 556 err = snd_ice1712_akm4xxx_init(ak, &akm_ews88mt, &akm_ews88mt_priv, ice);
551 break; 557 break;
552 case ICE1712_SUBDEVICE_EWX2496: 558 case ICE1712_SUBDEVICE_EWX2496:
@@ -973,6 +979,7 @@ static int __devinit snd_ice1712_ews_add_controls(struct snd_ice1712 *ice)
973 case ICE1712_SUBDEVICE_EWS88MT: 979 case ICE1712_SUBDEVICE_EWS88MT:
974 case ICE1712_SUBDEVICE_EWS88MT_NEW: 980 case ICE1712_SUBDEVICE_EWS88MT_NEW:
975 case ICE1712_SUBDEVICE_PHASE88: 981 case ICE1712_SUBDEVICE_PHASE88:
982 case ICE1712_SUBDEVICE_TS88:
976 case ICE1712_SUBDEVICE_DMX6FIRE: 983 case ICE1712_SUBDEVICE_DMX6FIRE:
977 err = snd_ice1712_akm4xxx_build_controls(ice); 984 err = snd_ice1712_akm4xxx_build_controls(ice);
978 if (err < 0) 985 if (err < 0)
@@ -992,6 +999,7 @@ static int __devinit snd_ice1712_ews_add_controls(struct snd_ice1712 *ice)
992 case ICE1712_SUBDEVICE_EWS88MT: 999 case ICE1712_SUBDEVICE_EWS88MT:
993 case ICE1712_SUBDEVICE_EWS88MT_NEW: 1000 case ICE1712_SUBDEVICE_EWS88MT_NEW:
994 case ICE1712_SUBDEVICE_PHASE88: 1001 case ICE1712_SUBDEVICE_PHASE88:
1002 case ICE1712_SUBDEVICE_TS88:
995 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_input_sense, ice)); 1003 err = snd_ctl_add(ice->card, snd_ctl_new1(&snd_ice1712_ews88mt_input_sense, ice));
996 if (err < 0) 1004 if (err < 0)
997 return err; 1005 return err;
@@ -1049,6 +1057,13 @@ struct snd_ice1712_card_info snd_ice1712_ews_cards[] __devinitdata = {
1049 .build_controls = snd_ice1712_ews_add_controls, 1057 .build_controls = snd_ice1712_ews_add_controls,
1050 }, 1058 },
1051 { 1059 {
1060 .subvendor = ICE1712_SUBDEVICE_TS88,
1061 .name = "terrasoniq TS88",
1062 .model = "phase88",
1063 .chip_init = snd_ice1712_ews_init,
1064 .build_controls = snd_ice1712_ews_add_controls,
1065 },
1066 {
1052 .subvendor = ICE1712_SUBDEVICE_EWS88D, 1067 .subvendor = ICE1712_SUBDEVICE_EWS88D,
1053 .name = "TerraTec EWS88D", 1068 .name = "TerraTec EWS88D",
1054 .model = "ews88d", 1069 .model = "ews88d",
diff --git a/sound/pci/ice1712/ews.h b/sound/pci/ice1712/ews.h
index e4ed1b475b08..1c443718af03 100644
--- a/sound/pci/ice1712/ews.h
+++ b/sound/pci/ice1712/ews.h
@@ -30,7 +30,8 @@
30 "{TerraTec,EWS 88MT},"\ 30 "{TerraTec,EWS 88MT},"\
31 "{TerraTec,EWS 88D},"\ 31 "{TerraTec,EWS 88D},"\
32 "{TerraTec,DMX 6Fire},"\ 32 "{TerraTec,DMX 6Fire},"\
33 "{TerraTec,Phase 88}," 33 "{TerraTec,Phase 88}," \
34 "{terrasoniq,TS 88},"
34 35
35#define ICE1712_SUBDEVICE_EWX2496 0x3b153011 36#define ICE1712_SUBDEVICE_EWX2496 0x3b153011
36#define ICE1712_SUBDEVICE_EWS88MT 0x3b151511 37#define ICE1712_SUBDEVICE_EWS88MT 0x3b151511
@@ -38,6 +39,7 @@
38#define ICE1712_SUBDEVICE_EWS88D 0x3b152b11 39#define ICE1712_SUBDEVICE_EWS88D 0x3b152b11
39#define ICE1712_SUBDEVICE_DMX6FIRE 0x3b153811 40#define ICE1712_SUBDEVICE_DMX6FIRE 0x3b153811
40#define ICE1712_SUBDEVICE_PHASE88 0x3b155111 41#define ICE1712_SUBDEVICE_PHASE88 0x3b155111
42#define ICE1712_SUBDEVICE_TS88 0x3b157c11
41 43
42/* entry point */ 44/* entry point */
43extern struct snd_ice1712_card_info snd_ice1712_ews_cards[]; 45extern struct snd_ice1712_card_info snd_ice1712_ews_cards[];
diff --git a/sound/pci/ice1712/hoontech.c b/sound/pci/ice1712/hoontech.c
index cf5c7c0898fd..6914189073a4 100644
--- a/sound/pci/ice1712/hoontech.c
+++ b/sound/pci/ice1712/hoontech.c
@@ -208,6 +208,19 @@ static int __devinit snd_ice1712_hoontech_init(struct snd_ice1712 *ice)
208 /* ICE1712_STDSP24_MUTE | 208 /* ICE1712_STDSP24_MUTE |
209 ICE1712_STDSP24_INSEL | 209 ICE1712_STDSP24_INSEL |
210 ICE1712_STDSP24_DAREAR; */ 210 ICE1712_STDSP24_DAREAR; */
211 /* These boxconfigs have caused problems in the past.
212 * The code is not optimal, but should now enable a working config to
213 * be achieved.
214 * ** MIDI IN can only be configured on one box **
215 * ICE1712_STDSP24_BOX_MIDI1 needs to be set for that box.
216 * Tests on a ADAC2000 box suggest the box config flags do not
217 * work as would be expected, and the inputs are crossed.
218 * Setting ICE1712_STDSP24_BOX_MIDI1 and ICE1712_STDSP24_BOX_MIDI2
219 * on the same box connects MIDI-In to both 401 uarts; both outputs
220 * are then active on all boxes.
221 * The default config here sets up everything on the first box.
222 * Alan Horstmann 5.2.2008
223 */
211 spec->boxconfig[0] = ICE1712_STDSP24_BOX_CHN1 | 224 spec->boxconfig[0] = ICE1712_STDSP24_BOX_CHN1 |
212 ICE1712_STDSP24_BOX_CHN2 | 225 ICE1712_STDSP24_BOX_CHN2 |
213 ICE1712_STDSP24_BOX_CHN3 | 226 ICE1712_STDSP24_BOX_CHN3 |
@@ -223,14 +236,14 @@ static int __devinit snd_ice1712_hoontech_init(struct snd_ice1712 *ice)
223 (spec->config & ICE1712_STDSP24_MUTE) ? 1 : 0); 236 (spec->config & ICE1712_STDSP24_MUTE) ? 1 : 0);
224 snd_ice1712_stdsp24_insel(ice, 237 snd_ice1712_stdsp24_insel(ice,
225 (spec->config & ICE1712_STDSP24_INSEL) ? 1 : 0); 238 (spec->config & ICE1712_STDSP24_INSEL) ? 1 : 0);
226 for (box = 0; box < 1; box++) { 239 for (box = 0; box < 4; box++) {
227 if (spec->boxconfig[box] & ICE1712_STDSP24_BOX_MIDI2) 240 if (spec->boxconfig[box] & ICE1712_STDSP24_BOX_MIDI2)
228 snd_ice1712_stdsp24_midi2(ice, 1); 241 snd_ice1712_stdsp24_midi2(ice, 1);
229 for (chn = 0; chn < 4; chn++) 242 for (chn = 0; chn < 4; chn++)
230 snd_ice1712_stdsp24_box_channel(ice, box, chn, 243 snd_ice1712_stdsp24_box_channel(ice, box, chn,
231 (spec->boxconfig[box] & (1 << chn)) ? 1 : 0); 244 (spec->boxconfig[box] & (1 << chn)) ? 1 : 0);
232 snd_ice1712_stdsp24_box_midi(ice, box, 245 if (spec->boxconfig[box] & ICE1712_STDSP24_BOX_MIDI1)
233 (spec->boxconfig[box] & ICE1712_STDSP24_BOX_MIDI1) ? 1 : 0); 246 snd_ice1712_stdsp24_box_midi(ice, box, 1);
234 } 247 }
235 248
236 return 0; 249 return 0;
@@ -322,6 +335,8 @@ struct snd_ice1712_card_info snd_ice1712_hoontech_cards[] __devinitdata = {
322 .name = "Hoontech SoundTrack Audio DSP24", 335 .name = "Hoontech SoundTrack Audio DSP24",
323 .model = "dsp24", 336 .model = "dsp24",
324 .chip_init = snd_ice1712_hoontech_init, 337 .chip_init = snd_ice1712_hoontech_init,
338 .mpu401_1_name = "MIDI-1 Hoontech/STA DSP24",
339 .mpu401_2_name = "MIDI-2 Hoontech/STA DSP24",
325 }, 340 },
326 { 341 {
327 .subvendor = ICE1712_SUBDEVICE_STDSP24_VALUE, /* a dummy id */ 342 .subvendor = ICE1712_SUBDEVICE_STDSP24_VALUE, /* a dummy id */
diff --git a/sound/pci/ice1712/ice1712.c b/sound/pci/ice1712/ice1712.c
index df292af67381..29d449d73c98 100644
--- a/sound/pci/ice1712/ice1712.c
+++ b/sound/pci/ice1712/ice1712.c
@@ -1297,11 +1297,14 @@ static void snd_ice1712_update_volume(struct snd_ice1712 *ice, int index)
1297static int snd_ice1712_pro_mixer_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1297static int snd_ice1712_pro_mixer_switch_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1298{ 1298{
1299 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1299 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1300 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value; 1300 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1301 kcontrol->private_value;
1301 1302
1302 spin_lock_irq(&ice->reg_lock); 1303 spin_lock_irq(&ice->reg_lock);
1303 ucontrol->value.integer.value[0] = !((ice->pro_volumes[index] >> 15) & 1); 1304 ucontrol->value.integer.value[0] =
1304 ucontrol->value.integer.value[1] = !((ice->pro_volumes[index] >> 31) & 1); 1305 !((ice->pro_volumes[priv_idx] >> 15) & 1);
1306 ucontrol->value.integer.value[1] =
1307 !((ice->pro_volumes[priv_idx] >> 31) & 1);
1305 spin_unlock_irq(&ice->reg_lock); 1308 spin_unlock_irq(&ice->reg_lock);
1306 return 0; 1309 return 0;
1307} 1310}
@@ -1309,16 +1312,17 @@ static int snd_ice1712_pro_mixer_switch_get(struct snd_kcontrol *kcontrol, struc
1309static int snd_ice1712_pro_mixer_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1312static int snd_ice1712_pro_mixer_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1310{ 1313{
1311 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1314 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1312 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value; 1315 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1316 kcontrol->private_value;
1313 unsigned int nval, change; 1317 unsigned int nval, change;
1314 1318
1315 nval = (ucontrol->value.integer.value[0] ? 0 : 0x00008000) | 1319 nval = (ucontrol->value.integer.value[0] ? 0 : 0x00008000) |
1316 (ucontrol->value.integer.value[1] ? 0 : 0x80000000); 1320 (ucontrol->value.integer.value[1] ? 0 : 0x80000000);
1317 spin_lock_irq(&ice->reg_lock); 1321 spin_lock_irq(&ice->reg_lock);
1318 nval |= ice->pro_volumes[index] & ~0x80008000; 1322 nval |= ice->pro_volumes[priv_idx] & ~0x80008000;
1319 change = nval != ice->pro_volumes[index]; 1323 change = nval != ice->pro_volumes[priv_idx];
1320 ice->pro_volumes[index] = nval; 1324 ice->pro_volumes[priv_idx] = nval;
1321 snd_ice1712_update_volume(ice, index); 1325 snd_ice1712_update_volume(ice, priv_idx);
1322 spin_unlock_irq(&ice->reg_lock); 1326 spin_unlock_irq(&ice->reg_lock);
1323 return change; 1327 return change;
1324} 1328}
@@ -1335,11 +1339,14 @@ static int snd_ice1712_pro_mixer_volume_info(struct snd_kcontrol *kcontrol, stru
1335static int snd_ice1712_pro_mixer_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1339static int snd_ice1712_pro_mixer_volume_get(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1336{ 1340{
1337 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1341 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1338 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value; 1342 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1343 kcontrol->private_value;
1339 1344
1340 spin_lock_irq(&ice->reg_lock); 1345 spin_lock_irq(&ice->reg_lock);
1341 ucontrol->value.integer.value[0] = (ice->pro_volumes[index] >> 0) & 127; 1346 ucontrol->value.integer.value[0] =
1342 ucontrol->value.integer.value[1] = (ice->pro_volumes[index] >> 16) & 127; 1347 (ice->pro_volumes[priv_idx] >> 0) & 127;
1348 ucontrol->value.integer.value[1] =
1349 (ice->pro_volumes[priv_idx] >> 16) & 127;
1343 spin_unlock_irq(&ice->reg_lock); 1350 spin_unlock_irq(&ice->reg_lock);
1344 return 0; 1351 return 0;
1345} 1352}
@@ -1347,16 +1354,17 @@ static int snd_ice1712_pro_mixer_volume_get(struct snd_kcontrol *kcontrol, struc
1347static int snd_ice1712_pro_mixer_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol) 1354static int snd_ice1712_pro_mixer_volume_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_value *ucontrol)
1348{ 1355{
1349 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1356 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1350 int index = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) + kcontrol->private_value; 1357 int priv_idx = snd_ctl_get_ioffidx(kcontrol, &ucontrol->id) +
1358 kcontrol->private_value;
1351 unsigned int nval, change; 1359 unsigned int nval, change;
1352 1360
1353 nval = (ucontrol->value.integer.value[0] & 127) | 1361 nval = (ucontrol->value.integer.value[0] & 127) |
1354 ((ucontrol->value.integer.value[1] & 127) << 16); 1362 ((ucontrol->value.integer.value[1] & 127) << 16);
1355 spin_lock_irq(&ice->reg_lock); 1363 spin_lock_irq(&ice->reg_lock);
1356 nval |= ice->pro_volumes[index] & ~0x007f007f; 1364 nval |= ice->pro_volumes[priv_idx] & ~0x007f007f;
1357 change = nval != ice->pro_volumes[index]; 1365 change = nval != ice->pro_volumes[priv_idx];
1358 ice->pro_volumes[index] = nval; 1366 ice->pro_volumes[priv_idx] = nval;
1359 snd_ice1712_update_volume(ice, index); 1367 snd_ice1712_update_volume(ice, priv_idx);
1360 spin_unlock_irq(&ice->reg_lock); 1368 spin_unlock_irq(&ice->reg_lock);
1361 return change; 1369 return change;
1362} 1370}
@@ -2482,10 +2490,9 @@ static int snd_ice1712_free(struct snd_ice1712 *ice)
2482 outb(0xff, ICEREG(ice, IRQMASK)); 2490 outb(0xff, ICEREG(ice, IRQMASK));
2483 /* --- */ 2491 /* --- */
2484 __hw_end: 2492 __hw_end:
2485 if (ice->irq >= 0) { 2493 if (ice->irq >= 0)
2486 synchronize_irq(ice->irq);
2487 free_irq(ice->irq, ice); 2494 free_irq(ice->irq, ice);
2488 } 2495
2489 if (ice->port) 2496 if (ice->port)
2490 pci_release_regions(ice->pci); 2497 pci_release_regions(ice->pci);
2491 snd_ice1712_akm4xxx_free(ice); 2498 snd_ice1712_akm4xxx_free(ice);
diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
index 303cffe08bd8..3208901c740e 100644
--- a/sound/pci/ice1712/ice1712.h
+++ b/sound/pci/ice1712/ice1712.h
@@ -367,6 +367,15 @@ struct snd_ice1712 {
367 367
368 /* other board-specific data */ 368 /* other board-specific data */
369 void *spec; 369 void *spec;
370
371 /* VT172x specific */
372 int pro_rate_default;
373 int (*is_spdif_master)(struct snd_ice1712 *ice);
374 unsigned int (*get_rate)(struct snd_ice1712 *ice);
375 void (*set_rate)(struct snd_ice1712 *ice, unsigned int rate);
376 unsigned char (*set_mclk)(struct snd_ice1712 *ice, unsigned int rate);
377 void (*set_spdif_clock)(struct snd_ice1712 *ice);
378
370}; 379};
371 380
372 381
@@ -429,10 +438,14 @@ int snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_valu
429static inline void snd_ice1712_gpio_write_bits(struct snd_ice1712 *ice, 438static inline void snd_ice1712_gpio_write_bits(struct snd_ice1712 *ice,
430 unsigned int mask, unsigned int bits) 439 unsigned int mask, unsigned int bits)
431{ 440{
441 unsigned val;
442
432 ice->gpio.direction |= mask; 443 ice->gpio.direction |= mask;
433 snd_ice1712_gpio_set_dir(ice, ice->gpio.direction); 444 snd_ice1712_gpio_set_dir(ice, ice->gpio.direction);
434 snd_ice1712_gpio_set_mask(ice, ~mask); 445 val = snd_ice1712_gpio_read(ice);
435 snd_ice1712_gpio_write(ice, mask & bits); 446 val &= ~mask;
447 val |= mask & bits;
448 snd_ice1712_gpio_write(ice, val);
436} 449}
437 450
438static inline int snd_ice1712_gpio_read_bits(struct snd_ice1712 *ice, 451static inline int snd_ice1712_gpio_read_bits(struct snd_ice1712 *ice,
diff --git a/sound/pci/ice1712/ice1724.c b/sound/pci/ice1712/ice1724.c
index f533850ec6e7..4490422fb930 100644
--- a/sound/pci/ice1712/ice1724.c
+++ b/sound/pci/ice1712/ice1724.c
@@ -106,15 +106,19 @@ static unsigned int PRO_RATE_DEFAULT = 44100;
106 * Basic I/O 106 * Basic I/O
107 */ 107 */
108 108
109/*
110 * default rates, default clock routines
111 */
112
109/* check whether the clock mode is spdif-in */ 113/* check whether the clock mode is spdif-in */
110static inline int is_spdif_master(struct snd_ice1712 *ice) 114static inline int stdclock_is_spdif_master(struct snd_ice1712 *ice)
111{ 115{
112 return (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER) ? 1 : 0; 116 return (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER) ? 1 : 0;
113} 117}
114 118
115static inline int is_pro_rate_locked(struct snd_ice1712 *ice) 119static inline int is_pro_rate_locked(struct snd_ice1712 *ice)
116{ 120{
117 return is_spdif_master(ice) || PRO_RATE_LOCKED; 121 return ice->is_spdif_master(ice) || PRO_RATE_LOCKED;
118} 122}
119 123
120/* 124/*
@@ -219,6 +223,32 @@ static unsigned int snd_vt1724_get_gpio_data(struct snd_ice1712 *ice)
219} 223}
220 224
221/* 225/*
226 * MPU401 accessor
227 */
228static unsigned char snd_vt1724_mpu401_read(struct snd_mpu401 *mpu,
229 unsigned long addr)
230{
231 /* fix status bits to the standard position */
232 /* only RX_EMPTY and TX_FULL are checked */
233 if (addr == MPU401C(mpu))
234 return (inb(addr) & 0x0c) << 4;
235 else
236 return inb(addr);
237}
238
239static void snd_vt1724_mpu401_write(struct snd_mpu401 *mpu,
240 unsigned char data, unsigned long addr)
241{
242 if (addr == MPU401C(mpu)) {
243 if (data == MPU401_ENTER_UART)
244 outb(0x01, addr);
245 /* what else? */
246 } else
247 outb(data, addr);
248}
249
250
251/*
222 * Interrupt handler 252 * Interrupt handler
223 */ 253 */
224 254
@@ -226,24 +256,53 @@ static irqreturn_t snd_vt1724_interrupt(int irq, void *dev_id)
226{ 256{
227 struct snd_ice1712 *ice = dev_id; 257 struct snd_ice1712 *ice = dev_id;
228 unsigned char status; 258 unsigned char status;
259 unsigned char status_mask =
260 VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX | VT1724_IRQ_MTPCM;
229 int handled = 0; 261 int handled = 0;
262#ifdef CONFIG_SND_DEBUG
263 int timeout = 0;
264#endif
230 265
231 while (1) { 266 while (1) {
232 status = inb(ICEREG1724(ice, IRQSTAT)); 267 status = inb(ICEREG1724(ice, IRQSTAT));
268 status &= status_mask;
233 if (status == 0) 269 if (status == 0)
234 break; 270 break;
235 271#ifdef CONFIG_SND_DEBUG
272 if (++timeout > 10) {
273 printk(KERN_ERR
274 "ice1724: Too long irq loop, status = 0x%x\n",
275 status);
276 break;
277 }
278#endif
236 handled = 1; 279 handled = 1;
237 /* these should probably be separated at some point, 280 if (status & VT1724_IRQ_MPU_TX) {
238 * but as we don't currently have MPU support on the board 281 if (ice->rmidi[0])
239 * I will leave it 282 snd_mpu401_uart_interrupt_tx(irq,
240 */ 283 ice->rmidi[0]->private_data);
241 if ((status & VT1724_IRQ_MPU_RX)||(status & VT1724_IRQ_MPU_TX)) { 284 else /* disable TX to be sure */
285 outb(inb(ICEREG1724(ice, IRQMASK)) |
286 VT1724_IRQ_MPU_TX,
287 ICEREG1724(ice, IRQMASK));
288 /* Due to mysterical reasons, MPU_TX is always
289 * generated (and can't be cleared) when a PCM
290 * playback is going. So let's ignore at the
291 * next loop.
292 */
293 status_mask &= ~VT1724_IRQ_MPU_TX;
294 }
295 if (status & VT1724_IRQ_MPU_RX) {
242 if (ice->rmidi[0]) 296 if (ice->rmidi[0])
243 snd_mpu401_uart_interrupt(irq, ice->rmidi[0]->private_data); 297 snd_mpu401_uart_interrupt(irq,
244 outb(status & (VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX), ICEREG1724(ice, IRQSTAT)); 298 ice->rmidi[0]->private_data);
245 status &= ~(VT1724_IRQ_MPU_RX|VT1724_IRQ_MPU_TX); 299 else /* disable RX to be sure */
300 outb(inb(ICEREG1724(ice, IRQMASK)) |
301 VT1724_IRQ_MPU_RX,
302 ICEREG1724(ice, IRQMASK));
246 } 303 }
304 /* ack MPU irq */
305 outb(status, ICEREG1724(ice, IRQSTAT));
247 if (status & VT1724_IRQ_MTPCM) { 306 if (status & VT1724_IRQ_MTPCM) {
248 /* 307 /*
249 * Multi-track PCM 308 * Multi-track PCM
@@ -391,51 +450,61 @@ static int snd_vt1724_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
391#define DMA_PAUSES (VT1724_RDMA0_PAUSE|VT1724_PDMA0_PAUSE|VT1724_RDMA1_PAUSE|\ 450#define DMA_PAUSES (VT1724_RDMA0_PAUSE|VT1724_PDMA0_PAUSE|VT1724_RDMA1_PAUSE|\
392 VT1724_PDMA1_PAUSE|VT1724_PDMA2_PAUSE|VT1724_PDMA3_PAUSE|VT1724_PDMA4_PAUSE) 451 VT1724_PDMA1_PAUSE|VT1724_PDMA2_PAUSE|VT1724_PDMA3_PAUSE|VT1724_PDMA4_PAUSE)
393 452
394static int get_max_rate(struct snd_ice1712 *ice) 453static const unsigned int stdclock_rate_list[16] = {
454 48000, 24000, 12000, 9600, 32000, 16000, 8000, 96000, 44100,
455 22050, 11025, 88200, 176400, 0, 192000, 64000
456};
457
458static unsigned int stdclock_get_rate(struct snd_ice1712 *ice)
395{ 459{
460 unsigned int rate;
461 rate = stdclock_rate_list[inb(ICEMT1724(ice, RATE)) & 15];
462 return rate;
463}
464
465static void stdclock_set_rate(struct snd_ice1712 *ice, unsigned int rate)
466{
467 int i;
468 for (i = 0; i < ARRAY_SIZE(stdclock_rate_list); i++) {
469 if (stdclock_rate_list[i] == rate) {
470 outb(i, ICEMT1724(ice, RATE));
471 return;
472 }
473 }
474}
475
476static unsigned char stdclock_set_mclk(struct snd_ice1712 *ice,
477 unsigned int rate)
478{
479 unsigned char val, old;
480 /* check MT02 */
396 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) { 481 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
397 if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720) 482 val = old = inb(ICEMT1724(ice, I2S_FORMAT));
398 return 192000; 483 if (rate > 96000)
484 val |= VT1724_MT_I2S_MCLK_128X; /* 128x MCLK */
399 else 485 else
400 return 96000; 486 val &= ~VT1724_MT_I2S_MCLK_128X; /* 256x MCLK */
401 } else 487 if (val != old) {
402 return 48000; 488 outb(val, ICEMT1724(ice, I2S_FORMAT));
489 /* master clock changed */
490 return 1;
491 }
492 }
493 /* no change in master clock */
494 return 0;
403} 495}
404 496
405static void snd_vt1724_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate, 497static void snd_vt1724_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate,
406 int force) 498 int force)
407{ 499{
408 unsigned long flags; 500 unsigned long flags;
409 unsigned char val, old; 501 unsigned char mclk_change;
410 unsigned int i, mclk_change; 502 unsigned int i, old_rate;
411 503
412 if (rate > get_max_rate(ice)) 504 if (rate > ice->hw_rates->list[ice->hw_rates->count - 1])
413 return; 505 return;
414
415 switch (rate) {
416 case 8000: val = 6; break;
417 case 9600: val = 3; break;
418 case 11025: val = 10; break;
419 case 12000: val = 2; break;
420 case 16000: val = 5; break;
421 case 22050: val = 9; break;
422 case 24000: val = 1; break;
423 case 32000: val = 4; break;
424 case 44100: val = 8; break;
425 case 48000: val = 0; break;
426 case 64000: val = 15; break;
427 case 88200: val = 11; break;
428 case 96000: val = 7; break;
429 case 176400: val = 12; break;
430 case 192000: val = 14; break;
431 default:
432 snd_BUG();
433 val = 0;
434 break;
435 }
436
437 spin_lock_irqsave(&ice->reg_lock, flags); 506 spin_lock_irqsave(&ice->reg_lock, flags);
438 if ((inb(ICEMT1724(ice, DMA_CONTROL)) & DMA_STARTS) || 507 if ((inb(ICEMT1724(ice, DMA_CONTROL)) & DMA_STARTS) ||
439 (inb(ICEMT1724(ice, DMA_PAUSE)) & DMA_PAUSES)) { 508 (inb(ICEMT1724(ice, DMA_PAUSE)) & DMA_PAUSES)) {
440 /* running? we cannot change the rate now... */ 509 /* running? we cannot change the rate now... */
441 spin_unlock_irqrestore(&ice->reg_lock, flags); 510 spin_unlock_irqrestore(&ice->reg_lock, flags);
@@ -446,9 +515,9 @@ static void snd_vt1724_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate,
446 return; 515 return;
447 } 516 }
448 517
449 old = inb(ICEMT1724(ice, RATE)); 518 old_rate = ice->get_rate(ice);
450 if (force || old != val) 519 if (force || (old_rate != rate))
451 outb(val, ICEMT1724(ice, RATE)); 520 ice->set_rate(ice, rate);
452 else if (rate == ice->cur_rate) { 521 else if (rate == ice->cur_rate) {
453 spin_unlock_irqrestore(&ice->reg_lock, flags); 522 spin_unlock_irqrestore(&ice->reg_lock, flags);
454 return; 523 return;
@@ -456,19 +525,9 @@ static void snd_vt1724_set_pro_rate(struct snd_ice1712 *ice, unsigned int rate,
456 525
457 ice->cur_rate = rate; 526 ice->cur_rate = rate;
458 527
459 /* check MT02 */ 528 /* setting master clock */
460 mclk_change = 0; 529 mclk_change = ice->set_mclk(ice, rate);
461 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) { 530
462 val = old = inb(ICEMT1724(ice, I2S_FORMAT));
463 if (rate > 96000)
464 val |= VT1724_MT_I2S_MCLK_128X; /* 128x MCLK */
465 else
466 val &= ~VT1724_MT_I2S_MCLK_128X; /* 256x MCLK */
467 if (val != old) {
468 outb(val, ICEMT1724(ice, I2S_FORMAT));
469 mclk_change = 1;
470 }
471 }
472 spin_unlock_irqrestore(&ice->reg_lock, flags); 531 spin_unlock_irqrestore(&ice->reg_lock, flags);
473 532
474 if (mclk_change && ice->gpio.i2s_mclk_changed) 533 if (mclk_change && ice->gpio.i2s_mclk_changed)
@@ -727,43 +786,32 @@ static const struct snd_pcm_hardware snd_vt1724_2ch_stereo =
727/* 786/*
728 * set rate constraints 787 * set rate constraints
729 */ 788 */
730static int set_rate_constraints(struct snd_ice1712 *ice, 789static void set_std_hw_rates(struct snd_ice1712 *ice)
731 struct snd_pcm_substream *substream)
732{ 790{
733 struct snd_pcm_runtime *runtime = substream->runtime;
734 if (ice->hw_rates) {
735 /* hardware specific */
736 runtime->hw.rate_min = ice->hw_rates->list[0];
737 runtime->hw.rate_max = ice->hw_rates->list[ice->hw_rates->count - 1];
738 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
739 return snd_pcm_hw_constraint_list(runtime, 0,
740 SNDRV_PCM_HW_PARAM_RATE,
741 ice->hw_rates);
742 }
743 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) { 791 if (ice->eeprom.data[ICE_EEP2_ACLINK] & VT1724_CFG_PRO_I2S) {
744 /* I2S */ 792 /* I2S */
745 /* VT1720 doesn't support more than 96kHz */ 793 /* VT1720 doesn't support more than 96kHz */
746 if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720) 794 if ((ice->eeprom.data[ICE_EEP2_I2S] & 0x08) && !ice->vt1720)
747 return snd_pcm_hw_constraint_list(runtime, 0, 795 ice->hw_rates = &hw_constraints_rates_192;
748 SNDRV_PCM_HW_PARAM_RATE, 796 else
749 &hw_constraints_rates_192); 797 ice->hw_rates = &hw_constraints_rates_96;
750 else { 798 } else {
751 runtime->hw.rates = SNDRV_PCM_RATE_KNOT |
752 SNDRV_PCM_RATE_8000_96000;
753 runtime->hw.rate_max = 96000;
754 return snd_pcm_hw_constraint_list(runtime, 0,
755 SNDRV_PCM_HW_PARAM_RATE,
756 &hw_constraints_rates_96);
757 }
758 } else if (ice->ac97) {
759 /* ACLINK */ 799 /* ACLINK */
760 runtime->hw.rate_max = 48000; 800 ice->hw_rates = &hw_constraints_rates_48;
761 runtime->hw.rates = SNDRV_PCM_RATE_KNOT | SNDRV_PCM_RATE_8000_48000;
762 return snd_pcm_hw_constraint_list(runtime, 0,
763 SNDRV_PCM_HW_PARAM_RATE,
764 &hw_constraints_rates_48);
765 } 801 }
766 return 0; 802}
803
804static int set_rate_constraints(struct snd_ice1712 *ice,
805 struct snd_pcm_substream *substream)
806{
807 struct snd_pcm_runtime *runtime = substream->runtime;
808
809 runtime->hw.rate_min = ice->hw_rates->list[0];
810 runtime->hw.rate_max = ice->hw_rates->list[ice->hw_rates->count - 1];
811 runtime->hw.rates = SNDRV_PCM_RATE_KNOT;
812 return snd_pcm_hw_constraint_list(runtime, 0,
813 SNDRV_PCM_HW_PARAM_RATE,
814 ice->hw_rates);
767} 815}
768 816
769/* multi-channel playback needs alignment 8x32bit regardless of the channels 817/* multi-channel playback needs alignment 8x32bit regardless of the channels
@@ -824,7 +872,7 @@ static int snd_vt1724_playback_pro_close(struct snd_pcm_substream *substream)
824 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); 872 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
825 873
826 if (PRO_RATE_RESET) 874 if (PRO_RATE_RESET)
827 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0); 875 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
828 ice->playback_pro_substream = NULL; 876 ice->playback_pro_substream = NULL;
829 877
830 return 0; 878 return 0;
@@ -835,7 +883,7 @@ static int snd_vt1724_capture_pro_close(struct snd_pcm_substream *substream)
835 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); 883 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
836 884
837 if (PRO_RATE_RESET) 885 if (PRO_RATE_RESET)
838 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0); 886 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
839 ice->capture_pro_substream = NULL; 887 ice->capture_pro_substream = NULL;
840 return 0; 888 return 0;
841} 889}
@@ -970,6 +1018,8 @@ static int snd_vt1724_playback_spdif_open(struct snd_pcm_substream *substream)
970 VT1724_BUFFER_ALIGN); 1018 VT1724_BUFFER_ALIGN);
971 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 1019 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
972 VT1724_BUFFER_ALIGN); 1020 VT1724_BUFFER_ALIGN);
1021 if (ice->spdif.ops.open)
1022 ice->spdif.ops.open(ice, substream);
973 return 0; 1023 return 0;
974} 1024}
975 1025
@@ -978,8 +1028,10 @@ static int snd_vt1724_playback_spdif_close(struct snd_pcm_substream *substream)
978 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); 1028 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
979 1029
980 if (PRO_RATE_RESET) 1030 if (PRO_RATE_RESET)
981 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0); 1031 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
982 ice->playback_con_substream = NULL; 1032 ice->playback_con_substream = NULL;
1033 if (ice->spdif.ops.close)
1034 ice->spdif.ops.close(ice, substream);
983 1035
984 return 0; 1036 return 0;
985} 1037}
@@ -1002,6 +1054,8 @@ static int snd_vt1724_capture_spdif_open(struct snd_pcm_substream *substream)
1002 VT1724_BUFFER_ALIGN); 1054 VT1724_BUFFER_ALIGN);
1003 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 1055 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
1004 VT1724_BUFFER_ALIGN); 1056 VT1724_BUFFER_ALIGN);
1057 if (ice->spdif.ops.open)
1058 ice->spdif.ops.open(ice, substream);
1005 return 0; 1059 return 0;
1006} 1060}
1007 1061
@@ -1010,8 +1064,10 @@ static int snd_vt1724_capture_spdif_close(struct snd_pcm_substream *substream)
1010 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); 1064 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1011 1065
1012 if (PRO_RATE_RESET) 1066 if (PRO_RATE_RESET)
1013 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0); 1067 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
1014 ice->capture_con_substream = NULL; 1068 ice->capture_con_substream = NULL;
1069 if (ice->spdif.ops.close)
1070 ice->spdif.ops.close(ice, substream);
1015 1071
1016 return 0; 1072 return 0;
1017} 1073}
@@ -1154,7 +1210,7 @@ static int snd_vt1724_playback_indep_close(struct snd_pcm_substream *substream)
1154 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream); 1210 struct snd_ice1712 *ice = snd_pcm_substream_chip(substream);
1155 1211
1156 if (PRO_RATE_RESET) 1212 if (PRO_RATE_RESET)
1157 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 0); 1213 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 0);
1158 ice->playback_con_substream_ds[substream->number] = NULL; 1214 ice->playback_con_substream_ds[substream->number] = NULL;
1159 ice->pcm_reserved[substream->number] = NULL; 1215 ice->pcm_reserved[substream->number] = NULL;
1160 1216
@@ -1572,50 +1628,18 @@ int snd_ice1712_gpio_put(struct snd_kcontrol *kcontrol,
1572static int snd_vt1724_pro_internal_clock_info(struct snd_kcontrol *kcontrol, 1628static int snd_vt1724_pro_internal_clock_info(struct snd_kcontrol *kcontrol,
1573 struct snd_ctl_elem_info *uinfo) 1629 struct snd_ctl_elem_info *uinfo)
1574{ 1630{
1575 static const char * const texts_1724[] = {
1576 "8000", /* 0: 6 */
1577 "9600", /* 1: 3 */
1578 "11025", /* 2: 10 */
1579 "12000", /* 3: 2 */
1580 "16000", /* 4: 5 */
1581 "22050", /* 5: 9 */
1582 "24000", /* 6: 1 */
1583 "32000", /* 7: 4 */
1584 "44100", /* 8: 8 */
1585 "48000", /* 9: 0 */
1586 "64000", /* 10: 15 */
1587 "88200", /* 11: 11 */
1588 "96000", /* 12: 7 */
1589 "176400", /* 13: 12 */
1590 "192000", /* 14: 14 */
1591 "IEC958 Input", /* 15: -- */
1592 };
1593 static const char * const texts_1720[] = {
1594 "8000", /* 0: 6 */
1595 "9600", /* 1: 3 */
1596 "11025", /* 2: 10 */
1597 "12000", /* 3: 2 */
1598 "16000", /* 4: 5 */
1599 "22050", /* 5: 9 */
1600 "24000", /* 6: 1 */
1601 "32000", /* 7: 4 */
1602 "44100", /* 8: 8 */
1603 "48000", /* 9: 0 */
1604 "64000", /* 10: 15 */
1605 "88200", /* 11: 11 */
1606 "96000", /* 12: 7 */
1607 "IEC958 Input", /* 13: -- */
1608 };
1609 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1631 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1610 1632
1611 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 1633 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
1612 uinfo->count = 1; 1634 uinfo->count = 1;
1613 uinfo->value.enumerated.items = ice->vt1720 ? 14 : 16; 1635 uinfo->value.enumerated.items = ice->hw_rates->count + 1;
1614 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items) 1636 if (uinfo->value.enumerated.item >= uinfo->value.enumerated.items)
1615 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1; 1637 uinfo->value.enumerated.item = uinfo->value.enumerated.items - 1;
1616 strcpy(uinfo->value.enumerated.name, 1638 if (uinfo->value.enumerated.item == uinfo->value.enumerated.items - 1)
1617 ice->vt1720 ? texts_1720[uinfo->value.enumerated.item] : 1639 strcpy(uinfo->value.enumerated.name, "IEC958 Input");
1618 texts_1724[uinfo->value.enumerated.item]); 1640 else
1641 sprintf(uinfo->value.enumerated.name, "%d",
1642 ice->hw_rates->list[uinfo->value.enumerated.item]);
1619 return 0; 1643 return 0;
1620} 1644}
1621 1645
@@ -1623,68 +1647,79 @@ static int snd_vt1724_pro_internal_clock_get(struct snd_kcontrol *kcontrol,
1623 struct snd_ctl_elem_value *ucontrol) 1647 struct snd_ctl_elem_value *ucontrol)
1624{ 1648{
1625 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1649 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1626 static const unsigned char xlate[16] = { 1650 unsigned int i, rate;
1627 9, 6, 3, 1, 7, 4, 0, 12, 8, 5, 2, 11, 13, 255, 14, 10
1628 };
1629 unsigned char val;
1630 1651
1631 spin_lock_irq(&ice->reg_lock); 1652 spin_lock_irq(&ice->reg_lock);
1632 if (is_spdif_master(ice)) { 1653 if (ice->is_spdif_master(ice)) {
1633 ucontrol->value.enumerated.item[0] = ice->vt1720 ? 13 : 15; 1654 ucontrol->value.enumerated.item[0] = ice->hw_rates->count;
1634 } else { 1655 } else {
1635 val = xlate[inb(ICEMT1724(ice, RATE)) & 15]; 1656 rate = ice->get_rate(ice);
1636 if (val == 255) { 1657 ucontrol->value.enumerated.item[0] = 0;
1637 snd_BUG(); 1658 for (i = 0; i < ice->hw_rates->count; i++) {
1638 val = 0; 1659 if (ice->hw_rates->list[i] == rate) {
1660 ucontrol->value.enumerated.item[0] = i;
1661 break;
1662 }
1639 } 1663 }
1640 ucontrol->value.enumerated.item[0] = val;
1641 } 1664 }
1642 spin_unlock_irq(&ice->reg_lock); 1665 spin_unlock_irq(&ice->reg_lock);
1643 return 0; 1666 return 0;
1644} 1667}
1645 1668
1669/* setting clock to external - SPDIF */
1670static void stdclock_set_spdif_clock(struct snd_ice1712 *ice)
1671{
1672 unsigned char oval;
1673 unsigned char i2s_oval;
1674 oval = inb(ICEMT1724(ice, RATE));
1675 outb(oval | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE));
1676 /* setting 256fs */
1677 i2s_oval = inb(ICEMT1724(ice, I2S_FORMAT));
1678 outb(i2s_oval & ~VT1724_MT_I2S_MCLK_128X, ICEMT1724(ice, I2S_FORMAT));
1679}
1680
1646static int snd_vt1724_pro_internal_clock_put(struct snd_kcontrol *kcontrol, 1681static int snd_vt1724_pro_internal_clock_put(struct snd_kcontrol *kcontrol,
1647 struct snd_ctl_elem_value *ucontrol) 1682 struct snd_ctl_elem_value *ucontrol)
1648{ 1683{
1649 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol); 1684 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
1650 unsigned char oval; 1685 unsigned int old_rate, new_rate;
1651 int rate; 1686 unsigned int item = ucontrol->value.enumerated.item[0];
1652 int change = 0; 1687 unsigned int spdif = ice->hw_rates->count;
1653 int spdif = ice->vt1720 ? 13 : 15; 1688
1689 if (item > spdif)
1690 return -EINVAL;
1654 1691
1655 spin_lock_irq(&ice->reg_lock); 1692 spin_lock_irq(&ice->reg_lock);
1656 oval = inb(ICEMT1724(ice, RATE)); 1693 if (ice->is_spdif_master(ice))
1657 if (ucontrol->value.enumerated.item[0] == spdif) { 1694 old_rate = 0;
1658 unsigned char i2s_oval; 1695 else
1659 outb(oval | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE)); 1696 old_rate = ice->get_rate(ice);
1660 /* setting 256fs */ 1697 if (item == spdif) {
1661 i2s_oval = inb(ICEMT1724(ice, I2S_FORMAT)); 1698 /* switching to external clock via SPDIF */
1662 outb(i2s_oval & ~VT1724_MT_I2S_MCLK_128X, 1699 ice->set_spdif_clock(ice);
1663 ICEMT1724(ice, I2S_FORMAT)); 1700 new_rate = 0;
1664 } else { 1701 } else {
1665 rate = rates[ucontrol->value.integer.value[0] % 15]; 1702 /* internal on-card clock */
1666 if (rate <= get_max_rate(ice)) { 1703 new_rate = ice->hw_rates->list[item];
1667 PRO_RATE_DEFAULT = rate; 1704 ice->pro_rate_default = new_rate;
1668 spin_unlock_irq(&ice->reg_lock); 1705 spin_unlock_irq(&ice->reg_lock);
1669 snd_vt1724_set_pro_rate(ice, PRO_RATE_DEFAULT, 1); 1706 snd_vt1724_set_pro_rate(ice, ice->pro_rate_default, 1);
1670 spin_lock_irq(&ice->reg_lock); 1707 spin_lock_irq(&ice->reg_lock);
1671 }
1672 } 1708 }
1673 change = inb(ICEMT1724(ice, RATE)) != oval;
1674 spin_unlock_irq(&ice->reg_lock); 1709 spin_unlock_irq(&ice->reg_lock);
1675 1710
1676 if ((oval & VT1724_SPDIF_MASTER) != 1711 /* the first reset to the SPDIF master mode? */
1677 (inb(ICEMT1724(ice, RATE)) & VT1724_SPDIF_MASTER)) { 1712 if (old_rate != new_rate && !new_rate) {
1678 /* notify akm chips as well */ 1713 /* notify akm chips as well */
1679 if (is_spdif_master(ice)) { 1714 unsigned int i;
1680 unsigned int i; 1715 if (ice->gpio.set_pro_rate)
1681 for (i = 0; i < ice->akm_codecs; i++) { 1716 ice->gpio.set_pro_rate(ice, 0);
1682 if (ice->akm[i].ops.set_rate_val) 1717 for (i = 0; i < ice->akm_codecs; i++) {
1683 ice->akm[i].ops.set_rate_val(&ice->akm[i], 0); 1718 if (ice->akm[i].ops.set_rate_val)
1684 } 1719 ice->akm[i].ops.set_rate_val(&ice->akm[i], 0);
1685 } 1720 }
1686 } 1721 }
1687 return change; 1722 return old_rate != new_rate;
1688} 1723}
1689 1724
1690static struct snd_kcontrol_new snd_vt1724_pro_internal_clock __devinitdata = { 1725static struct snd_kcontrol_new snd_vt1724_pro_internal_clock __devinitdata = {
@@ -2065,12 +2100,16 @@ static int __devinit snd_vt1724_read_eeprom(struct snd_ice1712 *ice,
2065 2100
2066 2101
2067 2102
2068static int __devinit snd_vt1724_chip_init(struct snd_ice1712 *ice) 2103static void __devinit snd_vt1724_chip_reset(struct snd_ice1712 *ice)
2069{ 2104{
2070 outb(VT1724_RESET , ICEREG1724(ice, CONTROL)); 2105 outb(VT1724_RESET , ICEREG1724(ice, CONTROL));
2071 udelay(200); 2106 msleep(10);
2072 outb(0, ICEREG1724(ice, CONTROL)); 2107 outb(0, ICEREG1724(ice, CONTROL));
2073 udelay(200); 2108 msleep(10);
2109}
2110
2111static int __devinit snd_vt1724_chip_init(struct snd_ice1712 *ice)
2112{
2074 outb(ice->eeprom.data[ICE_EEP2_SYSCONF], ICEREG1724(ice, SYS_CFG)); 2113 outb(ice->eeprom.data[ICE_EEP2_SYSCONF], ICEREG1724(ice, SYS_CFG));
2075 outb(ice->eeprom.data[ICE_EEP2_ACLINK], ICEREG1724(ice, AC97_CFG)); 2114 outb(ice->eeprom.data[ICE_EEP2_ACLINK], ICEREG1724(ice, AC97_CFG));
2076 outb(ice->eeprom.data[ICE_EEP2_I2S], ICEREG1724(ice, I2S_FEATURES)); 2115 outb(ice->eeprom.data[ICE_EEP2_I2S], ICEREG1724(ice, I2S_FEATURES));
@@ -2169,10 +2208,8 @@ static int snd_vt1724_free(struct snd_ice1712 *ice)
2169 outb(0xff, ICEREG1724(ice, IRQMASK)); 2208 outb(0xff, ICEREG1724(ice, IRQMASK));
2170 /* --- */ 2209 /* --- */
2171 __hw_end: 2210 __hw_end:
2172 if (ice->irq >= 0) { 2211 if (ice->irq >= 0)
2173 synchronize_irq(ice->irq);
2174 free_irq(ice->irq, ice); 2212 free_irq(ice->irq, ice);
2175 }
2176 pci_release_regions(ice->pci); 2213 pci_release_regions(ice->pci);
2177 snd_ice1712_akm4xxx_free(ice); 2214 snd_ice1712_akm4xxx_free(ice);
2178 pci_disable_device(ice->pci); 2215 pci_disable_device(ice->pci);
@@ -2243,6 +2280,7 @@ static int __devinit snd_vt1724_create(struct snd_card *card,
2243 2280
2244 ice->irq = pci->irq; 2281 ice->irq = pci->irq;
2245 2282
2283 snd_vt1724_chip_reset(ice);
2246 if (snd_vt1724_read_eeprom(ice, modelname) < 0) { 2284 if (snd_vt1724_read_eeprom(ice, modelname) < 0) {
2247 snd_vt1724_free(ice); 2285 snd_vt1724_free(ice);
2248 return -EIO; 2286 return -EIO;
@@ -2253,10 +2291,7 @@ static int __devinit snd_vt1724_create(struct snd_card *card,
2253 } 2291 }
2254 2292
2255 /* unmask used interrupts */ 2293 /* unmask used interrupts */
2256 if (! (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401)) 2294 mask = VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX;
2257 mask = VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX;
2258 else
2259 mask = 0;
2260 outb(mask, ICEREG1724(ice, IRQMASK)); 2295 outb(mask, ICEREG1724(ice, IRQMASK));
2261 /* don't handle FIFO overrun/underruns (just yet), 2296 /* don't handle FIFO overrun/underruns (just yet),
2262 * since they cause machine lockups 2297 * since they cause machine lockups
@@ -2335,6 +2370,19 @@ static int __devinit snd_vt1724_probe(struct pci_dev *pci,
2335 * was called so in ice1712 driver, and vt1724 driver is derived from 2370 * was called so in ice1712 driver, and vt1724 driver is derived from
2336 * ice1712 driver. 2371 * ice1712 driver.
2337 */ 2372 */
2373 ice->pro_rate_default = PRO_RATE_DEFAULT;
2374 if (!ice->is_spdif_master)
2375 ice->is_spdif_master = stdclock_is_spdif_master;
2376 if (!ice->get_rate)
2377 ice->get_rate = stdclock_get_rate;
2378 if (!ice->set_rate)
2379 ice->set_rate = stdclock_set_rate;
2380 if (!ice->set_mclk)
2381 ice->set_mclk = stdclock_set_mclk;
2382 if (!ice->set_spdif_clock)
2383 ice->set_spdif_clock = stdclock_set_spdif_clock;
2384 if (!ice->hw_rates)
2385 set_std_hw_rates(ice);
2338 2386
2339 if ((err = snd_vt1724_pcm_profi(ice, pcm_dev++)) < 0) { 2387 if ((err = snd_vt1724_pcm_profi(ice, pcm_dev++)) < 0) {
2340 snd_card_free(card); 2388 snd_card_free(card);
@@ -2377,14 +2425,29 @@ static int __devinit snd_vt1724_probe(struct pci_dev *pci,
2377 2425
2378 if (! c->no_mpu401) { 2426 if (! c->no_mpu401) {
2379 if (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401) { 2427 if (ice->eeprom.data[ICE_EEP2_SYSCONF] & VT1724_CFG_MPU401) {
2428 struct snd_mpu401 *mpu;
2380 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712, 2429 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
2381 ICEREG1724(ice, MPU_CTRL), 2430 ICEREG1724(ice, MPU_CTRL),
2382 MPU401_INFO_INTEGRATED, 2431 (MPU401_INFO_INTEGRATED |
2432 MPU401_INFO_TX_IRQ),
2383 ice->irq, 0, 2433 ice->irq, 0,
2384 &ice->rmidi[0])) < 0) { 2434 &ice->rmidi[0])) < 0) {
2385 snd_card_free(card); 2435 snd_card_free(card);
2386 return err; 2436 return err;
2387 } 2437 }
2438 mpu = ice->rmidi[0]->private_data;
2439 mpu->read = snd_vt1724_mpu401_read;
2440 mpu->write = snd_vt1724_mpu401_write;
2441 /* unmask MPU RX/TX irqs */
2442 outb(inb(ICEREG1724(ice, IRQMASK)) &
2443 ~(VT1724_IRQ_MPU_RX | VT1724_IRQ_MPU_TX),
2444 ICEREG1724(ice, IRQMASK));
2445#if 0 /* for testing */
2446 /* set watermarks */
2447 outb(VT1724_MPU_RX_FIFO | 0x1,
2448 ICEREG1724(ice, MPU_FIFO_WM));
2449 outb(0x1, ICEREG1724(ice, MPU_FIFO_WM));
2450#endif
2388 } 2451 }
2389 } 2452 }
2390 2453
diff --git a/sound/pci/ice1712/juli.c b/sound/pci/ice1712/juli.c
index e8038c0ceb72..b4e0c16852a6 100644
--- a/sound/pci/ice1712/juli.c
+++ b/sound/pci/ice1712/juli.c
@@ -4,6 +4,8 @@
4 * Lowlevel functions for ESI Juli@ cards 4 * Lowlevel functions for ESI Juli@ cards
5 * 5 *
6 * Copyright (c) 2004 Jaroslav Kysela <perex@perex.cz> 6 * Copyright (c) 2004 Jaroslav Kysela <perex@perex.cz>
7 * 2008 Pavel Hofman <dustin@seznam.cz>
8 *
7 * 9 *
8 * This program is free software; you can redistribute it and/or modify 10 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 11 * it under the terms of the GNU General Public License as published by
@@ -27,11 +29,11 @@
27#include <linux/init.h> 29#include <linux/init.h>
28#include <linux/slab.h> 30#include <linux/slab.h>
29#include <sound/core.h> 31#include <sound/core.h>
32#include <sound/tlv.h>
30 33
31#include "ice1712.h" 34#include "ice1712.h"
32#include "envy24ht.h" 35#include "envy24ht.h"
33#include "juli.h" 36#include "juli.h"
34
35struct juli_spec { 37struct juli_spec {
36 struct ak4114 *ak4114; 38 struct ak4114 *ak4114;
37 unsigned int analog: 1; 39 unsigned int analog: 1;
@@ -44,6 +46,32 @@ struct juli_spec {
44#define AK4358_ADDR 0x22 /* DAC */ 46#define AK4358_ADDR 0x22 /* DAC */
45 47
46/* 48/*
49 * Juli does not use the standard ICE1724 clock scheme. Juli's ice1724 chip is
50 * supplied by external clock provided by Xilinx array and MK73-1 PLL frequency
51 * multiplier. Actual frequency is set by ice1724 GPIOs hooked to the Xilinx.
52 *
53 * The clock circuitry is supplied by the two ice1724 crystals. This
54 * arrangement allows to generate independent clock signal for AK4114's input
55 * rate detection circuit. As a result, Juli, unlike most other
56 * ice1724+ak4114-based cards, detects spdif input rate correctly.
57 * This fact is applied in the driver, allowing to modify PCM stream rate
58 * parameter according to the actual input rate.
59 *
60 * Juli uses the remaining three stereo-channels of its DAC to optionally
61 * monitor analog input, digital input, and digital output. The corresponding
62 * I2S signals are routed by Xilinx, controlled by GPIOs.
63 *
64 * The master mute is implemented using output muting transistors (GPIO) in
65 * combination with smuting the DAC.
66 *
67 * The card itself has no HW master volume control, implemented using the
68 * vmaster control.
69 *
70 * TODO:
71 * researching and fixing the input monitors
72 */
73
74/*
47 * GPIO pins 75 * GPIO pins
48 */ 76 */
49#define GPIO_FREQ_MASK (3<<0) 77#define GPIO_FREQ_MASK (3<<0)
@@ -55,17 +83,82 @@ struct juli_spec {
55#define GPIO_MULTI_2X (1<<2) 83#define GPIO_MULTI_2X (1<<2)
56#define GPIO_MULTI_1X (2<<2) /* also external */ 84#define GPIO_MULTI_1X (2<<2) /* also external */
57#define GPIO_MULTI_HALF (3<<2) 85#define GPIO_MULTI_HALF (3<<2)
58#define GPIO_INTERNAL_CLOCK (1<<4) 86#define GPIO_INTERNAL_CLOCK (1<<4) /* 0 = external, 1 = internal */
87#define GPIO_CLOCK_MASK (1<<4)
59#define GPIO_ANALOG_PRESENT (1<<5) /* RO only: 0 = present */ 88#define GPIO_ANALOG_PRESENT (1<<5) /* RO only: 0 = present */
60#define GPIO_RXMCLK_SEL (1<<7) /* must be 0 */ 89#define GPIO_RXMCLK_SEL (1<<7) /* must be 0 */
61#define GPIO_AK5385A_CKS0 (1<<8) 90#define GPIO_AK5385A_CKS0 (1<<8)
62#define GPIO_AK5385A_DFS0 (1<<9) /* swapped with DFS1 according doc? */ 91#define GPIO_AK5385A_DFS1 (1<<9)
63#define GPIO_AK5385A_DFS1 (1<<10) 92#define GPIO_AK5385A_DFS0 (1<<10)
64#define GPIO_DIGOUT_MONITOR (1<<11) /* 1 = active */ 93#define GPIO_DIGOUT_MONITOR (1<<11) /* 1 = active */
65#define GPIO_DIGIN_MONITOR (1<<12) /* 1 = active */ 94#define GPIO_DIGIN_MONITOR (1<<12) /* 1 = active */
66#define GPIO_ANAIN_MONITOR (1<<13) /* 1 = active */ 95#define GPIO_ANAIN_MONITOR (1<<13) /* 1 = active */
67#define GPIO_AK5385A_MCLK (1<<14) /* must be 0 */ 96#define GPIO_AK5385A_CKS1 (1<<14) /* must be 0 */
68#define GPIO_MUTE_CONTROL (1<<15) /* 0 = off, 1 = on */ 97#define GPIO_MUTE_CONTROL (1<<15) /* output mute, 1 = muted */
98
99#define GPIO_RATE_MASK (GPIO_FREQ_MASK | GPIO_MULTI_MASK | \
100 GPIO_CLOCK_MASK)
101#define GPIO_AK5385A_MASK (GPIO_AK5385A_CKS0 | GPIO_AK5385A_DFS0 | \
102 GPIO_AK5385A_DFS1 | GPIO_AK5385A_CKS1)
103
104#define JULI_PCM_RATE (SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | \
105 SNDRV_PCM_RATE_32000 | SNDRV_PCM_RATE_44100 | \
106 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_64000 | \
107 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 | \
108 SNDRV_PCM_RATE_176400 | SNDRV_PCM_RATE_192000)
109
110#define GPIO_RATE_16000 (GPIO_FREQ_32KHZ | GPIO_MULTI_HALF | \
111 GPIO_INTERNAL_CLOCK)
112#define GPIO_RATE_22050 (GPIO_FREQ_44KHZ | GPIO_MULTI_HALF | \
113 GPIO_INTERNAL_CLOCK)
114#define GPIO_RATE_24000 (GPIO_FREQ_48KHZ | GPIO_MULTI_HALF | \
115 GPIO_INTERNAL_CLOCK)
116#define GPIO_RATE_32000 (GPIO_FREQ_32KHZ | GPIO_MULTI_1X | \
117 GPIO_INTERNAL_CLOCK)
118#define GPIO_RATE_44100 (GPIO_FREQ_44KHZ | GPIO_MULTI_1X | \
119 GPIO_INTERNAL_CLOCK)
120#define GPIO_RATE_48000 (GPIO_FREQ_48KHZ | GPIO_MULTI_1X | \
121 GPIO_INTERNAL_CLOCK)
122#define GPIO_RATE_64000 (GPIO_FREQ_32KHZ | GPIO_MULTI_2X | \
123 GPIO_INTERNAL_CLOCK)
124#define GPIO_RATE_88200 (GPIO_FREQ_44KHZ | GPIO_MULTI_2X | \
125 GPIO_INTERNAL_CLOCK)
126#define GPIO_RATE_96000 (GPIO_FREQ_48KHZ | GPIO_MULTI_2X | \
127 GPIO_INTERNAL_CLOCK)
128#define GPIO_RATE_176400 (GPIO_FREQ_44KHZ | GPIO_MULTI_4X | \
129 GPIO_INTERNAL_CLOCK)
130#define GPIO_RATE_192000 (GPIO_FREQ_48KHZ | GPIO_MULTI_4X | \
131 GPIO_INTERNAL_CLOCK)
132
133/*
134 * Initial setup of the conversion array GPIO <-> rate
135 */
136static unsigned int juli_rates[] = {
137 16000, 22050, 24000, 32000,
138 44100, 48000, 64000, 88200,
139 96000, 176400, 192000,
140};
141
142static unsigned int gpio_vals[] = {
143 GPIO_RATE_16000, GPIO_RATE_22050, GPIO_RATE_24000, GPIO_RATE_32000,
144 GPIO_RATE_44100, GPIO_RATE_48000, GPIO_RATE_64000, GPIO_RATE_88200,
145 GPIO_RATE_96000, GPIO_RATE_176400, GPIO_RATE_192000,
146};
147
148static struct snd_pcm_hw_constraint_list juli_rates_info = {
149 .count = ARRAY_SIZE(juli_rates),
150 .list = juli_rates,
151 .mask = 0,
152};
153
154static int get_gpio_val(int rate)
155{
156 int i;
157 for (i = 0; i < ARRAY_SIZE(juli_rates); i++)
158 if (juli_rates[i] == rate)
159 return gpio_vals[i];
160 return 0;
161}
69 162
70static void juli_ak4114_write(void *private_data, unsigned char reg, unsigned char val) 163static void juli_ak4114_write(void *private_data, unsigned char reg, unsigned char val)
71{ 164{
@@ -78,6 +171,27 @@ static unsigned char juli_ak4114_read(void *private_data, unsigned char reg)
78} 171}
79 172
80/* 173/*
174 * If SPDIF capture and slaved to SPDIF-IN, setting runtime rate
175 * to the external rate
176 */
177static void juli_spdif_in_open(struct snd_ice1712 *ice,
178 struct snd_pcm_substream *substream)
179{
180 struct juli_spec *spec = ice->spec;
181 struct snd_pcm_runtime *runtime = substream->runtime;
182 int rate;
183
184 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK ||
185 !ice->is_spdif_master(ice))
186 return;
187 rate = snd_ak4114_external_rate(spec->ak4114);
188 if (rate >= runtime->hw.rate_min && rate <= runtime->hw.rate_max) {
189 runtime->hw.rate_min = rate;
190 runtime->hw.rate_max = rate;
191 }
192}
193
194/*
81 * AK4358 section 195 * AK4358 section
82 */ 196 */
83 197
@@ -99,57 +213,285 @@ static void juli_akm_write(struct snd_akm4xxx *ak, int chip,
99} 213}
100 214
101/* 215/*
102 * change the rate of envy24HT, AK4358 216 * change the rate of envy24HT, AK4358, AK5385
103 */ 217 */
104static void juli_akm_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate) 218static void juli_akm_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
105{ 219{
106 unsigned char old, tmp, dfs; 220 unsigned char old, tmp, ak4358_dfs;
221 unsigned int ak5385_pins, old_gpio, new_gpio;
222 struct snd_ice1712 *ice = ak->private_data[0];
223 struct juli_spec *spec = ice->spec;
107 224
108 if (rate == 0) /* no hint - S/PDIF input is master, simply return */ 225 if (rate == 0) /* no hint - S/PDIF input is master or the new spdif
226 input rate undetected, simply return */
109 return; 227 return;
110 228
111 /* adjust DFS on codecs */ 229 /* adjust DFS on codecs */
112 if (rate > 96000) 230 if (rate > 96000) {
113 dfs = 2; 231 ak4358_dfs = 2;
114 else if (rate > 48000) 232 ak5385_pins = GPIO_AK5385A_DFS1 | GPIO_AK5385A_CKS0;
115 dfs = 1; 233 } else if (rate > 48000) {
116 else 234 ak4358_dfs = 1;
117 dfs = 0; 235 ak5385_pins = GPIO_AK5385A_DFS0;
118 236 } else {
237 ak4358_dfs = 0;
238 ak5385_pins = 0;
239 }
240 /* AK5385 first, since it requires cold reset affecting both codecs */
241 old_gpio = ice->gpio.get_data(ice);
242 new_gpio = (old_gpio & ~GPIO_AK5385A_MASK) | ak5385_pins;
243 /* printk(KERN_DEBUG "JULI - ak5385 set_rate_val: new gpio 0x%x\n",
244 new_gpio); */
245 ice->gpio.set_data(ice, new_gpio);
246
247 /* cold reset */
248 old = inb(ICEMT1724(ice, AC97_CMD));
249 outb(old | VT1724_AC97_COLD, ICEMT1724(ice, AC97_CMD));
250 udelay(1);
251 outb(old & ~VT1724_AC97_COLD, ICEMT1724(ice, AC97_CMD));
252
253 /* AK4358 */
254 /* set new value, reset DFS */
119 tmp = snd_akm4xxx_get(ak, 0, 2); 255 tmp = snd_akm4xxx_get(ak, 0, 2);
120 old = (tmp >> 4) & 0x03;
121 if (old == dfs)
122 return;
123 /* reset DFS */
124 snd_akm4xxx_reset(ak, 1); 256 snd_akm4xxx_reset(ak, 1);
125 tmp = snd_akm4xxx_get(ak, 0, 2); 257 tmp = snd_akm4xxx_get(ak, 0, 2);
126 tmp &= ~(0x03 << 4); 258 tmp &= ~(0x03 << 4);
127 tmp |= dfs << 4; 259 tmp |= ak4358_dfs << 4;
128 snd_akm4xxx_set(ak, 0, 2, tmp); 260 snd_akm4xxx_set(ak, 0, 2, tmp);
129 snd_akm4xxx_reset(ak, 0); 261 snd_akm4xxx_reset(ak, 0);
262
263 /* reinit ak4114 */
264 snd_ak4114_reinit(spec->ak4114);
130} 265}
131 266
267#define AK_DAC(xname, xch) { .name = xname, .num_channels = xch }
268#define PCM_VOLUME "PCM Playback Volume"
269#define MONITOR_AN_IN_VOLUME "Monitor Analog In Volume"
270#define MONITOR_DIG_IN_VOLUME "Monitor Digital In Volume"
271#define MONITOR_DIG_OUT_VOLUME "Monitor Digital Out Volume"
272
273static const struct snd_akm4xxx_dac_channel juli_dac[] = {
274 AK_DAC(PCM_VOLUME, 2),
275 AK_DAC(MONITOR_AN_IN_VOLUME, 2),
276 AK_DAC(MONITOR_DIG_OUT_VOLUME, 2),
277 AK_DAC(MONITOR_DIG_IN_VOLUME, 2),
278};
279
280
132static struct snd_akm4xxx akm_juli_dac __devinitdata = { 281static struct snd_akm4xxx akm_juli_dac __devinitdata = {
133 .type = SND_AK4358, 282 .type = SND_AK4358,
134 .num_dacs = 2, 283 .num_dacs = 8, /* DAC1 - analog out
284 DAC2 - analog in monitor
285 DAC3 - digital out monitor
286 DAC4 - digital in monitor
287 */
135 .ops = { 288 .ops = {
136 .lock = juli_akm_lock, 289 .lock = juli_akm_lock,
137 .unlock = juli_akm_unlock, 290 .unlock = juli_akm_unlock,
138 .write = juli_akm_write, 291 .write = juli_akm_write,
139 .set_rate_val = juli_akm_set_rate_val 292 .set_rate_val = juli_akm_set_rate_val
293 },
294 .dac_info = juli_dac,
295};
296
297#define juli_mute_info snd_ctl_boolean_mono_info
298
299static int juli_mute_get(struct snd_kcontrol *kcontrol,
300 struct snd_ctl_elem_value *ucontrol)
301{
302 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
303 unsigned int val;
304 val = ice->gpio.get_data(ice) & (unsigned int) kcontrol->private_value;
305 if (kcontrol->private_value == GPIO_MUTE_CONTROL)
306 /* val 0 = signal on */
307 ucontrol->value.integer.value[0] = (val) ? 0 : 1;
308 else
309 /* val 1 = signal on */
310 ucontrol->value.integer.value[0] = (val) ? 1 : 0;
311 return 0;
312}
313
314static int juli_mute_put(struct snd_kcontrol *kcontrol,
315 struct snd_ctl_elem_value *ucontrol)
316{
317 struct snd_ice1712 *ice = snd_kcontrol_chip(kcontrol);
318 unsigned int old_gpio, new_gpio;
319 old_gpio = ice->gpio.get_data(ice);
320 if (ucontrol->value.integer.value[0]) {
321 /* unmute */
322 if (kcontrol->private_value == GPIO_MUTE_CONTROL) {
323 /* 0 = signal on */
324 new_gpio = old_gpio & ~GPIO_MUTE_CONTROL;
325 /* un-smuting DAC */
326 snd_akm4xxx_write(ice->akm, 0, 0x01, 0x01);
327 } else
328 /* 1 = signal on */
329 new_gpio = old_gpio |
330 (unsigned int) kcontrol->private_value;
331 } else {
332 /* mute */
333 if (kcontrol->private_value == GPIO_MUTE_CONTROL) {
334 /* 1 = signal off */
335 new_gpio = old_gpio | GPIO_MUTE_CONTROL;
336 /* smuting DAC */
337 snd_akm4xxx_write(ice->akm, 0, 0x01, 0x03);
338 } else
339 /* 0 = signal off */
340 new_gpio = old_gpio &
341 ~((unsigned int) kcontrol->private_value);
342 }
343 /* printk("JULI - mute/unmute: control_value: 0x%x, old_gpio: 0x%x, \
344 new_gpio 0x%x\n",
345 (unsigned int)ucontrol->value.integer.value[0], old_gpio,
346 new_gpio); */
347 if (old_gpio != new_gpio) {
348 ice->gpio.set_data(ice, new_gpio);
349 return 1;
350 }
351 /* no change */
352 return 0;
353}
354
355static struct snd_kcontrol_new juli_mute_controls[] __devinitdata = {
356 {
357 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
358 .name = "Master Playback Switch",
359 .info = juli_mute_info,
360 .get = juli_mute_get,
361 .put = juli_mute_put,
362 .private_value = GPIO_MUTE_CONTROL,
363 },
364 /* Although the following functionality respects the succint NDA'd
365 * documentation from the card manufacturer, and the same way of
366 * operation is coded in OSS Juli driver, only Digital Out monitor
367 * seems to work. Surprisingly, Analog input monitor outputs Digital
368 * output data. The two are independent, as enabling both doubles
369 * volume of the monitor sound.
370 *
371 * Checking traces on the board suggests the functionality described
372 * by the manufacturer is correct - I2S from ADC and AK4114
373 * go to ICE as well as to Xilinx, I2S inputs of DAC2,3,4 (the monitor
374 * inputs) are fed from Xilinx.
375 *
376 * I even checked traces on board and coded a support in driver for
377 * an alternative possiblity - the unused I2S ICE output channels
378 * switched to HW-IN/SPDIF-IN and providing the monitoring signal to
379 * the DAC - to no avail. The I2S outputs seem to be unconnected.
380 *
381 * The windows driver supports the monitoring correctly.
382 */
383 {
384 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
385 .name = "Monitor Analog In Switch",
386 .info = juli_mute_info,
387 .get = juli_mute_get,
388 .put = juli_mute_put,
389 .private_value = GPIO_ANAIN_MONITOR,
390 },
391 {
392 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
393 .name = "Monitor Digital Out Switch",
394 .info = juli_mute_info,
395 .get = juli_mute_get,
396 .put = juli_mute_put,
397 .private_value = GPIO_DIGOUT_MONITOR,
398 },
399 {
400 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
401 .name = "Monitor Digital In Switch",
402 .info = juli_mute_info,
403 .get = juli_mute_get,
404 .put = juli_mute_put,
405 .private_value = GPIO_DIGIN_MONITOR,
406 },
407};
408
409
410static void ak4358_proc_regs_read(struct snd_info_entry *entry,
411 struct snd_info_buffer *buffer)
412{
413 struct snd_ice1712 *ice = (struct snd_ice1712 *)entry->private_data;
414 int reg, val;
415 for (reg = 0; reg <= 0xf; reg++) {
416 val = snd_akm4xxx_get(ice->akm, 0, reg);
417 snd_iprintf(buffer, "0x%02x = 0x%02x\n", reg, val);
140 } 418 }
419}
420
421static void ak4358_proc_init(struct snd_ice1712 *ice)
422{
423 struct snd_info_entry *entry;
424 if (!snd_card_proc_new(ice->card, "ak4358_codec", &entry))
425 snd_info_set_text_ops(entry, ice, ak4358_proc_regs_read);
426}
427
428static char *slave_vols[] __devinitdata = {
429 PCM_VOLUME,
430 MONITOR_AN_IN_VOLUME,
431 MONITOR_DIG_IN_VOLUME,
432 MONITOR_DIG_OUT_VOLUME,
433 NULL
141}; 434};
142 435
436static __devinitdata
437DECLARE_TLV_DB_SCALE(juli_master_db_scale, -6350, 50, 1);
438
439static struct snd_kcontrol __devinit *ctl_find(struct snd_card *card,
440 const char *name)
441{
442 struct snd_ctl_elem_id sid;
443 memset(&sid, 0, sizeof(sid));
444 /* FIXME: strcpy is bad. */
445 strcpy(sid.name, name);
446 sid.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
447 return snd_ctl_find_id(card, &sid);
448}
449
450static void __devinit add_slaves(struct snd_card *card,
451 struct snd_kcontrol *master, char **list)
452{
453 for (; *list; list++) {
454 struct snd_kcontrol *slave = ctl_find(card, *list);
455 /* printk(KERN_DEBUG "add_slaves - %s\n", *list); */
456 if (slave) {
457 /* printk(KERN_DEBUG "slave %s found\n", *list); */
458 snd_ctl_add_slave(master, slave);
459 }
460 }
461}
462
143static int __devinit juli_add_controls(struct snd_ice1712 *ice) 463static int __devinit juli_add_controls(struct snd_ice1712 *ice)
144{ 464{
145 struct juli_spec *spec = ice->spec; 465 struct juli_spec *spec = ice->spec;
146 int err; 466 int err;
467 unsigned int i;
468 struct snd_kcontrol *vmaster;
469
147 err = snd_ice1712_akm4xxx_build_controls(ice); 470 err = snd_ice1712_akm4xxx_build_controls(ice);
148 if (err < 0) 471 if (err < 0)
149 return err; 472 return err;
473
474 for (i = 0; i < ARRAY_SIZE(juli_mute_controls); i++) {
475 err = snd_ctl_add(ice->card,
476 snd_ctl_new1(&juli_mute_controls[i], ice));
477 if (err < 0)
478 return err;
479 }
480 /* Create virtual master control */
481 vmaster = snd_ctl_make_virtual_master("Master Playback Volume",
482 juli_master_db_scale);
483 if (!vmaster)
484 return -ENOMEM;
485 add_slaves(ice->card, vmaster, slave_vols);
486 err = snd_ctl_add(ice->card, vmaster);
487 if (err < 0)
488 return err;
489
150 /* only capture SPDIF over AK4114 */ 490 /* only capture SPDIF over AK4114 */
151 err = snd_ak4114_build(spec->ak4114, NULL, 491 err = snd_ak4114_build(spec->ak4114, NULL,
152 ice->pcm_pro->streams[SNDRV_PCM_STREAM_CAPTURE].substream); 492 ice->pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream);
493
494 ak4358_proc_init(ice);
153 if (err < 0) 495 if (err < 0)
154 return err; 496 return err;
155 return 0; 497 return 0;
@@ -158,6 +500,74 @@ static int __devinit juli_add_controls(struct snd_ice1712 *ice)
158/* 500/*
159 * initialize the chip 501 * initialize the chip
160 */ 502 */
503
504static inline int juli_is_spdif_master(struct snd_ice1712 *ice)
505{
506 return (ice->gpio.get_data(ice) & GPIO_INTERNAL_CLOCK) ? 0 : 1;
507}
508
509static unsigned int juli_get_rate(struct snd_ice1712 *ice)
510{
511 int i;
512 unsigned char result;
513
514 result = ice->gpio.get_data(ice) & GPIO_RATE_MASK;
515 for (i = 0; i < ARRAY_SIZE(gpio_vals); i++)
516 if (gpio_vals[i] == result)
517 return juli_rates[i];
518 return 0;
519}
520
521/* setting new rate */
522static void juli_set_rate(struct snd_ice1712 *ice, unsigned int rate)
523{
524 unsigned int old, new;
525 unsigned char val;
526
527 old = ice->gpio.get_data(ice);
528 new = (old & ~GPIO_RATE_MASK) | get_gpio_val(rate);
529 /* printk(KERN_DEBUG "JULI - set_rate: old %x, new %x\n",
530 old & GPIO_RATE_MASK,
531 new & GPIO_RATE_MASK); */
532
533 ice->gpio.set_data(ice, new);
534 /* switching to external clock - supplied by external circuits */
535 val = inb(ICEMT1724(ice, RATE));
536 outb(val | VT1724_SPDIF_MASTER, ICEMT1724(ice, RATE));
537}
538
539static inline unsigned char juli_set_mclk(struct snd_ice1712 *ice,
540 unsigned int rate)
541{
542 /* no change in master clock */
543 return 0;
544}
545
546/* setting clock to external - SPDIF */
547static void juli_set_spdif_clock(struct snd_ice1712 *ice)
548{
549 unsigned int old;
550 old = ice->gpio.get_data(ice);
551 /* external clock (= 0), multiply 1x, 48kHz */
552 ice->gpio.set_data(ice, (old & ~GPIO_RATE_MASK) | GPIO_MULTI_1X |
553 GPIO_FREQ_48KHZ);
554}
555
556/* Called when ak4114 detects change in the input SPDIF stream */
557static void juli_ak4114_change(struct ak4114 *ak4114, unsigned char c0,
558 unsigned char c1)
559{
560 struct snd_ice1712 *ice = ak4114->change_callback_private;
561 int rate;
562 if (ice->is_spdif_master(ice) && c1) {
563 /* only for SPDIF master mode, rate was changed */
564 rate = snd_ak4114_external_rate(ak4114);
565 /* printk(KERN_DEBUG "ak4114 - input rate changed to %d\n",
566 rate); */
567 juli_akm_set_rate_val(ice->akm, rate);
568 }
569}
570
161static int __devinit juli_init(struct snd_ice1712 *ice) 571static int __devinit juli_init(struct snd_ice1712 *ice)
162{ 572{
163 static const unsigned char ak4114_init_vals[] = { 573 static const unsigned char ak4114_init_vals[] = {
@@ -187,6 +597,11 @@ static int __devinit juli_init(struct snd_ice1712 *ice)
187 ice, &spec->ak4114); 597 ice, &spec->ak4114);
188 if (err < 0) 598 if (err < 0)
189 return err; 599 return err;
600 /* callback for codecs rate setting */
601 spec->ak4114->change_callback = juli_ak4114_change;
602 spec->ak4114->change_callback_private = ice;
603 /* AK4114 in Juli can detect external rate correctly */
604 spec->ak4114->check_flags = 0;
190 605
191#if 0 606#if 0
192 /* it seems that the analog doughter board detection does not work 607 /* it seems that the analog doughter board detection does not work
@@ -210,6 +625,15 @@ static int __devinit juli_init(struct snd_ice1712 *ice)
210 return err; 625 return err;
211 } 626 }
212 627
628 /* juli is clocked by Xilinx array */
629 ice->hw_rates = &juli_rates_info;
630 ice->is_spdif_master = juli_is_spdif_master;
631 ice->get_rate = juli_get_rate;
632 ice->set_rate = juli_set_rate;
633 ice->set_mclk = juli_set_mclk;
634 ice->set_spdif_clock = juli_set_spdif_clock;
635
636 ice->spdif.ops.open = juli_spdif_in_open;
213 return 0; 637 return 0;
214} 638}
215 639
@@ -220,18 +644,20 @@ static int __devinit juli_init(struct snd_ice1712 *ice)
220 */ 644 */
221 645
222static unsigned char juli_eeprom[] __devinitdata = { 646static unsigned char juli_eeprom[] __devinitdata = {
223 [ICE_EEP2_SYSCONF] = 0x20, /* clock 512, mpu401, 1xADC, 1xDACs */ 647 [ICE_EEP2_SYSCONF] = 0x2b, /* clock 512, mpu401, 1xADC, 1xDACs,
648 SPDIF in */
224 [ICE_EEP2_ACLINK] = 0x80, /* I2S */ 649 [ICE_EEP2_ACLINK] = 0x80, /* I2S */
225 [ICE_EEP2_I2S] = 0xf8, /* vol, 96k, 24bit, 192k */ 650 [ICE_EEP2_I2S] = 0xf8, /* vol, 96k, 24bit, 192k */
226 [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */ 651 [ICE_EEP2_SPDIF] = 0xc3, /* out-en, out-int, spdif-in */
227 [ICE_EEP2_GPIO_DIR] = 0x9f, 652 [ICE_EEP2_GPIO_DIR] = 0x9f, /* 5, 6:inputs; 7, 4-0 outputs*/
228 [ICE_EEP2_GPIO_DIR1] = 0xff, 653 [ICE_EEP2_GPIO_DIR1] = 0xff,
229 [ICE_EEP2_GPIO_DIR2] = 0x7f, 654 [ICE_EEP2_GPIO_DIR2] = 0x7f,
230 [ICE_EEP2_GPIO_MASK] = 0x9f, 655 [ICE_EEP2_GPIO_MASK] = 0x60, /* 5, 6: locked; 7, 4-0 writable */
231 [ICE_EEP2_GPIO_MASK1] = 0xff, 656 [ICE_EEP2_GPIO_MASK1] = 0x00, /* 0-7 writable */
232 [ICE_EEP2_GPIO_MASK2] = 0x7f, 657 [ICE_EEP2_GPIO_MASK2] = 0x7f,
233 [ICE_EEP2_GPIO_STATE] = 0x16, /* internal clock, multiple 1x, 48kHz */ 658 [ICE_EEP2_GPIO_STATE] = GPIO_FREQ_48KHZ | GPIO_MULTI_1X |
234 [ICE_EEP2_GPIO_STATE1] = 0x80, /* mute */ 659 GPIO_INTERNAL_CLOCK, /* internal clock, multiple 1x, 48kHz*/
660 [ICE_EEP2_GPIO_STATE1] = 0x00, /* unmuted */
235 [ICE_EEP2_GPIO_STATE2] = 0x00, 661 [ICE_EEP2_GPIO_STATE2] = 0x00,
236}; 662};
237 663
diff --git a/sound/pci/ice1712/pontis.c b/sound/pci/ice1712/pontis.c
index 4945c81e8a96..203cdc1bf8da 100644
--- a/sound/pci/ice1712/pontis.c
+++ b/sound/pci/ice1712/pontis.c
@@ -246,7 +246,7 @@ static int wm_adc_mux_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_val
246 wm_put(ice, WM_ADC_MUX, nval); 246 wm_put(ice, WM_ADC_MUX, nval);
247 } 247 }
248 mutex_unlock(&ice->gpio_mutex); 248 mutex_unlock(&ice->gpio_mutex);
249 return 0; 249 return change;
250} 250}
251 251
252/* 252/*
@@ -450,7 +450,7 @@ static int cs_source_put(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_valu
450 change = 1; 450 change = 1;
451 } 451 }
452 mutex_unlock(&ice->gpio_mutex); 452 mutex_unlock(&ice->gpio_mutex);
453 return 0; 453 return change;
454} 454}
455 455
456 456
diff --git a/sound/pci/ice1712/prodigy192.c b/sound/pci/ice1712/prodigy192.c
index 48cf40a8f32a..48d3679292a7 100644
--- a/sound/pci/ice1712/prodigy192.c
+++ b/sound/pci/ice1712/prodigy192.c
@@ -319,12 +319,11 @@ static int stac9460_mic_sw_put(struct snd_kcontrol *kcontrol,
319/* 319/*
320 * Handler for setting correct codec rate - called when rate change is detected 320 * Handler for setting correct codec rate - called when rate change is detected
321 */ 321 */
322static void stac9460_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate) 322static void stac9460_set_rate_val(struct snd_ice1712 *ice, unsigned int rate)
323{ 323{
324 unsigned char old, new; 324 unsigned char old, new;
325 int idx; 325 int idx;
326 unsigned char changed[7]; 326 unsigned char changed[7];
327 struct snd_ice1712 *ice = ak->private_data[0];
328 struct prodigy192_spec *spec = ice->spec; 327 struct prodigy192_spec *spec = ice->spec;
329 328
330 if (rate == 0) /* no hint - S/PDIF input is master, simply return */ 329 if (rate == 0) /* no hint - S/PDIF input is master, simply return */
@@ -357,16 +356,6 @@ static void stac9460_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
357 mutex_unlock(&spec->mute_mutex); 356 mutex_unlock(&spec->mute_mutex);
358} 357}
359 358
360/* using akm infrastructure for setting rate of the codec */
361static struct snd_akm4xxx akmlike_stac9460 __devinitdata = {
362 .type = NON_AKM, /* special value */
363 .num_adcs = 6, /* not used in any way, just for completeness */
364 .num_dacs = 2,
365 .ops = {
366 .set_rate_val = stac9460_set_rate_val
367 }
368};
369
370 359
371static const DECLARE_TLV_DB_SCALE(db_scale_dac, -19125, 75, 0); 360static const DECLARE_TLV_DB_SCALE(db_scale_dac, -19125, 75, 0);
372static const DECLARE_TLV_DB_SCALE(db_scale_adc, 0, 150, 0); 361static const DECLARE_TLV_DB_SCALE(db_scale_adc, 0, 150, 0);
@@ -642,12 +631,19 @@ static int prodigy192_ak4114_init(struct snd_ice1712 *ice)
642 0x41, 0x02, 0x2c, 0x00, 0x00 631 0x41, 0x02, 0x2c, 0x00, 0x00
643 }; 632 };
644 struct prodigy192_spec *spec = ice->spec; 633 struct prodigy192_spec *spec = ice->spec;
634 int err;
645 635
646 return snd_ak4114_create(ice->card, 636 err = snd_ak4114_create(ice->card,
647 prodigy192_ak4114_read, 637 prodigy192_ak4114_read,
648 prodigy192_ak4114_write, 638 prodigy192_ak4114_write,
649 ak4114_init_vals, ak4114_init_txcsb, 639 ak4114_init_vals, ak4114_init_txcsb,
650 ice, &spec->ak4114); 640 ice, &spec->ak4114);
641 if (err < 0)
642 return err;
643 /* AK4114 in Prodigy192 cannot detect external rate correctly.
644 * No reason to stop capture stream due to incorrect checks */
645 spec->ak4114->check_flags = AK4114_CHECK_NO_RATE;
646 return 0;
651} 647}
652 648
653static void stac9460_proc_regs_read(struct snd_info_entry *entry, 649static void stac9460_proc_regs_read(struct snd_info_entry *entry,
@@ -743,7 +739,6 @@ static int __devinit prodigy192_init(struct snd_ice1712 *ice)
743 }; 739 };
744 const unsigned short *p; 740 const unsigned short *p;
745 int err = 0; 741 int err = 0;
746 struct snd_akm4xxx *ak;
747 struct prodigy192_spec *spec; 742 struct prodigy192_spec *spec;
748 743
749 /* prodigy 192 */ 744 /* prodigy 192 */
@@ -761,15 +756,7 @@ static int __devinit prodigy192_init(struct snd_ice1712 *ice)
761 p = stac_inits_prodigy; 756 p = stac_inits_prodigy;
762 for (; *p != (unsigned short)-1; p += 2) 757 for (; *p != (unsigned short)-1; p += 2)
763 stac9460_put(ice, p[0], p[1]); 758 stac9460_put(ice, p[0], p[1]);
764 /* reusing the akm codecs infrastructure, 759 ice->gpio.set_pro_rate = stac9460_set_rate_val;
765 * for setting rate on stac9460 */
766 ak = ice->akm = kmalloc(sizeof(struct snd_akm4xxx), GFP_KERNEL);
767 if (!ak)
768 return -ENOMEM;
769 ice->akm_codecs = 1;
770 err = snd_ice1712_akm4xxx_init(ak, &akmlike_stac9460, NULL, ice);
771 if (err < 0)
772 return err;
773 760
774 /* MI/ODI/O add on card with AK4114 */ 761 /* MI/ODI/O add on card with AK4114 */
775 if (prodigy192_miodio_exists(ice)) { 762 if (prodigy192_miodio_exists(ice)) {
@@ -825,10 +812,6 @@ struct snd_ice1712_card_info snd_vt1724_prodigy192_cards[] __devinitdata = {
825 .build_controls = prodigy192_add_controls, 812 .build_controls = prodigy192_add_controls,
826 .eeprom_size = sizeof(prodigy71_eeprom), 813 .eeprom_size = sizeof(prodigy71_eeprom),
827 .eeprom_data = prodigy71_eeprom, 814 .eeprom_data = prodigy71_eeprom,
828 /* the current MPU401 code loops infinitely
829 * when opening midi device
830 */
831 .no_mpu401 = 1,
832 }, 815 },
833 { } /* terminator */ 816 { } /* terminator */
834}; 817};
diff --git a/sound/pci/ice1712/revo.c b/sound/pci/ice1712/revo.c
index 301bf929acd9..4d2631434dc8 100644
--- a/sound/pci/ice1712/revo.c
+++ b/sound/pci/ice1712/revo.c
@@ -322,17 +322,23 @@ static struct snd_pt2258 ptc_revo51_volume;
322static void ap192_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate) 322static void ap192_set_rate_val(struct snd_akm4xxx *ak, unsigned int rate)
323{ 323{
324 struct snd_ice1712 *ice = ak->private_data[0]; 324 struct snd_ice1712 *ice = ak->private_data[0];
325 int dfs;
325 326
326 revo_set_rate_val(ak, rate); 327 revo_set_rate_val(ak, rate);
327 328
328#if 1 /* FIXME: do we need this procedure? */ 329 /* reset CKS */
329 /* reset DFS pin of AK5385A for ADC, too */ 330 snd_ice1712_gpio_write_bits(ice, 1 << 8, rate > 96000 ? 1 << 8 : 0);
330 /* DFS0 (pin 18) -- GPIO10 pin 77 */ 331 /* reset DFS pins of AK5385A for ADC, too */
331 snd_ice1712_save_gpio_status(ice); 332 if (rate > 96000)
332 snd_ice1712_gpio_write_bits(ice, 1 << 10, 333 dfs = 2;
333 rate > 48000 ? (1 << 10) : 0); 334 else if (rate > 48000)
334 snd_ice1712_restore_gpio_status(ice); 335 dfs = 1;
335#endif 336 else
337 dfs = 0;
338 snd_ice1712_gpio_write_bits(ice, 3 << 9, dfs << 9);
339 /* reset ADC */
340 snd_ice1712_gpio_write_bits(ice, 1 << 11, 0);
341 snd_ice1712_gpio_write_bits(ice, 1 << 11, 1 << 11);
336} 342}
337 343
338static const struct snd_akm4xxx_dac_channel ap192_dac[] = { 344static const struct snd_akm4xxx_dac_channel ap192_dac[] = {
@@ -353,28 +359,20 @@ static struct snd_ak4xxx_private akm_ap192_priv __devinitdata = {
353 .cif = 0, 359 .cif = 0,
354 .data_mask = VT1724_REVO_CDOUT, 360 .data_mask = VT1724_REVO_CDOUT,
355 .clk_mask = VT1724_REVO_CCLK, 361 .clk_mask = VT1724_REVO_CCLK,
356 .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS3, 362 .cs_mask = VT1724_REVO_CS0 | VT1724_REVO_CS1,
357 .cs_addr = VT1724_REVO_CS3, 363 .cs_addr = VT1724_REVO_CS1,
358 .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS3, 364 .cs_none = VT1724_REVO_CS0 | VT1724_REVO_CS1,
359 .add_flags = VT1724_REVO_CCLK, /* high at init */ 365 .add_flags = VT1724_REVO_CCLK, /* high at init */
360 .mask_flags = 0, 366 .mask_flags = 0,
361}; 367};
362 368
363#if 0
364/* FIXME: ak4114 makes the sound much lower due to some confliction,
365 * so let's disable it right now...
366 */
367#define BUILD_AK4114_AP192
368#endif
369
370#ifdef BUILD_AK4114_AP192
371/* AK4114 support on Audiophile 192 */ 369/* AK4114 support on Audiophile 192 */
372/* CDTO (pin 32) -- GPIO2 pin 52 370/* CDTO (pin 32) -- GPIO2 pin 52
373 * CDTI (pin 33) -- GPIO3 pin 53 (shared with AK4358) 371 * CDTI (pin 33) -- GPIO3 pin 53 (shared with AK4358)
374 * CCLK (pin 34) -- GPIO1 pin 51 (shared with AK4358) 372 * CCLK (pin 34) -- GPIO1 pin 51 (shared with AK4358)
375 * CSN (pin 35) -- GPIO7 pin 59 373 * CSN (pin 35) -- GPIO7 pin 59
376 */ 374 */
377#define AK4114_ADDR 0x00 375#define AK4114_ADDR 0x02
378 376
379static void write_data(struct snd_ice1712 *ice, unsigned int gpio, 377static void write_data(struct snd_ice1712 *ice, unsigned int gpio,
380 unsigned int data, int idx) 378 unsigned int data, int idx)
@@ -428,7 +426,7 @@ static unsigned int ap192_4wire_start(struct snd_ice1712 *ice)
428 tmp = snd_ice1712_gpio_read(ice); 426 tmp = snd_ice1712_gpio_read(ice);
429 tmp |= VT1724_REVO_CCLK; /* high at init */ 427 tmp |= VT1724_REVO_CCLK; /* high at init */
430 tmp |= VT1724_REVO_CS0; 428 tmp |= VT1724_REVO_CS0;
431 tmp &= ~VT1724_REVO_CS3; 429 tmp &= ~VT1724_REVO_CS1;
432 snd_ice1712_gpio_write(ice, tmp); 430 snd_ice1712_gpio_write(ice, tmp);
433 udelay(1); 431 udelay(1);
434 return tmp; 432 return tmp;
@@ -436,7 +434,7 @@ static unsigned int ap192_4wire_start(struct snd_ice1712 *ice)
436 434
437static void ap192_4wire_finish(struct snd_ice1712 *ice, unsigned int tmp) 435static void ap192_4wire_finish(struct snd_ice1712 *ice, unsigned int tmp)
438{ 436{
439 tmp |= VT1724_REVO_CS3; 437 tmp |= VT1724_REVO_CS1;
440 tmp |= VT1724_REVO_CS0; 438 tmp |= VT1724_REVO_CS0;
441 snd_ice1712_gpio_write(ice, tmp); 439 snd_ice1712_gpio_write(ice, tmp);
442 udelay(1); 440 udelay(1);
@@ -485,13 +483,17 @@ static int __devinit ap192_ak4114_init(struct snd_ice1712 *ice)
485 struct ak4114 *ak; 483 struct ak4114 *ak;
486 int err; 484 int err;
487 485
488 return snd_ak4114_create(ice->card, 486 err = snd_ak4114_create(ice->card,
489 ap192_ak4114_read, 487 ap192_ak4114_read,
490 ap192_ak4114_write, 488 ap192_ak4114_write,
491 ak4114_init_vals, ak4114_init_txcsb, 489 ak4114_init_vals, ak4114_init_txcsb,
492 ice, &ak); 490 ice, &ak);
491 /* AK4114 in Revo cannot detect external rate correctly.
492 * No reason to stop capture stream due to incorrect checks */
493 ak->check_flags = AK4114_CHECK_NO_RATE;
494
495 return 0; /* error ignored; it's no fatal error */
493} 496}
494#endif /* BUILD_AK4114_AP192 */
495 497
496static int __devinit revo_init(struct snd_ice1712 *ice) 498static int __devinit revo_init(struct snd_ice1712 *ice)
497{ 499{
@@ -557,6 +559,9 @@ static int __devinit revo_init(struct snd_ice1712 *ice)
557 if (err < 0) 559 if (err < 0)
558 return err; 560 return err;
559 561
562 /* unmute all codecs */
563 snd_ice1712_gpio_write_bits(ice, VT1724_REVO_MUTE,
564 VT1724_REVO_MUTE);
560 break; 565 break;
561 } 566 }
562 567
@@ -588,11 +593,9 @@ static int __devinit revo_add_controls(struct snd_ice1712 *ice)
588 err = snd_ice1712_akm4xxx_build_controls(ice); 593 err = snd_ice1712_akm4xxx_build_controls(ice);
589 if (err < 0) 594 if (err < 0)
590 return err; 595 return err;
591#ifdef BUILD_AK4114_AP192
592 err = ap192_ak4114_init(ice); 596 err = ap192_ak4114_init(ice);
593 if (err < 0) 597 if (err < 0)
594 return err; 598 return err;
595#endif
596 break; 599 break;
597 } 600 }
598 return 0; 601 return 0;
diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c
index c52abd0bf22e..048d99e25ab0 100644
--- a/sound/pci/intel8x0.c
+++ b/sound/pci/intel8x0.c
@@ -155,7 +155,8 @@ DEFINE_REGSET(SP, 0x60); /* SPDIF out */
155#define ICH_PCM_SPDIF_69 0x80000000 /* s/pdif pcm on slots 6&9 */ 155#define ICH_PCM_SPDIF_69 0x80000000 /* s/pdif pcm on slots 6&9 */
156#define ICH_PCM_SPDIF_1011 0xc0000000 /* s/pdif pcm on slots 10&11 */ 156#define ICH_PCM_SPDIF_1011 0xc0000000 /* s/pdif pcm on slots 10&11 */
157#define ICH_PCM_20BIT 0x00400000 /* 20-bit samples (ICH4) */ 157#define ICH_PCM_20BIT 0x00400000 /* 20-bit samples (ICH4) */
158#define ICH_PCM_246_MASK 0x00300000 /* 6 channels (not all chips) */ 158#define ICH_PCM_246_MASK 0x00300000 /* chan mask (not all chips) */
159#define ICH_PCM_8 0x00300000 /* 8 channels (not all chips) */
159#define ICH_PCM_6 0x00200000 /* 6 channels (not all chips) */ 160#define ICH_PCM_6 0x00200000 /* 6 channels (not all chips) */
160#define ICH_PCM_4 0x00100000 /* 4 channels (not all chips) */ 161#define ICH_PCM_4 0x00100000 /* 4 channels (not all chips) */
161#define ICH_PCM_2 0x00000000 /* 2 channels (stereo) */ 162#define ICH_PCM_2 0x00000000 /* 2 channels (stereo) */
@@ -382,6 +383,7 @@ struct intel8x0 {
382 383
383 unsigned multi4: 1, 384 unsigned multi4: 1,
384 multi6: 1, 385 multi6: 1,
386 multi8 :1,
385 dra: 1, 387 dra: 1,
386 smp20bit: 1; 388 smp20bit: 1;
387 unsigned in_ac97_init: 1, 389 unsigned in_ac97_init: 1,
@@ -997,6 +999,8 @@ static void snd_intel8x0_setup_pcm_out(struct intel8x0 *chip,
997 cnt |= ICH_PCM_4; 999 cnt |= ICH_PCM_4;
998 else if (runtime->channels == 6) 1000 else if (runtime->channels == 6)
999 cnt |= ICH_PCM_6; 1001 cnt |= ICH_PCM_6;
1002 else if (runtime->channels == 8)
1003 cnt |= ICH_PCM_8;
1000 if (chip->device_type == DEVICE_NFORCE) { 1004 if (chip->device_type == DEVICE_NFORCE) {
1001 /* reset to 2ch once to keep the 6 channel data in alignment, 1005 /* reset to 2ch once to keep the 6 channel data in alignment,
1002 * to start from Front Left always 1006 * to start from Front Left always
@@ -1106,6 +1110,16 @@ static struct snd_pcm_hw_constraint_list hw_constraints_channels6 = {
1106 .mask = 0, 1110 .mask = 0,
1107}; 1111};
1108 1112
1113static unsigned int channels8[] = {
1114 2, 4, 6, 8,
1115};
1116
1117static struct snd_pcm_hw_constraint_list hw_constraints_channels8 = {
1118 .count = ARRAY_SIZE(channels8),
1119 .list = channels8,
1120 .mask = 0,
1121};
1122
1109static int snd_intel8x0_pcm_open(struct snd_pcm_substream *substream, struct ichdev *ichdev) 1123static int snd_intel8x0_pcm_open(struct snd_pcm_substream *substream, struct ichdev *ichdev)
1110{ 1124{
1111 struct intel8x0 *chip = snd_pcm_substream_chip(substream); 1125 struct intel8x0 *chip = snd_pcm_substream_chip(substream);
@@ -1136,7 +1150,12 @@ static int snd_intel8x0_playback_open(struct snd_pcm_substream *substream)
1136 if (err < 0) 1150 if (err < 0)
1137 return err; 1151 return err;
1138 1152
1139 if (chip->multi6) { 1153 if (chip->multi8) {
1154 runtime->hw.channels_max = 8;
1155 snd_pcm_hw_constraint_list(runtime, 0,
1156 SNDRV_PCM_HW_PARAM_CHANNELS,
1157 &hw_constraints_channels8);
1158 } else if (chip->multi6) {
1140 runtime->hw.channels_max = 6; 1159 runtime->hw.channels_max = 6;
1141 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 1160 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS,
1142 &hw_constraints_channels6); 1161 &hw_constraints_channels6);
@@ -2203,8 +2222,11 @@ static int __devinit snd_intel8x0_mixer(struct intel8x0 *chip, int ac97_clock,
2203 } 2222 }
2204 if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_PCM_SLEFT)) { 2223 if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_PCM_SLEFT)) {
2205 chip->multi4 = 1; 2224 chip->multi4 = 1;
2206 if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_LFE)) 2225 if (pbus->pcms[0].r[0].slots & (1 << AC97_SLOT_LFE)) {
2207 chip->multi6 = 1; 2226 chip->multi6 = 1;
2227 if (chip->ac97[0]->flags & AC97_HAS_8CH)
2228 chip->multi8 = 1;
2229 }
2208 } 2230 }
2209 if (pbus->pcms[0].r[1].rslots[0]) { 2231 if (pbus->pcms[0].r[1].rslots[0]) {
2210 chip->dra = 1; 2232 chip->dra = 1;
@@ -2446,7 +2468,7 @@ static int snd_intel8x0_free(struct intel8x0 *chip)
2446 pci_write_config_dword(chip->pci, 0x4c, val); 2468 pci_write_config_dword(chip->pci, 0x4c, val);
2447 } 2469 }
2448 /* --- */ 2470 /* --- */
2449 synchronize_irq(chip->irq); 2471
2450 __hw_end: 2472 __hw_end:
2451 if (chip->irq >= 0) 2473 if (chip->irq >= 0)
2452 free_irq(chip->irq, chip); 2474 free_irq(chip->irq, chip);
@@ -2495,7 +2517,6 @@ static int intel8x0_suspend(struct pci_dev *pci, pm_message_t state)
2495 chip->sdm_saved = igetbyte(chip, ICHREG(SDM)); 2517 chip->sdm_saved = igetbyte(chip, ICHREG(SDM));
2496 2518
2497 if (chip->irq >= 0) { 2519 if (chip->irq >= 0) {
2498 synchronize_irq(chip->irq);
2499 free_irq(chip->irq, chip); 2520 free_irq(chip->irq, chip);
2500 chip->irq = -1; 2521 chip->irq = -1;
2501 } 2522 }
@@ -2648,7 +2669,7 @@ static void __devinit intel8x0_measure_ac97_clock(struct intel8x0 *chip)
2648 t = stop_time.tv_sec - start_time.tv_sec; 2669 t = stop_time.tv_sec - start_time.tv_sec;
2649 t *= 1000000; 2670 t *= 1000000;
2650 t += stop_time.tv_usec - start_time.tv_usec; 2671 t += stop_time.tv_usec - start_time.tv_usec;
2651 printk(KERN_INFO "%s: measured %lu usecs\n", __FUNCTION__, t); 2672 printk(KERN_INFO "%s: measured %lu usecs\n", __func__, t);
2652 if (t == 0) { 2673 if (t == 0) {
2653 snd_printk(KERN_ERR "?? calculation error..\n"); 2674 snd_printk(KERN_ERR "?? calculation error..\n");
2654 return; 2675 return;
diff --git a/sound/pci/intel8x0m.c b/sound/pci/intel8x0m.c
index cadda8d6b70f..faf674e671ac 100644
--- a/sound/pci/intel8x0m.c
+++ b/sound/pci/intel8x0m.c
@@ -985,17 +985,15 @@ static int snd_intel8x0_free(struct intel8x0m *chip)
985 /* reset channels */ 985 /* reset channels */
986 for (i = 0; i < chip->bdbars_count; i++) 986 for (i = 0; i < chip->bdbars_count; i++)
987 iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS); 987 iputbyte(chip, ICH_REG_OFF_CR + chip->ichd[i].reg_offset, ICH_RESETREGS);
988 /* --- */ 988 __hw_end:
989 synchronize_irq(chip->irq); 989 if (chip->irq >= 0)
990 __hw_end: 990 free_irq(chip->irq, chip);
991 if (chip->bdbars.area) 991 if (chip->bdbars.area)
992 snd_dma_free_pages(&chip->bdbars); 992 snd_dma_free_pages(&chip->bdbars);
993 if (chip->addr) 993 if (chip->addr)
994 pci_iounmap(chip->pci, chip->addr); 994 pci_iounmap(chip->pci, chip->addr);
995 if (chip->bmaddr) 995 if (chip->bmaddr)
996 pci_iounmap(chip->pci, chip->bmaddr); 996 pci_iounmap(chip->pci, chip->bmaddr);
997 if (chip->irq >= 0)
998 free_irq(chip->irq, chip);
999 pci_release_regions(chip->pci); 997 pci_release_regions(chip->pci);
1000 pci_disable_device(chip->pci); 998 pci_disable_device(chip->pci);
1001 kfree(chip); 999 kfree(chip);
@@ -1017,7 +1015,6 @@ static int intel8x0m_suspend(struct pci_dev *pci, pm_message_t state)
1017 snd_pcm_suspend_all(chip->pcm[i]); 1015 snd_pcm_suspend_all(chip->pcm[i]);
1018 snd_ac97_suspend(chip->ac97); 1016 snd_ac97_suspend(chip->ac97);
1019 if (chip->irq >= 0) { 1017 if (chip->irq >= 0) {
1020 synchronize_irq(chip->irq);
1021 free_irq(chip->irq, chip); 1018 free_irq(chip->irq, chip);
1022 chip->irq = -1; 1019 chip->irq = -1;
1023 } 1020 }
diff --git a/sound/pci/korg1212/korg1212.c b/sound/pci/korg1212/korg1212.c
index 10c713d9ac49..f4c85b52bde3 100644
--- a/sound/pci/korg1212/korg1212.c
+++ b/sound/pci/korg1212/korg1212.c
@@ -2102,7 +2102,6 @@ snd_korg1212_free(struct snd_korg1212 *korg1212)
2102 snd_korg1212_TurnOffIdleMonitor(korg1212); 2102 snd_korg1212_TurnOffIdleMonitor(korg1212);
2103 2103
2104 if (korg1212->irq >= 0) { 2104 if (korg1212->irq >= 0) {
2105 synchronize_irq(korg1212->irq);
2106 snd_korg1212_DisableCardInterrupts(korg1212); 2105 snd_korg1212_DisableCardInterrupts(korg1212);
2107 free_irq(korg1212->irq, korg1212); 2106 free_irq(korg1212->irq, korg1212);
2108 korg1212->irq = -1; 2107 korg1212->irq = -1;
diff --git a/sound/pci/maestro3.c b/sound/pci/maestro3.c
index 04fa0a68416c..a536c59fbea1 100644
--- a/sound/pci/maestro3.c
+++ b/sound/pci/maestro3.c
@@ -2068,7 +2068,7 @@ static int __devinit snd_m3_mixer(struct snd_m3 *chip)
2068{ 2068{
2069 struct snd_ac97_bus *pbus; 2069 struct snd_ac97_bus *pbus;
2070 struct snd_ac97_template ac97; 2070 struct snd_ac97_template ac97;
2071 struct snd_ctl_elem_id id; 2071 struct snd_ctl_elem_id elem_id;
2072 int err; 2072 int err;
2073 static struct snd_ac97_bus_ops ops = { 2073 static struct snd_ac97_bus_ops ops = {
2074 .write = snd_m3_ac97_write, 2074 .write = snd_m3_ac97_write,
@@ -2088,14 +2088,14 @@ static int __devinit snd_m3_mixer(struct snd_m3 *chip)
2088 schedule_timeout_uninterruptible(msecs_to_jiffies(100)); 2088 schedule_timeout_uninterruptible(msecs_to_jiffies(100));
2089 snd_ac97_write(chip->ac97, AC97_PCM, 0); 2089 snd_ac97_write(chip->ac97, AC97_PCM, 0);
2090 2090
2091 memset(&id, 0, sizeof(id)); 2091 memset(&elem_id, 0, sizeof(elem_id));
2092 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 2092 elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2093 strcpy(id.name, "Master Playback Switch"); 2093 strcpy(elem_id.name, "Master Playback Switch");
2094 chip->master_switch = snd_ctl_find_id(chip->card, &id); 2094 chip->master_switch = snd_ctl_find_id(chip->card, &elem_id);
2095 memset(&id, 0, sizeof(id)); 2095 memset(&elem_id, 0, sizeof(elem_id));
2096 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 2096 elem_id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
2097 strcpy(id.name, "Master Playback Volume"); 2097 strcpy(elem_id.name, "Master Playback Volume");
2098 chip->master_volume = snd_ctl_find_id(chip->card, &id); 2098 chip->master_volume = snd_ctl_find_id(chip->card, &elem_id);
2099 2099
2100 return 0; 2100 return 0;
2101} 2101}
@@ -2542,10 +2542,8 @@ static int snd_m3_free(struct snd_m3 *chip)
2542 vfree(chip->suspend_mem); 2542 vfree(chip->suspend_mem);
2543#endif 2543#endif
2544 2544
2545 if (chip->irq >= 0) { 2545 if (chip->irq >= 0)
2546 synchronize_irq(chip->irq);
2547 free_irq(chip->irq, chip); 2546 free_irq(chip->irq, chip);
2548 }
2549 2547
2550 if (chip->iobase) 2548 if (chip->iobase)
2551 pci_release_regions(chip->pci); 2549 pci_release_regions(chip->pci);
@@ -2569,7 +2567,7 @@ static int m3_suspend(struct pci_dev *pci, pm_message_t state)
2569{ 2567{
2570 struct snd_card *card = pci_get_drvdata(pci); 2568 struct snd_card *card = pci_get_drvdata(pci);
2571 struct snd_m3 *chip = card->private_data; 2569 struct snd_m3 *chip = card->private_data;
2572 int i, index; 2570 int i, dsp_index;
2573 2571
2574 if (chip->suspend_mem == NULL) 2572 if (chip->suspend_mem == NULL)
2575 return 0; 2573 return 0;
@@ -2583,12 +2581,12 @@ static int m3_suspend(struct pci_dev *pci, pm_message_t state)
2583 snd_m3_assp_halt(chip); 2581 snd_m3_assp_halt(chip);
2584 2582
2585 /* save dsp image */ 2583 /* save dsp image */
2586 index = 0; 2584 dsp_index = 0;
2587 for (i = REV_B_CODE_MEMORY_BEGIN; i <= REV_B_CODE_MEMORY_END; i++) 2585 for (i = REV_B_CODE_MEMORY_BEGIN; i <= REV_B_CODE_MEMORY_END; i++)
2588 chip->suspend_mem[index++] = 2586 chip->suspend_mem[dsp_index++] =
2589 snd_m3_assp_read(chip, MEMTYPE_INTERNAL_CODE, i); 2587 snd_m3_assp_read(chip, MEMTYPE_INTERNAL_CODE, i);
2590 for (i = REV_B_DATA_MEMORY_BEGIN ; i <= REV_B_DATA_MEMORY_END; i++) 2588 for (i = REV_B_DATA_MEMORY_BEGIN ; i <= REV_B_DATA_MEMORY_END; i++)
2591 chip->suspend_mem[index++] = 2589 chip->suspend_mem[dsp_index++] =
2592 snd_m3_assp_read(chip, MEMTYPE_INTERNAL_DATA, i); 2590 snd_m3_assp_read(chip, MEMTYPE_INTERNAL_DATA, i);
2593 2591
2594 pci_disable_device(pci); 2592 pci_disable_device(pci);
@@ -2601,7 +2599,7 @@ static int m3_resume(struct pci_dev *pci)
2601{ 2599{
2602 struct snd_card *card = pci_get_drvdata(pci); 2600 struct snd_card *card = pci_get_drvdata(pci);
2603 struct snd_m3 *chip = card->private_data; 2601 struct snd_m3 *chip = card->private_data;
2604 int i, index; 2602 int i, dsp_index;
2605 2603
2606 if (chip->suspend_mem == NULL) 2604 if (chip->suspend_mem == NULL)
2607 return 0; 2605 return 0;
@@ -2625,13 +2623,13 @@ static int m3_resume(struct pci_dev *pci)
2625 snd_m3_ac97_reset(chip); 2623 snd_m3_ac97_reset(chip);
2626 2624
2627 /* restore dsp image */ 2625 /* restore dsp image */
2628 index = 0; 2626 dsp_index = 0;
2629 for (i = REV_B_CODE_MEMORY_BEGIN; i <= REV_B_CODE_MEMORY_END; i++) 2627 for (i = REV_B_CODE_MEMORY_BEGIN; i <= REV_B_CODE_MEMORY_END; i++)
2630 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_CODE, i, 2628 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_CODE, i,
2631 chip->suspend_mem[index++]); 2629 chip->suspend_mem[dsp_index++]);
2632 for (i = REV_B_DATA_MEMORY_BEGIN ; i <= REV_B_DATA_MEMORY_END; i++) 2630 for (i = REV_B_DATA_MEMORY_BEGIN ; i <= REV_B_DATA_MEMORY_END; i++)
2633 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, i, 2631 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, i,
2634 chip->suspend_mem[index++]); 2632 chip->suspend_mem[dsp_index++]);
2635 2633
2636 /* tell the dma engine to restart itself */ 2634 /* tell the dma engine to restart itself */
2637 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA, 2635 snd_m3_assp_write(chip, MEMTYPE_INTERNAL_DATA,
diff --git a/sound/pci/nm256/nm256.c b/sound/pci/nm256/nm256.c
index 7ac654e381da..7efb838d18a6 100644
--- a/sound/pci/nm256/nm256.c
+++ b/sound/pci/nm256/nm256.c
@@ -1439,7 +1439,7 @@ static int snd_nm256_free(struct nm256 *chip)
1439 snd_nm256_capture_stop(chip); 1439 snd_nm256_capture_stop(chip);
1440 1440
1441 if (chip->irq >= 0) 1441 if (chip->irq >= 0)
1442 synchronize_irq(chip->irq); 1442 free_irq(chip->irq, chip);
1443 1443
1444 if (chip->cport) 1444 if (chip->cport)
1445 iounmap(chip->cport); 1445 iounmap(chip->cport);
@@ -1447,8 +1447,6 @@ static int snd_nm256_free(struct nm256 *chip)
1447 iounmap(chip->buffer); 1447 iounmap(chip->buffer);
1448 release_and_free_resource(chip->res_cport); 1448 release_and_free_resource(chip->res_cport);
1449 release_and_free_resource(chip->res_buffer); 1449 release_and_free_resource(chip->res_buffer);
1450 if (chip->irq >= 0)
1451 free_irq(chip->irq, chip);
1452 1450
1453 pci_disable_device(chip->pci); 1451 pci_disable_device(chip->pci);
1454 kfree(chip->ac97_regs); 1452 kfree(chip->ac97_regs);
diff --git a/sound/pci/oxygen/cs4362a.h b/sound/pci/oxygen/cs4362a.h
new file mode 100644
index 000000000000..6a4fedf5e1ec
--- /dev/null
+++ b/sound/pci/oxygen/cs4362a.h
@@ -0,0 +1,69 @@
1/* register 01h */
2#define CS4362A_PDN 0x01
3#define CS4362A_DAC1_DIS 0x02
4#define CS4362A_DAC2_DIS 0x04
5#define CS4362A_DAC3_DIS 0x08
6#define CS4362A_MCLKDIV 0x20
7#define CS4362A_FREEZE 0x40
8#define CS4362A_CPEN 0x80
9/* register 02h */
10#define CS4362A_DIF_MASK 0x70
11#define CS4362A_DIF_LJUST 0x00
12#define CS4362A_DIF_I2S 0x10
13#define CS4362A_DIF_RJUST_16 0x20
14#define CS4362A_DIF_RJUST_24 0x30
15#define CS4362A_DIF_RJUST_20 0x40
16#define CS4362A_DIF_RJUST_18 0x50
17/* register 03h */
18#define CS4362A_MUTEC_MASK 0x03
19#define CS4362A_MUTEC_6 0x00
20#define CS4362A_MUTEC_1 0x01
21#define CS4362A_MUTEC_3 0x03
22#define CS4362A_AMUTE 0x04
23#define CS4362A_MUTEC_POL 0x08
24#define CS4362A_RMP_UP 0x10
25#define CS4362A_SNGLVOL 0x20
26#define CS4362A_ZERO_CROSS 0x40
27#define CS4362A_SOFT_RAMP 0x80
28/* register 04h */
29#define CS4362A_RMP_DN 0x01
30#define CS4362A_DEM_MASK 0x06
31#define CS4362A_DEM_NONE 0x00
32#define CS4362A_DEM_44100 0x02
33#define CS4362A_DEM_48000 0x04
34#define CS4362A_DEM_32000 0x06
35#define CS4362A_FILT_SEL 0x10
36/* register 05h */
37#define CS4362A_INV_A1 0x01
38#define CS4362A_INV_B1 0x02
39#define CS4362A_INV_A2 0x04
40#define CS4362A_INV_B2 0x08
41#define CS4362A_INV_A3 0x10
42#define CS4362A_INV_B3 0x20
43/* register 06h */
44#define CS4362A_FM_MASK 0x03
45#define CS4362A_FM_SINGLE 0x00
46#define CS4362A_FM_DOUBLE 0x01
47#define CS4362A_FM_QUAD 0x02
48#define CS4362A_FM_DSD 0x03
49#define CS4362A_ATAPI_MASK 0x7c
50#define CS4362A_ATAPI_B_MUTE 0x00
51#define CS4362A_ATAPI_B_R 0x04
52#define CS4362A_ATAPI_B_L 0x08
53#define CS4362A_ATAPI_B_LR 0x0c
54#define CS4362A_ATAPI_A_MUTE 0x00
55#define CS4362A_ATAPI_A_R 0x10
56#define CS4362A_ATAPI_A_L 0x20
57#define CS4362A_ATAPI_A_LR 0x30
58#define CS4362A_ATAPI_MIX_LR_VOL 0x40
59#define CS4362A_A_EQ_B 0x80
60/* register 07h */
61#define CS4362A_VOL_MASK 0x7f
62#define CS4362A_MUTE 0x80
63/* register 08h: like 07h */
64/* registers 09h..0Bh: like 06h..08h */
65/* registers 0Ch..0Eh: like 06h..08h */
66/* register 12h */
67#define CS4362A_REV_MASK 0x07
68#define CS4362A_PART_MASK 0xf8
69#define CS4362A_PART_CS4362A 0x50
diff --git a/sound/pci/oxygen/cs4398.h b/sound/pci/oxygen/cs4398.h
new file mode 100644
index 000000000000..5faf5efc8826
--- /dev/null
+++ b/sound/pci/oxygen/cs4398.h
@@ -0,0 +1,69 @@
1/* register 1 */
2#define CS4398_REV_MASK 0x07
3#define CS4398_PART_MASK 0xf8
4#define CS4398_PART_CS4398 0x70
5/* register 2 */
6#define CS4398_FM_MASK 0x03
7#define CS4398_FM_SINGLE 0x00
8#define CS4398_FM_DOUBLE 0x01
9#define CS4398_FM_QUAD 0x02
10#define CS4398_FM_DSD 0x03
11#define CS4398_DEM_MASK 0x0c
12#define CS4398_DEM_NONE 0x00
13#define CS4398_DEM_44100 0x04
14#define CS4398_DEM_48000 0x08
15#define CS4398_DEM_32000 0x0c
16#define CS4398_DIF_MASK 0x70
17#define CS4398_DIF_LJUST 0x00
18#define CS4398_DIF_I2S 0x10
19#define CS4398_DIF_RJUST_16 0x20
20#define CS4398_DIF_RJUST_24 0x30
21#define CS4398_DIF_RJUST_20 0x40
22#define CS4398_DIF_RJUST_18 0x50
23#define CS4398_DSD_SRC 0x80
24/* register 3 */
25#define CS4398_ATAPI_MASK 0x1f
26#define CS4398_ATAPI_B_MUTE 0x00
27#define CS4398_ATAPI_B_R 0x01
28#define CS4398_ATAPI_B_L 0x02
29#define CS4398_ATAPI_B_LR 0x03
30#define CS4398_ATAPI_A_MUTE 0x00
31#define CS4398_ATAPI_A_R 0x04
32#define CS4398_ATAPI_A_L 0x08
33#define CS4398_ATAPI_A_LR 0x0c
34#define CS4398_ATAPI_MIX_LR_VOL 0x10
35#define CS4398_INVERT_B 0x20
36#define CS4398_INVERT_A 0x40
37#define CS4398_VOL_B_EQ_A 0x80
38/* register 4 */
39#define CS4398_MUTEP_MASK 0x03
40#define CS4398_MUTEP_AUTO 0x00
41#define CS4398_MUTEP_LOW 0x02
42#define CS4398_MUTEP_HIGH 0x03
43#define CS4398_MUTE_B 0x08
44#define CS4398_MUTE_A 0x10
45#define CS4398_MUTEC_A_EQ_B 0x20
46#define CS4398_DAMUTE 0x40
47#define CS4398_PAMUTE 0x80
48/* register 5 */
49#define CS4398_VOL_A_MASK 0xff
50/* register 6 */
51#define CS4398_VOL_B_MASK 0xff
52/* register 7 */
53#define CS4398_DIR_DSD 0x01
54#define CS4398_FILT_SEL 0x04
55#define CS4398_RMP_DN 0x10
56#define CS4398_RMP_UP 0x20
57#define CS4398_ZERO_CROSS 0x40
58#define CS4398_SOFT_RAMP 0x80
59/* register 8 */
60#define CS4398_MCLKDIV3 0x08
61#define CS4398_MCLKDIV2 0x10
62#define CS4398_FREEZE 0x20
63#define CS4398_CPEN 0x40
64#define CS4398_PDN 0x80
65/* register 9 */
66#define CS4398_DSD_PM_EN 0x01
67#define CS4398_DSD_PM_MODE 0x02
68#define CS4398_INVALID_DSD 0x04
69#define CS4398_STATIC_DSD 0x08
diff --git a/sound/pci/oxygen/hifier.c b/sound/pci/oxygen/hifier.c
index 666f69a3312e..090dd4354a28 100644
--- a/sound/pci/oxygen/hifier.c
+++ b/sound/pci/oxygen/hifier.c
@@ -66,12 +66,12 @@ static void hifier_init(struct oxygen *chip)
66{ 66{
67 struct hifier_data *data = chip->model_data; 67 struct hifier_data *data = chip->model_data;
68 68
69 data->ak4396_ctl2 = AK4396_DEM_OFF | AK4396_DFS_NORMAL; 69 data->ak4396_ctl2 = AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL;
70 ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN); 70 ak4396_write(chip, AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN);
71 ak4396_write(chip, AK4396_CONTROL_2, data->ak4396_ctl2); 71 ak4396_write(chip, AK4396_CONTROL_2, data->ak4396_ctl2);
72 ak4396_write(chip, AK4396_CONTROL_3, AK4396_PCM); 72 ak4396_write(chip, AK4396_CONTROL_3, AK4396_PCM);
73 ak4396_write(chip, AK4396_LCH_ATT, 0xff); 73 ak4396_write(chip, AK4396_LCH_ATT, 0);
74 ak4396_write(chip, AK4396_RCH_ATT, 0xff); 74 ak4396_write(chip, AK4396_RCH_ATT, 0);
75 75
76 snd_component_add(chip->card, "AK4396"); 76 snd_component_add(chip->card, "AK4396");
77 snd_component_add(chip->card, "CS5340"); 77 snd_component_add(chip->card, "CS5340");
@@ -127,22 +127,8 @@ static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);
127 127
128static int hifier_control_filter(struct snd_kcontrol_new *template) 128static int hifier_control_filter(struct snd_kcontrol_new *template)
129{ 129{
130 if (!strcmp(template->name, "Master Playback Volume")) { 130 if (!strcmp(template->name, "Stereo Upmixing"))
131 template->access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
132 template->tlv.p = ak4396_db_scale;
133 } else if (!strcmp(template->name, "Stereo Upmixing")) {
134 return 1; /* stereo only - we don't need upmixing */ 131 return 1; /* stereo only - we don't need upmixing */
135 } else if (!strcmp(template->name,
136 SNDRV_CTL_NAME_IEC958("", CAPTURE, MASK)) ||
137 !strcmp(template->name,
138 SNDRV_CTL_NAME_IEC958("", CAPTURE, DEFAULT))) {
139 return 1; /* no digital input */
140 }
141 return 0;
142}
143
144static int hifier_mixer_init(struct oxygen *chip)
145{
146 return 0; 132 return 0;
147} 133}
148 134
@@ -153,18 +139,20 @@ static const struct oxygen_model model_hifier = {
153 .owner = THIS_MODULE, 139 .owner = THIS_MODULE,
154 .init = hifier_init, 140 .init = hifier_init,
155 .control_filter = hifier_control_filter, 141 .control_filter = hifier_control_filter,
156 .mixer_init = hifier_mixer_init,
157 .cleanup = hifier_cleanup, 142 .cleanup = hifier_cleanup,
158 .set_dac_params = set_ak4396_params, 143 .set_dac_params = set_ak4396_params,
159 .set_adc_params = set_cs5340_params, 144 .set_adc_params = set_cs5340_params,
160 .update_dac_volume = update_ak4396_volume, 145 .update_dac_volume = update_ak4396_volume,
161 .update_dac_mute = update_ak4396_mute, 146 .update_dac_mute = update_ak4396_mute,
147 .dac_tlv = ak4396_db_scale,
162 .model_data_size = sizeof(struct hifier_data), 148 .model_data_size = sizeof(struct hifier_data),
149 .pcm_dev_cfg = PLAYBACK_0_TO_I2S |
150 PLAYBACK_1_TO_SPDIF |
151 CAPTURE_0_FROM_I2S_1,
163 .dac_channels = 2, 152 .dac_channels = 2,
164 .used_channels = OXYGEN_CHANNEL_A | 153 .dac_volume_min = 0,
165 OXYGEN_CHANNEL_SPDIF | 154 .dac_volume_max = 255,
166 OXYGEN_CHANNEL_MULTICH, 155 .function_flags = OXYGEN_FUNCTION_SPI,
167 .function_flags = 0,
168 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 156 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
169 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 157 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
170}; 158};
@@ -181,7 +169,7 @@ static int __devinit hifier_probe(struct pci_dev *pci,
181 ++dev; 169 ++dev;
182 return -ENOENT; 170 return -ENOENT;
183 } 171 }
184 err = oxygen_pci_probe(pci, index[dev], id[dev], 0, &model_hifier); 172 err = oxygen_pci_probe(pci, index[dev], id[dev], &model_hifier);
185 if (err >= 0) 173 if (err >= 0)
186 ++dev; 174 ++dev;
187 return err; 175 return err;
diff --git a/sound/pci/oxygen/oxygen.c b/sound/pci/oxygen/oxygen.c
index 9a9941bb0460..63f185c1ed1e 100644
--- a/sound/pci/oxygen/oxygen.c
+++ b/sound/pci/oxygen/oxygen.c
@@ -39,7 +39,7 @@
39#include <sound/tlv.h> 39#include <sound/tlv.h>
40#include "oxygen.h" 40#include "oxygen.h"
41#include "ak4396.h" 41#include "ak4396.h"
42#include "cm9780.h" 42#include "wm8785.h"
43 43
44MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>"); 44MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
45MODULE_DESCRIPTION("C-Media CMI8788 driver"); 45MODULE_DESCRIPTION("C-Media CMI8788 driver");
@@ -78,49 +78,6 @@ MODULE_DEVICE_TABLE(pci, oxygen_ids);
78#define GPIO_AK5385_DFS_DOUBLE 0x0001 78#define GPIO_AK5385_DFS_DOUBLE 0x0001
79#define GPIO_AK5385_DFS_QUAD 0x0002 79#define GPIO_AK5385_DFS_QUAD 0x0002
80 80
81#define GPIO_LINE_MUTE CM9780_GPO0
82
83#define WM8785_R0 0
84#define WM8785_R1 1
85#define WM8785_R2 2
86#define WM8785_R7 7
87
88/* R0 */
89#define WM8785_MCR_MASK 0x007
90#define WM8785_MCR_SLAVE 0x000
91#define WM8785_MCR_MASTER_128 0x001
92#define WM8785_MCR_MASTER_192 0x002
93#define WM8785_MCR_MASTER_256 0x003
94#define WM8785_MCR_MASTER_384 0x004
95#define WM8785_MCR_MASTER_512 0x005
96#define WM8785_MCR_MASTER_768 0x006
97#define WM8785_OSR_MASK 0x018
98#define WM8785_OSR_SINGLE 0x000
99#define WM8785_OSR_DOUBLE 0x008
100#define WM8785_OSR_QUAD 0x010
101#define WM8785_FORMAT_MASK 0x060
102#define WM8785_FORMAT_RJUST 0x000
103#define WM8785_FORMAT_LJUST 0x020
104#define WM8785_FORMAT_I2S 0x040
105#define WM8785_FORMAT_DSP 0x060
106/* R1 */
107#define WM8785_WL_MASK 0x003
108#define WM8785_WL_16 0x000
109#define WM8785_WL_20 0x001
110#define WM8785_WL_24 0x002
111#define WM8785_WL_32 0x003
112#define WM8785_LRP 0x004
113#define WM8785_BCLKINV 0x008
114#define WM8785_LRSWAP 0x010
115#define WM8785_DEVNO_MASK 0x0e0
116/* R2 */
117#define WM8785_HPFR 0x001
118#define WM8785_HPFL 0x002
119#define WM8785_SDODIS 0x004
120#define WM8785_PWRDNR 0x008
121#define WM8785_PWRDNL 0x010
122#define WM8785_TDM_MASK 0x1c0
123
124struct generic_data { 81struct generic_data {
125 u8 ak4396_ctl2; 82 u8 ak4396_ctl2;
126}; 83};
@@ -155,7 +112,7 @@ static void ak4396_init(struct oxygen *chip)
155 struct generic_data *data = chip->model_data; 112 struct generic_data *data = chip->model_data;
156 unsigned int i; 113 unsigned int i;
157 114
158 data->ak4396_ctl2 = AK4396_DEM_OFF | AK4396_DFS_NORMAL; 115 data->ak4396_ctl2 = AK4396_SMUTE | AK4396_DEM_OFF | AK4396_DFS_NORMAL;
159 for (i = 0; i < 4; ++i) { 116 for (i = 0; i < 4; ++i) {
160 ak4396_write(chip, i, 117 ak4396_write(chip, i,
161 AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN); 118 AK4396_CONTROL_1, AK4396_DIF_24_MSB | AK4396_RSTN);
@@ -163,8 +120,8 @@ static void ak4396_init(struct oxygen *chip)
163 AK4396_CONTROL_2, data->ak4396_ctl2); 120 AK4396_CONTROL_2, data->ak4396_ctl2);
164 ak4396_write(chip, i, 121 ak4396_write(chip, i,
165 AK4396_CONTROL_3, AK4396_PCM); 122 AK4396_CONTROL_3, AK4396_PCM);
166 ak4396_write(chip, i, AK4396_LCH_ATT, 0xff); 123 ak4396_write(chip, i, AK4396_LCH_ATT, 0);
167 ak4396_write(chip, i, AK4396_RCH_ATT, 0xff); 124 ak4396_write(chip, i, AK4396_RCH_ATT, 0);
168 } 125 }
169 snd_component_add(chip->card, "AK4396"); 126 snd_component_add(chip->card, "AK4396");
170} 127}
@@ -185,23 +142,16 @@ static void wm8785_init(struct oxygen *chip)
185 snd_component_add(chip->card, "WM8785"); 142 snd_component_add(chip->card, "WM8785");
186} 143}
187 144
188static void cmi9780_init(struct oxygen *chip)
189{
190 oxygen_ac97_clear_bits(chip, 0, CM9780_GPIO_STATUS, GPIO_LINE_MUTE);
191}
192
193static void generic_init(struct oxygen *chip) 145static void generic_init(struct oxygen *chip)
194{ 146{
195 ak4396_init(chip); 147 ak4396_init(chip);
196 wm8785_init(chip); 148 wm8785_init(chip);
197 cmi9780_init(chip);
198} 149}
199 150
200static void meridian_init(struct oxygen *chip) 151static void meridian_init(struct oxygen *chip)
201{ 152{
202 ak4396_init(chip); 153 ak4396_init(chip);
203 ak5385_init(chip); 154 ak5385_init(chip);
204 cmi9780_init(chip);
205} 155}
206 156
207static void generic_cleanup(struct oxygen *chip) 157static void generic_cleanup(struct oxygen *chip)
@@ -297,59 +247,32 @@ static void set_ak5385_params(struct oxygen *chip,
297 value, GPIO_AK5385_DFS_MASK); 247 value, GPIO_AK5385_DFS_MASK);
298} 248}
299 249
300static void cmi9780_switch_hook(struct oxygen *chip, unsigned int codec,
301 unsigned int reg, int mute)
302{
303 if (codec != 0)
304 return;
305 switch (reg) {
306 case AC97_LINE:
307 oxygen_write_ac97_masked(chip, 0, CM9780_GPIO_STATUS,
308 mute ? GPIO_LINE_MUTE : 0,
309 GPIO_LINE_MUTE);
310 break;
311 case AC97_MIC:
312 case AC97_CD:
313 case AC97_AUX:
314 if (!mute)
315 oxygen_ac97_set_bits(chip, 0, CM9780_GPIO_STATUS,
316 GPIO_LINE_MUTE);
317 break;
318 }
319}
320
321static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0); 250static const DECLARE_TLV_DB_LINEAR(ak4396_db_scale, TLV_DB_GAIN_MUTE, 0);
322 251
323static int ak4396_control_filter(struct snd_kcontrol_new *template)
324{
325 if (!strcmp(template->name, "Master Playback Volume")) {
326 template->access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
327 template->tlv.p = ak4396_db_scale;
328 }
329 return 0;
330}
331
332static const struct oxygen_model model_generic = { 252static const struct oxygen_model model_generic = {
333 .shortname = "C-Media CMI8788", 253 .shortname = "C-Media CMI8788",
334 .longname = "C-Media Oxygen HD Audio", 254 .longname = "C-Media Oxygen HD Audio",
335 .chip = "CMI8788", 255 .chip = "CMI8788",
336 .owner = THIS_MODULE, 256 .owner = THIS_MODULE,
337 .init = generic_init, 257 .init = generic_init,
338 .control_filter = ak4396_control_filter,
339 .cleanup = generic_cleanup, 258 .cleanup = generic_cleanup,
340 .set_dac_params = set_ak4396_params, 259 .set_dac_params = set_ak4396_params,
341 .set_adc_params = set_wm8785_params, 260 .set_adc_params = set_wm8785_params,
342 .update_dac_volume = update_ak4396_volume, 261 .update_dac_volume = update_ak4396_volume,
343 .update_dac_mute = update_ak4396_mute, 262 .update_dac_mute = update_ak4396_mute,
344 .ac97_switch_hook = cmi9780_switch_hook, 263 .dac_tlv = ak4396_db_scale,
345 .model_data_size = sizeof(struct generic_data), 264 .model_data_size = sizeof(struct generic_data),
265 .pcm_dev_cfg = PLAYBACK_0_TO_I2S |
266 PLAYBACK_1_TO_SPDIF |
267 PLAYBACK_2_TO_AC97_1 |
268 CAPTURE_0_FROM_I2S_1 |
269 CAPTURE_1_FROM_SPDIF |
270 CAPTURE_2_FROM_AC97_1,
346 .dac_channels = 8, 271 .dac_channels = 8,
347 .used_channels = OXYGEN_CHANNEL_A | 272 .dac_volume_min = 0,
348 OXYGEN_CHANNEL_C | 273 .dac_volume_max = 255,
349 OXYGEN_CHANNEL_SPDIF | 274 .function_flags = OXYGEN_FUNCTION_SPI |
350 OXYGEN_CHANNEL_MULTICH | 275 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
351 OXYGEN_CHANNEL_AC97,
352 .function_flags = OXYGEN_FUNCTION_ENABLE_SPI_4_5,
353 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 276 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
354 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 277 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
355}; 278};
@@ -359,21 +282,25 @@ static const struct oxygen_model model_meridian = {
359 .chip = "CMI8788", 282 .chip = "CMI8788",
360 .owner = THIS_MODULE, 283 .owner = THIS_MODULE,
361 .init = meridian_init, 284 .init = meridian_init,
362 .control_filter = ak4396_control_filter,
363 .cleanup = generic_cleanup, 285 .cleanup = generic_cleanup,
364 .set_dac_params = set_ak4396_params, 286 .set_dac_params = set_ak4396_params,
365 .set_adc_params = set_ak5385_params, 287 .set_adc_params = set_ak5385_params,
366 .update_dac_volume = update_ak4396_volume, 288 .update_dac_volume = update_ak4396_volume,
367 .update_dac_mute = update_ak4396_mute, 289 .update_dac_mute = update_ak4396_mute,
368 .ac97_switch_hook = cmi9780_switch_hook, 290 .dac_tlv = ak4396_db_scale,
369 .model_data_size = sizeof(struct generic_data), 291 .model_data_size = sizeof(struct generic_data),
292 .pcm_dev_cfg = PLAYBACK_0_TO_I2S |
293 PLAYBACK_1_TO_SPDIF |
294 PLAYBACK_2_TO_AC97_1 |
295 CAPTURE_0_FROM_I2S_2 |
296 CAPTURE_1_FROM_SPDIF |
297 CAPTURE_2_FROM_AC97_1,
370 .dac_channels = 8, 298 .dac_channels = 8,
371 .used_channels = OXYGEN_CHANNEL_B | 299 .dac_volume_min = 0,
372 OXYGEN_CHANNEL_C | 300 .dac_volume_max = 255,
373 OXYGEN_CHANNEL_SPDIF | 301 .misc_flags = OXYGEN_MISC_MIDI,
374 OXYGEN_CHANNEL_MULTICH | 302 .function_flags = OXYGEN_FUNCTION_SPI |
375 OXYGEN_CHANNEL_AC97, 303 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
376 .function_flags = OXYGEN_FUNCTION_ENABLE_SPI_4_5,
377 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 304 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
378 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 305 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
379}; 306};
@@ -392,7 +319,7 @@ static int __devinit generic_oxygen_probe(struct pci_dev *pci,
392 return -ENOENT; 319 return -ENOENT;
393 } 320 }
394 is_meridian = pci_id->driver_data; 321 is_meridian = pci_id->driver_data;
395 err = oxygen_pci_probe(pci, index[dev], id[dev], is_meridian, 322 err = oxygen_pci_probe(pci, index[dev], id[dev],
396 is_meridian ? &model_meridian : &model_generic); 323 is_meridian ? &model_meridian : &model_generic);
397 if (err >= 0) 324 if (err >= 0)
398 ++dev; 325 ++dev;
diff --git a/sound/pci/oxygen/oxygen.h b/sound/pci/oxygen/oxygen.h
index ad50fb8b206b..a71c6e059260 100644
--- a/sound/pci/oxygen/oxygen.h
+++ b/sound/pci/oxygen/oxygen.h
@@ -16,6 +16,16 @@
16#define PCM_AC97 5 16#define PCM_AC97 5
17#define PCM_COUNT 6 17#define PCM_COUNT 6
18 18
19/* model-specific configuration of outputs/inputs */
20#define PLAYBACK_0_TO_I2S 0x001
21#define PLAYBACK_1_TO_SPDIF 0x004
22#define PLAYBACK_2_TO_AC97_1 0x008
23#define CAPTURE_0_FROM_I2S_1 0x010
24#define CAPTURE_0_FROM_I2S_2 0x020
25#define CAPTURE_1_FROM_SPDIF 0x080
26#define CAPTURE_2_FROM_I2S_2 0x100
27#define CAPTURE_2_FROM_AC97_1 0x200
28
19enum { 29enum {
20 CONTROL_SPDIF_PCM, 30 CONTROL_SPDIF_PCM,
21 CONTROL_SPDIF_INPUT_BITS, 31 CONTROL_SPDIF_INPUT_BITS,
@@ -87,12 +97,16 @@ struct oxygen_model {
87 struct snd_pcm_hw_params *params); 97 struct snd_pcm_hw_params *params);
88 void (*update_dac_volume)(struct oxygen *chip); 98 void (*update_dac_volume)(struct oxygen *chip);
89 void (*update_dac_mute)(struct oxygen *chip); 99 void (*update_dac_mute)(struct oxygen *chip);
90 void (*ac97_switch_hook)(struct oxygen *chip, unsigned int codec,
91 unsigned int reg, int mute);
92 void (*gpio_changed)(struct oxygen *chip); 100 void (*gpio_changed)(struct oxygen *chip);
101 void (*ac97_switch)(struct oxygen *chip,
102 unsigned int reg, unsigned int mute);
103 const unsigned int *dac_tlv;
93 size_t model_data_size; 104 size_t model_data_size;
105 unsigned int pcm_dev_cfg;
94 u8 dac_channels; 106 u8 dac_channels;
95 u8 used_channels; 107 u8 dac_volume_min;
108 u8 dac_volume_max;
109 u8 misc_flags;
96 u8 function_flags; 110 u8 function_flags;
97 u16 dac_i2s_format; 111 u16 dac_i2s_format;
98 u16 adc_i2s_format; 112 u16 adc_i2s_format;
@@ -100,7 +114,7 @@ struct oxygen_model {
100 114
101/* oxygen_lib.c */ 115/* oxygen_lib.c */
102 116
103int oxygen_pci_probe(struct pci_dev *pci, int index, char *id, int midi, 117int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
104 const struct oxygen_model *model); 118 const struct oxygen_model *model);
105void oxygen_pci_remove(struct pci_dev *pci); 119void oxygen_pci_remove(struct pci_dev *pci);
106 120
@@ -137,6 +151,7 @@ void oxygen_write_ac97_masked(struct oxygen *chip, unsigned int codec,
137 unsigned int index, u16 data, u16 mask); 151 unsigned int index, u16 data, u16 mask);
138 152
139void oxygen_write_spi(struct oxygen *chip, u8 control, unsigned int data); 153void oxygen_write_spi(struct oxygen *chip, u8 control, unsigned int data);
154void oxygen_write_i2c(struct oxygen *chip, u8 device, u8 map, u8 data);
140 155
141static inline void oxygen_set_bits8(struct oxygen *chip, 156static inline void oxygen_set_bits8(struct oxygen *chip,
142 unsigned int reg, u8 value) 157 unsigned int reg, u8 value)
diff --git a/sound/pci/oxygen/oxygen_io.c b/sound/pci/oxygen/oxygen_io.c
index 74e23ef9c946..5569606ee87f 100644
--- a/sound/pci/oxygen/oxygen_io.c
+++ b/sound/pci/oxygen/oxygen_io.c
@@ -190,12 +190,31 @@ void oxygen_write_spi(struct oxygen *chip, u8 control, unsigned int data)
190 --count; 190 --count;
191 } 191 }
192 192
193 spin_lock_irq(&chip->reg_lock);
194 oxygen_write8(chip, OXYGEN_SPI_DATA1, data); 193 oxygen_write8(chip, OXYGEN_SPI_DATA1, data);
195 oxygen_write8(chip, OXYGEN_SPI_DATA2, data >> 8); 194 oxygen_write8(chip, OXYGEN_SPI_DATA2, data >> 8);
196 if (control & OXYGEN_SPI_DATA_LENGTH_3) 195 if (control & OXYGEN_SPI_DATA_LENGTH_3)
197 oxygen_write8(chip, OXYGEN_SPI_DATA3, data >> 16); 196 oxygen_write8(chip, OXYGEN_SPI_DATA3, data >> 16);
198 oxygen_write8(chip, OXYGEN_SPI_CONTROL, control); 197 oxygen_write8(chip, OXYGEN_SPI_CONTROL, control);
199 spin_unlock_irq(&chip->reg_lock);
200} 198}
201EXPORT_SYMBOL(oxygen_write_spi); 199EXPORT_SYMBOL(oxygen_write_spi);
200
201void oxygen_write_i2c(struct oxygen *chip, u8 device, u8 map, u8 data)
202{
203 unsigned long timeout;
204
205 /* should not need more than about 300 us */
206 timeout = jiffies + msecs_to_jiffies(1);
207 do {
208 if (!(oxygen_read16(chip, OXYGEN_2WIRE_BUS_STATUS)
209 & OXYGEN_2WIRE_BUSY))
210 break;
211 udelay(1);
212 cond_resched();
213 } while (time_after_eq(timeout, jiffies));
214
215 oxygen_write8(chip, OXYGEN_2WIRE_MAP, map);
216 oxygen_write8(chip, OXYGEN_2WIRE_DATA, data);
217 oxygen_write8(chip, OXYGEN_2WIRE_CONTROL,
218 device | OXYGEN_2WIRE_DIR_WRITE);
219}
220EXPORT_SYMBOL(oxygen_write_i2c);
diff --git a/sound/pci/oxygen/oxygen_lib.c b/sound/pci/oxygen/oxygen_lib.c
index 78c21155218e..897697d43506 100644
--- a/sound/pci/oxygen/oxygen_lib.c
+++ b/sound/pci/oxygen/oxygen_lib.c
@@ -221,7 +221,8 @@ static void oxygen_init(struct oxygen *chip)
221 221
222 chip->dac_routing = 1; 222 chip->dac_routing = 1;
223 for (i = 0; i < 8; ++i) 223 for (i = 0; i < 8; ++i)
224 chip->dac_volume[i] = 0xff; 224 chip->dac_volume[i] = chip->model->dac_volume_min;
225 chip->dac_mute = 1;
225 chip->spdif_playback_enable = 1; 226 chip->spdif_playback_enable = 1;
226 chip->spdif_bits = OXYGEN_SPDIF_C | OXYGEN_SPDIF_ORIGINAL | 227 chip->spdif_bits = OXYGEN_SPDIF_C | OXYGEN_SPDIF_ORIGINAL |
227 (IEC958_AES1_CON_PCM_CODER << OXYGEN_SPDIF_CATEGORY_SHIFT); 228 (IEC958_AES1_CON_PCM_CODER << OXYGEN_SPDIF_CATEGORY_SHIFT);
@@ -240,12 +241,12 @@ static void oxygen_init(struct oxygen *chip)
240 chip->has_ac97_0 = (i & OXYGEN_AC97_CODEC_0) != 0; 241 chip->has_ac97_0 = (i & OXYGEN_AC97_CODEC_0) != 0;
241 chip->has_ac97_1 = (i & OXYGEN_AC97_CODEC_1) != 0; 242 chip->has_ac97_1 = (i & OXYGEN_AC97_CODEC_1) != 0;
242 243
243 oxygen_set_bits8(chip, OXYGEN_FUNCTION,
244 OXYGEN_FUNCTION_RESET_CODEC |
245 chip->model->function_flags);
246 oxygen_write8_masked(chip, OXYGEN_FUNCTION, 244 oxygen_write8_masked(chip, OXYGEN_FUNCTION,
247 OXYGEN_FUNCTION_SPI, 245 OXYGEN_FUNCTION_RESET_CODEC |
248 OXYGEN_FUNCTION_2WIRE_SPI_MASK); 246 chip->model->function_flags,
247 OXYGEN_FUNCTION_RESET_CODEC |
248 OXYGEN_FUNCTION_2WIRE_SPI_MASK |
249 OXYGEN_FUNCTION_ENABLE_SPI_4_5);
249 oxygen_write8(chip, OXYGEN_DMA_STATUS, 0); 250 oxygen_write8(chip, OXYGEN_DMA_STATUS, 0);
250 oxygen_write8(chip, OXYGEN_DMA_PAUSE, 0); 251 oxygen_write8(chip, OXYGEN_DMA_PAUSE, 0);
251 oxygen_write8(chip, OXYGEN_PLAY_CHANNELS, 252 oxygen_write8(chip, OXYGEN_PLAY_CHANNELS,
@@ -253,11 +254,13 @@ static void oxygen_init(struct oxygen *chip)
253 OXYGEN_DMA_A_BURST_8 | 254 OXYGEN_DMA_A_BURST_8 |
254 OXYGEN_DMA_MULTICH_BURST_8); 255 OXYGEN_DMA_MULTICH_BURST_8);
255 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, 0); 256 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, 0);
256 oxygen_write8_masked(chip, OXYGEN_MISC, 0, 257 oxygen_write8_masked(chip, OXYGEN_MISC,
258 chip->model->misc_flags,
257 OXYGEN_MISC_WRITE_PCI_SUBID | 259 OXYGEN_MISC_WRITE_PCI_SUBID |
258 OXYGEN_MISC_REC_C_FROM_SPDIF | 260 OXYGEN_MISC_REC_C_FROM_SPDIF |
259 OXYGEN_MISC_REC_B_FROM_AC97 | 261 OXYGEN_MISC_REC_B_FROM_AC97 |
260 OXYGEN_MISC_REC_A_FROM_MULTICH); 262 OXYGEN_MISC_REC_A_FROM_MULTICH |
263 OXYGEN_MISC_MIDI);
261 oxygen_write8(chip, OXYGEN_REC_FORMAT, 264 oxygen_write8(chip, OXYGEN_REC_FORMAT,
262 (OXYGEN_FORMAT_16 << OXYGEN_REC_FORMAT_A_SHIFT) | 265 (OXYGEN_FORMAT_16 << OXYGEN_REC_FORMAT_A_SHIFT) |
263 (OXYGEN_FORMAT_16 << OXYGEN_REC_FORMAT_B_SHIFT) | 266 (OXYGEN_FORMAT_16 << OXYGEN_REC_FORMAT_B_SHIFT) |
@@ -267,35 +270,49 @@ static void oxygen_init(struct oxygen *chip)
267 (OXYGEN_FORMAT_16 << OXYGEN_MULTICH_FORMAT_SHIFT)); 270 (OXYGEN_FORMAT_16 << OXYGEN_MULTICH_FORMAT_SHIFT));
268 oxygen_write8(chip, OXYGEN_REC_CHANNELS, OXYGEN_REC_CHANNELS_2_2_2); 271 oxygen_write8(chip, OXYGEN_REC_CHANNELS, OXYGEN_REC_CHANNELS_2_2_2);
269 oxygen_write16(chip, OXYGEN_I2S_MULTICH_FORMAT, 272 oxygen_write16(chip, OXYGEN_I2S_MULTICH_FORMAT,
270 OXYGEN_RATE_48000 | OXYGEN_I2S_FORMAT_LJUST | 273 OXYGEN_RATE_48000 | chip->model->dac_i2s_format |
271 OXYGEN_I2S_MCLK_128 | OXYGEN_I2S_BITS_16 | 274 OXYGEN_I2S_MCLK_256 | OXYGEN_I2S_BITS_16 |
272 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
273 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
274 OXYGEN_RATE_48000 | OXYGEN_I2S_FORMAT_LJUST |
275 OXYGEN_I2S_MCLK_128 | OXYGEN_I2S_BITS_16 |
276 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
277 oxygen_write16(chip, OXYGEN_I2S_B_FORMAT,
278 OXYGEN_RATE_48000 | OXYGEN_I2S_FORMAT_LJUST |
279 OXYGEN_I2S_MCLK_128 | OXYGEN_I2S_BITS_16 |
280 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64); 275 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
276 if (chip->model->pcm_dev_cfg & CAPTURE_0_FROM_I2S_1)
277 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
278 OXYGEN_RATE_48000 | chip->model->adc_i2s_format |
279 OXYGEN_I2S_MCLK_256 | OXYGEN_I2S_BITS_16 |
280 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
281 else
282 oxygen_write16(chip, OXYGEN_I2S_A_FORMAT,
283 OXYGEN_I2S_MASTER | OXYGEN_I2S_MUTE_MCLK);
284 if (chip->model->pcm_dev_cfg & (CAPTURE_0_FROM_I2S_2 |
285 CAPTURE_2_FROM_I2S_2))
286 oxygen_write16(chip, OXYGEN_I2S_B_FORMAT,
287 OXYGEN_RATE_48000 | chip->model->adc_i2s_format |
288 OXYGEN_I2S_MCLK_256 | OXYGEN_I2S_BITS_16 |
289 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64);
290 else
291 oxygen_write16(chip, OXYGEN_I2S_B_FORMAT,
292 OXYGEN_I2S_MASTER | OXYGEN_I2S_MUTE_MCLK);
281 oxygen_write16(chip, OXYGEN_I2S_C_FORMAT, 293 oxygen_write16(chip, OXYGEN_I2S_C_FORMAT,
282 OXYGEN_RATE_48000 | OXYGEN_I2S_FORMAT_LJUST | 294 OXYGEN_I2S_MASTER | OXYGEN_I2S_MUTE_MCLK);
283 OXYGEN_I2S_MCLK_128 | OXYGEN_I2S_BITS_16 | 295 oxygen_clear_bits32(chip, OXYGEN_SPDIF_CONTROL,
284 OXYGEN_I2S_MASTER | OXYGEN_I2S_BCLK_64); 296 OXYGEN_SPDIF_OUT_ENABLE |
285 oxygen_write32_masked(chip, OXYGEN_SPDIF_CONTROL, 297 OXYGEN_SPDIF_LOOPBACK);
286 OXYGEN_SPDIF_SENSE_MASK | 298 if (chip->model->pcm_dev_cfg & CAPTURE_1_FROM_SPDIF)
287 OXYGEN_SPDIF_LOCK_MASK | 299 oxygen_write32_masked(chip, OXYGEN_SPDIF_CONTROL,
288 OXYGEN_SPDIF_RATE_MASK | 300 OXYGEN_SPDIF_SENSE_MASK |
289 OXYGEN_SPDIF_LOCK_PAR | 301 OXYGEN_SPDIF_LOCK_MASK |
290 OXYGEN_SPDIF_IN_CLOCK_96, 302 OXYGEN_SPDIF_RATE_MASK |
291 OXYGEN_SPDIF_OUT_ENABLE | 303 OXYGEN_SPDIF_LOCK_PAR |
292 OXYGEN_SPDIF_LOOPBACK | 304 OXYGEN_SPDIF_IN_CLOCK_96,
293 OXYGEN_SPDIF_SENSE_MASK | 305 OXYGEN_SPDIF_SENSE_MASK |
294 OXYGEN_SPDIF_LOCK_MASK | 306 OXYGEN_SPDIF_LOCK_MASK |
295 OXYGEN_SPDIF_RATE_MASK | 307 OXYGEN_SPDIF_RATE_MASK |
296 OXYGEN_SPDIF_SENSE_PAR | 308 OXYGEN_SPDIF_SENSE_PAR |
297 OXYGEN_SPDIF_LOCK_PAR | 309 OXYGEN_SPDIF_LOCK_PAR |
298 OXYGEN_SPDIF_IN_CLOCK_MASK); 310 OXYGEN_SPDIF_IN_CLOCK_MASK);
311 else
312 oxygen_clear_bits32(chip, OXYGEN_SPDIF_CONTROL,
313 OXYGEN_SPDIF_SENSE_MASK |
314 OXYGEN_SPDIF_LOCK_MASK |
315 OXYGEN_SPDIF_RATE_MASK);
299 oxygen_write32(chip, OXYGEN_SPDIF_OUTPUT_BITS, chip->spdif_bits); 316 oxygen_write32(chip, OXYGEN_SPDIF_OUTPUT_BITS, chip->spdif_bits);
300 oxygen_clear_bits8(chip, OXYGEN_MPU401_CONTROL, OXYGEN_MPU401_LOOPBACK); 317 oxygen_clear_bits8(chip, OXYGEN_MPU401_CONTROL, OXYGEN_MPU401_LOOPBACK);
301 oxygen_write8(chip, OXYGEN_GPI_INTERRUPT_MASK, 0); 318 oxygen_write8(chip, OXYGEN_GPI_INTERRUPT_MASK, 0);
@@ -318,9 +335,12 @@ static void oxygen_init(struct oxygen *chip)
318 (2 << OXYGEN_A_MONITOR_ROUTE_2_SHIFT) | 335 (2 << OXYGEN_A_MONITOR_ROUTE_2_SHIFT) |
319 (3 << OXYGEN_A_MONITOR_ROUTE_3_SHIFT)); 336 (3 << OXYGEN_A_MONITOR_ROUTE_3_SHIFT));
320 337
321 oxygen_write8(chip, OXYGEN_AC97_INTERRUPT_MASK, 338 if (chip->has_ac97_0 | chip->has_ac97_1)
322 OXYGEN_AC97_INT_READ_DONE | 339 oxygen_write8(chip, OXYGEN_AC97_INTERRUPT_MASK,
323 OXYGEN_AC97_INT_WRITE_DONE); 340 OXYGEN_AC97_INT_READ_DONE |
341 OXYGEN_AC97_INT_WRITE_DONE);
342 else
343 oxygen_write8(chip, OXYGEN_AC97_INTERRUPT_MASK, 0);
324 oxygen_write32(chip, OXYGEN_AC97_OUT_CONFIG, 0); 344 oxygen_write32(chip, OXYGEN_AC97_OUT_CONFIG, 0);
325 oxygen_write32(chip, OXYGEN_AC97_IN_CONFIG, 0); 345 oxygen_write32(chip, OXYGEN_AC97_IN_CONFIG, 0);
326 if (!(chip->has_ac97_0 | chip->has_ac97_1)) 346 if (!(chip->has_ac97_0 | chip->has_ac97_1))
@@ -351,6 +371,8 @@ static void oxygen_init(struct oxygen *chip)
351 oxygen_write_ac97(chip, 0, AC97_REC_GAIN, 0x8000); 371 oxygen_write_ac97(chip, 0, AC97_REC_GAIN, 0x8000);
352 oxygen_write_ac97(chip, 0, AC97_CENTER_LFE_MASTER, 0x8080); 372 oxygen_write_ac97(chip, 0, AC97_CENTER_LFE_MASTER, 0x8080);
353 oxygen_write_ac97(chip, 0, AC97_SURROUND_MASTER, 0x8080); 373 oxygen_write_ac97(chip, 0, AC97_SURROUND_MASTER, 0x8080);
374 oxygen_ac97_clear_bits(chip, 0, CM9780_GPIO_STATUS,
375 CM9780_GPO0);
354 /* power down unused ADCs and DACs */ 376 /* power down unused ADCs and DACs */
355 oxygen_ac97_set_bits(chip, 0, AC97_POWERDOWN, 377 oxygen_ac97_set_bits(chip, 0, AC97_POWERDOWN,
356 AC97_PD_PR0 | AC97_PD_PR1); 378 AC97_PD_PR0 | AC97_PD_PR1);
@@ -388,10 +410,8 @@ static void oxygen_card_free(struct snd_card *card)
388 oxygen_write16(chip, OXYGEN_DMA_STATUS, 0); 410 oxygen_write16(chip, OXYGEN_DMA_STATUS, 0);
389 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, 0); 411 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, 0);
390 spin_unlock_irq(&chip->reg_lock); 412 spin_unlock_irq(&chip->reg_lock);
391 if (chip->irq >= 0) { 413 if (chip->irq >= 0)
392 free_irq(chip->irq, chip); 414 free_irq(chip->irq, chip);
393 synchronize_irq(chip->irq);
394 }
395 flush_scheduled_work(); 415 flush_scheduled_work();
396 chip->model->cleanup(chip); 416 chip->model->cleanup(chip);
397 mutex_destroy(&chip->mutex); 417 mutex_destroy(&chip->mutex);
@@ -400,7 +420,7 @@ static void oxygen_card_free(struct snd_card *card)
400} 420}
401 421
402int oxygen_pci_probe(struct pci_dev *pci, int index, char *id, 422int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
403 int midi, const struct oxygen_model *model) 423 const struct oxygen_model *model)
404{ 424{
405 struct snd_card *card; 425 struct snd_card *card;
406 struct oxygen *chip; 426 struct oxygen *chip;
@@ -472,9 +492,7 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
472 if (err < 0) 492 if (err < 0)
473 goto err_card; 493 goto err_card;
474 494
475 oxygen_write8_masked(chip, OXYGEN_MISC, 495 if (model->misc_flags & OXYGEN_MISC_MIDI) {
476 midi ? OXYGEN_MISC_MIDI : 0, OXYGEN_MISC_MIDI);
477 if (midi) {
478 err = snd_mpu401_uart_new(card, 0, MPU401_HW_CMIPCI, 496 err = snd_mpu401_uart_new(card, 0, MPU401_HW_CMIPCI,
479 chip->addr + OXYGEN_MPU401, 497 chip->addr + OXYGEN_MPU401,
480 MPU401_INFO_INTEGRATED, 0, 0, 498 MPU401_INFO_INTEGRATED, 0, 0,
@@ -486,7 +504,10 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
486 oxygen_proc_init(chip); 504 oxygen_proc_init(chip);
487 505
488 spin_lock_irq(&chip->reg_lock); 506 spin_lock_irq(&chip->reg_lock);
489 chip->interrupt_mask |= OXYGEN_INT_SPDIF_IN_DETECT | OXYGEN_INT_AC97; 507 if (chip->model->pcm_dev_cfg & CAPTURE_1_FROM_SPDIF)
508 chip->interrupt_mask |= OXYGEN_INT_SPDIF_IN_DETECT;
509 if (chip->has_ac97_0 | chip->has_ac97_1)
510 chip->interrupt_mask |= OXYGEN_INT_AC97;
490 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, chip->interrupt_mask); 511 oxygen_write16(chip, OXYGEN_INTERRUPT_MASK, chip->interrupt_mask);
491 spin_unlock_irq(&chip->reg_lock); 512 spin_unlock_irq(&chip->reg_lock);
492 513
diff --git a/sound/pci/oxygen/oxygen_mixer.c b/sound/pci/oxygen/oxygen_mixer.c
index a8e4623415d9..cc0cddadd589 100644
--- a/sound/pci/oxygen/oxygen_mixer.c
+++ b/sound/pci/oxygen/oxygen_mixer.c
@@ -32,8 +32,8 @@ static int dac_volume_info(struct snd_kcontrol *ctl,
32 32
33 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 33 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
34 info->count = chip->model->dac_channels; 34 info->count = chip->model->dac_channels;
35 info->value.integer.min = 0; 35 info->value.integer.min = chip->model->dac_volume_min;
36 info->value.integer.max = 0xff; 36 info->value.integer.max = chip->model->dac_volume_max;
37 return 0; 37 return 0;
38} 38}
39 39
@@ -446,6 +446,50 @@ static int spdif_loopback_put(struct snd_kcontrol *ctl,
446 return changed; 446 return changed;
447} 447}
448 448
449static int monitor_volume_info(struct snd_kcontrol *ctl,
450 struct snd_ctl_elem_info *info)
451{
452 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
453 info->count = 1;
454 info->value.integer.min = 0;
455 info->value.integer.max = 1;
456 return 0;
457}
458
459static int monitor_get(struct snd_kcontrol *ctl,
460 struct snd_ctl_elem_value *value)
461{
462 struct oxygen *chip = ctl->private_data;
463 u8 bit = ctl->private_value;
464 int invert = ctl->private_value & (1 << 8);
465
466 value->value.integer.value[0] =
467 !!invert ^ !!(oxygen_read8(chip, OXYGEN_ADC_MONITOR) & bit);
468 return 0;
469}
470
471static int monitor_put(struct snd_kcontrol *ctl,
472 struct snd_ctl_elem_value *value)
473{
474 struct oxygen *chip = ctl->private_data;
475 u8 bit = ctl->private_value;
476 int invert = ctl->private_value & (1 << 8);
477 u8 oldreg, newreg;
478 int changed;
479
480 spin_lock_irq(&chip->reg_lock);
481 oldreg = oxygen_read8(chip, OXYGEN_ADC_MONITOR);
482 if ((!!value->value.integer.value[0] ^ !!invert) != 0)
483 newreg = oldreg | bit;
484 else
485 newreg = oldreg & ~bit;
486 changed = newreg != oldreg;
487 if (changed)
488 oxygen_write8(chip, OXYGEN_ADC_MONITOR, newreg);
489 spin_unlock_irq(&chip->reg_lock);
490 return changed;
491}
492
449static int ac97_switch_get(struct snd_kcontrol *ctl, 493static int ac97_switch_get(struct snd_kcontrol *ctl,
450 struct snd_ctl_elem_value *value) 494 struct snd_ctl_elem_value *value)
451{ 495{
@@ -466,6 +510,21 @@ static int ac97_switch_get(struct snd_kcontrol *ctl,
466 return 0; 510 return 0;
467} 511}
468 512
513static void mute_ac97_ctl(struct oxygen *chip, unsigned int control)
514{
515 unsigned int priv_idx = chip->controls[control]->private_value & 0xff;
516 u16 value;
517
518 value = oxygen_read_ac97(chip, 0, priv_idx);
519 if (!(value & 0x8000)) {
520 oxygen_write_ac97(chip, 0, priv_idx, value | 0x8000);
521 if (chip->model->ac97_switch)
522 chip->model->ac97_switch(chip, priv_idx, 0x8000);
523 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
524 &chip->controls[control]->id);
525 }
526}
527
469static int ac97_switch_put(struct snd_kcontrol *ctl, 528static int ac97_switch_put(struct snd_kcontrol *ctl,
470 struct snd_ctl_elem_value *value) 529 struct snd_ctl_elem_value *value)
471{ 530{
@@ -487,9 +546,24 @@ static int ac97_switch_put(struct snd_kcontrol *ctl,
487 change = newreg != oldreg; 546 change = newreg != oldreg;
488 if (change) { 547 if (change) {
489 oxygen_write_ac97(chip, codec, index, newreg); 548 oxygen_write_ac97(chip, codec, index, newreg);
490 if (bitnr == 15 && chip->model->ac97_switch_hook) 549 if (codec == 0 && chip->model->ac97_switch)
491 chip->model->ac97_switch_hook(chip, codec, index, 550 chip->model->ac97_switch(chip, index, newreg & 0x8000);
492 newreg & 0x8000); 551 if (index == AC97_LINE) {
552 oxygen_write_ac97_masked(chip, 0, CM9780_GPIO_STATUS,
553 newreg & 0x8000 ?
554 CM9780_GPO0 : 0, CM9780_GPO0);
555 if (!(newreg & 0x8000)) {
556 mute_ac97_ctl(chip, CONTROL_MIC_CAPTURE_SWITCH);
557 mute_ac97_ctl(chip, CONTROL_CD_CAPTURE_SWITCH);
558 mute_ac97_ctl(chip, CONTROL_AUX_CAPTURE_SWITCH);
559 }
560 } else if ((index == AC97_MIC || index == AC97_CD ||
561 index == AC97_VIDEO || index == AC97_AUX) &&
562 bitnr == 15 && !(newreg & 0x8000)) {
563 mute_ac97_ctl(chip, CONTROL_LINE_CAPTURE_SWITCH);
564 oxygen_write_ac97_masked(chip, 0, CM9780_GPIO_STATUS,
565 CM9780_GPO0, CM9780_GPO0);
566 }
493 } 567 }
494 mutex_unlock(&chip->mutex); 568 mutex_unlock(&chip->mutex);
495 return change; 569 return change;
@@ -608,6 +682,7 @@ static int ac97_fp_rec_volume_put(struct snd_kcontrol *ctl,
608 .private_value = ((codec) << 24) | (index), \ 682 .private_value = ((codec) << 24) | (index), \
609 } 683 }
610 684
685static DECLARE_TLV_DB_SCALE(monitor_db_scale, -1000, 1000, 0);
611static DECLARE_TLV_DB_SCALE(ac97_db_scale, -3450, 150, 0); 686static DECLARE_TLV_DB_SCALE(ac97_db_scale, -3450, 150, 0);
612static DECLARE_TLV_DB_SCALE(ac97_rec_db_scale, 0, 150, 0); 687static DECLARE_TLV_DB_SCALE(ac97_rec_db_scale, 0, 150, 0);
613 688
@@ -667,6 +742,9 @@ static const struct snd_kcontrol_new controls[] = {
667 .get = spdif_pcm_get, 742 .get = spdif_pcm_get,
668 .put = spdif_pcm_put, 743 .put = spdif_pcm_put,
669 }, 744 },
745};
746
747static const struct snd_kcontrol_new spdif_input_controls[] = {
670 { 748 {
671 .iface = SNDRV_CTL_ELEM_IFACE_PCM, 749 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
672 .device = 1, 750 .device = 1,
@@ -692,11 +770,118 @@ static const struct snd_kcontrol_new controls[] = {
692 }, 770 },
693}; 771};
694 772
773static const struct {
774 unsigned int pcm_dev;
775 struct snd_kcontrol_new controls[2];
776} monitor_controls[] = {
777 {
778 .pcm_dev = CAPTURE_0_FROM_I2S_1,
779 .controls = {
780 {
781 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
782 .name = "Analog Input Monitor Switch",
783 .info = snd_ctl_boolean_mono_info,
784 .get = monitor_get,
785 .put = monitor_put,
786 .private_value = OXYGEN_ADC_MONITOR_A,
787 },
788 {
789 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
790 .name = "Analog Input Monitor Volume",
791 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
792 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
793 .info = monitor_volume_info,
794 .get = monitor_get,
795 .put = monitor_put,
796 .private_value = OXYGEN_ADC_MONITOR_A_HALF_VOL
797 | (1 << 8),
798 .tlv = { .p = monitor_db_scale, },
799 },
800 },
801 },
802 {
803 .pcm_dev = CAPTURE_0_FROM_I2S_2,
804 .controls = {
805 {
806 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
807 .name = "Analog Input Monitor Switch",
808 .info = snd_ctl_boolean_mono_info,
809 .get = monitor_get,
810 .put = monitor_put,
811 .private_value = OXYGEN_ADC_MONITOR_B,
812 },
813 {
814 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
815 .name = "Analog Input Monitor Volume",
816 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
817 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
818 .info = monitor_volume_info,
819 .get = monitor_get,
820 .put = monitor_put,
821 .private_value = OXYGEN_ADC_MONITOR_B_HALF_VOL
822 | (1 << 8),
823 .tlv = { .p = monitor_db_scale, },
824 },
825 },
826 },
827 {
828 .pcm_dev = CAPTURE_2_FROM_I2S_2,
829 .controls = {
830 {
831 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
832 .name = "Analog Input Monitor Switch",
833 .index = 1,
834 .info = snd_ctl_boolean_mono_info,
835 .get = monitor_get,
836 .put = monitor_put,
837 .private_value = OXYGEN_ADC_MONITOR_B,
838 },
839 {
840 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
841 .name = "Analog Input Monitor Volume",
842 .index = 1,
843 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
844 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
845 .info = monitor_volume_info,
846 .get = monitor_get,
847 .put = monitor_put,
848 .private_value = OXYGEN_ADC_MONITOR_B_HALF_VOL
849 | (1 << 8),
850 .tlv = { .p = monitor_db_scale, },
851 },
852 },
853 },
854 {
855 .pcm_dev = CAPTURE_1_FROM_SPDIF,
856 .controls = {
857 {
858 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
859 .name = "Digital Input Monitor Switch",
860 .info = snd_ctl_boolean_mono_info,
861 .get = monitor_get,
862 .put = monitor_put,
863 .private_value = OXYGEN_ADC_MONITOR_C,
864 },
865 {
866 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
867 .name = "Digital Input Monitor Volume",
868 .access = SNDRV_CTL_ELEM_ACCESS_READWRITE |
869 SNDRV_CTL_ELEM_ACCESS_TLV_READ,
870 .info = monitor_volume_info,
871 .get = monitor_get,
872 .put = monitor_put,
873 .private_value = OXYGEN_ADC_MONITOR_C_HALF_VOL
874 | (1 << 8),
875 .tlv = { .p = monitor_db_scale, },
876 },
877 },
878 },
879};
880
695static const struct snd_kcontrol_new ac97_controls[] = { 881static const struct snd_kcontrol_new ac97_controls[] = {
696 AC97_VOLUME("Mic Capture Volume", 0, AC97_MIC), 882 AC97_VOLUME("Mic Capture Volume", 0, AC97_MIC),
697 AC97_SWITCH("Mic Capture Switch", 0, AC97_MIC, 15, 1), 883 AC97_SWITCH("Mic Capture Switch", 0, AC97_MIC, 15, 1),
698 AC97_SWITCH("Mic Boost (+20dB)", 0, AC97_MIC, 6, 0), 884 AC97_SWITCH("Mic Boost (+20dB)", 0, AC97_MIC, 6, 0),
699 AC97_VOLUME("Line Capture Volume", 0, AC97_LINE),
700 AC97_SWITCH("Line Capture Switch", 0, AC97_LINE, 15, 1), 885 AC97_SWITCH("Line Capture Switch", 0, AC97_LINE, 15, 1),
701 AC97_VOLUME("CD Capture Volume", 0, AC97_CD), 886 AC97_VOLUME("CD Capture Volume", 0, AC97_CD),
702 AC97_SWITCH("CD Capture Switch", 0, AC97_CD, 15, 1), 887 AC97_SWITCH("CD Capture Switch", 0, AC97_CD, 15, 1),
@@ -756,6 +941,11 @@ static int add_controls(struct oxygen *chip,
756 return err; 941 return err;
757 if (err == 1) 942 if (err == 1)
758 continue; 943 continue;
944 if (!strcmp(template.name, "Master Playback Volume") &&
945 chip->model->dac_tlv) {
946 template.tlv.p = chip->model->dac_tlv;
947 template.access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
948 }
759 ctl = snd_ctl_new1(&template, chip); 949 ctl = snd_ctl_new1(&template, chip);
760 if (!ctl) 950 if (!ctl)
761 return -ENOMEM; 951 return -ENOMEM;
@@ -773,11 +963,26 @@ static int add_controls(struct oxygen *chip,
773 963
774int oxygen_mixer_init(struct oxygen *chip) 964int oxygen_mixer_init(struct oxygen *chip)
775{ 965{
966 unsigned int i;
776 int err; 967 int err;
777 968
778 err = add_controls(chip, controls, ARRAY_SIZE(controls)); 969 err = add_controls(chip, controls, ARRAY_SIZE(controls));
779 if (err < 0) 970 if (err < 0)
780 return err; 971 return err;
972 if (chip->model->pcm_dev_cfg & CAPTURE_1_FROM_SPDIF) {
973 err = add_controls(chip, spdif_input_controls,
974 ARRAY_SIZE(spdif_input_controls));
975 if (err < 0)
976 return err;
977 }
978 for (i = 0; i < ARRAY_SIZE(monitor_controls); ++i) {
979 if (!(chip->model->pcm_dev_cfg & monitor_controls[i].pcm_dev))
980 continue;
981 err = add_controls(chip, monitor_controls[i].controls,
982 ARRAY_SIZE(monitor_controls[i].controls));
983 if (err < 0)
984 return err;
985 }
781 if (chip->has_ac97_0) { 986 if (chip->has_ac97_0) {
782 err = add_controls(chip, ac97_controls, 987 err = add_controls(chip, ac97_controls,
783 ARRAY_SIZE(ac97_controls)); 988 ARRAY_SIZE(ac97_controls));
diff --git a/sound/pci/oxygen/oxygen_pcm.c b/sound/pci/oxygen/oxygen_pcm.c
index b70046aca657..b17c405e069d 100644
--- a/sound/pci/oxygen/oxygen_pcm.c
+++ b/sound/pci/oxygen/oxygen_pcm.c
@@ -119,7 +119,7 @@ static int oxygen_open(struct snd_pcm_substream *substream,
119 119
120 runtime->private_data = (void *)(uintptr_t)channel; 120 runtime->private_data = (void *)(uintptr_t)channel;
121 if (channel == PCM_B && chip->has_ac97_1 && 121 if (channel == PCM_B && chip->has_ac97_1 &&
122 (chip->model->used_channels & OXYGEN_CHANNEL_AC97)) 122 (chip->model->pcm_dev_cfg & CAPTURE_2_FROM_AC97_1))
123 runtime->hw = oxygen_ac97_hardware; 123 runtime->hw = oxygen_ac97_hardware;
124 else 124 else
125 runtime->hw = *oxygen_hardware[channel]; 125 runtime->hw = *oxygen_hardware[channel];
@@ -365,7 +365,7 @@ static int oxygen_rec_b_hw_params(struct snd_pcm_substream *substream,
365 return err; 365 return err;
366 366
367 is_ac97 = chip->has_ac97_1 && 367 is_ac97 = chip->has_ac97_1 &&
368 (chip->model->used_channels & OXYGEN_CHANNEL_AC97); 368 (chip->model->pcm_dev_cfg & CAPTURE_2_FROM_AC97_1);
369 369
370 spin_lock_irq(&chip->reg_lock); 370 spin_lock_irq(&chip->reg_lock);
371 oxygen_write8_masked(chip, OXYGEN_REC_FORMAT, 371 oxygen_write8_masked(chip, OXYGEN_REC_FORMAT,
@@ -640,34 +640,39 @@ int oxygen_pcm_init(struct oxygen *chip)
640 int outs, ins; 640 int outs, ins;
641 int err; 641 int err;
642 642
643 outs = 1; /* OXYGEN_CHANNEL_MULTICH is always used */ 643 outs = !!(chip->model->pcm_dev_cfg & PLAYBACK_0_TO_I2S);
644 ins = !!(chip->model->used_channels & (OXYGEN_CHANNEL_A | 644 ins = !!(chip->model->pcm_dev_cfg & (CAPTURE_0_FROM_I2S_1 |
645 OXYGEN_CHANNEL_B)); 645 CAPTURE_0_FROM_I2S_2));
646 err = snd_pcm_new(chip->card, "Analog", 0, outs, ins, &pcm); 646 if (outs | ins) {
647 if (err < 0) 647 err = snd_pcm_new(chip->card, "Analog", 0, outs, ins, &pcm);
648 return err; 648 if (err < 0)
649 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &oxygen_multich_ops); 649 return err;
650 if (chip->model->used_channels & OXYGEN_CHANNEL_A) 650 if (outs)
651 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, 651 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
652 &oxygen_rec_a_ops); 652 &oxygen_multich_ops);
653 else if (chip->model->used_channels & OXYGEN_CHANNEL_B) 653 if (chip->model->pcm_dev_cfg & CAPTURE_0_FROM_I2S_1)
654 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, 654 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
655 &oxygen_rec_b_ops); 655 &oxygen_rec_a_ops);
656 pcm->private_data = chip; 656 else if (chip->model->pcm_dev_cfg & CAPTURE_0_FROM_I2S_2)
657 pcm->private_free = oxygen_pcm_free; 657 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE,
658 strcpy(pcm->name, "Analog"); 658 &oxygen_rec_b_ops);
659 snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream, 659 pcm->private_data = chip;
660 SNDRV_DMA_TYPE_DEV, 660 pcm->private_free = oxygen_pcm_free;
661 snd_dma_pci_data(chip->pci), 661 strcpy(pcm->name, "Analog");
662 512 * 1024, 2048 * 1024); 662 if (outs)
663 if (ins) 663 snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_PLAYBACK].substream,
664 snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream, 664 SNDRV_DMA_TYPE_DEV,
665 SNDRV_DMA_TYPE_DEV, 665 snd_dma_pci_data(chip->pci),
666 snd_dma_pci_data(chip->pci), 666 512 * 1024, 2048 * 1024);
667 128 * 1024, 256 * 1024); 667 if (ins)
668 668 snd_pcm_lib_preallocate_pages(pcm->streams[SNDRV_PCM_STREAM_CAPTURE].substream,
669 outs = !!(chip->model->used_channels & OXYGEN_CHANNEL_SPDIF); 669 SNDRV_DMA_TYPE_DEV,
670 ins = !!(chip->model->used_channels & OXYGEN_CHANNEL_C); 670 snd_dma_pci_data(chip->pci),
671 128 * 1024, 256 * 1024);
672 }
673
674 outs = !!(chip->model->pcm_dev_cfg & PLAYBACK_1_TO_SPDIF);
675 ins = !!(chip->model->pcm_dev_cfg & CAPTURE_1_FROM_SPDIF);
671 if (outs | ins) { 676 if (outs | ins) {
672 err = snd_pcm_new(chip->card, "Digital", 1, outs, ins, &pcm); 677 err = snd_pcm_new(chip->card, "Digital", 1, outs, ins, &pcm);
673 if (err < 0) 678 if (err < 0)
@@ -686,12 +691,13 @@ int oxygen_pcm_init(struct oxygen *chip)
686 128 * 1024, 256 * 1024); 691 128 * 1024, 256 * 1024);
687 } 692 }
688 693
689 outs = chip->has_ac97_1 && 694 if (chip->has_ac97_1) {
690 (chip->model->used_channels & OXYGEN_CHANNEL_AC97); 695 outs = !!(chip->model->pcm_dev_cfg & PLAYBACK_2_TO_AC97_1);
691 ins = outs || 696 ins = !!(chip->model->pcm_dev_cfg & CAPTURE_2_FROM_AC97_1);
692 (chip->model->used_channels & (OXYGEN_CHANNEL_A | 697 } else {
693 OXYGEN_CHANNEL_B)) 698 outs = 0;
694 == (OXYGEN_CHANNEL_A | OXYGEN_CHANNEL_B); 699 ins = !!(chip->model->pcm_dev_cfg & CAPTURE_2_FROM_I2S_2);
700 }
695 if (outs | ins) { 701 if (outs | ins) {
696 err = snd_pcm_new(chip->card, outs ? "AC97" : "Analog2", 702 err = snd_pcm_new(chip->card, outs ? "AC97" : "Analog2",
697 2, outs, ins, &pcm); 703 2, outs, ins, &pcm);
diff --git a/sound/pci/oxygen/pcm1796.h b/sound/pci/oxygen/pcm1796.h
new file mode 100644
index 000000000000..698bf46c710c
--- /dev/null
+++ b/sound/pci/oxygen/pcm1796.h
@@ -0,0 +1,58 @@
1#ifndef PCM1796_H_INCLUDED
2#define PCM1796_H_INCLUDED
3
4/* register 16 */
5#define PCM1796_ATL_MASK 0xff
6/* register 17 */
7#define PCM1796_ATR_MASK 0xff
8/* register 18 */
9#define PCM1796_MUTE 0x01
10#define PCM1796_DME 0x02
11#define PCM1796_DMF_MASK 0x0c
12#define PCM1796_DMF_DISABLED 0x00
13#define PCM1796_DMF_48 0x04
14#define PCM1796_DMF_441 0x08
15#define PCM1796_DMF_32 0x0c
16#define PCM1796_FMT_MASK 0x70
17#define PCM1796_FMT_16_RJUST 0x00
18#define PCM1796_FMT_20_RJUST 0x10
19#define PCM1796_FMT_24_RJUST 0x20
20#define PCM1796_FMT_24_LJUST 0x30
21#define PCM1796_FMT_16_I2S 0x40
22#define PCM1796_FMT_24_I2S 0x50
23#define PCM1796_ATLD 0x80
24/* register 19 */
25#define PCM1796_INZD 0x01
26#define PCM1796_FLT_MASK 0x02
27#define PCM1796_FLT_SHARP 0x00
28#define PCM1796_FLT_SLOW 0x02
29#define PCM1796_DFMS 0x04
30#define PCM1796_OPE 0x10
31#define PCM1796_ATS_MASK 0x60
32#define PCM1796_ATS_1 0x00
33#define PCM1796_ATS_2 0x20
34#define PCM1796_ATS_4 0x40
35#define PCM1796_ATS_8 0x60
36#define PCM1796_REV 0x80
37/* register 20 */
38#define PCM1796_OS_MASK 0x03
39#define PCM1796_OS_64 0x00
40#define PCM1796_OS_32 0x01
41#define PCM1796_OS_128 0x02
42#define PCM1796_CHSL_MASK 0x04
43#define PCM1796_CHSL_LEFT 0x00
44#define PCM1796_CHSL_RIGHT 0x04
45#define PCM1796_MONO 0x08
46#define PCM1796_DFTH 0x10
47#define PCM1796_DSD 0x20
48#define PCM1796_SRST 0x40
49/* register 21 */
50#define PCM1796_PCMZ 0x01
51#define PCM1796_DZ_MASK 0x06
52/* register 22 */
53#define PCM1796_ZFGL 0x01
54#define PCM1796_ZFGR 0x02
55/* register 23 */
56#define PCM1796_ID_MASK 0x1f
57
58#endif
diff --git a/sound/pci/oxygen/virtuoso.c b/sound/pci/oxygen/virtuoso.c
index d163397b85cc..7f84fa5deca2 100644
--- a/sound/pci/oxygen/virtuoso.c
+++ b/sound/pci/oxygen/virtuoso.c
@@ -18,6 +18,9 @@
18 */ 18 */
19 19
20/* 20/*
21 * Xonar D2/D2X
22 * ------------
23 *
21 * CMI8788: 24 * CMI8788:
22 * 25 *
23 * SPI 0 -> 1st PCM1796 (front) 26 * SPI 0 -> 1st PCM1796 (front)
@@ -30,10 +33,33 @@
30 * GPIO 5 <- external power present (D2X only) 33 * GPIO 5 <- external power present (D2X only)
31 * GPIO 7 -> ALT 34 * GPIO 7 -> ALT
32 * GPIO 8 -> enable output to speakers 35 * GPIO 8 -> enable output to speakers
36 */
37
38/*
39 * Xonar DX
40 * --------
41 *
42 * CMI8788:
43 *
44 * I²C <-> CS4398 (front)
45 * <-> CS4362A (surround, center/LFE, back)
46 *
47 * GPI 0 <- external power present
33 * 48 *
34 * CM9780: 49 * GPIO 0 -> enable output to speakers
50 * GPIO 1 -> enable front panel I/O
51 * GPIO 2 -> M0 of CS5361
52 * GPIO 3 -> M1 of CS5361
53 * GPIO 8 -> route input jack to line-in (0) or mic-in (1)
35 * 54 *
36 * GPIO 0 -> enable AC'97 bypass (line in -> ADC) 55 * CS4398:
56 *
57 * AD0 <- 1
58 * AD1 <- 1
59 *
60 * CS4362A:
61 *
62 * AD0 <- 0
37 */ 63 */
38 64
39#include <linux/pci.h> 65#include <linux/pci.h>
@@ -47,11 +73,14 @@
47#include <sound/tlv.h> 73#include <sound/tlv.h>
48#include "oxygen.h" 74#include "oxygen.h"
49#include "cm9780.h" 75#include "cm9780.h"
76#include "pcm1796.h"
77#include "cs4398.h"
78#include "cs4362a.h"
50 79
51MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>"); 80MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
52MODULE_DESCRIPTION("Asus AV200 driver"); 81MODULE_DESCRIPTION("Asus AVx00 driver");
53MODULE_LICENSE("GPL"); 82MODULE_LICENSE("GPL");
54MODULE_SUPPORTED_DEVICE("{{Asus,AV200}}"); 83MODULE_SUPPORTED_DEVICE("{{Asus,AV100},{Asus,AV200}}");
55 84
56static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; 85static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX;
57static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; 86static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR;
@@ -64,80 +93,44 @@ MODULE_PARM_DESC(id, "ID string");
64module_param_array(enable, bool, NULL, 0444); 93module_param_array(enable, bool, NULL, 0444);
65MODULE_PARM_DESC(enable, "enable card"); 94MODULE_PARM_DESC(enable, "enable card");
66 95
96enum {
97 MODEL_D2,
98 MODEL_D2X,
99 MODEL_DX,
100};
101
67static struct pci_device_id xonar_ids[] __devinitdata = { 102static struct pci_device_id xonar_ids[] __devinitdata = {
68 { OXYGEN_PCI_SUBID(0x1043, 0x8269) }, /* Asus Xonar D2 */ 103 { OXYGEN_PCI_SUBID(0x1043, 0x8269), .driver_data = MODEL_D2 },
69 { OXYGEN_PCI_SUBID(0x1043, 0x82b7) }, /* Asus Xonar D2X */ 104 { OXYGEN_PCI_SUBID(0x1043, 0x8275), .driver_data = MODEL_DX },
105 { OXYGEN_PCI_SUBID(0x1043, 0x82b7), .driver_data = MODEL_D2X },
70 { } 106 { }
71}; 107};
72MODULE_DEVICE_TABLE(pci, xonar_ids); 108MODULE_DEVICE_TABLE(pci, xonar_ids);
73 109
74 110
75#define GPIO_CS5381_M_MASK 0x000c 111#define GPIO_CS53x1_M_MASK 0x000c
76#define GPIO_CS5381_M_SINGLE 0x0000 112#define GPIO_CS53x1_M_SINGLE 0x0000
77#define GPIO_CS5381_M_DOUBLE 0x0004 113#define GPIO_CS53x1_M_DOUBLE 0x0004
78#define GPIO_CS5381_M_QUAD 0x0008 114#define GPIO_CS53x1_M_QUAD 0x0008
79#define GPIO_EXT_POWER 0x0020 115
80#define GPIO_ALT 0x0080 116#define GPIO_D2X_EXT_POWER 0x0020
81#define GPIO_OUTPUT_ENABLE 0x0100 117#define GPIO_D2_ALT 0x0080
82 118#define GPIO_D2_OUTPUT_ENABLE 0x0100
83#define GPIO_LINE_MUTE CM9780_GPO0 119
84 120#define GPI_DX_EXT_POWER 0x01
85/* register 16 */ 121#define GPIO_DX_OUTPUT_ENABLE 0x0001
86#define PCM1796_ATL_MASK 0xff 122#define GPIO_DX_FRONT_PANEL 0x0002
87/* register 17 */ 123#define GPIO_DX_INPUT_ROUTE 0x0100
88#define PCM1796_ATR_MASK 0xff 124
89/* register 18 */ 125#define I2C_DEVICE_CS4398 0x9e /* 10011, AD1=1, AD0=1, /W=0 */
90#define PCM1796_MUTE 0x01 126#define I2C_DEVICE_CS4362A 0x30 /* 001100, AD0=0, /W=0 */
91#define PCM1796_DME 0x02
92#define PCM1796_DMF_MASK 0x0c
93#define PCM1796_DMF_DISABLED 0x00
94#define PCM1796_DMF_48 0x04
95#define PCM1796_DMF_441 0x08
96#define PCM1796_DMF_32 0x0c
97#define PCM1796_FMT_MASK 0x70
98#define PCM1796_FMT_16_RJUST 0x00
99#define PCM1796_FMT_20_RJUST 0x10
100#define PCM1796_FMT_24_RJUST 0x20
101#define PCM1796_FMT_24_LJUST 0x30
102#define PCM1796_FMT_16_I2S 0x40
103#define PCM1796_FMT_24_I2S 0x50
104#define PCM1796_ATLD 0x80
105/* register 19 */
106#define PCM1796_INZD 0x01
107#define PCM1796_FLT_MASK 0x02
108#define PCM1796_FLT_SHARP 0x00
109#define PCM1796_FLT_SLOW 0x02
110#define PCM1796_DFMS 0x04
111#define PCM1796_OPE 0x10
112#define PCM1796_ATS_MASK 0x60
113#define PCM1796_ATS_1 0x00
114#define PCM1796_ATS_2 0x20
115#define PCM1796_ATS_4 0x40
116#define PCM1796_ATS_8 0x60
117#define PCM1796_REV 0x80
118/* register 20 */
119#define PCM1796_OS_MASK 0x03
120#define PCM1796_OS_64 0x00
121#define PCM1796_OS_32 0x01
122#define PCM1796_OS_128 0x02
123#define PCM1796_CHSL_MASK 0x04
124#define PCM1796_CHSL_LEFT 0x00
125#define PCM1796_CHSL_RIGHT 0x04
126#define PCM1796_MONO 0x08
127#define PCM1796_DFTH 0x10
128#define PCM1796_DSD 0x20
129#define PCM1796_SRST 0x40
130/* register 21 */
131#define PCM1796_PCMZ 0x01
132#define PCM1796_DZ_MASK 0x06
133/* register 22 */
134#define PCM1796_ZFGL 0x01
135#define PCM1796_ZFGR 0x02
136/* register 23 */
137#define PCM1796_ID_MASK 0x1f
138 127
139struct xonar_data { 128struct xonar_data {
140 u8 is_d2x; 129 unsigned int anti_pop_delay;
130 u16 output_enable_bit;
131 u8 ext_power_reg;
132 u8 ext_power_int_reg;
133 u8 ext_power_bit;
141 u8 has_power; 134 u8 has_power;
142}; 135};
143 136
@@ -156,62 +149,157 @@ static void pcm1796_write(struct oxygen *chip, unsigned int codec,
156 (reg << 8) | value); 149 (reg << 8) | value);
157} 150}
158 151
159static void xonar_init(struct oxygen *chip) 152static void cs4398_write(struct oxygen *chip, u8 reg, u8 value)
153{
154 oxygen_write_i2c(chip, I2C_DEVICE_CS4398, reg, value);
155}
156
157static void cs4362a_write(struct oxygen *chip, u8 reg, u8 value)
158{
159 oxygen_write_i2c(chip, I2C_DEVICE_CS4362A, reg, value);
160}
161
162static void xonar_common_init(struct oxygen *chip)
163{
164 struct xonar_data *data = chip->model_data;
165
166 if (data->ext_power_reg) {
167 oxygen_set_bits8(chip, data->ext_power_int_reg,
168 data->ext_power_bit);
169 chip->interrupt_mask |= OXYGEN_INT_GPIO;
170 data->has_power = !!(oxygen_read8(chip, data->ext_power_reg)
171 & data->ext_power_bit);
172 }
173 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_CS53x1_M_MASK);
174 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
175 GPIO_CS53x1_M_SINGLE, GPIO_CS53x1_M_MASK);
176 oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
177 msleep(data->anti_pop_delay);
178 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, data->output_enable_bit);
179 oxygen_set_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
180}
181
182static void xonar_d2_init(struct oxygen *chip)
160{ 183{
161 struct xonar_data *data = chip->model_data; 184 struct xonar_data *data = chip->model_data;
162 unsigned int i; 185 unsigned int i;
163 186
164 data->is_d2x = chip->pci->subsystem_device == 0x82b7; 187 data->anti_pop_delay = 300;
188 data->output_enable_bit = GPIO_D2_OUTPUT_ENABLE;
165 189
166 for (i = 0; i < 4; ++i) { 190 for (i = 0; i < 4; ++i) {
167 pcm1796_write(chip, i, 18, PCM1796_FMT_24_LJUST | PCM1796_ATLD); 191 pcm1796_write(chip, i, 18, PCM1796_MUTE | PCM1796_DMF_DISABLED |
192 PCM1796_FMT_24_LJUST | PCM1796_ATLD);
168 pcm1796_write(chip, i, 19, PCM1796_FLT_SHARP | PCM1796_ATS_1); 193 pcm1796_write(chip, i, 19, PCM1796_FLT_SHARP | PCM1796_ATS_1);
169 pcm1796_write(chip, i, 20, PCM1796_OS_64); 194 pcm1796_write(chip, i, 20, PCM1796_OS_64);
170 pcm1796_write(chip, i, 21, 0); 195 pcm1796_write(chip, i, 21, 0);
171 pcm1796_write(chip, i, 16, 0xff); /* set ATL/ATR after ATLD */ 196 pcm1796_write(chip, i, 16, 0x0f); /* set ATL/ATR after ATLD */
172 pcm1796_write(chip, i, 17, 0xff); 197 pcm1796_write(chip, i, 17, 0x0f);
173 } 198 }
174 199
175 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, 200 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2_ALT);
176 GPIO_CS5381_M_MASK | GPIO_ALT); 201 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_D2_ALT);
177 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA, 202
178 GPIO_CS5381_M_SINGLE, 203 xonar_common_init(chip);
179 GPIO_CS5381_M_MASK | GPIO_ALT);
180 if (data->is_d2x) {
181 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL,
182 GPIO_EXT_POWER);
183 oxygen_set_bits16(chip, OXYGEN_GPIO_INTERRUPT_MASK,
184 GPIO_EXT_POWER);
185 chip->interrupt_mask |= OXYGEN_INT_GPIO;
186 data->has_power = !!(oxygen_read16(chip, OXYGEN_GPIO_DATA)
187 & GPIO_EXT_POWER);
188 }
189 oxygen_ac97_set_bits(chip, 0, CM9780_JACK, CM9780_FMIC2MIC);
190 oxygen_ac97_clear_bits(chip, 0, CM9780_GPIO_STATUS, GPIO_LINE_MUTE);
191 msleep(300);
192 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_OUTPUT_ENABLE);
193 oxygen_set_bits16(chip, OXYGEN_GPIO_DATA, GPIO_OUTPUT_ENABLE);
194 204
195 snd_component_add(chip->card, "PCM1796"); 205 snd_component_add(chip->card, "PCM1796");
196 snd_component_add(chip->card, "CS5381"); 206 snd_component_add(chip->card, "CS5381");
197} 207}
198 208
209static void xonar_d2x_init(struct oxygen *chip)
210{
211 struct xonar_data *data = chip->model_data;
212
213 data->ext_power_reg = OXYGEN_GPIO_DATA;
214 data->ext_power_int_reg = OXYGEN_GPIO_INTERRUPT_MASK;
215 data->ext_power_bit = GPIO_D2X_EXT_POWER;
216 oxygen_clear_bits16(chip, OXYGEN_GPIO_CONTROL, GPIO_D2X_EXT_POWER);
217 xonar_d2_init(chip);
218}
219
220static void xonar_dx_init(struct oxygen *chip)
221{
222 struct xonar_data *data = chip->model_data;
223
224 data->anti_pop_delay = 800;
225 data->output_enable_bit = GPIO_DX_OUTPUT_ENABLE;
226 data->ext_power_reg = OXYGEN_GPI_DATA;
227 data->ext_power_int_reg = OXYGEN_GPI_INTERRUPT_MASK;
228 data->ext_power_bit = GPI_DX_EXT_POWER;
229
230 oxygen_write16(chip, OXYGEN_2WIRE_BUS_STATUS,
231 OXYGEN_2WIRE_LENGTH_8 |
232 OXYGEN_2WIRE_INTERRUPT_MASK |
233 OXYGEN_2WIRE_SPEED_FAST);
234
235 /* set CPEN (control port mode) and power down */
236 cs4398_write(chip, 8, CS4398_CPEN | CS4398_PDN);
237 cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN);
238 /* configure */
239 cs4398_write(chip, 2, CS4398_FM_SINGLE |
240 CS4398_DEM_NONE | CS4398_DIF_LJUST);
241 cs4398_write(chip, 3, CS4398_ATAPI_B_R | CS4398_ATAPI_A_L);
242 cs4398_write(chip, 4, CS4398_MUTEP_LOW | CS4398_PAMUTE);
243 cs4398_write(chip, 5, 0xfe);
244 cs4398_write(chip, 6, 0xfe);
245 cs4398_write(chip, 7, CS4398_RMP_DN | CS4398_RMP_UP |
246 CS4398_ZERO_CROSS | CS4398_SOFT_RAMP);
247 cs4362a_write(chip, 0x02, CS4362A_DIF_LJUST);
248 cs4362a_write(chip, 0x03, CS4362A_MUTEC_6 | CS4362A_AMUTE |
249 CS4362A_RMP_UP | CS4362A_ZERO_CROSS | CS4362A_SOFT_RAMP);
250 cs4362a_write(chip, 0x04, CS4362A_RMP_DN | CS4362A_DEM_NONE);
251 cs4362a_write(chip, 0x05, 0);
252 cs4362a_write(chip, 0x06, CS4362A_FM_SINGLE |
253 CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L);
254 cs4362a_write(chip, 0x07, 0x7f | CS4362A_MUTE);
255 cs4362a_write(chip, 0x08, 0x7f | CS4362A_MUTE);
256 cs4362a_write(chip, 0x09, CS4362A_FM_SINGLE |
257 CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L);
258 cs4362a_write(chip, 0x0a, 0x7f | CS4362A_MUTE);
259 cs4362a_write(chip, 0x0b, 0x7f | CS4362A_MUTE);
260 cs4362a_write(chip, 0x0c, CS4362A_FM_SINGLE |
261 CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L);
262 cs4362a_write(chip, 0x0d, 0x7f | CS4362A_MUTE);
263 cs4362a_write(chip, 0x0e, 0x7f | CS4362A_MUTE);
264 /* clear power down */
265 cs4398_write(chip, 8, CS4398_CPEN);
266 cs4362a_write(chip, 0x01, CS4362A_CPEN);
267
268 oxygen_set_bits16(chip, OXYGEN_GPIO_CONTROL,
269 GPIO_DX_FRONT_PANEL | GPIO_DX_INPUT_ROUTE);
270 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA,
271 GPIO_DX_FRONT_PANEL | GPIO_DX_INPUT_ROUTE);
272
273 xonar_common_init(chip);
274
275 snd_component_add(chip->card, "CS4398");
276 snd_component_add(chip->card, "CS4362A");
277 snd_component_add(chip->card, "CS5361");
278}
279
199static void xonar_cleanup(struct oxygen *chip) 280static void xonar_cleanup(struct oxygen *chip)
200{ 281{
201 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, GPIO_OUTPUT_ENABLE); 282 struct xonar_data *data = chip->model_data;
283
284 oxygen_clear_bits16(chip, OXYGEN_GPIO_DATA, data->output_enable_bit);
285}
286
287static void xonar_dx_cleanup(struct oxygen *chip)
288{
289 xonar_cleanup(chip);
290 cs4362a_write(chip, 0x01, CS4362A_PDN | CS4362A_CPEN);
291 oxygen_clear_bits8(chip, OXYGEN_FUNCTION, OXYGEN_FUNCTION_RESET_CODEC);
202} 292}
203 293
204static void set_pcm1796_params(struct oxygen *chip, 294static void set_pcm1796_params(struct oxygen *chip,
205 struct snd_pcm_hw_params *params) 295 struct snd_pcm_hw_params *params)
206{ 296{
207#if 0
208 unsigned int i; 297 unsigned int i;
209 u8 value; 298 u8 value;
210 299
211 value = params_rate(params) >= 96000 ? PCM1796_OS_32 : PCM1796_OS_64; 300 value = params_rate(params) >= 96000 ? PCM1796_OS_32 : PCM1796_OS_64;
212 for (i = 0; i < 4; ++i) 301 for (i = 0; i < 4; ++i)
213 pcm1796_write(chip, i, 20, value); 302 pcm1796_write(chip, i, 20, value);
214#endif
215} 303}
216 304
217static void update_pcm1796_volume(struct oxygen *chip) 305static void update_pcm1796_volume(struct oxygen *chip)
@@ -236,19 +324,73 @@ static void update_pcm1796_mute(struct oxygen *chip)
236 pcm1796_write(chip, i, 18, value); 324 pcm1796_write(chip, i, 18, value);
237} 325}
238 326
239static void set_cs5381_params(struct oxygen *chip, 327static void set_cs53x1_params(struct oxygen *chip,
240 struct snd_pcm_hw_params *params) 328 struct snd_pcm_hw_params *params)
241{ 329{
242 unsigned int value; 330 unsigned int value;
243 331
244 if (params_rate(params) <= 54000) 332 if (params_rate(params) <= 54000)
245 value = GPIO_CS5381_M_SINGLE; 333 value = GPIO_CS53x1_M_SINGLE;
246 else if (params_rate(params) <= 108000) 334 else if (params_rate(params) <= 108000)
247 value = GPIO_CS5381_M_DOUBLE; 335 value = GPIO_CS53x1_M_DOUBLE;
248 else 336 else
249 value = GPIO_CS5381_M_QUAD; 337 value = GPIO_CS53x1_M_QUAD;
250 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA, 338 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
251 value, GPIO_CS5381_M_MASK); 339 value, GPIO_CS53x1_M_MASK);
340}
341
342static void set_cs43xx_params(struct oxygen *chip,
343 struct snd_pcm_hw_params *params)
344{
345 u8 fm_cs4398, fm_cs4362a;
346
347 fm_cs4398 = CS4398_DEM_NONE | CS4398_DIF_LJUST;
348 fm_cs4362a = CS4362A_ATAPI_B_R | CS4362A_ATAPI_A_L;
349 if (params_rate(params) <= 50000) {
350 fm_cs4398 |= CS4398_FM_SINGLE;
351 fm_cs4362a |= CS4362A_FM_SINGLE;
352 } else if (params_rate(params) <= 100000) {
353 fm_cs4398 |= CS4398_FM_DOUBLE;
354 fm_cs4362a |= CS4362A_FM_DOUBLE;
355 } else {
356 fm_cs4398 |= CS4398_FM_QUAD;
357 fm_cs4362a |= CS4362A_FM_QUAD;
358 }
359 cs4398_write(chip, 2, fm_cs4398);
360 cs4362a_write(chip, 0x06, fm_cs4362a);
361 cs4362a_write(chip, 0x09, fm_cs4362a);
362 cs4362a_write(chip, 0x0c, fm_cs4362a);
363}
364
365static void update_cs4362a_volumes(struct oxygen *chip)
366{
367 u8 mute;
368
369 mute = chip->dac_mute ? CS4362A_MUTE : 0;
370 cs4362a_write(chip, 7, (127 - chip->dac_volume[2]) | mute);
371 cs4362a_write(chip, 8, (127 - chip->dac_volume[3]) | mute);
372 cs4362a_write(chip, 10, (127 - chip->dac_volume[4]) | mute);
373 cs4362a_write(chip, 11, (127 - chip->dac_volume[5]) | mute);
374 cs4362a_write(chip, 13, (127 - chip->dac_volume[6]) | mute);
375 cs4362a_write(chip, 14, (127 - chip->dac_volume[7]) | mute);
376}
377
378static void update_cs43xx_volume(struct oxygen *chip)
379{
380 cs4398_write(chip, 5, (127 - chip->dac_volume[0]) * 2);
381 cs4398_write(chip, 6, (127 - chip->dac_volume[1]) * 2);
382 update_cs4362a_volumes(chip);
383}
384
385static void update_cs43xx_mute(struct oxygen *chip)
386{
387 u8 reg;
388
389 reg = CS4398_MUTEP_LOW | CS4398_PAMUTE;
390 if (chip->dac_mute)
391 reg |= CS4398_MUTE_B | CS4398_MUTE_A;
392 cs4398_write(chip, 4, reg);
393 update_cs4362a_volumes(chip);
252} 394}
253 395
254static void xonar_gpio_changed(struct oxygen *chip) 396static void xonar_gpio_changed(struct oxygen *chip)
@@ -256,10 +398,8 @@ static void xonar_gpio_changed(struct oxygen *chip)
256 struct xonar_data *data = chip->model_data; 398 struct xonar_data *data = chip->model_data;
257 u8 has_power; 399 u8 has_power;
258 400
259 if (!data->is_d2x) 401 has_power = !!(oxygen_read8(chip, data->ext_power_reg)
260 return; 402 & data->ext_power_bit);
261 has_power = !!(oxygen_read16(chip, OXYGEN_GPIO_DATA)
262 & GPIO_EXT_POWER);
263 if (has_power != data->has_power) { 403 if (has_power != data->has_power) {
264 data->has_power = has_power; 404 data->has_power = has_power;
265 if (has_power) { 405 if (has_power) {
@@ -272,66 +412,13 @@ static void xonar_gpio_changed(struct oxygen *chip)
272 } 412 }
273} 413}
274 414
275static void mute_ac97_ctl(struct oxygen *chip, unsigned int control)
276{
277 unsigned int index = chip->controls[control]->private_value & 0xff;
278 u16 value;
279
280 value = oxygen_read_ac97(chip, 0, index);
281 if (!(value & 0x8000)) {
282 oxygen_write_ac97(chip, 0, index, value | 0x8000);
283 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
284 &chip->controls[control]->id);
285 }
286}
287
288static void xonar_ac97_switch_hook(struct oxygen *chip, unsigned int codec,
289 unsigned int reg, int mute)
290{
291 if (codec != 0)
292 return;
293 /* line-in is exclusive */
294 switch (reg) {
295 case AC97_LINE:
296 oxygen_write_ac97_masked(chip, 0, CM9780_GPIO_STATUS,
297 mute ? GPIO_LINE_MUTE : 0,
298 GPIO_LINE_MUTE);
299 if (!mute) {
300 mute_ac97_ctl(chip, CONTROL_MIC_CAPTURE_SWITCH);
301 mute_ac97_ctl(chip, CONTROL_CD_CAPTURE_SWITCH);
302 mute_ac97_ctl(chip, CONTROL_AUX_CAPTURE_SWITCH);
303 }
304 break;
305 case AC97_MIC:
306 case AC97_CD:
307 case AC97_VIDEO:
308 case AC97_AUX:
309 if (!mute) {
310 oxygen_ac97_set_bits(chip, 0, CM9780_GPIO_STATUS,
311 GPIO_LINE_MUTE);
312 mute_ac97_ctl(chip, CONTROL_LINE_CAPTURE_SWITCH);
313 }
314 break;
315 }
316}
317
318static int pcm1796_volume_info(struct snd_kcontrol *ctl,
319 struct snd_ctl_elem_info *info)
320{
321 info->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
322 info->count = 8;
323 info->value.integer.min = 0x0f;
324 info->value.integer.max = 0xff;
325 return 0;
326}
327
328static int alt_switch_get(struct snd_kcontrol *ctl, 415static int alt_switch_get(struct snd_kcontrol *ctl,
329 struct snd_ctl_elem_value *value) 416 struct snd_ctl_elem_value *value)
330{ 417{
331 struct oxygen *chip = ctl->private_data; 418 struct oxygen *chip = ctl->private_data;
332 419
333 value->value.integer.value[0] = 420 value->value.integer.value[0] =
334 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_ALT); 421 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_D2_ALT);
335 return 0; 422 return 0;
336} 423}
337 424
@@ -345,9 +432,9 @@ static int alt_switch_put(struct snd_kcontrol *ctl,
345 spin_lock_irq(&chip->reg_lock); 432 spin_lock_irq(&chip->reg_lock);
346 old_bits = oxygen_read16(chip, OXYGEN_GPIO_DATA); 433 old_bits = oxygen_read16(chip, OXYGEN_GPIO_DATA);
347 if (value->value.integer.value[0]) 434 if (value->value.integer.value[0])
348 new_bits = old_bits | GPIO_ALT; 435 new_bits = old_bits | GPIO_D2_ALT;
349 else 436 else
350 new_bits = old_bits & ~GPIO_ALT; 437 new_bits = old_bits & ~GPIO_D2_ALT;
351 changed = new_bits != old_bits; 438 changed = new_bits != old_bits;
352 if (changed) 439 if (changed)
353 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_bits); 440 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_bits);
@@ -363,20 +450,68 @@ static const struct snd_kcontrol_new alt_switch = {
363 .put = alt_switch_put, 450 .put = alt_switch_put,
364}; 451};
365 452
453static int front_panel_get(struct snd_kcontrol *ctl,
454 struct snd_ctl_elem_value *value)
455{
456 struct oxygen *chip = ctl->private_data;
457
458 value->value.integer.value[0] =
459 !!(oxygen_read16(chip, OXYGEN_GPIO_DATA) & GPIO_DX_FRONT_PANEL);
460 return 0;
461}
462
463static int front_panel_put(struct snd_kcontrol *ctl,
464 struct snd_ctl_elem_value *value)
465{
466 struct oxygen *chip = ctl->private_data;
467 u16 old_reg, new_reg;
468
469 spin_lock_irq(&chip->reg_lock);
470 old_reg = oxygen_read16(chip, OXYGEN_GPIO_DATA);
471 if (value->value.integer.value[0])
472 new_reg = old_reg | GPIO_DX_FRONT_PANEL;
473 else
474 new_reg = old_reg & ~GPIO_DX_FRONT_PANEL;
475 oxygen_write16(chip, OXYGEN_GPIO_DATA, new_reg);
476 spin_unlock_irq(&chip->reg_lock);
477 return old_reg != new_reg;
478}
479
480static const struct snd_kcontrol_new front_panel_switch = {
481 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
482 .name = "Front Panel Switch",
483 .info = snd_ctl_boolean_mono_info,
484 .get = front_panel_get,
485 .put = front_panel_put,
486};
487
488static void xonar_dx_ac97_switch(struct oxygen *chip,
489 unsigned int reg, unsigned int mute)
490{
491 if (reg == AC97_LINE) {
492 spin_lock_irq(&chip->reg_lock);
493 oxygen_write16_masked(chip, OXYGEN_GPIO_DATA,
494 mute ? GPIO_DX_INPUT_ROUTE : 0,
495 GPIO_DX_INPUT_ROUTE);
496 spin_unlock_irq(&chip->reg_lock);
497 }
498}
499
366static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -12000, 50, 0); 500static const DECLARE_TLV_DB_SCALE(pcm1796_db_scale, -12000, 50, 0);
501static const DECLARE_TLV_DB_SCALE(cs4362a_db_scale, -12700, 100, 0);
367 502
368static int xonar_control_filter(struct snd_kcontrol_new *template) 503static int xonar_d2_control_filter(struct snd_kcontrol_new *template)
369{ 504{
370 if (!strcmp(template->name, "Master Playback Volume")) { 505 if (!strncmp(template->name, "CD Capture ", 11))
371 template->access |= SNDRV_CTL_ELEM_ACCESS_TLV_READ;
372 template->info = pcm1796_volume_info,
373 template->tlv.p = pcm1796_db_scale;
374 } else if (!strncmp(template->name, "CD Capture ", 11)) {
375 /* CD in is actually connected to the video in pin */ 506 /* CD in is actually connected to the video in pin */
376 template->private_value ^= AC97_CD ^ AC97_VIDEO; 507 template->private_value ^= AC97_CD ^ AC97_VIDEO;
377 } else if (!strcmp(template->name, "Line Capture Volume")) { 508 return 0;
378 return 1; /* line-in bypasses the AC'97 mixer */ 509}
379 } 510
511static int xonar_dx_control_filter(struct snd_kcontrol_new *template)
512{
513 if (!strncmp(template->name, "CD Capture ", 11))
514 return 1; /* no CD input */
380 return 0; 515 return 0;
381} 516}
382 517
@@ -385,30 +520,96 @@ static int xonar_mixer_init(struct oxygen *chip)
385 return snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip)); 520 return snd_ctl_add(chip->card, snd_ctl_new1(&alt_switch, chip));
386} 521}
387 522
388static const struct oxygen_model model_xonar = { 523static int xonar_dx_mixer_init(struct oxygen *chip)
389 .shortname = "Asus AV200", 524{
390 .longname = "Asus Virtuoso 200", 525 return snd_ctl_add(chip->card, snd_ctl_new1(&front_panel_switch, chip));
391 .chip = "AV200", 526}
392 .owner = THIS_MODULE, 527
393 .init = xonar_init, 528static const struct oxygen_model xonar_models[] = {
394 .control_filter = xonar_control_filter, 529 [MODEL_D2] = {
395 .mixer_init = xonar_mixer_init, 530 .shortname = "Xonar D2",
396 .cleanup = xonar_cleanup, 531 .longname = "Asus Virtuoso 200",
397 .set_dac_params = set_pcm1796_params, 532 .chip = "AV200",
398 .set_adc_params = set_cs5381_params, 533 .owner = THIS_MODULE,
399 .update_dac_volume = update_pcm1796_volume, 534 .init = xonar_d2_init,
400 .update_dac_mute = update_pcm1796_mute, 535 .control_filter = xonar_d2_control_filter,
401 .ac97_switch_hook = xonar_ac97_switch_hook, 536 .mixer_init = xonar_mixer_init,
402 .gpio_changed = xonar_gpio_changed, 537 .cleanup = xonar_cleanup,
403 .model_data_size = sizeof(struct xonar_data), 538 .set_dac_params = set_pcm1796_params,
404 .dac_channels = 8, 539 .set_adc_params = set_cs53x1_params,
405 .used_channels = OXYGEN_CHANNEL_B | 540 .update_dac_volume = update_pcm1796_volume,
406 OXYGEN_CHANNEL_C | 541 .update_dac_mute = update_pcm1796_mute,
407 OXYGEN_CHANNEL_SPDIF | 542 .dac_tlv = pcm1796_db_scale,
408 OXYGEN_CHANNEL_MULTICH, 543 .model_data_size = sizeof(struct xonar_data),
409 .function_flags = OXYGEN_FUNCTION_ENABLE_SPI_4_5, 544 .pcm_dev_cfg = PLAYBACK_0_TO_I2S |
410 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 545 PLAYBACK_1_TO_SPDIF |
411 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST, 546 CAPTURE_0_FROM_I2S_2 |
547 CAPTURE_1_FROM_SPDIF,
548 .dac_channels = 8,
549 .dac_volume_min = 0x0f,
550 .dac_volume_max = 0xff,
551 .misc_flags = OXYGEN_MISC_MIDI,
552 .function_flags = OXYGEN_FUNCTION_SPI |
553 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
554 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
555 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
556 },
557 [MODEL_D2X] = {
558 .shortname = "Xonar D2X",
559 .longname = "Asus Virtuoso 200",
560 .chip = "AV200",
561 .owner = THIS_MODULE,
562 .init = xonar_d2x_init,
563 .control_filter = xonar_d2_control_filter,
564 .mixer_init = xonar_mixer_init,
565 .cleanup = xonar_cleanup,
566 .set_dac_params = set_pcm1796_params,
567 .set_adc_params = set_cs53x1_params,
568 .update_dac_volume = update_pcm1796_volume,
569 .update_dac_mute = update_pcm1796_mute,
570 .gpio_changed = xonar_gpio_changed,
571 .dac_tlv = pcm1796_db_scale,
572 .model_data_size = sizeof(struct xonar_data),
573 .pcm_dev_cfg = PLAYBACK_0_TO_I2S |
574 PLAYBACK_1_TO_SPDIF |
575 CAPTURE_0_FROM_I2S_2 |
576 CAPTURE_1_FROM_SPDIF,
577 .dac_channels = 8,
578 .dac_volume_min = 0x0f,
579 .dac_volume_max = 0xff,
580 .misc_flags = OXYGEN_MISC_MIDI,
581 .function_flags = OXYGEN_FUNCTION_SPI |
582 OXYGEN_FUNCTION_ENABLE_SPI_4_5,
583 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
584 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
585 },
586 [MODEL_DX] = {
587 .shortname = "Xonar DX",
588 .longname = "Asus Virtuoso 100",
589 .chip = "AV200",
590 .owner = THIS_MODULE,
591 .init = xonar_dx_init,
592 .control_filter = xonar_dx_control_filter,
593 .mixer_init = xonar_dx_mixer_init,
594 .cleanup = xonar_dx_cleanup,
595 .set_dac_params = set_cs43xx_params,
596 .set_adc_params = set_cs53x1_params,
597 .update_dac_volume = update_cs43xx_volume,
598 .update_dac_mute = update_cs43xx_mute,
599 .gpio_changed = xonar_gpio_changed,
600 .ac97_switch = xonar_dx_ac97_switch,
601 .dac_tlv = cs4362a_db_scale,
602 .model_data_size = sizeof(struct xonar_data),
603 .pcm_dev_cfg = PLAYBACK_0_TO_I2S |
604 PLAYBACK_1_TO_SPDIF |
605 CAPTURE_0_FROM_I2S_2,
606 .dac_channels = 8,
607 .dac_volume_min = 0,
608 .dac_volume_max = 127,
609 .function_flags = OXYGEN_FUNCTION_2WIRE,
610 .dac_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
611 .adc_i2s_format = OXYGEN_I2S_FORMAT_LJUST,
612 },
412}; 613};
413 614
414static int __devinit xonar_probe(struct pci_dev *pci, 615static int __devinit xonar_probe(struct pci_dev *pci,
@@ -423,7 +624,8 @@ static int __devinit xonar_probe(struct pci_dev *pci,
423 ++dev; 624 ++dev;
424 return -ENOENT; 625 return -ENOENT;
425 } 626 }
426 err = oxygen_pci_probe(pci, index[dev], id[dev], 1, &model_xonar); 627 err = oxygen_pci_probe(pci, index[dev], id[dev],
628 &xonar_models[pci_id->driver_data]);
427 if (err >= 0) 629 if (err >= 0)
428 ++dev; 630 ++dev;
429 return err; 631 return err;
diff --git a/sound/pci/oxygen/wm8785.h b/sound/pci/oxygen/wm8785.h
new file mode 100644
index 000000000000..8c23e315ae66
--- /dev/null
+++ b/sound/pci/oxygen/wm8785.h
@@ -0,0 +1,45 @@
1#ifndef WM8785_H_INCLUDED
2#define WM8785_H_INCLUDED
3
4#define WM8785_R0 0
5#define WM8785_R1 1
6#define WM8785_R2 2
7#define WM8785_R7 7
8
9/* R0 */
10#define WM8785_MCR_MASK 0x007
11#define WM8785_MCR_SLAVE 0x000
12#define WM8785_MCR_MASTER_128 0x001
13#define WM8785_MCR_MASTER_192 0x002
14#define WM8785_MCR_MASTER_256 0x003
15#define WM8785_MCR_MASTER_384 0x004
16#define WM8785_MCR_MASTER_512 0x005
17#define WM8785_MCR_MASTER_768 0x006
18#define WM8785_OSR_MASK 0x018
19#define WM8785_OSR_SINGLE 0x000
20#define WM8785_OSR_DOUBLE 0x008
21#define WM8785_OSR_QUAD 0x010
22#define WM8785_FORMAT_MASK 0x060
23#define WM8785_FORMAT_RJUST 0x000
24#define WM8785_FORMAT_LJUST 0x020
25#define WM8785_FORMAT_I2S 0x040
26#define WM8785_FORMAT_DSP 0x060
27/* R1 */
28#define WM8785_WL_MASK 0x003
29#define WM8785_WL_16 0x000
30#define WM8785_WL_20 0x001
31#define WM8785_WL_24 0x002
32#define WM8785_WL_32 0x003
33#define WM8785_LRP 0x004
34#define WM8785_BCLKINV 0x008
35#define WM8785_LRSWAP 0x010
36#define WM8785_DEVNO_MASK 0x0e0
37/* R2 */
38#define WM8785_HPFR 0x001
39#define WM8785_HPFL 0x002
40#define WM8785_SDODIS 0x004
41#define WM8785_PWRDNR 0x008
42#define WM8785_PWRDNL 0x010
43#define WM8785_TDM_MASK 0x1c0
44
45#endif
diff --git a/sound/pci/pcxhr/pcxhr.c b/sound/pci/pcxhr/pcxhr.c
index 9d5bb76229a8..7fdcdc8c6b64 100644
--- a/sound/pci/pcxhr/pcxhr.c
+++ b/sound/pci/pcxhr/pcxhr.c
@@ -458,7 +458,7 @@ static int pcxhr_update_r_buffer(struct pcxhr_stream *stream)
458 458
459 snd_printdd("pcxhr_update_r_buffer(pcm%c%d) : addr(%p) bytes(%zx) subs(%d)\n", 459 snd_printdd("pcxhr_update_r_buffer(pcm%c%d) : addr(%p) bytes(%zx) subs(%d)\n",
460 is_capture ? 'c' : 'p', 460 is_capture ? 'c' : 'p',
461 chip->chip_idx, (void*)subs->runtime->dma_addr, 461 chip->chip_idx, (void *)(long)subs->runtime->dma_addr,
462 subs->runtime->dma_bytes, subs->number); 462 subs->runtime->dma_bytes, subs->number);
463 463
464 pcxhr_init_rmh(&rmh, CMD_UPDATE_R_BUFFERS); 464 pcxhr_init_rmh(&rmh, CMD_UPDATE_R_BUFFERS);
@@ -626,7 +626,7 @@ static void pcxhr_trigger_tasklet(unsigned long arg)
626#ifdef CONFIG_SND_DEBUG_DETECT 626#ifdef CONFIG_SND_DEBUG_DETECT
627 do_gettimeofday(&my_tv2); 627 do_gettimeofday(&my_tv2);
628 snd_printdd("***TRIGGER TASKLET*** TIME = %ld (err = %x)\n", 628 snd_printdd("***TRIGGER TASKLET*** TIME = %ld (err = %x)\n",
629 my_tv2.tv_usec - my_tv1.tv_usec, err); 629 (long)(my_tv2.tv_usec - my_tv1.tv_usec), err);
630#endif 630#endif
631} 631}
632 632
@@ -846,7 +846,6 @@ static int pcxhr_open(struct snd_pcm_substream *subs)
846 struct pcxhr_mgr *mgr = chip->mgr; 846 struct pcxhr_mgr *mgr = chip->mgr;
847 struct snd_pcm_runtime *runtime = subs->runtime; 847 struct snd_pcm_runtime *runtime = subs->runtime;
848 struct pcxhr_stream *stream; 848 struct pcxhr_stream *stream;
849 int is_capture;
850 849
851 mutex_lock(&mgr->setup_mutex); 850 mutex_lock(&mgr->setup_mutex);
852 851
@@ -856,12 +855,10 @@ static int pcxhr_open(struct snd_pcm_substream *subs)
856 if( subs->stream == SNDRV_PCM_STREAM_PLAYBACK ) { 855 if( subs->stream == SNDRV_PCM_STREAM_PLAYBACK ) {
857 snd_printdd("pcxhr_open playback chip%d subs%d\n", 856 snd_printdd("pcxhr_open playback chip%d subs%d\n",
858 chip->chip_idx, subs->number); 857 chip->chip_idx, subs->number);
859 is_capture = 0;
860 stream = &chip->playback_stream[subs->number]; 858 stream = &chip->playback_stream[subs->number];
861 } else { 859 } else {
862 snd_printdd("pcxhr_open capture chip%d subs%d\n", 860 snd_printdd("pcxhr_open capture chip%d subs%d\n",
863 chip->chip_idx, subs->number); 861 chip->chip_idx, subs->number);
864 is_capture = 1;
865 if (mgr->mono_capture) 862 if (mgr->mono_capture)
866 runtime->hw.channels_max = 1; 863 runtime->hw.channels_max = 1;
867 else 864 else
diff --git a/sound/pci/pcxhr/pcxhr_core.c b/sound/pci/pcxhr/pcxhr_core.c
index c4e415d07380..78aa81feaa4a 100644
--- a/sound/pci/pcxhr/pcxhr_core.c
+++ b/sound/pci/pcxhr/pcxhr_core.c
@@ -897,7 +897,7 @@ int pcxhr_set_pipe_state(struct pcxhr_mgr *mgr, int playback_mask, int capture_m
897#ifdef CONFIG_SND_DEBUG_DETECT 897#ifdef CONFIG_SND_DEBUG_DETECT
898 do_gettimeofday(&my_tv2); 898 do_gettimeofday(&my_tv2);
899 snd_printdd("***SET PIPE STATE*** TIME = %ld (err = %x)\n", 899 snd_printdd("***SET PIPE STATE*** TIME = %ld (err = %x)\n",
900 my_tv2.tv_usec - my_tv1.tv_usec, err); 900 (long)(my_tv2.tv_usec - my_tv1.tv_usec), err);
901#endif 901#endif
902 return 0; 902 return 0;
903} 903}
@@ -1005,30 +1005,37 @@ void pcxhr_msg_tasklet(unsigned long arg)
1005 int nb_stream = (prmh->stat[i] >> (2*FIELD_SIZE)) & MASK_FIRST_FIELD; 1005 int nb_stream = (prmh->stat[i] >> (2*FIELD_SIZE)) & MASK_FIRST_FIELD;
1006 int pipe = prmh->stat[i] & MASK_FIRST_FIELD; 1006 int pipe = prmh->stat[i] & MASK_FIRST_FIELD;
1007 int is_capture = prmh->stat[i] & 0x400000; 1007 int is_capture = prmh->stat[i] & 0x400000;
1008 u32 err; 1008 u32 err2;
1009 1009
1010 if (prmh->stat[i] & 0x800000) { /* if BIT_END */ 1010 if (prmh->stat[i] & 0x800000) { /* if BIT_END */
1011 snd_printdd("TASKLET : End%sPipe %d\n", 1011 snd_printdd("TASKLET : End%sPipe %d\n",
1012 is_capture ? "Record" : "Play", pipe); 1012 is_capture ? "Record" : "Play", pipe);
1013 } 1013 }
1014 i++; 1014 i++;
1015 err = prmh->stat[i] ? prmh->stat[i] : prmh->stat[i+1]; 1015 err2 = prmh->stat[i] ? prmh->stat[i] : prmh->stat[i+1];
1016 if (err) 1016 if (err2)
1017 pcxhr_handle_async_err(mgr, err, PCXHR_ERR_PIPE, 1017 pcxhr_handle_async_err(mgr, err2,
1018 PCXHR_ERR_PIPE,
1018 pipe, is_capture); 1019 pipe, is_capture);
1019 i += 2; 1020 i += 2;
1020 for (j = 0; j < nb_stream; j++) { 1021 for (j = 0; j < nb_stream; j++) {
1021 err = prmh->stat[i] ? prmh->stat[i] : prmh->stat[i+1]; 1022 err2 = prmh->stat[i] ?
1022 if (err) 1023 prmh->stat[i] : prmh->stat[i+1];
1023 pcxhr_handle_async_err(mgr, err, PCXHR_ERR_STREAM, 1024 if (err2)
1024 pipe, is_capture); 1025 pcxhr_handle_async_err(mgr, err2,
1026 PCXHR_ERR_STREAM,
1027 pipe,
1028 is_capture);
1025 i += 2; 1029 i += 2;
1026 } 1030 }
1027 for (j = 0; j < nb_audio; j++) { 1031 for (j = 0; j < nb_audio; j++) {
1028 err = prmh->stat[i] ? prmh->stat[i] : prmh->stat[i+1]; 1032 err2 = prmh->stat[i] ?
1029 if (err) 1033 prmh->stat[i] : prmh->stat[i+1];
1030 pcxhr_handle_async_err(mgr, err, PCXHR_ERR_AUDIO, 1034 if (err2)
1031 pipe, is_capture); 1035 pcxhr_handle_async_err(mgr, err2,
1036 PCXHR_ERR_AUDIO,
1037 pipe,
1038 is_capture);
1032 i += 2; 1039 i += 2;
1033 } 1040 }
1034 } 1041 }
diff --git a/sound/pci/riptide/riptide.c b/sound/pci/riptide/riptide.c
index 9408b1eeec40..979f7da641ce 100644
--- a/sound/pci/riptide/riptide.c
+++ b/sound/pci/riptide/riptide.c
@@ -1630,14 +1630,14 @@ static int snd_riptide_playback_open(struct snd_pcm_substream *substream)
1630 struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1630 struct snd_riptide *chip = snd_pcm_substream_chip(substream);
1631 struct snd_pcm_runtime *runtime = substream->runtime; 1631 struct snd_pcm_runtime *runtime = substream->runtime;
1632 struct pcmhw *data; 1632 struct pcmhw *data;
1633 int index = substream->number; 1633 int sub_num = substream->number;
1634 1634
1635 chip->playback_substream[index] = substream; 1635 chip->playback_substream[sub_num] = substream;
1636 runtime->hw = snd_riptide_playback; 1636 runtime->hw = snd_riptide_playback;
1637 data = kzalloc(sizeof(struct pcmhw), GFP_KERNEL); 1637 data = kzalloc(sizeof(struct pcmhw), GFP_KERNEL);
1638 data->paths = lbus_play_paths[index]; 1638 data->paths = lbus_play_paths[sub_num];
1639 data->id = play_ids[index]; 1639 data->id = play_ids[sub_num];
1640 data->source = play_sources[index]; 1640 data->source = play_sources[sub_num];
1641 data->intdec[0] = 0xff; 1641 data->intdec[0] = 0xff;
1642 data->intdec[1] = 0xff; 1642 data->intdec[1] = 0xff;
1643 data->state = ST_STOP; 1643 data->state = ST_STOP;
@@ -1670,10 +1670,10 @@ static int snd_riptide_playback_close(struct snd_pcm_substream *substream)
1670{ 1670{
1671 struct snd_riptide *chip = snd_pcm_substream_chip(substream); 1671 struct snd_riptide *chip = snd_pcm_substream_chip(substream);
1672 struct pcmhw *data = get_pcmhwdev(substream); 1672 struct pcmhw *data = get_pcmhwdev(substream);
1673 int index = substream->number; 1673 int sub_num = substream->number;
1674 1674
1675 substream->runtime->private_data = NULL; 1675 substream->runtime->private_data = NULL;
1676 chip->playback_substream[index] = NULL; 1676 chip->playback_substream[sub_num] = NULL;
1677 kfree(data); 1677 kfree(data);
1678 return 0; 1678 return 0;
1679} 1679}
diff --git a/sound/pci/rme32.c b/sound/pci/rme32.c
index df184aabce84..e7ef3a1a25a8 100644
--- a/sound/pci/rme32.c
+++ b/sound/pci/rme32.c
@@ -1350,7 +1350,8 @@ static int __devinit snd_rme32_create(struct rme32 * rme32)
1350 return err; 1350 return err;
1351 rme32->port = pci_resource_start(rme32->pci, 0); 1351 rme32->port = pci_resource_start(rme32->pci, 0);
1352 1352
1353 if ((rme32->iobase = ioremap_nocache(rme32->port, RME32_IO_SIZE)) == 0) { 1353 rme32->iobase = ioremap_nocache(rme32->port, RME32_IO_SIZE);
1354 if (!rme32->iobase) {
1354 snd_printk(KERN_ERR "unable to remap memory region 0x%lx-0x%lx\n", 1355 snd_printk(KERN_ERR "unable to remap memory region 0x%lx-0x%lx\n",
1355 rme32->port, rme32->port + RME32_IO_SIZE - 1); 1356 rme32->port, rme32->port + RME32_IO_SIZE - 1);
1356 return -ENOMEM; 1357 return -ENOMEM;
diff --git a/sound/pci/rme96.c b/sound/pci/rme96.c
index fb0a4ee8bc02..3fdd488d0975 100644
--- a/sound/pci/rme96.c
+++ b/sound/pci/rme96.c
@@ -1559,7 +1559,8 @@ snd_rme96_create(struct rme96 *rme96)
1559 return err; 1559 return err;
1560 rme96->port = pci_resource_start(rme96->pci, 0); 1560 rme96->port = pci_resource_start(rme96->pci, 0);
1561 1561
1562 if ((rme96->iobase = ioremap_nocache(rme96->port, RME96_IO_SIZE)) == 0) { 1562 rme96->iobase = ioremap_nocache(rme96->port, RME96_IO_SIZE);
1563 if (!rme96->iobase) {
1563 snd_printk(KERN_ERR "unable to remap memory region 0x%lx-0x%lx\n", rme96->port, rme96->port + RME96_IO_SIZE - 1); 1564 snd_printk(KERN_ERR "unable to remap memory region 0x%lx-0x%lx\n", rme96->port, rme96->port + RME96_IO_SIZE - 1);
1564 return -ENOMEM; 1565 return -ENOMEM;
1565 } 1566 }
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
index 1be84f22d0de..4d6fbb36ab8a 100644
--- a/sound/pci/rme9652/hdsp.c
+++ b/sound/pci/rme9652/hdsp.c
@@ -318,6 +318,10 @@ MODULE_FIRMWARE("digiface_firmware_rev11.bin");
318#define HDSP_midi1IRQPending (1<<31) 318#define HDSP_midi1IRQPending (1<<31)
319 319
320#define HDSP_spdifFrequencyMask (HDSP_spdifFrequency0|HDSP_spdifFrequency1|HDSP_spdifFrequency2) 320#define HDSP_spdifFrequencyMask (HDSP_spdifFrequency0|HDSP_spdifFrequency1|HDSP_spdifFrequency2)
321#define HDSP_spdifFrequencyMask_9632 (HDSP_spdifFrequency0|\
322 HDSP_spdifFrequency1|\
323 HDSP_spdifFrequency2|\
324 HDSP_spdifFrequency3)
321 325
322#define HDSP_spdifFrequency32KHz (HDSP_spdifFrequency0) 326#define HDSP_spdifFrequency32KHz (HDSP_spdifFrequency0)
323#define HDSP_spdifFrequency44_1KHz (HDSP_spdifFrequency1) 327#define HDSP_spdifFrequency44_1KHz (HDSP_spdifFrequency1)
@@ -328,7 +332,9 @@ MODULE_FIRMWARE("digiface_firmware_rev11.bin");
328#define HDSP_spdifFrequency96KHz (HDSP_spdifFrequency2|HDSP_spdifFrequency1) 332#define HDSP_spdifFrequency96KHz (HDSP_spdifFrequency2|HDSP_spdifFrequency1)
329 333
330/* This is for H9632 cards */ 334/* This is for H9632 cards */
331#define HDSP_spdifFrequency128KHz HDSP_spdifFrequencyMask 335#define HDSP_spdifFrequency128KHz (HDSP_spdifFrequency0|\
336 HDSP_spdifFrequency1|\
337 HDSP_spdifFrequency2)
332#define HDSP_spdifFrequency176_4KHz HDSP_spdifFrequency3 338#define HDSP_spdifFrequency176_4KHz HDSP_spdifFrequency3
333#define HDSP_spdifFrequency192KHz (HDSP_spdifFrequency3|HDSP_spdifFrequency0) 339#define HDSP_spdifFrequency192KHz (HDSP_spdifFrequency3|HDSP_spdifFrequency0)
334 340
@@ -885,28 +891,15 @@ static int snd_hdsp_use_is_exclusive(struct hdsp *hdsp)
885 return ret; 891 return ret;
886} 892}
887 893
888static int hdsp_external_sample_rate (struct hdsp *hdsp)
889{
890 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
891 unsigned int rate_bits = status2 & HDSP_systemFrequencyMask;
892
893 switch (rate_bits) {
894 case HDSP_systemFrequency32: return 32000;
895 case HDSP_systemFrequency44_1: return 44100;
896 case HDSP_systemFrequency48: return 48000;
897 case HDSP_systemFrequency64: return 64000;
898 case HDSP_systemFrequency88_2: return 88200;
899 case HDSP_systemFrequency96: return 96000;
900 default:
901 return 0;
902 }
903}
904
905static int hdsp_spdif_sample_rate(struct hdsp *hdsp) 894static int hdsp_spdif_sample_rate(struct hdsp *hdsp)
906{ 895{
907 unsigned int status = hdsp_read(hdsp, HDSP_statusRegister); 896 unsigned int status = hdsp_read(hdsp, HDSP_statusRegister);
908 unsigned int rate_bits = (status & HDSP_spdifFrequencyMask); 897 unsigned int rate_bits = (status & HDSP_spdifFrequencyMask);
909 898
899 /* For the 9632, the mask is different */
900 if (hdsp->io_type == H9632)
901 rate_bits = (status & HDSP_spdifFrequencyMask_9632);
902
910 if (status & HDSP_SPDIFErrorFlag) 903 if (status & HDSP_SPDIFErrorFlag)
911 return 0; 904 return 0;
912 905
@@ -933,6 +926,31 @@ static int hdsp_spdif_sample_rate(struct hdsp *hdsp)
933 return 0; 926 return 0;
934} 927}
935 928
929static int hdsp_external_sample_rate(struct hdsp *hdsp)
930{
931 unsigned int status2 = hdsp_read(hdsp, HDSP_status2Register);
932 unsigned int rate_bits = status2 & HDSP_systemFrequencyMask;
933
934 /* For the 9632 card, there seems to be no bit for indicating external
935 * sample rate greater than 96kHz. The card reports the corresponding
936 * single speed. So the best means seems to get spdif rate when
937 * autosync reference is spdif */
938 if (hdsp->io_type == H9632 &&
939 hdsp_autosync_ref(hdsp) == HDSP_AUTOSYNC_FROM_SPDIF)
940 return hdsp_spdif_sample_rate(hdsp);
941
942 switch (rate_bits) {
943 case HDSP_systemFrequency32: return 32000;
944 case HDSP_systemFrequency44_1: return 44100;
945 case HDSP_systemFrequency48: return 48000;
946 case HDSP_systemFrequency64: return 64000;
947 case HDSP_systemFrequency88_2: return 88200;
948 case HDSP_systemFrequency96: return 96000;
949 default:
950 return 0;
951 }
952}
953
936static void hdsp_compute_period_size(struct hdsp *hdsp) 954static void hdsp_compute_period_size(struct hdsp *hdsp)
937{ 955{
938 hdsp->period_bytes = 1 << ((hdsp_decode_latency(hdsp->control_register) + 8)); 956 hdsp->period_bytes = 1 << ((hdsp_decode_latency(hdsp->control_register) + 8));
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
index 9a19ae6a64d9..ab423bc82342 100644
--- a/sound/pci/rme9652/hdspm.c
+++ b/sound/pci/rme9652/hdspm.c
@@ -540,7 +540,8 @@ static void hdspm_set_sgbuf(struct hdspm * hdspm, struct snd_sg_buf *sgbuf,
540 540
541static inline int HDSPM_bit2freq(int n) 541static inline int HDSPM_bit2freq(int n)
542{ 542{
543 static int bit2freq_tab[] = { 0, 32000, 44100, 48000, 64000, 88200, 543 static const int bit2freq_tab[] = {
544 0, 32000, 44100, 48000, 64000, 88200,
544 96000, 128000, 176400, 192000 }; 545 96000, 128000, 176400, 192000 };
545 if (n < 1 || n > 9) 546 if (n < 1 || n > 9)
546 return 0; 547 return 0;
@@ -582,7 +583,7 @@ static inline int hdspm_read_pb_gain(struct hdspm * hdspm, unsigned int chan,
582 return hdspm->mixer->ch[chan].pb[pb]; 583 return hdspm->mixer->ch[chan].pb[pb];
583} 584}
584 585
585static inline int hdspm_write_in_gain(struct hdspm * hdspm, unsigned int chan, 586static int hdspm_write_in_gain(struct hdspm *hdspm, unsigned int chan,
586 unsigned int in, unsigned short data) 587 unsigned int in, unsigned short data)
587{ 588{
588 if (chan >= HDSPM_MIXER_CHANNELS || in >= HDSPM_MIXER_CHANNELS) 589 if (chan >= HDSPM_MIXER_CHANNELS || in >= HDSPM_MIXER_CHANNELS)
@@ -595,7 +596,7 @@ static inline int hdspm_write_in_gain(struct hdspm * hdspm, unsigned int chan,
595 return 0; 596 return 0;
596} 597}
597 598
598static inline int hdspm_write_pb_gain(struct hdspm * hdspm, unsigned int chan, 599static int hdspm_write_pb_gain(struct hdspm *hdspm, unsigned int chan,
599 unsigned int pb, unsigned short data) 600 unsigned int pb, unsigned short data)
600{ 601{
601 if (chan >= HDSPM_MIXER_CHANNELS || pb >= HDSPM_MIXER_CHANNELS) 602 if (chan >= HDSPM_MIXER_CHANNELS || pb >= HDSPM_MIXER_CHANNELS)
@@ -621,7 +622,7 @@ static inline void snd_hdspm_enable_out(struct hdspm * hdspm, int i, int v)
621} 622}
622 623
623/* check if same process is writing and reading */ 624/* check if same process is writing and reading */
624static inline int snd_hdspm_use_is_exclusive(struct hdspm * hdspm) 625static int snd_hdspm_use_is_exclusive(struct hdspm *hdspm)
625{ 626{
626 unsigned long flags; 627 unsigned long flags;
627 int ret = 1; 628 int ret = 1;
@@ -636,7 +637,7 @@ static inline int snd_hdspm_use_is_exclusive(struct hdspm * hdspm)
636} 637}
637 638
638/* check for external sample rate */ 639/* check for external sample rate */
639static inline int hdspm_external_sample_rate(struct hdspm * hdspm) 640static int hdspm_external_sample_rate(struct hdspm *hdspm)
640{ 641{
641 if (hdspm->is_aes32) { 642 if (hdspm->is_aes32) {
642 unsigned int status2 = hdspm_read(hdspm, HDSPM_statusRegister2); 643 unsigned int status2 = hdspm_read(hdspm, HDSPM_statusRegister2);
@@ -787,7 +788,7 @@ static inline void hdspm_stop_audio(struct hdspm * s)
787} 788}
788 789
789/* should I silence all or only opened ones ? doit all for first even is 4MB*/ 790/* should I silence all or only opened ones ? doit all for first even is 4MB*/
790static inline void hdspm_silence_playback(struct hdspm * hdspm) 791static void hdspm_silence_playback(struct hdspm *hdspm)
791{ 792{
792 int i; 793 int i;
793 int n = hdspm->period_bytes; 794 int n = hdspm->period_bytes;
@@ -1028,9 +1029,9 @@ static inline void snd_hdspm_midi_write_byte (struct hdspm *hdspm, int id,
1028{ 1029{
1029 /* the hardware already does the relevant bit-mask with 0xff */ 1030 /* the hardware already does the relevant bit-mask with 0xff */
1030 if (id) 1031 if (id)
1031 return hdspm_write(hdspm, HDSPM_midiDataOut1, val); 1032 hdspm_write(hdspm, HDSPM_midiDataOut1, val);
1032 else 1033 else
1033 return hdspm_write(hdspm, HDSPM_midiDataOut0, val); 1034 hdspm_write(hdspm, HDSPM_midiDataOut0, val);
1034} 1035}
1035 1036
1036static inline int snd_hdspm_midi_input_available (struct hdspm *hdspm, int id) 1037static inline int snd_hdspm_midi_input_available (struct hdspm *hdspm, int id)
@@ -1057,7 +1058,7 @@ static inline int snd_hdspm_midi_output_possible (struct hdspm *hdspm, int id)
1057 return 0; 1058 return 0;
1058} 1059}
1059 1060
1060static inline void snd_hdspm_flush_midi_input (struct hdspm *hdspm, int id) 1061static void snd_hdspm_flush_midi_input(struct hdspm *hdspm, int id)
1061{ 1062{
1062 while (snd_hdspm_midi_input_available (hdspm, id)) 1063 while (snd_hdspm_midi_input_available (hdspm, id))
1063 snd_hdspm_midi_read_byte (hdspm, id); 1064 snd_hdspm_midi_read_byte (hdspm, id);
diff --git a/sound/pci/sis7019.c b/sound/pci/sis7019.c
index 742f1180c39e..df2007e3be7c 100644
--- a/sound/pci/sis7019.c
+++ b/sound/pci/sis7019.c
@@ -1194,7 +1194,6 @@ static int sis_suspend(struct pci_dev *pci, pm_message_t state)
1194 /* snd_pcm_suspend_all() stopped all channels, so we're quiescent. 1194 /* snd_pcm_suspend_all() stopped all channels, so we're quiescent.
1195 */ 1195 */
1196 if (sis->irq >= 0) { 1196 if (sis->irq >= 0) {
1197 synchronize_irq(sis->irq);
1198 free_irq(sis->irq, sis); 1197 free_irq(sis->irq, sis);
1199 sis->irq = -1; 1198 sis->irq = -1;
1200 } 1199 }
diff --git a/sound/pci/trident/trident_main.c b/sound/pci/trident/trident_main.c
index 71138ff9b310..bbcee2c09ae4 100644
--- a/sound/pci/trident/trident_main.c
+++ b/sound/pci/trident/trident_main.c
@@ -3676,6 +3676,8 @@ static int snd_trident_free(struct snd_trident *trident)
3676 else if (trident->device == TRIDENT_DEVICE_ID_SI7018) { 3676 else if (trident->device == TRIDENT_DEVICE_ID_SI7018) {
3677 outl(0, TRID_REG(trident, SI_SERIAL_INTF_CTRL)); 3677 outl(0, TRID_REG(trident, SI_SERIAL_INTF_CTRL));
3678 } 3678 }
3679 if (trident->irq >= 0)
3680 free_irq(trident->irq, trident);
3679 if (trident->tlb.buffer.area) { 3681 if (trident->tlb.buffer.area) {
3680 outl(0, TRID_REG(trident, NX_TLBC)); 3682 outl(0, TRID_REG(trident, NX_TLBC));
3681 if (trident->tlb.memhdr) 3683 if (trident->tlb.memhdr)
@@ -3685,8 +3687,6 @@ static int snd_trident_free(struct snd_trident *trident)
3685 vfree(trident->tlb.shadow_entries); 3687 vfree(trident->tlb.shadow_entries);
3686 snd_dma_free_pages(&trident->tlb.buffer); 3688 snd_dma_free_pages(&trident->tlb.buffer);
3687 } 3689 }
3688 if (trident->irq >= 0)
3689 free_irq(trident->irq, trident);
3690 pci_release_regions(trident->pci); 3690 pci_release_regions(trident->pci);
3691 pci_disable_device(trident->pci); 3691 pci_disable_device(trident->pci);
3692 kfree(trident); 3692 kfree(trident);
diff --git a/sound/pci/via82xx.c b/sound/pci/via82xx.c
index a756be661f9a..b585cc3e4c47 100644
--- a/sound/pci/via82xx.c
+++ b/sound/pci/via82xx.c
@@ -2236,7 +2236,7 @@ static int snd_via82xx_free(struct via82xx *chip)
2236 /* disable interrupts */ 2236 /* disable interrupts */
2237 for (i = 0; i < chip->num_devs; i++) 2237 for (i = 0; i < chip->num_devs; i++)
2238 snd_via82xx_channel_reset(chip, &chip->devs[i]); 2238 snd_via82xx_channel_reset(chip, &chip->devs[i]);
2239 synchronize_irq(chip->irq); 2239
2240 if (chip->irq >= 0) 2240 if (chip->irq >= 0)
2241 free_irq(chip->irq, chip); 2241 free_irq(chip->irq, chip);
2242 __end_hw: 2242 __end_hw:
diff --git a/sound/pci/via82xx_modem.c b/sound/pci/via82xx_modem.c
index f5df1c79bee1..31f64ee39882 100644
--- a/sound/pci/via82xx_modem.c
+++ b/sound/pci/via82xx_modem.c
@@ -1075,7 +1075,7 @@ static int snd_via82xx_free(struct via82xx_modem *chip)
1075 /* disable interrupts */ 1075 /* disable interrupts */
1076 for (i = 0; i < chip->num_devs; i++) 1076 for (i = 0; i < chip->num_devs; i++)
1077 snd_via82xx_channel_reset(chip, &chip->devs[i]); 1077 snd_via82xx_channel_reset(chip, &chip->devs[i]);
1078 synchronize_irq(chip->irq); 1078
1079 __end_hw: 1079 __end_hw:
1080 if (chip->irq >= 0) 1080 if (chip->irq >= 0)
1081 free_irq(chip->irq, chip); 1081 free_irq(chip->irq, chip);
diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
index 42c1eb7d35f5..29b3056c5109 100644
--- a/sound/pci/ymfpci/ymfpci_main.c
+++ b/sound/pci/ymfpci/ymfpci_main.c
@@ -2249,6 +2249,8 @@ static int snd_ymfpci_free(struct snd_ymfpci *chip)
2249#ifdef CONFIG_PM 2249#ifdef CONFIG_PM
2250 vfree(chip->saved_regs); 2250 vfree(chip->saved_regs);
2251#endif 2251#endif
2252 if (chip->irq >= 0)
2253 free_irq(chip->irq, chip);
2252 release_and_free_resource(chip->mpu_res); 2254 release_and_free_resource(chip->mpu_res);
2253 release_and_free_resource(chip->fm_res); 2255 release_and_free_resource(chip->fm_res);
2254 snd_ymfpci_free_gameport(chip); 2256 snd_ymfpci_free_gameport(chip);
@@ -2257,8 +2259,6 @@ static int snd_ymfpci_free(struct snd_ymfpci *chip)
2257 if (chip->work_ptr.area) 2259 if (chip->work_ptr.area)
2258 snd_dma_free_pages(&chip->work_ptr); 2260 snd_dma_free_pages(&chip->work_ptr);
2259 2261
2260 if (chip->irq >= 0)
2261 free_irq(chip->irq, chip);
2262 release_and_free_resource(chip->res_reg_area); 2262 release_and_free_resource(chip->res_reg_area);
2263 2263
2264 pci_write_config_word(chip->pci, 0x40, chip->old_legacy_ctrl); 2264 pci_write_config_word(chip->pci, 0x40, chip->old_legacy_ctrl);
diff --git a/sound/ppc/awacs.c b/sound/ppc/awacs.c
index 8441e780df00..566a6d0daf4a 100644
--- a/sound/ppc/awacs.c
+++ b/sound/ppc/awacs.c
@@ -141,7 +141,7 @@ static int snd_pmac_awacs_info_volume(struct snd_kcontrol *kcontrol,
141 uinfo->value.integer.max = 15; 141 uinfo->value.integer.max = 15;
142 return 0; 142 return 0;
143} 143}
144 144
145static int snd_pmac_awacs_get_volume(struct snd_kcontrol *kcontrol, 145static int snd_pmac_awacs_get_volume(struct snd_kcontrol *kcontrol,
146 struct snd_ctl_elem_value *ucontrol) 146 struct snd_ctl_elem_value *ucontrol)
147{ 147{
@@ -267,7 +267,8 @@ static int snd_pmac_awacs_put_switch(struct snd_kcontrol *kcontrol,
267static void awacs_set_cuda(int reg, int val) 267static void awacs_set_cuda(int reg, int val)
268{ 268{
269 struct adb_request req; 269 struct adb_request req;
270 cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC, 0x8a, reg, val); 270 cuda_request(&req, NULL, 5, CUDA_PACKET, CUDA_GET_SET_IIC, 0x8a,
271 reg, val);
271 while (! req.complete) 272 while (! req.complete)
272 cuda_poll(); 273 cuda_poll();
273} 274}
@@ -289,11 +290,11 @@ static void awacs_amp_set_tone(struct awacs_amp *amp, int bass, int treble)
289/* 290/*
290 * vol = 0 - 31 (attenuation), 32 = mute bit, stereo 291 * vol = 0 - 31 (attenuation), 32 = mute bit, stereo
291 */ 292 */
292static int awacs_amp_set_vol(struct awacs_amp *amp, int index, int lvol, int rvol, 293static int awacs_amp_set_vol(struct awacs_amp *amp, int index,
293 int do_check) 294 int lvol, int rvol, int do_check)
294{ 295{
295 if (do_check && amp->amp_vol[index][0] == lvol && 296 if (do_check && amp->amp_vol[index][0] == lvol &&
296 amp->amp_vol[index][1] == rvol) 297 amp->amp_vol[index][1] == rvol)
297 return 0; 298 return 0;
298 awacs_set_cuda(3 + index, lvol); 299 awacs_set_cuda(3 + index, lvol);
299 awacs_set_cuda(5 + index, rvol); 300 awacs_set_cuda(5 + index, rvol);
@@ -337,7 +338,7 @@ static int snd_pmac_awacs_info_volume_amp(struct snd_kcontrol *kcontrol,
337 uinfo->value.integer.max = 31; 338 uinfo->value.integer.max = 31;
338 return 0; 339 return 0;
339} 340}
340 341
341static int snd_pmac_awacs_get_volume_amp(struct snd_kcontrol *kcontrol, 342static int snd_pmac_awacs_get_volume_amp(struct snd_kcontrol *kcontrol,
342 struct snd_ctl_elem_value *ucontrol) 343 struct snd_ctl_elem_value *ucontrol)
343{ 344{
@@ -361,8 +362,10 @@ static int snd_pmac_awacs_put_volume_amp(struct snd_kcontrol *kcontrol,
361 snd_assert(amp, return -EINVAL); 362 snd_assert(amp, return -EINVAL);
362 snd_assert(index >= 0 && index <= 1, return -EINVAL); 363 snd_assert(index >= 0 && index <= 1, return -EINVAL);
363 364
364 vol[0] = (31 - (ucontrol->value.integer.value[0] & 31)) | (amp->amp_vol[index][0] & 32); 365 vol[0] = (31 - (ucontrol->value.integer.value[0] & 31))
365 vol[1] = (31 - (ucontrol->value.integer.value[1] & 31)) | (amp->amp_vol[index][1] & 32); 366 | (amp->amp_vol[index][0] & 32);
367 vol[1] = (31 - (ucontrol->value.integer.value[1] & 31))
368 | (amp->amp_vol[index][1] & 32);
366 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1); 369 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
367} 370}
368 371
@@ -374,8 +377,10 @@ static int snd_pmac_awacs_get_switch_amp(struct snd_kcontrol *kcontrol,
374 struct awacs_amp *amp = chip->mixer_data; 377 struct awacs_amp *amp = chip->mixer_data;
375 snd_assert(amp, return -EINVAL); 378 snd_assert(amp, return -EINVAL);
376 snd_assert(index >= 0 && index <= 1, return -EINVAL); 379 snd_assert(index >= 0 && index <= 1, return -EINVAL);
377 ucontrol->value.integer.value[0] = (amp->amp_vol[index][0] & 32) ? 0 : 1; 380 ucontrol->value.integer.value[0] = (amp->amp_vol[index][0] & 32)
378 ucontrol->value.integer.value[1] = (amp->amp_vol[index][1] & 32) ? 0 : 1; 381 ? 0 : 1;
382 ucontrol->value.integer.value[1] = (amp->amp_vol[index][1] & 32)
383 ? 0 : 1;
379 return 0; 384 return 0;
380} 385}
381 386
@@ -389,8 +394,10 @@ static int snd_pmac_awacs_put_switch_amp(struct snd_kcontrol *kcontrol,
389 snd_assert(amp, return -EINVAL); 394 snd_assert(amp, return -EINVAL);
390 snd_assert(index >= 0 && index <= 1, return -EINVAL); 395 snd_assert(index >= 0 && index <= 1, return -EINVAL);
391 396
392 vol[0] = (ucontrol->value.integer.value[0] ? 0 : 32) | (amp->amp_vol[index][0] & 31); 397 vol[0] = (ucontrol->value.integer.value[0] ? 0 : 32)
393 vol[1] = (ucontrol->value.integer.value[1] ? 0 : 32) | (amp->amp_vol[index][1] & 31); 398 | (amp->amp_vol[index][0] & 31);
399 vol[1] = (ucontrol->value.integer.value[1] ? 0 : 32)
400 | (amp->amp_vol[index][1] & 31);
394 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1); 401 return awacs_amp_set_vol(amp, index, vol[0], vol[1], 1);
395} 402}
396 403
@@ -403,7 +410,7 @@ static int snd_pmac_awacs_info_tone_amp(struct snd_kcontrol *kcontrol,
403 uinfo->value.integer.max = 14; 410 uinfo->value.integer.max = 14;
404 return 0; 411 return 0;
405} 412}
406 413
407static int snd_pmac_awacs_get_tone_amp(struct snd_kcontrol *kcontrol, 414static int snd_pmac_awacs_get_tone_amp(struct snd_kcontrol *kcontrol,
408 struct snd_ctl_elem_value *ucontrol) 415 struct snd_ctl_elem_value *ucontrol)
409{ 416{
@@ -445,7 +452,7 @@ static int snd_pmac_awacs_info_master_amp(struct snd_kcontrol *kcontrol,
445 uinfo->value.integer.max = 99; 452 uinfo->value.integer.max = 99;
446 return 0; 453 return 0;
447} 454}
448 455
449static int snd_pmac_awacs_get_master_amp(struct snd_kcontrol *kcontrol, 456static int snd_pmac_awacs_get_master_amp(struct snd_kcontrol *kcontrol,
450 struct snd_ctl_elem_value *ucontrol) 457 struct snd_ctl_elem_value *ucontrol)
451{ 458{
@@ -544,7 +551,7 @@ static int snd_pmac_screamer_mic_boost_info(struct snd_kcontrol *kcontrol,
544 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 551 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
545 uinfo->count = 1; 552 uinfo->count = 1;
546 uinfo->value.integer.min = 0; 553 uinfo->value.integer.min = 0;
547 uinfo->value.integer.max = 2; 554 uinfo->value.integer.max = 3;
548 return 0; 555 return 0;
549} 556}
550 557
@@ -552,16 +559,14 @@ static int snd_pmac_screamer_mic_boost_get(struct snd_kcontrol *kcontrol,
552 struct snd_ctl_elem_value *ucontrol) 559 struct snd_ctl_elem_value *ucontrol)
553{ 560{
554 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 561 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
555 int val; 562 int val = 0;
556 unsigned long flags; 563 unsigned long flags;
557 564
558 spin_lock_irqsave(&chip->reg_lock, flags); 565 spin_lock_irqsave(&chip->reg_lock, flags);
559 if (chip->awacs_reg[6] & MASK_MIC_BOOST) 566 if (chip->awacs_reg[6] & MASK_MIC_BOOST)
560 val = 2; 567 val |= 2;
561 else if (chip->awacs_reg[0] & MASK_GAINLINE) 568 if (chip->awacs_reg[0] & MASK_GAINLINE)
562 val = 1; 569 val |= 1;
563 else
564 val = 0;
565 spin_unlock_irqrestore(&chip->reg_lock, flags); 570 spin_unlock_irqrestore(&chip->reg_lock, flags);
566 ucontrol->value.integer.value[0] = val; 571 ucontrol->value.integer.value[0] = val;
567 return 0; 572 return 0;
@@ -578,11 +583,10 @@ static int snd_pmac_screamer_mic_boost_put(struct snd_kcontrol *kcontrol,
578 spin_lock_irqsave(&chip->reg_lock, flags); 583 spin_lock_irqsave(&chip->reg_lock, flags);
579 val0 = chip->awacs_reg[0] & ~MASK_GAINLINE; 584 val0 = chip->awacs_reg[0] & ~MASK_GAINLINE;
580 val6 = chip->awacs_reg[6] & ~MASK_MIC_BOOST; 585 val6 = chip->awacs_reg[6] & ~MASK_MIC_BOOST;
581 if (ucontrol->value.integer.value[0] > 0) { 586 if (ucontrol->value.integer.value[0] & 1)
582 val0 |= MASK_GAINLINE; 587 val0 |= MASK_GAINLINE;
583 if (ucontrol->value.integer.value[0] > 1) 588 if (ucontrol->value.integer.value[0] & 2)
584 val6 |= MASK_MIC_BOOST; 589 val6 |= MASK_MIC_BOOST;
585 }
586 if (val0 != chip->awacs_reg[0]) { 590 if (val0 != chip->awacs_reg[0]) {
587 snd_pmac_awacs_write_reg(chip, 0, val0); 591 snd_pmac_awacs_write_reg(chip, 0, val0);
588 changed = 1; 592 changed = 1;
@@ -599,9 +603,32 @@ static int snd_pmac_screamer_mic_boost_put(struct snd_kcontrol *kcontrol,
599 * lists of mixer elements 603 * lists of mixer elements
600 */ 604 */
601static struct snd_kcontrol_new snd_pmac_awacs_mixers[] __initdata = { 605static struct snd_kcontrol_new snd_pmac_awacs_mixers[] __initdata = {
602 AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
603 AWACS_SWITCH("Master Capture Switch", 1, SHIFT_LOOPTHRU, 0), 606 AWACS_SWITCH("Master Capture Switch", 1, SHIFT_LOOPTHRU, 0),
604 AWACS_VOLUME("Capture Volume", 0, 4, 0), 607 AWACS_VOLUME("Master Capture Volume", 0, 4, 0),
608/* AWACS_SWITCH("Unknown Playback Switch", 6, SHIFT_PAROUT0, 0), */
609};
610
611static struct snd_kcontrol_new snd_pmac_screamer_mixers_beige[] __initdata = {
612 AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
613 AWACS_VOLUME("Play-through Playback Volume", 5, 6, 1),
614 AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
615 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_LINE, 0),
616};
617
618static struct snd_kcontrol_new snd_pmac_screamer_mixers_imac[] __initdata = {
619 AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
620 AWACS_VOLUME("Master Playback Volume", 5, 6, 1),
621 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
622};
623
624static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac7500[] __initdata = {
625 AWACS_VOLUME("Line out Playback Volume", 2, 6, 1),
626 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
627 AWACS_SWITCH("Line Capture Switch", 0, SHIFT_MUX_MIC, 0),
628};
629
630static struct snd_kcontrol_new snd_pmac_awacs_mixers_pmac[] __initdata = {
631 AWACS_VOLUME("Master Playback Volume", 2, 6, 1),
605 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0), 632 AWACS_SWITCH("CD Capture Switch", 0, SHIFT_MUX_CD, 0),
606}; 633};
607 634
@@ -621,35 +648,61 @@ static struct snd_kcontrol_new snd_pmac_screamer_mixers2[] __initdata = {
621static struct snd_kcontrol_new snd_pmac_awacs_master_sw __initdata = 648static struct snd_kcontrol_new snd_pmac_awacs_master_sw __initdata =
622AWACS_SWITCH("Master Playback Switch", 1, SHIFT_HDMUTE, 1); 649AWACS_SWITCH("Master Playback Switch", 1, SHIFT_HDMUTE, 1);
623 650
651static struct snd_kcontrol_new snd_pmac_awacs_master_sw_imac __initdata =
652AWACS_SWITCH("Line out Playback Switch", 1, SHIFT_HDMUTE, 1);
653
624static struct snd_kcontrol_new snd_pmac_awacs_mic_boost[] __initdata = { 654static struct snd_kcontrol_new snd_pmac_awacs_mic_boost[] __initdata = {
625 AWACS_SWITCH("Mic Boost", 0, SHIFT_GAINLINE, 0), 655 AWACS_SWITCH("Mic Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
626}; 656};
627 657
628static struct snd_kcontrol_new snd_pmac_screamer_mic_boost[] __initdata = { 658static struct snd_kcontrol_new snd_pmac_screamer_mic_boost[] __initdata = {
629 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER, 659 { .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
630 .name = "Mic Boost", 660 .name = "Mic Boost Capture Volume",
631 .info = snd_pmac_screamer_mic_boost_info, 661 .info = snd_pmac_screamer_mic_boost_info,
632 .get = snd_pmac_screamer_mic_boost_get, 662 .get = snd_pmac_screamer_mic_boost_get,
633 .put = snd_pmac_screamer_mic_boost_put, 663 .put = snd_pmac_screamer_mic_boost_put,
634 }, 664 },
635}; 665};
636 666
667static struct snd_kcontrol_new snd_pmac_awacs_mic_boost_pmac7500[] __initdata =
668{
669 AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
670};
671
672static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_beige[] __initdata =
673{
674 AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
675 AWACS_SWITCH("CD Boost Capture Switch", 6, SHIFT_MIC_BOOST, 0),
676};
677
678static struct snd_kcontrol_new snd_pmac_screamer_mic_boost_imac[] __initdata =
679{
680 AWACS_SWITCH("Line Boost Capture Switch", 0, SHIFT_GAINLINE, 0),
681 AWACS_SWITCH("Mic Boost Capture Switch", 6, SHIFT_MIC_BOOST, 0),
682};
683
637static struct snd_kcontrol_new snd_pmac_awacs_speaker_vol[] __initdata = { 684static struct snd_kcontrol_new snd_pmac_awacs_speaker_vol[] __initdata = {
638 AWACS_VOLUME("PC Speaker Playback Volume", 4, 6, 1), 685 AWACS_VOLUME("PC Speaker Playback Volume", 4, 6, 1),
639}; 686};
687
640static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw __initdata = 688static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw __initdata =
641AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_SPKMUTE, 1); 689AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_SPKMUTE, 1);
642 690
691static struct snd_kcontrol_new snd_pmac_awacs_speaker_sw_imac __initdata =
692AWACS_SWITCH("PC Speaker Playback Switch", 1, SHIFT_PAROUT1, 0);
693
643 694
644/* 695/*
645 * add new mixer elements to the card 696 * add new mixer elements to the card
646 */ 697 */
647static int build_mixers(struct snd_pmac *chip, int nums, struct snd_kcontrol_new *mixers) 698static int build_mixers(struct snd_pmac *chip, int nums,
699 struct snd_kcontrol_new *mixers)
648{ 700{
649 int i, err; 701 int i, err;
650 702
651 for (i = 0; i < nums; i++) { 703 for (i = 0; i < nums; i++) {
652 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&mixers[i], chip))) < 0) 704 err = snd_ctl_add(chip->card, snd_ctl_new1(&mixers[i], chip));
705 if (err < 0)
653 return err; 706 return err;
654 } 707 }
655 return 0; 708 return 0;
@@ -699,8 +752,10 @@ static void snd_pmac_awacs_resume(struct snd_pmac *chip)
699#ifdef PMAC_AMP_AVAIL 752#ifdef PMAC_AMP_AVAIL
700 if (chip->mixer_data) { 753 if (chip->mixer_data) {
701 struct awacs_amp *amp = chip->mixer_data; 754 struct awacs_amp *amp = chip->mixer_data;
702 awacs_amp_set_vol(amp, 0, amp->amp_vol[0][0], amp->amp_vol[0][1], 0); 755 awacs_amp_set_vol(amp, 0,
703 awacs_amp_set_vol(amp, 1, amp->amp_vol[1][0], amp->amp_vol[1][1], 0); 756 amp->amp_vol[0][0], amp->amp_vol[0][1], 0);
757 awacs_amp_set_vol(amp, 1,
758 amp->amp_vol[1][0], amp->amp_vol[1][1], 0);
704 awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]); 759 awacs_amp_set_tone(amp, amp->amp_tone[0], amp->amp_tone[1]);
705 awacs_amp_set_master(amp, amp->amp_master); 760 awacs_amp_set_master(amp, amp->amp_master);
706 } 761 }
@@ -708,6 +763,14 @@ static void snd_pmac_awacs_resume(struct snd_pmac *chip)
708} 763}
709#endif /* CONFIG_PM */ 764#endif /* CONFIG_PM */
710 765
766#define IS_PM7500 (machine_is_compatible("AAPL,7500"))
767#define IS_BEIGE (machine_is_compatible("AAPL,Gossamer"))
768#define IS_IMAC (machine_is_compatible("PowerMac2,1") \
769 || machine_is_compatible("PowerMac2,2") \
770 || machine_is_compatible("PowerMac4,1"))
771
772static int imac;
773
711#ifdef PMAC_SUPPORT_AUTOMUTE 774#ifdef PMAC_SUPPORT_AUTOMUTE
712/* 775/*
713 * auto-mute stuffs 776 * auto-mute stuffs
@@ -750,9 +813,16 @@ static void snd_pmac_awacs_update_automute(struct snd_pmac *chip, int do_notify)
750 } else 813 } else
751#endif 814#endif
752 { 815 {
753 int reg = chip->awacs_reg[1] | (MASK_HDMUTE|MASK_SPKMUTE); 816 int reg = chip->awacs_reg[1]
817 | (MASK_HDMUTE | MASK_SPKMUTE);
818 if (imac) {
819 reg &= ~MASK_SPKMUTE;
820 reg &= ~MASK_PAROUT1;
821 }
754 if (snd_pmac_awacs_detect_headphone(chip)) 822 if (snd_pmac_awacs_detect_headphone(chip))
755 reg &= ~MASK_HDMUTE; 823 reg &= ~MASK_HDMUTE;
824 else if (imac)
825 reg |= MASK_PAROUT1;
756 else 826 else
757 reg &= ~MASK_SPKMUTE; 827 reg &= ~MASK_SPKMUTE;
758 if (do_notify && reg == chip->awacs_reg[1]) 828 if (do_notify && reg == chip->awacs_reg[1])
@@ -778,8 +848,11 @@ static void snd_pmac_awacs_update_automute(struct snd_pmac *chip, int do_notify)
778int __init 848int __init
779snd_pmac_awacs_init(struct snd_pmac *chip) 849snd_pmac_awacs_init(struct snd_pmac *chip)
780{ 850{
851 int pm7500 = IS_PM7500;
852 int beige = IS_BEIGE;
781 int err, vol; 853 int err, vol;
782 854
855 imac = IS_IMAC;
783 /* looks like MASK_GAINLINE triggers something, so we set here 856 /* looks like MASK_GAINLINE triggers something, so we set here
784 * as start-up 857 * as start-up
785 */ 858 */
@@ -787,7 +860,7 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
787 chip->awacs_reg[1] = MASK_CMUTE | MASK_AMUTE; 860 chip->awacs_reg[1] = MASK_CMUTE | MASK_AMUTE;
788 /* FIXME: Only machines with external SRS module need MASK_PAROUT */ 861 /* FIXME: Only machines with external SRS module need MASK_PAROUT */
789 if (chip->has_iic || chip->device_id == 0x5 || 862 if (chip->has_iic || chip->device_id == 0x5 ||
790 /*chip->_device_id == 0x8 || */ 863 /* chip->_device_id == 0x8 || */
791 chip->device_id == 0xb) 864 chip->device_id == 0xb)
792 chip->awacs_reg[1] |= MASK_PAROUT; 865 chip->awacs_reg[1] |= MASK_PAROUT;
793 /* get default volume from nvram */ 866 /* get default volume from nvram */
@@ -798,8 +871,10 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
798 chip->awacs_reg[2] = vol; 871 chip->awacs_reg[2] = vol;
799 chip->awacs_reg[4] = vol; 872 chip->awacs_reg[4] = vol;
800 if (chip->model == PMAC_SCREAMER) { 873 if (chip->model == PMAC_SCREAMER) {
801 chip->awacs_reg[5] = vol; /* FIXME: screamer has loopthru vol control */ 874 /* FIXME: screamer has loopthru vol control */
802 chip->awacs_reg[6] = MASK_MIC_BOOST; /* FIXME: maybe should be vol << 3 for PCMCIA speaker */ 875 chip->awacs_reg[5] = vol;
876 /* FIXME: maybe should be vol << 3 for PCMCIA speaker */
877 chip->awacs_reg[6] = MASK_MIC_BOOST;
803 chip->awacs_reg[7] = 0; 878 chip->awacs_reg[7] = 0;
804 } 879 }
805 880
@@ -815,7 +890,8 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
815 return -ENOMEM; 890 return -ENOMEM;
816 chip->mixer_data = amp; 891 chip->mixer_data = amp;
817 chip->mixer_free = awacs_amp_free; 892 chip->mixer_free = awacs_amp_free;
818 awacs_amp_set_vol(amp, 0, 63, 63, 0); /* mute and zero vol */ 893 /* mute and zero vol */
894 awacs_amp_set_vol(amp, 0, 63, 63, 0);
819 awacs_amp_set_vol(amp, 1, 63, 63, 0); 895 awacs_amp_set_vol(amp, 1, 63, 63, 0);
820 awacs_amp_set_tone(amp, 7, 7); /* 0 dB */ 896 awacs_amp_set_tone(amp, 7, 7); /* 0 dB */
821 awacs_amp_set_master(amp, 79); /* 0 dB */ 897 awacs_amp_set_master(amp, 79); /* 0 dB */
@@ -826,20 +902,25 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
826 /* set headphone-jack detection bit */ 902 /* set headphone-jack detection bit */
827 switch (chip->model) { 903 switch (chip->model) {
828 case PMAC_AWACS: 904 case PMAC_AWACS:
829 chip->hp_stat_mask = 0x04; 905 chip->hp_stat_mask = pm7500 ? MASK_HDPCONN
906 : MASK_LOCONN;
830 break; 907 break;
831 case PMAC_SCREAMER: 908 case PMAC_SCREAMER:
832 switch (chip->device_id) { 909 switch (chip->device_id) {
833 case 0x08: 910 case 0x08:
834 /* 1 = side jack, 2 = front jack */ 911 case 0x0B:
835 chip->hp_stat_mask = 0x03; 912 chip->hp_stat_mask = imac
913 ? MASK_LOCONN_IMAC |
914 MASK_HDPLCONN_IMAC |
915 MASK_HDPRCONN_IMAC
916 : MASK_HDPCONN;
836 break; 917 break;
837 case 0x00: 918 case 0x00:
838 case 0x05: 919 case 0x05:
839 chip->hp_stat_mask = 0x04; 920 chip->hp_stat_mask = MASK_LOCONN;
840 break; 921 break;
841 default: 922 default:
842 chip->hp_stat_mask = 0x08; 923 chip->hp_stat_mask = MASK_HDPCONN;
843 break; 924 break;
844 } 925 }
845 break; 926 break;
@@ -854,19 +935,43 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
854 */ 935 */
855 strcpy(chip->card->mixername, "PowerMac AWACS"); 936 strcpy(chip->card->mixername, "PowerMac AWACS");
856 937
857 if ((err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers), 938 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers),
858 snd_pmac_awacs_mixers)) < 0) 939 snd_pmac_awacs_mixers);
940 if (err < 0)
859 return err; 941 return err;
860 if (chip->model == PMAC_SCREAMER) 942 if (beige)
943 ;
944 else if (chip->model == PMAC_SCREAMER)
861 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_screamer_mixers2), 945 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_screamer_mixers2),
862 snd_pmac_screamer_mixers2); 946 snd_pmac_screamer_mixers2);
863 else 947 else if (!pm7500)
864 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers2), 948 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mixers2),
865 snd_pmac_awacs_mixers2); 949 snd_pmac_awacs_mixers2);
866 if (err < 0) 950 if (err < 0)
867 return err; 951 return err;
868 chip->master_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_master_sw, chip); 952 if (pm7500)
869 if ((err = snd_ctl_add(chip->card, chip->master_sw_ctl)) < 0) 953 err = build_mixers(chip,
954 ARRAY_SIZE(snd_pmac_awacs_mixers_pmac7500),
955 snd_pmac_awacs_mixers_pmac7500);
956 else if (beige)
957 err = build_mixers(chip,
958 ARRAY_SIZE(snd_pmac_screamer_mixers_beige),
959 snd_pmac_screamer_mixers_beige);
960 else if (imac)
961 err = build_mixers(chip,
962 ARRAY_SIZE(snd_pmac_screamer_mixers_imac),
963 snd_pmac_screamer_mixers_imac);
964 else
965 err = build_mixers(chip,
966 ARRAY_SIZE(snd_pmac_awacs_mixers_pmac),
967 snd_pmac_awacs_mixers_pmac);
968 if (err < 0)
969 return err;
970 chip->master_sw_ctl = snd_ctl_new1((pm7500 || imac)
971 ? &snd_pmac_awacs_master_sw_imac
972 : &snd_pmac_awacs_master_sw, chip);
973 err = snd_ctl_add(chip->card, chip->master_sw_ctl);
974 if (err < 0)
870 return err; 975 return err;
871#ifdef PMAC_AMP_AVAIL 976#ifdef PMAC_AMP_AVAIL
872 if (chip->mixer_data) { 977 if (chip->mixer_data) {
@@ -876,37 +981,58 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
876 * screamer registers. 981 * screamer registers.
877 * in this case, it seems the route C is not used. 982 * in this case, it seems the route C is not used.
878 */ 983 */
879 if ((err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_amp_vol), 984 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_amp_vol),
880 snd_pmac_awacs_amp_vol)) < 0) 985 snd_pmac_awacs_amp_vol);
986 if (err < 0)
881 return err; 987 return err;
882 /* overwrite */ 988 /* overwrite */
883 chip->master_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_hp_sw, chip); 989 chip->master_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_hp_sw,
884 if ((err = snd_ctl_add(chip->card, chip->master_sw_ctl)) < 0) 990 chip);
991 err = snd_ctl_add(chip->card, chip->master_sw_ctl);
992 if (err < 0)
885 return err; 993 return err;
886 chip->speaker_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_spk_sw, chip); 994 chip->speaker_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_amp_spk_sw,
887 if ((err = snd_ctl_add(chip->card, chip->speaker_sw_ctl)) < 0) 995 chip);
996 err = snd_ctl_add(chip->card, chip->speaker_sw_ctl);
997 if (err < 0)
888 return err; 998 return err;
889 } else 999 } else
890#endif /* PMAC_AMP_AVAIL */ 1000#endif /* PMAC_AMP_AVAIL */
891 { 1001 {
892 /* route A = headphone, route C = speaker */ 1002 /* route A = headphone, route C = speaker */
893 if ((err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_speaker_vol), 1003 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_speaker_vol),
894 snd_pmac_awacs_speaker_vol)) < 0) 1004 snd_pmac_awacs_speaker_vol);
1005 if (err < 0)
895 return err; 1006 return err;
896 chip->speaker_sw_ctl = snd_ctl_new1(&snd_pmac_awacs_speaker_sw, chip); 1007 chip->speaker_sw_ctl = snd_ctl_new1(imac
897 if ((err = snd_ctl_add(chip->card, chip->speaker_sw_ctl)) < 0) 1008 ? &snd_pmac_awacs_speaker_sw_imac
1009 : &snd_pmac_awacs_speaker_sw, chip);
1010 err = snd_ctl_add(chip->card, chip->speaker_sw_ctl);
1011 if (err < 0)
898 return err; 1012 return err;
899 } 1013 }
900 1014
901 if (chip->model == PMAC_SCREAMER) { 1015 if (beige)
902 if ((err = build_mixers(chip, ARRAY_SIZE(snd_pmac_screamer_mic_boost), 1016 err = build_mixers(chip,
903 snd_pmac_screamer_mic_boost)) < 0) 1017 ARRAY_SIZE(snd_pmac_screamer_mic_boost_beige),
904 return err; 1018 snd_pmac_screamer_mic_boost_beige);
905 } else { 1019 else if (imac)
906 if ((err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mic_boost), 1020 err = build_mixers(chip,
907 snd_pmac_awacs_mic_boost)) < 0) 1021 ARRAY_SIZE(snd_pmac_screamer_mic_boost_imac),
908 return err; 1022 snd_pmac_screamer_mic_boost_imac);
909 } 1023 else if (chip->model == PMAC_SCREAMER)
1024 err = build_mixers(chip,
1025 ARRAY_SIZE(snd_pmac_screamer_mic_boost),
1026 snd_pmac_screamer_mic_boost);
1027 else if (pm7500)
1028 err = build_mixers(chip,
1029 ARRAY_SIZE(snd_pmac_awacs_mic_boost_pmac7500),
1030 snd_pmac_awacs_mic_boost_pmac7500);
1031 else
1032 err = build_mixers(chip, ARRAY_SIZE(snd_pmac_awacs_mic_boost),
1033 snd_pmac_awacs_mic_boost);
1034 if (err < 0)
1035 return err;
910 1036
911 /* 1037 /*
912 * set lowlevel callbacks 1038 * set lowlevel callbacks
@@ -917,7 +1043,8 @@ snd_pmac_awacs_init(struct snd_pmac *chip)
917 chip->resume = snd_pmac_awacs_resume; 1043 chip->resume = snd_pmac_awacs_resume;
918#endif 1044#endif
919#ifdef PMAC_SUPPORT_AUTOMUTE 1045#ifdef PMAC_SUPPORT_AUTOMUTE
920 if ((err = snd_pmac_add_automute(chip)) < 0) 1046 err = snd_pmac_add_automute(chip);
1047 if (err < 0)
921 return err; 1048 return err;
922 chip->detect_headphone = snd_pmac_awacs_detect_headphone; 1049 chip->detect_headphone = snd_pmac_awacs_detect_headphone;
923 chip->update_automute = snd_pmac_awacs_update_automute; 1050 chip->update_automute = snd_pmac_awacs_update_automute;
diff --git a/sound/ppc/awacs.h b/sound/ppc/awacs.h
index 1b2cc44eda57..c33e6a531cf7 100644
--- a/sound/ppc/awacs.h
+++ b/sound/ppc/awacs.h
@@ -116,6 +116,11 @@ struct awacs_regs {
116#define MASK_HDMUTE MASK_AMUTE 116#define MASK_HDMUTE MASK_AMUTE
117#define SHIFT_HDMUTE 9 117#define SHIFT_HDMUTE 9
118#define MASK_PAROUT (0x3 << 10) /* Parallel Out (???) */ 118#define MASK_PAROUT (0x3 << 10) /* Parallel Out (???) */
119#define MASK_PAROUT0 (0x1 << 10) /* Parallel Out (???) */
120#define MASK_PAROUT1 (0x1 << 11) /* Parallel Out (enable speaker) */
121#define SHIFT_PAROUT 10
122#define SHIFT_PAROUT0 10
123#define SHIFT_PAROUT1 11
119 124
120#define SAMPLERATE_48000 (0x0 << 3) /* 48 or 44.1 kHz */ 125#define SAMPLERATE_48000 (0x0 << 3) /* 48 or 44.1 kHz */
121#define SAMPLERATE_32000 (0x1 << 3) /* 32 or 29.4 kHz */ 126#define SAMPLERATE_32000 (0x1 << 3) /* 32 or 29.4 kHz */
@@ -139,7 +144,7 @@ struct awacs_regs {
139#define VOLLEFT(x) (((~(x)) << 6) & MASK_OUTVOLLEFT) 144#define VOLLEFT(x) (((~(x)) << 6) & MASK_OUTVOLLEFT)
140 145
141/* address 6 */ 146/* address 6 */
142#define MASK_MIC_BOOST (0x4) /* screamer mic boost */ 147#define MASK_MIC_BOOST (0x4) /* screamer mic boost */
143#define SHIFT_MIC_BOOST 2 148#define SHIFT_MIC_BOOST 2
144 149
145/* Audio Codec Status Reg Bit Masks */ 150/* Audio Codec Status Reg Bit Masks */
@@ -152,8 +157,15 @@ struct awacs_regs {
152#define MASK_REVISION (0xf << 12) /* Revision Number */ 157#define MASK_REVISION (0xf << 12) /* Revision Number */
153#define MASK_MFGID (0xf << 8) /* Mfg. ID */ 158#define MASK_MFGID (0xf << 8) /* Mfg. ID */
154#define MASK_CODSTATRES (0xf << 4) /* bits 4 - 7 reserved */ 159#define MASK_CODSTATRES (0xf << 4) /* bits 4 - 7 reserved */
155#define MASK_INPPORT (0xf) /* Input Port */ 160#define MASK_INSENSE (0xf) /* port sense bits: */
156#define MASK_HDPCONN 8 /* headphone plugged in */ 161#define MASK_HDPCONN 8 /* headphone plugged in */
162#define MASK_LOCONN 4 /* line-out plugged in */
163#define MASK_LICONN 2 /* line-in plugged in */
164#define MASK_MICCONN 1 /* microphone plugged in */
165#define MASK_LICONN_IMAC 8 /* line-in plugged in */
166#define MASK_HDPRCONN_IMAC 4 /* headphone right plugged in */
167#define MASK_HDPLCONN_IMAC 2 /* headphone left plugged in */
168#define MASK_LOCONN_IMAC 1 /* line-out plugged in */
157 169
158/* Clipping Count Reg Bit Masks */ 170/* Clipping Count Reg Bit Masks */
159/* -------- ----- --- --- ----- */ 171/* -------- ----- --- --- ----- */
@@ -163,7 +175,8 @@ struct awacs_regs {
163/* DBDMA ChannelStatus Bit Masks */ 175/* DBDMA ChannelStatus Bit Masks */
164/* ----- ------------- --- ----- */ 176/* ----- ------------- --- ----- */
165#define MASK_CSERR (0x1 << 7) /* Error */ 177#define MASK_CSERR (0x1 << 7) /* Error */
166#define MASK_EOI (0x1 << 6) /* End of Input -- only for Input Channel */ 178#define MASK_EOI (0x1 << 6) /* End of Input --
179 only for Input Channel */
167#define MASK_CSUNUSED (0x1f << 1) /* bits 1-5 not used */ 180#define MASK_CSUNUSED (0x1f << 1) /* bits 1-5 not used */
168#define MASK_WAIT (0x1) /* Wait */ 181#define MASK_WAIT (0x1) /* Wait */
169 182
diff --git a/sound/ppc/burgundy.c b/sound/ppc/burgundy.c
index 1a545ac0de04..f860d39af36b 100644
--- a/sound/ppc/burgundy.c
+++ b/sound/ppc/burgundy.c
@@ -102,7 +102,8 @@ snd_pmac_burgundy_rcw(struct snd_pmac *chip, unsigned addr)
102} 102}
103 103
104static void 104static void
105snd_pmac_burgundy_wcb(struct snd_pmac *chip, unsigned int addr, unsigned int val) 105snd_pmac_burgundy_wcb(struct snd_pmac *chip, unsigned int addr,
106 unsigned int val)
106{ 107{
107 out_le32(&chip->awacs->codec_ctrl, addr + 0x300000 + (val & 0xff)); 108 out_le32(&chip->awacs->codec_ctrl, addr + 0x300000 + (val & 0xff));
108 snd_pmac_burgundy_busy_wait(chip); 109 snd_pmac_burgundy_busy_wait(chip);
@@ -126,8 +127,11 @@ snd_pmac_burgundy_rcb(struct snd_pmac *chip, unsigned int addr)
126 return val; 127 return val;
127} 128}
128 129
130#define BASE2ADDR(base) ((base) << 12)
131#define ADDR2BASE(addr) ((addr) >> 12)
132
129/* 133/*
130 * Burgundy volume: 0 - 100, stereo 134 * Burgundy volume: 0 - 100, stereo, word reg
131 */ 135 */
132static void 136static void
133snd_pmac_burgundy_write_volume(struct snd_pmac *chip, unsigned int address, 137snd_pmac_burgundy_write_volume(struct snd_pmac *chip, unsigned int address,
@@ -168,13 +172,6 @@ snd_pmac_burgundy_read_volume(struct snd_pmac *chip, unsigned int address,
168 volume[1] = 0; 172 volume[1] = 0;
169} 173}
170 174
171
172/*
173 */
174
175#define BASE2ADDR(base) ((base) << 12)
176#define ADDR2BASE(addr) ((addr) >> 12)
177
178static int snd_pmac_burgundy_info_volume(struct snd_kcontrol *kcontrol, 175static int snd_pmac_burgundy_info_volume(struct snd_kcontrol *kcontrol,
179 struct snd_ctl_elem_info *uinfo) 176 struct snd_ctl_elem_info *uinfo)
180{ 177{
@@ -191,8 +188,8 @@ static int snd_pmac_burgundy_get_volume(struct snd_kcontrol *kcontrol,
191 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 188 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
192 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff); 189 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
193 int shift = (kcontrol->private_value >> 8) & 0xff; 190 int shift = (kcontrol->private_value >> 8) & 0xff;
194 snd_pmac_burgundy_read_volume(chip, addr, ucontrol->value.integer.value, 191 snd_pmac_burgundy_read_volume(chip, addr,
195 shift); 192 ucontrol->value.integer.value, shift);
196 return 0; 193 return 0;
197} 194}
198 195
@@ -204,24 +201,163 @@ static int snd_pmac_burgundy_put_volume(struct snd_kcontrol *kcontrol,
204 int shift = (kcontrol->private_value >> 8) & 0xff; 201 int shift = (kcontrol->private_value >> 8) & 0xff;
205 long nvoices[2]; 202 long nvoices[2];
206 203
207 snd_pmac_burgundy_write_volume(chip, addr, ucontrol->value.integer.value, 204 snd_pmac_burgundy_write_volume(chip, addr,
208 shift); 205 ucontrol->value.integer.value, shift);
209 snd_pmac_burgundy_read_volume(chip, addr, nvoices, shift); 206 snd_pmac_burgundy_read_volume(chip, addr, nvoices, shift);
210 return (nvoices[0] != ucontrol->value.integer.value[0] || 207 return (nvoices[0] != ucontrol->value.integer.value[0] ||
211 nvoices[1] != ucontrol->value.integer.value[1]); 208 nvoices[1] != ucontrol->value.integer.value[1]);
212} 209}
213 210
214#define BURGUNDY_VOLUME(xname, xindex, addr, shift) \ 211#define BURGUNDY_VOLUME_W(xname, xindex, addr, shift) \
215{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\ 212{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
216 .info = snd_pmac_burgundy_info_volume,\ 213 .info = snd_pmac_burgundy_info_volume,\
217 .get = snd_pmac_burgundy_get_volume,\ 214 .get = snd_pmac_burgundy_get_volume,\
218 .put = snd_pmac_burgundy_put_volume,\ 215 .put = snd_pmac_burgundy_put_volume,\
219 .private_value = ((ADDR2BASE(addr) & 0xff) | ((shift) << 8)) } 216 .private_value = ((ADDR2BASE(addr) & 0xff) | ((shift) << 8)) }
220 217
221/* lineout/speaker */ 218/*
219 * Burgundy volume: 0 - 100, stereo, 2-byte reg
220 */
221static void
222snd_pmac_burgundy_write_volume_2b(struct snd_pmac *chip, unsigned int address,
223 long *volume, int off)
224{
225 int lvolume, rvolume;
222 226
223static int snd_pmac_burgundy_info_switch_out(struct snd_kcontrol *kcontrol, 227 off |= off << 2;
224 struct snd_ctl_elem_info *uinfo) 228 lvolume = volume[0] ? volume[0] + BURGUNDY_VOLUME_OFFSET : 0;
229 rvolume = volume[1] ? volume[1] + BURGUNDY_VOLUME_OFFSET : 0;
230
231 snd_pmac_burgundy_wcb(chip, address + off, lvolume);
232 snd_pmac_burgundy_wcb(chip, address + off + 0x500, rvolume);
233}
234
235static void
236snd_pmac_burgundy_read_volume_2b(struct snd_pmac *chip, unsigned int address,
237 long *volume, int off)
238{
239 volume[0] = snd_pmac_burgundy_rcb(chip, address + off);
240 if (volume[0] >= BURGUNDY_VOLUME_OFFSET)
241 volume[0] -= BURGUNDY_VOLUME_OFFSET;
242 else
243 volume[0] = 0;
244 volume[1] = snd_pmac_burgundy_rcb(chip, address + off + 0x100);
245 if (volume[1] >= BURGUNDY_VOLUME_OFFSET)
246 volume[1] -= BURGUNDY_VOLUME_OFFSET;
247 else
248 volume[1] = 0;
249}
250
251static int snd_pmac_burgundy_info_volume_2b(struct snd_kcontrol *kcontrol,
252 struct snd_ctl_elem_info *uinfo)
253{
254 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
255 uinfo->count = 2;
256 uinfo->value.integer.min = 0;
257 uinfo->value.integer.max = 100;
258 return 0;
259}
260
261static int snd_pmac_burgundy_get_volume_2b(struct snd_kcontrol *kcontrol,
262 struct snd_ctl_elem_value *ucontrol)
263{
264 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
265 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
266 int off = kcontrol->private_value & 0x300;
267 snd_pmac_burgundy_read_volume_2b(chip, addr,
268 ucontrol->value.integer.value, off);
269 return 0;
270}
271
272static int snd_pmac_burgundy_put_volume_2b(struct snd_kcontrol *kcontrol,
273 struct snd_ctl_elem_value *ucontrol)
274{
275 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
276 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
277 int off = kcontrol->private_value & 0x300;
278 long nvoices[2];
279
280 snd_pmac_burgundy_write_volume_2b(chip, addr,
281 ucontrol->value.integer.value, off);
282 snd_pmac_burgundy_read_volume_2b(chip, addr, nvoices, off);
283 return (nvoices[0] != ucontrol->value.integer.value[0] ||
284 nvoices[1] != ucontrol->value.integer.value[1]);
285}
286
287#define BURGUNDY_VOLUME_2B(xname, xindex, addr, off) \
288{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
289 .info = snd_pmac_burgundy_info_volume_2b,\
290 .get = snd_pmac_burgundy_get_volume_2b,\
291 .put = snd_pmac_burgundy_put_volume_2b,\
292 .private_value = ((ADDR2BASE(addr) & 0xff) | ((off) << 8)) }
293
294/*
295 * Burgundy gain/attenuation: 0 - 15, mono/stereo, byte reg
296 */
297static int snd_pmac_burgundy_info_gain(struct snd_kcontrol *kcontrol,
298 struct snd_ctl_elem_info *uinfo)
299{
300 int stereo = (kcontrol->private_value >> 24) & 1;
301 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER;
302 uinfo->count = stereo + 1;
303 uinfo->value.integer.min = 0;
304 uinfo->value.integer.max = 15;
305 return 0;
306}
307
308static int snd_pmac_burgundy_get_gain(struct snd_kcontrol *kcontrol,
309 struct snd_ctl_elem_value *ucontrol)
310{
311 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
312 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
313 int stereo = (kcontrol->private_value >> 24) & 1;
314 int atten = (kcontrol->private_value >> 25) & 1;
315 int oval;
316
317 oval = snd_pmac_burgundy_rcb(chip, addr);
318 if (atten)
319 oval = ~oval & 0xff;
320 ucontrol->value.integer.value[0] = oval & 0xf;
321 if (stereo)
322 ucontrol->value.integer.value[1] = (oval >> 4) & 0xf;
323 return 0;
324}
325
326static int snd_pmac_burgundy_put_gain(struct snd_kcontrol *kcontrol,
327 struct snd_ctl_elem_value *ucontrol)
328{
329 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
330 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff);
331 int stereo = (kcontrol->private_value >> 24) & 1;
332 int atten = (kcontrol->private_value >> 25) & 1;
333 int oval, val;
334
335 oval = snd_pmac_burgundy_rcb(chip, addr);
336 if (atten)
337 oval = ~oval & 0xff;
338 val = ucontrol->value.integer.value[0];
339 if (stereo)
340 val |= ucontrol->value.integer.value[1] << 4;
341 else
342 val |= ucontrol->value.integer.value[0] << 4;
343 if (atten)
344 val = ~val & 0xff;
345 snd_pmac_burgundy_wcb(chip, addr, val);
346 return val != oval;
347}
348
349#define BURGUNDY_VOLUME_B(xname, xindex, addr, stereo, atten) \
350{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
351 .info = snd_pmac_burgundy_info_gain,\
352 .get = snd_pmac_burgundy_get_gain,\
353 .put = snd_pmac_burgundy_put_gain,\
354 .private_value = (ADDR2BASE(addr) | ((stereo) << 24) | ((atten) << 25)) }
355
356/*
357 * Burgundy switch: 0/1, mono/stereo, word reg
358 */
359static int snd_pmac_burgundy_info_switch_w(struct snd_kcontrol *kcontrol,
360 struct snd_ctl_elem_info *uinfo)
225{ 361{
226 int stereo = (kcontrol->private_value >> 24) & 1; 362 int stereo = (kcontrol->private_value >> 24) & 1;
227 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN; 363 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
@@ -231,111 +367,207 @@ static int snd_pmac_burgundy_info_switch_out(struct snd_kcontrol *kcontrol,
231 return 0; 367 return 0;
232} 368}
233 369
234static int snd_pmac_burgundy_get_switch_out(struct snd_kcontrol *kcontrol, 370static int snd_pmac_burgundy_get_switch_w(struct snd_kcontrol *kcontrol,
235 struct snd_ctl_elem_value *ucontrol) 371 struct snd_ctl_elem_value *ucontrol)
236{ 372{
237 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 373 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
238 int lmask = kcontrol->private_value & 0xff; 374 unsigned int addr = BASE2ADDR((kcontrol->private_value >> 16) & 0xff);
239 int rmask = (kcontrol->private_value >> 8) & 0xff; 375 int lmask = 1 << (kcontrol->private_value & 0xff);
376 int rmask = 1 << ((kcontrol->private_value >> 8) & 0xff);
240 int stereo = (kcontrol->private_value >> 24) & 1; 377 int stereo = (kcontrol->private_value >> 24) & 1;
241 int val = snd_pmac_burgundy_rcb(chip, MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES); 378 int val = snd_pmac_burgundy_rcw(chip, addr);
242 ucontrol->value.integer.value[0] = (val & lmask) ? 1 : 0; 379 ucontrol->value.integer.value[0] = (val & lmask) ? 1 : 0;
243 if (stereo) 380 if (stereo)
244 ucontrol->value.integer.value[1] = (val & rmask) ? 1 : 0; 381 ucontrol->value.integer.value[1] = (val & rmask) ? 1 : 0;
245 return 0; 382 return 0;
246} 383}
247 384
248static int snd_pmac_burgundy_put_switch_out(struct snd_kcontrol *kcontrol, 385static int snd_pmac_burgundy_put_switch_w(struct snd_kcontrol *kcontrol,
249 struct snd_ctl_elem_value *ucontrol) 386 struct snd_ctl_elem_value *ucontrol)
250{ 387{
251 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 388 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
252 int lmask = kcontrol->private_value & 0xff; 389 unsigned int addr = BASE2ADDR((kcontrol->private_value >> 16) & 0xff);
253 int rmask = (kcontrol->private_value >> 8) & 0xff; 390 int lmask = 1 << (kcontrol->private_value & 0xff);
391 int rmask = 1 << ((kcontrol->private_value >> 8) & 0xff);
254 int stereo = (kcontrol->private_value >> 24) & 1; 392 int stereo = (kcontrol->private_value >> 24) & 1;
255 int val, oval; 393 int val, oval;
256 oval = snd_pmac_burgundy_rcb(chip, MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES); 394 oval = snd_pmac_burgundy_rcw(chip, addr);
257 val = oval & ~(lmask | rmask); 395 val = oval & ~(lmask | (stereo ? rmask : 0));
258 if (ucontrol->value.integer.value[0]) 396 if (ucontrol->value.integer.value[0])
259 val |= lmask; 397 val |= lmask;
260 if (stereo && ucontrol->value.integer.value[1]) 398 if (stereo && ucontrol->value.integer.value[1])
261 val |= rmask; 399 val |= rmask;
262 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, val); 400 snd_pmac_burgundy_wcw(chip, addr, val);
263 return val != oval; 401 return val != oval;
264} 402}
265 403
266#define BURGUNDY_OUTPUT_SWITCH(xname, xindex, lmask, rmask, stereo) \ 404#define BURGUNDY_SWITCH_W(xname, xindex, addr, lbit, rbit, stereo) \
267{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\ 405{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
268 .info = snd_pmac_burgundy_info_switch_out,\ 406 .info = snd_pmac_burgundy_info_switch_w,\
269 .get = snd_pmac_burgundy_get_switch_out,\ 407 .get = snd_pmac_burgundy_get_switch_w,\
270 .put = snd_pmac_burgundy_put_switch_out,\ 408 .put = snd_pmac_burgundy_put_switch_w,\
271 .private_value = ((lmask) | ((rmask) << 8) | ((stereo) << 24)) } 409 .private_value = ((lbit) | ((rbit) << 8)\
272 410 | (ADDR2BASE(addr) << 16) | ((stereo) << 24)) }
273/* line/speaker output volume */ 411
274static int snd_pmac_burgundy_info_volume_out(struct snd_kcontrol *kcontrol, 412/*
275 struct snd_ctl_elem_info *uinfo) 413 * Burgundy switch: 0/1, mono/stereo, byte reg, bit mask
414 */
415static int snd_pmac_burgundy_info_switch_b(struct snd_kcontrol *kcontrol,
416 struct snd_ctl_elem_info *uinfo)
276{ 417{
277 int stereo = (kcontrol->private_value >> 24) & 1; 418 int stereo = (kcontrol->private_value >> 24) & 1;
278 uinfo->type = SNDRV_CTL_ELEM_TYPE_INTEGER; 419 uinfo->type = SNDRV_CTL_ELEM_TYPE_BOOLEAN;
279 uinfo->count = stereo + 1; 420 uinfo->count = stereo + 1;
280 uinfo->value.integer.min = 0; 421 uinfo->value.integer.min = 0;
281 uinfo->value.integer.max = 15; 422 uinfo->value.integer.max = 1;
282 return 0; 423 return 0;
283} 424}
284 425
285static int snd_pmac_burgundy_get_volume_out(struct snd_kcontrol *kcontrol, 426static int snd_pmac_burgundy_get_switch_b(struct snd_kcontrol *kcontrol,
286 struct snd_ctl_elem_value *ucontrol) 427 struct snd_ctl_elem_value *ucontrol)
287{ 428{
288 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 429 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
289 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff); 430 unsigned int addr = BASE2ADDR((kcontrol->private_value >> 16) & 0xff);
431 int lmask = kcontrol->private_value & 0xff;
432 int rmask = (kcontrol->private_value >> 8) & 0xff;
290 int stereo = (kcontrol->private_value >> 24) & 1; 433 int stereo = (kcontrol->private_value >> 24) & 1;
291 int oval; 434 int val = snd_pmac_burgundy_rcb(chip, addr);
292 435 ucontrol->value.integer.value[0] = (val & lmask) ? 1 : 0;
293 oval = ~snd_pmac_burgundy_rcb(chip, addr) & 0xff;
294 ucontrol->value.integer.value[0] = oval & 0xf;
295 if (stereo) 436 if (stereo)
296 ucontrol->value.integer.value[1] = (oval >> 4) & 0xf; 437 ucontrol->value.integer.value[1] = (val & rmask) ? 1 : 0;
297 return 0; 438 return 0;
298} 439}
299 440
300static int snd_pmac_burgundy_put_volume_out(struct snd_kcontrol *kcontrol, 441static int snd_pmac_burgundy_put_switch_b(struct snd_kcontrol *kcontrol,
301 struct snd_ctl_elem_value *ucontrol) 442 struct snd_ctl_elem_value *ucontrol)
302{ 443{
303 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol); 444 struct snd_pmac *chip = snd_kcontrol_chip(kcontrol);
304 unsigned int addr = BASE2ADDR(kcontrol->private_value & 0xff); 445 unsigned int addr = BASE2ADDR((kcontrol->private_value >> 16) & 0xff);
446 int lmask = kcontrol->private_value & 0xff;
447 int rmask = (kcontrol->private_value >> 8) & 0xff;
305 int stereo = (kcontrol->private_value >> 24) & 1; 448 int stereo = (kcontrol->private_value >> 24) & 1;
306 unsigned int oval, val; 449 int val, oval;
307 450 oval = snd_pmac_burgundy_rcb(chip, addr);
308 oval = ~snd_pmac_burgundy_rcb(chip, addr) & 0xff; 451 val = oval & ~(lmask | rmask);
309 val = ucontrol->value.integer.value[0] & 15; 452 if (ucontrol->value.integer.value[0])
310 if (stereo) 453 val |= lmask;
311 val |= (ucontrol->value.integer.value[1] & 15) << 4; 454 if (stereo && ucontrol->value.integer.value[1])
312 else 455 val |= rmask;
313 val |= val << 4;
314 val = ~val & 0xff;
315 snd_pmac_burgundy_wcb(chip, addr, val); 456 snd_pmac_burgundy_wcb(chip, addr, val);
316 return val != oval; 457 return val != oval;
317} 458}
318 459
319#define BURGUNDY_OUTPUT_VOLUME(xname, xindex, addr, stereo) \ 460#define BURGUNDY_SWITCH_B(xname, xindex, addr, lmask, rmask, stereo) \
320{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\ 461{ .iface = SNDRV_CTL_ELEM_IFACE_MIXER, .name = xname, .index = xindex,\
321 .info = snd_pmac_burgundy_info_volume_out,\ 462 .info = snd_pmac_burgundy_info_switch_b,\
322 .get = snd_pmac_burgundy_get_volume_out,\ 463 .get = snd_pmac_burgundy_get_switch_b,\
323 .put = snd_pmac_burgundy_put_volume_out,\ 464 .put = snd_pmac_burgundy_put_switch_b,\
324 .private_value = (ADDR2BASE(addr) | ((stereo) << 24)) } 465 .private_value = ((lmask) | ((rmask) << 8)\
466 | (ADDR2BASE(addr) << 16) | ((stereo) << 24)) }
325 467
468/*
469 * Burgundy mixers
470 */
326static struct snd_kcontrol_new snd_pmac_burgundy_mixers[] __initdata = { 471static struct snd_kcontrol_new snd_pmac_burgundy_mixers[] __initdata = {
327 BURGUNDY_VOLUME("Master Playback Volume", 0, MASK_ADDR_BURGUNDY_MASTER_VOLUME, 8), 472 BURGUNDY_VOLUME_W("Master Playback Volume", 0,
328 BURGUNDY_VOLUME("Line Playback Volume", 0, MASK_ADDR_BURGUNDY_VOLLINE, 16), 473 MASK_ADDR_BURGUNDY_MASTER_VOLUME, 8),
329 BURGUNDY_VOLUME("CD Playback Volume", 0, MASK_ADDR_BURGUNDY_VOLCD, 16), 474 BURGUNDY_VOLUME_W("CD Capture Volume", 0,
330 BURGUNDY_VOLUME("Mic Playback Volume", 0, MASK_ADDR_BURGUNDY_VOLMIC, 16), 475 MASK_ADDR_BURGUNDY_VOLCD, 16),
331 BURGUNDY_OUTPUT_VOLUME("PC Speaker Playback Volume", 0, MASK_ADDR_BURGUNDY_ATTENHP, 0), 476 BURGUNDY_VOLUME_2B("Input Capture Volume", 0,
332 /*BURGUNDY_OUTPUT_VOLUME("PCM Playback Volume", 0, MASK_ADDR_BURGUNDY_ATTENLINEOUT, 1),*/ 477 MASK_ADDR_BURGUNDY_VOLMIX01, 2),
333 BURGUNDY_OUTPUT_VOLUME("Headphone Playback Volume", 0, MASK_ADDR_BURGUNDY_ATTENSPEAKER, 1), 478 BURGUNDY_VOLUME_2B("Mixer Playback Volume", 0,
334}; 479 MASK_ADDR_BURGUNDY_VOLMIX23, 0),
335static struct snd_kcontrol_new snd_pmac_burgundy_master_sw __initdata = 480 BURGUNDY_VOLUME_B("CD Gain Capture Volume", 0,
336BURGUNDY_OUTPUT_SWITCH("Headphone Playback Switch", 0, BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1); 481 MASK_ADDR_BURGUNDY_GAINCD, 1, 0),
337static struct snd_kcontrol_new snd_pmac_burgundy_speaker_sw __initdata = 482 BURGUNDY_SWITCH_W("Master Capture Switch", 0,
338BURGUNDY_OUTPUT_SWITCH("PC Speaker Playback Switch", 0, BURGUNDY_OUTPUT_INTERN, 0, 0); 483 MASK_ADDR_BURGUNDY_OUTPUTENABLES, 24, 0, 0),
484 BURGUNDY_SWITCH_W("CD Capture Switch", 0,
485 MASK_ADDR_BURGUNDY_CAPTURESELECTS, 0, 16, 1),
486 BURGUNDY_SWITCH_W("CD Playback Switch", 0,
487 MASK_ADDR_BURGUNDY_OUTPUTSELECTS, 0, 16, 1),
488/* BURGUNDY_SWITCH_W("Loop Capture Switch", 0,
489 * MASK_ADDR_BURGUNDY_CAPTURESELECTS, 8, 24, 1),
490 * BURGUNDY_SWITCH_B("Mixer out Capture Switch", 0,
491 * MASK_ADDR_BURGUNDY_HOSTIFAD, 0x02, 0, 0),
492 * BURGUNDY_SWITCH_B("Mixer Capture Switch", 0,
493 * MASK_ADDR_BURGUNDY_HOSTIFAD, 0x01, 0, 0),
494 * BURGUNDY_SWITCH_B("PCM out Capture Switch", 0,
495 * MASK_ADDR_BURGUNDY_HOSTIFEH, 0x02, 0, 0),
496 */ BURGUNDY_SWITCH_B("PCM Capture Switch", 0,
497 MASK_ADDR_BURGUNDY_HOSTIFEH, 0x01, 0, 0)
498};
499static struct snd_kcontrol_new snd_pmac_burgundy_mixers_imac[] __initdata = {
500 BURGUNDY_VOLUME_W("Line in Capture Volume", 0,
501 MASK_ADDR_BURGUNDY_VOLLINE, 16),
502 BURGUNDY_VOLUME_W("Mic Capture Volume", 0,
503 MASK_ADDR_BURGUNDY_VOLMIC, 16),
504 BURGUNDY_VOLUME_B("Line in Gain Capture Volume", 0,
505 MASK_ADDR_BURGUNDY_GAINLINE, 1, 0),
506 BURGUNDY_VOLUME_B("Mic Gain Capture Volume", 0,
507 MASK_ADDR_BURGUNDY_GAINMIC, 1, 0),
508 BURGUNDY_VOLUME_B("PC Speaker Playback Volume", 0,
509 MASK_ADDR_BURGUNDY_ATTENSPEAKER, 1, 1),
510 BURGUNDY_VOLUME_B("Line out Playback Volume", 0,
511 MASK_ADDR_BURGUNDY_ATTENLINEOUT, 1, 1),
512 BURGUNDY_VOLUME_B("Headphone Playback Volume", 0,
513 MASK_ADDR_BURGUNDY_ATTENHP, 1, 1),
514 BURGUNDY_SWITCH_W("Line in Capture Switch", 0,
515 MASK_ADDR_BURGUNDY_CAPTURESELECTS, 1, 17, 1),
516 BURGUNDY_SWITCH_W("Mic Capture Switch", 0,
517 MASK_ADDR_BURGUNDY_CAPTURESELECTS, 2, 18, 1),
518 BURGUNDY_SWITCH_W("Line in Playback Switch", 0,
519 MASK_ADDR_BURGUNDY_OUTPUTSELECTS, 1, 17, 1),
520 BURGUNDY_SWITCH_W("Mic Playback Switch", 0,
521 MASK_ADDR_BURGUNDY_OUTPUTSELECTS, 2, 18, 1),
522 BURGUNDY_SWITCH_B("Mic Boost Capture Switch", 0,
523 MASK_ADDR_BURGUNDY_INPBOOST, 0x40, 0x80, 1)
524};
525static struct snd_kcontrol_new snd_pmac_burgundy_mixers_pmac[] __initdata = {
526 BURGUNDY_VOLUME_W("Line in Capture Volume", 0,
527 MASK_ADDR_BURGUNDY_VOLMIC, 16),
528 BURGUNDY_VOLUME_B("Line in Gain Capture Volume", 0,
529 MASK_ADDR_BURGUNDY_GAINMIC, 1, 0),
530 BURGUNDY_VOLUME_B("PC Speaker Playback Volume", 0,
531 MASK_ADDR_BURGUNDY_ATTENMONO, 0, 1),
532 BURGUNDY_VOLUME_B("Line out Playback Volume", 0,
533 MASK_ADDR_BURGUNDY_ATTENSPEAKER, 1, 1),
534 BURGUNDY_SWITCH_W("Line in Capture Switch", 0,
535 MASK_ADDR_BURGUNDY_CAPTURESELECTS, 2, 18, 1),
536 BURGUNDY_SWITCH_W("Line in Playback Switch", 0,
537 MASK_ADDR_BURGUNDY_OUTPUTSELECTS, 2, 18, 1),
538/* BURGUNDY_SWITCH_B("Line in Boost Capture Switch", 0,
539 * MASK_ADDR_BURGUNDY_INPBOOST, 0x40, 0x80, 1) */
540};
541static struct snd_kcontrol_new snd_pmac_burgundy_master_sw_imac __initdata =
542BURGUNDY_SWITCH_B("Master Playback Switch", 0,
543 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
544 BURGUNDY_OUTPUT_LEFT | BURGUNDY_LINEOUT_LEFT | BURGUNDY_HP_LEFT,
545 BURGUNDY_OUTPUT_RIGHT | BURGUNDY_LINEOUT_RIGHT | BURGUNDY_HP_RIGHT, 1);
546static struct snd_kcontrol_new snd_pmac_burgundy_master_sw_pmac __initdata =
547BURGUNDY_SWITCH_B("Master Playback Switch", 0,
548 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
549 BURGUNDY_OUTPUT_INTERN
550 | BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1);
551static struct snd_kcontrol_new snd_pmac_burgundy_speaker_sw_imac __initdata =
552BURGUNDY_SWITCH_B("PC Speaker Playback Switch", 0,
553 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
554 BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1);
555static struct snd_kcontrol_new snd_pmac_burgundy_speaker_sw_pmac __initdata =
556BURGUNDY_SWITCH_B("PC Speaker Playback Switch", 0,
557 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
558 BURGUNDY_OUTPUT_INTERN, 0, 0);
559static struct snd_kcontrol_new snd_pmac_burgundy_line_sw_imac __initdata =
560BURGUNDY_SWITCH_B("Line out Playback Switch", 0,
561 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
562 BURGUNDY_LINEOUT_LEFT, BURGUNDY_LINEOUT_RIGHT, 1);
563static struct snd_kcontrol_new snd_pmac_burgundy_line_sw_pmac __initdata =
564BURGUNDY_SWITCH_B("Line out Playback Switch", 0,
565 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
566 BURGUNDY_OUTPUT_LEFT, BURGUNDY_OUTPUT_RIGHT, 1);
567static struct snd_kcontrol_new snd_pmac_burgundy_hp_sw_imac __initdata =
568BURGUNDY_SWITCH_B("Headphone Playback Switch", 0,
569 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
570 BURGUNDY_HP_LEFT, BURGUNDY_HP_RIGHT, 1);
339 571
340 572
341#ifdef PMAC_SUPPORT_AUTOMUTE 573#ifdef PMAC_SUPPORT_AUTOMUTE
@@ -350,16 +582,26 @@ static int snd_pmac_burgundy_detect_headphone(struct snd_pmac *chip)
350static void snd_pmac_burgundy_update_automute(struct snd_pmac *chip, int do_notify) 582static void snd_pmac_burgundy_update_automute(struct snd_pmac *chip, int do_notify)
351{ 583{
352 if (chip->auto_mute) { 584 if (chip->auto_mute) {
585 int imac = machine_is_compatible("iMac");
353 int reg, oreg; 586 int reg, oreg;
354 reg = oreg = snd_pmac_burgundy_rcb(chip, MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES); 587 reg = oreg = snd_pmac_burgundy_rcb(chip,
355 reg &= ~(BURGUNDY_OUTPUT_LEFT | BURGUNDY_OUTPUT_RIGHT | BURGUNDY_OUTPUT_INTERN); 588 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES);
589 reg &= imac ? ~(BURGUNDY_OUTPUT_LEFT | BURGUNDY_OUTPUT_RIGHT
590 | BURGUNDY_HP_LEFT | BURGUNDY_HP_RIGHT)
591 : ~(BURGUNDY_OUTPUT_LEFT | BURGUNDY_OUTPUT_RIGHT
592 | BURGUNDY_OUTPUT_INTERN);
356 if (snd_pmac_burgundy_detect_headphone(chip)) 593 if (snd_pmac_burgundy_detect_headphone(chip))
357 reg |= BURGUNDY_OUTPUT_LEFT | BURGUNDY_OUTPUT_RIGHT; 594 reg |= imac ? (BURGUNDY_HP_LEFT | BURGUNDY_HP_RIGHT)
595 : (BURGUNDY_OUTPUT_LEFT
596 | BURGUNDY_OUTPUT_RIGHT);
358 else 597 else
359 reg |= BURGUNDY_OUTPUT_INTERN; 598 reg |= imac ? (BURGUNDY_OUTPUT_LEFT
599 | BURGUNDY_OUTPUT_RIGHT)
600 : (BURGUNDY_OUTPUT_INTERN);
360 if (do_notify && reg == oreg) 601 if (do_notify && reg == oreg)
361 return; 602 return;
362 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, reg); 603 snd_pmac_burgundy_wcb(chip,
604 MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, reg);
363 if (do_notify) { 605 if (do_notify) {
364 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE, 606 snd_ctl_notify(chip->card, SNDRV_CTL_EVENT_MASK_VALUE,
365 &chip->master_sw_ctl->id); 607 &chip->master_sw_ctl->id);
@@ -378,6 +620,7 @@ static void snd_pmac_burgundy_update_automute(struct snd_pmac *chip, int do_noti
378 */ 620 */
379int __init snd_pmac_burgundy_init(struct snd_pmac *chip) 621int __init snd_pmac_burgundy_init(struct snd_pmac *chip)
380{ 622{
623 int imac = machine_is_compatible("iMac");
381 int i, err; 624 int i, err;
382 625
383 /* Checks to see the chip is alive and kicking */ 626 /* Checks to see the chip is alive and kicking */
@@ -386,7 +629,7 @@ int __init snd_pmac_burgundy_init(struct snd_pmac *chip)
386 return 1; 629 return 1;
387 } 630 }
388 631
389 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_OUTPUTENABLES, 632 snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_OUTPUTENABLES,
390 DEF_BURGUNDY_OUTPUTENABLES); 633 DEF_BURGUNDY_OUTPUTENABLES);
391 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES, 634 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_MORE_OUTPUTENABLES,
392 DEF_BURGUNDY_MORE_OUTPUTENABLES); 635 DEF_BURGUNDY_MORE_OUTPUTENABLES);
@@ -396,7 +639,8 @@ int __init snd_pmac_burgundy_init(struct snd_pmac *chip)
396 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_INPSEL21, 639 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_INPSEL21,
397 DEF_BURGUNDY_INPSEL21); 640 DEF_BURGUNDY_INPSEL21);
398 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_INPSEL3, 641 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_INPSEL3,
399 DEF_BURGUNDY_INPSEL3); 642 imac ? DEF_BURGUNDY_INPSEL3_IMAC
643 : DEF_BURGUNDY_INPSEL3_PMAC);
400 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_GAINCD, 644 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_GAINCD,
401 DEF_BURGUNDY_GAINCD); 645 DEF_BURGUNDY_GAINCD);
402 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_GAINLINE, 646 snd_pmac_burgundy_wcb(chip, MASK_ADDR_BURGUNDY_GAINLINE,
@@ -422,27 +666,62 @@ int __init snd_pmac_burgundy_init(struct snd_pmac *chip)
422 snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_VOLMIC, 666 snd_pmac_burgundy_wcw(chip, MASK_ADDR_BURGUNDY_VOLMIC,
423 DEF_BURGUNDY_VOLMIC); 667 DEF_BURGUNDY_VOLMIC);
424 668
425 if (chip->hp_stat_mask == 0) 669 if (chip->hp_stat_mask == 0) {
426 /* set headphone-jack detection bit */ 670 /* set headphone-jack detection bit */
427 chip->hp_stat_mask = 0x04; 671 if (imac)
428 672 chip->hp_stat_mask = BURGUNDY_HPDETECT_IMAC_UPPER
673 | BURGUNDY_HPDETECT_IMAC_LOWER
674 | BURGUNDY_HPDETECT_IMAC_SIDE;
675 else
676 chip->hp_stat_mask = BURGUNDY_HPDETECT_PMAC_BACK;
677 }
429 /* 678 /*
430 * build burgundy mixers 679 * build burgundy mixers
431 */ 680 */
432 strcpy(chip->card->mixername, "PowerMac Burgundy"); 681 strcpy(chip->card->mixername, "PowerMac Burgundy");
433 682
434 for (i = 0; i < ARRAY_SIZE(snd_pmac_burgundy_mixers); i++) { 683 for (i = 0; i < ARRAY_SIZE(snd_pmac_burgundy_mixers); i++) {
435 if ((err = snd_ctl_add(chip->card, snd_ctl_new1(&snd_pmac_burgundy_mixers[i], chip))) < 0) 684 err = snd_ctl_add(chip->card,
685 snd_ctl_new1(&snd_pmac_burgundy_mixers[i], chip));
686 if (err < 0)
687 return err;
688 }
689 for (i = 0; i < (imac ? ARRAY_SIZE(snd_pmac_burgundy_mixers_imac)
690 : ARRAY_SIZE(snd_pmac_burgundy_mixers_pmac)); i++) {
691 err = snd_ctl_add(chip->card,
692 snd_ctl_new1(imac ? &snd_pmac_burgundy_mixers_imac[i]
693 : &snd_pmac_burgundy_mixers_pmac[i], chip));
694 if (err < 0)
436 return err; 695 return err;
437 } 696 }
438 chip->master_sw_ctl = snd_ctl_new1(&snd_pmac_burgundy_master_sw, chip); 697 chip->master_sw_ctl = snd_ctl_new1(imac
439 if ((err = snd_ctl_add(chip->card, chip->master_sw_ctl)) < 0) 698 ? &snd_pmac_burgundy_master_sw_imac
699 : &snd_pmac_burgundy_master_sw_pmac, chip);
700 err = snd_ctl_add(chip->card, chip->master_sw_ctl);
701 if (err < 0)
702 return err;
703 chip->master_sw_ctl = snd_ctl_new1(imac
704 ? &snd_pmac_burgundy_line_sw_imac
705 : &snd_pmac_burgundy_line_sw_pmac, chip);
706 err = snd_ctl_add(chip->card, chip->master_sw_ctl);
707 if (err < 0)
440 return err; 708 return err;
441 chip->speaker_sw_ctl = snd_ctl_new1(&snd_pmac_burgundy_speaker_sw, chip); 709 if (imac) {
442 if ((err = snd_ctl_add(chip->card, chip->speaker_sw_ctl)) < 0) 710 chip->master_sw_ctl = snd_ctl_new1(
711 &snd_pmac_burgundy_hp_sw_imac, chip);
712 err = snd_ctl_add(chip->card, chip->master_sw_ctl);
713 if (err < 0)
714 return err;
715 }
716 chip->speaker_sw_ctl = snd_ctl_new1(imac
717 ? &snd_pmac_burgundy_speaker_sw_imac
718 : &snd_pmac_burgundy_speaker_sw_pmac, chip);
719 err = snd_ctl_add(chip->card, chip->speaker_sw_ctl);
720 if (err < 0)
443 return err; 721 return err;
444#ifdef PMAC_SUPPORT_AUTOMUTE 722#ifdef PMAC_SUPPORT_AUTOMUTE
445 if ((err = snd_pmac_add_automute(chip)) < 0) 723 err = snd_pmac_add_automute(chip);
724 if (err < 0)
446 return err; 725 return err;
447 726
448 chip->detect_headphone = snd_pmac_burgundy_detect_headphone; 727 chip->detect_headphone = snd_pmac_burgundy_detect_headphone;
diff --git a/sound/ppc/burgundy.h b/sound/ppc/burgundy.h
index ebb457a8342c..7a7f9cf3d299 100644
--- a/sound/ppc/burgundy.h
+++ b/sound/ppc/burgundy.h
@@ -22,6 +22,7 @@
22#ifndef __BURGUNDY_H 22#ifndef __BURGUNDY_H
23#define __BURGUNDY_H 23#define __BURGUNDY_H
24 24
25#define MASK_ADDR_BURGUNDY_INPBOOST (0x10 << 12)
25#define MASK_ADDR_BURGUNDY_INPSEL21 (0x11 << 12) 26#define MASK_ADDR_BURGUNDY_INPSEL21 (0x11 << 12)
26#define MASK_ADDR_BURGUNDY_INPSEL3 (0x12 << 12) 27#define MASK_ADDR_BURGUNDY_INPSEL3 (0x12 << 12)
27 28
@@ -35,7 +36,10 @@
35#define MASK_ADDR_BURGUNDY_VOLCH3 (0x22 << 12) 36#define MASK_ADDR_BURGUNDY_VOLCH3 (0x22 << 12)
36#define MASK_ADDR_BURGUNDY_VOLCH4 (0x23 << 12) 37#define MASK_ADDR_BURGUNDY_VOLCH4 (0x23 << 12)
37 38
39#define MASK_ADDR_BURGUNDY_CAPTURESELECTS (0x2A << 12)
38#define MASK_ADDR_BURGUNDY_OUTPUTSELECTS (0x2B << 12) 40#define MASK_ADDR_BURGUNDY_OUTPUTSELECTS (0x2B << 12)
41#define MASK_ADDR_BURGUNDY_VOLMIX01 (0x2D << 12)
42#define MASK_ADDR_BURGUNDY_VOLMIX23 (0x2E << 12)
39#define MASK_ADDR_BURGUNDY_OUTPUTENABLES (0x2F << 12) 43#define MASK_ADDR_BURGUNDY_OUTPUTENABLES (0x2F << 12)
40 44
41#define MASK_ADDR_BURGUNDY_MASTER_VOLUME (0x30 << 12) 45#define MASK_ADDR_BURGUNDY_MASTER_VOLUME (0x30 << 12)
@@ -45,6 +49,10 @@
45#define MASK_ADDR_BURGUNDY_ATTENSPEAKER (0x62 << 12) 49#define MASK_ADDR_BURGUNDY_ATTENSPEAKER (0x62 << 12)
46#define MASK_ADDR_BURGUNDY_ATTENLINEOUT (0x63 << 12) 50#define MASK_ADDR_BURGUNDY_ATTENLINEOUT (0x63 << 12)
47#define MASK_ADDR_BURGUNDY_ATTENHP (0x64 << 12) 51#define MASK_ADDR_BURGUNDY_ATTENHP (0x64 << 12)
52#define MASK_ADDR_BURGUNDY_ATTENMONO (0x65 << 12)
53
54#define MASK_ADDR_BURGUNDY_HOSTIFAD (0x78 << 12)
55#define MASK_ADDR_BURGUNDY_HOSTIFEH (0x79 << 12)
48 56
49#define MASK_ADDR_BURGUNDY_VOLCD (MASK_ADDR_BURGUNDY_VOLCH1) 57#define MASK_ADDR_BURGUNDY_VOLCD (MASK_ADDR_BURGUNDY_VOLCH1)
50#define MASK_ADDR_BURGUNDY_VOLLINE (MASK_ADDR_BURGUNDY_VOLCH2) 58#define MASK_ADDR_BURGUNDY_VOLLINE (MASK_ADDR_BURGUNDY_VOLCH2)
@@ -59,21 +67,22 @@
59 67
60/* These are all default values for the burgundy */ 68/* These are all default values for the burgundy */
61#define DEF_BURGUNDY_INPSEL21 (0xAA) 69#define DEF_BURGUNDY_INPSEL21 (0xAA)
62#define DEF_BURGUNDY_INPSEL3 (0x0A) 70#define DEF_BURGUNDY_INPSEL3_IMAC (0x0A)
71#define DEF_BURGUNDY_INPSEL3_PMAC (0x05)
63 72
64#define DEF_BURGUNDY_GAINCD (0x33) 73#define DEF_BURGUNDY_GAINCD (0x33)
65#define DEF_BURGUNDY_GAINLINE (0x44) 74#define DEF_BURGUNDY_GAINLINE (0x44)
66#define DEF_BURGUNDY_GAINMIC (0x44) 75#define DEF_BURGUNDY_GAINMIC (0x44)
67#define DEF_BURGUNDY_GAINMODEM (0x06) 76#define DEF_BURGUNDY_GAINMODEM (0x06)
68 77
69/* Remember: lowest volume here is 0x9b */ 78/* Remember: lowest volume here is 0x9B (155) */
70#define DEF_BURGUNDY_VOLCD (0xCCCCCCCC) 79#define DEF_BURGUNDY_VOLCD (0xCCCCCCCC)
71#define DEF_BURGUNDY_VOLLINE (0x00000000) 80#define DEF_BURGUNDY_VOLLINE (0x00000000)
72#define DEF_BURGUNDY_VOLMIC (0x00000000) 81#define DEF_BURGUNDY_VOLMIC (0x00000000)
73#define DEF_BURGUNDY_VOLMODEM (0xCCCCCCCC) 82#define DEF_BURGUNDY_VOLMODEM (0xCCCCCCCC)
74 83
75#define DEF_BURGUNDY_OUTPUTSELECTS (0x010f010f) 84#define DEF_BURGUNDY_OUTPUTSELECTS (0x010F010F)
76#define DEF_BURGUNDY_OUTPUTENABLES (0x0A) 85#define DEF_BURGUNDY_OUTPUTENABLES (0x0100000A)
77 86
78/* #define DEF_BURGUNDY_MASTER_VOLUME (0xFFFFFFFF) */ /* too loud */ 87/* #define DEF_BURGUNDY_MASTER_VOLUME (0xFFFFFFFF) */ /* too loud */
79#define DEF_BURGUNDY_MASTER_VOLUME (0xDDDDDDDD) 88#define DEF_BURGUNDY_MASTER_VOLUME (0xDDDDDDDD)
@@ -84,12 +93,22 @@
84#define DEF_BURGUNDY_ATTENLINEOUT (0xCC) 93#define DEF_BURGUNDY_ATTENLINEOUT (0xCC)
85#define DEF_BURGUNDY_ATTENHP (0xCC) 94#define DEF_BURGUNDY_ATTENHP (0xCC)
86 95
87/* OUTPUTENABLES bits */ 96/* MORE_OUTPUTENABLES bits */
88#define BURGUNDY_OUTPUT_LEFT 0x02 97#define BURGUNDY_OUTPUT_LEFT 0x02
89#define BURGUNDY_OUTPUT_RIGHT 0x04 98#define BURGUNDY_OUTPUT_RIGHT 0x04
99#define BURGUNDY_LINEOUT_LEFT 0x08
100#define BURGUNDY_LINEOUT_RIGHT 0x10
101#define BURGUNDY_HP_LEFT 0x20
102#define BURGUNDY_HP_RIGHT 0x40
90#define BURGUNDY_OUTPUT_INTERN 0x80 103#define BURGUNDY_OUTPUT_INTERN 0x80
91 104
92/* volume offset */ 105/* Headphone detection bits */
106#define BURGUNDY_HPDETECT_PMAC_BACK 0x04
107#define BURGUNDY_HPDETECT_IMAC_SIDE 0x04
108#define BURGUNDY_HPDETECT_IMAC_UPPER 0x08
109#define BURGUNDY_HPDETECT_IMAC_LOWER 0x01
110
111/* Volume offset */
93#define BURGUNDY_VOLUME_OFFSET 155 112#define BURGUNDY_VOLUME_OFFSET 155
94 113
95#endif /* __BURGUNDY_H */ 114#endif /* __BURGUNDY_H */
diff --git a/sound/ppc/pmac.c b/sound/ppc/pmac.c
index 613a565e04de..a38c0c790d2b 100644
--- a/sound/ppc/pmac.c
+++ b/sound/ppc/pmac.c
@@ -214,7 +214,7 @@ static int snd_pmac_pcm_prepare(struct snd_pmac *chip, struct pmac_stream *rec,
214 int rate_index; 214 int rate_index;
215 long offset; 215 long offset;
216 struct pmac_stream *astr; 216 struct pmac_stream *astr;
217 217
218 rec->dma_size = snd_pcm_lib_buffer_bytes(subs); 218 rec->dma_size = snd_pcm_lib_buffer_bytes(subs);
219 rec->period_size = snd_pcm_lib_period_bytes(subs); 219 rec->period_size = snd_pcm_lib_period_bytes(subs);
220 rec->nperiods = rec->dma_size / rec->period_size; 220 rec->nperiods = rec->dma_size / rec->period_size;
@@ -643,7 +643,7 @@ static int snd_pmac_pcm_close(struct snd_pmac *chip, struct pmac_stream *rec,
643 /* reset constraints */ 643 /* reset constraints */
644 astr->cur_freqs = chip->freqs_ok; 644 astr->cur_freqs = chip->freqs_ok;
645 astr->cur_formats = chip->formats_ok; 645 astr->cur_formats = chip->formats_ok;
646 646
647 return 0; 647 return 0;
648} 648}
649 649
@@ -1300,9 +1300,9 @@ int __init snd_pmac_new(struct snd_card *card, struct snd_pmac **chip_return)
1300 1300
1301 snd_pmac_sound_feature(chip, 1); 1301 snd_pmac_sound_feature(chip, 1);
1302 1302
1303 /* reset */ 1303 /* reset & enable interrupts */
1304 if (chip->model == PMAC_AWACS) 1304 if (chip->model <= PMAC_BURGUNDY)
1305 out_le32(&chip->awacs->control, 0x11); 1305 out_le32(&chip->awacs->control, chip->control_mask);
1306 1306
1307 /* Powerbooks have odd ways of enabling inputs such as 1307 /* Powerbooks have odd ways of enabling inputs such as
1308 an expansion-bay CD or sound from an internal modem 1308 an expansion-bay CD or sound from an internal modem
diff --git a/sound/soc/Kconfig b/sound/soc/Kconfig
index 276585215160..a3b51df2bea1 100644
--- a/sound/soc/Kconfig
+++ b/sound/soc/Kconfig
@@ -29,6 +29,7 @@ source "sound/soc/pxa/Kconfig"
29source "sound/soc/s3c24xx/Kconfig" 29source "sound/soc/s3c24xx/Kconfig"
30source "sound/soc/sh/Kconfig" 30source "sound/soc/sh/Kconfig"
31source "sound/soc/fsl/Kconfig" 31source "sound/soc/fsl/Kconfig"
32source "sound/soc/davinci/Kconfig"
32 33
33# Supported codecs 34# Supported codecs
34source "sound/soc/codecs/Kconfig" 35source "sound/soc/codecs/Kconfig"
diff --git a/sound/soc/Makefile b/sound/soc/Makefile
index 4869c9ae7a03..e489dbdde458 100644
--- a/sound/soc/Makefile
+++ b/sound/soc/Makefile
@@ -1,4 +1,4 @@
1snd-soc-core-objs := soc-core.o soc-dapm.o 1snd-soc-core-objs := soc-core.o soc-dapm.o
2 2
3obj-$(CONFIG_SND_SOC) += snd-soc-core.o 3obj-$(CONFIG_SND_SOC) += snd-soc-core.o
4obj-$(CONFIG_SND_SOC) += codecs/ at91/ pxa/ s3c24xx/ sh/ fsl/ 4obj-$(CONFIG_SND_SOC) += codecs/ at91/ pxa/ s3c24xx/ sh/ fsl/ davinci/
diff --git a/sound/soc/codecs/Kconfig b/sound/soc/codecs/Kconfig
index 898a7d363284..3903ab7dfa4a 100644
--- a/sound/soc/codecs/Kconfig
+++ b/sound/soc/codecs/Kconfig
@@ -18,6 +18,10 @@ config SND_SOC_WM9712
18 tristate 18 tristate
19 depends on SND_SOC 19 depends on SND_SOC
20 20
21config SND_SOC_WM9713
22 tristate
23 depends on SND_SOC
24
21# Cirrus Logic CS4270 Codec 25# Cirrus Logic CS4270 Codec
22config SND_SOC_CS4270 26config SND_SOC_CS4270
23 tristate 27 tristate
diff --git a/sound/soc/codecs/Makefile b/sound/soc/codecs/Makefile
index c6e5338c2666..4e1314c9d3ec 100644
--- a/sound/soc/codecs/Makefile
+++ b/sound/soc/codecs/Makefile
@@ -3,6 +3,7 @@ snd-soc-wm8731-objs := wm8731.o
3snd-soc-wm8750-objs := wm8750.o 3snd-soc-wm8750-objs := wm8750.o
4snd-soc-wm8753-objs := wm8753.o 4snd-soc-wm8753-objs := wm8753.o
5snd-soc-wm9712-objs := wm9712.o 5snd-soc-wm9712-objs := wm9712.o
6snd-soc-wm9713-objs := wm9713.o
6snd-soc-cs4270-objs := cs4270.o 7snd-soc-cs4270-objs := cs4270.o
7snd-soc-tlv320aic3x-objs := tlv320aic3x.o 8snd-soc-tlv320aic3x-objs := tlv320aic3x.o
8 9
@@ -11,5 +12,6 @@ obj-$(CONFIG_SND_SOC_WM8731) += snd-soc-wm8731.o
11obj-$(CONFIG_SND_SOC_WM8750) += snd-soc-wm8750.o 12obj-$(CONFIG_SND_SOC_WM8750) += snd-soc-wm8750.o
12obj-$(CONFIG_SND_SOC_WM8753) += snd-soc-wm8753.o 13obj-$(CONFIG_SND_SOC_WM8753) += snd-soc-wm8753.o
13obj-$(CONFIG_SND_SOC_WM9712) += snd-soc-wm9712.o 14obj-$(CONFIG_SND_SOC_WM9712) += snd-soc-wm9712.o
15obj-$(CONFIG_SND_SOC_WM9713) += snd-soc-wm9713.o
14obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o 16obj-$(CONFIG_SND_SOC_CS4270) += snd-soc-cs4270.o
15obj-$(CONFIG_SND_SOC_TLV320AIC3X) += snd-soc-tlv320aic3x.o 17obj-$(CONFIG_SND_SOC_TLV320AIC3X) += snd-soc-tlv320aic3x.o
diff --git a/sound/soc/codecs/ac97.c b/sound/soc/codecs/ac97.c
index 242130cf1abd..2a1ffe396908 100644
--- a/sound/soc/codecs/ac97.c
+++ b/sound/soc/codecs/ac97.c
@@ -40,7 +40,8 @@ static int ac97_prepare(struct snd_pcm_substream *substream)
40} 40}
41 41
42#define STD_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ 42#define STD_AC97_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
43 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000) 43 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 |\
44 SNDRV_PCM_RATE_48000)
44 45
45struct snd_soc_codec_dai ac97_dai = { 46struct snd_soc_codec_dai ac97_dai = {
46 .name = "AC97 HiFi", 47 .name = "AC97 HiFi",
@@ -86,7 +87,7 @@ static int ac97_soc_probe(struct platform_device *pdev)
86 printk(KERN_INFO "AC97 SoC Audio Codec %s\n", AC97_VERSION); 87 printk(KERN_INFO "AC97 SoC Audio Codec %s\n", AC97_VERSION);
87 88
88 socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL); 89 socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
89 if (socdev->codec == NULL) 90 if (!socdev->codec)
90 return -ENOMEM; 91 return -ENOMEM;
91 codec = socdev->codec; 92 codec = socdev->codec;
92 mutex_init(&codec->mutex); 93 mutex_init(&codec->mutex);
@@ -102,17 +103,17 @@ static int ac97_soc_probe(struct platform_device *pdev)
102 103
103 /* register pcms */ 104 /* register pcms */
104 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1); 105 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
105 if(ret < 0) 106 if (ret < 0)
106 goto err; 107 goto err;
107 108
108 /* add codec as bus device for standard ac97 */ 109 /* add codec as bus device for standard ac97 */
109 ret = snd_ac97_bus(codec->card, 0, &soc_ac97_ops, NULL, &ac97_bus); 110 ret = snd_ac97_bus(codec->card, 0, &soc_ac97_ops, NULL, &ac97_bus);
110 if(ret < 0) 111 if (ret < 0)
111 goto bus_err; 112 goto bus_err;
112 113
113 memset(&ac97_template, 0, sizeof(struct snd_ac97_template)); 114 memset(&ac97_template, 0, sizeof(struct snd_ac97_template));
114 ret = snd_ac97_mixer(ac97_bus, &ac97_template, &codec->ac97); 115 ret = snd_ac97_mixer(ac97_bus, &ac97_template, &codec->ac97);
115 if(ret < 0) 116 if (ret < 0)
116 goto bus_err; 117 goto bus_err;
117 118
118 ret = snd_soc_register_card(socdev); 119 ret = snd_soc_register_card(socdev);
@@ -135,7 +136,7 @@ static int ac97_soc_remove(struct platform_device *pdev)
135 struct snd_soc_device *socdev = platform_get_drvdata(pdev); 136 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
136 struct snd_soc_codec *codec = socdev->codec; 137 struct snd_soc_codec *codec = socdev->codec;
137 138
138 if(codec == NULL) 139 if (!codec)
139 return 0; 140 return 0;
140 141
141 snd_soc_free_pcms(socdev); 142 snd_soc_free_pcms(socdev);
@@ -145,11 +146,10 @@ static int ac97_soc_remove(struct platform_device *pdev)
145 return 0; 146 return 0;
146} 147}
147 148
148struct snd_soc_codec_device soc_codec_dev_ac97= { 149struct snd_soc_codec_device soc_codec_dev_ac97 = {
149 .probe = ac97_soc_probe, 150 .probe = ac97_soc_probe,
150 .remove = ac97_soc_remove, 151 .remove = ac97_soc_remove,
151}; 152};
152
153EXPORT_SYMBOL_GPL(soc_codec_dev_ac97); 153EXPORT_SYMBOL_GPL(soc_codec_dev_ac97);
154 154
155MODULE_DESCRIPTION("Soc Generic AC97 driver"); 155MODULE_DESCRIPTION("Soc Generic AC97 driver");
diff --git a/sound/soc/codecs/cs4270.c b/sound/soc/codecs/cs4270.c
index bf2ab72d49bf..e73fcfd9f5cd 100644
--- a/sound/soc/codecs/cs4270.c
+++ b/sound/soc/codecs/cs4270.c
@@ -372,7 +372,7 @@ static int cs4270_hw_params(struct snd_pcm_substream *substream,
372 struct snd_soc_device *socdev = rtd->socdev; 372 struct snd_soc_device *socdev = rtd->socdev;
373 struct snd_soc_codec *codec = socdev->codec; 373 struct snd_soc_codec *codec = socdev->codec;
374 struct cs4270_private *cs4270 = codec->private_data; 374 struct cs4270_private *cs4270 = codec->private_data;
375 unsigned int ret = 0; 375 int ret;
376 unsigned int i; 376 unsigned int i;
377 unsigned int rate; 377 unsigned int rate;
378 unsigned int ratio; 378 unsigned int ratio;
diff --git a/sound/soc/codecs/tlv320aic3x.c b/sound/soc/codecs/tlv320aic3x.c
index 889a897d41ac..630684f4a0bc 100644
--- a/sound/soc/codecs/tlv320aic3x.c
+++ b/sound/soc/codecs/tlv320aic3x.c
@@ -660,33 +660,53 @@ struct aic3x_rate_divs {
660/* AIC3X codec mclk clock divider coefficients */ 660/* AIC3X codec mclk clock divider coefficients */
661static const struct aic3x_rate_divs aic3x_divs[] = { 661static const struct aic3x_rate_divs aic3x_divs[] = {
662 /* 8k */ 662 /* 8k */
663 {12000000, 8000, 48000, 0xa, 16, 3840},
664 {19200000, 8000, 48000, 0xa, 10, 2400},
663 {22579200, 8000, 48000, 0xa, 8, 7075}, 665 {22579200, 8000, 48000, 0xa, 8, 7075},
664 {33868800, 8000, 48000, 0xa, 5, 8049}, 666 {33868800, 8000, 48000, 0xa, 5, 8049},
665 /* 11.025k */ 667 /* 11.025k */
668 {12000000, 11025, 44100, 0x6, 15, 528},
669 {19200000, 11025, 44100, 0x6, 9, 4080},
666 {22579200, 11025, 44100, 0x6, 8, 0}, 670 {22579200, 11025, 44100, 0x6, 8, 0},
667 {33868800, 11025, 44100, 0x6, 5, 3333}, 671 {33868800, 11025, 44100, 0x6, 5, 3333},
668 /* 16k */ 672 /* 16k */
673 {12000000, 16000, 48000, 0x4, 16, 3840},
674 {19200000, 16000, 48000, 0x4, 10, 2400},
669 {22579200, 16000, 48000, 0x4, 8, 7075}, 675 {22579200, 16000, 48000, 0x4, 8, 7075},
670 {33868800, 16000, 48000, 0x4, 5, 8049}, 676 {33868800, 16000, 48000, 0x4, 5, 8049},
671 /* 22.05k */ 677 /* 22.05k */
678 {12000000, 22050, 44100, 0x2, 15, 528},
679 {19200000, 22050, 44100, 0x2, 9, 4080},
672 {22579200, 22050, 44100, 0x2, 8, 0}, 680 {22579200, 22050, 44100, 0x2, 8, 0},
673 {33868800, 22050, 44100, 0x2, 5, 3333}, 681 {33868800, 22050, 44100, 0x2, 5, 3333},
674 /* 32k */ 682 /* 32k */
683 {12000000, 32000, 48000, 0x1, 16, 3840},
684 {19200000, 32000, 48000, 0x1, 10, 2400},
675 {22579200, 32000, 48000, 0x1, 8, 7075}, 685 {22579200, 32000, 48000, 0x1, 8, 7075},
676 {33868800, 32000, 48000, 0x1, 5, 8049}, 686 {33868800, 32000, 48000, 0x1, 5, 8049},
677 /* 44.1k */ 687 /* 44.1k */
688 {12000000, 44100, 44100, 0x0, 15, 528},
689 {19200000, 44100, 44100, 0x0, 9, 4080},
678 {22579200, 44100, 44100, 0x0, 8, 0}, 690 {22579200, 44100, 44100, 0x0, 8, 0},
679 {33868800, 44100, 44100, 0x0, 5, 3333}, 691 {33868800, 44100, 44100, 0x0, 5, 3333},
680 /* 48k */ 692 /* 48k */
693 {12000000, 48000, 48000, 0x0, 16, 3840},
694 {19200000, 48000, 48000, 0x0, 10, 2400},
681 {22579200, 48000, 48000, 0x0, 8, 7075}, 695 {22579200, 48000, 48000, 0x0, 8, 7075},
682 {33868800, 48000, 48000, 0x0, 5, 8049}, 696 {33868800, 48000, 48000, 0x0, 5, 8049},
683 /* 64k */ 697 /* 64k */
698 {12000000, 64000, 96000, 0x1, 16, 3840},
699 {19200000, 64000, 96000, 0x1, 10, 2400},
684 {22579200, 64000, 96000, 0x1, 8, 7075}, 700 {22579200, 64000, 96000, 0x1, 8, 7075},
685 {33868800, 64000, 96000, 0x1, 5, 8049}, 701 {33868800, 64000, 96000, 0x1, 5, 8049},
686 /* 88.2k */ 702 /* 88.2k */
703 {12000000, 88200, 88200, 0x0, 15, 528},
704 {19200000, 88200, 88200, 0x0, 9, 4080},
687 {22579200, 88200, 88200, 0x0, 8, 0}, 705 {22579200, 88200, 88200, 0x0, 8, 0},
688 {33868800, 88200, 88200, 0x0, 5, 3333}, 706 {33868800, 88200, 88200, 0x0, 5, 3333},
689 /* 96k */ 707 /* 96k */
708 {12000000, 96000, 96000, 0x0, 16, 3840},
709 {19200000, 96000, 96000, 0x0, 10, 2400},
690 {22579200, 96000, 96000, 0x0, 8, 7075}, 710 {22579200, 96000, 96000, 0x0, 8, 7075},
691 {33868800, 96000, 96000, 0x0, 5, 8049}, 711 {33868800, 96000, 96000, 0x0, 5, 8049},
692}; 712};
@@ -807,6 +827,8 @@ static int aic3x_set_dai_sysclk(struct snd_soc_codec_dai *codec_dai,
807 struct aic3x_priv *aic3x = codec->private_data; 827 struct aic3x_priv *aic3x = codec->private_data;
808 828
809 switch (freq) { 829 switch (freq) {
830 case 12000000:
831 case 19200000:
810 case 22579200: 832 case 22579200:
811 case 33868800: 833 case 33868800:
812 aic3x->sysclk = freq; 834 aic3x->sysclk = freq;
diff --git a/sound/soc/codecs/wm8731.c b/sound/soc/codecs/wm8731.c
index 9c33fe874928..0cf9265fca8f 100644
--- a/sound/soc/codecs/wm8731.c
+++ b/sound/soc/codecs/wm8731.c
@@ -110,7 +110,7 @@ static int wm8731_write(struct snd_soc_codec *codec, unsigned int reg,
110 data[0] = (reg << 1) | ((value >> 8) & 0x0001); 110 data[0] = (reg << 1) | ((value >> 8) & 0x0001);
111 data[1] = value & 0x00ff; 111 data[1] = value & 0x00ff;
112 112
113 wm8731_write_reg_cache (codec, reg, value); 113 wm8731_write_reg_cache(codec, reg, value);
114 if (codec->hw_write(codec->control_data, data, 2) == 2) 114 if (codec->hw_write(codec->control_data, data, 2) == 2)
115 return 0; 115 return 0;
116 else 116 else
@@ -154,8 +154,10 @@ static int wm8731_add_controls(struct snd_soc_codec *codec)
154 int err, i; 154 int err, i;
155 155
156 for (i = 0; i < ARRAY_SIZE(wm8731_snd_controls); i++) { 156 for (i = 0; i < ARRAY_SIZE(wm8731_snd_controls); i++) {
157 if ((err = snd_ctl_add(codec->card, 157 err = snd_ctl_add(codec->card,
158 snd_soc_cnew(&wm8731_snd_controls[i],codec, NULL))) < 0) 158 snd_soc_cnew(&wm8731_snd_controls[i],
159 codec, NULL));
160 if (err < 0)
159 return err; 161 return err;
160 } 162 }
161 163
@@ -221,15 +223,13 @@ static int wm8731_add_widgets(struct snd_soc_codec *codec)
221{ 223{
222 int i; 224 int i;
223 225
224 for(i = 0; i < ARRAY_SIZE(wm8731_dapm_widgets); i++) { 226 for (i = 0; i < ARRAY_SIZE(wm8731_dapm_widgets); i++)
225 snd_soc_dapm_new_control(codec, &wm8731_dapm_widgets[i]); 227 snd_soc_dapm_new_control(codec, &wm8731_dapm_widgets[i]);
226 }
227 228
228 /* set up audio path interconnects */ 229 /* set up audio path interconnects */
229 for(i = 0; intercon[i][0] != NULL; i++) { 230 for (i = 0; intercon[i][0] != NULL; i++)
230 snd_soc_dapm_connect_input(codec, intercon[i][0], 231 snd_soc_dapm_connect_input(codec, intercon[i][0],
231 intercon[i][1], intercon[i][2]); 232 intercon[i][1], intercon[i][2]);
232 }
233 233
234 snd_soc_dapm_new_widgets(codec); 234 snd_soc_dapm_new_widgets(codec);
235 return 0; 235 return 0;
@@ -589,7 +589,7 @@ pcm_err:
589 589
590static struct snd_soc_device *wm8731_socdev; 590static struct snd_soc_device *wm8731_socdev;
591 591
592#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) 592#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
593 593
594/* 594/*
595 * WM8731 2 wire address is determined by GPIO5 595 * WM8731 2 wire address is determined by GPIO5
@@ -651,7 +651,7 @@ err:
651 651
652static int wm8731_i2c_detach(struct i2c_client *client) 652static int wm8731_i2c_detach(struct i2c_client *client)
653{ 653{
654 struct snd_soc_codec* codec = i2c_get_clientdata(client); 654 struct snd_soc_codec *codec = i2c_get_clientdata(client);
655 i2c_detach_client(client); 655 i2c_detach_client(client);
656 kfree(codec->reg_cache); 656 kfree(codec->reg_cache);
657 kfree(client); 657 kfree(client);
@@ -709,7 +709,7 @@ static int wm8731_probe(struct platform_device *pdev)
709 INIT_LIST_HEAD(&codec->dapm_paths); 709 INIT_LIST_HEAD(&codec->dapm_paths);
710 710
711 wm8731_socdev = socdev; 711 wm8731_socdev = socdev;
712#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) 712#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
713 if (setup->i2c_address) { 713 if (setup->i2c_address) {
714 normal_i2c[0] = setup->i2c_address; 714 normal_i2c[0] = setup->i2c_address;
715 codec->hw_write = (hw_write_t)i2c_master_send; 715 codec->hw_write = (hw_write_t)i2c_master_send;
@@ -734,7 +734,7 @@ static int wm8731_remove(struct platform_device *pdev)
734 734
735 snd_soc_free_pcms(socdev); 735 snd_soc_free_pcms(socdev);
736 snd_soc_dapm_free(socdev); 736 snd_soc_dapm_free(socdev);
737#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) 737#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
738 i2c_del_driver(&wm8731_i2c_driver); 738 i2c_del_driver(&wm8731_i2c_driver);
739#endif 739#endif
740 kfree(codec->private_data); 740 kfree(codec->private_data);
@@ -749,7 +749,6 @@ struct snd_soc_codec_device soc_codec_dev_wm8731 = {
749 .suspend = wm8731_suspend, 749 .suspend = wm8731_suspend,
750 .resume = wm8731_resume, 750 .resume = wm8731_resume,
751}; 751};
752
753EXPORT_SYMBOL_GPL(soc_codec_dev_wm8731); 752EXPORT_SYMBOL_GPL(soc_codec_dev_wm8731);
754 753
755MODULE_DESCRIPTION("ASoC WM8731 driver"); 754MODULE_DESCRIPTION("ASoC WM8731 driver");
diff --git a/sound/soc/codecs/wm8750.c b/sound/soc/codecs/wm8750.c
index 77a857b997a2..16cd5d4d5ad9 100644
--- a/sound/soc/codecs/wm8750.c
+++ b/sound/soc/codecs/wm8750.c
@@ -110,7 +110,7 @@ static int wm8750_write(struct snd_soc_codec *codec, unsigned int reg,
110 data[0] = (reg << 1) | ((value >> 8) & 0x0001); 110 data[0] = (reg << 1) | ((value >> 8) & 0x0001);
111 data[1] = value & 0x00ff; 111 data[1] = value & 0x00ff;
112 112
113 wm8750_write_reg_cache (codec, reg, value); 113 wm8750_write_reg_cache(codec, reg, value);
114 if (codec->hw_write(codec->control_data, data, 2) == 2) 114 if (codec->hw_write(codec->control_data, data, 2) == 2)
115 return 0; 115 return 0;
116 else 116 else
@@ -257,7 +257,8 @@ static int wm8750_add_controls(struct snd_soc_codec *codec)
257 257
258 for (i = 0; i < ARRAY_SIZE(wm8750_snd_controls); i++) { 258 for (i = 0; i < ARRAY_SIZE(wm8750_snd_controls); i++) {
259 err = snd_ctl_add(codec->card, 259 err = snd_ctl_add(codec->card,
260 snd_soc_cnew(&wm8750_snd_controls[i],codec, NULL)); 260 snd_soc_cnew(&wm8750_snd_controls[i],
261 codec, NULL));
261 if (err < 0) 262 if (err < 0)
262 return err; 263 return err;
263 } 264 }
@@ -478,15 +479,13 @@ static int wm8750_add_widgets(struct snd_soc_codec *codec)
478{ 479{
479 int i; 480 int i;
480 481
481 for(i = 0; i < ARRAY_SIZE(wm8750_dapm_widgets); i++) { 482 for (i = 0; i < ARRAY_SIZE(wm8750_dapm_widgets); i++)
482 snd_soc_dapm_new_control(codec, &wm8750_dapm_widgets[i]); 483 snd_soc_dapm_new_control(codec, &wm8750_dapm_widgets[i]);
483 }
484 484
485 /* set up audio path audio_mapnects */ 485 /* set up audio path audio_mapnects */
486 for(i = 0; audio_map[i][0] != NULL; i++) { 486 for (i = 0; audio_map[i][0] != NULL; i++)
487 snd_soc_dapm_connect_input(codec, audio_map[i][0], 487 snd_soc_dapm_connect_input(codec, audio_map[i][0],
488 audio_map[i][1], audio_map[i][2]); 488 audio_map[i][1], audio_map[i][2]);
489 }
490 489
491 snd_soc_dapm_new_widgets(codec); 490 snd_soc_dapm_new_widgets(codec);
492 return 0; 491 return 0;
@@ -714,8 +713,8 @@ static int wm8750_dapm_event(struct snd_soc_codec *codec, int event)
714} 713}
715 714
716#define WM8750_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\ 715#define WM8750_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
717 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \ 716 SNDRV_PCM_RATE_16000 | SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 | \
718 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000) 717 SNDRV_PCM_RATE_48000 | SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000)
719 718
720#define WM8750_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\ 719#define WM8750_FORMATS (SNDRV_PCM_FMTBIT_S16_LE | SNDRV_PCM_FMTBIT_S20_3LE |\
721 SNDRV_PCM_FMTBIT_S24_LE) 720 SNDRV_PCM_FMTBIT_S24_LE)
@@ -784,7 +783,8 @@ static int wm8750_resume(struct platform_device *pdev)
784 if (codec->suspend_dapm_state == SNDRV_CTL_POWER_D0) { 783 if (codec->suspend_dapm_state == SNDRV_CTL_POWER_D0) {
785 wm8750_dapm_event(codec, SNDRV_CTL_POWER_D2); 784 wm8750_dapm_event(codec, SNDRV_CTL_POWER_D2);
786 codec->dapm_state = SNDRV_CTL_POWER_D0; 785 codec->dapm_state = SNDRV_CTL_POWER_D0;
787 schedule_delayed_work(&codec->delayed_work, msecs_to_jiffies(1000)); 786 schedule_delayed_work(&codec->delayed_work,
787 msecs_to_jiffies(1000));
788 } 788 }
789 789
790 return 0; 790 return 0;
@@ -864,7 +864,7 @@ pcm_err:
864 around */ 864 around */
865static struct snd_soc_device *wm8750_socdev; 865static struct snd_soc_device *wm8750_socdev;
866 866
867#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) 867#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
868 868
869/* 869/*
870 * WM8731 2 wire address is determined by GPIO5 870 * WM8731 2 wire address is determined by GPIO5
@@ -979,8 +979,8 @@ static int wm8750_probe(struct platform_device *pdev)
979 INIT_LIST_HEAD(&codec->dapm_paths); 979 INIT_LIST_HEAD(&codec->dapm_paths);
980 wm8750_socdev = socdev; 980 wm8750_socdev = socdev;
981 INIT_DELAYED_WORK(&codec->delayed_work, wm8750_work); 981 INIT_DELAYED_WORK(&codec->delayed_work, wm8750_work);
982 982
983#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) 983#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
984 if (setup->i2c_address) { 984 if (setup->i2c_address) {
985 normal_i2c[0] = setup->i2c_address; 985 normal_i2c[0] = setup->i2c_address;
986 codec->hw_write = (hw_write_t)i2c_master_send; 986 codec->hw_write = (hw_write_t)i2c_master_send;
@@ -1025,7 +1025,7 @@ static int wm8750_remove(struct platform_device *pdev)
1025 run_delayed_work(&codec->delayed_work); 1025 run_delayed_work(&codec->delayed_work);
1026 snd_soc_free_pcms(socdev); 1026 snd_soc_free_pcms(socdev);
1027 snd_soc_dapm_free(socdev); 1027 snd_soc_dapm_free(socdev);
1028#if defined (CONFIG_I2C) || defined (CONFIG_I2C_MODULE) 1028#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
1029 i2c_del_driver(&wm8750_i2c_driver); 1029 i2c_del_driver(&wm8750_i2c_driver);
1030#endif 1030#endif
1031 kfree(codec->private_data); 1031 kfree(codec->private_data);
@@ -1040,7 +1040,6 @@ struct snd_soc_codec_device soc_codec_dev_wm8750 = {
1040 .suspend = wm8750_suspend, 1040 .suspend = wm8750_suspend,
1041 .resume = wm8750_resume, 1041 .resume = wm8750_resume,
1042}; 1042};
1043
1044EXPORT_SYMBOL_GPL(soc_codec_dev_wm8750); 1043EXPORT_SYMBOL_GPL(soc_codec_dev_wm8750);
1045 1044
1046MODULE_DESCRIPTION("ASoC WM8750 driver"); 1045MODULE_DESCRIPTION("ASoC WM8750 driver");
diff --git a/sound/soc/codecs/wm8753.c b/sound/soc/codecs/wm8753.c
index ddd9c71b3fde..76a5c7b05dfb 100644
--- a/sound/soc/codecs/wm8753.c
+++ b/sound/soc/codecs/wm8753.c
@@ -198,6 +198,7 @@ static const char *wm8753_mic_sel[] = {"Mic 1", "Mic 2", "Mic 3"};
198static const char *wm8753_dai_mode[] = {"DAI 0", "DAI 1", "DAI 2", "DAI 3"}; 198static const char *wm8753_dai_mode[] = {"DAI 0", "DAI 1", "DAI 2", "DAI 3"};
199static const char *wm8753_dat_sel[] = {"Stereo", "Left ADC", "Right ADC", 199static const char *wm8753_dat_sel[] = {"Stereo", "Left ADC", "Right ADC",
200 "Channel Swap"}; 200 "Channel Swap"};
201static const char *wm8753_rout2_phase[] = {"Non Inverted", "Inverted"};
201 202
202static const struct soc_enum wm8753_enum[] = { 203static const struct soc_enum wm8753_enum[] = {
203SOC_ENUM_SINGLE(WM8753_BASS, 7, 2, wm8753_base), 204SOC_ENUM_SINGLE(WM8753_BASS, 7, 2, wm8753_base),
@@ -228,6 +229,7 @@ SOC_ENUM_SINGLE(WM8753_ADC, 4, 2, wm8753_adc_filter),
228SOC_ENUM_SINGLE(WM8753_MICBIAS, 6, 3, wm8753_mic_sel), 229SOC_ENUM_SINGLE(WM8753_MICBIAS, 6, 3, wm8753_mic_sel),
229SOC_ENUM_SINGLE(WM8753_IOCTL, 2, 4, wm8753_dai_mode), 230SOC_ENUM_SINGLE(WM8753_IOCTL, 2, 4, wm8753_dai_mode),
230SOC_ENUM_SINGLE(WM8753_ADC, 7, 4, wm8753_dat_sel), 231SOC_ENUM_SINGLE(WM8753_ADC, 7, 4, wm8753_dat_sel),
232SOC_ENUM_SINGLE(WM8753_OUTCTL, 2, 2, wm8753_rout2_phase),
231}; 233};
232 234
233 235
@@ -279,7 +281,7 @@ SOC_DOUBLE_R("Speaker Playback ZC Switch", WM8753_LOUT2V, WM8753_ROUT2V, 7, 1, 0
279 281
280SOC_SINGLE("Mono Bypass Playback Volume", WM8753_MOUTM1, 4, 7, 1), 282SOC_SINGLE("Mono Bypass Playback Volume", WM8753_MOUTM1, 4, 7, 1),
281SOC_SINGLE("Mono Sidetone Playback Volume", WM8753_MOUTM2, 4, 7, 1), 283SOC_SINGLE("Mono Sidetone Playback Volume", WM8753_MOUTM2, 4, 7, 1),
282SOC_SINGLE("Mono Voice Playback Volume", WM8753_MOUTM2, 4, 7, 1), 284SOC_SINGLE("Mono Voice Playback Volume", WM8753_MOUTM2, 0, 7, 1),
283SOC_SINGLE("Mono Playback ZC Switch", WM8753_MOUTV, 7, 1, 0), 285SOC_SINGLE("Mono Playback ZC Switch", WM8753_MOUTV, 7, 1, 0),
284 286
285SOC_ENUM("Bass Boost", wm8753_enum[0]), 287SOC_ENUM("Bass Boost", wm8753_enum[0]),
@@ -330,6 +332,7 @@ SOC_SINGLE("Mic1 Capture Volume", WM8753_INCTL1, 5, 3, 0),
330SOC_ENUM_EXT("DAI Mode", wm8753_enum[26], wm8753_get_dai, wm8753_set_dai), 332SOC_ENUM_EXT("DAI Mode", wm8753_enum[26], wm8753_get_dai, wm8753_set_dai),
331 333
332SOC_ENUM("ADC Data Select", wm8753_enum[27]), 334SOC_ENUM("ADC Data Select", wm8753_enum[27]),
335SOC_ENUM("ROUT2 Phase", wm8753_enum[28]),
333}; 336};
334 337
335/* add non dapm controls */ 338/* add non dapm controls */
diff --git a/sound/soc/codecs/wm9712.c b/sound/soc/codecs/wm9712.c
index 524f7450804f..d2d79e182a45 100644
--- a/sound/soc/codecs/wm9712.c
+++ b/sound/soc/codecs/wm9712.c
@@ -581,22 +581,14 @@ static int wm9712_dapm_event(struct snd_soc_codec *codec, int event)
581 581
582 switch (event) { 582 switch (event) {
583 case SNDRV_CTL_POWER_D0: /* full On */ 583 case SNDRV_CTL_POWER_D0: /* full On */
584 /* liam - maybe enable thermal shutdown */
585 reg = ac97_read(codec, AC97_EXTENDED_MID) & 0xdfff;
586 ac97_write(codec, AC97_EXTENDED_MID, reg);
587 break;
588 case SNDRV_CTL_POWER_D1: /* partial On */ 584 case SNDRV_CTL_POWER_D1: /* partial On */
589 case SNDRV_CTL_POWER_D2: /* partial On */ 585 case SNDRV_CTL_POWER_D2: /* partial On */
590 break; 586 break;
591 case SNDRV_CTL_POWER_D3hot: /* Off, with power */ 587 case SNDRV_CTL_POWER_D3hot: /* Off, with power */
592 /* enable master bias and vmid */
593 reg = ac97_read(codec, AC97_EXTENDED_MID) & 0xbbff;
594 ac97_write(codec, AC97_EXTENDED_MID, reg);
595 ac97_write(codec, AC97_POWERDOWN, 0x0000); 588 ac97_write(codec, AC97_POWERDOWN, 0x0000);
596 break; 589 break;
597 case SNDRV_CTL_POWER_D3cold: /* Off, without power */ 590 case SNDRV_CTL_POWER_D3cold: /* Off, without power */
598 /* disable everything including AC link */ 591 /* disable everything including AC link */
599 ac97_write(codec, AC97_EXTENDED_MID, 0xffff);
600 ac97_write(codec, AC97_EXTENDED_MSTATUS, 0xffff); 592 ac97_write(codec, AC97_EXTENDED_MSTATUS, 0xffff);
601 ac97_write(codec, AC97_POWERDOWN, 0xffff); 593 ac97_write(codec, AC97_POWERDOWN, 0xffff);
602 break; 594 break;
diff --git a/sound/soc/codecs/wm9713.c b/sound/soc/codecs/wm9713.c
new file mode 100644
index 000000000000..1f241161445c
--- /dev/null
+++ b/sound/soc/codecs/wm9713.c
@@ -0,0 +1,1300 @@
1/*
2 * wm9713.c -- ALSA Soc WM9713 codec support
3 *
4 * Copyright 2006 Wolfson Microelectronics PLC.
5 * Author: Liam Girdwood
6 * liam.girdwood@wolfsonmicro.com or linux@wolfsonmicro.com
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
12 *
13 * Revision history
14 * 4th Feb 2006 Initial version.
15 *
16 * Features:-
17 *
18 * o Support for AC97 Codec, Voice DAC and Aux DAC
19 * o Support for DAPM
20 */
21
22#include <linux/init.h>
23#include <linux/module.h>
24#include <linux/device.h>
25#include <sound/core.h>
26#include <sound/pcm.h>
27#include <sound/ac97_codec.h>
28#include <sound/initval.h>
29#include <sound/pcm_params.h>
30#include <sound/soc.h>
31#include <sound/soc-dapm.h>
32
33#include "wm9713.h"
34
35#define WM9713_VERSION "0.15"
36
37struct wm9713_priv {
38 u32 pll_in; /* PLL input frequency */
39 u32 pll_out; /* PLL output frequency */
40};
41
42static unsigned int ac97_read(struct snd_soc_codec *codec,
43 unsigned int reg);
44static int ac97_write(struct snd_soc_codec *codec,
45 unsigned int reg, unsigned int val);
46
47/*
48 * WM9713 register cache
49 * Reg 0x3c bit 15 is used by touch driver.
50 */
51static const u16 wm9713_reg[] = {
52 0x6174, 0x8080, 0x8080, 0x8080,
53 0xc880, 0xe808, 0xe808, 0x0808,
54 0x00da, 0x8000, 0xd600, 0xaaa0,
55 0xaaa0, 0xaaa0, 0x0000, 0x0000,
56 0x0f0f, 0x0040, 0x0000, 0x7f00,
57 0x0405, 0x0410, 0xbb80, 0xbb80,
58 0x0000, 0xbb80, 0x0000, 0x4523,
59 0x0000, 0x2000, 0x7eff, 0xffff,
60 0x0000, 0x0000, 0x0080, 0x0000,
61 0x0000, 0x0000, 0xfffe, 0xffff,
62 0x0000, 0x0000, 0x0000, 0xfffe,
63 0x4000, 0x0000, 0x0000, 0x0000,
64 0xb032, 0x3e00, 0x0000, 0x0000,
65 0x0000, 0x0000, 0x0000, 0x0000,
66 0x0000, 0x0000, 0x0000, 0x0006,
67 0x0001, 0x0000, 0x574d, 0x4c13,
68 0x0000, 0x0000, 0x0000
69};
70
71/* virtual HP mixers regs */
72#define HPL_MIXER 0x80
73#define HPR_MIXER 0x82
74#define MICB_MUX 0x82
75
76static const char *wm9713_mic_mixer[] = {"Stereo", "Mic 1", "Mic 2", "Mute"};
77static const char *wm9713_rec_mux[] = {"Stereo", "Left", "Right", "Mute"};
78static const char *wm9713_rec_src[] =
79 {"Mic 1", "Mic 2", "Line", "Mono In", "Headphone", "Speaker",
80 "Mono Out", "Zh"};
81static const char *wm9713_rec_gain[] = {"+1.5dB Steps", "+0.75dB Steps"};
82static const char *wm9713_alc_select[] = {"None", "Left", "Right", "Stereo"};
83static const char *wm9713_mono_pga[] = {"Vmid", "Zh", "Mono", "Inv",
84 "Mono Vmid", "Inv Vmid"};
85static const char *wm9713_spk_pga[] =
86 {"Vmid", "Zh", "Headphone", "Speaker", "Inv", "Headphone Vmid",
87 "Speaker Vmid", "Inv Vmid"};
88static const char *wm9713_hp_pga[] = {"Vmid", "Zh", "Headphone",
89 "Headphone Vmid"};
90static const char *wm9713_out3_pga[] = {"Vmid", "Zh", "Inv 1", "Inv 1 Vmid"};
91static const char *wm9713_out4_pga[] = {"Vmid", "Zh", "Inv 2", "Inv 2 Vmid"};
92static const char *wm9713_dac_inv[] =
93 {"Off", "Mono", "Speaker", "Left Headphone", "Right Headphone",
94 "Headphone Mono", "NC", "Vmid"};
95static const char *wm9713_bass[] = {"Linear Control", "Adaptive Boost"};
96static const char *wm9713_ng_type[] = {"Constant Gain", "Mute"};
97static const char *wm9713_mic_select[] = {"Mic 1", "Mic 2 A", "Mic 2 B"};
98static const char *wm9713_micb_select[] = {"MPB", "MPA"};
99
100static const struct soc_enum wm9713_enum[] = {
101SOC_ENUM_SINGLE(AC97_LINE, 3, 4, wm9713_mic_mixer), /* record mic mixer 0 */
102SOC_ENUM_SINGLE(AC97_VIDEO, 14, 4, wm9713_rec_mux), /* record mux hp 1 */
103SOC_ENUM_SINGLE(AC97_VIDEO, 9, 4, wm9713_rec_mux), /* record mux mono 2 */
104SOC_ENUM_SINGLE(AC97_VIDEO, 3, 8, wm9713_rec_src), /* record mux left 3 */
105SOC_ENUM_SINGLE(AC97_VIDEO, 0, 8, wm9713_rec_src), /* record mux right 4*/
106SOC_ENUM_DOUBLE(AC97_CD, 14, 6, 2, wm9713_rec_gain), /* record step size 5 */
107SOC_ENUM_SINGLE(AC97_PCI_SVID, 14, 4, wm9713_alc_select), /* alc source select 6*/
108SOC_ENUM_SINGLE(AC97_REC_GAIN, 14, 4, wm9713_mono_pga), /* mono input select 7 */
109SOC_ENUM_SINGLE(AC97_REC_GAIN, 11, 8, wm9713_spk_pga), /* speaker left input select 8 */
110SOC_ENUM_SINGLE(AC97_REC_GAIN, 8, 8, wm9713_spk_pga), /* speaker right input select 9 */
111SOC_ENUM_SINGLE(AC97_REC_GAIN, 6, 3, wm9713_hp_pga), /* headphone left input 10 */
112SOC_ENUM_SINGLE(AC97_REC_GAIN, 4, 3, wm9713_hp_pga), /* headphone right input 11 */
113SOC_ENUM_SINGLE(AC97_REC_GAIN, 2, 4, wm9713_out3_pga), /* out 3 source 12 */
114SOC_ENUM_SINGLE(AC97_REC_GAIN, 0, 4, wm9713_out4_pga), /* out 4 source 13 */
115SOC_ENUM_SINGLE(AC97_REC_GAIN_MIC, 13, 8, wm9713_dac_inv), /* dac invert 1 14 */
116SOC_ENUM_SINGLE(AC97_REC_GAIN_MIC, 10, 8, wm9713_dac_inv), /* dac invert 2 15 */
117SOC_ENUM_SINGLE(AC97_GENERAL_PURPOSE, 15, 2, wm9713_bass), /* bass control 16 */
118SOC_ENUM_SINGLE(AC97_PCI_SVID, 5, 2, wm9713_ng_type), /* noise gate type 17 */
119SOC_ENUM_SINGLE(AC97_3D_CONTROL, 12, 3, wm9713_mic_select), /* mic selection 18 */
120SOC_ENUM_SINGLE(MICB_MUX, 0, 2, wm9713_micb_select), /* mic selection 19 */
121};
122
123static const struct snd_kcontrol_new wm9713_snd_ac97_controls[] = {
124SOC_DOUBLE("Speaker Playback Volume", AC97_MASTER, 8, 0, 31, 1),
125SOC_DOUBLE("Speaker Playback Switch", AC97_MASTER, 15, 7, 1, 1),
126SOC_DOUBLE("Headphone Playback Volume", AC97_HEADPHONE, 8, 0, 31, 1),
127SOC_DOUBLE("Headphone Playback Switch", AC97_HEADPHONE, 15, 7, 1, 1),
128SOC_DOUBLE("Line In Volume", AC97_PC_BEEP, 8, 0, 31, 1),
129SOC_DOUBLE("PCM Playback Volume", AC97_PHONE, 8, 0, 31, 1),
130SOC_SINGLE("Mic 1 Volume", AC97_MIC, 8, 31, 1),
131SOC_SINGLE("Mic 2 Volume", AC97_MIC, 0, 31, 1),
132
133SOC_SINGLE("Mic Boost (+20dB) Switch", AC97_LINE, 5, 1, 0),
134SOC_SINGLE("Mic Headphone Mixer Volume", AC97_LINE, 0, 7, 1),
135
136SOC_SINGLE("Capture Switch", AC97_CD, 15, 1, 1),
137SOC_ENUM("Capture Volume Steps", wm9713_enum[5]),
138SOC_DOUBLE("Capture Volume", AC97_CD, 8, 0, 31, 0),
139SOC_SINGLE("Capture ZC Switch", AC97_CD, 7, 1, 0),
140
141SOC_SINGLE("Capture to Headphone Volume", AC97_VIDEO, 11, 7, 1),
142SOC_SINGLE("Capture to Mono Boost (+20dB) Switch", AC97_VIDEO, 8, 1, 0),
143SOC_SINGLE("Capture ADC Boost (+20dB) Switch", AC97_VIDEO, 6, 1, 0),
144
145SOC_SINGLE("ALC Target Volume", AC97_CODEC_CLASS_REV, 12, 15, 0),
146SOC_SINGLE("ALC Hold Time", AC97_CODEC_CLASS_REV, 8, 15, 0),
147SOC_SINGLE("ALC Decay Time ", AC97_CODEC_CLASS_REV, 4, 15, 0),
148SOC_SINGLE("ALC Attack Time", AC97_CODEC_CLASS_REV, 0, 15, 0),
149SOC_ENUM("ALC Function", wm9713_enum[6]),
150SOC_SINGLE("ALC Max Volume", AC97_PCI_SVID, 11, 7, 0),
151SOC_SINGLE("ALC ZC Timeout", AC97_PCI_SVID, 9, 3, 0),
152SOC_SINGLE("ALC ZC Switch", AC97_PCI_SVID, 8, 1, 0),
153SOC_SINGLE("ALC NG Switch", AC97_PCI_SVID, 7, 1, 0),
154SOC_ENUM("ALC NG Type", wm9713_enum[17]),
155SOC_SINGLE("ALC NG Threshold", AC97_PCI_SVID, 0, 31, 0),
156
157SOC_DOUBLE("Speaker Playback ZC Switch", AC97_MASTER, 14, 6, 1, 0),
158SOC_DOUBLE("Headphone Playback ZC Switch", AC97_HEADPHONE, 14, 6, 1, 0),
159
160SOC_SINGLE("Out4 Playback Switch", AC97_MASTER_MONO, 15, 1, 1),
161SOC_SINGLE("Out4 Playback ZC Switch", AC97_MASTER_MONO, 14, 1, 0),
162SOC_SINGLE("Out4 Playback Volume", AC97_MASTER_MONO, 8, 63, 1),
163
164SOC_SINGLE("Out3 Playback Switch", AC97_MASTER_MONO, 7, 1, 1),
165SOC_SINGLE("Out3 Playback ZC Switch", AC97_MASTER_MONO, 6, 1, 0),
166SOC_SINGLE("Out3 Playback Volume", AC97_MASTER_MONO, 0, 63, 1),
167
168SOC_SINGLE("Mono Capture Volume", AC97_MASTER_TONE, 8, 31, 1),
169SOC_SINGLE("Mono Playback Switch", AC97_MASTER_TONE, 7, 1, 1),
170SOC_SINGLE("Mono Playback ZC Switch", AC97_MASTER_TONE, 6, 1, 0),
171SOC_SINGLE("Mono Playback Volume", AC97_MASTER_TONE, 0, 31, 1),
172
173SOC_SINGLE("PC Beep Playback Headphone Volume", AC97_AUX, 12, 7, 1),
174SOC_SINGLE("PC Beep Playback Speaker Volume", AC97_AUX, 8, 7, 1),
175SOC_SINGLE("PC Beep Playback Mono Volume", AC97_AUX, 4, 7, 1),
176
177SOC_SINGLE("Voice Playback Headphone Volume", AC97_PCM, 12, 7, 1),
178SOC_SINGLE("Voice Playback Master Volume", AC97_PCM, 8, 7, 1),
179SOC_SINGLE("Voice Playback Mono Volume", AC97_PCM, 4, 7, 1),
180
181SOC_SINGLE("Aux Playback Headphone Volume", AC97_REC_SEL, 12, 7, 1),
182SOC_SINGLE("Aux Playback Master Volume", AC97_REC_SEL, 8, 7, 1),
183SOC_SINGLE("Aux Playback Mono Volume", AC97_REC_SEL, 4, 7, 1),
184
185SOC_ENUM("Bass Control", wm9713_enum[16]),
186SOC_SINGLE("Bass Cut-off Switch", AC97_GENERAL_PURPOSE, 12, 1, 1),
187SOC_SINGLE("Tone Cut-off Switch", AC97_GENERAL_PURPOSE, 4, 1, 1),
188SOC_SINGLE("Playback Attenuate (-6dB) Switch", AC97_GENERAL_PURPOSE, 6, 1, 0),
189SOC_SINGLE("Bass Volume", AC97_GENERAL_PURPOSE, 8, 15, 1),
190SOC_SINGLE("Tone Volume", AC97_GENERAL_PURPOSE, 0, 15, 1),
191
192SOC_SINGLE("3D Upper Cut-off Switch", AC97_REC_GAIN_MIC, 5, 1, 0),
193SOC_SINGLE("3D Lower Cut-off Switch", AC97_REC_GAIN_MIC, 4, 1, 0),
194SOC_SINGLE("3D Depth", AC97_REC_GAIN_MIC, 0, 15, 1),
195};
196
197/* add non dapm controls */
198static int wm9713_add_controls(struct snd_soc_codec *codec)
199{
200 int err, i;
201
202 for (i = 0; i < ARRAY_SIZE(wm9713_snd_ac97_controls); i++) {
203 err = snd_ctl_add(codec->card,
204 snd_soc_cnew(&wm9713_snd_ac97_controls[i],
205 codec, NULL));
206 if (err < 0)
207 return err;
208 }
209 return 0;
210}
211
212/* We have to create a fake left and right HP mixers because
213 * the codec only has a single control that is shared by both channels.
214 * This makes it impossible to determine the audio path using the current
215 * register map, thus we add a new (virtual) register to help determine the
216 * audio route within the device.
217 */
218static int mixer_event(struct snd_soc_dapm_widget *w,
219 struct snd_kcontrol *kcontrol, int event)
220{
221 u16 l, r, beep, tone, phone, rec, pcm, aux;
222
223 l = ac97_read(w->codec, HPL_MIXER);
224 r = ac97_read(w->codec, HPR_MIXER);
225 beep = ac97_read(w->codec, AC97_PC_BEEP);
226 tone = ac97_read(w->codec, AC97_MASTER_TONE);
227 phone = ac97_read(w->codec, AC97_PHONE);
228 rec = ac97_read(w->codec, AC97_REC_SEL);
229 pcm = ac97_read(w->codec, AC97_PCM);
230 aux = ac97_read(w->codec, AC97_AUX);
231
232 if (event & SND_SOC_DAPM_PRE_REG)
233 return 0;
234 if ((l & 0x1) || (r & 0x1))
235 ac97_write(w->codec, AC97_PC_BEEP, beep & 0x7fff);
236 else
237 ac97_write(w->codec, AC97_PC_BEEP, beep | 0x8000);
238
239 if ((l & 0x2) || (r & 0x2))
240 ac97_write(w->codec, AC97_MASTER_TONE, tone & 0x7fff);
241 else
242 ac97_write(w->codec, AC97_MASTER_TONE, tone | 0x8000);
243
244 if ((l & 0x4) || (r & 0x4))
245 ac97_write(w->codec, AC97_PHONE, phone & 0x7fff);
246 else
247 ac97_write(w->codec, AC97_PHONE, phone | 0x8000);
248
249 if ((l & 0x8) || (r & 0x8))
250 ac97_write(w->codec, AC97_REC_SEL, rec & 0x7fff);
251 else
252 ac97_write(w->codec, AC97_REC_SEL, rec | 0x8000);
253
254 if ((l & 0x10) || (r & 0x10))
255 ac97_write(w->codec, AC97_PCM, pcm & 0x7fff);
256 else
257 ac97_write(w->codec, AC97_PCM, pcm | 0x8000);
258
259 if ((l & 0x20) || (r & 0x20))
260 ac97_write(w->codec, AC97_AUX, aux & 0x7fff);
261 else
262 ac97_write(w->codec, AC97_AUX, aux | 0x8000);
263
264 return 0;
265}
266
267/* Left Headphone Mixers */
268static const struct snd_kcontrol_new wm9713_hpl_mixer_controls[] = {
269SOC_DAPM_SINGLE("PC Beep Playback Switch", HPL_MIXER, 5, 1, 0),
270SOC_DAPM_SINGLE("Voice Playback Switch", HPL_MIXER, 4, 1, 0),
271SOC_DAPM_SINGLE("Aux Playback Switch", HPL_MIXER, 3, 1, 0),
272SOC_DAPM_SINGLE("PCM Playback Switch", HPL_MIXER, 2, 1, 0),
273SOC_DAPM_SINGLE("MonoIn Playback Switch", HPL_MIXER, 1, 1, 0),
274SOC_DAPM_SINGLE("Bypass Playback Switch", HPL_MIXER, 0, 1, 0),
275};
276
277/* Right Headphone Mixers */
278static const struct snd_kcontrol_new wm9713_hpr_mixer_controls[] = {
279SOC_DAPM_SINGLE("PC Beep Playback Switch", HPR_MIXER, 5, 1, 0),
280SOC_DAPM_SINGLE("Voice Playback Switch", HPR_MIXER, 4, 1, 0),
281SOC_DAPM_SINGLE("Aux Playback Switch", HPR_MIXER, 3, 1, 0),
282SOC_DAPM_SINGLE("PCM Playback Switch", HPR_MIXER, 2, 1, 0),
283SOC_DAPM_SINGLE("MonoIn Playback Switch", HPR_MIXER, 1, 1, 0),
284SOC_DAPM_SINGLE("Bypass Playback Switch", HPR_MIXER, 0, 1, 0),
285};
286
287/* headphone capture mux */
288static const struct snd_kcontrol_new wm9713_hp_rec_mux_controls =
289SOC_DAPM_ENUM("Route", wm9713_enum[1]);
290
291/* headphone mic mux */
292static const struct snd_kcontrol_new wm9713_hp_mic_mux_controls =
293SOC_DAPM_ENUM("Route", wm9713_enum[0]);
294
295/* Speaker Mixer */
296static const struct snd_kcontrol_new wm9713_speaker_mixer_controls[] = {
297SOC_DAPM_SINGLE("PC Beep Playback Switch", AC97_AUX, 11, 1, 1),
298SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 11, 1, 1),
299SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 11, 1, 1),
300SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 14, 1, 1),
301SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE, 14, 1, 1),
302SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP, 14, 1, 1),
303};
304
305/* Mono Mixer */
306static const struct snd_kcontrol_new wm9713_mono_mixer_controls[] = {
307SOC_DAPM_SINGLE("PC Beep Playback Switch", AC97_AUX, 7, 1, 1),
308SOC_DAPM_SINGLE("Voice Playback Switch", AC97_PCM, 7, 1, 1),
309SOC_DAPM_SINGLE("Aux Playback Switch", AC97_REC_SEL, 7, 1, 1),
310SOC_DAPM_SINGLE("PCM Playback Switch", AC97_PHONE, 13, 1, 1),
311SOC_DAPM_SINGLE("MonoIn Playback Switch", AC97_MASTER_TONE, 13, 1, 1),
312SOC_DAPM_SINGLE("Bypass Playback Switch", AC97_PC_BEEP, 13, 1, 1),
313SOC_DAPM_SINGLE("Mic 1 Sidetone Switch", AC97_LINE, 7, 1, 1),
314SOC_DAPM_SINGLE("Mic 2 Sidetone Switch", AC97_LINE, 6, 1, 1),
315};
316
317/* mono mic mux */
318static const struct snd_kcontrol_new wm9713_mono_mic_mux_controls =
319SOC_DAPM_ENUM("Route", wm9713_enum[2]);
320
321/* mono output mux */
322static const struct snd_kcontrol_new wm9713_mono_mux_controls =
323SOC_DAPM_ENUM("Route", wm9713_enum[7]);
324
325/* speaker left output mux */
326static const struct snd_kcontrol_new wm9713_hp_spkl_mux_controls =
327SOC_DAPM_ENUM("Route", wm9713_enum[8]);
328
329/* speaker right output mux */
330static const struct snd_kcontrol_new wm9713_hp_spkr_mux_controls =
331SOC_DAPM_ENUM("Route", wm9713_enum[9]);
332
333/* headphone left output mux */
334static const struct snd_kcontrol_new wm9713_hpl_out_mux_controls =
335SOC_DAPM_ENUM("Route", wm9713_enum[10]);
336
337/* headphone right output mux */
338static const struct snd_kcontrol_new wm9713_hpr_out_mux_controls =
339SOC_DAPM_ENUM("Route", wm9713_enum[11]);
340
341/* Out3 mux */
342static const struct snd_kcontrol_new wm9713_out3_mux_controls =
343SOC_DAPM_ENUM("Route", wm9713_enum[12]);
344
345/* Out4 mux */
346static const struct snd_kcontrol_new wm9713_out4_mux_controls =
347SOC_DAPM_ENUM("Route", wm9713_enum[13]);
348
349/* DAC inv mux 1 */
350static const struct snd_kcontrol_new wm9713_dac_inv1_mux_controls =
351SOC_DAPM_ENUM("Route", wm9713_enum[14]);
352
353/* DAC inv mux 2 */
354static const struct snd_kcontrol_new wm9713_dac_inv2_mux_controls =
355SOC_DAPM_ENUM("Route", wm9713_enum[15]);
356
357/* Capture source left */
358static const struct snd_kcontrol_new wm9713_rec_srcl_mux_controls =
359SOC_DAPM_ENUM("Route", wm9713_enum[3]);
360
361/* Capture source right */
362static const struct snd_kcontrol_new wm9713_rec_srcr_mux_controls =
363SOC_DAPM_ENUM("Route", wm9713_enum[4]);
364
365/* mic source */
366static const struct snd_kcontrol_new wm9713_mic_sel_mux_controls =
367SOC_DAPM_ENUM("Route", wm9713_enum[18]);
368
369/* mic source B virtual control */
370static const struct snd_kcontrol_new wm9713_micb_sel_mux_controls =
371SOC_DAPM_ENUM("Route", wm9713_enum[19]);
372
373static const struct snd_soc_dapm_widget wm9713_dapm_widgets[] = {
374SND_SOC_DAPM_MUX("Capture Headphone Mux", SND_SOC_NOPM, 0, 0,
375 &wm9713_hp_rec_mux_controls),
376SND_SOC_DAPM_MUX("Sidetone Mux", SND_SOC_NOPM, 0, 0,
377 &wm9713_hp_mic_mux_controls),
378SND_SOC_DAPM_MUX("Capture Mono Mux", SND_SOC_NOPM, 0, 0,
379 &wm9713_mono_mic_mux_controls),
380SND_SOC_DAPM_MUX("Mono Out Mux", SND_SOC_NOPM, 0, 0,
381 &wm9713_mono_mux_controls),
382SND_SOC_DAPM_MUX("Left Speaker Out Mux", SND_SOC_NOPM, 0, 0,
383 &wm9713_hp_spkl_mux_controls),
384SND_SOC_DAPM_MUX("Right Speaker Out Mux", SND_SOC_NOPM, 0, 0,
385 &wm9713_hp_spkr_mux_controls),
386SND_SOC_DAPM_MUX("Left Headphone Out Mux", SND_SOC_NOPM, 0, 0,
387 &wm9713_hpl_out_mux_controls),
388SND_SOC_DAPM_MUX("Right Headphone Out Mux", SND_SOC_NOPM, 0, 0,
389 &wm9713_hpr_out_mux_controls),
390SND_SOC_DAPM_MUX("Out 3 Mux", SND_SOC_NOPM, 0, 0,
391 &wm9713_out3_mux_controls),
392SND_SOC_DAPM_MUX("Out 4 Mux", SND_SOC_NOPM, 0, 0,
393 &wm9713_out4_mux_controls),
394SND_SOC_DAPM_MUX("DAC Inv Mux 1", SND_SOC_NOPM, 0, 0,
395 &wm9713_dac_inv1_mux_controls),
396SND_SOC_DAPM_MUX("DAC Inv Mux 2", SND_SOC_NOPM, 0, 0,
397 &wm9713_dac_inv2_mux_controls),
398SND_SOC_DAPM_MUX("Left Capture Source", SND_SOC_NOPM, 0, 0,
399 &wm9713_rec_srcl_mux_controls),
400SND_SOC_DAPM_MUX("Right Capture Source", SND_SOC_NOPM, 0, 0,
401 &wm9713_rec_srcr_mux_controls),
402SND_SOC_DAPM_MUX("Mic A Source", SND_SOC_NOPM, 0, 0,
403 &wm9713_mic_sel_mux_controls),
404SND_SOC_DAPM_MUX("Mic B Source", SND_SOC_NOPM, 0, 0,
405 &wm9713_micb_sel_mux_controls),
406SND_SOC_DAPM_MIXER_E("Left HP Mixer", AC97_EXTENDED_MID, 3, 1,
407 &wm9713_hpl_mixer_controls[0], ARRAY_SIZE(wm9713_hpl_mixer_controls),
408 mixer_event, SND_SOC_DAPM_POST_REG),
409SND_SOC_DAPM_MIXER_E("Right HP Mixer", AC97_EXTENDED_MID, 2, 1,
410 &wm9713_hpr_mixer_controls[0], ARRAY_SIZE(wm9713_hpr_mixer_controls),
411 mixer_event, SND_SOC_DAPM_POST_REG),
412SND_SOC_DAPM_MIXER("Mono Mixer", AC97_EXTENDED_MID, 0, 1,
413 &wm9713_mono_mixer_controls[0], ARRAY_SIZE(wm9713_mono_mixer_controls)),
414SND_SOC_DAPM_MIXER("Speaker Mixer", AC97_EXTENDED_MID, 1, 1,
415 &wm9713_speaker_mixer_controls[0],
416 ARRAY_SIZE(wm9713_speaker_mixer_controls)),
417SND_SOC_DAPM_DAC("Left DAC", "Left HiFi Playback", AC97_EXTENDED_MID, 7, 1),
418SND_SOC_DAPM_DAC("Right DAC", "Right HiFi Playback", AC97_EXTENDED_MID, 6, 1),
419SND_SOC_DAPM_MIXER("AC97 Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
420SND_SOC_DAPM_MIXER("HP Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
421SND_SOC_DAPM_MIXER("Line Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
422SND_SOC_DAPM_MIXER("Capture Mixer", SND_SOC_NOPM, 0, 0, NULL, 0),
423SND_SOC_DAPM_DAC("Voice DAC", "Voice Playback", AC97_EXTENDED_MID, 12, 1),
424SND_SOC_DAPM_DAC("Aux DAC", "Aux Playback", AC97_EXTENDED_MID, 11, 1),
425SND_SOC_DAPM_ADC("Left ADC", "Left HiFi Capture", AC97_EXTENDED_MID, 5, 1),
426SND_SOC_DAPM_ADC("Right ADC", "Right HiFi Capture", AC97_EXTENDED_MID, 4, 1),
427SND_SOC_DAPM_PGA("Left Headphone", AC97_EXTENDED_MSTATUS, 10, 1, NULL, 0),
428SND_SOC_DAPM_PGA("Right Headphone", AC97_EXTENDED_MSTATUS, 9, 1, NULL, 0),
429SND_SOC_DAPM_PGA("Left Speaker", AC97_EXTENDED_MSTATUS, 8, 1, NULL, 0),
430SND_SOC_DAPM_PGA("Right Speaker", AC97_EXTENDED_MSTATUS, 7, 1, NULL, 0),
431SND_SOC_DAPM_PGA("Out 3", AC97_EXTENDED_MSTATUS, 11, 1, NULL, 0),
432SND_SOC_DAPM_PGA("Out 4", AC97_EXTENDED_MSTATUS, 12, 1, NULL, 0),
433SND_SOC_DAPM_PGA("Mono Out", AC97_EXTENDED_MSTATUS, 13, 1, NULL, 0),
434SND_SOC_DAPM_PGA("Left Line In", AC97_EXTENDED_MSTATUS, 6, 1, NULL, 0),
435SND_SOC_DAPM_PGA("Right Line In", AC97_EXTENDED_MSTATUS, 5, 1, NULL, 0),
436SND_SOC_DAPM_PGA("Mono In", AC97_EXTENDED_MSTATUS, 4, 1, NULL, 0),
437SND_SOC_DAPM_PGA("Mic A PGA", AC97_EXTENDED_MSTATUS, 3, 1, NULL, 0),
438SND_SOC_DAPM_PGA("Mic B PGA", AC97_EXTENDED_MSTATUS, 2, 1, NULL, 0),
439SND_SOC_DAPM_PGA("Mic A Pre Amp", AC97_EXTENDED_MSTATUS, 1, 1, NULL, 0),
440SND_SOC_DAPM_PGA("Mic B Pre Amp", AC97_EXTENDED_MSTATUS, 0, 1, NULL, 0),
441SND_SOC_DAPM_MICBIAS("Mic Bias", AC97_EXTENDED_MSTATUS, 14, 1),
442SND_SOC_DAPM_OUTPUT("MONO"),
443SND_SOC_DAPM_OUTPUT("HPL"),
444SND_SOC_DAPM_OUTPUT("HPR"),
445SND_SOC_DAPM_OUTPUT("SPKL"),
446SND_SOC_DAPM_OUTPUT("SPKR"),
447SND_SOC_DAPM_OUTPUT("OUT3"),
448SND_SOC_DAPM_OUTPUT("OUT4"),
449SND_SOC_DAPM_INPUT("LINEL"),
450SND_SOC_DAPM_INPUT("LINER"),
451SND_SOC_DAPM_INPUT("MONOIN"),
452SND_SOC_DAPM_INPUT("PCBEEP"),
453SND_SOC_DAPM_INPUT("MIC1"),
454SND_SOC_DAPM_INPUT("MIC2A"),
455SND_SOC_DAPM_INPUT("MIC2B"),
456SND_SOC_DAPM_VMID("VMID"),
457};
458
459static const char *audio_map[][3] = {
460 /* left HP mixer */
461 {"Left HP Mixer", "PC Beep Playback Switch", "PCBEEP"},
462 {"Left HP Mixer", "Voice Playback Switch", "Voice DAC"},
463 {"Left HP Mixer", "Aux Playback Switch", "Aux DAC"},
464 {"Left HP Mixer", "Bypass Playback Switch", "Left Line In"},
465 {"Left HP Mixer", "PCM Playback Switch", "Left DAC"},
466 {"Left HP Mixer", "MonoIn Playback Switch", "Mono In"},
467 {"Left HP Mixer", NULL, "Capture Headphone Mux"},
468
469 /* right HP mixer */
470 {"Right HP Mixer", "PC Beep Playback Switch", "PCBEEP"},
471 {"Right HP Mixer", "Voice Playback Switch", "Voice DAC"},
472 {"Right HP Mixer", "Aux Playback Switch", "Aux DAC"},
473 {"Right HP Mixer", "Bypass Playback Switch", "Right Line In"},
474 {"Right HP Mixer", "PCM Playback Switch", "Right DAC"},
475 {"Right HP Mixer", "MonoIn Playback Switch", "Mono In"},
476 {"Right HP Mixer", NULL, "Capture Headphone Mux"},
477
478 /* virtual mixer - mixes left & right channels for spk and mono */
479 {"AC97 Mixer", NULL, "Left DAC"},
480 {"AC97 Mixer", NULL, "Right DAC"},
481 {"Line Mixer", NULL, "Right Line In"},
482 {"Line Mixer", NULL, "Left Line In"},
483 {"HP Mixer", NULL, "Left HP Mixer"},
484 {"HP Mixer", NULL, "Right HP Mixer"},
485 {"Capture Mixer", NULL, "Left Capture Source"},
486 {"Capture Mixer", NULL, "Right Capture Source"},
487
488 /* speaker mixer */
489 {"Speaker Mixer", "PC Beep Playback Switch", "PCBEEP"},
490 {"Speaker Mixer", "Voice Playback Switch", "Voice DAC"},
491 {"Speaker Mixer", "Aux Playback Switch", "Aux DAC"},
492 {"Speaker Mixer", "Bypass Playback Switch", "Line Mixer"},
493 {"Speaker Mixer", "PCM Playback Switch", "AC97 Mixer"},
494 {"Speaker Mixer", "MonoIn Playback Switch", "Mono In"},
495
496 /* mono mixer */
497 {"Mono Mixer", "PC Beep Playback Switch", "PCBEEP"},
498 {"Mono Mixer", "Voice Playback Switch", "Voice DAC"},
499 {"Mono Mixer", "Aux Playback Switch", "Aux DAC"},
500 {"Mono Mixer", "Bypass Playback Switch", "Line Mixer"},
501 {"Mono Mixer", "PCM Playback Switch", "AC97 Mixer"},
502 {"Mono Mixer", "Mic 1 Sidetone Switch", "Mic A PGA"},
503 {"Mono Mixer", "Mic 2 Sidetone Switch", "Mic B PGA"},
504 {"Mono Mixer", NULL, "Capture Mono Mux"},
505
506 /* DAC inv mux 1 */
507 {"DAC Inv Mux 1", "Mono", "Mono Mixer"},
508 {"DAC Inv Mux 1", "Speaker", "Speaker Mixer"},
509 {"DAC Inv Mux 1", "Left Headphone", "Left HP Mixer"},
510 {"DAC Inv Mux 1", "Right Headphone", "Right HP Mixer"},
511 {"DAC Inv Mux 1", "Headphone Mono", "HP Mixer"},
512
513 /* DAC inv mux 2 */
514 {"DAC Inv Mux 2", "Mono", "Mono Mixer"},
515 {"DAC Inv Mux 2", "Speaker", "Speaker Mixer"},
516 {"DAC Inv Mux 2", "Left Headphone", "Left HP Mixer"},
517 {"DAC Inv Mux 2", "Right Headphone", "Right HP Mixer"},
518 {"DAC Inv Mux 2", "Headphone Mono", "HP Mixer"},
519
520 /* headphone left mux */
521 {"Left Headphone Out Mux", "Headphone", "Left HP Mixer"},
522
523 /* headphone right mux */
524 {"Right Headphone Out Mux", "Headphone", "Right HP Mixer"},
525
526 /* speaker left mux */
527 {"Left Speaker Out Mux", "Headphone", "Left HP Mixer"},
528 {"Left Speaker Out Mux", "Speaker", "Speaker Mixer"},
529 {"Left Speaker Out Mux", "Inv", "DAC Inv Mux 1"},
530
531 /* speaker right mux */
532 {"Right Speaker Out Mux", "Headphone", "Right HP Mixer"},
533 {"Right Speaker Out Mux", "Speaker", "Speaker Mixer"},
534 {"Right Speaker Out Mux", "Inv", "DAC Inv Mux 2"},
535
536 /* mono mux */
537 {"Mono Out Mux", "Mono", "Mono Mixer"},
538 {"Mono Out Mux", "Inv", "DAC Inv Mux 1"},
539
540 /* out 3 mux */
541 {"Out 3 Mux", "Inv 1", "DAC Inv Mux 1"},
542
543 /* out 4 mux */
544 {"Out 4 Mux", "Inv 2", "DAC Inv Mux 2"},
545
546 /* output pga */
547 {"HPL", NULL, "Left Headphone"},
548 {"Left Headphone", NULL, "Left Headphone Out Mux"},
549 {"HPR", NULL, "Right Headphone"},
550 {"Right Headphone", NULL, "Right Headphone Out Mux"},
551 {"OUT3", NULL, "Out 3"},
552 {"Out 3", NULL, "Out 3 Mux"},
553 {"OUT4", NULL, "Out 4"},
554 {"Out 4", NULL, "Out 4 Mux"},
555 {"SPKL", NULL, "Left Speaker"},
556 {"Left Speaker", NULL, "Left Speaker Out Mux"},
557 {"SPKR", NULL, "Right Speaker"},
558 {"Right Speaker", NULL, "Right Speaker Out Mux"},
559 {"MONO", NULL, "Mono Out"},
560 {"Mono Out", NULL, "Mono Out Mux"},
561
562 /* input pga */
563 {"Left Line In", NULL, "LINEL"},
564 {"Right Line In", NULL, "LINER"},
565 {"Mono In", NULL, "MONOIN"},
566 {"Mic A PGA", NULL, "Mic A Pre Amp"},
567 {"Mic B PGA", NULL, "Mic B Pre Amp"},
568
569 /* left capture select */
570 {"Left Capture Source", "Mic 1", "Mic A Pre Amp"},
571 {"Left Capture Source", "Mic 2", "Mic B Pre Amp"},
572 {"Left Capture Source", "Line", "LINEL"},
573 {"Left Capture Source", "Mono In", "MONOIN"},
574 {"Left Capture Source", "Headphone", "Left HP Mixer"},
575 {"Left Capture Source", "Speaker", "Speaker Mixer"},
576 {"Left Capture Source", "Mono Out", "Mono Mixer"},
577
578 /* right capture select */
579 {"Right Capture Source", "Mic 1", "Mic A Pre Amp"},
580 {"Right Capture Source", "Mic 2", "Mic B Pre Amp"},
581 {"Right Capture Source", "Line", "LINER"},
582 {"Right Capture Source", "Mono In", "MONOIN"},
583 {"Right Capture Source", "Headphone", "Right HP Mixer"},
584 {"Right Capture Source", "Speaker", "Speaker Mixer"},
585 {"Right Capture Source", "Mono Out", "Mono Mixer"},
586
587 /* left ADC */
588 {"Left ADC", NULL, "Left Capture Source"},
589
590 /* right ADC */
591 {"Right ADC", NULL, "Right Capture Source"},
592
593 /* mic */
594 {"Mic A Pre Amp", NULL, "Mic A Source"},
595 {"Mic A Source", "Mic 1", "MIC1"},
596 {"Mic A Source", "Mic 2 A", "MIC2A"},
597 {"Mic A Source", "Mic 2 B", "Mic B Source"},
598 {"Mic B Pre Amp", "MPB", "Mic B Source"},
599 {"Mic B Source", NULL, "MIC2B"},
600
601 /* headphone capture */
602 {"Capture Headphone Mux", "Stereo", "Capture Mixer"},
603 {"Capture Headphone Mux", "Left", "Left Capture Source"},
604 {"Capture Headphone Mux", "Right", "Right Capture Source"},
605
606 /* mono capture */
607 {"Capture Mono Mux", "Stereo", "Capture Mixer"},
608 {"Capture Mono Mux", "Left", "Left Capture Source"},
609 {"Capture Mono Mux", "Right", "Right Capture Source"},
610
611 {NULL, NULL, NULL},
612};
613
614static int wm9713_add_widgets(struct snd_soc_codec *codec)
615{
616 int i;
617
618 for (i = 0; i < ARRAY_SIZE(wm9713_dapm_widgets); i++)
619 snd_soc_dapm_new_control(codec, &wm9713_dapm_widgets[i]);
620
621 /* set up audio path audio_mapnects */
622 for (i = 0; audio_map[i][0] != NULL; i++)
623 snd_soc_dapm_connect_input(codec, audio_map[i][0],
624 audio_map[i][1], audio_map[i][2]);
625
626 snd_soc_dapm_new_widgets(codec);
627 return 0;
628}
629
630static unsigned int ac97_read(struct snd_soc_codec *codec,
631 unsigned int reg)
632{
633 u16 *cache = codec->reg_cache;
634
635 if (reg == AC97_RESET || reg == AC97_GPIO_STATUS ||
636 reg == AC97_VENDOR_ID1 || reg == AC97_VENDOR_ID2 ||
637 reg == AC97_CD)
638 return soc_ac97_ops.read(codec->ac97, reg);
639 else {
640 reg = reg >> 1;
641
642 if (reg > (ARRAY_SIZE(wm9713_reg)))
643 return -EIO;
644
645 return cache[reg];
646 }
647}
648
649static int ac97_write(struct snd_soc_codec *codec, unsigned int reg,
650 unsigned int val)
651{
652 u16 *cache = codec->reg_cache;
653 if (reg < 0x7c)
654 soc_ac97_ops.write(codec->ac97, reg, val);
655 reg = reg >> 1;
656 if (reg <= (ARRAY_SIZE(wm9713_reg)))
657 cache[reg] = val;
658
659 return 0;
660}
661
662/* PLL divisors */
663struct _pll_div {
664 u32 divsel:1;
665 u32 divctl:1;
666 u32 lf:1;
667 u32 n:4;
668 u32 k:24;
669};
670
671/* The size in bits of the PLL divide multiplied by 10
672 * to allow rounding later */
673#define FIXED_PLL_SIZE ((1 << 22) * 10)
674
675static void pll_factors(struct _pll_div *pll_div, unsigned int source)
676{
677 u64 Kpart;
678 unsigned int K, Ndiv, Nmod, target;
679
680 /* The the PLL output is always 98.304MHz. */
681 target = 98304000;
682
683 /* If the input frequency is over 14.4MHz then scale it down. */
684 if (source > 14400000) {
685 source >>= 1;
686 pll_div->divsel = 1;
687
688 if (source > 14400000) {
689 source >>= 1;
690 pll_div->divctl = 1;
691 } else
692 pll_div->divctl = 0;
693
694 } else {
695 pll_div->divsel = 0;
696 pll_div->divctl = 0;
697 }
698
699 /* Low frequency sources require an additional divide in the
700 * loop.
701 */
702 if (source < 8192000) {
703 pll_div->lf = 1;
704 target >>= 2;
705 } else
706 pll_div->lf = 0;
707
708 Ndiv = target / source;
709 if ((Ndiv < 5) || (Ndiv > 12))
710 printk(KERN_WARNING
711 "WM9713 PLL N value %d out of recommended range!\n",
712 Ndiv);
713
714 pll_div->n = Ndiv;
715 Nmod = target % source;
716 Kpart = FIXED_PLL_SIZE * (long long)Nmod;
717
718 do_div(Kpart, source);
719
720 K = Kpart & 0xFFFFFFFF;
721
722 /* Check if we need to round */
723 if ((K % 10) >= 5)
724 K += 5;
725
726 /* Move down to proper range now rounding is done */
727 K /= 10;
728
729 pll_div->k = K;
730}
731
732/**
733 * Please note that changing the PLL input frequency may require
734 * resynchronisation with the AC97 controller.
735 */
736static int wm9713_set_pll(struct snd_soc_codec *codec,
737 int pll_id, unsigned int freq_in, unsigned int freq_out)
738{
739 struct wm9713_priv *wm9713 = codec->private_data;
740 u16 reg, reg2;
741 struct _pll_div pll_div;
742
743 /* turn PLL off ? */
744 if (freq_in == 0 || freq_out == 0) {
745 /* disable PLL power and select ext source */
746 reg = ac97_read(codec, AC97_HANDSET_RATE);
747 ac97_write(codec, AC97_HANDSET_RATE, reg | 0x0080);
748 reg = ac97_read(codec, AC97_EXTENDED_MID);
749 ac97_write(codec, AC97_EXTENDED_MID, reg | 0x0200);
750 wm9713->pll_out = 0;
751 return 0;
752 }
753
754 pll_factors(&pll_div, freq_in);
755
756 if (pll_div.k == 0) {
757 reg = (pll_div.n << 12) | (pll_div.lf << 11) |
758 (pll_div.divsel << 9) | (pll_div.divctl << 8);
759 ac97_write(codec, AC97_LINE1_LEVEL, reg);
760 } else {
761 /* write the fractional k to the reg 0x46 pages */
762 reg2 = (pll_div.n << 12) | (pll_div.lf << 11) | (1 << 10) |
763 (pll_div.divsel << 9) | (pll_div.divctl << 8);
764
765 /* K [21:20] */
766 reg = reg2 | (0x5 << 4) | (pll_div.k >> 20);
767 ac97_write(codec, AC97_LINE1_LEVEL, reg);
768
769 /* K [19:16] */
770 reg = reg2 | (0x4 << 4) | ((pll_div.k >> 16) & 0xf);
771 ac97_write(codec, AC97_LINE1_LEVEL, reg);
772
773 /* K [15:12] */
774 reg = reg2 | (0x3 << 4) | ((pll_div.k >> 12) & 0xf);
775 ac97_write(codec, AC97_LINE1_LEVEL, reg);
776
777 /* K [11:8] */
778 reg = reg2 | (0x2 << 4) | ((pll_div.k >> 8) & 0xf);
779 ac97_write(codec, AC97_LINE1_LEVEL, reg);
780
781 /* K [7:4] */
782 reg = reg2 | (0x1 << 4) | ((pll_div.k >> 4) & 0xf);
783 ac97_write(codec, AC97_LINE1_LEVEL, reg);
784
785 reg = reg2 | (0x0 << 4) | (pll_div.k & 0xf); /* K [3:0] */
786 ac97_write(codec, AC97_LINE1_LEVEL, reg);
787 }
788
789 /* turn PLL on and select as source */
790 reg = ac97_read(codec, AC97_EXTENDED_MID);
791 ac97_write(codec, AC97_EXTENDED_MID, reg & 0xfdff);
792 reg = ac97_read(codec, AC97_HANDSET_RATE);
793 ac97_write(codec, AC97_HANDSET_RATE, reg & 0xff7f);
794 wm9713->pll_out = freq_out;
795 wm9713->pll_in = freq_in;
796
797 /* wait 10ms AC97 link frames for the link to stabilise */
798 schedule_timeout_interruptible(msecs_to_jiffies(10));
799 return 0;
800}
801
802static int wm9713_set_dai_pll(struct snd_soc_codec_dai *codec_dai,
803 int pll_id, unsigned int freq_in, unsigned int freq_out)
804{
805 struct snd_soc_codec *codec = codec_dai->codec;
806 return wm9713_set_pll(codec, pll_id, freq_in, freq_out);
807}
808
809/*
810 * Tristate the PCM DAI lines, tristate can be disabled by calling
811 * wm9713_set_dai_fmt()
812 */
813static int wm9713_set_dai_tristate(struct snd_soc_codec_dai *codec_dai,
814 int tristate)
815{
816 struct snd_soc_codec *codec = codec_dai->codec;
817 u16 reg = ac97_read(codec, AC97_CENTER_LFE_MASTER) & 0x9fff;
818
819 if (tristate)
820 ac97_write(codec, AC97_CENTER_LFE_MASTER, reg);
821
822 return 0;
823}
824
825/*
826 * Configure WM9713 clock dividers.
827 * Voice DAC needs 256 FS
828 */
829static int wm9713_set_dai_clkdiv(struct snd_soc_codec_dai *codec_dai,
830 int div_id, int div)
831{
832 struct snd_soc_codec *codec = codec_dai->codec;
833 u16 reg;
834
835 switch (div_id) {
836 case WM9713_PCMCLK_DIV:
837 reg = ac97_read(codec, AC97_HANDSET_RATE) & 0xf0ff;
838 ac97_write(codec, AC97_HANDSET_RATE, reg | div);
839 break;
840 case WM9713_CLKA_MULT:
841 reg = ac97_read(codec, AC97_HANDSET_RATE) & 0xfffd;
842 ac97_write(codec, AC97_HANDSET_RATE, reg | div);
843 break;
844 case WM9713_CLKB_MULT:
845 reg = ac97_read(codec, AC97_HANDSET_RATE) & 0xfffb;
846 ac97_write(codec, AC97_HANDSET_RATE, reg | div);
847 break;
848 case WM9713_HIFI_DIV:
849 reg = ac97_read(codec, AC97_HANDSET_RATE) & 0x8fff;
850 ac97_write(codec, AC97_HANDSET_RATE, reg | div);
851 break;
852 case WM9713_PCMBCLK_DIV:
853 reg = ac97_read(codec, AC97_CENTER_LFE_MASTER) & 0xf1ff;
854 ac97_write(codec, AC97_CENTER_LFE_MASTER, reg | div);
855 break;
856 case WM9713_PCMCLK_PLL_DIV:
857 reg = ac97_read(codec, AC97_LINE1_LEVEL) & 0xff80;
858 ac97_write(codec, AC97_LINE1_LEVEL, reg | 0x60 | div);
859 break;
860 case WM9713_HIFI_PLL_DIV:
861 reg = ac97_read(codec, AC97_LINE1_LEVEL) & 0xff80;
862 ac97_write(codec, AC97_LINE1_LEVEL, reg | 0x70 | div);
863 break;
864 default:
865 return -EINVAL;
866 }
867
868 return 0;
869}
870
871static int wm9713_set_dai_fmt(struct snd_soc_codec_dai *codec_dai,
872 unsigned int fmt)
873{
874 struct snd_soc_codec *codec = codec_dai->codec;
875 u16 gpio = ac97_read(codec, AC97_GPIO_CFG) & 0xffc5;
876 u16 reg = 0x8000;
877
878 /* clock masters */
879 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
880 case SND_SOC_DAIFMT_CBM_CFM:
881 reg |= 0x4000;
882 gpio |= 0x0010;
883 break;
884 case SND_SOC_DAIFMT_CBM_CFS:
885 reg |= 0x6000;
886 gpio |= 0x0018;
887 break;
888 case SND_SOC_DAIFMT_CBS_CFS:
889 reg |= 0x0200;
890 gpio |= 0x001a;
891 break;
892 case SND_SOC_DAIFMT_CBS_CFM:
893 gpio |= 0x0012;
894 break;
895 }
896
897 /* clock inversion */
898 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
899 case SND_SOC_DAIFMT_IB_IF:
900 reg |= 0x00c0;
901 break;
902 case SND_SOC_DAIFMT_IB_NF:
903 reg |= 0x0080;
904 break;
905 case SND_SOC_DAIFMT_NB_IF:
906 reg |= 0x0040;
907 break;
908 }
909
910 /* DAI format */
911 switch (fmt & SND_SOC_DAIFMT_FORMAT_MASK) {
912 case SND_SOC_DAIFMT_I2S:
913 reg |= 0x0002;
914 break;
915 case SND_SOC_DAIFMT_RIGHT_J:
916 break;
917 case SND_SOC_DAIFMT_LEFT_J:
918 reg |= 0x0001;
919 break;
920 case SND_SOC_DAIFMT_DSP_A:
921 reg |= 0x0003;
922 break;
923 case SND_SOC_DAIFMT_DSP_B:
924 reg |= 0x0043;
925 break;
926 }
927
928 ac97_write(codec, AC97_GPIO_CFG, gpio);
929 ac97_write(codec, AC97_CENTER_LFE_MASTER, reg);
930 return 0;
931}
932
933static int wm9713_pcm_hw_params(struct snd_pcm_substream *substream,
934 struct snd_pcm_hw_params *params)
935{
936 struct snd_soc_pcm_runtime *rtd = substream->private_data;
937 struct snd_soc_device *socdev = rtd->socdev;
938 struct snd_soc_codec *codec = socdev->codec;
939 u16 reg = ac97_read(codec, AC97_CENTER_LFE_MASTER) & 0xfff3;
940
941 switch (params_format(params)) {
942 case SNDRV_PCM_FORMAT_S16_LE:
943 break;
944 case SNDRV_PCM_FORMAT_S20_3LE:
945 reg |= 0x0004;
946 break;
947 case SNDRV_PCM_FORMAT_S24_LE:
948 reg |= 0x0008;
949 break;
950 case SNDRV_PCM_FORMAT_S32_LE:
951 reg |= 0x000c;
952 break;
953 }
954
955 /* enable PCM interface in master mode */
956 ac97_write(codec, AC97_CENTER_LFE_MASTER, reg);
957 return 0;
958}
959
960static void wm9713_voiceshutdown(struct snd_pcm_substream *substream)
961{
962 struct snd_soc_pcm_runtime *rtd = substream->private_data;
963 struct snd_soc_device *socdev = rtd->socdev;
964 struct snd_soc_codec *codec = socdev->codec;
965 u16 status;
966
967 /* Gracefully shut down the voice interface. */
968 status = ac97_read(codec, AC97_EXTENDED_STATUS) | 0x1000;
969 ac97_write(codec, AC97_HANDSET_RATE, 0x0280);
970 schedule_timeout_interruptible(msecs_to_jiffies(1));
971 ac97_write(codec, AC97_HANDSET_RATE, 0x0F80);
972 ac97_write(codec, AC97_EXTENDED_MID, status);
973}
974
975static int ac97_hifi_prepare(struct snd_pcm_substream *substream)
976{
977 struct snd_pcm_runtime *runtime = substream->runtime;
978 struct snd_soc_pcm_runtime *rtd = substream->private_data;
979 struct snd_soc_device *socdev = rtd->socdev;
980 struct snd_soc_codec *codec = socdev->codec;
981 int reg;
982 u16 vra;
983
984 vra = ac97_read(codec, AC97_EXTENDED_STATUS);
985 ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1);
986
987 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
988 reg = AC97_PCM_FRONT_DAC_RATE;
989 else
990 reg = AC97_PCM_LR_ADC_RATE;
991
992 return ac97_write(codec, reg, runtime->rate);
993}
994
995static int ac97_aux_prepare(struct snd_pcm_substream *substream)
996{
997 struct snd_pcm_runtime *runtime = substream->runtime;
998 struct snd_soc_pcm_runtime *rtd = substream->private_data;
999 struct snd_soc_device *socdev = rtd->socdev;
1000 struct snd_soc_codec *codec = socdev->codec;
1001 u16 vra, xsle;
1002
1003 vra = ac97_read(codec, AC97_EXTENDED_STATUS);
1004 ac97_write(codec, AC97_EXTENDED_STATUS, vra | 0x1);
1005 xsle = ac97_read(codec, AC97_PCI_SID);
1006 ac97_write(codec, AC97_PCI_SID, xsle | 0x8000);
1007
1008 if (substream->stream != SNDRV_PCM_STREAM_PLAYBACK)
1009 return -ENODEV;
1010
1011 return ac97_write(codec, AC97_PCM_SURR_DAC_RATE, runtime->rate);
1012}
1013
1014#define WM9713_RATES (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_11025 |\
1015 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_44100 |\
1016 SNDRV_PCM_RATE_48000)
1017
1018#define WM9713_PCM_FORMATS \
1019 (SNDRV_PCM_FORMAT_S16_LE | SNDRV_PCM_FORMAT_S20_3LE | \
1020 SNDRV_PCM_FORMAT_S24_LE)
1021
1022struct snd_soc_codec_dai wm9713_dai[] = {
1023{
1024 .name = "AC97 HiFi",
1025 .type = SND_SOC_DAI_AC97_BUS,
1026 .playback = {
1027 .stream_name = "HiFi Playback",
1028 .channels_min = 1,
1029 .channels_max = 2,
1030 .rates = WM9713_RATES,
1031 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
1032 .capture = {
1033 .stream_name = "HiFi Capture",
1034 .channels_min = 1,
1035 .channels_max = 2,
1036 .rates = WM9713_RATES,
1037 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
1038 .ops = {
1039 .prepare = ac97_hifi_prepare,},
1040 .dai_ops = {
1041 .set_clkdiv = wm9713_set_dai_clkdiv,
1042 .set_pll = wm9713_set_dai_pll,},
1043 },
1044 {
1045 .name = "AC97 Aux",
1046 .playback = {
1047 .stream_name = "Aux Playback",
1048 .channels_min = 1,
1049 .channels_max = 1,
1050 .rates = WM9713_RATES,
1051 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
1052 .ops = {
1053 .prepare = ac97_aux_prepare,},
1054 .dai_ops = {
1055 .set_clkdiv = wm9713_set_dai_clkdiv,
1056 .set_pll = wm9713_set_dai_pll,},
1057 },
1058 {
1059 .name = "WM9713 Voice",
1060 .playback = {
1061 .stream_name = "Voice Playback",
1062 .channels_min = 1,
1063 .channels_max = 1,
1064 .rates = WM9713_RATES,
1065 .formats = WM9713_PCM_FORMATS,},
1066 .capture = {
1067 .stream_name = "Voice Capture",
1068 .channels_min = 1,
1069 .channels_max = 2,
1070 .rates = WM9713_RATES,
1071 .formats = WM9713_PCM_FORMATS,},
1072 .ops = {
1073 .hw_params = wm9713_pcm_hw_params,
1074 .shutdown = wm9713_voiceshutdown,},
1075 .dai_ops = {
1076 .set_clkdiv = wm9713_set_dai_clkdiv,
1077 .set_pll = wm9713_set_dai_pll,
1078 .set_fmt = wm9713_set_dai_fmt,
1079 .set_tristate = wm9713_set_dai_tristate,
1080 },
1081 },
1082};
1083EXPORT_SYMBOL_GPL(wm9713_dai);
1084
1085int wm9713_reset(struct snd_soc_codec *codec, int try_warm)
1086{
1087 if (try_warm && soc_ac97_ops.warm_reset) {
1088 soc_ac97_ops.warm_reset(codec->ac97);
1089 if (!(ac97_read(codec, 0) & 0x8000))
1090 return 1;
1091 }
1092
1093 soc_ac97_ops.reset(codec->ac97);
1094 if (ac97_read(codec, 0) & 0x8000)
1095 return -EIO;
1096 return 0;
1097}
1098EXPORT_SYMBOL_GPL(wm9713_reset);
1099
1100static int wm9713_dapm_event(struct snd_soc_codec *codec, int event)
1101{
1102 u16 reg;
1103
1104 switch (event) {
1105 case SNDRV_CTL_POWER_D0: /* full On */
1106 /* enable thermal shutdown */
1107 reg = ac97_read(codec, AC97_EXTENDED_MID) & 0x1bff;
1108 ac97_write(codec, AC97_EXTENDED_MID, reg);
1109 break;
1110 case SNDRV_CTL_POWER_D1: /* partial On */
1111 case SNDRV_CTL_POWER_D2: /* partial On */
1112 break;
1113 case SNDRV_CTL_POWER_D3hot: /* Off, with power */
1114 /* enable master bias and vmid */
1115 reg = ac97_read(codec, AC97_EXTENDED_MID) & 0x3bff;
1116 ac97_write(codec, AC97_EXTENDED_MID, reg);
1117 ac97_write(codec, AC97_POWERDOWN, 0x0000);
1118 break;
1119 case SNDRV_CTL_POWER_D3cold: /* Off, without power */
1120 /* disable everything including AC link */
1121 ac97_write(codec, AC97_EXTENDED_MID, 0xffff);
1122 ac97_write(codec, AC97_EXTENDED_MSTATUS, 0xffff);
1123 ac97_write(codec, AC97_POWERDOWN, 0xffff);
1124 break;
1125 }
1126 codec->dapm_state = event;
1127 return 0;
1128}
1129
1130static int wm9713_soc_suspend(struct platform_device *pdev,
1131 pm_message_t state)
1132{
1133 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1134 struct snd_soc_codec *codec = socdev->codec;
1135 u16 reg;
1136
1137 /* Disable everything except touchpanel - that will be handled
1138 * by the touch driver and left disabled if touch is not in
1139 * use. */
1140 reg = ac97_read(codec, AC97_EXTENDED_MID);
1141 ac97_write(codec, AC97_EXTENDED_MID, reg | 0x7fff);
1142 ac97_write(codec, AC97_EXTENDED_MSTATUS, 0xffff);
1143 ac97_write(codec, AC97_POWERDOWN, 0x6f00);
1144 ac97_write(codec, AC97_POWERDOWN, 0xffff);
1145
1146 return 0;
1147}
1148
1149static int wm9713_soc_resume(struct platform_device *pdev)
1150{
1151 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1152 struct snd_soc_codec *codec = socdev->codec;
1153 struct wm9713_priv *wm9713 = codec->private_data;
1154 int i, ret;
1155 u16 *cache = codec->reg_cache;
1156
1157 ret = wm9713_reset(codec, 1);
1158 if (ret < 0) {
1159 printk(KERN_ERR "could not reset AC97 codec\n");
1160 return ret;
1161 }
1162
1163 wm9713_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
1164
1165 /* do we need to re-start the PLL ? */
1166 if (wm9713->pll_out)
1167 wm9713_set_pll(codec, 0, wm9713->pll_in, wm9713->pll_out);
1168
1169 /* only synchronise the codec if warm reset failed */
1170 if (ret == 0) {
1171 for (i = 2; i < ARRAY_SIZE(wm9713_reg) << 1; i += 2) {
1172 if (i == AC97_POWERDOWN || i == AC97_EXTENDED_MID ||
1173 i == AC97_EXTENDED_MSTATUS || i > 0x66)
1174 continue;
1175 soc_ac97_ops.write(codec->ac97, i, cache[i>>1]);
1176 }
1177 }
1178
1179 if (codec->suspend_dapm_state == SNDRV_CTL_POWER_D0)
1180 wm9713_dapm_event(codec, SNDRV_CTL_POWER_D0);
1181
1182 return ret;
1183}
1184
1185static int wm9713_soc_probe(struct platform_device *pdev)
1186{
1187 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1188 struct snd_soc_codec *codec;
1189 int ret = 0, reg;
1190
1191 printk(KERN_INFO "WM9713/WM9714 SoC Audio Codec %s\n", WM9713_VERSION);
1192
1193 socdev->codec = kzalloc(sizeof(struct snd_soc_codec), GFP_KERNEL);
1194 if (socdev->codec == NULL)
1195 return -ENOMEM;
1196 codec = socdev->codec;
1197 mutex_init(&codec->mutex);
1198
1199 codec->reg_cache = kmemdup(wm9713_reg, sizeof(wm9713_reg), GFP_KERNEL);
1200 if (codec->reg_cache == NULL) {
1201 ret = -ENOMEM;
1202 goto cache_err;
1203 }
1204 codec->reg_cache_size = sizeof(wm9713_reg);
1205 codec->reg_cache_step = 2;
1206
1207 codec->private_data = kzalloc(sizeof(struct wm9713_priv), GFP_KERNEL);
1208 if (codec->private_data == NULL) {
1209 ret = -ENOMEM;
1210 goto priv_err;
1211 }
1212
1213 codec->name = "WM9713";
1214 codec->owner = THIS_MODULE;
1215 codec->dai = wm9713_dai;
1216 codec->num_dai = ARRAY_SIZE(wm9713_dai);
1217 codec->write = ac97_write;
1218 codec->read = ac97_read;
1219 codec->dapm_event = wm9713_dapm_event;
1220 INIT_LIST_HEAD(&codec->dapm_widgets);
1221 INIT_LIST_HEAD(&codec->dapm_paths);
1222
1223 ret = snd_soc_new_ac97_codec(codec, &soc_ac97_ops, 0);
1224 if (ret < 0)
1225 goto codec_err;
1226
1227 /* register pcms */
1228 ret = snd_soc_new_pcms(socdev, SNDRV_DEFAULT_IDX1, SNDRV_DEFAULT_STR1);
1229 if (ret < 0)
1230 goto pcm_err;
1231
1232 /* do a cold reset for the controller and then try
1233 * a warm reset followed by an optional cold reset for codec */
1234 wm9713_reset(codec, 0);
1235 ret = wm9713_reset(codec, 1);
1236 if (ret < 0) {
1237 printk(KERN_ERR "AC97 link error\n");
1238 goto reset_err;
1239 }
1240
1241 wm9713_dapm_event(codec, SNDRV_CTL_POWER_D3hot);
1242
1243 /* unmute the adc - move to kcontrol */
1244 reg = ac97_read(codec, AC97_CD) & 0x7fff;
1245 ac97_write(codec, AC97_CD, reg);
1246
1247 wm9713_add_controls(codec);
1248 wm9713_add_widgets(codec);
1249 ret = snd_soc_register_card(socdev);
1250 if (ret < 0)
1251 goto reset_err;
1252 return 0;
1253
1254reset_err:
1255 snd_soc_free_pcms(socdev);
1256
1257pcm_err:
1258 snd_soc_free_ac97_codec(codec);
1259
1260codec_err:
1261 kfree(codec->private_data);
1262
1263priv_err:
1264 kfree(codec->reg_cache);
1265
1266cache_err:
1267 kfree(socdev->codec);
1268 socdev->codec = NULL;
1269 return ret;
1270}
1271
1272static int wm9713_soc_remove(struct platform_device *pdev)
1273{
1274 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
1275 struct snd_soc_codec *codec = socdev->codec;
1276
1277 if (codec == NULL)
1278 return 0;
1279
1280 snd_soc_dapm_free(socdev);
1281 snd_soc_free_pcms(socdev);
1282 snd_soc_free_ac97_codec(codec);
1283 kfree(codec->private_data);
1284 kfree(codec->reg_cache);
1285 kfree(codec->dai);
1286 kfree(codec);
1287 return 0;
1288}
1289
1290struct snd_soc_codec_device soc_codec_dev_wm9713 = {
1291 .probe = wm9713_soc_probe,
1292 .remove = wm9713_soc_remove,
1293 .suspend = wm9713_soc_suspend,
1294 .resume = wm9713_soc_resume,
1295};
1296EXPORT_SYMBOL_GPL(soc_codec_dev_wm9713);
1297
1298MODULE_DESCRIPTION("ASoC WM9713/WM9714 driver");
1299MODULE_AUTHOR("Liam Girdwood");
1300MODULE_LICENSE("GPL");
diff --git a/sound/soc/codecs/wm9713.h b/sound/soc/codecs/wm9713.h
new file mode 100644
index 000000000000..d357b6c8134b
--- /dev/null
+++ b/sound/soc/codecs/wm9713.h
@@ -0,0 +1,53 @@
1/*
2 * wm9713.h -- WM9713 Soc Audio driver
3 */
4
5#ifndef _WM9713_H
6#define _WM9713_H
7
8/* clock inputs */
9#define WM9713_CLKA_PIN 0
10#define WM9713_CLKB_PIN 1
11
12/* clock divider ID's */
13#define WM9713_PCMCLK_DIV 0
14#define WM9713_CLKA_MULT 1
15#define WM9713_CLKB_MULT 2
16#define WM9713_HIFI_DIV 3
17#define WM9713_PCMBCLK_DIV 4
18#define WM9713_PCMCLK_PLL_DIV 5
19#define WM9713_HIFI_PLL_DIV 6
20
21/* Calculate the appropriate bit mask for the external PCM clock divider */
22#define WM9713_PCMDIV(x) ((x - 1) << 8)
23
24/* Calculate the appropriate bit mask for the external HiFi clock divider */
25#define WM9713_HIFIDIV(x) ((x - 1) << 12)
26
27/* MCLK clock mulitipliers */
28#define WM9713_CLKA_X1 (0 << 1)
29#define WM9713_CLKA_X2 (1 << 1)
30#define WM9713_CLKB_X1 (0 << 2)
31#define WM9713_CLKB_X2 (1 << 2)
32
33/* MCLK clock MUX */
34#define WM9713_CLK_MUX_A (0 << 0)
35#define WM9713_CLK_MUX_B (1 << 0)
36
37/* Voice DAI BCLK divider */
38#define WM9713_PCMBCLK_DIV_1 (0 << 9)
39#define WM9713_PCMBCLK_DIV_2 (1 << 9)
40#define WM9713_PCMBCLK_DIV_4 (2 << 9)
41#define WM9713_PCMBCLK_DIV_8 (3 << 9)
42#define WM9713_PCMBCLK_DIV_16 (4 << 9)
43
44#define WM9713_DAI_AC97_HIFI 0
45#define WM9713_DAI_AC97_AUX 1
46#define WM9713_DAI_PCM_VOICE 2
47
48extern struct snd_soc_codec_device soc_codec_dev_wm9713;
49extern struct snd_soc_codec_dai wm9713_dai[3];
50
51int wm9713_reset(struct snd_soc_codec *codec, int try_warm);
52
53#endif
diff --git a/sound/soc/davinci/Kconfig b/sound/soc/davinci/Kconfig
new file mode 100644
index 000000000000..20680c551aab
--- /dev/null
+++ b/sound/soc/davinci/Kconfig
@@ -0,0 +1,19 @@
1config SND_DAVINCI_SOC
2 tristate "SoC Audio for the TI DAVINCI chip"
3 depends on ARCH_DAVINCI && SND_SOC
4 help
5 Say Y or M if you want to add support for codecs attached to
6 the DAVINCI AC97 or I2S interface. You will also need
7 to select the audio interfaces to support below.
8
9config SND_DAVINCI_SOC_I2S
10 tristate
11
12config SND_DAVINCI_SOC_EVM
13 tristate "SoC Audio support for DaVinci EVM"
14 depends on SND_DAVINCI_SOC && MACH_DAVINCI_EVM
15 select SND_DAVINCI_SOC_I2S
16 select SND_SOC_TLV320AIC3X
17 help
18 Say Y if you want to add support for SoC audio on TI
19 DaVinci EVM platform.
diff --git a/sound/soc/davinci/Makefile b/sound/soc/davinci/Makefile
new file mode 100644
index 000000000000..ca772e5b4637
--- /dev/null
+++ b/sound/soc/davinci/Makefile
@@ -0,0 +1,11 @@
1# DAVINCI Platform Support
2snd-soc-davinci-objs := davinci-pcm.o
3snd-soc-davinci-i2s-objs := davinci-i2s.o
4
5obj-$(CONFIG_SND_DAVINCI_SOC) += snd-soc-davinci.o
6obj-$(CONFIG_SND_DAVINCI_SOC_I2S) += snd-soc-davinci-i2s.o
7
8# DAVINCI Machine Support
9snd-soc-evm-objs := davinci-evm.o
10
11obj-$(CONFIG_SND_DAVINCI_SOC_EVM) += snd-soc-evm.o
diff --git a/sound/soc/davinci/davinci-evm.c b/sound/soc/davinci/davinci-evm.c
new file mode 100644
index 000000000000..fcd165240333
--- /dev/null
+++ b/sound/soc/davinci/davinci-evm.c
@@ -0,0 +1,208 @@
1/*
2 * ASoC driver for TI DAVINCI EVM platform
3 *
4 * Author: Vladimir Barinov, <vbarinov@ru.mvista.com>
5 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/moduleparam.h>
14#include <linux/timer.h>
15#include <linux/interrupt.h>
16#include <linux/platform_device.h>
17#include <sound/core.h>
18#include <sound/pcm.h>
19#include <sound/soc.h>
20#include <sound/soc-dapm.h>
21
22#include <asm/mach-types.h>
23#include <asm/dma.h>
24#include <asm/arch/hardware.h>
25
26#include "../codecs/tlv320aic3x.h"
27#include "davinci-pcm.h"
28#include "davinci-i2s.h"
29
30#define EVM_CODEC_CLOCK 22579200
31
32static int evm_hw_params(struct snd_pcm_substream *substream,
33 struct snd_pcm_hw_params *params)
34{
35 struct snd_soc_pcm_runtime *rtd = substream->private_data;
36 struct snd_soc_codec_dai *codec_dai = rtd->dai->codec_dai;
37 struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
38 int ret = 0;
39
40 /* set codec DAI configuration */
41 ret = codec_dai->dai_ops.set_fmt(codec_dai, SND_SOC_DAIFMT_I2S |
42 SND_SOC_DAIFMT_CBM_CFM);
43 if (ret < 0)
44 return ret;
45
46 /* set cpu DAI configuration */
47 ret = cpu_dai->dai_ops.set_fmt(cpu_dai, SND_SOC_DAIFMT_CBM_CFM |
48 SND_SOC_DAIFMT_IB_NF);
49 if (ret < 0)
50 return ret;
51
52 /* set the codec system clock */
53 ret = codec_dai->dai_ops.set_sysclk(codec_dai, 0, EVM_CODEC_CLOCK,
54 SND_SOC_CLOCK_OUT);
55 if (ret < 0)
56 return ret;
57
58 return 0;
59}
60
61static struct snd_soc_ops evm_ops = {
62 .hw_params = evm_hw_params,
63};
64
65/* davinci-evm machine dapm widgets */
66static const struct snd_soc_dapm_widget aic3x_dapm_widgets[] = {
67 SND_SOC_DAPM_HP("Headphone Jack", NULL),
68 SND_SOC_DAPM_LINE("Line Out", NULL),
69 SND_SOC_DAPM_MIC("Mic Jack", NULL),
70 SND_SOC_DAPM_LINE("Line In", NULL),
71};
72
73/* davinci-evm machine audio_mapnections to the codec pins */
74static const char *audio_map[][3] = {
75 /* Headphone connected to HPLOUT, HPROUT */
76 {"Headphone Jack", NULL, "HPLOUT"},
77 {"Headphone Jack", NULL, "HPROUT"},
78
79 /* Line Out connected to LLOUT, RLOUT */
80 {"Line Out", NULL, "LLOUT"},
81 {"Line Out", NULL, "RLOUT"},
82
83 /* Mic connected to (MIC3L | MIC3R) */
84 {"MIC3L", NULL, "Mic Bias 2V"},
85 {"MIC3R", NULL, "Mic Bias 2V"},
86 {"Mic Bias 2V", NULL, "Mic Jack"},
87
88 /* Line In connected to (LINE1L | LINE2L), (LINE1R | LINE2R) */
89 {"LINE1L", NULL, "Line In"},
90 {"LINE2L", NULL, "Line In"},
91 {"LINE1R", NULL, "Line In"},
92 {"LINE2R", NULL, "Line In"},
93
94 {NULL, NULL, NULL},
95};
96
97/* Logic for a aic3x as connected on a davinci-evm */
98static int evm_aic3x_init(struct snd_soc_codec *codec)
99{
100 int i;
101
102 /* Add davinci-evm specific widgets */
103 for (i = 0; i < ARRAY_SIZE(aic3x_dapm_widgets); i++)
104 snd_soc_dapm_new_control(codec, &aic3x_dapm_widgets[i]);
105
106 /* Set up davinci-evm specific audio path audio_map */
107 for (i = 0; audio_map[i][0] != NULL; i++)
108 snd_soc_dapm_connect_input(codec, audio_map[i][0],
109 audio_map[i][1], audio_map[i][2]);
110
111 /* not connected */
112 snd_soc_dapm_set_endpoint(codec, "MONO_LOUT", 0);
113 snd_soc_dapm_set_endpoint(codec, "HPLCOM", 0);
114 snd_soc_dapm_set_endpoint(codec, "HPRCOM", 0);
115
116 /* always connected */
117 snd_soc_dapm_set_endpoint(codec, "Headphone Jack", 1);
118 snd_soc_dapm_set_endpoint(codec, "Line Out", 1);
119 snd_soc_dapm_set_endpoint(codec, "Mic Jack", 1);
120 snd_soc_dapm_set_endpoint(codec, "Line In", 1);
121
122 snd_soc_dapm_sync_endpoints(codec);
123
124 return 0;
125}
126
127/* davinci-evm digital audio interface glue - connects codec <--> CPU */
128static struct snd_soc_dai_link evm_dai = {
129 .name = "TLV320AIC3X",
130 .stream_name = "AIC3X",
131 .cpu_dai = &davinci_i2s_dai,
132 .codec_dai = &aic3x_dai,
133 .init = evm_aic3x_init,
134 .ops = &evm_ops,
135};
136
137/* davinci-evm audio machine driver */
138static struct snd_soc_machine snd_soc_machine_evm = {
139 .name = "DaVinci EVM",
140 .dai_link = &evm_dai,
141 .num_links = 1,
142};
143
144/* evm audio private data */
145static struct aic3x_setup_data evm_aic3x_setup = {
146 .i2c_address = 0x1b,
147};
148
149/* evm audio subsystem */
150static struct snd_soc_device evm_snd_devdata = {
151 .machine = &snd_soc_machine_evm,
152 .platform = &davinci_soc_platform,
153 .codec_dev = &soc_codec_dev_aic3x,
154 .codec_data = &evm_aic3x_setup,
155};
156
157static struct resource evm_snd_resources[] = {
158 {
159 .start = DAVINCI_MCBSP_BASE,
160 .end = DAVINCI_MCBSP_BASE + SZ_8K - 1,
161 .flags = IORESOURCE_MEM,
162 },
163};
164
165static struct evm_snd_platform_data evm_snd_data = {
166 .tx_dma_ch = DM644X_DMACH_MCBSP_TX,
167 .rx_dma_ch = DM644X_DMACH_MCBSP_RX,
168};
169
170static struct platform_device *evm_snd_device;
171
172static int __init evm_init(void)
173{
174 int ret;
175
176 evm_snd_device = platform_device_alloc("soc-audio", 0);
177 if (!evm_snd_device)
178 return -ENOMEM;
179
180 platform_set_drvdata(evm_snd_device, &evm_snd_devdata);
181 evm_snd_devdata.dev = &evm_snd_device->dev;
182 evm_snd_device->dev.platform_data = &evm_snd_data;
183
184 ret = platform_device_add_resources(evm_snd_device, evm_snd_resources,
185 ARRAY_SIZE(evm_snd_resources));
186 if (ret) {
187 platform_device_put(evm_snd_device);
188 return ret;
189 }
190
191 ret = platform_device_add(evm_snd_device);
192 if (ret)
193 platform_device_put(evm_snd_device);
194
195 return ret;
196}
197
198static void __exit evm_exit(void)
199{
200 platform_device_unregister(evm_snd_device);
201}
202
203module_init(evm_init);
204module_exit(evm_exit);
205
206MODULE_AUTHOR("Vladimir Barinov");
207MODULE_DESCRIPTION("TI DAVINCI EVM ASoC driver");
208MODULE_LICENSE("GPL");
diff --git a/sound/soc/davinci/davinci-i2s.c b/sound/soc/davinci/davinci-i2s.c
new file mode 100644
index 000000000000..c421774b33ee
--- /dev/null
+++ b/sound/soc/davinci/davinci-i2s.c
@@ -0,0 +1,407 @@
1/*
2 * ALSA SoC I2S (McBSP) Audio Layer for TI DAVINCI processor
3 *
4 * Author: Vladimir Barinov, <vbarinov@ru.mvista.com>
5 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/init.h>
13#include <linux/module.h>
14#include <linux/device.h>
15#include <linux/delay.h>
16#include <linux/io.h>
17#include <linux/clk.h>
18
19#include <sound/core.h>
20#include <sound/pcm.h>
21#include <sound/pcm_params.h>
22#include <sound/initval.h>
23#include <sound/soc.h>
24
25#include "davinci-pcm.h"
26
27#define DAVINCI_MCBSP_DRR_REG 0x00
28#define DAVINCI_MCBSP_DXR_REG 0x04
29#define DAVINCI_MCBSP_SPCR_REG 0x08
30#define DAVINCI_MCBSP_RCR_REG 0x0c
31#define DAVINCI_MCBSP_XCR_REG 0x10
32#define DAVINCI_MCBSP_SRGR_REG 0x14
33#define DAVINCI_MCBSP_PCR_REG 0x24
34
35#define DAVINCI_MCBSP_SPCR_RRST (1 << 0)
36#define DAVINCI_MCBSP_SPCR_RINTM(v) ((v) << 4)
37#define DAVINCI_MCBSP_SPCR_XRST (1 << 16)
38#define DAVINCI_MCBSP_SPCR_XINTM(v) ((v) << 20)
39#define DAVINCI_MCBSP_SPCR_GRST (1 << 22)
40#define DAVINCI_MCBSP_SPCR_FRST (1 << 23)
41#define DAVINCI_MCBSP_SPCR_FREE (1 << 25)
42
43#define DAVINCI_MCBSP_RCR_RWDLEN1(v) ((v) << 5)
44#define DAVINCI_MCBSP_RCR_RFRLEN1(v) ((v) << 8)
45#define DAVINCI_MCBSP_RCR_RDATDLY(v) ((v) << 16)
46#define DAVINCI_MCBSP_RCR_RWDLEN2(v) ((v) << 21)
47
48#define DAVINCI_MCBSP_XCR_XWDLEN1(v) ((v) << 5)
49#define DAVINCI_MCBSP_XCR_XFRLEN1(v) ((v) << 8)
50#define DAVINCI_MCBSP_XCR_XDATDLY(v) ((v) << 16)
51#define DAVINCI_MCBSP_XCR_XFIG (1 << 18)
52#define DAVINCI_MCBSP_XCR_XWDLEN2(v) ((v) << 21)
53
54#define DAVINCI_MCBSP_SRGR_FWID(v) ((v) << 8)
55#define DAVINCI_MCBSP_SRGR_FPER(v) ((v) << 16)
56#define DAVINCI_MCBSP_SRGR_FSGM (1 << 28)
57
58#define DAVINCI_MCBSP_PCR_CLKRP (1 << 0)
59#define DAVINCI_MCBSP_PCR_CLKXP (1 << 1)
60#define DAVINCI_MCBSP_PCR_FSRP (1 << 2)
61#define DAVINCI_MCBSP_PCR_FSXP (1 << 3)
62#define DAVINCI_MCBSP_PCR_CLKRM (1 << 8)
63#define DAVINCI_MCBSP_PCR_CLKXM (1 << 9)
64#define DAVINCI_MCBSP_PCR_FSRM (1 << 10)
65#define DAVINCI_MCBSP_PCR_FSXM (1 << 11)
66
67#define MOD_REG_BIT(val, mask, set) do { \
68 if (set) { \
69 val |= mask; \
70 } else { \
71 val &= ~mask; \
72 } \
73} while (0)
74
75enum {
76 DAVINCI_MCBSP_WORD_8 = 0,
77 DAVINCI_MCBSP_WORD_12,
78 DAVINCI_MCBSP_WORD_16,
79 DAVINCI_MCBSP_WORD_20,
80 DAVINCI_MCBSP_WORD_24,
81 DAVINCI_MCBSP_WORD_32,
82};
83
84static struct davinci_pcm_dma_params davinci_i2s_pcm_out = {
85 .name = "I2S PCM Stereo out",
86};
87
88static struct davinci_pcm_dma_params davinci_i2s_pcm_in = {
89 .name = "I2S PCM Stereo in",
90};
91
92struct davinci_mcbsp_dev {
93 void __iomem *base;
94 struct clk *clk;
95 struct davinci_pcm_dma_params *dma_params[2];
96};
97
98static inline void davinci_mcbsp_write_reg(struct davinci_mcbsp_dev *dev,
99 int reg, u32 val)
100{
101 __raw_writel(val, dev->base + reg);
102}
103
104static inline u32 davinci_mcbsp_read_reg(struct davinci_mcbsp_dev *dev, int reg)
105{
106 return __raw_readl(dev->base + reg);
107}
108
109static void davinci_mcbsp_start(struct snd_pcm_substream *substream)
110{
111 struct snd_soc_pcm_runtime *rtd = substream->private_data;
112 struct davinci_mcbsp_dev *dev = rtd->dai->cpu_dai->private_data;
113 u32 w;
114
115 /* Start the sample generator and enable transmitter/receiver */
116 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG);
117 MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_GRST, 1);
118 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
119 MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_XRST, 1);
120 else
121 MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_RRST, 1);
122 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, w);
123
124 /* Start frame sync */
125 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG);
126 MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_FRST, 1);
127 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, w);
128}
129
130static void davinci_mcbsp_stop(struct snd_pcm_substream *substream)
131{
132 struct snd_soc_pcm_runtime *rtd = substream->private_data;
133 struct davinci_mcbsp_dev *dev = rtd->dai->cpu_dai->private_data;
134 u32 w;
135
136 /* Reset transmitter/receiver and sample rate/frame sync generators */
137 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG);
138 MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_GRST |
139 DAVINCI_MCBSP_SPCR_FRST, 0);
140 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
141 MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_XRST, 0);
142 else
143 MOD_REG_BIT(w, DAVINCI_MCBSP_SPCR_RRST, 0);
144 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG, w);
145}
146
147static int davinci_i2s_startup(struct snd_pcm_substream *substream)
148{
149 struct snd_soc_pcm_runtime *rtd = substream->private_data;
150 struct snd_soc_cpu_dai *cpu_dai = rtd->dai->cpu_dai;
151 struct davinci_mcbsp_dev *dev = rtd->dai->cpu_dai->private_data;
152
153 cpu_dai->dma_data = dev->dma_params[substream->stream];
154
155 return 0;
156}
157
158static int davinci_i2s_set_dai_fmt(struct snd_soc_cpu_dai *cpu_dai,
159 unsigned int fmt)
160{
161 struct davinci_mcbsp_dev *dev = cpu_dai->private_data;
162 u32 w;
163
164 switch (fmt & SND_SOC_DAIFMT_MASTER_MASK) {
165 case SND_SOC_DAIFMT_CBS_CFS:
166 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG,
167 DAVINCI_MCBSP_PCR_FSXM |
168 DAVINCI_MCBSP_PCR_FSRM |
169 DAVINCI_MCBSP_PCR_CLKXM |
170 DAVINCI_MCBSP_PCR_CLKRM);
171 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SRGR_REG,
172 DAVINCI_MCBSP_SRGR_FSGM);
173 break;
174 case SND_SOC_DAIFMT_CBM_CFM:
175 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, 0);
176 break;
177 default:
178 return -EINVAL;
179 }
180
181 switch (fmt & SND_SOC_DAIFMT_INV_MASK) {
182 case SND_SOC_DAIFMT_IB_NF:
183 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_PCR_REG);
184 MOD_REG_BIT(w, DAVINCI_MCBSP_PCR_CLKXP |
185 DAVINCI_MCBSP_PCR_CLKRP, 1);
186 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, w);
187 break;
188 case SND_SOC_DAIFMT_NB_IF:
189 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_PCR_REG);
190 MOD_REG_BIT(w, DAVINCI_MCBSP_PCR_FSXP |
191 DAVINCI_MCBSP_PCR_FSRP, 1);
192 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, w);
193 break;
194 case SND_SOC_DAIFMT_IB_IF:
195 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_PCR_REG);
196 MOD_REG_BIT(w, DAVINCI_MCBSP_PCR_CLKXP |
197 DAVINCI_MCBSP_PCR_CLKRP |
198 DAVINCI_MCBSP_PCR_FSXP |
199 DAVINCI_MCBSP_PCR_FSRP, 1);
200 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_PCR_REG, w);
201 break;
202 case SND_SOC_DAIFMT_NB_NF:
203 break;
204 default:
205 return -EINVAL;
206 }
207
208 return 0;
209}
210
211static int davinci_i2s_hw_params(struct snd_pcm_substream *substream,
212 struct snd_pcm_hw_params *params)
213{
214 struct snd_soc_pcm_runtime *rtd = substream->private_data;
215 struct davinci_pcm_dma_params *dma_params = rtd->dai->cpu_dai->dma_data;
216 struct davinci_mcbsp_dev *dev = rtd->dai->cpu_dai->private_data;
217 struct snd_interval *i = NULL;
218 int mcbsp_word_length;
219 u32 w;
220
221 /* general line settings */
222 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SPCR_REG,
223 DAVINCI_MCBSP_SPCR_RINTM(3) |
224 DAVINCI_MCBSP_SPCR_XINTM(3) |
225 DAVINCI_MCBSP_SPCR_FREE);
226 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_RCR_REG,
227 DAVINCI_MCBSP_RCR_RFRLEN1(1) |
228 DAVINCI_MCBSP_RCR_RDATDLY(1));
229 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_XCR_REG,
230 DAVINCI_MCBSP_XCR_XFRLEN1(1) |
231 DAVINCI_MCBSP_XCR_XDATDLY(1) |
232 DAVINCI_MCBSP_XCR_XFIG);
233
234 i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_SAMPLE_BITS);
235 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SRGR_REG);
236 MOD_REG_BIT(w, DAVINCI_MCBSP_SRGR_FWID(snd_interval_value(i) - 1), 1);
237 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SRGR_REG, w);
238
239 i = hw_param_interval(params, SNDRV_PCM_HW_PARAM_FRAME_BITS);
240 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SRGR_REG);
241 MOD_REG_BIT(w, DAVINCI_MCBSP_SRGR_FPER(snd_interval_value(i) - 1), 1);
242 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_SRGR_REG, w);
243
244 /* Determine xfer data type */
245 switch (params_format(params)) {
246 case SNDRV_PCM_FORMAT_S8:
247 dma_params->data_type = 1;
248 mcbsp_word_length = DAVINCI_MCBSP_WORD_8;
249 break;
250 case SNDRV_PCM_FORMAT_S16_LE:
251 dma_params->data_type = 2;
252 mcbsp_word_length = DAVINCI_MCBSP_WORD_16;
253 break;
254 case SNDRV_PCM_FORMAT_S32_LE:
255 dma_params->data_type = 4;
256 mcbsp_word_length = DAVINCI_MCBSP_WORD_32;
257 break;
258 default:
259 printk(KERN_WARNING "davinci-i2s: unsupported PCM format");
260 return -EINVAL;
261 }
262
263 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_RCR_REG);
264 MOD_REG_BIT(w, DAVINCI_MCBSP_RCR_RWDLEN1(mcbsp_word_length) |
265 DAVINCI_MCBSP_RCR_RWDLEN2(mcbsp_word_length), 1);
266 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_RCR_REG, w);
267
268 w = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_XCR_REG);
269 MOD_REG_BIT(w, DAVINCI_MCBSP_XCR_XWDLEN1(mcbsp_word_length) |
270 DAVINCI_MCBSP_XCR_XWDLEN2(mcbsp_word_length), 1);
271 davinci_mcbsp_write_reg(dev, DAVINCI_MCBSP_XCR_REG, w);
272
273 return 0;
274}
275
276static int davinci_i2s_trigger(struct snd_pcm_substream *substream, int cmd)
277{
278 int ret = 0;
279
280 switch (cmd) {
281 case SNDRV_PCM_TRIGGER_START:
282 case SNDRV_PCM_TRIGGER_RESUME:
283 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
284 davinci_mcbsp_start(substream);
285 break;
286 case SNDRV_PCM_TRIGGER_STOP:
287 case SNDRV_PCM_TRIGGER_SUSPEND:
288 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
289 davinci_mcbsp_stop(substream);
290 break;
291 default:
292 ret = -EINVAL;
293 }
294
295 return ret;
296}
297
298static int davinci_i2s_probe(struct platform_device *pdev)
299{
300 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
301 struct snd_soc_machine *machine = socdev->machine;
302 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[pdev->id].cpu_dai;
303 struct davinci_mcbsp_dev *dev;
304 struct resource *mem, *ioarea;
305 struct evm_snd_platform_data *pdata;
306 int ret;
307
308 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
309 if (!mem) {
310 dev_err(&pdev->dev, "no mem resource?\n");
311 return -ENODEV;
312 }
313
314 ioarea = request_mem_region(mem->start, (mem->end - mem->start) + 1,
315 pdev->name);
316 if (!ioarea) {
317 dev_err(&pdev->dev, "McBSP region already claimed\n");
318 return -EBUSY;
319 }
320
321 dev = kzalloc(sizeof(struct davinci_mcbsp_dev), GFP_KERNEL);
322 if (!dev) {
323 ret = -ENOMEM;
324 goto err_release_region;
325 }
326
327 cpu_dai->private_data = dev;
328
329 dev->clk = clk_get(&pdev->dev, "McBSPCLK");
330 if (IS_ERR(dev->clk)) {
331 ret = -ENODEV;
332 goto err_free_mem;
333 }
334 clk_enable(dev->clk);
335
336 dev->base = (void __iomem *)IO_ADDRESS(mem->start);
337 pdata = pdev->dev.platform_data;
338
339 dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK] = &davinci_i2s_pcm_out;
340 dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK]->channel = pdata->tx_dma_ch;
341 dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK]->dma_addr =
342 (dma_addr_t)(io_v2p(dev->base) + DAVINCI_MCBSP_DXR_REG);
343
344 dev->dma_params[SNDRV_PCM_STREAM_CAPTURE] = &davinci_i2s_pcm_in;
345 dev->dma_params[SNDRV_PCM_STREAM_CAPTURE]->channel = pdata->rx_dma_ch;
346 dev->dma_params[SNDRV_PCM_STREAM_CAPTURE]->dma_addr =
347 (dma_addr_t)(io_v2p(dev->base) + DAVINCI_MCBSP_DRR_REG);
348
349 return 0;
350
351err_free_mem:
352 kfree(dev);
353err_release_region:
354 release_mem_region(mem->start, (mem->end - mem->start) + 1);
355
356 return ret;
357}
358
359static void davinci_i2s_remove(struct platform_device *pdev)
360{
361 struct snd_soc_device *socdev = platform_get_drvdata(pdev);
362 struct snd_soc_machine *machine = socdev->machine;
363 struct snd_soc_cpu_dai *cpu_dai = machine->dai_link[pdev->id].cpu_dai;
364 struct davinci_mcbsp_dev *dev = cpu_dai->private_data;
365 struct resource *mem;
366
367 clk_disable(dev->clk);
368 clk_put(dev->clk);
369 dev->clk = NULL;
370
371 kfree(dev);
372
373 mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
374 release_mem_region(mem->start, (mem->end - mem->start) + 1);
375}
376
377#define DAVINCI_I2S_RATES SNDRV_PCM_RATE_8000_96000
378
379struct snd_soc_cpu_dai davinci_i2s_dai = {
380 .name = "davinci-i2s",
381 .id = 0,
382 .type = SND_SOC_DAI_I2S,
383 .probe = davinci_i2s_probe,
384 .remove = davinci_i2s_remove,
385 .playback = {
386 .channels_min = 2,
387 .channels_max = 2,
388 .rates = DAVINCI_I2S_RATES,
389 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
390 .capture = {
391 .channels_min = 2,
392 .channels_max = 2,
393 .rates = DAVINCI_I2S_RATES,
394 .formats = SNDRV_PCM_FMTBIT_S16_LE,},
395 .ops = {
396 .startup = davinci_i2s_startup,
397 .trigger = davinci_i2s_trigger,
398 .hw_params = davinci_i2s_hw_params,},
399 .dai_ops = {
400 .set_fmt = davinci_i2s_set_dai_fmt,
401 },
402};
403EXPORT_SYMBOL_GPL(davinci_i2s_dai);
404
405MODULE_AUTHOR("Vladimir Barinov");
406MODULE_DESCRIPTION("TI DAVINCI I2S (McBSP) SoC Interface");
407MODULE_LICENSE("GPL");
diff --git a/sound/soc/davinci/davinci-i2s.h b/sound/soc/davinci/davinci-i2s.h
new file mode 100644
index 000000000000..9592d17db320
--- /dev/null
+++ b/sound/soc/davinci/davinci-i2s.h
@@ -0,0 +1,17 @@
1/*
2 * ALSA SoC I2S (McBSP) Audio Layer for TI DAVINCI processor
3 *
4 * Author: Vladimir Barinov, <vbarinov@ru.mvista.com>
5 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef _DAVINCI_I2S_H
13#define _DAVINCI_I2S_H
14
15extern struct snd_soc_cpu_dai davinci_i2s_dai;
16
17#endif
diff --git a/sound/soc/davinci/davinci-pcm.c b/sound/soc/davinci/davinci-pcm.c
new file mode 100644
index 000000000000..6a76927c9971
--- /dev/null
+++ b/sound/soc/davinci/davinci-pcm.c
@@ -0,0 +1,389 @@
1/*
2 * ALSA PCM interface for the TI DAVINCI processor
3 *
4 * Author: Vladimir Barinov, <vbarinov@ru.mvista.com>
5 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/module.h>
13#include <linux/init.h>
14#include <linux/platform_device.h>
15#include <linux/slab.h>
16#include <linux/dma-mapping.h>
17
18#include <sound/core.h>
19#include <sound/pcm.h>
20#include <sound/pcm_params.h>
21#include <sound/soc.h>
22
23#include <asm/dma.h>
24
25#include "davinci-pcm.h"
26
27#define DAVINCI_PCM_DEBUG 0
28#if DAVINCI_PCM_DEBUG
29#define DPRINTK(x...) printk(KERN_DEBUG x)
30#else
31#define DPRINTK(x...)
32#endif
33
34static struct snd_pcm_hardware davinci_pcm_hardware = {
35 .info = (SNDRV_PCM_INFO_INTERLEAVED | SNDRV_PCM_INFO_BLOCK_TRANSFER |
36 SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID |
37 SNDRV_PCM_INFO_PAUSE),
38 .formats = (SNDRV_PCM_FMTBIT_S16_LE),
39 .rates = (SNDRV_PCM_RATE_8000 | SNDRV_PCM_RATE_16000 |
40 SNDRV_PCM_RATE_22050 | SNDRV_PCM_RATE_32000 |
41 SNDRV_PCM_RATE_44100 | SNDRV_PCM_RATE_48000 |
42 SNDRV_PCM_RATE_88200 | SNDRV_PCM_RATE_96000 |
43 SNDRV_PCM_RATE_KNOT),
44 .rate_min = 8000,
45 .rate_max = 96000,
46 .channels_min = 2,
47 .channels_max = 2,
48 .buffer_bytes_max = 128 * 1024,
49 .period_bytes_min = 32,
50 .period_bytes_max = 8 * 1024,
51 .periods_min = 16,
52 .periods_max = 255,
53 .fifo_size = 0,
54};
55
56struct davinci_runtime_data {
57 spinlock_t lock;
58 int period; /* current DMA period */
59 int master_lch; /* Master DMA channel */
60 int slave_lch; /* Slave DMA channel */
61 struct davinci_pcm_dma_params *params; /* DMA params */
62};
63
64static void davinci_pcm_enqueue_dma(struct snd_pcm_substream *substream)
65{
66 struct davinci_runtime_data *prtd = substream->runtime->private_data;
67 struct snd_pcm_runtime *runtime = substream->runtime;
68 int lch = prtd->slave_lch;
69 unsigned int period_size;
70 unsigned int dma_offset;
71 dma_addr_t dma_pos;
72 dma_addr_t src, dst;
73 unsigned short src_bidx, dst_bidx;
74 unsigned int data_type;
75 unsigned int count;
76
77 period_size = snd_pcm_lib_period_bytes(substream);
78 dma_offset = prtd->period * period_size;
79 dma_pos = runtime->dma_addr + dma_offset;
80
81 DPRINTK("audio_set_dma_params_play channel = %d dma_ptr = %x "
82 "period_size=%x\n", lch, dma_pos, period_size);
83
84 data_type = prtd->params->data_type;
85 count = period_size / data_type;
86
87 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
88 src = dma_pos;
89 dst = prtd->params->dma_addr;
90 src_bidx = data_type;
91 dst_bidx = 0;
92 } else {
93 src = prtd->params->dma_addr;
94 dst = dma_pos;
95 src_bidx = 0;
96 dst_bidx = data_type;
97 }
98
99 davinci_set_dma_src_params(lch, src, INCR, W8BIT);
100 davinci_set_dma_dest_params(lch, dst, INCR, W8BIT);
101 davinci_set_dma_src_index(lch, src_bidx, 0);
102 davinci_set_dma_dest_index(lch, dst_bidx, 0);
103 davinci_set_dma_transfer_params(lch, data_type, count, 1, 0, ASYNC);
104
105 prtd->period++;
106 if (unlikely(prtd->period >= runtime->periods))
107 prtd->period = 0;
108}
109
110static void davinci_pcm_dma_irq(int lch, u16 ch_status, void *data)
111{
112 struct snd_pcm_substream *substream = data;
113 struct davinci_runtime_data *prtd = substream->runtime->private_data;
114
115 DPRINTK("lch=%d, status=0x%x\n", lch, ch_status);
116
117 if (unlikely(ch_status != DMA_COMPLETE))
118 return;
119
120 if (snd_pcm_running(substream)) {
121 snd_pcm_period_elapsed(substream);
122
123 spin_lock(&prtd->lock);
124 davinci_pcm_enqueue_dma(substream);
125 spin_unlock(&prtd->lock);
126 }
127}
128
129static int davinci_pcm_dma_request(struct snd_pcm_substream *substream)
130{
131 struct davinci_runtime_data *prtd = substream->runtime->private_data;
132 struct snd_soc_pcm_runtime *rtd = substream->private_data;
133 struct davinci_pcm_dma_params *dma_data = rtd->dai->cpu_dai->dma_data;
134 int tcc = TCC_ANY;
135 int ret;
136
137 if (!dma_data)
138 return -ENODEV;
139
140 prtd->params = dma_data;
141
142 /* Request master DMA channel */
143 ret = davinci_request_dma(prtd->params->channel, prtd->params->name,
144 davinci_pcm_dma_irq, substream,
145 &prtd->master_lch, &tcc, EVENTQ_0);
146 if (ret)
147 return ret;
148
149 /* Request slave DMA channel */
150 ret = davinci_request_dma(PARAM_ANY, "Link",
151 NULL, NULL, &prtd->slave_lch, &tcc, EVENTQ_0);
152 if (ret) {
153 davinci_free_dma(prtd->master_lch);
154 return ret;
155 }
156
157 /* Link slave DMA channel in loopback */
158 davinci_dma_link_lch(prtd->slave_lch, prtd->slave_lch);
159
160 return 0;
161}
162
163static int davinci_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
164{
165 struct davinci_runtime_data *prtd = substream->runtime->private_data;
166 int ret = 0;
167
168 spin_lock(&prtd->lock);
169
170 switch (cmd) {
171 case SNDRV_PCM_TRIGGER_START:
172 case SNDRV_PCM_TRIGGER_RESUME:
173 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
174 davinci_start_dma(prtd->master_lch);
175 break;
176 case SNDRV_PCM_TRIGGER_STOP:
177 case SNDRV_PCM_TRIGGER_SUSPEND:
178 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
179 davinci_stop_dma(prtd->master_lch);
180 break;
181 default:
182 ret = -EINVAL;
183 break;
184 }
185
186 spin_unlock(&prtd->lock);
187
188 return ret;
189}
190
191static int davinci_pcm_prepare(struct snd_pcm_substream *substream)
192{
193 struct davinci_runtime_data *prtd = substream->runtime->private_data;
194 struct paramentry_descriptor temp;
195
196 prtd->period = 0;
197 davinci_pcm_enqueue_dma(substream);
198
199 /* Get slave channel dma params for master channel startup */
200 davinci_get_dma_params(prtd->slave_lch, &temp);
201 davinci_set_dma_params(prtd->master_lch, &temp);
202
203 return 0;
204}
205
206static snd_pcm_uframes_t
207davinci_pcm_pointer(struct snd_pcm_substream *substream)
208{
209 struct snd_pcm_runtime *runtime = substream->runtime;
210 struct davinci_runtime_data *prtd = runtime->private_data;
211 unsigned int offset;
212 dma_addr_t count;
213 dma_addr_t src, dst;
214
215 spin_lock(&prtd->lock);
216
217 davinci_dma_getposition(prtd->master_lch, &src, &dst);
218 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
219 count = src - runtime->dma_addr;
220 else
221 count = dst - runtime->dma_addr;;
222
223 spin_unlock(&prtd->lock);
224
225 offset = bytes_to_frames(runtime, count);
226 if (offset >= runtime->buffer_size)
227 offset = 0;
228
229 return offset;
230}
231
232static int davinci_pcm_open(struct snd_pcm_substream *substream)
233{
234 struct snd_pcm_runtime *runtime = substream->runtime;
235 struct davinci_runtime_data *prtd;
236 int ret = 0;
237
238 snd_soc_set_runtime_hwparams(substream, &davinci_pcm_hardware);
239
240 prtd = kzalloc(sizeof(struct davinci_runtime_data), GFP_KERNEL);
241 if (prtd == NULL)
242 return -ENOMEM;
243
244 spin_lock_init(&prtd->lock);
245
246 runtime->private_data = prtd;
247
248 ret = davinci_pcm_dma_request(substream);
249 if (ret) {
250 printk(KERN_ERR "davinci_pcm: Failed to get dma channels\n");
251 kfree(prtd);
252 }
253
254 return ret;
255}
256
257static int davinci_pcm_close(struct snd_pcm_substream *substream)
258{
259 struct snd_pcm_runtime *runtime = substream->runtime;
260 struct davinci_runtime_data *prtd = runtime->private_data;
261
262 davinci_dma_unlink_lch(prtd->slave_lch, prtd->slave_lch);
263
264 davinci_free_dma(prtd->slave_lch);
265 davinci_free_dma(prtd->master_lch);
266
267 kfree(prtd);
268
269 return 0;
270}
271
272static int davinci_pcm_hw_params(struct snd_pcm_substream *substream,
273 struct snd_pcm_hw_params *hw_params)
274{
275 return snd_pcm_lib_malloc_pages(substream,
276 params_buffer_bytes(hw_params));
277}
278
279static int davinci_pcm_hw_free(struct snd_pcm_substream *substream)
280{
281 return snd_pcm_lib_free_pages(substream);
282}
283
284static int davinci_pcm_mmap(struct snd_pcm_substream *substream,
285 struct vm_area_struct *vma)
286{
287 struct snd_pcm_runtime *runtime = substream->runtime;
288
289 return dma_mmap_writecombine(substream->pcm->card->dev, vma,
290 runtime->dma_area,
291 runtime->dma_addr,
292 runtime->dma_bytes);
293}
294
295struct snd_pcm_ops davinci_pcm_ops = {
296 .open = davinci_pcm_open,
297 .close = davinci_pcm_close,
298 .ioctl = snd_pcm_lib_ioctl,
299 .hw_params = davinci_pcm_hw_params,
300 .hw_free = davinci_pcm_hw_free,
301 .prepare = davinci_pcm_prepare,
302 .trigger = davinci_pcm_trigger,
303 .pointer = davinci_pcm_pointer,
304 .mmap = davinci_pcm_mmap,
305};
306
307static int davinci_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
308{
309 struct snd_pcm_substream *substream = pcm->streams[stream].substream;
310 struct snd_dma_buffer *buf = &substream->dma_buffer;
311 size_t size = davinci_pcm_hardware.buffer_bytes_max;
312
313 buf->dev.type = SNDRV_DMA_TYPE_DEV;
314 buf->dev.dev = pcm->card->dev;
315 buf->private_data = NULL;
316 buf->area = dma_alloc_writecombine(pcm->card->dev, size,
317 &buf->addr, GFP_KERNEL);
318
319 DPRINTK("preallocate_dma_buffer: area=%p, addr=%p, size=%d\n",
320 (void *) buf->area, (void *) buf->addr, size);
321
322 if (!buf->area)
323 return -ENOMEM;
324
325 buf->bytes = size;
326 return 0;
327}
328
329static void davinci_pcm_free(struct snd_pcm *pcm)
330{
331 struct snd_pcm_substream *substream;
332 struct snd_dma_buffer *buf;
333 int stream;
334
335 for (stream = 0; stream < 2; stream++) {
336 substream = pcm->streams[stream].substream;
337 if (!substream)
338 continue;
339
340 buf = &substream->dma_buffer;
341 if (!buf->area)
342 continue;
343
344 dma_free_writecombine(pcm->card->dev, buf->bytes,
345 buf->area, buf->addr);
346 buf->area = NULL;
347 }
348}
349
350static u64 davinci_pcm_dmamask = 0xffffffff;
351
352static int davinci_pcm_new(struct snd_card *card,
353 struct snd_soc_codec_dai *dai, struct snd_pcm *pcm)
354{
355 int ret;
356
357 if (!card->dev->dma_mask)
358 card->dev->dma_mask = &davinci_pcm_dmamask;
359 if (!card->dev->coherent_dma_mask)
360 card->dev->coherent_dma_mask = 0xffffffff;
361
362 if (dai->playback.channels_min) {
363 ret = davinci_pcm_preallocate_dma_buffer(pcm,
364 SNDRV_PCM_STREAM_PLAYBACK);
365 if (ret)
366 return ret;
367 }
368
369 if (dai->capture.channels_min) {
370 ret = davinci_pcm_preallocate_dma_buffer(pcm,
371 SNDRV_PCM_STREAM_CAPTURE);
372 if (ret)
373 return ret;
374 }
375
376 return 0;
377}
378
379struct snd_soc_platform davinci_soc_platform = {
380 .name = "davinci-audio",
381 .pcm_ops = &davinci_pcm_ops,
382 .pcm_new = davinci_pcm_new,
383 .pcm_free = davinci_pcm_free,
384};
385EXPORT_SYMBOL_GPL(davinci_soc_platform);
386
387MODULE_AUTHOR("Vladimir Barinov");
388MODULE_DESCRIPTION("TI DAVINCI PCM DMA module");
389MODULE_LICENSE("GPL");
diff --git a/sound/soc/davinci/davinci-pcm.h b/sound/soc/davinci/davinci-pcm.h
new file mode 100644
index 000000000000..8d6a45e75a6e
--- /dev/null
+++ b/sound/soc/davinci/davinci-pcm.h
@@ -0,0 +1,29 @@
1/*
2 * ALSA PCM interface for the TI DAVINCI processor
3 *
4 * Author: Vladimir Barinov, <vbarinov@ru.mvista.com>
5 * Copyright: (C) 2007 MontaVista Software, Inc., <source@mvista.com>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef _DAVINCI_PCM_H
13#define _DAVINCI_PCM_H
14
15struct davinci_pcm_dma_params {
16 char *name; /* stream identifier */
17 int channel; /* sync dma channel ID */
18 dma_addr_t dma_addr; /* device physical address for DMA */
19 unsigned int data_type; /* xfer data type */
20};
21
22struct evm_snd_platform_data {
23 int tx_dma_ch;
24 int rx_dma_ch;
25};
26
27extern struct snd_soc_platform davinci_soc_platform;
28
29#endif
diff --git a/sound/soc/fsl/fsl_dma.c b/sound/soc/fsl/fsl_dma.c
index 652514fc8142..78de7168d2ba 100644
--- a/sound/soc/fsl/fsl_dma.c
+++ b/sound/soc/fsl/fsl_dma.c
@@ -20,7 +20,6 @@
20#include <linux/interrupt.h> 20#include <linux/interrupt.h>
21#include <linux/delay.h> 21#include <linux/delay.h>
22 22
23#include <sound/driver.h>
24#include <sound/core.h> 23#include <sound/core.h>
25#include <sound/pcm.h> 24#include <sound/pcm.h>
26#include <sound/pcm_params.h> 25#include <sound/pcm_params.h>
diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
index 145ad13d52d1..b2a11b0d2e4c 100644
--- a/sound/soc/fsl/fsl_ssi.c
+++ b/sound/soc/fsl/fsl_ssi.c
@@ -15,7 +15,6 @@
15#include <linux/device.h> 15#include <linux/device.h>
16#include <linux/delay.h> 16#include <linux/delay.h>
17 17
18#include <sound/driver.h>
19#include <sound/core.h> 18#include <sound/core.h>
20#include <sound/pcm.h> 19#include <sound/pcm.h>
21#include <sound/pcm_params.h> 20#include <sound/pcm_params.h>
diff --git a/sound/soc/pxa/corgi.c b/sound/soc/pxa/corgi.c
index 1a70a6ac98ce..7f32a1167572 100644
--- a/sound/soc/pxa/corgi.c
+++ b/sound/soc/pxa/corgi.c
@@ -297,21 +297,19 @@ static int corgi_wm8731_init(struct snd_soc_codec *codec)
297 /* Add corgi specific controls */ 297 /* Add corgi specific controls */
298 for (i = 0; i < ARRAY_SIZE(wm8731_corgi_controls); i++) { 298 for (i = 0; i < ARRAY_SIZE(wm8731_corgi_controls); i++) {
299 err = snd_ctl_add(codec->card, 299 err = snd_ctl_add(codec->card,
300 snd_soc_cnew(&wm8731_corgi_controls[i],codec, NULL)); 300 snd_soc_cnew(&wm8731_corgi_controls[i], codec, NULL));
301 if (err < 0) 301 if (err < 0)
302 return err; 302 return err;
303 } 303 }
304 304
305 /* Add corgi specific widgets */ 305 /* Add corgi specific widgets */
306 for(i = 0; i < ARRAY_SIZE(wm8731_dapm_widgets); i++) { 306 for (i = 0; i < ARRAY_SIZE(wm8731_dapm_widgets); i++)
307 snd_soc_dapm_new_control(codec, &wm8731_dapm_widgets[i]); 307 snd_soc_dapm_new_control(codec, &wm8731_dapm_widgets[i]);
308 }
309 308
310 /* Set up corgi specific audio path audio_map */ 309 /* Set up corgi specific audio path audio_map */
311 for(i = 0; audio_map[i][0] != NULL; i++) { 310 for (i = 0; audio_map[i][0] != NULL; i++)
312 snd_soc_dapm_connect_input(codec, audio_map[i][0], 311 snd_soc_dapm_connect_input(codec, audio_map[i][0],
313 audio_map[i][1], audio_map[i][2]); 312 audio_map[i][1], audio_map[i][2]);
314 }
315 313
316 snd_soc_dapm_sync_endpoints(codec); 314 snd_soc_dapm_sync_endpoints(codec);
317 return 0; 315 return 0;
@@ -353,7 +351,8 @@ static int __init corgi_init(void)
353{ 351{
354 int ret; 352 int ret;
355 353
356 if (!(machine_is_corgi() || machine_is_shepherd() || machine_is_husky())) 354 if (!(machine_is_corgi() || machine_is_shepherd() ||
355 machine_is_husky()))
357 return -ENODEV; 356 return -ENODEV;
358 357
359 corgi_snd_device = platform_device_alloc("soc-audio", -1); 358 corgi_snd_device = platform_device_alloc("soc-audio", -1);
diff --git a/sound/soc/pxa/poodle.c b/sound/soc/pxa/poodle.c
index 4fbf8bba9627..7e830b218943 100644
--- a/sound/soc/pxa/poodle.c
+++ b/sound/soc/pxa/poodle.c
@@ -257,21 +257,19 @@ static int poodle_wm8731_init(struct snd_soc_codec *codec)
257 /* Add poodle specific controls */ 257 /* Add poodle specific controls */
258 for (i = 0; i < ARRAY_SIZE(wm8731_poodle_controls); i++) { 258 for (i = 0; i < ARRAY_SIZE(wm8731_poodle_controls); i++) {
259 err = snd_ctl_add(codec->card, 259 err = snd_ctl_add(codec->card,
260 snd_soc_cnew(&wm8731_poodle_controls[i],codec, NULL)); 260 snd_soc_cnew(&wm8731_poodle_controls[i], codec, NULL));
261 if (err < 0) 261 if (err < 0)
262 return err; 262 return err;
263 } 263 }
264 264
265 /* Add poodle specific widgets */ 265 /* Add poodle specific widgets */
266 for (i = 0; i < ARRAY_SIZE(wm8731_dapm_widgets); i++) { 266 for (i = 0; i < ARRAY_SIZE(wm8731_dapm_widgets); i++)
267 snd_soc_dapm_new_control(codec, &wm8731_dapm_widgets[i]); 267 snd_soc_dapm_new_control(codec, &wm8731_dapm_widgets[i]);
268 }
269 268
270 /* Set up poodle specific audio path audio_map */ 269 /* Set up poodle specific audio path audio_map */
271 for (i = 0; audio_map[i][0] != NULL; i++) { 270 for (i = 0; audio_map[i][0] != NULL; i++)
272 snd_soc_dapm_connect_input(codec, audio_map[i][0], 271 snd_soc_dapm_connect_input(codec, audio_map[i][0],
273 audio_map[i][1], audio_map[i][2]); 272 audio_map[i][1], audio_map[i][2]);
274 }
275 273
276 snd_soc_dapm_sync_endpoints(codec); 274 snd_soc_dapm_sync_endpoints(codec);
277 return 0; 275 return 0;
diff --git a/sound/soc/pxa/pxa2xx-ac97.c b/sound/soc/pxa/pxa2xx-ac97.c
index e17379998802..97ec2d90547c 100644
--- a/sound/soc/pxa/pxa2xx-ac97.c
+++ b/sound/soc/pxa/pxa2xx-ac97.c
@@ -61,7 +61,7 @@ static unsigned short pxa2xx_ac97_read(struct snd_ac97 *ac97,
61 mutex_lock(&car_mutex); 61 mutex_lock(&car_mutex);
62 62
63 /* set up primary or secondary codec/modem space */ 63 /* set up primary or secondary codec/modem space */
64#ifdef CONFIG_PXA27x 64#if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
65 reg_addr = ac97->num ? &SAC_REG_BASE : &PAC_REG_BASE; 65 reg_addr = ac97->num ? &SAC_REG_BASE : &PAC_REG_BASE;
66#else 66#else
67 if (reg == AC97_GPIO_STATUS) 67 if (reg == AC97_GPIO_STATUS)
@@ -87,7 +87,7 @@ static unsigned short pxa2xx_ac97_read(struct snd_ac97 *ac97,
87 wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1); 87 wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_SDONE, 1);
88 if (!((GSR | gsr_bits) & GSR_SDONE)) { 88 if (!((GSR | gsr_bits) & GSR_SDONE)) {
89 printk(KERN_ERR "%s: read error (ac97_reg=%x GSR=%#lx)\n", 89 printk(KERN_ERR "%s: read error (ac97_reg=%x GSR=%#lx)\n",
90 __FUNCTION__, reg, GSR | gsr_bits); 90 __func__, reg, GSR | gsr_bits);
91 val = -1; 91 val = -1;
92 goto out; 92 goto out;
93 } 93 }
@@ -111,7 +111,7 @@ static void pxa2xx_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
111 mutex_lock(&car_mutex); 111 mutex_lock(&car_mutex);
112 112
113 /* set up primary or secondary codec/modem space */ 113 /* set up primary or secondary codec/modem space */
114#ifdef CONFIG_PXA27x 114#if defined(CONFIG_PXA27x) || defined(CONFIG_PXA3xx)
115 reg_addr = ac97->num ? &SAC_REG_BASE : &PAC_REG_BASE; 115 reg_addr = ac97->num ? &SAC_REG_BASE : &PAC_REG_BASE;
116#else 116#else
117 if (reg == AC97_GPIO_STATUS) 117 if (reg == AC97_GPIO_STATUS)
@@ -127,13 +127,16 @@ static void pxa2xx_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
127 wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_CDONE, 1); 127 wait_event_timeout(gsr_wq, (GSR | gsr_bits) & GSR_CDONE, 1);
128 if (!((GSR | gsr_bits) & GSR_CDONE)) 128 if (!((GSR | gsr_bits) & GSR_CDONE))
129 printk(KERN_ERR "%s: write error (ac97_reg=%x GSR=%#lx)\n", 129 printk(KERN_ERR "%s: write error (ac97_reg=%x GSR=%#lx)\n",
130 __FUNCTION__, reg, GSR | gsr_bits); 130 __func__, reg, GSR | gsr_bits);
131 131
132 mutex_unlock(&car_mutex); 132 mutex_unlock(&car_mutex);
133} 133}
134 134
135static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97) 135static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97)
136{ 136{
137#ifdef CONFIG_PXA3xx
138 int timeout = 100;
139#endif
137 gsr_bits = 0; 140 gsr_bits = 0;
138 141
139#ifdef CONFIG_PXA27x 142#ifdef CONFIG_PXA27x
@@ -144,6 +147,11 @@ static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97)
144 GCR |= GCR_WARM_RST; 147 GCR |= GCR_WARM_RST;
145 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT); 148 pxa_gpio_mode(113 | GPIO_ALT_FN_2_OUT);
146 udelay(500); 149 udelay(500);
150#elif defined(CONFIG_PXA3xx)
151 /* Can't use interrupts */
152 GCR |= GCR_WARM_RST;
153 while (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)) && timeout--)
154 mdelay(1);
147#else 155#else
148 GCR |= GCR_WARM_RST | GCR_PRIRDY_IEN | GCR_SECRDY_IEN; 156 GCR |= GCR_WARM_RST | GCR_PRIRDY_IEN | GCR_SECRDY_IEN;
149 wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1); 157 wait_event_timeout(gsr_wq, gsr_bits & (GSR_PCR | GSR_SCR), 1);
@@ -151,7 +159,7 @@ static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97)
151 159
152 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR))) 160 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)))
153 printk(KERN_INFO "%s: warm reset timeout (GSR=%#lx)\n", 161 printk(KERN_INFO "%s: warm reset timeout (GSR=%#lx)\n",
154 __FUNCTION__, gsr_bits); 162 __func__, gsr_bits);
155 163
156 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN); 164 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
157 GCR |= GCR_SDONE_IE|GCR_CDONE_IE; 165 GCR |= GCR_SDONE_IE|GCR_CDONE_IE;
@@ -159,6 +167,16 @@ static void pxa2xx_ac97_warm_reset(struct snd_ac97 *ac97)
159 167
160static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97) 168static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97)
161{ 169{
170#ifdef CONFIG_PXA3xx
171 int timeout = 1000;
172
173 /* Hold CLKBPB for 100us */
174 GCR = 0;
175 GCR = GCR_CLKBPB;
176 udelay(100);
177 GCR = 0;
178#endif
179
162 GCR &= GCR_COLD_RST; /* clear everything but nCRST */ 180 GCR &= GCR_COLD_RST; /* clear everything but nCRST */
163 GCR &= ~GCR_COLD_RST; /* then assert nCRST */ 181 GCR &= ~GCR_COLD_RST; /* then assert nCRST */
164 182
@@ -170,6 +188,13 @@ static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97)
170 clk_disable(ac97conf_clk); 188 clk_disable(ac97conf_clk);
171 GCR = GCR_COLD_RST; 189 GCR = GCR_COLD_RST;
172 udelay(50); 190 udelay(50);
191#elif defined(CONFIG_PXA3xx)
192 /* Can't use interrupts on PXA3xx */
193 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
194
195 GCR = GCR_WARM_RST | GCR_COLD_RST;
196 while (!(GSR & (GSR_PCR | GSR_SCR)) && timeout--)
197 mdelay(10);
173#else 198#else
174 GCR = GCR_COLD_RST; 199 GCR = GCR_COLD_RST;
175 GCR |= GCR_CDONE_IE|GCR_SDONE_IE; 200 GCR |= GCR_CDONE_IE|GCR_SDONE_IE;
@@ -178,7 +203,7 @@ static void pxa2xx_ac97_cold_reset(struct snd_ac97 *ac97)
178 203
179 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR))) 204 if (!((GSR | gsr_bits) & (GSR_PCR | GSR_SCR)))
180 printk(KERN_INFO "%s: cold reset timeout (GSR=%#lx)\n", 205 printk(KERN_INFO "%s: cold reset timeout (GSR=%#lx)\n",
181 __FUNCTION__, gsr_bits); 206 __func__, gsr_bits);
182 207
183 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN); 208 GCR &= ~(GCR_PRIRDY_IEN|GCR_SECRDY_IEN);
184 GCR |= GCR_SDONE_IE|GCR_CDONE_IE; 209 GCR |= GCR_SDONE_IE|GCR_CDONE_IE;
diff --git a/sound/soc/pxa/pxa2xx-pcm.c b/sound/soc/pxa/pxa2xx-pcm.c
index daeaa4c8b876..01ad7bf716b7 100644
--- a/sound/soc/pxa/pxa2xx-pcm.c
+++ b/sound/soc/pxa/pxa2xx-pcm.c
@@ -64,8 +64,8 @@ static void pxa2xx_pcm_dma_irq(int dma_ch, void *dev_id)
64 if (dcsr & DCSR_ENDINTR) { 64 if (dcsr & DCSR_ENDINTR) {
65 snd_pcm_period_elapsed(substream); 65 snd_pcm_period_elapsed(substream);
66 } else { 66 } else {
67 printk( KERN_ERR "%s: DMA error on channel %d (DCSR=%#x)\n", 67 printk(KERN_ERR "%s: DMA error on channel %d (DCSR=%#x)\n",
68 prtd->params->name, dma_ch, dcsr ); 68 prtd->params->name, dma_ch, dcsr);
69 } 69 }
70} 70}
71 71
@@ -84,8 +84,8 @@ static int pxa2xx_pcm_hw_params(struct snd_pcm_substream *substream,
84 84
85 /* return if this is a bufferless transfer e.g. 85 /* return if this is a bufferless transfer e.g.
86 * codec <--> BT codec or GSM modem -- lg FIXME */ 86 * codec <--> BT codec or GSM modem -- lg FIXME */
87 if (!dma) 87 if (!dma)
88 return 0; 88 return 0;
89 89
90 /* this may get called several times by oss emulation 90 /* this may get called several times by oss emulation
91 * with different params */ 91 * with different params */
@@ -363,7 +363,6 @@ struct snd_soc_platform pxa2xx_soc_platform = {
363 .pcm_new = pxa2xx_pcm_new, 363 .pcm_new = pxa2xx_pcm_new,
364 .pcm_free = pxa2xx_pcm_free_dma_buffers, 364 .pcm_free = pxa2xx_pcm_free_dma_buffers,
365}; 365};
366
367EXPORT_SYMBOL_GPL(pxa2xx_soc_platform); 366EXPORT_SYMBOL_GPL(pxa2xx_soc_platform);
368 367
369MODULE_AUTHOR("Nicolas Pitre"); 368MODULE_AUTHOR("Nicolas Pitre");
diff --git a/sound/soc/pxa/spitz.c b/sound/soc/pxa/spitz.c
index ecca39033fcc..d8b8372db00e 100644
--- a/sound/soc/pxa/spitz.c
+++ b/sound/soc/pxa/spitz.c
@@ -313,15 +313,13 @@ static int spitz_wm8750_init(struct snd_soc_codec *codec)
313 } 313 }
314 314
315 /* Add spitz specific widgets */ 315 /* Add spitz specific widgets */
316 for (i = 0; i < ARRAY_SIZE(wm8750_dapm_widgets); i++) { 316 for (i = 0; i < ARRAY_SIZE(wm8750_dapm_widgets); i++)
317 snd_soc_dapm_new_control(codec, &wm8750_dapm_widgets[i]); 317 snd_soc_dapm_new_control(codec, &wm8750_dapm_widgets[i]);
318 }
319 318
320 /* Set up spitz specific audio path audio_map */ 319 /* Set up spitz specific audio path audio_map */
321 for (i = 0; audio_map[i][0] != NULL; i++) { 320 for (i = 0; audio_map[i][0] != NULL; i++)
322 snd_soc_dapm_connect_input(codec, audio_map[i][0], 321 snd_soc_dapm_connect_input(codec, audio_map[i][0],
323 audio_map[i][1], audio_map[i][2]); 322 audio_map[i][1], audio_map[i][2]);
324 }
325 323
326 snd_soc_dapm_sync_endpoints(codec); 324 snd_soc_dapm_sync_endpoints(codec);
327 return 0; 325 return 0;
diff --git a/sound/soc/s3c24xx/neo1973_wm8753.c b/sound/soc/s3c24xx/neo1973_wm8753.c
index 6ee115ceb011..962cc20b1af5 100644
--- a/sound/soc/s3c24xx/neo1973_wm8753.c
+++ b/sound/soc/s3c24xx/neo1973_wm8753.c
@@ -659,6 +659,7 @@ static int __init neo1973_init(void)
659 659
660static void __exit neo1973_exit(void) 660static void __exit neo1973_exit(void)
661{ 661{
662 i2c_del_driver(&lm4857_i2c_driver);
662 platform_device_unregister(neo1973_snd_device); 663 platform_device_unregister(neo1973_snd_device);
663} 664}
664 665
diff --git a/sound/soc/s3c24xx/s3c24xx-i2s.c b/sound/soc/s3c24xx/s3c24xx-i2s.c
index 0a3c630951be..4ebcd6a8bf28 100644
--- a/sound/soc/s3c24xx/s3c24xx-i2s.c
+++ b/sound/soc/s3c24xx/s3c24xx-i2s.c
@@ -25,6 +25,7 @@
25#include <linux/delay.h> 25#include <linux/delay.h>
26#include <linux/clk.h> 26#include <linux/clk.h>
27#include <linux/jiffies.h> 27#include <linux/jiffies.h>
28#include <linux/io.h>
28#include <sound/core.h> 29#include <sound/core.h>
29#include <sound/pcm.h> 30#include <sound/pcm.h>
30#include <sound/pcm_params.h> 31#include <sound/pcm_params.h>
@@ -32,7 +33,6 @@
32#include <sound/soc.h> 33#include <sound/soc.h>
33 34
34#include <asm/hardware.h> 35#include <asm/hardware.h>
35#include <asm/io.h>
36#include <asm/arch/regs-gpio.h> 36#include <asm/arch/regs-gpio.h>
37#include <asm/arch/regs-clock.h> 37#include <asm/arch/regs-clock.h>
38#include <asm/arch/audio.h> 38#include <asm/arch/audio.h>
@@ -46,7 +46,7 @@
46 46
47#define S3C24XX_I2S_DEBUG 0 47#define S3C24XX_I2S_DEBUG 0
48#if S3C24XX_I2S_DEBUG 48#if S3C24XX_I2S_DEBUG
49#define DBG(x...) printk(KERN_DEBUG x) 49#define DBG(x...) printk(KERN_DEBUG "s3c24xx-i2s: " x)
50#else 50#else
51#define DBG(x...) 51#define DBG(x...)
52#endif 52#endif
@@ -89,7 +89,7 @@ static void s3c24xx_snd_txctrl(int on)
89 u32 iiscon; 89 u32 iiscon;
90 u32 iismod; 90 u32 iismod;
91 91
92 DBG("Entered %s\n", __FUNCTION__); 92 DBG("Entered %s\n", __func__);
93 93
94 iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON); 94 iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON);
95 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON); 95 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
@@ -134,7 +134,7 @@ static void s3c24xx_snd_rxctrl(int on)
134 u32 iiscon; 134 u32 iiscon;
135 u32 iismod; 135 u32 iismod;
136 136
137 DBG("Entered %s\n", __FUNCTION__); 137 DBG("Entered %s\n", __func__);
138 138
139 iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON); 139 iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON);
140 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON); 140 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
@@ -159,10 +159,10 @@ static void s3c24xx_snd_rxctrl(int on)
159 * DMA engine will simply freeze randomly. 159 * DMA engine will simply freeze randomly.
160 */ 160 */
161 161
162 iisfcon &= ~S3C2410_IISFCON_RXENABLE; 162 iisfcon &= ~S3C2410_IISFCON_RXENABLE;
163 iisfcon &= ~S3C2410_IISFCON_RXDMA; 163 iisfcon &= ~S3C2410_IISFCON_RXDMA;
164 iiscon |= S3C2410_IISCON_RXIDLE; 164 iiscon |= S3C2410_IISCON_RXIDLE;
165 iiscon &= ~S3C2410_IISCON_RXDMAEN; 165 iiscon &= ~S3C2410_IISCON_RXDMAEN;
166 iismod &= ~S3C2410_IISMOD_RXMODE; 166 iismod &= ~S3C2410_IISMOD_RXMODE;
167 167
168 writel(iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON); 168 writel(iisfcon, s3c24xx_i2s.regs + S3C2410_IISFCON);
@@ -182,7 +182,7 @@ static int s3c24xx_snd_lrsync(void)
182 u32 iiscon; 182 u32 iiscon;
183 unsigned long timeout = jiffies + msecs_to_jiffies(5); 183 unsigned long timeout = jiffies + msecs_to_jiffies(5);
184 184
185 DBG("Entered %s\n", __FUNCTION__); 185 DBG("Entered %s\n", __func__);
186 186
187 while (1) { 187 while (1) {
188 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON); 188 iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
@@ -201,7 +201,7 @@ static int s3c24xx_snd_lrsync(void)
201 */ 201 */
202static inline int s3c24xx_snd_is_clkmaster(void) 202static inline int s3c24xx_snd_is_clkmaster(void)
203{ 203{
204 DBG("Entered %s\n", __FUNCTION__); 204 DBG("Entered %s\n", __func__);
205 205
206 return (readl(s3c24xx_i2s.regs + S3C2410_IISMOD) & S3C2410_IISMOD_SLAVE) ? 0:1; 206 return (readl(s3c24xx_i2s.regs + S3C2410_IISMOD) & S3C2410_IISMOD_SLAVE) ? 0:1;
207} 207}
@@ -214,7 +214,7 @@ static int s3c24xx_i2s_set_fmt(struct snd_soc_cpu_dai *cpu_dai,
214{ 214{
215 u32 iismod; 215 u32 iismod;
216 216
217 DBG("Entered %s\n", __FUNCTION__); 217 DBG("Entered %s\n", __func__);
218 218
219 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); 219 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
220 DBG("hw_params r: IISMOD: %lx \n", iismod); 220 DBG("hw_params r: IISMOD: %lx \n", iismod);
@@ -250,7 +250,7 @@ static int s3c24xx_i2s_hw_params(struct snd_pcm_substream *substream,
250 struct snd_soc_pcm_runtime *rtd = substream->private_data; 250 struct snd_soc_pcm_runtime *rtd = substream->private_data;
251 u32 iismod; 251 u32 iismod;
252 252
253 DBG("Entered %s\n", __FUNCTION__); 253 DBG("Entered %s\n", __func__);
254 254
255 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 255 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
256 rtd->dai->cpu_dai->dma_data = &s3c24xx_i2s_pcm_stereo_out; 256 rtd->dai->cpu_dai->dma_data = &s3c24xx_i2s_pcm_stereo_out;
@@ -278,7 +278,7 @@ static int s3c24xx_i2s_trigger(struct snd_pcm_substream *substream, int cmd)
278{ 278{
279 int ret = 0; 279 int ret = 0;
280 280
281 DBG("Entered %s\n", __FUNCTION__); 281 DBG("Entered %s\n", __func__);
282 282
283 switch (cmd) { 283 switch (cmd) {
284 case SNDRV_PCM_TRIGGER_START: 284 case SNDRV_PCM_TRIGGER_START:
@@ -320,7 +320,7 @@ static int s3c24xx_i2s_set_sysclk(struct snd_soc_cpu_dai *cpu_dai,
320{ 320{
321 u32 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); 321 u32 iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
322 322
323 DBG("Entered %s\n", __FUNCTION__); 323 DBG("Entered %s\n", __func__);
324 324
325 iismod &= ~S3C2440_IISMOD_MPLL; 325 iismod &= ~S3C2440_IISMOD_MPLL;
326 326
@@ -346,7 +346,7 @@ static int s3c24xx_i2s_set_clkdiv(struct snd_soc_cpu_dai *cpu_dai,
346{ 346{
347 u32 reg; 347 u32 reg;
348 348
349 DBG("Entered %s\n", __FUNCTION__); 349 DBG("Entered %s\n", __func__);
350 350
351 switch (div_id) { 351 switch (div_id) {
352 case S3C24XX_DIV_BCLK: 352 case S3C24XX_DIV_BCLK:
@@ -381,13 +381,13 @@ EXPORT_SYMBOL_GPL(s3c24xx_i2s_get_clockrate);
381 381
382static int s3c24xx_i2s_probe(struct platform_device *pdev) 382static int s3c24xx_i2s_probe(struct platform_device *pdev)
383{ 383{
384 DBG("Entered %s\n", __FUNCTION__); 384 DBG("Entered %s\n", __func__);
385 385
386 s3c24xx_i2s.regs = ioremap(S3C2410_PA_IIS, 0x100); 386 s3c24xx_i2s.regs = ioremap(S3C2410_PA_IIS, 0x100);
387 if (s3c24xx_i2s.regs == NULL) 387 if (s3c24xx_i2s.regs == NULL)
388 return -ENXIO; 388 return -ENXIO;
389 389
390 s3c24xx_i2s.iis_clk=clk_get(&pdev->dev, "iis"); 390 s3c24xx_i2s.iis_clk = clk_get(&pdev->dev, "iis");
391 if (s3c24xx_i2s.iis_clk == NULL) { 391 if (s3c24xx_i2s.iis_clk == NULL) {
392 DBG("failed to get iis_clock\n"); 392 DBG("failed to get iis_clock\n");
393 iounmap(s3c24xx_i2s.regs); 393 iounmap(s3c24xx_i2s.regs);
@@ -411,9 +411,11 @@ static int s3c24xx_i2s_probe(struct platform_device *pdev)
411} 411}
412 412
413#ifdef CONFIG_PM 413#ifdef CONFIG_PM
414int s3c24xx_i2s_suspend(struct platform_device *pdev, 414static int s3c24xx_i2s_suspend(struct platform_device *pdev,
415 struct snd_soc_cpu_dai *cpu_dai) 415 struct snd_soc_cpu_dai *cpu_dai)
416{ 416{
417 DBG("Entered %s\n", __func__);
418
417 s3c24xx_i2s.iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON); 419 s3c24xx_i2s.iiscon = readl(s3c24xx_i2s.regs + S3C2410_IISCON);
418 s3c24xx_i2s.iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD); 420 s3c24xx_i2s.iismod = readl(s3c24xx_i2s.regs + S3C2410_IISMOD);
419 s3c24xx_i2s.iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON); 421 s3c24xx_i2s.iisfcon = readl(s3c24xx_i2s.regs + S3C2410_IISFCON);
@@ -424,9 +426,10 @@ int s3c24xx_i2s_suspend(struct platform_device *pdev,
424 return 0; 426 return 0;
425} 427}
426 428
427int s3c24xx_i2s_resume(struct platform_device *pdev, 429static int s3c24xx_i2s_resume(struct platform_device *pdev,
428 struct snd_soc_cpu_dai *cpu_dai) 430 struct snd_soc_cpu_dai *cpu_dai)
429{ 431{
432 DBG("Entered %s\n", __func__);
430 clk_enable(s3c24xx_i2s.iis_clk); 433 clk_enable(s3c24xx_i2s.iis_clk);
431 434
432 writel(s3c24xx_i2s.iiscon, s3c24xx_i2s.regs + S3C2410_IISCON); 435 writel(s3c24xx_i2s.iiscon, s3c24xx_i2s.regs + S3C2410_IISCON);
diff --git a/sound/soc/s3c24xx/s3c24xx-pcm.c b/sound/soc/s3c24xx/s3c24xx-pcm.c
index 29a6c82f873a..49580fb481d5 100644
--- a/sound/soc/s3c24xx/s3c24xx-pcm.c
+++ b/sound/soc/s3c24xx/s3c24xx-pcm.c
@@ -39,7 +39,7 @@
39 39
40#define S3C24XX_PCM_DEBUG 0 40#define S3C24XX_PCM_DEBUG 0
41#if S3C24XX_PCM_DEBUG 41#if S3C24XX_PCM_DEBUG
42#define DBG(x...) printk(KERN_DEBUG x) 42#define DBG(x...) printk(KERN_DEBUG "s3c24xx-pcm: " x)
43#else 43#else
44#define DBG(x...) 44#define DBG(x...)
45#endif 45#endif
@@ -88,7 +88,7 @@ static void s3c24xx_pcm_enqueue(struct snd_pcm_substream *substream)
88 dma_addr_t pos = prtd->dma_pos; 88 dma_addr_t pos = prtd->dma_pos;
89 int ret; 89 int ret;
90 90
91 DBG("Entered %s\n", __FUNCTION__); 91 DBG("Entered %s\n", __func__);
92 92
93 while (prtd->dma_loaded < prtd->dma_limit) { 93 while (prtd->dma_loaded < prtd->dma_limit) {
94 unsigned long len = prtd->dma_period; 94 unsigned long len = prtd->dma_period;
@@ -98,7 +98,7 @@ static void s3c24xx_pcm_enqueue(struct snd_pcm_substream *substream)
98 if ((pos + len) > prtd->dma_end) { 98 if ((pos + len) > prtd->dma_end) {
99 len = prtd->dma_end - pos; 99 len = prtd->dma_end - pos;
100 DBG(KERN_DEBUG "%s: corrected dma len %ld\n", 100 DBG(KERN_DEBUG "%s: corrected dma len %ld\n",
101 __FUNCTION__, len); 101 __func__, len);
102 } 102 }
103 103
104 ret = s3c2410_dma_enqueue(prtd->params->channel, 104 ret = s3c2410_dma_enqueue(prtd->params->channel,
@@ -123,7 +123,7 @@ static void s3c24xx_audio_buffdone(struct s3c2410_dma_chan *channel,
123 struct snd_pcm_substream *substream = dev_id; 123 struct snd_pcm_substream *substream = dev_id;
124 struct s3c24xx_runtime_data *prtd; 124 struct s3c24xx_runtime_data *prtd;
125 125
126 DBG("Entered %s\n", __FUNCTION__); 126 DBG("Entered %s\n", __func__);
127 127
128 if (result == S3C2410_RES_ABORT || result == S3C2410_RES_ERR) 128 if (result == S3C2410_RES_ABORT || result == S3C2410_RES_ERR)
129 return; 129 return;
@@ -152,7 +152,7 @@ static int s3c24xx_pcm_hw_params(struct snd_pcm_substream *substream,
152 unsigned long totbytes = params_buffer_bytes(params); 152 unsigned long totbytes = params_buffer_bytes(params);
153 int ret=0; 153 int ret=0;
154 154
155 DBG("Entered %s\n", __FUNCTION__); 155 DBG("Entered %s\n", __func__);
156 156
157 /* return if this is a bufferless transfer e.g. 157 /* return if this is a bufferless transfer e.g.
158 * codec <--> BT codec or GSM modem -- lg FIXME */ 158 * codec <--> BT codec or GSM modem -- lg FIXME */
@@ -200,7 +200,7 @@ static int s3c24xx_pcm_hw_free(struct snd_pcm_substream *substream)
200{ 200{
201 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data; 201 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data;
202 202
203 DBG("Entered %s\n", __FUNCTION__); 203 DBG("Entered %s\n", __func__);
204 204
205 /* TODO - do we need to ensure DMA flushed */ 205 /* TODO - do we need to ensure DMA flushed */
206 snd_pcm_set_runtime_buffer(substream, NULL); 206 snd_pcm_set_runtime_buffer(substream, NULL);
@@ -218,7 +218,7 @@ static int s3c24xx_pcm_prepare(struct snd_pcm_substream *substream)
218 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data; 218 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data;
219 int ret = 0; 219 int ret = 0;
220 220
221 DBG("Entered %s\n", __FUNCTION__); 221 DBG("Entered %s\n", __func__);
222 222
223 /* return if this is a bufferless transfer e.g. 223 /* return if this is a bufferless transfer e.g.
224 * codec <--> BT codec or GSM modem -- lg FIXME */ 224 * codec <--> BT codec or GSM modem -- lg FIXME */
@@ -263,7 +263,7 @@ static int s3c24xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
263 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data; 263 struct s3c24xx_runtime_data *prtd = substream->runtime->private_data;
264 int ret = 0; 264 int ret = 0;
265 265
266 DBG("Entered %s\n", __FUNCTION__); 266 DBG("Entered %s\n", __func__);
267 267
268 spin_lock(&prtd->lock); 268 spin_lock(&prtd->lock);
269 269
@@ -301,7 +301,7 @@ static snd_pcm_uframes_t
301 unsigned long res; 301 unsigned long res;
302 dma_addr_t src, dst; 302 dma_addr_t src, dst;
303 303
304 DBG("Entered %s\n", __FUNCTION__); 304 DBG("Entered %s\n", __func__);
305 305
306 spin_lock(&prtd->lock); 306 spin_lock(&prtd->lock);
307 s3c2410_dma_getposition(prtd->params->channel, &src, &dst); 307 s3c2410_dma_getposition(prtd->params->channel, &src, &dst);
@@ -334,7 +334,7 @@ static int s3c24xx_pcm_open(struct snd_pcm_substream *substream)
334 struct snd_pcm_runtime *runtime = substream->runtime; 334 struct snd_pcm_runtime *runtime = substream->runtime;
335 struct s3c24xx_runtime_data *prtd; 335 struct s3c24xx_runtime_data *prtd;
336 336
337 DBG("Entered %s\n", __FUNCTION__); 337 DBG("Entered %s\n", __func__);
338 338
339 snd_soc_set_runtime_hwparams(substream, &s3c24xx_pcm_hardware); 339 snd_soc_set_runtime_hwparams(substream, &s3c24xx_pcm_hardware);
340 340
@@ -353,7 +353,7 @@ static int s3c24xx_pcm_close(struct snd_pcm_substream *substream)
353 struct snd_pcm_runtime *runtime = substream->runtime; 353 struct snd_pcm_runtime *runtime = substream->runtime;
354 struct s3c24xx_runtime_data *prtd = runtime->private_data; 354 struct s3c24xx_runtime_data *prtd = runtime->private_data;
355 355
356 DBG("Entered %s\n", __FUNCTION__); 356 DBG("Entered %s\n", __func__);
357 357
358 if (prtd) 358 if (prtd)
359 kfree(prtd); 359 kfree(prtd);
@@ -368,7 +368,7 @@ static int s3c24xx_pcm_mmap(struct snd_pcm_substream *substream,
368{ 368{
369 struct snd_pcm_runtime *runtime = substream->runtime; 369 struct snd_pcm_runtime *runtime = substream->runtime;
370 370
371 DBG("Entered %s\n", __FUNCTION__); 371 DBG("Entered %s\n", __func__);
372 372
373 return dma_mmap_writecombine(substream->pcm->card->dev, vma, 373 return dma_mmap_writecombine(substream->pcm->card->dev, vma,
374 runtime->dma_area, 374 runtime->dma_area,
@@ -394,7 +394,7 @@ static int s3c24xx_pcm_preallocate_dma_buffer(struct snd_pcm *pcm, int stream)
394 struct snd_dma_buffer *buf = &substream->dma_buffer; 394 struct snd_dma_buffer *buf = &substream->dma_buffer;
395 size_t size = s3c24xx_pcm_hardware.buffer_bytes_max; 395 size_t size = s3c24xx_pcm_hardware.buffer_bytes_max;
396 396
397 DBG("Entered %s\n", __FUNCTION__); 397 DBG("Entered %s\n", __func__);
398 398
399 buf->dev.type = SNDRV_DMA_TYPE_DEV; 399 buf->dev.type = SNDRV_DMA_TYPE_DEV;
400 buf->dev.dev = pcm->card->dev; 400 buf->dev.dev = pcm->card->dev;
@@ -413,7 +413,7 @@ static void s3c24xx_pcm_free_dma_buffers(struct snd_pcm *pcm)
413 struct snd_dma_buffer *buf; 413 struct snd_dma_buffer *buf;
414 int stream; 414 int stream;
415 415
416 DBG("Entered %s\n", __FUNCTION__); 416 DBG("Entered %s\n", __func__);
417 417
418 for (stream = 0; stream < 2; stream++) { 418 for (stream = 0; stream < 2; stream++) {
419 substream = pcm->streams[stream].substream; 419 substream = pcm->streams[stream].substream;
@@ -437,7 +437,7 @@ static int s3c24xx_pcm_new(struct snd_card *card,
437{ 437{
438 int ret = 0; 438 int ret = 0;
439 439
440 DBG("Entered %s\n", __FUNCTION__); 440 DBG("Entered %s\n", __func__);
441 441
442 if (!card->dev->dma_mask) 442 if (!card->dev->dma_mask)
443 card->dev->dma_mask = &s3c24xx_pcm_dmamask; 443 card->dev->dma_mask = &s3c24xx_pcm_dmamask;
diff --git a/sound/soc/sh/Kconfig b/sound/soc/sh/Kconfig
index f03220d23e73..4c1e013381c9 100644
--- a/sound/soc/sh/Kconfig
+++ b/sound/soc/sh/Kconfig
@@ -1,4 +1,5 @@
1menu "SoC Audio support for SuperH" 1menu "SoC Audio support for SuperH"
2 depends on SUPERH
2 3
3config SND_SOC_PCM_SH7760 4config SND_SOC_PCM_SH7760
4 tristate "SoC Audio support for Renesas SH7760" 5 tristate "SoC Audio support for Renesas SH7760"
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 9eb5479787c1..e148db940cfc 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -839,6 +839,7 @@ static int soc_remove(struct platform_device *pdev)
839static struct platform_driver soc_driver = { 839static struct platform_driver soc_driver = {
840 .driver = { 840 .driver = {
841 .name = "soc-audio", 841 .name = "soc-audio",
842 .owner = THIS_MODULE,
842 }, 843 },
843 .probe = soc_probe, 844 .probe = soc_probe,
844 .remove = soc_remove, 845 .remove = soc_remove,
@@ -1601,3 +1602,4 @@ module_exit(snd_soc_exit);
1601MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com"); 1602MODULE_AUTHOR("Liam Girdwood, liam.girdwood@wolfsonmicro.com, www.wolfsonmicro.com");
1602MODULE_DESCRIPTION("ALSA SoC Core"); 1603MODULE_DESCRIPTION("ALSA SoC Core");
1603MODULE_LICENSE("GPL"); 1604MODULE_LICENSE("GPL");
1605MODULE_ALIAS("platform:soc-audio");
diff --git a/sound/soc/soc-dapm.c b/sound/soc/soc-dapm.c
index 620d7ea3c15f..af3326c63504 100644
--- a/sound/soc/soc-dapm.c
+++ b/sound/soc/soc-dapm.c
@@ -226,7 +226,7 @@ static int dapm_update_bits(struct snd_soc_dapm_widget *widget)
226 snd_soc_write(codec, widget->reg, new); 226 snd_soc_write(codec, widget->reg, new);
227 pop_wait(POP_TIME); 227 pop_wait(POP_TIME);
228 } 228 }
229 dbg("reg old %x new %x change %d\n", old, new, change); 229 dbg("reg %x old %x new %x change %d\n", widget->reg, old, new, change);
230 return change; 230 return change;
231} 231}
232 232
@@ -1288,7 +1288,7 @@ int snd_soc_dapm_stream_event(struct snd_soc_codec *codec,
1288 mutex_unlock(&codec->mutex); 1288 mutex_unlock(&codec->mutex);
1289 1289
1290 dapm_power_widgets(codec, event); 1290 dapm_power_widgets(codec, event);
1291 dump_dapm(codec, __FUNCTION__); 1291 dump_dapm(codec, __func__);
1292 return 0; 1292 return 0;
1293} 1293}
1294EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event); 1294EXPORT_SYMBOL_GPL(snd_soc_dapm_stream_event);
@@ -1334,10 +1334,11 @@ int snd_soc_dapm_set_endpoint(struct snd_soc_codec *codec,
1334 list_for_each_entry(w, &codec->dapm_widgets, list) { 1334 list_for_each_entry(w, &codec->dapm_widgets, list) {
1335 if (!strcmp(w->name, endpoint)) { 1335 if (!strcmp(w->name, endpoint)) {
1336 w->connected = status; 1336 w->connected = status;
1337 return 0;
1337 } 1338 }
1338 } 1339 }
1339 1340
1340 return 0; 1341 return -ENODEV;
1341} 1342}
1342EXPORT_SYMBOL_GPL(snd_soc_dapm_set_endpoint); 1343EXPORT_SYMBOL_GPL(snd_soc_dapm_set_endpoint);
1343 1344
diff --git a/sound/spi/at73c213.c b/sound/spi/at73c213.c
index 89d6e9c35140..09802e8a6fb8 100644
--- a/sound/spi/at73c213.c
+++ b/sound/spi/at73c213.c
@@ -118,7 +118,7 @@ static struct snd_pcm_hardware snd_at73c213_playback_hw = {
118 .rates = SNDRV_PCM_RATE_CONTINUOUS, 118 .rates = SNDRV_PCM_RATE_CONTINUOUS,
119 .rate_min = 8000, /* Replaced by chip->bitrate later. */ 119 .rate_min = 8000, /* Replaced by chip->bitrate later. */
120 .rate_max = 50000, /* Replaced by chip->bitrate later. */ 120 .rate_max = 50000, /* Replaced by chip->bitrate later. */
121 .channels_min = 2, 121 .channels_min = 1,
122 .channels_max = 2, 122 .channels_max = 2,
123 .buffer_bytes_max = 64 * 1024 - 1, 123 .buffer_bytes_max = 64 * 1024 - 1,
124 .period_bytes_min = 512, 124 .period_bytes_min = 512,
@@ -133,7 +133,8 @@ static struct snd_pcm_hardware snd_at73c213_playback_hw = {
133static int snd_at73c213_set_bitrate(struct snd_at73c213 *chip) 133static int snd_at73c213_set_bitrate(struct snd_at73c213 *chip)
134{ 134{
135 unsigned long ssc_rate = clk_get_rate(chip->ssc->clk); 135 unsigned long ssc_rate = clk_get_rate(chip->ssc->clk);
136 unsigned long dac_rate_new, ssc_div, status; 136 unsigned long dac_rate_new, ssc_div;
137 int status;
137 unsigned long ssc_div_max, ssc_div_min; 138 unsigned long ssc_div_max, ssc_div_min;
138 int max_tries; 139 int max_tries;
139 140
@@ -209,7 +210,13 @@ static int snd_at73c213_pcm_open(struct snd_pcm_substream *substream)
209{ 210{
210 struct snd_at73c213 *chip = snd_pcm_substream_chip(substream); 211 struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
211 struct snd_pcm_runtime *runtime = substream->runtime; 212 struct snd_pcm_runtime *runtime = substream->runtime;
213 int err;
212 214
215 /* ensure buffer_size is a multiple of period_size */
216 err = snd_pcm_hw_constraint_integer(runtime,
217 SNDRV_PCM_HW_PARAM_PERIODS);
218 if (err < 0)
219 return err;
213 snd_at73c213_playback_hw.rate_min = chip->bitrate; 220 snd_at73c213_playback_hw.rate_min = chip->bitrate;
214 snd_at73c213_playback_hw.rate_max = chip->bitrate; 221 snd_at73c213_playback_hw.rate_max = chip->bitrate;
215 runtime->hw = snd_at73c213_playback_hw; 222 runtime->hw = snd_at73c213_playback_hw;
@@ -228,6 +235,14 @@ static int snd_at73c213_pcm_close(struct snd_pcm_substream *substream)
228static int snd_at73c213_pcm_hw_params(struct snd_pcm_substream *substream, 235static int snd_at73c213_pcm_hw_params(struct snd_pcm_substream *substream,
229 struct snd_pcm_hw_params *hw_params) 236 struct snd_pcm_hw_params *hw_params)
230{ 237{
238 struct snd_at73c213 *chip = snd_pcm_substream_chip(substream);
239 int channels = params_channels(hw_params);
240 int val;
241
242 val = ssc_readl(chip->ssc->regs, TFMR);
243 val = SSC_BFINS(TFMR_DATNB, channels - 1, val);
244 ssc_writel(chip->ssc->regs, TFMR, val);
245
231 return snd_pcm_lib_malloc_pages(substream, 246 return snd_pcm_lib_malloc_pages(substream,
232 params_buffer_bytes(hw_params)); 247 params_buffer_bytes(hw_params));
233} 248}
@@ -249,10 +264,12 @@ static int snd_at73c213_pcm_prepare(struct snd_pcm_substream *substream)
249 264
250 ssc_writel(chip->ssc->regs, PDC_TPR, 265 ssc_writel(chip->ssc->regs, PDC_TPR,
251 (long)runtime->dma_addr); 266 (long)runtime->dma_addr);
252 ssc_writel(chip->ssc->regs, PDC_TCR, runtime->period_size * 2); 267 ssc_writel(chip->ssc->regs, PDC_TCR,
268 runtime->period_size * runtime->channels);
253 ssc_writel(chip->ssc->regs, PDC_TNPR, 269 ssc_writel(chip->ssc->regs, PDC_TNPR,
254 (long)runtime->dma_addr + block_size); 270 (long)runtime->dma_addr + block_size);
255 ssc_writel(chip->ssc->regs, PDC_TNCR, runtime->period_size * 2); 271 ssc_writel(chip->ssc->regs, PDC_TNCR,
272 runtime->period_size * runtime->channels);
256 273
257 return 0; 274 return 0;
258} 275}
@@ -314,15 +331,6 @@ static struct snd_pcm_ops at73c213_playback_ops = {
314 .pointer = snd_at73c213_pcm_pointer, 331 .pointer = snd_at73c213_pcm_pointer,
315}; 332};
316 333
317static void snd_at73c213_pcm_free(struct snd_pcm *pcm)
318{
319 struct snd_at73c213 *chip = snd_pcm_chip(pcm);
320 if (chip->pcm) {
321 snd_pcm_lib_preallocate_free_for_all(chip->pcm);
322 chip->pcm = NULL;
323 }
324}
325
326static int __devinit snd_at73c213_pcm_new(struct snd_at73c213 *chip, int device) 334static int __devinit snd_at73c213_pcm_new(struct snd_at73c213 *chip, int device)
327{ 335{
328 struct snd_pcm *pcm; 336 struct snd_pcm *pcm;
@@ -334,7 +342,6 @@ static int __devinit snd_at73c213_pcm_new(struct snd_at73c213 *chip, int device)
334 goto out; 342 goto out;
335 343
336 pcm->private_data = chip; 344 pcm->private_data = chip;
337 pcm->private_free = snd_at73c213_pcm_free;
338 pcm->info_flags = SNDRV_PCM_INFO_BLOCK_TRANSFER; 345 pcm->info_flags = SNDRV_PCM_INFO_BLOCK_TRANSFER;
339 strcpy(pcm->name, "at73c213"); 346 strcpy(pcm->name, "at73c213");
340 chip->pcm = pcm; 347 chip->pcm = pcm;
@@ -375,7 +382,8 @@ static irqreturn_t snd_at73c213_interrupt(int irq, void *dev_id)
375 382
376 ssc_writel(chip->ssc->regs, PDC_TNPR, 383 ssc_writel(chip->ssc->regs, PDC_TNPR,
377 (long)runtime->dma_addr + offset); 384 (long)runtime->dma_addr + offset);
378 ssc_writel(chip->ssc->regs, PDC_TNCR, runtime->period_size * 2); 385 ssc_writel(chip->ssc->regs, PDC_TNCR,
386 runtime->period_size * runtime->channels);
379 retval = IRQ_HANDLED; 387 retval = IRQ_HANDLED;
380 } 388 }
381 389
@@ -737,7 +745,7 @@ cleanup:
737/* 745/*
738 * Device functions 746 * Device functions
739 */ 747 */
740static int snd_at73c213_ssc_init(struct snd_at73c213 *chip) 748static int __devinit snd_at73c213_ssc_init(struct snd_at73c213 *chip)
741{ 749{
742 /* 750 /*
743 * Continuous clock output. 751 * Continuous clock output.
@@ -767,7 +775,7 @@ static int snd_at73c213_ssc_init(struct snd_at73c213 *chip)
767 return 0; 775 return 0;
768} 776}
769 777
770static int snd_at73c213_chip_init(struct snd_at73c213 *chip) 778static int __devinit snd_at73c213_chip_init(struct snd_at73c213 *chip)
771{ 779{
772 int retval; 780 int retval;
773 unsigned char dac_ctrl = 0; 781 unsigned char dac_ctrl = 0;
@@ -933,7 +941,7 @@ out:
933 return retval; 941 return retval;
934} 942}
935 943
936static int snd_at73c213_probe(struct spi_device *spi) 944static int __devinit snd_at73c213_probe(struct spi_device *spi)
937{ 945{
938 struct snd_card *card; 946 struct snd_card *card;
939 struct snd_at73c213 *chip; 947 struct snd_at73c213 *chip;
diff --git a/sound/usb/caiaq/caiaq-audio.c b/sound/usb/caiaq/caiaq-audio.c
index 9cc4cd8283f9..24970a5c888f 100644
--- a/sound/usb/caiaq/caiaq-audio.c
+++ b/sound/usb/caiaq/caiaq-audio.c
@@ -1,5 +1,5 @@
1/* 1/*
2 * Copyright (c) 2006,2007 Daniel Mack, Karsten Wiese 2 * Copyright (c) 2006-2008 Daniel Mack, Karsten Wiese
3 * 3 *
4 * This program is free software; you can redistribute it and/or modify 4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by 5 * it under the terms of the GNU General Public License as published by
@@ -39,7 +39,8 @@
39#define BYTES_PER_SAMPLE 3 39#define BYTES_PER_SAMPLE 3
40#define BYTES_PER_SAMPLE_USB 4 40#define BYTES_PER_SAMPLE_USB 4
41#define MAX_BUFFER_SIZE (128*1024) 41#define MAX_BUFFER_SIZE (128*1024)
42 42#define MAX_ENDPOINT_SIZE 512
43
43#define ENDPOINT_CAPTURE 2 44#define ENDPOINT_CAPTURE 2
44#define ENDPOINT_PLAYBACK 6 45#define ENDPOINT_PLAYBACK 6
45 46
@@ -77,10 +78,15 @@ static void
77deactivate_substream(struct snd_usb_caiaqdev *dev, 78deactivate_substream(struct snd_usb_caiaqdev *dev,
78 struct snd_pcm_substream *sub) 79 struct snd_pcm_substream *sub)
79{ 80{
81 unsigned long flags;
82 spin_lock_irqsave(&dev->spinlock, flags);
83
80 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK) 84 if (sub->stream == SNDRV_PCM_STREAM_PLAYBACK)
81 dev->sub_playback[sub->number] = NULL; 85 dev->sub_playback[sub->number] = NULL;
82 else 86 else
83 dev->sub_capture[sub->number] = NULL; 87 dev->sub_capture[sub->number] = NULL;
88
89 spin_unlock_irqrestore(&dev->spinlock, flags);
84} 90}
85 91
86static int 92static int
@@ -97,13 +103,13 @@ static int stream_start(struct snd_usb_caiaqdev *dev)
97{ 103{
98 int i, ret; 104 int i, ret;
99 105
100 debug("stream_start(%p)\n", dev); 106 debug("%s(%p)\n", __func__, dev);
101 spin_lock_irq(&dev->spinlock); 107
102 if (dev->streaming) { 108 if (dev->streaming)
103 spin_unlock_irq(&dev->spinlock);
104 return -EINVAL; 109 return -EINVAL;
105 }
106 110
111 memset(dev->sub_playback, 0, sizeof(dev->sub_playback));
112 memset(dev->sub_capture, 0, sizeof(dev->sub_capture));
107 dev->input_panic = 0; 113 dev->input_panic = 0;
108 dev->output_panic = 0; 114 dev->output_panic = 0;
109 dev->first_packet = 1; 115 dev->first_packet = 1;
@@ -112,37 +118,35 @@ static int stream_start(struct snd_usb_caiaqdev *dev)
112 for (i = 0; i < N_URBS; i++) { 118 for (i = 0; i < N_URBS; i++) {
113 ret = usb_submit_urb(dev->data_urbs_in[i], GFP_ATOMIC); 119 ret = usb_submit_urb(dev->data_urbs_in[i], GFP_ATOMIC);
114 if (ret) { 120 if (ret) {
115 log("unable to trigger initial read #%d! (ret = %d)\n", 121 log("unable to trigger read #%d! (ret %d)\n", i, ret);
116 i, ret);
117 dev->streaming = 0; 122 dev->streaming = 0;
118 spin_unlock_irq(&dev->spinlock);
119 return -EPIPE; 123 return -EPIPE;
120 } 124 }
121 } 125 }
122 126
123 spin_unlock_irq(&dev->spinlock);
124 return 0; 127 return 0;
125} 128}
126 129
127static void stream_stop(struct snd_usb_caiaqdev *dev) 130static void stream_stop(struct snd_usb_caiaqdev *dev)
128{ 131{
129 int i; 132 int i;
130 133
131 debug("stream_stop(%p)\n", dev); 134 debug("%s(%p)\n", __func__, dev);
132 if (!dev->streaming) 135 if (!dev->streaming)
133 return; 136 return;
134 137
135 dev->streaming = 0; 138 dev->streaming = 0;
139
136 for (i = 0; i < N_URBS; i++) { 140 for (i = 0; i < N_URBS; i++) {
137 usb_unlink_urb(dev->data_urbs_in[i]); 141 usb_kill_urb(dev->data_urbs_in[i]);
138 usb_unlink_urb(dev->data_urbs_out[i]); 142 usb_kill_urb(dev->data_urbs_out[i]);
139 } 143 }
140} 144}
141 145
142static int snd_usb_caiaq_substream_open(struct snd_pcm_substream *substream) 146static int snd_usb_caiaq_substream_open(struct snd_pcm_substream *substream)
143{ 147{
144 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream); 148 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream);
145 debug("snd_usb_caiaq_substream_open(%p)\n", substream); 149 debug("%s(%p)\n", __func__, substream);
146 substream->runtime->hw = dev->pcm_info; 150 substream->runtime->hw = dev->pcm_info;
147 snd_pcm_limit_hw_rates(substream->runtime); 151 snd_pcm_limit_hw_rates(substream->runtime);
148 return 0; 152 return 0;
@@ -152,7 +156,7 @@ static int snd_usb_caiaq_substream_close(struct snd_pcm_substream *substream)
152{ 156{
153 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream); 157 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream);
154 158
155 debug("snd_usb_caiaq_substream_close(%p)\n", substream); 159 debug("%s(%p)\n", __func__, substream);
156 if (all_substreams_zero(dev->sub_playback) && 160 if (all_substreams_zero(dev->sub_playback) &&
157 all_substreams_zero(dev->sub_capture)) { 161 all_substreams_zero(dev->sub_capture)) {
158 /* when the last client has stopped streaming, 162 /* when the last client has stopped streaming,
@@ -160,24 +164,22 @@ static int snd_usb_caiaq_substream_close(struct snd_pcm_substream *substream)
160 stream_stop(dev); 164 stream_stop(dev);
161 dev->pcm_info.rates = dev->samplerates; 165 dev->pcm_info.rates = dev->samplerates;
162 } 166 }
163 167
164 return 0; 168 return 0;
165} 169}
166 170
167static int snd_usb_caiaq_pcm_hw_params(struct snd_pcm_substream *sub, 171static int snd_usb_caiaq_pcm_hw_params(struct snd_pcm_substream *sub,
168 struct snd_pcm_hw_params *hw_params) 172 struct snd_pcm_hw_params *hw_params)
169{ 173{
170 debug("snd_usb_caiaq_pcm_hw_params(%p)\n", sub); 174 debug("%s(%p)\n", __func__, sub);
171 return snd_pcm_lib_malloc_pages(sub, params_buffer_bytes(hw_params)); 175 return snd_pcm_lib_malloc_pages(sub, params_buffer_bytes(hw_params));
172} 176}
173 177
174static int snd_usb_caiaq_pcm_hw_free(struct snd_pcm_substream *sub) 178static int snd_usb_caiaq_pcm_hw_free(struct snd_pcm_substream *sub)
175{ 179{
176 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(sub); 180 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(sub);
177 debug("snd_usb_caiaq_pcm_hw_free(%p)\n", sub); 181 debug("%s(%p)\n", __func__, sub);
178 spin_lock_irq(&dev->spinlock);
179 deactivate_substream(dev, sub); 182 deactivate_substream(dev, sub);
180 spin_unlock_irq(&dev->spinlock);
181 return snd_pcm_lib_free_pages(sub); 183 return snd_pcm_lib_free_pages(sub);
182} 184}
183 185
@@ -196,12 +198,12 @@ static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
196 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream); 198 struct snd_usb_caiaqdev *dev = snd_pcm_substream_chip(substream);
197 struct snd_pcm_runtime *runtime = substream->runtime; 199 struct snd_pcm_runtime *runtime = substream->runtime;
198 200
199 debug("snd_usb_caiaq_pcm_prepare(%p)\n", substream); 201 debug("%s(%p)\n", __func__, substream);
200 202
201 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) 203 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
202 dev->audio_out_buf_pos[index] = BYTES_PER_SAMPLE + 1; 204 dev->audio_out_buf_pos[index] = BYTES_PER_SAMPLE + 1;
203 else 205 else
204 dev->audio_in_buf_pos[index] = 0; 206 dev->audio_in_buf_pos[index] = BYTES_PER_SAMPLE;
205 207
206 if (dev->streaming) 208 if (dev->streaming)
207 return 0; 209 return 0;
@@ -220,7 +222,10 @@ static int snd_usb_caiaq_pcm_prepare(struct snd_pcm_substream *substream)
220 222
221 bpp = ((runtime->rate / 8000) + CLOCK_DRIFT_TOLERANCE) 223 bpp = ((runtime->rate / 8000) + CLOCK_DRIFT_TOLERANCE)
222 * bytes_per_sample * CHANNELS_PER_STREAM * dev->n_streams; 224 * bytes_per_sample * CHANNELS_PER_STREAM * dev->n_streams;
223 225
226 if (bpp > MAX_ENDPOINT_SIZE)
227 bpp = MAX_ENDPOINT_SIZE;
228
224 ret = snd_usb_caiaq_set_audio_params(dev, runtime->rate, 229 ret = snd_usb_caiaq_set_audio_params(dev, runtime->rate,
225 runtime->sample_bits, bpp); 230 runtime->sample_bits, bpp);
226 if (ret) 231 if (ret)
@@ -247,15 +252,11 @@ static int snd_usb_caiaq_pcm_trigger(struct snd_pcm_substream *sub, int cmd)
247 switch (cmd) { 252 switch (cmd) {
248 case SNDRV_PCM_TRIGGER_START: 253 case SNDRV_PCM_TRIGGER_START:
249 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: 254 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
250 spin_lock(&dev->spinlock);
251 activate_substream(dev, sub); 255 activate_substream(dev, sub);
252 spin_unlock(&dev->spinlock);
253 break; 256 break;
254 case SNDRV_PCM_TRIGGER_STOP: 257 case SNDRV_PCM_TRIGGER_STOP:
255 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: 258 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
256 spin_lock(&dev->spinlock);
257 deactivate_substream(dev, sub); 259 deactivate_substream(dev, sub);
258 spin_unlock(&dev->spinlock);
259 break; 260 break;
260 default: 261 default:
261 return -EINVAL; 262 return -EINVAL;
@@ -328,8 +329,6 @@ static void read_in_urb_mode0(struct snd_usb_caiaqdev *dev,
328 if (all_substreams_zero(dev->sub_capture)) 329 if (all_substreams_zero(dev->sub_capture))
329 return; 330 return;
330 331
331 spin_lock(&dev->spinlock);
332
333 for (i = 0; i < iso->actual_length;) { 332 for (i = 0; i < iso->actual_length;) {
334 for (stream = 0; stream < dev->n_streams; stream++, i++) { 333 for (stream = 0; stream < dev->n_streams; stream++, i++) {
335 sub = dev->sub_capture[stream]; 334 sub = dev->sub_capture[stream];
@@ -345,8 +344,6 @@ static void read_in_urb_mode0(struct snd_usb_caiaqdev *dev,
345 } 344 }
346 } 345 }
347 } 346 }
348
349 spin_unlock(&dev->spinlock);
350} 347}
351 348
352static void read_in_urb_mode2(struct snd_usb_caiaqdev *dev, 349static void read_in_urb_mode2(struct snd_usb_caiaqdev *dev,
@@ -358,8 +355,6 @@ static void read_in_urb_mode2(struct snd_usb_caiaqdev *dev,
358 struct snd_pcm_substream *sub; 355 struct snd_pcm_substream *sub;
359 int stream, i; 356 int stream, i;
360 357
361 spin_lock(&dev->spinlock);
362
363 for (i = 0; i < iso->actual_length;) { 358 for (i = 0; i < iso->actual_length;) {
364 if (i % (dev->n_streams * BYTES_PER_SAMPLE_USB) == 0) { 359 if (i % (dev->n_streams * BYTES_PER_SAMPLE_USB) == 0) {
365 for (stream = 0; 360 for (stream = 0;
@@ -393,8 +388,6 @@ static void read_in_urb_mode2(struct snd_usb_caiaqdev *dev,
393 } 388 }
394 } 389 }
395 } 390 }
396
397 spin_unlock(&dev->spinlock);
398} 391}
399 392
400static void read_in_urb(struct snd_usb_caiaqdev *dev, 393static void read_in_urb(struct snd_usb_caiaqdev *dev,
@@ -418,8 +411,6 @@ static void read_in_urb(struct snd_usb_caiaqdev *dev,
418 dev->input_panic ? "(input)" : "", 411 dev->input_panic ? "(input)" : "",
419 dev->output_panic ? "(output)" : ""); 412 dev->output_panic ? "(output)" : "");
420 } 413 }
421
422 check_for_elapsed_periods(dev, dev->sub_capture);
423} 414}
424 415
425static void fill_out_urb(struct snd_usb_caiaqdev *dev, 416static void fill_out_urb(struct snd_usb_caiaqdev *dev,
@@ -429,8 +420,6 @@ static void fill_out_urb(struct snd_usb_caiaqdev *dev,
429 unsigned char *usb_buf = urb->transfer_buffer + iso->offset; 420 unsigned char *usb_buf = urb->transfer_buffer + iso->offset;
430 struct snd_pcm_substream *sub; 421 struct snd_pcm_substream *sub;
431 int stream, i; 422 int stream, i;
432
433 spin_lock(&dev->spinlock);
434 423
435 for (i = 0; i < iso->length;) { 424 for (i = 0; i < iso->length;) {
436 for (stream = 0; stream < dev->n_streams; stream++, i++) { 425 for (stream = 0; stream < dev->n_streams; stream++, i++) {
@@ -456,9 +445,6 @@ static void fill_out_urb(struct snd_usb_caiaqdev *dev,
456 for (stream = 0; stream < dev->n_streams; stream++, i++) 445 for (stream = 0; stream < dev->n_streams; stream++, i++)
457 usb_buf[i] = MAKE_CHECKBYTE(dev, stream, i); 446 usb_buf[i] = MAKE_CHECKBYTE(dev, stream, i);
458 } 447 }
459
460 spin_unlock(&dev->spinlock);
461 check_for_elapsed_periods(dev, dev->sub_playback);
462} 448}
463 449
464static void read_completed(struct urb *urb) 450static void read_completed(struct urb *urb)
@@ -472,6 +458,7 @@ static void read_completed(struct urb *urb)
472 return; 458 return;
473 459
474 dev = info->dev; 460 dev = info->dev;
461
475 if (!dev->streaming) 462 if (!dev->streaming)
476 return; 463 return;
477 464
@@ -489,8 +476,12 @@ static void read_completed(struct urb *urb)
489 out->iso_frame_desc[outframe].offset = BYTES_PER_FRAME * frame; 476 out->iso_frame_desc[outframe].offset = BYTES_PER_FRAME * frame;
490 477
491 if (len > 0) { 478 if (len > 0) {
479 spin_lock(&dev->spinlock);
492 fill_out_urb(dev, out, &out->iso_frame_desc[outframe]); 480 fill_out_urb(dev, out, &out->iso_frame_desc[outframe]);
493 read_in_urb(dev, urb, &urb->iso_frame_desc[frame]); 481 read_in_urb(dev, urb, &urb->iso_frame_desc[frame]);
482 spin_unlock(&dev->spinlock);
483 check_for_elapsed_periods(dev, dev->sub_playback);
484 check_for_elapsed_periods(dev, dev->sub_capture);
494 send_it = 1; 485 send_it = 1;
495 } 486 }
496 487
@@ -696,7 +687,7 @@ int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *dev)
696 687
697void snd_usb_caiaq_audio_free(struct snd_usb_caiaqdev *dev) 688void snd_usb_caiaq_audio_free(struct snd_usb_caiaqdev *dev)
698{ 689{
699 debug("snd_usb_caiaq_audio_free (%p)\n", dev); 690 debug("%s(%p)\n", __func__, dev);
700 stream_stop(dev); 691 stream_stop(dev);
701 free_urbs(dev->data_urbs_in); 692 free_urbs(dev->data_urbs_in);
702 free_urbs(dev->data_urbs_out); 693 free_urbs(dev->data_urbs_out);
diff --git a/sound/usb/caiaq/caiaq-device.c b/sound/usb/caiaq/caiaq-device.c
index 7c44a2c7f963..e97d8b2ac16a 100644
--- a/sound/usb/caiaq/caiaq-device.c
+++ b/sound/usb/caiaq/caiaq-device.c
@@ -42,7 +42,7 @@
42#endif 42#endif
43 43
44MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>"); 44MODULE_AUTHOR("Daniel Mack <daniel@caiaq.de>");
45MODULE_DESCRIPTION("caiaq USB audio, version 1.3.2"); 45MODULE_DESCRIPTION("caiaq USB audio, version 1.3.6");
46MODULE_LICENSE("GPL"); 46MODULE_LICENSE("GPL");
47MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2}," 47MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2},"
48 "{Native Instruments, RigKontrol3}," 48 "{Native Instruments, RigKontrol3},"
@@ -456,7 +456,7 @@ static void snd_disconnect(struct usb_interface *intf)
456 struct snd_usb_caiaqdev *dev; 456 struct snd_usb_caiaqdev *dev;
457 struct snd_card *card = dev_get_drvdata(&intf->dev); 457 struct snd_card *card = dev_get_drvdata(&intf->dev);
458 458
459 debug("snd_disconnect(%p)\n", intf); 459 debug("%s(%p)\n", __func__, intf);
460 460
461 if (!card) 461 if (!card)
462 return; 462 return;
diff --git a/sound/usb/usbaudio.c b/sound/usb/usbaudio.c
index f48838a078cb..410be4aff1ba 100644
--- a/sound/usb/usbaudio.c
+++ b/sound/usb/usbaudio.c
@@ -64,9 +64,10 @@ MODULE_SUPPORTED_DEVICE("{{Generic,USB Audio}}");
64 64
65static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */ 65static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-MAX */
66static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */ 66static char *id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* ID for this card */
67static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP; /* Enable this card */ 67static int enable[SNDRV_CARDS] = SNDRV_DEFAULT_ENABLE_PNP;/* Enable this card */
68static int vid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 }; /* Vendor ID for this card */ 68/* Vendor/product IDs for this card */
69static int pid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 }; /* Product ID for this card */ 69static int vid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 };
70static int pid[SNDRV_CARDS] = { [0 ... (SNDRV_CARDS-1)] = -1 };
70static int nrpacks = 8; /* max. number of packets per urb */ 71static int nrpacks = 8; /* max. number of packets per urb */
71static int async_unlink = 1; 72static int async_unlink = 1;
72static int device_setup[SNDRV_CARDS]; /* device parameter for this card*/ 73static int device_setup[SNDRV_CARDS]; /* device parameter for this card*/
@@ -687,7 +688,7 @@ static void snd_complete_urb(struct urb *urb)
687 int err = 0; 688 int err = 0;
688 689
689 if ((subs->running && subs->ops.retire(subs, substream->runtime, urb)) || 690 if ((subs->running && subs->ops.retire(subs, substream->runtime, urb)) ||
690 ! subs->running || /* can be stopped during retire callback */ 691 !subs->running || /* can be stopped during retire callback */
691 (err = subs->ops.prepare(subs, substream->runtime, urb)) < 0 || 692 (err = subs->ops.prepare(subs, substream->runtime, urb)) < 0 ||
692 (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { 693 (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
693 clear_bit(ctx->index, &subs->active_mask); 694 clear_bit(ctx->index, &subs->active_mask);
@@ -710,7 +711,7 @@ static void snd_complete_sync_urb(struct urb *urb)
710 int err = 0; 711 int err = 0;
711 712
712 if ((subs->running && subs->ops.retire_sync(subs, substream->runtime, urb)) || 713 if ((subs->running && subs->ops.retire_sync(subs, substream->runtime, urb)) ||
713 ! subs->running || /* can be stopped during retire callback */ 714 !subs->running || /* can be stopped during retire callback */
714 (err = subs->ops.prepare_sync(subs, substream->runtime, urb)) < 0 || 715 (err = subs->ops.prepare_sync(subs, substream->runtime, urb)) < 0 ||
715 (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) { 716 (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
716 clear_bit(ctx->index + 16, &subs->active_mask); 717 clear_bit(ctx->index + 16, &subs->active_mask);
@@ -740,7 +741,7 @@ static int snd_pcm_alloc_vmalloc_buffer(struct snd_pcm_substream *subs, size_t s
740 vfree(runtime->dma_area); 741 vfree(runtime->dma_area);
741 } 742 }
742 runtime->dma_area = vmalloc(size); 743 runtime->dma_area = vmalloc(size);
743 if (! runtime->dma_area) 744 if (!runtime->dma_area)
744 return -ENOMEM; 745 return -ENOMEM;
745 runtime->dma_bytes = size; 746 runtime->dma_bytes = size;
746 return 0; 747 return 0;
@@ -772,12 +773,12 @@ static int deactivate_urbs(struct snd_usb_substream *subs, int force, int can_sl
772 773
773 async = !can_sleep && async_unlink; 774 async = !can_sleep && async_unlink;
774 775
775 if (! async && in_interrupt()) 776 if (!async && in_interrupt())
776 return 0; 777 return 0;
777 778
778 for (i = 0; i < subs->nurbs; i++) { 779 for (i = 0; i < subs->nurbs; i++) {
779 if (test_bit(i, &subs->active_mask)) { 780 if (test_bit(i, &subs->active_mask)) {
780 if (! test_and_set_bit(i, &subs->unlink_mask)) { 781 if (!test_and_set_bit(i, &subs->unlink_mask)) {
781 struct urb *u = subs->dataurb[i].urb; 782 struct urb *u = subs->dataurb[i].urb;
782 if (async) 783 if (async)
783 usb_unlink_urb(u); 784 usb_unlink_urb(u);
@@ -789,7 +790,7 @@ static int deactivate_urbs(struct snd_usb_substream *subs, int force, int can_sl
789 if (subs->syncpipe) { 790 if (subs->syncpipe) {
790 for (i = 0; i < SYNC_URBS; i++) { 791 for (i = 0; i < SYNC_URBS; i++) {
791 if (test_bit(i+16, &subs->active_mask)) { 792 if (test_bit(i+16, &subs->active_mask)) {
792 if (! test_and_set_bit(i+16, &subs->unlink_mask)) { 793 if (!test_and_set_bit(i+16, &subs->unlink_mask)) {
793 struct urb *u = subs->syncurb[i].urb; 794 struct urb *u = subs->syncurb[i].urb;
794 if (async) 795 if (async)
795 usb_unlink_urb(u); 796 usb_unlink_urb(u);
@@ -1137,12 +1138,12 @@ static int init_substream_urbs(struct snd_usb_substream *subs, unsigned int peri
1137 if (subs->fmt_type == USB_FORMAT_TYPE_II) 1138 if (subs->fmt_type == USB_FORMAT_TYPE_II)
1138 u->packets++; /* for transfer delimiter */ 1139 u->packets++; /* for transfer delimiter */
1139 u->urb = usb_alloc_urb(u->packets, GFP_KERNEL); 1140 u->urb = usb_alloc_urb(u->packets, GFP_KERNEL);
1140 if (! u->urb) 1141 if (!u->urb)
1141 goto out_of_memory; 1142 goto out_of_memory;
1142 u->urb->transfer_buffer = 1143 u->urb->transfer_buffer =
1143 usb_buffer_alloc(subs->dev, u->buffer_size, GFP_KERNEL, 1144 usb_buffer_alloc(subs->dev, u->buffer_size, GFP_KERNEL,
1144 &u->urb->transfer_dma); 1145 &u->urb->transfer_dma);
1145 if (! u->urb->transfer_buffer) 1146 if (!u->urb->transfer_buffer)
1146 goto out_of_memory; 1147 goto out_of_memory;
1147 u->urb->pipe = subs->datapipe; 1148 u->urb->pipe = subs->datapipe;
1148 u->urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP; 1149 u->urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
@@ -1155,7 +1156,7 @@ static int init_substream_urbs(struct snd_usb_substream *subs, unsigned int peri
1155 /* allocate and initialize sync urbs */ 1156 /* allocate and initialize sync urbs */
1156 subs->syncbuf = usb_buffer_alloc(subs->dev, SYNC_URBS * 4, 1157 subs->syncbuf = usb_buffer_alloc(subs->dev, SYNC_URBS * 4,
1157 GFP_KERNEL, &subs->sync_dma); 1158 GFP_KERNEL, &subs->sync_dma);
1158 if (! subs->syncbuf) 1159 if (!subs->syncbuf)
1159 goto out_of_memory; 1160 goto out_of_memory;
1160 for (i = 0; i < SYNC_URBS; i++) { 1161 for (i = 0; i < SYNC_URBS; i++) {
1161 struct snd_urb_ctx *u = &subs->syncurb[i]; 1162 struct snd_urb_ctx *u = &subs->syncurb[i];
@@ -1163,7 +1164,7 @@ static int init_substream_urbs(struct snd_usb_substream *subs, unsigned int peri
1163 u->subs = subs; 1164 u->subs = subs;
1164 u->packets = 1; 1165 u->packets = 1;
1165 u->urb = usb_alloc_urb(1, GFP_KERNEL); 1166 u->urb = usb_alloc_urb(1, GFP_KERNEL);
1166 if (! u->urb) 1167 if (!u->urb)
1167 goto out_of_memory; 1168 goto out_of_memory;
1168 u->urb->transfer_buffer = subs->syncbuf + i * 4; 1169 u->urb->transfer_buffer = subs->syncbuf + i * 4;
1169 u->urb->transfer_dma = subs->sync_dma + i * 4; 1170 u->urb->transfer_dma = subs->sync_dma + i * 4;
@@ -1427,8 +1428,8 @@ static int set_format(struct snd_usb_substream *subs, struct audioformat *fmt)
1427 subs->cur_audiofmt = fmt; 1428 subs->cur_audiofmt = fmt;
1428 1429
1429#if 0 1430#if 0
1430 printk("setting done: format = %d, rate = %d, channels = %d\n", 1431 printk("setting done: format = %d, rate = %d..%d, channels = %d\n",
1431 fmt->format, fmt->rate, fmt->channels); 1432 fmt->format, fmt->rate_min, fmt->rate_max, fmt->channels);
1432 printk(" datapipe = 0x%0x, syncpipe = 0x%0x\n", 1433 printk(" datapipe = 0x%0x, syncpipe = 0x%0x\n",
1433 subs->datapipe, subs->syncpipe); 1434 subs->datapipe, subs->syncpipe);
1434#endif 1435#endif
@@ -1463,7 +1464,7 @@ static int snd_usb_hw_params(struct snd_pcm_substream *substream,
1463 rate = params_rate(hw_params); 1464 rate = params_rate(hw_params);
1464 channels = params_channels(hw_params); 1465 channels = params_channels(hw_params);
1465 fmt = find_format(subs, format, rate, channels); 1466 fmt = find_format(subs, format, rate, channels);
1466 if (! fmt) { 1467 if (!fmt) {
1467 snd_printd(KERN_DEBUG "cannot set format: format = 0x%x, rate = %d, channels = %d\n", 1468 snd_printd(KERN_DEBUG "cannot set format: format = 0x%x, rate = %d, channels = %d\n",
1468 format, rate, channels); 1469 format, rate, channels);
1469 return -EINVAL; 1470 return -EINVAL;
@@ -1584,7 +1585,7 @@ static int hw_check_valid_format(struct snd_pcm_hw_params *params, struct audiof
1584 struct snd_mask *fmts = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); 1585 struct snd_mask *fmts = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT);
1585 1586
1586 /* check the format */ 1587 /* check the format */
1587 if (! snd_mask_test(fmts, fp->format)) { 1588 if (!snd_mask_test(fmts, fp->format)) {
1588 hwc_debug(" > check: no supported format %d\n", fp->format); 1589 hwc_debug(" > check: no supported format %d\n", fp->format);
1589 return 0; 1590 return 0;
1590 } 1591 }
@@ -1620,7 +1621,7 @@ static int hw_rule_rate(struct snd_pcm_hw_params *params,
1620 list_for_each(p, &subs->fmt_list) { 1621 list_for_each(p, &subs->fmt_list) {
1621 struct audioformat *fp; 1622 struct audioformat *fp;
1622 fp = list_entry(p, struct audioformat, list); 1623 fp = list_entry(p, struct audioformat, list);
1623 if (! hw_check_valid_format(params, fp)) 1624 if (!hw_check_valid_format(params, fp))
1624 continue; 1625 continue;
1625 if (changed++) { 1626 if (changed++) {
1626 if (rmin > fp->rate_min) 1627 if (rmin > fp->rate_min)
@@ -1633,7 +1634,7 @@ static int hw_rule_rate(struct snd_pcm_hw_params *params,
1633 } 1634 }
1634 } 1635 }
1635 1636
1636 if (! changed) { 1637 if (!changed) {
1637 hwc_debug(" --> get empty\n"); 1638 hwc_debug(" --> get empty\n");
1638 it->empty = 1; 1639 it->empty = 1;
1639 return -EINVAL; 1640 return -EINVAL;
@@ -1674,7 +1675,7 @@ static int hw_rule_channels(struct snd_pcm_hw_params *params,
1674 list_for_each(p, &subs->fmt_list) { 1675 list_for_each(p, &subs->fmt_list) {
1675 struct audioformat *fp; 1676 struct audioformat *fp;
1676 fp = list_entry(p, struct audioformat, list); 1677 fp = list_entry(p, struct audioformat, list);
1677 if (! hw_check_valid_format(params, fp)) 1678 if (!hw_check_valid_format(params, fp))
1678 continue; 1679 continue;
1679 if (changed++) { 1680 if (changed++) {
1680 if (rmin > fp->channels) 1681 if (rmin > fp->channels)
@@ -1687,7 +1688,7 @@ static int hw_rule_channels(struct snd_pcm_hw_params *params,
1687 } 1688 }
1688 } 1689 }
1689 1690
1690 if (! changed) { 1691 if (!changed) {
1691 hwc_debug(" --> get empty\n"); 1692 hwc_debug(" --> get empty\n");
1692 it->empty = 1; 1693 it->empty = 1;
1693 return -EINVAL; 1694 return -EINVAL;
@@ -1727,7 +1728,7 @@ static int hw_rule_format(struct snd_pcm_hw_params *params,
1727 list_for_each(p, &subs->fmt_list) { 1728 list_for_each(p, &subs->fmt_list) {
1728 struct audioformat *fp; 1729 struct audioformat *fp;
1729 fp = list_entry(p, struct audioformat, list); 1730 fp = list_entry(p, struct audioformat, list);
1730 if (! hw_check_valid_format(params, fp)) 1731 if (!hw_check_valid_format(params, fp))
1731 continue; 1732 continue;
1732 fbits |= (1ULL << fp->format); 1733 fbits |= (1ULL << fp->format);
1733 } 1734 }
@@ -1736,7 +1737,7 @@ static int hw_rule_format(struct snd_pcm_hw_params *params,
1736 oldbits[1] = fmt->bits[1]; 1737 oldbits[1] = fmt->bits[1];
1737 fmt->bits[0] &= (u32)fbits; 1738 fmt->bits[0] &= (u32)fbits;
1738 fmt->bits[1] &= (u32)(fbits >> 32); 1739 fmt->bits[1] &= (u32)(fbits >> 32);
1739 if (! fmt->bits[0] && ! fmt->bits[1]) { 1740 if (!fmt->bits[0] && !fmt->bits[1]) {
1740 hwc_debug(" --> get empty\n"); 1741 hwc_debug(" --> get empty\n");
1741 return -EINVAL; 1742 return -EINVAL;
1742 } 1743 }
@@ -1762,8 +1763,10 @@ static int check_hw_params_convention(struct snd_usb_substream *subs)
1762 1763
1763 channels = kcalloc(MAX_MASK, sizeof(u32), GFP_KERNEL); 1764 channels = kcalloc(MAX_MASK, sizeof(u32), GFP_KERNEL);
1764 rates = kcalloc(MAX_MASK, sizeof(u32), GFP_KERNEL); 1765 rates = kcalloc(MAX_MASK, sizeof(u32), GFP_KERNEL);
1765 if (!channels || !rates) 1766 if (!channels || !rates) {
1767 err = -ENOMEM;
1766 goto __out; 1768 goto __out;
1769 }
1767 1770
1768 list_for_each(p, &subs->fmt_list) { 1771 list_for_each(p, &subs->fmt_list) {
1769 struct audioformat *f; 1772 struct audioformat *f;
@@ -1916,7 +1919,10 @@ static int setup_hw_info(struct snd_pcm_runtime *runtime, struct snd_usb_substre
1916 1000 * MIN_PACKS_URB, 1919 1000 * MIN_PACKS_URB,
1917 /*(nrpacks * MAX_URBS) * 1000*/ UINT_MAX); 1920 /*(nrpacks * MAX_URBS) * 1000*/ UINT_MAX);
1918 1921
1919 if (check_hw_params_convention(subs)) { 1922 err = check_hw_params_convention(subs);
1923 if (err < 0)
1924 return err;
1925 else if (err) {
1920 hwc_debug("setting extra hw constraints...\n"); 1926 hwc_debug("setting extra hw constraints...\n");
1921 if ((err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 1927 if ((err = snd_pcm_hw_rule_add(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
1922 hw_rule_rate, subs, 1928 hw_rule_rate, subs,
@@ -2222,7 +2228,7 @@ static void proc_pcm_format_add(struct snd_usb_stream *stream)
2222 struct snd_card *card = stream->chip->card; 2228 struct snd_card *card = stream->chip->card;
2223 2229
2224 sprintf(name, "stream%d", stream->pcm_index); 2230 sprintf(name, "stream%d", stream->pcm_index);
2225 if (! snd_card_proc_new(card, name, &entry)) 2231 if (!snd_card_proc_new(card, name, &entry))
2226 snd_info_set_text_ops(entry, stream, proc_pcm_format_read); 2232 snd_info_set_text_ops(entry, stream, proc_pcm_format_read);
2227} 2233}
2228 2234
@@ -2278,7 +2284,7 @@ static void free_substream(struct snd_usb_substream *subs)
2278{ 2284{
2279 struct list_head *p, *n; 2285 struct list_head *p, *n;
2280 2286
2281 if (! subs->num_formats) 2287 if (!subs->num_formats)
2282 return; /* not initialized */ 2288 return; /* not initialized */
2283 list_for_each_safe(p, n, &subs->fmt_list) { 2289 list_for_each_safe(p, n, &subs->fmt_list) {
2284 struct audioformat *fp = list_entry(p, struct audioformat, list); 2290 struct audioformat *fp = list_entry(p, struct audioformat, list);
@@ -2328,7 +2334,7 @@ static int add_audio_endpoint(struct snd_usb_audio *chip, int stream, struct aud
2328 if (as->fmt_type != fp->fmt_type) 2334 if (as->fmt_type != fp->fmt_type)
2329 continue; 2335 continue;
2330 subs = &as->substream[stream]; 2336 subs = &as->substream[stream];
2331 if (! subs->endpoint) 2337 if (!subs->endpoint)
2332 continue; 2338 continue;
2333 if (subs->endpoint == fp->endpoint) { 2339 if (subs->endpoint == fp->endpoint) {
2334 list_add_tail(&fp->list, &subs->fmt_list); 2340 list_add_tail(&fp->list, &subs->fmt_list);
@@ -2354,7 +2360,7 @@ static int add_audio_endpoint(struct snd_usb_audio *chip, int stream, struct aud
2354 2360
2355 /* create a new pcm */ 2361 /* create a new pcm */
2356 as = kzalloc(sizeof(*as), GFP_KERNEL); 2362 as = kzalloc(sizeof(*as), GFP_KERNEL);
2357 if (! as) 2363 if (!as)
2358 return -ENOMEM; 2364 return -ENOMEM;
2359 as->pcm_index = chip->pcm_devs; 2365 as->pcm_index = chip->pcm_devs;
2360 as->chip = chip; 2366 as->chip = chip;
@@ -2463,11 +2469,12 @@ static int parse_audio_format_i_type(struct snd_usb_audio *chip, struct audiofor
2463 } 2469 }
2464 break; 2470 break;
2465 case USB_AUDIO_FORMAT_PCM8: 2471 case USB_AUDIO_FORMAT_PCM8:
2466 /* Dallas DS4201 workaround */ 2472 pcm_format = SNDRV_PCM_FORMAT_U8;
2473
2474 /* Dallas DS4201 workaround: it advertises U8 format, but really
2475 supports S8. */
2467 if (chip->usb_id == USB_ID(0x04fa, 0x4201)) 2476 if (chip->usb_id == USB_ID(0x04fa, 0x4201))
2468 pcm_format = SNDRV_PCM_FORMAT_S8; 2477 pcm_format = SNDRV_PCM_FORMAT_S8;
2469 else
2470 pcm_format = SNDRV_PCM_FORMAT_U8;
2471 break; 2478 break;
2472 case USB_AUDIO_FORMAT_IEEE_FLOAT: 2479 case USB_AUDIO_FORMAT_IEEE_FLOAT:
2473 pcm_format = SNDRV_PCM_FORMAT_FLOAT_LE; 2480 pcm_format = SNDRV_PCM_FORMAT_FLOAT_LE;
@@ -2671,12 +2678,23 @@ static int parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no)
2671 int format; 2678 int format;
2672 struct audioformat *fp; 2679 struct audioformat *fp;
2673 unsigned char *fmt, *csep; 2680 unsigned char *fmt, *csep;
2681 int num;
2674 2682
2675 dev = chip->dev; 2683 dev = chip->dev;
2676 2684
2677 /* parse the interface's altsettings */ 2685 /* parse the interface's altsettings */
2678 iface = usb_ifnum_to_if(dev, iface_no); 2686 iface = usb_ifnum_to_if(dev, iface_no);
2679 for (i = 0; i < iface->num_altsetting; i++) { 2687
2688 num = iface->num_altsetting;
2689
2690 /*
2691 * Dallas DS4201 workaround: It presents 5 altsettings, but the last
2692 * one misses syncpipe, and does not produce any sound.
2693 */
2694 if (chip->usb_id == USB_ID(0x04fa, 0x4201))
2695 num = 4;
2696
2697 for (i = 0; i < num; i++) {
2680 alts = &iface->altsetting[i]; 2698 alts = &iface->altsetting[i];
2681 altsd = get_iface_desc(alts); 2699 altsd = get_iface_desc(alts);
2682 /* skip invalid one */ 2700 /* skip invalid one */
@@ -3375,14 +3393,14 @@ static int snd_usb_create_quirk(struct snd_usb_audio *chip,
3375static void proc_audio_usbbus_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) 3393static void proc_audio_usbbus_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
3376{ 3394{
3377 struct snd_usb_audio *chip = entry->private_data; 3395 struct snd_usb_audio *chip = entry->private_data;
3378 if (! chip->shutdown) 3396 if (!chip->shutdown)
3379 snd_iprintf(buffer, "%03d/%03d\n", chip->dev->bus->busnum, chip->dev->devnum); 3397 snd_iprintf(buffer, "%03d/%03d\n", chip->dev->bus->busnum, chip->dev->devnum);
3380} 3398}
3381 3399
3382static void proc_audio_usbid_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer) 3400static void proc_audio_usbid_read(struct snd_info_entry *entry, struct snd_info_buffer *buffer)
3383{ 3401{
3384 struct snd_usb_audio *chip = entry->private_data; 3402 struct snd_usb_audio *chip = entry->private_data;
3385 if (! chip->shutdown) 3403 if (!chip->shutdown)
3386 snd_iprintf(buffer, "%04x:%04x\n", 3404 snd_iprintf(buffer, "%04x:%04x\n",
3387 USB_ID_VENDOR(chip->usb_id), 3405 USB_ID_VENDOR(chip->usb_id),
3388 USB_ID_PRODUCT(chip->usb_id)); 3406 USB_ID_PRODUCT(chip->usb_id));
@@ -3391,9 +3409,9 @@ static void proc_audio_usbid_read(struct snd_info_entry *entry, struct snd_info_
3391static void snd_usb_audio_create_proc(struct snd_usb_audio *chip) 3409static void snd_usb_audio_create_proc(struct snd_usb_audio *chip)
3392{ 3410{
3393 struct snd_info_entry *entry; 3411 struct snd_info_entry *entry;
3394 if (! snd_card_proc_new(chip->card, "usbbus", &entry)) 3412 if (!snd_card_proc_new(chip->card, "usbbus", &entry))
3395 snd_info_set_text_ops(entry, chip, proc_audio_usbbus_read); 3413 snd_info_set_text_ops(entry, chip, proc_audio_usbbus_read);
3396 if (! snd_card_proc_new(chip->card, "usbid", &entry)) 3414 if (!snd_card_proc_new(chip->card, "usbid", &entry))
3397 snd_info_set_text_ops(entry, chip, proc_audio_usbid_read); 3415 snd_info_set_text_ops(entry, chip, proc_audio_usbid_read);
3398} 3416}
3399 3417
@@ -3406,7 +3424,6 @@ static void snd_usb_audio_create_proc(struct snd_usb_audio *chip)
3406 3424
3407static int snd_usb_audio_free(struct snd_usb_audio *chip) 3425static int snd_usb_audio_free(struct snd_usb_audio *chip)
3408{ 3426{
3409 usb_chip[chip->index] = NULL;
3410 kfree(chip); 3427 kfree(chip);
3411 return 0; 3428 return 0;
3412} 3429}
@@ -3600,8 +3617,8 @@ static void *snd_usb_audio_probe(struct usb_device *dev,
3600 snd_card_set_dev(chip->card, &intf->dev); 3617 snd_card_set_dev(chip->card, &intf->dev);
3601 break; 3618 break;
3602 } 3619 }
3603 if (! chip) { 3620 if (!chip) {
3604 snd_printk(KERN_ERR "no available usb audio device\n"); 3621 printk(KERN_ERR "no available usb audio device\n");
3605 goto __error; 3622 goto __error;
3606 } 3623 }
3607 } 3624 }
@@ -3671,6 +3688,7 @@ static void snd_usb_audio_disconnect(struct usb_device *dev, void *ptr)
3671 list_for_each(p, &chip->mixer_list) { 3688 list_for_each(p, &chip->mixer_list) {
3672 snd_usb_mixer_disconnect(p); 3689 snd_usb_mixer_disconnect(p);
3673 } 3690 }
3691 usb_chip[chip->index] = NULL;
3674 mutex_unlock(&register_mutex); 3692 mutex_unlock(&register_mutex);
3675 snd_card_free_when_closed(card); 3693 snd_card_free_when_closed(card);
3676 } else { 3694 } else {
diff --git a/sound/usb/usbquirks.h b/sound/usb/usbquirks.h
index 938dff5f9cef..82a8d14c26af 100644
--- a/sound/usb/usbquirks.h
+++ b/sound/usb/usbquirks.h
@@ -39,6 +39,30 @@
39 .idProduct = prod, \ 39 .idProduct = prod, \
40 .bInterfaceClass = USB_CLASS_VENDOR_SPEC 40 .bInterfaceClass = USB_CLASS_VENDOR_SPEC
41 41
42/* Creative/E-Mu devices */
43{
44 USB_DEVICE(0x041e, 0x3010),
45 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
46 .vendor_name = "Creative Labs",
47 .product_name = "Sound Blaster MP3+",
48 .ifnum = QUIRK_NO_INTERFACE
49 }
50},
51{
52 /* E-Mu 0202 USB */
53 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
54 .idVendor = 0x041e,
55 .idProduct = 0x3f02,
56 .bInterfaceClass = USB_CLASS_AUDIO,
57},
58{
59 /* E-Mu 0404 USB */
60 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
61 .idVendor = 0x041e,
62 .idProduct = 0x3f04,
63 .bInterfaceClass = USB_CLASS_AUDIO,
64},
65
42/* 66/*
43 * Logitech QuickCam: bDeviceClass is vendor-specific, so generic interface 67 * Logitech QuickCam: bDeviceClass is vendor-specific, so generic interface
44 * class matches do not take effect without an explicit ID match. 68 * class matches do not take effect without an explicit ID match.
@@ -97,19 +121,7 @@
97 .bInterfaceClass = USB_CLASS_AUDIO, 121 .bInterfaceClass = USB_CLASS_AUDIO,
98 .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL 122 .bInterfaceSubClass = USB_SUBCLASS_AUDIO_CONTROL
99}, 123},
100/* E-Mu devices */ 124
101{
102 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
103 .idVendor = 0x041e,
104 .idProduct = 0x3f02,
105 .bInterfaceClass = USB_CLASS_AUDIO,
106},
107{
108 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
109 .idVendor = 0x041e,
110 .idProduct = 0x3f04,
111 .bInterfaceClass = USB_CLASS_AUDIO,
112},
113/* 125/*
114 * Yamaha devices 126 * Yamaha devices
115 */ 127 */
@@ -1165,19 +1177,6 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1165 } 1177 }
1166 } 1178 }
1167}, 1179},
1168{
1169 USB_DEVICE(0x582, 0x00a6),
1170 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1171 .vendor_name = "Roland",
1172 .product_name = "Juno-G",
1173 .ifnum = 0,
1174 .type = QUIRK_MIDI_FIXED_ENDPOINT,
1175 .data = & (const struct snd_usb_midi_endpoint_info) {
1176 .out_cables = 0x0001,
1177 .in_cables = 0x0001
1178 }
1179 }
1180},
1181{ /* 1180{ /*
1182 * This quirk is for the "Advanced" modes of the Edirol UA-25. 1181 * This quirk is for the "Advanced" modes of the Edirol UA-25.
1183 * If the switch is not in an advanced setting, the UA-25 has 1182 * If the switch is not in an advanced setting, the UA-25 has
@@ -1336,6 +1335,19 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1336}, 1335},
1337 /* TODO: add Edirol MD-P1 support */ 1336 /* TODO: add Edirol MD-P1 support */
1338{ 1337{
1338 USB_DEVICE(0x582, 0x00a6),
1339 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1340 .vendor_name = "Roland",
1341 .product_name = "Juno-G",
1342 .ifnum = 0,
1343 .type = QUIRK_MIDI_FIXED_ENDPOINT,
1344 .data = & (const struct snd_usb_midi_endpoint_info) {
1345 .out_cables = 0x0001,
1346 .in_cables = 0x0001
1347 }
1348 }
1349},
1350{
1339 /* Roland SH-201 */ 1351 /* Roland SH-201 */
1340 USB_DEVICE(0x0582, 0x00ad), 1352 USB_DEVICE(0x0582, 0x00ad),
1341 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) { 1353 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
@@ -1719,17 +1731,6 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1719 } 1731 }
1720}, 1732},
1721 1733
1722{
1723 /* Creative Sound Blaster MP3+ */
1724 USB_DEVICE(0x041e, 0x3010),
1725 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1726 .vendor_name = "Creative Labs",
1727 .product_name = "Sound Blaster MP3+",
1728 .ifnum = QUIRK_NO_INTERFACE
1729 }
1730
1731},
1732
1733/* Emagic devices */ 1734/* Emagic devices */
1734{ 1735{
1735 USB_DEVICE(0x086a, 0x0001), 1736 USB_DEVICE(0x086a, 0x0001),